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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
FStar.BufferNG.fst | FStar.BufferNG.fill | val fill: #t:typ
-> b:buffer t
-> z: P.type_of_typ t
-> len:UInt32.t{UInt32.v len <= length b}
-> HST.Stack unit
(requires (fun h -> live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\
P.modifies (P.loc_buffer (gsub b 0ul len)) h0 h1
/\ Seq.slice (as_seq h1 b) 0 (UInt32.v len) == Seq.create (UInt32.v len) z
/\ Seq.slice (as_seq h1 b) (UInt32.v len) (length b) ==
Seq.slice (as_seq h0 b) (UInt32.v len) (length b) )) | val fill: #t:typ
-> b:buffer t
-> z: P.type_of_typ t
-> len:UInt32.t{UInt32.v len <= length b}
-> HST.Stack unit
(requires (fun h -> live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\
P.modifies (P.loc_buffer (gsub b 0ul len)) h0 h1
/\ Seq.slice (as_seq h1 b) 0 (UInt32.v len) == Seq.create (UInt32.v len) z
/\ Seq.slice (as_seq h1 b) (UInt32.v len) (length b) ==
Seq.slice (as_seq h0 b) (UInt32.v len) (length b) )) | let fill #t b z len =
let h0 = HST.get () in
P.fill_buffer b 0ul len z;
let h1 = HST.get () in
assert (as_seq h1 (gsub b 0ul len) == Seq.slice (as_seq h1 b) 0 (UInt32.v len));
assert (let g = gsub b len (UInt32.sub (P.buffer_length b) len) in as_seq h1 g == as_seq h0 g) | {
"file_name": "ulib/legacy/FStar.BufferNG.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 96,
"end_line": 492,
"start_col": 0,
"start_line": 487
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.BufferNG
module HH = FStar.HyperStack
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module P = FStar.Pointer
(* This module will help for the transition of some buffer-based code
It tries to sidestep the following two issues:
- the type of elements must be embeddable into P.typ
- all elements must always be readable (no uninitialized data)
*)
let rec supported
(t : P.typ)
: Tot bool
= match t with
| P.TBase _ -> true
| P.TStruct l -> struct_typ_supported l.P.fields
| _ -> false
and struct_typ_supported
(l: list (string * P.typ))
: Tot bool
= match l with
| [] -> true
| (_, t) :: l' -> supported t && struct_typ_supported l'
let typ = (t: P.typ { supported t } )
unfold
let buffer
(t: typ)
: Tot Type0
= P.buffer t
unfold
let live (#a: typ) (h: HS.mem) (b: buffer a) : GTot Type0 =
P.buffer_readable h b
unfold
let unused_in (#a: typ) (b: buffer a) (h: HS.mem) : GTot Type0 =
P.buffer_unused_in b h
unfold
let length (#a: typ) (b: buffer a) : GTot nat =
UInt32.v (P.buffer_length b)
unfold
let as_addr (#a: typ) (b: buffer a) : GTot nat =
P.buffer_as_addr b
unfold
let frameOf (#a: typ) (b: buffer a) : GTot HH.rid =
P.frameOf_buffer b
unfold
let as_seq (#a: typ) (h: HS.mem) (b: buffer a) : GTot (s: Seq.seq (P.type_of_typ a) { Seq.length s == length b } ) =
P.buffer_as_seq h b
unfold
let equal (#a: typ) (h: HS.mem) (b: buffer a) (h' : HS.mem) (b' : buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
unfold
let includes
(#a: typ)
(x y: buffer a)
: GTot Type0
= P.buffer_includes x y
let includes_live
(#a: typ)
(h: HS.mem)
(x y : buffer a)
: Lemma
(requires (x `includes` y /\ live h x))
(ensures (live h y))
= P.buffer_includes_elim x y
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= P.buffer_includes_elim x y
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= P.buffer_includes_trans x y z
unfold
let disjoint (#a #a' : typ) (x: buffer a) (y: buffer a') : GTot Type0 =
P.loc_disjoint (P.loc_buffer x) (P.loc_buffer y)
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= P.buffer_includes_loc_includes x subx;
P.loc_disjoint_includes (P.loc_buffer x) (P.loc_buffer y) (P.loc_buffer subx) (P.loc_buffer y)
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
let lemma_live_disjoint #a #a' h (b:buffer a) (b':buffer a') : Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
= ()
(** Concrete getters and setters *)
val create
(#a:typ)
(init: P.type_of_typ a)
(len:UInt32.t)
: HST.StackInline (buffer a)
(requires (fun h ->
UInt32.v len > 0
))
(ensures (fun (h0: HS.mem) b h1 ->
UInt32.v len > 0 /\
b `unused_in` h0 /\
live h1 b /\
length b == UInt32.v len /\
frameOf b == (HS.get_tip h0) /\
P.modifies_0 h0 h1 /\
as_seq h1 b == Seq.create (UInt32.v len) init
))
let create #a init len =
let len : P.array_length_t = len in
let content = P.screate (P.TArray len a) (Some (Seq.create (UInt32.v len) init)) in
P.buffer_of_array_pointer content
unfold let p (#a:typ) (init:list (P.type_of_typ a)) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init < UInt.max_int 32)
unfold let q (#a:typ) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
val createL
(#a: typ)
(init:list (P.type_of_typ a))
: HST.StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0: HS.mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0 /\
b `unused_in` h0 /\
live h1 b /\
length b == len /\
frameOf b == (HS.get_tip h0) /\
P.modifies_0 h0 h1 /\
as_seq h1 b == Seq.seq_of_list init /\
q #a len b
))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len : P.array_length_t = UInt32.uint_to_t (List.Tot.length init) in
let s = Seq.seq_of_list init in
let content = P.screate (P.TArray len a) (Some s) in
P.buffer_of_array_pointer content
#reset-options "--initial_fuel 0 --max_fuel 0"
val rcreate
(#a: typ)
(r:HH.rid)
(init: P.type_of_typ a)
(len:UInt32.t)
: HST.ST (buffer a)
(requires (fun h ->
HST.is_eternal_region r /\
HST.witnessed (HST.region_contains_pred r) /\
UInt32.v len > 0
))
(ensures (fun (h0: HS.mem) b h1 ->
b `unused_in` h0 /\
live h1 b /\
length b == UInt32.v len /\
(HS.get_tip h1) == (HS.get_tip h0) /\
P.modifies (P.loc_addresses r Set.empty) h0 h1 /\
as_seq h1 b == Seq.create (UInt32.v len) init
))
let rcreate #a r init len =
let len : P.array_length_t = len in
let content = P.ecreate (P.TArray len a) r (Some (Seq.create (UInt32.v len) init)) in
P.buffer_of_array_pointer content
val index
(#a: typ)
(b: buffer a)
(n: UInt32.t)
: HST.Stack (P.type_of_typ a)
(requires (fun h ->
UInt32.v n < length b /\
live h b
))
(ensures (fun h0 z h1 ->
UInt32.v n < length b /\
h1 == h0 /\
z == Seq.index (as_seq h0 b) (UInt32.v n)
))
let index #a b n =
P.read_buffer b n
val upd
(#a: typ)
(b: buffer a)
(n: UInt32.t)
(z: P.type_of_typ a)
: HST.Stack unit
(requires (fun h ->
live h b /\
UInt32.v n < length b
))
(ensures (fun h0 _ h1 ->
live h1 b /\
UInt32.v n < length b /\
P.modifies (P.loc_pointer (P.gpointer_of_buffer_cell b n)) h0 h1 /\
as_seq h1 b == Seq.upd (as_seq h0 b) (UInt32.v n) z
))
let upd #a b n z =
let h0 = HST.get () in
P.write_buffer b n z;
let h1 = HST.get () in
assert (Seq.equal (as_seq h1 b) (Seq.upd (as_seq h0 b) (UInt32.v n) z))
(* NOTE: Here I cannot fully respect the Buffer interface,
because pure sub no longer exists, since it has been split
into ghost gsub and stateful sub
*)
unfold
let gsub
(#a: typ)
(b: buffer a)
(i: UInt32.t)
(len: UInt32.t)
: Ghost (buffer a)
(requires (UInt32.v i + UInt32.v len <= length b))
(ensures (fun _ -> True))
= P.gsub_buffer b i len
let sub
(#a: typ)
(b: buffer a)
(i: UInt32.t)
(len: UInt32.t)
: HST.Stack (buffer a)
(requires (fun h ->
live h b /\
UInt32.v i + UInt32.v len <= length b
))
(ensures (fun h0 b' h1 ->
live h0 b /\
UInt32.v i + UInt32.v len <= length b /\
h1 == h0 /\
b' == gsub b i len /\
b `includes` b'
))
= P.sub_buffer b i len
let sub_sub
(#a: typ)
(b: buffer a)
(i1: UInt32.t)
(len1: UInt32.t)
(i2: UInt32.t)
(len2: UInt32.t)
: Lemma
(requires (
UInt32.v i1 + UInt32.v len1 <= length b /\
UInt32.v i2 + UInt32.v len2 <= UInt32.v len1
))
(ensures (
UInt32.v i1 + UInt32.v len1 <= length b /\
UInt32.v i2 + UInt32.v len2 <= UInt32.v len1 /\
gsub (gsub b i1 len1) i2 len2 == gsub b (UInt32.add i1 i2) len2
))
= ()
let sub_zero_length
(#a: typ)
(b: buffer a)
: Lemma
(ensures (gsub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b))
= ()
let lemma_sub_spec (#a:typ) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t)
(h: HS.mem)
: Lemma
(requires (
UInt32.v i + UInt32.v len <= length b /\
live h b
))
(ensures (
UInt32.v i + UInt32.v len <= length b /\
live h (gsub b i len) /\
as_seq h (gsub b i len) == Seq.slice (as_seq h b) (UInt32.v i) (UInt32.v i + UInt32.v len)
))
[SMTPatOr [
[SMTPat (gsub b i len); SMTPat (live h b)];
[SMTPat (live h (gsub b i len))]
]]
= Seq.lemma_eq_intro (as_seq h (gsub b i len)) (Seq.slice (as_seq h b) (UInt32.v i) (UInt32.v i + UInt32.v len))
(* Same here *)
let goffset
(#a: typ)
(b: buffer a)
(i: UInt32.t)
: Ghost (buffer a)
(requires (UInt32.v i <= length b))
(ensures (fun b' ->
UInt32.v i <= length b /\
b' == gsub b i (UInt32.sub (P.buffer_length b) i)
))
= P.gsub_buffer b i (UInt32.sub (P.buffer_length b) i)
let offset
(#a:typ)
(b:buffer a)
(i:UInt32.t)
: HST.Stack (buffer a)
(requires (fun h0 ->
live h0 b /\
UInt32.v i <= length b
))
(ensures (fun h0 b' h1 ->
h1 == h0 /\
UInt32.v i <= length b /\
b' == goffset b i
))
= P.offset_buffer b i
let lemma_offset_spec
(#a: typ)
(b: buffer a)
(i: UInt32.t)
(h: HS.mem)
: Lemma
(requires (
UInt32.v i <= length b /\
live h b
))
(ensures (
UInt32.v i <= length b /\
as_seq h (goffset b i) == Seq.slice (as_seq h b) (UInt32.v i) (length b)
))
= ()
val eqb: #a:typ -> b1:buffer a -> b2:buffer a
-> len:UInt32.t
-> HST.ST bool
(requires (fun h ->
hasEq (P.type_of_typ a) /\
UInt32.v len <= length b1 /\
UInt32.v len <= length b2 /\
live h b1 /\
live h b2
))
(ensures (fun h0 z h1 ->
h1 == h0 /\
UInt32.v len <= length b1 /\
UInt32.v len <= length b2 /\
(z <==> equal h0 (gsub b1 0ul len) h0 (gsub b2 0ul len))
))
let eqb #a b1 b2 len =
P.buffer_contents_equal b1 b2 len
(* JP: if the [val] is not specified, there's an issue with these functions
* taking an extra unification parameter at extraction-time... *)
val op_Array_Access: #a:typ -> b:buffer a -> n:UInt32.t -> HST.Stack (P.type_of_typ a)
(requires (fun h -> UInt32.v n<length b /\ live h b))
(ensures (fun h0 z h1 -> h1 == h0 /\
UInt32.v n<length b /\
z == Seq.index (as_seq h0 b) (UInt32.v n)))
let op_Array_Access #a b n = index #a b n
val op_Array_Assignment: #a:typ -> b:buffer a -> n:UInt32.t -> z:P.type_of_typ a -> HST.Stack unit
(requires (fun h -> live h b /\ UInt32.v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ UInt32.v n < length b
/\ P.modifies (P.loc_pointer (P.gpointer_of_buffer_cell b n)) h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (UInt32.v n) z ))
let op_Array_Assignment #a b n z = upd #a b n z
val live_slice_middle
(#t: typ)
(b: buffer t)
(i: UInt32.t)
(len: UInt32.t)
(h: HS.mem)
: Lemma
(requires (
UInt32.v i + UInt32.v len <= length b /\
live h (gsub b 0ul i) /\
live h (gsub b i len) /\ (
let off = UInt32.add i len in
live h (gsub b off (UInt32.sub (P.buffer_length b) off))
)))
(ensures (live h b))
[SMTPat (live h (gsub b i len))]
let live_slice_middle #t b i len h =
P.buffer_readable_gsub_merge b i len h
(** Corresponds to memcpy *)
val blit: #t:typ
-> a:buffer t
-> idx_a:UInt32.t
-> b:buffer t{disjoint a b}
-> idx_b:UInt32.t
-> len:UInt32.t{UInt32.v idx_a + UInt32.v len <= length a /\ UInt32.v idx_b + UInt32.v len <= length b}
-> HST.Stack unit
(requires (fun h -> live h a /\ live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h0 a /\ live h1 b /\ live h1 a /\ P.modifies (P.loc_buffer (gsub b idx_b len)) h0 h1
/\ Seq.slice (as_seq h1 b) (UInt32.v idx_b) (UInt32.v idx_b + UInt32.v len) ==
Seq.slice (as_seq h0 a) (UInt32.v idx_a) (UInt32.v idx_a + UInt32.v len)
/\ Seq.slice (as_seq h1 b) 0 (UInt32.v idx_b) ==
Seq.slice (as_seq h0 b) 0 (UInt32.v idx_b)
/\ Seq.slice (as_seq h1 b) (UInt32.v idx_b+UInt32.v len) (length b) ==
Seq.slice (as_seq h0 b) (UInt32.v idx_b+UInt32.v len) (length b) ))
let blit #t a idx_a b idx_b len =
if len = 0ul
then ()
else begin
let h0 = HST.get () in
P.copy_buffer_contents a idx_a b idx_b len;
let h1 = HST.get () in
P.buffer_readable_modifies_gsub b idx_b len h0 h1 (P.loc_buffer (P.gsub_buffer b idx_b len));
assert (let g = (gsub b (UInt32.add idx_b len) (UInt32.sub (P.buffer_length b) (UInt32.add idx_b len))) in as_seq h1 g == as_seq h0 g);
assert (as_seq h1 (gsub b idx_b len) == as_seq h0 (gsub a idx_a len));
assert (let g = gsub b 0ul idx_b in as_seq h1 g == as_seq h0 g)
end
(** Corresponds to memset *)
val fill: #t:typ
-> b:buffer t
-> z: P.type_of_typ t
-> len:UInt32.t{UInt32.v len <= length b}
-> HST.Stack unit
(requires (fun h -> live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\
P.modifies (P.loc_buffer (gsub b 0ul len)) h0 h1
/\ Seq.slice (as_seq h1 b) 0 (UInt32.v len) == Seq.create (UInt32.v len) z
/\ Seq.slice (as_seq h1 b) (UInt32.v len) (length b) ==
Seq.slice (as_seq h0 b) (UInt32.v len) (length b) )) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pointer.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.BufferNG.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Pointer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HH"
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: FStar.BufferNG.buffer t ->
z: FStar.Pointer.Base.type_of_typ t ->
len: FStar.UInt32.t{FStar.UInt32.v len <= FStar.BufferNG.length b}
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.BufferNG.typ",
"FStar.BufferNG.buffer",
"FStar.Pointer.Base.type_of_typ",
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"FStar.BufferNG.length",
"Prims._assert",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.BufferNG.as_seq",
"FStar.Pointer.Base.buffer",
"FStar.BufferNG.gsub",
"FStar.UInt32.sub",
"FStar.Pointer.Base.buffer_length",
"Prims.unit",
"FStar.UInt32.__uint_to_t",
"FStar.Seq.Base.slice",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"FStar.Pointer.Derived3.fill_buffer"
] | [] | false | true | false | false | false | let fill #t b z len =
| let h0 = HST.get () in
P.fill_buffer b 0ul len z;
let h1 = HST.get () in
assert (as_seq h1 (gsub b 0ul len) == Seq.slice (as_seq h1 b) 0 (UInt32.v len));
assert (let g = gsub b len (UInt32.sub (P.buffer_length b) len) in
as_seq h1 g == as_seq h0 g) | false |
Vale.AES.GCTR_BE_s.fst | Vale.AES.GCTR_BE_s.gctr_encrypt_reveal | val gctr_encrypt_reveal : _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.AES.GCTR_BE_s.gctr_encrypt == Vale.AES.GCTR_BE_s.gctr_encrypt_def) | let gctr_encrypt_reveal = opaque_revealer (`%gctr_encrypt) gctr_encrypt gctr_encrypt_def | {
"file_name": "vale/specs/crypto/Vale.AES.GCTR_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 100,
"end_line": 70,
"start_col": 12,
"start_line": 70
} | module Vale.AES.GCTR_BE_s
// IMPORTANT: Following NIST's specification, this spec is written assuming a big-endian mapping from bytes to quad32s
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open Vale.AES.AES_BE_s
open FStar.Seq
// The max length of pow2_32 corresponds to the max length of buffers in Low*
// length plain < pow2_32 <= spec max of 2**39 - 256;
let is_gctr_plain (p:seq nat8) : prop0 = length p < pow2_32
type gctr_plain:eqtype = p:seq nat8 { is_gctr_plain p }
type gctr_plain_internal:eqtype = seq quad32
let inc32 (cb:quad32) (i:int) : quad32 =
Mkfour ((cb.lo0 + i) % pow2_32) cb.lo1 cb.hi2 cb.hi3
let gctr_encrypt_block (icb:quad32) (plain:quad32) (alg:algorithm) (key:seq nat32) (i:int) : Pure quad32
(requires is_aes_key_word alg key)
(ensures fun _ -> True)
=
quad32_xor plain (aes_encrypt_word alg key (inc32 icb i))
let rec gctr_encrypt_recursive (icb:quad32) (plain:gctr_plain_internal)
(alg:algorithm) (key:aes_key_word alg) (i:int) : Tot (seq quad32) (decreases %[length plain]) =
if length plain = 0 then empty
else
cons (gctr_encrypt_block icb (head plain) alg key i) (gctr_encrypt_recursive icb (tail plain) alg key (i + 1))
let pad_to_128_bits (p:seq nat8) : Pure (seq nat8)
(requires True)
(ensures fun q -> length q % 16 == 0 /\ length q <= length p + 15)
=
let num_extra_bytes = length p % 16 in
if num_extra_bytes = 0 then p
else p @| (create (16 - num_extra_bytes) 0)
let gctr_encrypt_def (icb:quad32) (plain:seq nat8) (alg:algorithm) (key:seq nat32) : Pure (seq nat8)
(requires is_gctr_plain plain /\ is_aes_key_word alg key)
(ensures fun _ -> True)
=
let num_extra = (length plain) % 16 in
if num_extra = 0 then
let plain_quads = be_bytes_to_seq_quad32 plain in
let cipher_quads = gctr_encrypt_recursive icb plain_quads alg key 0 in
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_quads)
else
let full_bytes_len = (length plain) - num_extra in
let full_blocks, final_block = split plain full_bytes_len in
let full_quads = be_bytes_to_seq_quad32 full_blocks in
let final_quad = be_bytes_to_quad32 (pad_to_128_bits final_block) in
let cipher_quads = gctr_encrypt_recursive icb full_quads alg key 0 in
let final_cipher_quad = gctr_encrypt_block icb final_quad alg key (full_bytes_len / 16) in
let cipher_bytes_full = seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_quads) in
let final_cipher_bytes = slice (be_quad32_to_bytes final_cipher_quad) 0 num_extra in
cipher_bytes_full @| final_cipher_bytes | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.GCTR_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.AES.GCTR_BE_s.gctr_encrypt == Vale.AES.GCTR_BE_s.gctr_encrypt_def) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Opaque_s.opaque_revealer",
"Vale.Def.Types_s.quad32",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat8",
"Vale.AES.AES_common_s.algorithm",
"Vale.Def.Types_s.nat32",
"Prims.l_and",
"Vale.AES.GCTR_BE_s.is_gctr_plain",
"Vale.AES.AES_BE_s.is_aes_key_word",
"Prims.l_True",
"Vale.AES.GCTR_BE_s.gctr_encrypt",
"Vale.AES.GCTR_BE_s.gctr_encrypt_def"
] | [] | true | false | true | false | false | let gctr_encrypt_reveal =
| opaque_revealer (`%gctr_encrypt) gctr_encrypt gctr_encrypt_def | false |
|
Steel.Channel.Duplex.fsti | Steel.Channel.Duplex.prot | val prot:Type u#1 | val prot:Type u#1 | let prot : Type u#1 = protocol unit | {
"file_name": "lib/steel/Steel.Channel.Duplex.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 35,
"end_line": 31,
"start_col": 0,
"start_line": 31
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Channel.Duplex
open Steel.Channel.Protocol
open Steel.Memory
open Steel.Effect
/// This library provides a model of two-party session types in Steel.
/// Protocols are specified using the structure in Steel.Channel.Protocol
/// Channels are indexed by a given protocols, and ensure that any message exchanged
/// on the channel respect the protocol.
/// An implementation of this model is currently available in Duplex.PCM.fst
/// Msg int (fun x -> Msg (y:int { y > x }) (fun _ -> Ret unit))
/// | {
"checked_file": "/",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.Effect.fsti.checked",
"Steel.Channel.Protocol.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Channel.Duplex.fsti"
} | [
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Channel.Protocol",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Channel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Channel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | Type | Prims.Tot | [
"total"
] | [] | [
"Steel.Channel.Protocol.protocol",
"Prims.unit"
] | [] | false | false | false | true | true | let prot:Type u#1 =
| protocol unit | false |
Vale.AES.GCTR_BE_s.fst | Vale.AES.GCTR_BE_s.gctr_encrypt_block | val gctr_encrypt_block (icb plain: quad32) (alg: algorithm) (key: seq nat32) (i: int)
: Pure quad32 (requires is_aes_key_word alg key) (ensures fun _ -> True) | val gctr_encrypt_block (icb plain: quad32) (alg: algorithm) (key: seq nat32) (i: int)
: Pure quad32 (requires is_aes_key_word alg key) (ensures fun _ -> True) | let gctr_encrypt_block (icb:quad32) (plain:quad32) (alg:algorithm) (key:seq nat32) (i:int) : Pure quad32
(requires is_aes_key_word alg key)
(ensures fun _ -> True)
=
quad32_xor plain (aes_encrypt_word alg key (inc32 icb i)) | {
"file_name": "vale/specs/crypto/Vale.AES.GCTR_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 59,
"end_line": 28,
"start_col": 0,
"start_line": 24
} | module Vale.AES.GCTR_BE_s
// IMPORTANT: Following NIST's specification, this spec is written assuming a big-endian mapping from bytes to quad32s
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open Vale.AES.AES_BE_s
open FStar.Seq
// The max length of pow2_32 corresponds to the max length of buffers in Low*
// length plain < pow2_32 <= spec max of 2**39 - 256;
let is_gctr_plain (p:seq nat8) : prop0 = length p < pow2_32
type gctr_plain:eqtype = p:seq nat8 { is_gctr_plain p }
type gctr_plain_internal:eqtype = seq quad32
let inc32 (cb:quad32) (i:int) : quad32 =
Mkfour ((cb.lo0 + i) % pow2_32) cb.lo1 cb.hi2 cb.hi3 | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.GCTR_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 |
icb: Vale.Def.Types_s.quad32 ->
plain: Vale.Def.Types_s.quad32 ->
alg: Vale.AES.AES_common_s.algorithm ->
key: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 ->
i: Prims.int
-> Prims.Pure Vale.Def.Types_s.quad32 | Prims.Pure | [] | [] | [
"Vale.Def.Types_s.quad32",
"Vale.AES.AES_common_s.algorithm",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Prims.int",
"Vale.Def.Types_s.quad32_xor",
"Vale.AES.AES_BE_s.aes_encrypt_word",
"Vale.AES.GCTR_BE_s.inc32",
"Vale.AES.AES_BE_s.is_aes_key_word",
"Prims.l_True"
] | [] | false | false | false | false | false | let gctr_encrypt_block (icb plain: quad32) (alg: algorithm) (key: seq nat32) (i: int)
: Pure quad32 (requires is_aes_key_word alg key) (ensures fun _ -> True) =
| quad32_xor plain (aes_encrypt_word alg key (inc32 icb i)) | false |
Vale.AES.GCTR_BE_s.fst | Vale.AES.GCTR_BE_s.gctr_encrypt_recursive | val gctr_encrypt_recursive
(icb: quad32)
(plain: gctr_plain_internal)
(alg: algorithm)
(key: aes_key_word alg)
(i: int)
: Tot (seq quad32) (decreases %[length plain]) | val gctr_encrypt_recursive
(icb: quad32)
(plain: gctr_plain_internal)
(alg: algorithm)
(key: aes_key_word alg)
(i: int)
: Tot (seq quad32) (decreases %[length plain]) | let rec gctr_encrypt_recursive (icb:quad32) (plain:gctr_plain_internal)
(alg:algorithm) (key:aes_key_word alg) (i:int) : Tot (seq quad32) (decreases %[length plain]) =
if length plain = 0 then empty
else
cons (gctr_encrypt_block icb (head plain) alg key i) (gctr_encrypt_recursive icb (tail plain) alg key (i + 1)) | {
"file_name": "vale/specs/crypto/Vale.AES.GCTR_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 114,
"end_line": 35,
"start_col": 0,
"start_line": 31
} | module Vale.AES.GCTR_BE_s
// IMPORTANT: Following NIST's specification, this spec is written assuming a big-endian mapping from bytes to quad32s
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open Vale.AES.AES_BE_s
open FStar.Seq
// The max length of pow2_32 corresponds to the max length of buffers in Low*
// length plain < pow2_32 <= spec max of 2**39 - 256;
let is_gctr_plain (p:seq nat8) : prop0 = length p < pow2_32
type gctr_plain:eqtype = p:seq nat8 { is_gctr_plain p }
type gctr_plain_internal:eqtype = seq quad32
let inc32 (cb:quad32) (i:int) : quad32 =
Mkfour ((cb.lo0 + i) % pow2_32) cb.lo1 cb.hi2 cb.hi3
let gctr_encrypt_block (icb:quad32) (plain:quad32) (alg:algorithm) (key:seq nat32) (i:int) : Pure quad32
(requires is_aes_key_word alg key)
(ensures fun _ -> True)
=
quad32_xor plain (aes_encrypt_word alg key (inc32 icb i)) | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.GCTR_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 |
icb: Vale.Def.Types_s.quad32 ->
plain: Vale.AES.GCTR_BE_s.gctr_plain_internal ->
alg: Vale.AES.AES_common_s.algorithm ->
key: Vale.AES.AES_BE_s.aes_key_word alg ->
i: Prims.int
-> Prims.Tot (FStar.Seq.Base.seq Vale.Def.Types_s.quad32) | Prims.Tot | [
"total",
""
] | [] | [
"Vale.Def.Types_s.quad32",
"Vale.AES.GCTR_BE_s.gctr_plain_internal",
"Vale.AES.AES_common_s.algorithm",
"Vale.AES.AES_BE_s.aes_key_word",
"Prims.int",
"Prims.op_Equality",
"FStar.Seq.Base.length",
"FStar.Seq.Base.empty",
"Prims.bool",
"FStar.Seq.Base.cons",
"Vale.AES.GCTR_BE_s.gctr_encrypt_block",
"FStar.Seq.Properties.head",
"Vale.AES.GCTR_BE_s.gctr_encrypt_recursive",
"FStar.Seq.Properties.tail",
"Prims.op_Addition",
"FStar.Seq.Base.seq"
] | [
"recursion"
] | false | false | false | false | false | let rec gctr_encrypt_recursive
(icb: quad32)
(plain: gctr_plain_internal)
(alg: algorithm)
(key: aes_key_word alg)
(i: int)
: Tot (seq quad32) (decreases %[length plain]) =
| if length plain = 0
then empty
else
cons (gctr_encrypt_block icb (head plain) alg key i)
(gctr_encrypt_recursive icb (tail plain) alg key (i + 1)) | false |
FStar.BufferNG.fst | FStar.BufferNG.blit | val blit: #t:typ
-> a:buffer t
-> idx_a:UInt32.t
-> b:buffer t{disjoint a b}
-> idx_b:UInt32.t
-> len:UInt32.t{UInt32.v idx_a + UInt32.v len <= length a /\ UInt32.v idx_b + UInt32.v len <= length b}
-> HST.Stack unit
(requires (fun h -> live h a /\ live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h0 a /\ live h1 b /\ live h1 a /\ P.modifies (P.loc_buffer (gsub b idx_b len)) h0 h1
/\ Seq.slice (as_seq h1 b) (UInt32.v idx_b) (UInt32.v idx_b + UInt32.v len) ==
Seq.slice (as_seq h0 a) (UInt32.v idx_a) (UInt32.v idx_a + UInt32.v len)
/\ Seq.slice (as_seq h1 b) 0 (UInt32.v idx_b) ==
Seq.slice (as_seq h0 b) 0 (UInt32.v idx_b)
/\ Seq.slice (as_seq h1 b) (UInt32.v idx_b+UInt32.v len) (length b) ==
Seq.slice (as_seq h0 b) (UInt32.v idx_b+UInt32.v len) (length b) )) | val blit: #t:typ
-> a:buffer t
-> idx_a:UInt32.t
-> b:buffer t{disjoint a b}
-> idx_b:UInt32.t
-> len:UInt32.t{UInt32.v idx_a + UInt32.v len <= length a /\ UInt32.v idx_b + UInt32.v len <= length b}
-> HST.Stack unit
(requires (fun h -> live h a /\ live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h0 a /\ live h1 b /\ live h1 a /\ P.modifies (P.loc_buffer (gsub b idx_b len)) h0 h1
/\ Seq.slice (as_seq h1 b) (UInt32.v idx_b) (UInt32.v idx_b + UInt32.v len) ==
Seq.slice (as_seq h0 a) (UInt32.v idx_a) (UInt32.v idx_a + UInt32.v len)
/\ Seq.slice (as_seq h1 b) 0 (UInt32.v idx_b) ==
Seq.slice (as_seq h0 b) 0 (UInt32.v idx_b)
/\ Seq.slice (as_seq h1 b) (UInt32.v idx_b+UInt32.v len) (length b) ==
Seq.slice (as_seq h0 b) (UInt32.v idx_b+UInt32.v len) (length b) )) | let blit #t a idx_a b idx_b len =
if len = 0ul
then ()
else begin
let h0 = HST.get () in
P.copy_buffer_contents a idx_a b idx_b len;
let h1 = HST.get () in
P.buffer_readable_modifies_gsub b idx_b len h0 h1 (P.loc_buffer (P.gsub_buffer b idx_b len));
assert (let g = (gsub b (UInt32.add idx_b len) (UInt32.sub (P.buffer_length b) (UInt32.add idx_b len))) in as_seq h1 g == as_seq h0 g);
assert (as_seq h1 (gsub b idx_b len) == as_seq h0 (gsub a idx_a len));
assert (let g = gsub b 0ul idx_b in as_seq h1 g == as_seq h0 g)
end | {
"file_name": "ulib/legacy/FStar.BufferNG.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 5,
"end_line": 472,
"start_col": 0,
"start_line": 461
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.BufferNG
module HH = FStar.HyperStack
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module P = FStar.Pointer
(* This module will help for the transition of some buffer-based code
It tries to sidestep the following two issues:
- the type of elements must be embeddable into P.typ
- all elements must always be readable (no uninitialized data)
*)
let rec supported
(t : P.typ)
: Tot bool
= match t with
| P.TBase _ -> true
| P.TStruct l -> struct_typ_supported l.P.fields
| _ -> false
and struct_typ_supported
(l: list (string * P.typ))
: Tot bool
= match l with
| [] -> true
| (_, t) :: l' -> supported t && struct_typ_supported l'
let typ = (t: P.typ { supported t } )
unfold
let buffer
(t: typ)
: Tot Type0
= P.buffer t
unfold
let live (#a: typ) (h: HS.mem) (b: buffer a) : GTot Type0 =
P.buffer_readable h b
unfold
let unused_in (#a: typ) (b: buffer a) (h: HS.mem) : GTot Type0 =
P.buffer_unused_in b h
unfold
let length (#a: typ) (b: buffer a) : GTot nat =
UInt32.v (P.buffer_length b)
unfold
let as_addr (#a: typ) (b: buffer a) : GTot nat =
P.buffer_as_addr b
unfold
let frameOf (#a: typ) (b: buffer a) : GTot HH.rid =
P.frameOf_buffer b
unfold
let as_seq (#a: typ) (h: HS.mem) (b: buffer a) : GTot (s: Seq.seq (P.type_of_typ a) { Seq.length s == length b } ) =
P.buffer_as_seq h b
unfold
let equal (#a: typ) (h: HS.mem) (b: buffer a) (h' : HS.mem) (b' : buffer a) : GTot Type0 =
as_seq h b == as_seq h' b'
unfold
let includes
(#a: typ)
(x y: buffer a)
: GTot Type0
= P.buffer_includes x y
let includes_live
(#a: typ)
(h: HS.mem)
(x y : buffer a)
: Lemma
(requires (x `includes` y /\ live h x))
(ensures (live h y))
= P.buffer_includes_elim x y
let includes_as_seq #a h1 h2 (x: buffer a) (y: buffer a)
: Lemma
(requires (x `includes` y /\ as_seq h1 x == as_seq h2 x))
(ensures (as_seq h1 y == as_seq h2 y))
= P.buffer_includes_elim x y
let includes_trans #a (x y z: buffer a)
: Lemma
(requires (x `includes` y /\ y `includes` z))
(ensures (x `includes` z))
= P.buffer_includes_trans x y z
unfold
let disjoint (#a #a' : typ) (x: buffer a) (y: buffer a') : GTot Type0 =
P.loc_disjoint (P.loc_buffer x) (P.loc_buffer y)
(* Disjointness is symmetric *)
let lemma_disjoint_symm #a #a' (x:buffer a) (y:buffer a') : Lemma
(requires True)
(ensures (disjoint x y <==> disjoint y x))
[SMTPat (disjoint x y)]
= ()
let lemma_disjoint_sub #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint subx y); SMTPat (includes x subx)]
= P.buffer_includes_loc_includes x subx;
P.loc_disjoint_includes (P.loc_buffer x) (P.loc_buffer y) (P.loc_buffer subx) (P.loc_buffer y)
let lemma_disjoint_sub' #a #a' (x:buffer a) (subx:buffer a) (y:buffer a') : Lemma
(requires (includes x subx /\ disjoint x y))
(ensures (disjoint subx y))
[SMTPat (disjoint y subx); SMTPat (includes x subx)]
= ()
let lemma_live_disjoint #a #a' h (b:buffer a) (b':buffer a') : Lemma
(requires (live h b /\ b' `unused_in` h))
(ensures (disjoint b b'))
[SMTPat (disjoint b b'); SMTPat (live h b)]
= ()
(** Concrete getters and setters *)
val create
(#a:typ)
(init: P.type_of_typ a)
(len:UInt32.t)
: HST.StackInline (buffer a)
(requires (fun h ->
UInt32.v len > 0
))
(ensures (fun (h0: HS.mem) b h1 ->
UInt32.v len > 0 /\
b `unused_in` h0 /\
live h1 b /\
length b == UInt32.v len /\
frameOf b == (HS.get_tip h0) /\
P.modifies_0 h0 h1 /\
as_seq h1 b == Seq.create (UInt32.v len) init
))
let create #a init len =
let len : P.array_length_t = len in
let content = P.screate (P.TArray len a) (Some (Seq.create (UInt32.v len) init)) in
P.buffer_of_array_pointer content
unfold let p (#a:typ) (init:list (P.type_of_typ a)) : GTot Type0 =
normalize (0 < FStar.List.Tot.length init) /\
normalize (FStar.List.Tot.length init < UInt.max_int 32)
unfold let q (#a:typ) (len:nat) (buf:buffer a) : GTot Type0 =
normalize (length buf == len)
val createL
(#a: typ)
(init:list (P.type_of_typ a))
: HST.StackInline (buffer a)
(requires (fun h -> p #a init))
(ensures (fun (h0: HS.mem) b h1 ->
let len = FStar.List.Tot.length init in
len > 0 /\
b `unused_in` h0 /\
live h1 b /\
length b == len /\
frameOf b == (HS.get_tip h0) /\
P.modifies_0 h0 h1 /\
as_seq h1 b == Seq.seq_of_list init /\
q #a len b
))
#set-options "--initial_fuel 1 --max_fuel 1" //the normalize_term (length init) in the pre-condition will be unfolded
//whereas the L.length init below will not
let createL #a init =
let len : P.array_length_t = UInt32.uint_to_t (List.Tot.length init) in
let s = Seq.seq_of_list init in
let content = P.screate (P.TArray len a) (Some s) in
P.buffer_of_array_pointer content
#reset-options "--initial_fuel 0 --max_fuel 0"
val rcreate
(#a: typ)
(r:HH.rid)
(init: P.type_of_typ a)
(len:UInt32.t)
: HST.ST (buffer a)
(requires (fun h ->
HST.is_eternal_region r /\
HST.witnessed (HST.region_contains_pred r) /\
UInt32.v len > 0
))
(ensures (fun (h0: HS.mem) b h1 ->
b `unused_in` h0 /\
live h1 b /\
length b == UInt32.v len /\
(HS.get_tip h1) == (HS.get_tip h0) /\
P.modifies (P.loc_addresses r Set.empty) h0 h1 /\
as_seq h1 b == Seq.create (UInt32.v len) init
))
let rcreate #a r init len =
let len : P.array_length_t = len in
let content = P.ecreate (P.TArray len a) r (Some (Seq.create (UInt32.v len) init)) in
P.buffer_of_array_pointer content
val index
(#a: typ)
(b: buffer a)
(n: UInt32.t)
: HST.Stack (P.type_of_typ a)
(requires (fun h ->
UInt32.v n < length b /\
live h b
))
(ensures (fun h0 z h1 ->
UInt32.v n < length b /\
h1 == h0 /\
z == Seq.index (as_seq h0 b) (UInt32.v n)
))
let index #a b n =
P.read_buffer b n
val upd
(#a: typ)
(b: buffer a)
(n: UInt32.t)
(z: P.type_of_typ a)
: HST.Stack unit
(requires (fun h ->
live h b /\
UInt32.v n < length b
))
(ensures (fun h0 _ h1 ->
live h1 b /\
UInt32.v n < length b /\
P.modifies (P.loc_pointer (P.gpointer_of_buffer_cell b n)) h0 h1 /\
as_seq h1 b == Seq.upd (as_seq h0 b) (UInt32.v n) z
))
let upd #a b n z =
let h0 = HST.get () in
P.write_buffer b n z;
let h1 = HST.get () in
assert (Seq.equal (as_seq h1 b) (Seq.upd (as_seq h0 b) (UInt32.v n) z))
(* NOTE: Here I cannot fully respect the Buffer interface,
because pure sub no longer exists, since it has been split
into ghost gsub and stateful sub
*)
unfold
let gsub
(#a: typ)
(b: buffer a)
(i: UInt32.t)
(len: UInt32.t)
: Ghost (buffer a)
(requires (UInt32.v i + UInt32.v len <= length b))
(ensures (fun _ -> True))
= P.gsub_buffer b i len
let sub
(#a: typ)
(b: buffer a)
(i: UInt32.t)
(len: UInt32.t)
: HST.Stack (buffer a)
(requires (fun h ->
live h b /\
UInt32.v i + UInt32.v len <= length b
))
(ensures (fun h0 b' h1 ->
live h0 b /\
UInt32.v i + UInt32.v len <= length b /\
h1 == h0 /\
b' == gsub b i len /\
b `includes` b'
))
= P.sub_buffer b i len
let sub_sub
(#a: typ)
(b: buffer a)
(i1: UInt32.t)
(len1: UInt32.t)
(i2: UInt32.t)
(len2: UInt32.t)
: Lemma
(requires (
UInt32.v i1 + UInt32.v len1 <= length b /\
UInt32.v i2 + UInt32.v len2 <= UInt32.v len1
))
(ensures (
UInt32.v i1 + UInt32.v len1 <= length b /\
UInt32.v i2 + UInt32.v len2 <= UInt32.v len1 /\
gsub (gsub b i1 len1) i2 len2 == gsub b (UInt32.add i1 i2) len2
))
= ()
let sub_zero_length
(#a: typ)
(b: buffer a)
: Lemma
(ensures (gsub b (UInt32.uint_to_t 0) (UInt32.uint_to_t (length b)) == b))
= ()
let lemma_sub_spec (#a:typ) (b:buffer a)
(i:UInt32.t)
(len:UInt32.t)
(h: HS.mem)
: Lemma
(requires (
UInt32.v i + UInt32.v len <= length b /\
live h b
))
(ensures (
UInt32.v i + UInt32.v len <= length b /\
live h (gsub b i len) /\
as_seq h (gsub b i len) == Seq.slice (as_seq h b) (UInt32.v i) (UInt32.v i + UInt32.v len)
))
[SMTPatOr [
[SMTPat (gsub b i len); SMTPat (live h b)];
[SMTPat (live h (gsub b i len))]
]]
= Seq.lemma_eq_intro (as_seq h (gsub b i len)) (Seq.slice (as_seq h b) (UInt32.v i) (UInt32.v i + UInt32.v len))
(* Same here *)
let goffset
(#a: typ)
(b: buffer a)
(i: UInt32.t)
: Ghost (buffer a)
(requires (UInt32.v i <= length b))
(ensures (fun b' ->
UInt32.v i <= length b /\
b' == gsub b i (UInt32.sub (P.buffer_length b) i)
))
= P.gsub_buffer b i (UInt32.sub (P.buffer_length b) i)
let offset
(#a:typ)
(b:buffer a)
(i:UInt32.t)
: HST.Stack (buffer a)
(requires (fun h0 ->
live h0 b /\
UInt32.v i <= length b
))
(ensures (fun h0 b' h1 ->
h1 == h0 /\
UInt32.v i <= length b /\
b' == goffset b i
))
= P.offset_buffer b i
let lemma_offset_spec
(#a: typ)
(b: buffer a)
(i: UInt32.t)
(h: HS.mem)
: Lemma
(requires (
UInt32.v i <= length b /\
live h b
))
(ensures (
UInt32.v i <= length b /\
as_seq h (goffset b i) == Seq.slice (as_seq h b) (UInt32.v i) (length b)
))
= ()
val eqb: #a:typ -> b1:buffer a -> b2:buffer a
-> len:UInt32.t
-> HST.ST bool
(requires (fun h ->
hasEq (P.type_of_typ a) /\
UInt32.v len <= length b1 /\
UInt32.v len <= length b2 /\
live h b1 /\
live h b2
))
(ensures (fun h0 z h1 ->
h1 == h0 /\
UInt32.v len <= length b1 /\
UInt32.v len <= length b2 /\
(z <==> equal h0 (gsub b1 0ul len) h0 (gsub b2 0ul len))
))
let eqb #a b1 b2 len =
P.buffer_contents_equal b1 b2 len
(* JP: if the [val] is not specified, there's an issue with these functions
* taking an extra unification parameter at extraction-time... *)
val op_Array_Access: #a:typ -> b:buffer a -> n:UInt32.t -> HST.Stack (P.type_of_typ a)
(requires (fun h -> UInt32.v n<length b /\ live h b))
(ensures (fun h0 z h1 -> h1 == h0 /\
UInt32.v n<length b /\
z == Seq.index (as_seq h0 b) (UInt32.v n)))
let op_Array_Access #a b n = index #a b n
val op_Array_Assignment: #a:typ -> b:buffer a -> n:UInt32.t -> z:P.type_of_typ a -> HST.Stack unit
(requires (fun h -> live h b /\ UInt32.v n < length b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ UInt32.v n < length b
/\ P.modifies (P.loc_pointer (P.gpointer_of_buffer_cell b n)) h0 h1
/\ as_seq h1 b == Seq.upd (as_seq h0 b) (UInt32.v n) z ))
let op_Array_Assignment #a b n z = upd #a b n z
val live_slice_middle
(#t: typ)
(b: buffer t)
(i: UInt32.t)
(len: UInt32.t)
(h: HS.mem)
: Lemma
(requires (
UInt32.v i + UInt32.v len <= length b /\
live h (gsub b 0ul i) /\
live h (gsub b i len) /\ (
let off = UInt32.add i len in
live h (gsub b off (UInt32.sub (P.buffer_length b) off))
)))
(ensures (live h b))
[SMTPat (live h (gsub b i len))]
let live_slice_middle #t b i len h =
P.buffer_readable_gsub_merge b i len h
(** Corresponds to memcpy *)
val blit: #t:typ
-> a:buffer t
-> idx_a:UInt32.t
-> b:buffer t{disjoint a b}
-> idx_b:UInt32.t
-> len:UInt32.t{UInt32.v idx_a + UInt32.v len <= length a /\ UInt32.v idx_b + UInt32.v len <= length b}
-> HST.Stack unit
(requires (fun h -> live h a /\ live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h0 a /\ live h1 b /\ live h1 a /\ P.modifies (P.loc_buffer (gsub b idx_b len)) h0 h1
/\ Seq.slice (as_seq h1 b) (UInt32.v idx_b) (UInt32.v idx_b + UInt32.v len) ==
Seq.slice (as_seq h0 a) (UInt32.v idx_a) (UInt32.v idx_a + UInt32.v len)
/\ Seq.slice (as_seq h1 b) 0 (UInt32.v idx_b) ==
Seq.slice (as_seq h0 b) 0 (UInt32.v idx_b)
/\ Seq.slice (as_seq h1 b) (UInt32.v idx_b+UInt32.v len) (length b) ==
Seq.slice (as_seq h0 b) (UInt32.v idx_b+UInt32.v len) (length b) )) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pointer.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "FStar.BufferNG.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Pointer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HH"
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"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: FStar.BufferNG.buffer t ->
idx_a: FStar.UInt32.t ->
b: FStar.BufferNG.buffer t {FStar.BufferNG.disjoint a b} ->
idx_b: FStar.UInt32.t ->
len:
FStar.UInt32.t
{ FStar.UInt32.v idx_a + FStar.UInt32.v len <= FStar.BufferNG.length a /\
FStar.UInt32.v idx_b + FStar.UInt32.v len <= FStar.BufferNG.length b }
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.BufferNG.typ",
"FStar.BufferNG.buffer",
"FStar.UInt32.t",
"FStar.BufferNG.disjoint",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.UInt32.v",
"FStar.BufferNG.length",
"Prims.op_Equality",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"Prims.bool",
"Prims._assert",
"Prims.eq2",
"FStar.Seq.Base.seq",
"FStar.Pointer.Base.type_of_typ",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"FStar.BufferNG.as_seq",
"FStar.Pointer.Base.buffer",
"FStar.BufferNG.gsub",
"FStar.UInt32.add",
"FStar.UInt32.sub",
"FStar.Pointer.Base.buffer_length",
"FStar.Pointer.Derived1.buffer_readable_modifies_gsub",
"FStar.Pointer.Base.loc_buffer",
"FStar.Pointer.Base.gsub_buffer",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"FStar.Pointer.Derived2.copy_buffer_contents"
] | [] | false | true | false | false | false | let blit #t a idx_a b idx_b len =
| if len = 0ul
then ()
else
let h0 = HST.get () in
P.copy_buffer_contents a idx_a b idx_b len;
let h1 = HST.get () in
P.buffer_readable_modifies_gsub b idx_b len h0 h1 (P.loc_buffer (P.gsub_buffer b idx_b len));
assert (let g =
(gsub b (UInt32.add idx_b len) (UInt32.sub (P.buffer_length b) (UInt32.add idx_b len)))
in
as_seq h1 g == as_seq h0 g);
assert (as_seq h1 (gsub b idx_b len) == as_seq h0 (gsub a idx_a len));
assert (let g = gsub b 0ul idx_b in
as_seq h1 g == as_seq h0 g) | false |
Vale.AES.GCTR_BE_s.fst | Vale.AES.GCTR_BE_s.inc32 | val inc32 (cb: quad32) (i: int) : quad32 | val inc32 (cb: quad32) (i: int) : quad32 | let inc32 (cb:quad32) (i:int) : quad32 =
Mkfour ((cb.lo0 + i) % pow2_32) cb.lo1 cb.hi2 cb.hi3 | {
"file_name": "vale/specs/crypto/Vale.AES.GCTR_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 54,
"end_line": 22,
"start_col": 0,
"start_line": 21
} | module Vale.AES.GCTR_BE_s
// IMPORTANT: Following NIST's specification, this spec is written assuming a big-endian mapping from bytes to quad32s
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open Vale.AES.AES_BE_s
open FStar.Seq
// The max length of pow2_32 corresponds to the max length of buffers in Low*
// length plain < pow2_32 <= spec max of 2**39 - 256;
let is_gctr_plain (p:seq nat8) : prop0 = length p < pow2_32
type gctr_plain:eqtype = p:seq nat8 { is_gctr_plain p }
type gctr_plain_internal:eqtype = seq quad32 | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.GCTR_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | cb: Vale.Def.Types_s.quad32 -> i: Prims.int -> Vale.Def.Types_s.quad32 | Prims.Tot | [
"total"
] | [] | [
"Vale.Def.Types_s.quad32",
"Prims.int",
"Vale.Def.Words_s.Mkfour",
"Vale.Def.Types_s.nat32",
"Prims.op_Modulus",
"Prims.op_Addition",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Def.Words_s.pow2_32",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3"
] | [] | false | false | false | true | false | let inc32 (cb: quad32) (i: int) : quad32 =
| Mkfour ((cb.lo0 + i) % pow2_32) cb.lo1 cb.hi2 cb.hi3 | false |
Vale.AES.GCTR_BE_s.fst | Vale.AES.GCTR_BE_s.gctr_encrypt_def | val gctr_encrypt_def (icb: quad32) (plain: seq nat8) (alg: algorithm) (key: seq nat32)
: Pure (seq nat8)
(requires is_gctr_plain plain /\ is_aes_key_word alg key)
(ensures fun _ -> True) | val gctr_encrypt_def (icb: quad32) (plain: seq nat8) (alg: algorithm) (key: seq nat32)
: Pure (seq nat8)
(requires is_gctr_plain plain /\ is_aes_key_word alg key)
(ensures fun _ -> True) | let gctr_encrypt_def (icb:quad32) (plain:seq nat8) (alg:algorithm) (key:seq nat32) : Pure (seq nat8)
(requires is_gctr_plain plain /\ is_aes_key_word alg key)
(ensures fun _ -> True)
=
let num_extra = (length plain) % 16 in
if num_extra = 0 then
let plain_quads = be_bytes_to_seq_quad32 plain in
let cipher_quads = gctr_encrypt_recursive icb plain_quads alg key 0 in
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_quads)
else
let full_bytes_len = (length plain) - num_extra in
let full_blocks, final_block = split plain full_bytes_len in
let full_quads = be_bytes_to_seq_quad32 full_blocks in
let final_quad = be_bytes_to_quad32 (pad_to_128_bits final_block) in
let cipher_quads = gctr_encrypt_recursive icb full_quads alg key 0 in
let final_cipher_quad = gctr_encrypt_block icb final_quad alg key (full_bytes_len / 16) in
let cipher_bytes_full = seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_quads) in
let final_cipher_bytes = slice (be_quad32_to_bytes final_cipher_quad) 0 num_extra in
cipher_bytes_full @| final_cipher_bytes | {
"file_name": "vale/specs/crypto/Vale.AES.GCTR_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 43,
"end_line": 68,
"start_col": 0,
"start_line": 45
} | module Vale.AES.GCTR_BE_s
// IMPORTANT: Following NIST's specification, this spec is written assuming a big-endian mapping from bytes to quad32s
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open Vale.AES.AES_BE_s
open FStar.Seq
// The max length of pow2_32 corresponds to the max length of buffers in Low*
// length plain < pow2_32 <= spec max of 2**39 - 256;
let is_gctr_plain (p:seq nat8) : prop0 = length p < pow2_32
type gctr_plain:eqtype = p:seq nat8 { is_gctr_plain p }
type gctr_plain_internal:eqtype = seq quad32
let inc32 (cb:quad32) (i:int) : quad32 =
Mkfour ((cb.lo0 + i) % pow2_32) cb.lo1 cb.hi2 cb.hi3
let gctr_encrypt_block (icb:quad32) (plain:quad32) (alg:algorithm) (key:seq nat32) (i:int) : Pure quad32
(requires is_aes_key_word alg key)
(ensures fun _ -> True)
=
quad32_xor plain (aes_encrypt_word alg key (inc32 icb i))
let rec gctr_encrypt_recursive (icb:quad32) (plain:gctr_plain_internal)
(alg:algorithm) (key:aes_key_word alg) (i:int) : Tot (seq quad32) (decreases %[length plain]) =
if length plain = 0 then empty
else
cons (gctr_encrypt_block icb (head plain) alg key i) (gctr_encrypt_recursive icb (tail plain) alg key (i + 1))
let pad_to_128_bits (p:seq nat8) : Pure (seq nat8)
(requires True)
(ensures fun q -> length q % 16 == 0 /\ length q <= length p + 15)
=
let num_extra_bytes = length p % 16 in
if num_extra_bytes = 0 then p
else p @| (create (16 - num_extra_bytes) 0) | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.GCTR_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 |
icb: Vale.Def.Types_s.quad32 ->
plain: FStar.Seq.Base.seq Vale.Def.Types_s.nat8 ->
alg: Vale.AES.AES_common_s.algorithm ->
key: FStar.Seq.Base.seq Vale.Def.Types_s.nat32
-> Prims.Pure (FStar.Seq.Base.seq Vale.Def.Types_s.nat8) | Prims.Pure | [] | [] | [
"Vale.Def.Types_s.quad32",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat8",
"Vale.AES.AES_common_s.algorithm",
"Vale.Def.Types_s.nat32",
"Prims.op_Equality",
"Prims.int",
"Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE",
"Vale.Def.Words.Seq_s.seq_four_to_seq_BE",
"Vale.AES.GCTR_BE_s.gctr_encrypt_recursive",
"Vale.Def.Types_s.be_bytes_to_seq_quad32",
"Prims.bool",
"FStar.Seq.Base.op_At_Bar",
"Vale.Def.Words_s.nat8",
"FStar.Seq.Base.slice",
"Vale.Arch.Types.be_quad32_to_bytes",
"Vale.AES.GCTR_BE_s.gctr_encrypt_block",
"Prims.op_Division",
"Vale.Def.Types_s.be_bytes_to_quad32",
"Vale.AES.GCTR_BE_s.pad_to_128_bits",
"FStar.Pervasives.Native.tuple2",
"FStar.Seq.Properties.split",
"Prims.op_Subtraction",
"FStar.Seq.Base.length",
"Prims.op_Modulus",
"Prims.l_and",
"Vale.AES.GCTR_BE_s.is_gctr_plain",
"Vale.AES.AES_BE_s.is_aes_key_word",
"Prims.l_True"
] | [] | false | false | false | false | false | let gctr_encrypt_def (icb: quad32) (plain: seq nat8) (alg: algorithm) (key: seq nat32)
: Pure (seq nat8)
(requires is_gctr_plain plain /\ is_aes_key_word alg key)
(ensures fun _ -> True) =
| let num_extra = (length plain) % 16 in
if num_extra = 0
then
let plain_quads = be_bytes_to_seq_quad32 plain in
let cipher_quads = gctr_encrypt_recursive icb plain_quads alg key 0 in
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_quads)
else
let full_bytes_len = (length plain) - num_extra in
let full_blocks, final_block = split plain full_bytes_len in
let full_quads = be_bytes_to_seq_quad32 full_blocks in
let final_quad = be_bytes_to_quad32 (pad_to_128_bits final_block) in
let cipher_quads = gctr_encrypt_recursive icb full_quads alg key 0 in
let final_cipher_quad = gctr_encrypt_block icb final_quad alg key (full_bytes_len / 16) in
let cipher_bytes_full = seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_quads) in
let final_cipher_bytes = slice (be_quad32_to_bytes final_cipher_quad) 0 num_extra in
cipher_bytes_full @| final_cipher_bytes | false |
FStar.Math.Euclid.fsti | FStar.Math.Euclid.divides | val divides (a b: int) : prop | val divides (a b: int) : prop | let divides (a b:int) : prop = exists q. b = q * a | {
"file_name": "ulib/FStar.Math.Euclid.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 50,
"end_line": 12,
"start_col": 0,
"start_line": 12
} | module FStar.Math.Euclid
open FStar.Mul
///
/// Divides relation
///
/// It is reflexive, transitive, and antisymmetric up to sign.
/// When a <> 0, a `divides` b iff a % b = 0 (this is proved below)
/// | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Math.Euclid.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Prims.int -> b: Prims.int -> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Prims.l_Exists",
"Prims.b2t",
"Prims.op_Equality",
"FStar.Mul.op_Star",
"Prims.prop"
] | [] | false | false | false | true | true | let divides (a b: int) : prop =
| exists q. b = q * a | false |
FStar.Math.Euclid.fsti | FStar.Math.Euclid.is_gcd | val is_gcd (a b d: int) : prop | val is_gcd (a b d: int) : prop | let is_gcd (a b d:int) : prop =
d `divides` a /\
d `divides` b /\
(forall x. (x `divides` a /\ x `divides` b) ==> x `divides` d) | {
"file_name": "ulib/FStar.Math.Euclid.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 64,
"end_line": 58,
"start_col": 0,
"start_line": 55
} | module FStar.Math.Euclid
open FStar.Mul
///
/// Divides relation
///
/// It is reflexive, transitive, and antisymmetric up to sign.
/// When a <> 0, a `divides` b iff a % b = 0 (this is proved below)
///
let divides (a b:int) : prop = exists q. b = q * a
val divides_reflexive (a:int) : Lemma (a `divides` a) [SMTPat (a `divides` a)]
val divides_transitive (a b c:int) : Lemma
(requires a `divides` b /\ b `divides` c)
(ensures a `divides` c)
val divide_antisym (a b:int) : Lemma
(requires a `divides` b /\ b `divides` a)
(ensures a = b \/ a = -b)
val divides_0 (a:int) : Lemma (a `divides` 0)
val divides_1 (a:int) : Lemma (requires a `divides` 1) (ensures a = 1 \/ a = -1)
val divides_minus (a b:int) : Lemma
(requires a `divides` b)
(ensures a `divides` (-b))
val divides_opp (a b:int) : Lemma
(requires a `divides` b)
(ensures (-a) `divides` b)
val divides_plus (a b d:int) : Lemma
(requires d `divides` a /\ d `divides` b)
(ensures d `divides` (a + b))
val divides_sub (a b d:int) : Lemma
(requires d `divides` a /\ d `divides` b)
(ensures d `divides` (a - b))
val divides_mult_right (a b d:int) : Lemma
(requires d `divides` b)
(ensures d `divides` (a * b))
///
/// Greatest Common Divisor (GCD) relation
///
/// We deviate from the standard definition in that we allow the divisor to
/// be negative. Thus, the GCD of two integers is unique up to sign.
/// | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Math.Euclid.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Prims.int -> b: Prims.int -> d: Prims.int -> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Prims.l_and",
"FStar.Math.Euclid.divides",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.prop"
] | [] | false | false | false | true | true | let is_gcd (a b d: int) : prop =
| d `divides` a /\ d `divides` b /\ (forall x. (x `divides` a /\ x `divides` b) ==> x `divides` d) | false |
Vale.AES.GCTR_BE_s.fst | Vale.AES.GCTR_BE_s.pad_to_128_bits | val pad_to_128_bits (p: seq nat8)
: Pure (seq nat8)
(requires True)
(ensures fun q -> length q % 16 == 0 /\ length q <= length p + 15) | val pad_to_128_bits (p: seq nat8)
: Pure (seq nat8)
(requires True)
(ensures fun q -> length q % 16 == 0 /\ length q <= length p + 15) | let pad_to_128_bits (p:seq nat8) : Pure (seq nat8)
(requires True)
(ensures fun q -> length q % 16 == 0 /\ length q <= length p + 15)
=
let num_extra_bytes = length p % 16 in
if num_extra_bytes = 0 then p
else p @| (create (16 - num_extra_bytes) 0) | {
"file_name": "vale/specs/crypto/Vale.AES.GCTR_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 43,
"start_col": 0,
"start_line": 37
} | module Vale.AES.GCTR_BE_s
// IMPORTANT: Following NIST's specification, this spec is written assuming a big-endian mapping from bytes to quad32s
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open Vale.AES.AES_BE_s
open FStar.Seq
// The max length of pow2_32 corresponds to the max length of buffers in Low*
// length plain < pow2_32 <= spec max of 2**39 - 256;
let is_gctr_plain (p:seq nat8) : prop0 = length p < pow2_32
type gctr_plain:eqtype = p:seq nat8 { is_gctr_plain p }
type gctr_plain_internal:eqtype = seq quad32
let inc32 (cb:quad32) (i:int) : quad32 =
Mkfour ((cb.lo0 + i) % pow2_32) cb.lo1 cb.hi2 cb.hi3
let gctr_encrypt_block (icb:quad32) (plain:quad32) (alg:algorithm) (key:seq nat32) (i:int) : Pure quad32
(requires is_aes_key_word alg key)
(ensures fun _ -> True)
=
quad32_xor plain (aes_encrypt_word alg key (inc32 icb i))
let rec gctr_encrypt_recursive (icb:quad32) (plain:gctr_plain_internal)
(alg:algorithm) (key:aes_key_word alg) (i:int) : Tot (seq quad32) (decreases %[length plain]) =
if length plain = 0 then empty
else
cons (gctr_encrypt_block icb (head plain) alg key i) (gctr_encrypt_recursive icb (tail plain) alg key (i + 1)) | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.GCTR_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: FStar.Seq.Base.seq Vale.Def.Types_s.nat8 -> Prims.Pure (FStar.Seq.Base.seq Vale.Def.Types_s.nat8) | Prims.Pure | [] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat8",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"FStar.Seq.Base.op_At_Bar",
"FStar.Seq.Base.create",
"Prims.op_Subtraction",
"Prims.op_Modulus",
"FStar.Seq.Base.length",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition"
] | [] | false | false | false | false | false | let pad_to_128_bits (p: seq nat8)
: Pure (seq nat8)
(requires True)
(ensures fun q -> length q % 16 == 0 /\ length q <= length p + 15) =
| let num_extra_bytes = length p % 16 in
if num_extra_bytes = 0 then p else p @| (create (16 - num_extra_bytes) 0) | false |
FStar.Math.Euclid.fsti | FStar.Math.Euclid.is_prime | val is_prime : p: Prims.int -> Prims.logical | let is_prime (p:int) =
1 < p /\
(forall (d:int).{:pattern (d `divides` p)}
(d `divides` p ==> (d = 1 \/ d = -1 \/ d = p \/ d = -p))) | {
"file_name": "ulib/FStar.Math.Euclid.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 62,
"end_line": 108,
"start_col": 0,
"start_line": 105
} | module FStar.Math.Euclid
open FStar.Mul
///
/// Divides relation
///
/// It is reflexive, transitive, and antisymmetric up to sign.
/// When a <> 0, a `divides` b iff a % b = 0 (this is proved below)
///
let divides (a b:int) : prop = exists q. b = q * a
val divides_reflexive (a:int) : Lemma (a `divides` a) [SMTPat (a `divides` a)]
val divides_transitive (a b c:int) : Lemma
(requires a `divides` b /\ b `divides` c)
(ensures a `divides` c)
val divide_antisym (a b:int) : Lemma
(requires a `divides` b /\ b `divides` a)
(ensures a = b \/ a = -b)
val divides_0 (a:int) : Lemma (a `divides` 0)
val divides_1 (a:int) : Lemma (requires a `divides` 1) (ensures a = 1 \/ a = -1)
val divides_minus (a b:int) : Lemma
(requires a `divides` b)
(ensures a `divides` (-b))
val divides_opp (a b:int) : Lemma
(requires a `divides` b)
(ensures (-a) `divides` b)
val divides_plus (a b d:int) : Lemma
(requires d `divides` a /\ d `divides` b)
(ensures d `divides` (a + b))
val divides_sub (a b d:int) : Lemma
(requires d `divides` a /\ d `divides` b)
(ensures d `divides` (a - b))
val divides_mult_right (a b d:int) : Lemma
(requires d `divides` b)
(ensures d `divides` (a * b))
///
/// Greatest Common Divisor (GCD) relation
///
/// We deviate from the standard definition in that we allow the divisor to
/// be negative. Thus, the GCD of two integers is unique up to sign.
///
let is_gcd (a b d:int) : prop =
d `divides` a /\
d `divides` b /\
(forall x. (x `divides` a /\ x `divides` b) ==> x `divides` d)
val mod_divides (a:int) (b:nonzero) : Lemma (requires a % b = 0) (ensures b `divides` a)
val divides_mod (a:int) (b:nonzero) : Lemma (requires b `divides` a) (ensures a % b = 0)
val is_gcd_unique (a b c d:int) : Lemma
(requires is_gcd a b c /\ is_gcd a b d)
(ensures c = d \/ c = -d)
val is_gcd_reflexive (a:int) : Lemma (is_gcd a a a)
val is_gcd_symmetric (a b d:int) : Lemma
(requires is_gcd a b d)
(ensures is_gcd b a d)
val is_gcd_0 (a:int) : Lemma (is_gcd a 0 a)
val is_gcd_1 (a:int) : Lemma (is_gcd a 1 1)
val is_gcd_minus (a b d:int) : Lemma
(requires is_gcd a (-b) d)
(ensures is_gcd b a d)
val is_gcd_opp (a b d:int) : Lemma
(requires is_gcd a b d)
(ensures is_gcd b a (-d))
val is_gcd_plus (a b q d:int) : Lemma
(requires is_gcd a b d)
(ensures is_gcd a (b + q * a) d)
///
/// Extended Euclidean algorithm
///
/// Computes the GCD of two integers (a, b) together with Bézout coefficients
/// (r, s) satisfying r a + s b = gcd(a, b)
///
val euclid_gcd (a b:int) : Pure (int & int & int)
(requires True)
(ensures fun (r, s, d) -> r * a + s * b = d /\ is_gcd a b d)
///
/// A definition of primality based on the divides relation
/// | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Math.Euclid.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Prims.int -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.l_Forall",
"Prims.l_imp",
"FStar.Math.Euclid.divides",
"Prims.l_or",
"Prims.op_Equality",
"Prims.op_Minus",
"Prims.logical"
] | [] | false | false | false | true | true | let is_prime (p: int) =
| 1 < p /\
(forall (d: int). {:pattern (d `divides` p)}
(d `divides` p ==> (d = 1 \/ d = - 1 \/ d = p \/ d = - p))) | false |
|
Hacl.Spec.K256.ECSM.Lemmas.fst | Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul | val aff_point_mul : a: Prims.nat -> p: Spec.K256.PointOps.aff_point -> Spec.K256.PointOps.aff_point | let aff_point_mul = S.aff_point_mul | {
"file_name": "code/k256/Hacl.Spec.K256.ECSM.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 15,
"start_col": 0,
"start_line": 15
} | module Hacl.Spec.K256.ECSM.Lemmas
open FStar.Mul
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module S = Spec.K256
module LS = Spec.K256.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0" | {
"checked_file": "/",
"dependencies": [
"Spec.K256.Lemmas.fsti.checked",
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.ECSM.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256.Lemmas",
"short_module": "LS"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.ECSM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.ECSM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Prims.nat -> p: Spec.K256.PointOps.aff_point -> Spec.K256.PointOps.aff_point | Prims.Tot | [
"total"
] | [] | [
"Spec.K256.aff_point_mul"
] | [] | false | false | false | true | false | let aff_point_mul =
| S.aff_point_mul | false |
|
LowParse.Spec.Endianness.Instances.fst | LowParse.Spec.Endianness.Instances.uint64 | val uint64:uinttype U64.t 8 | val uint64:uinttype U64.t 8 | let uint64 : uinttype U64.t 8 =
UIntType
(fun x -> U64.v x)
(fun x -> FStar.Int.Cast.uint64_to_uint8 x)
(fun x -> FStar.Int.Cast.uint8_to_uint64 x)
0uL
(fun _ _ -> ())
(fun x y -> x `U64.add` y)
(fun x -> x `U64.mul` 256uL)
(fun x -> x `U64.div` 256uL) | {
"file_name": "src/lowparse/LowParse.Spec.Endianness.Instances.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 32,
"end_line": 62,
"start_col": 0,
"start_line": 53
} | module LowParse.Spec.Endianness.Instances
include LowParse.Spec.Endianness
module U8 = FStar.UInt8
inline_for_extraction
noextract
let uint8 : uinttype U8.t 1 =
UIntType
(fun x -> U8.v x)
(fun x -> x)
(fun x -> x)
0uy
(fun _ _ -> ())
(fun x y -> x `U8.add` y)
(fun x -> 0uy)
(fun x -> 0uy)
module U16 = FStar.UInt16
inline_for_extraction
noextract
let uint16 : uinttype U16.t 2 =
UIntType
(fun x -> U16.v x)
(fun x -> FStar.Int.Cast.uint16_to_uint8 x)
(fun x -> FStar.Int.Cast.uint8_to_uint16 x)
0us
(fun _ _ -> ())
(fun x y -> x `U16.add` y)
(fun x -> x `U16.mul` 256us)
(fun x -> x `U16.div` 256us)
module U32 = FStar.UInt32
inline_for_extraction
noextract
let uint32 : uinttype U32.t 4 =
UIntType
(fun x -> U32.v x)
(fun x -> FStar.Int.Cast.uint32_to_uint8 x)
(fun x -> FStar.Int.Cast.uint8_to_uint32 x)
0ul
(fun _ _ -> ())
(fun x y -> x `U32.add` y)
(fun x -> x `U32.mul` 256ul)
(fun x -> x `U32.div` 256ul)
module U64 = FStar.UInt64
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Endianness.fst.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Endianness.Instances.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | LowParse.Spec.Endianness.uinttype FStar.UInt64.t 8 | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Endianness.UIntType",
"FStar.UInt64.t",
"FStar.UInt64.v",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"FStar.Mul.op_Star",
"FStar.Int.Cast.uint64_to_uint8",
"FStar.UInt8.t",
"Prims.eq2",
"Prims.int",
"FStar.UInt8.v",
"Prims.op_Modulus",
"FStar.Int.Cast.uint8_to_uint64",
"Prims.l_or",
"Prims.l_and",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt8.n",
"FStar.UInt64.__uint_to_t",
"Prims.unit",
"FStar.UInt64.add",
"FStar.UInt64.mul",
"FStar.UInt64.div"
] | [] | false | false | false | false | false | let uint64:uinttype U64.t 8 =
| UIntType (fun x -> U64.v x)
(fun x -> FStar.Int.Cast.uint64_to_uint8 x)
(fun x -> FStar.Int.Cast.uint8_to_uint64 x)
0uL
(fun _ _ -> ())
(fun x y -> x `U64.add` y)
(fun x -> x `U64.mul` 256uL)
(fun x -> x `U64.div` 256uL) | false |
Hacl.Spec.K256.ECSM.Lemmas.fst | Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul_neg | val aff_point_mul_neg (a: int) (p: S.aff_point) : S.aff_point | val aff_point_mul_neg (a: int) (p: S.aff_point) : S.aff_point | let aff_point_mul_neg (a:int) (p:S.aff_point) : S.aff_point =
LE.pow_neg S.mk_k256_abelian_group p a | {
"file_name": "code/k256/Hacl.Spec.K256.ECSM.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 40,
"end_line": 19,
"start_col": 0,
"start_line": 18
} | module Hacl.Spec.K256.ECSM.Lemmas
open FStar.Mul
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module S = Spec.K256
module LS = Spec.K256.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
// [a]P in affine coordinates for a >= 0
let aff_point_mul = S.aff_point_mul | {
"checked_file": "/",
"dependencies": [
"Spec.K256.Lemmas.fsti.checked",
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.ECSM.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256.Lemmas",
"short_module": "LS"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.ECSM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.ECSM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Prims.int -> p: Spec.K256.PointOps.aff_point -> Spec.K256.PointOps.aff_point | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Spec.K256.PointOps.aff_point",
"Lib.Exponentiation.Definition.pow_neg",
"Spec.K256.mk_k256_abelian_group"
] | [] | false | false | false | true | false | let aff_point_mul_neg (a: int) (p: S.aff_point) : S.aff_point =
| LE.pow_neg S.mk_k256_abelian_group p a | false |
LowParse.Spec.Endianness.Instances.fst | LowParse.Spec.Endianness.Instances.uint32 | val uint32:uinttype U32.t 4 | val uint32:uinttype U32.t 4 | let uint32 : uinttype U32.t 4 =
UIntType
(fun x -> U32.v x)
(fun x -> FStar.Int.Cast.uint32_to_uint8 x)
(fun x -> FStar.Int.Cast.uint8_to_uint32 x)
0ul
(fun _ _ -> ())
(fun x y -> x `U32.add` y)
(fun x -> x `U32.mul` 256ul)
(fun x -> x `U32.div` 256ul) | {
"file_name": "src/lowparse/LowParse.Spec.Endianness.Instances.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 32,
"end_line": 47,
"start_col": 0,
"start_line": 38
} | module LowParse.Spec.Endianness.Instances
include LowParse.Spec.Endianness
module U8 = FStar.UInt8
inline_for_extraction
noextract
let uint8 : uinttype U8.t 1 =
UIntType
(fun x -> U8.v x)
(fun x -> x)
(fun x -> x)
0uy
(fun _ _ -> ())
(fun x y -> x `U8.add` y)
(fun x -> 0uy)
(fun x -> 0uy)
module U16 = FStar.UInt16
inline_for_extraction
noextract
let uint16 : uinttype U16.t 2 =
UIntType
(fun x -> U16.v x)
(fun x -> FStar.Int.Cast.uint16_to_uint8 x)
(fun x -> FStar.Int.Cast.uint8_to_uint16 x)
0us
(fun _ _ -> ())
(fun x y -> x `U16.add` y)
(fun x -> x `U16.mul` 256us)
(fun x -> x `U16.div` 256us)
module U32 = FStar.UInt32
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Endianness.fst.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Endianness.Instances.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | LowParse.Spec.Endianness.uinttype FStar.UInt32.t 4 | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Endianness.UIntType",
"FStar.UInt32.t",
"FStar.UInt32.v",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"FStar.Mul.op_Star",
"FStar.Int.Cast.uint32_to_uint8",
"FStar.UInt8.t",
"Prims.eq2",
"Prims.int",
"FStar.UInt8.v",
"Prims.op_Modulus",
"FStar.Int.Cast.uint8_to_uint32",
"Prims.l_or",
"Prims.l_and",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt8.n",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"FStar.UInt32.add",
"FStar.UInt32.mul",
"FStar.UInt32.div"
] | [] | false | false | false | false | false | let uint32:uinttype U32.t 4 =
| UIntType (fun x -> U32.v x)
(fun x -> FStar.Int.Cast.uint32_to_uint8 x)
(fun x -> FStar.Int.Cast.uint8_to_uint32 x)
0ul
(fun _ _ -> ())
(fun x y -> x `U32.add` y)
(fun x -> x `U32.mul` 256ul)
(fun x -> x `U32.div` 256ul) | false |
LowParse.Spec.Endianness.Instances.fst | LowParse.Spec.Endianness.Instances.uint16 | val uint16:uinttype U16.t 2 | val uint16:uinttype U16.t 2 | let uint16 : uinttype U16.t 2 =
UIntType
(fun x -> U16.v x)
(fun x -> FStar.Int.Cast.uint16_to_uint8 x)
(fun x -> FStar.Int.Cast.uint8_to_uint16 x)
0us
(fun _ _ -> ())
(fun x y -> x `U16.add` y)
(fun x -> x `U16.mul` 256us)
(fun x -> x `U16.div` 256us) | {
"file_name": "src/lowparse/LowParse.Spec.Endianness.Instances.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 32,
"end_line": 32,
"start_col": 0,
"start_line": 23
} | module LowParse.Spec.Endianness.Instances
include LowParse.Spec.Endianness
module U8 = FStar.UInt8
inline_for_extraction
noextract
let uint8 : uinttype U8.t 1 =
UIntType
(fun x -> U8.v x)
(fun x -> x)
(fun x -> x)
0uy
(fun _ _ -> ())
(fun x y -> x `U8.add` y)
(fun x -> 0uy)
(fun x -> 0uy)
module U16 = FStar.UInt16
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Endianness.fst.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Endianness.Instances.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | LowParse.Spec.Endianness.uinttype FStar.UInt16.t 2 | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Endianness.UIntType",
"FStar.UInt16.t",
"FStar.UInt16.v",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"FStar.Mul.op_Star",
"FStar.Int.Cast.uint16_to_uint8",
"FStar.UInt8.t",
"Prims.eq2",
"Prims.int",
"FStar.UInt8.v",
"Prims.op_Modulus",
"FStar.Int.Cast.uint8_to_uint16",
"Prims.l_or",
"Prims.l_and",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt8.n",
"FStar.UInt16.__uint_to_t",
"Prims.unit",
"FStar.UInt16.add",
"FStar.UInt16.mul",
"FStar.UInt16.div"
] | [] | false | false | false | false | false | let uint16:uinttype U16.t 2 =
| UIntType (fun x -> U16.v x)
(fun x -> FStar.Int.Cast.uint16_to_uint8 x)
(fun x -> FStar.Int.Cast.uint8_to_uint16 x)
0us
(fun _ _ -> ())
(fun x y -> x `U16.add` y)
(fun x -> x `U16.mul` 256us)
(fun x -> x `U16.div` 256us) | false |
LowParse.Spec.Endianness.Instances.fst | LowParse.Spec.Endianness.Instances.uint8 | val uint8:uinttype U8.t 1 | val uint8:uinttype U8.t 1 | let uint8 : uinttype U8.t 1 =
UIntType
(fun x -> U8.v x)
(fun x -> x)
(fun x -> x)
0uy
(fun _ _ -> ())
(fun x y -> x `U8.add` y)
(fun x -> 0uy)
(fun x -> 0uy) | {
"file_name": "src/lowparse/LowParse.Spec.Endianness.Instances.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 18,
"end_line": 17,
"start_col": 0,
"start_line": 8
} | module LowParse.Spec.Endianness.Instances
include LowParse.Spec.Endianness
module U8 = FStar.UInt8
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Endianness.fst.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Endianness.Instances.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | LowParse.Spec.Endianness.uinttype FStar.UInt8.t 1 | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Endianness.UIntType",
"FStar.UInt8.t",
"FStar.UInt8.v",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"FStar.Mul.op_Star",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"Prims.l_or",
"Prims.l_and",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt8.n",
"FStar.UInt8.__uint_to_t",
"Prims.unit",
"FStar.UInt8.add"
] | [] | false | false | false | false | false | let uint8:uinttype U8.t 1 =
| UIntType (fun x -> U8.v x)
(fun x -> x)
(fun x -> x)
0uy
(fun _ _ -> ())
(fun x y -> x `U8.add` y)
(fun x -> 0uy)
(fun x -> 0uy) | false |
Hacl.Spec.K256.ECSM.Lemmas.fst | Hacl.Spec.K256.ECSM.Lemmas.lemma_aff_point_mul_neg_add | val lemma_aff_point_mul_neg_add (a b:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg (a + b) p ==
S.aff_point_add (aff_point_mul_neg a p) (aff_point_mul_neg b p)) | val lemma_aff_point_mul_neg_add (a b:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg (a + b) p ==
S.aff_point_add (aff_point_mul_neg a p) (aff_point_mul_neg b p)) | let lemma_aff_point_mul_neg_add a b p =
LE.lemma_pow_neg_add S.mk_k256_abelian_group p a b | {
"file_name": "code/k256/Hacl.Spec.K256.ECSM.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 52,
"end_line": 36,
"start_col": 0,
"start_line": 35
} | module Hacl.Spec.K256.ECSM.Lemmas
open FStar.Mul
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module S = Spec.K256
module LS = Spec.K256.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
// [a]P in affine coordinates for a >= 0
let aff_point_mul = S.aff_point_mul
// [a]P in affine coordinates for any a
let aff_point_mul_neg (a:int) (p:S.aff_point) : S.aff_point =
LE.pow_neg S.mk_k256_abelian_group p a
assume
val lemma_order_of_curve_group (p:S.aff_point) :
Lemma (aff_point_mul S.q p == S.aff_point_at_inf)
(**
Properties for Elliptic Curve Scalar Multiplication in affine coordinates
*)
// [a + b]P = [a]P + [b]P
val lemma_aff_point_mul_neg_add (a b:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg (a + b) p ==
S.aff_point_add (aff_point_mul_neg a p) (aff_point_mul_neg b p)) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.Lemmas.fsti.checked",
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.ECSM.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256.Lemmas",
"short_module": "LS"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.ECSM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.ECSM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Prims.int -> b: Prims.int -> p: Spec.K256.PointOps.aff_point
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul_neg (a + b) p ==
Spec.K256.PointOps.aff_point_add (Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul_neg a p)
(Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul_neg b p)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.int",
"Spec.K256.PointOps.aff_point",
"Lib.Exponentiation.Definition.lemma_pow_neg_add",
"Spec.K256.mk_k256_abelian_group",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_aff_point_mul_neg_add a b p =
| LE.lemma_pow_neg_add S.mk_k256_abelian_group p a b | false |
LowParse.Spec.Endianness.Instances.fst | LowParse.Spec.Endianness.Instances.bounded_integer | val bounded_integer (i: integer_size) : Tot (uinttype (bounded_integer i) i) | val bounded_integer (i: integer_size) : Tot (uinttype (bounded_integer i) i) | let bounded_integer
(i: integer_size)
: Tot (uinttype (bounded_integer i) i)
= UIntType
(fun (x: bounded_integer i) -> bounded_integer_prop_equiv i x; U32.v x)
(fun x -> FStar.Int.Cast.uint32_to_uint8 x)
(fun x -> FStar.Int.Cast.uint8_to_uint32 x)
0ul
(fun _ _ -> ())
(fun x y -> x `U32.add` y)
(fun x -> x `U32.mul` 256ul)
(fun x -> x `U32.div` 256ul) | {
"file_name": "src/lowparse/LowParse.Spec.Endianness.Instances.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 32,
"end_line": 79,
"start_col": 0,
"start_line": 68
} | module LowParse.Spec.Endianness.Instances
include LowParse.Spec.Endianness
module U8 = FStar.UInt8
inline_for_extraction
noextract
let uint8 : uinttype U8.t 1 =
UIntType
(fun x -> U8.v x)
(fun x -> x)
(fun x -> x)
0uy
(fun _ _ -> ())
(fun x y -> x `U8.add` y)
(fun x -> 0uy)
(fun x -> 0uy)
module U16 = FStar.UInt16
inline_for_extraction
noextract
let uint16 : uinttype U16.t 2 =
UIntType
(fun x -> U16.v x)
(fun x -> FStar.Int.Cast.uint16_to_uint8 x)
(fun x -> FStar.Int.Cast.uint8_to_uint16 x)
0us
(fun _ _ -> ())
(fun x y -> x `U16.add` y)
(fun x -> x `U16.mul` 256us)
(fun x -> x `U16.div` 256us)
module U32 = FStar.UInt32
inline_for_extraction
noextract
let uint32 : uinttype U32.t 4 =
UIntType
(fun x -> U32.v x)
(fun x -> FStar.Int.Cast.uint32_to_uint8 x)
(fun x -> FStar.Int.Cast.uint8_to_uint32 x)
0ul
(fun _ _ -> ())
(fun x y -> x `U32.add` y)
(fun x -> x `U32.mul` 256ul)
(fun x -> x `U32.div` 256ul)
module U64 = FStar.UInt64
inline_for_extraction
noextract
let uint64 : uinttype U64.t 8 =
UIntType
(fun x -> U64.v x)
(fun x -> FStar.Int.Cast.uint64_to_uint8 x)
(fun x -> FStar.Int.Cast.uint8_to_uint64 x)
0uL
(fun _ _ -> ())
(fun x y -> x `U64.add` y)
(fun x -> x `U64.mul` 256uL)
(fun x -> x `U64.div` 256uL)
open LowParse.Spec.BoundedInt
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Endianness.fst.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.Endianness.Instances.fst"
} | [
{
"abbrev": false,
"full_module": "LowParse.Spec.BoundedInt",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: LowParse.Spec.BoundedInt.integer_size
-> LowParse.Spec.Endianness.uinttype (LowParse.Spec.BoundedInt.bounded_integer i) i | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.Endianness.UIntType",
"LowParse.Spec.BoundedInt.bounded_integer",
"FStar.UInt32.v",
"Prims.unit",
"LowParse.Spec.BoundedInt.bounded_integer_prop_equiv",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"FStar.Mul.op_Star",
"FStar.Int.Cast.uint32_to_uint8",
"FStar.UInt8.t",
"Prims.eq2",
"Prims.int",
"FStar.UInt8.v",
"Prims.op_Modulus",
"FStar.Int.Cast.uint8_to_uint32",
"Prims.l_or",
"Prims.l_and",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt8.n",
"FStar.UInt32.__uint_to_t",
"FStar.UInt32.add",
"FStar.UInt32.mul",
"FStar.UInt32.div",
"LowParse.Spec.Endianness.uinttype"
] | [] | false | false | false | false | false | let bounded_integer (i: integer_size) : Tot (uinttype (bounded_integer i) i) =
| UIntType
(fun (x: bounded_integer i) ->
bounded_integer_prop_equiv i x;
U32.v x)
(fun x -> FStar.Int.Cast.uint32_to_uint8 x)
(fun x -> FStar.Int.Cast.uint8_to_uint32 x)
0ul
(fun _ _ -> ())
(fun x y -> x `U32.add` y)
(fun x -> x `U32.mul` 256ul)
(fun x -> x `U32.div` 256ul) | false |
Hacl.Impl.K256.GLV.Constants.fst | Hacl.Impl.K256.GLV.Constants.make_minus_b1 | val make_minus_b1: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_b1) | val make_minus_b1: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_b1) | let make_minus_b1 f =
[@inline_let]
let x =
(u64 0x6f547fa90abfe4c3,
u64 0xe4437ed6010e8828,
u64 0x0,
u64 0x0) in
assert_norm (SG.minus_b1 == qas_nat4 x);
make_u64_4 f x | {
"file_name": "code/k256/Hacl.Impl.K256.GLV.Constants.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 16,
"end_line": 76,
"start_col": 0,
"start_line": 67
} | module Hacl.Impl.K256.GLV.Constants
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module S = Spec.K256
module SG = Hacl.Spec.K256.GLV
module SGL = Hacl.Spec.K256.GLV.Lemmas
open Hacl.K256.Field
open Hacl.K256.Scalar
open Hacl.Impl.K256.Point
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val make_minus_lambda: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_lambda)
let make_minus_lambda f =
[@inline_let]
let x =
(u64 0xe0cfc810b51283cf,
u64 0xa880b9fc8ec739c2,
u64 0x5ad9e3fd77ed9ba4,
u64 0xac9c52b33fa3cf1f) in
assert_norm (SG.minus_lambda == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_beta: f:felem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
as_nat h1 f == SG.beta /\ inv_fully_reduced h1 f)
let make_beta f =
[@inline_let]
let x =
(u64 0x96c28719501ee,
u64 0x7512f58995c13,
u64 0xc3434e99cf049,
u64 0x7106e64479ea,
u64 0x7ae96a2b657c) in
assert_norm (0x96c28719501ee <= max52);
assert_norm (0x7ae96a2b657c <= max48);
assert_norm (SG.beta == as_nat5 x);
make_u52_5 f x
inline_for_extraction noextract
val make_minus_b1: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_b1) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.GLV.Lemmas.fst.checked",
"Hacl.Spec.K256.GLV.fst.checked",
"Hacl.K256.Scalar.fsti.checked",
"Hacl.K256.Field.fsti.checked",
"Hacl.Impl.K256.Point.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": true,
"source_file": "Hacl.Impl.K256.GLV.Constants.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV.Lemmas",
"short_module": "SGL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV",
"short_module": "SG"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV",
"short_module": "SG"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Hacl.K256.Scalar.qelem -> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.K256.Scalar.qelem",
"Hacl.K256.Scalar.make_u64_4",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"Hacl.Spec.K256.GLV.minus_b1",
"Hacl.K256.Scalar.qas_nat4",
"FStar.Pervasives.Native.tuple4",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"FStar.Pervasives.Native.Mktuple4",
"Lib.IntTypes.uint64",
"Lib.IntTypes.u64"
] | [] | false | true | false | false | false | let make_minus_b1 f =
| [@@ inline_let ]let x = (u64 0x6f547fa90abfe4c3, u64 0xe4437ed6010e8828, u64 0x0, u64 0x0) in
assert_norm (SG.minus_b1 == qas_nat4 x);
make_u64_4 f x | false |
Hacl.Spec.K256.ECSM.Lemmas.fst | Hacl.Spec.K256.ECSM.Lemmas.lemma_aff_point_mul_neg_mul_add | val lemma_aff_point_mul_neg_mul_add (a b c:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg (a * b + c) p ==
S.aff_point_add (aff_point_mul_neg b (aff_point_mul_neg a p)) (aff_point_mul_neg c p)) | val lemma_aff_point_mul_neg_mul_add (a b c:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg (a * b + c) p ==
S.aff_point_add (aff_point_mul_neg b (aff_point_mul_neg a p)) (aff_point_mul_neg c p)) | let lemma_aff_point_mul_neg_mul_add a b c p =
lemma_aff_point_mul_neg_add (a * b) c p;
lemma_aff_point_mul_neg_mul a b p | {
"file_name": "code/k256/Hacl.Spec.K256.ECSM.Lemmas.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": 52
} | module Hacl.Spec.K256.ECSM.Lemmas
open FStar.Mul
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module S = Spec.K256
module LS = Spec.K256.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
// [a]P in affine coordinates for a >= 0
let aff_point_mul = S.aff_point_mul
// [a]P in affine coordinates for any a
let aff_point_mul_neg (a:int) (p:S.aff_point) : S.aff_point =
LE.pow_neg S.mk_k256_abelian_group p a
assume
val lemma_order_of_curve_group (p:S.aff_point) :
Lemma (aff_point_mul S.q p == S.aff_point_at_inf)
(**
Properties for Elliptic Curve Scalar Multiplication in affine coordinates
*)
// [a + b]P = [a]P + [b]P
val lemma_aff_point_mul_neg_add (a b:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg (a + b) p ==
S.aff_point_add (aff_point_mul_neg a p) (aff_point_mul_neg b p))
let lemma_aff_point_mul_neg_add a b p =
LE.lemma_pow_neg_add S.mk_k256_abelian_group p a b
// [a * b]P = [b]([a]P)
val lemma_aff_point_mul_neg_mul (a b:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg (a * b) p == aff_point_mul_neg b (aff_point_mul_neg a p))
let lemma_aff_point_mul_neg_mul a b p =
LE.lemma_pow_neg_mul S.mk_k256_abelian_group p a b
// [a * b + c]P = [b]([a]P) + [c]P
val lemma_aff_point_mul_neg_mul_add (a b c:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg (a * b + c) p ==
S.aff_point_add (aff_point_mul_neg b (aff_point_mul_neg a p)) (aff_point_mul_neg c p)) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.Lemmas.fsti.checked",
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.ECSM.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256.Lemmas",
"short_module": "LS"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.ECSM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.ECSM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Prims.int -> b: Prims.int -> c: Prims.int -> p: Spec.K256.PointOps.aff_point
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul_neg (a * b + c) p ==
Spec.K256.PointOps.aff_point_add (Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul_neg b
(Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul_neg a p))
(Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul_neg c p)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.int",
"Spec.K256.PointOps.aff_point",
"Hacl.Spec.K256.ECSM.Lemmas.lemma_aff_point_mul_neg_mul",
"Prims.unit",
"Hacl.Spec.K256.ECSM.Lemmas.lemma_aff_point_mul_neg_add",
"FStar.Mul.op_Star"
] | [] | true | false | true | false | false | let lemma_aff_point_mul_neg_mul_add a b c p =
| lemma_aff_point_mul_neg_add (a * b) c p;
lemma_aff_point_mul_neg_mul a b p | false |
Hacl.Impl.K256.GLV.Constants.fst | Hacl.Impl.K256.GLV.Constants.make_g2 | val make_g2: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.g2) | val make_g2: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.g2) | let make_g2 f =
[@inline_let]
let x =
(u64 0x1571b4ae8ac47f71,
u64 0x221208ac9df506c6,
u64 0x6f547fa90abfe4c4,
u64 0xe4437ed6010e8828) in
assert_norm (SG.g2 == qas_nat4 x);
make_u64_4 f x | {
"file_name": "code/k256/Hacl.Impl.K256.GLV.Constants.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 16,
"end_line": 130,
"start_col": 0,
"start_line": 121
} | module Hacl.Impl.K256.GLV.Constants
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module S = Spec.K256
module SG = Hacl.Spec.K256.GLV
module SGL = Hacl.Spec.K256.GLV.Lemmas
open Hacl.K256.Field
open Hacl.K256.Scalar
open Hacl.Impl.K256.Point
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val make_minus_lambda: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_lambda)
let make_minus_lambda f =
[@inline_let]
let x =
(u64 0xe0cfc810b51283cf,
u64 0xa880b9fc8ec739c2,
u64 0x5ad9e3fd77ed9ba4,
u64 0xac9c52b33fa3cf1f) in
assert_norm (SG.minus_lambda == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_beta: f:felem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
as_nat h1 f == SG.beta /\ inv_fully_reduced h1 f)
let make_beta f =
[@inline_let]
let x =
(u64 0x96c28719501ee,
u64 0x7512f58995c13,
u64 0xc3434e99cf049,
u64 0x7106e64479ea,
u64 0x7ae96a2b657c) in
assert_norm (0x96c28719501ee <= max52);
assert_norm (0x7ae96a2b657c <= max48);
assert_norm (SG.beta == as_nat5 x);
make_u52_5 f x
inline_for_extraction noextract
val make_minus_b1: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_b1)
let make_minus_b1 f =
[@inline_let]
let x =
(u64 0x6f547fa90abfe4c3,
u64 0xe4437ed6010e8828,
u64 0x0,
u64 0x0) in
assert_norm (SG.minus_b1 == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_minus_b2: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_b2)
let make_minus_b2 f =
[@inline_let]
let x =
(u64 0xd765cda83db1562c,
u64 0x8a280ac50774346d,
u64 0xfffffffffffffffe,
u64 0xffffffffffffffff) in
assert_norm (SG.minus_b2 == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_g1: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.g1)
let make_g1 f =
[@inline_let]
let x =
(u64 0xe893209a45dbb031,
u64 0x3daa8a1471e8ca7f,
u64 0xe86c90e49284eb15,
u64 0x3086d221a7d46bcd) in
assert_norm (SG.g1 == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_g2: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.g2) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.GLV.Lemmas.fst.checked",
"Hacl.Spec.K256.GLV.fst.checked",
"Hacl.K256.Scalar.fsti.checked",
"Hacl.K256.Field.fsti.checked",
"Hacl.Impl.K256.Point.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": true,
"source_file": "Hacl.Impl.K256.GLV.Constants.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV.Lemmas",
"short_module": "SGL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV",
"short_module": "SG"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV",
"short_module": "SG"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Hacl.K256.Scalar.qelem -> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.K256.Scalar.qelem",
"Hacl.K256.Scalar.make_u64_4",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"Hacl.Spec.K256.GLV.g2",
"Hacl.K256.Scalar.qas_nat4",
"FStar.Pervasives.Native.tuple4",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"FStar.Pervasives.Native.Mktuple4",
"Lib.IntTypes.uint64",
"Lib.IntTypes.u64"
] | [] | false | true | false | false | false | let make_g2 f =
| [@@ inline_let ]let x =
(u64 0x1571b4ae8ac47f71, u64 0x221208ac9df506c6, u64 0x6f547fa90abfe4c4, u64 0xe4437ed6010e8828)
in
assert_norm (SG.g2 == qas_nat4 x);
make_u64_4 f x | false |
Hacl.Spec.K256.ECSM.Lemmas.fst | Hacl.Spec.K256.ECSM.Lemmas.lemma_aff_point_mul_neg_mul | val lemma_aff_point_mul_neg_mul (a b:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg (a * b) p == aff_point_mul_neg b (aff_point_mul_neg a p)) | val lemma_aff_point_mul_neg_mul (a b:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg (a * b) p == aff_point_mul_neg b (aff_point_mul_neg a p)) | let lemma_aff_point_mul_neg_mul a b p =
LE.lemma_pow_neg_mul S.mk_k256_abelian_group p a b | {
"file_name": "code/k256/Hacl.Spec.K256.ECSM.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 52,
"end_line": 44,
"start_col": 0,
"start_line": 43
} | module Hacl.Spec.K256.ECSM.Lemmas
open FStar.Mul
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module S = Spec.K256
module LS = Spec.K256.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
// [a]P in affine coordinates for a >= 0
let aff_point_mul = S.aff_point_mul
// [a]P in affine coordinates for any a
let aff_point_mul_neg (a:int) (p:S.aff_point) : S.aff_point =
LE.pow_neg S.mk_k256_abelian_group p a
assume
val lemma_order_of_curve_group (p:S.aff_point) :
Lemma (aff_point_mul S.q p == S.aff_point_at_inf)
(**
Properties for Elliptic Curve Scalar Multiplication in affine coordinates
*)
// [a + b]P = [a]P + [b]P
val lemma_aff_point_mul_neg_add (a b:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg (a + b) p ==
S.aff_point_add (aff_point_mul_neg a p) (aff_point_mul_neg b p))
let lemma_aff_point_mul_neg_add a b p =
LE.lemma_pow_neg_add S.mk_k256_abelian_group p a b
// [a * b]P = [b]([a]P)
val lemma_aff_point_mul_neg_mul (a b:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg (a * b) p == aff_point_mul_neg b (aff_point_mul_neg a p)) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.Lemmas.fsti.checked",
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.ECSM.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256.Lemmas",
"short_module": "LS"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.ECSM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.ECSM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Prims.int -> b: Prims.int -> p: Spec.K256.PointOps.aff_point
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul_neg (a * b) p ==
Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul_neg b
(Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul_neg a p)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.int",
"Spec.K256.PointOps.aff_point",
"Lib.Exponentiation.Definition.lemma_pow_neg_mul",
"Spec.K256.mk_k256_abelian_group",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_aff_point_mul_neg_mul a b p =
| LE.lemma_pow_neg_mul S.mk_k256_abelian_group p a b | false |
Hacl.Impl.K256.GLV.Constants.fst | Hacl.Impl.K256.GLV.Constants.make_minus_b2 | val make_minus_b2: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_b2) | val make_minus_b2: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_b2) | let make_minus_b2 f =
[@inline_let]
let x =
(u64 0xd765cda83db1562c,
u64 0x8a280ac50774346d,
u64 0xfffffffffffffffe,
u64 0xffffffffffffffff) in
assert_norm (SG.minus_b2 == qas_nat4 x);
make_u64_4 f x | {
"file_name": "code/k256/Hacl.Impl.K256.GLV.Constants.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 16,
"end_line": 94,
"start_col": 0,
"start_line": 85
} | module Hacl.Impl.K256.GLV.Constants
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module S = Spec.K256
module SG = Hacl.Spec.K256.GLV
module SGL = Hacl.Spec.K256.GLV.Lemmas
open Hacl.K256.Field
open Hacl.K256.Scalar
open Hacl.Impl.K256.Point
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val make_minus_lambda: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_lambda)
let make_minus_lambda f =
[@inline_let]
let x =
(u64 0xe0cfc810b51283cf,
u64 0xa880b9fc8ec739c2,
u64 0x5ad9e3fd77ed9ba4,
u64 0xac9c52b33fa3cf1f) in
assert_norm (SG.minus_lambda == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_beta: f:felem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
as_nat h1 f == SG.beta /\ inv_fully_reduced h1 f)
let make_beta f =
[@inline_let]
let x =
(u64 0x96c28719501ee,
u64 0x7512f58995c13,
u64 0xc3434e99cf049,
u64 0x7106e64479ea,
u64 0x7ae96a2b657c) in
assert_norm (0x96c28719501ee <= max52);
assert_norm (0x7ae96a2b657c <= max48);
assert_norm (SG.beta == as_nat5 x);
make_u52_5 f x
inline_for_extraction noextract
val make_minus_b1: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_b1)
let make_minus_b1 f =
[@inline_let]
let x =
(u64 0x6f547fa90abfe4c3,
u64 0xe4437ed6010e8828,
u64 0x0,
u64 0x0) in
assert_norm (SG.minus_b1 == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_minus_b2: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_b2) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.GLV.Lemmas.fst.checked",
"Hacl.Spec.K256.GLV.fst.checked",
"Hacl.K256.Scalar.fsti.checked",
"Hacl.K256.Field.fsti.checked",
"Hacl.Impl.K256.Point.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": true,
"source_file": "Hacl.Impl.K256.GLV.Constants.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV.Lemmas",
"short_module": "SGL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV",
"short_module": "SG"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV",
"short_module": "SG"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Hacl.K256.Scalar.qelem -> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.K256.Scalar.qelem",
"Hacl.K256.Scalar.make_u64_4",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"Hacl.Spec.K256.GLV.minus_b2",
"Hacl.K256.Scalar.qas_nat4",
"FStar.Pervasives.Native.tuple4",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"FStar.Pervasives.Native.Mktuple4",
"Lib.IntTypes.uint64",
"Lib.IntTypes.u64"
] | [] | false | true | false | false | false | let make_minus_b2 f =
| [@@ inline_let ]let x =
(u64 0xd765cda83db1562c, u64 0x8a280ac50774346d, u64 0xfffffffffffffffe, u64 0xffffffffffffffff)
in
assert_norm (SG.minus_b2 == qas_nat4 x);
make_u64_4 f x | false |
Hacl.Spec.K256.ECSM.Lemmas.fst | Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul_mul_neg_lemma | val aff_point_mul_mul_neg_lemma: a:nat -> b:nat -> p:S.aff_point ->
Lemma (aff_point_mul a (S.aff_point_negate (aff_point_mul b p)) ==
aff_point_mul b (S.aff_point_negate (aff_point_mul a p))) | val aff_point_mul_mul_neg_lemma: a:nat -> b:nat -> p:S.aff_point ->
Lemma (aff_point_mul a (S.aff_point_negate (aff_point_mul b p)) ==
aff_point_mul b (S.aff_point_negate (aff_point_mul a p))) | let aff_point_mul_mul_neg_lemma a b p =
let p_neg = S.aff_point_negate p in
calc (==) {
aff_point_mul a (S.aff_point_negate (aff_point_mul b p));
(==) { aff_point_mul_neg_lemma b p }
aff_point_mul a (aff_point_mul b p_neg);
(==) { aff_point_mul_mul_lemma a b p_neg }
aff_point_mul b (aff_point_mul a p_neg);
(==) { aff_point_mul_neg_lemma a p }
aff_point_mul b (S.aff_point_negate (aff_point_mul a p));
} | {
"file_name": "code/k256/Hacl.Spec.K256.ECSM.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 145,
"start_col": 0,
"start_line": 134
} | module Hacl.Spec.K256.ECSM.Lemmas
open FStar.Mul
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module S = Spec.K256
module LS = Spec.K256.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
// [a]P in affine coordinates for a >= 0
let aff_point_mul = S.aff_point_mul
// [a]P in affine coordinates for any a
let aff_point_mul_neg (a:int) (p:S.aff_point) : S.aff_point =
LE.pow_neg S.mk_k256_abelian_group p a
assume
val lemma_order_of_curve_group (p:S.aff_point) :
Lemma (aff_point_mul S.q p == S.aff_point_at_inf)
(**
Properties for Elliptic Curve Scalar Multiplication in affine coordinates
*)
// [a + b]P = [a]P + [b]P
val lemma_aff_point_mul_neg_add (a b:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg (a + b) p ==
S.aff_point_add (aff_point_mul_neg a p) (aff_point_mul_neg b p))
let lemma_aff_point_mul_neg_add a b p =
LE.lemma_pow_neg_add S.mk_k256_abelian_group p a b
// [a * b]P = [b]([a]P)
val lemma_aff_point_mul_neg_mul (a b:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg (a * b) p == aff_point_mul_neg b (aff_point_mul_neg a p))
let lemma_aff_point_mul_neg_mul a b p =
LE.lemma_pow_neg_mul S.mk_k256_abelian_group p a b
// [a * b + c]P = [b]([a]P) + [c]P
val lemma_aff_point_mul_neg_mul_add (a b c:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg (a * b + c) p ==
S.aff_point_add (aff_point_mul_neg b (aff_point_mul_neg a p)) (aff_point_mul_neg c p))
let lemma_aff_point_mul_neg_mul_add a b c p =
lemma_aff_point_mul_neg_add (a * b) c p;
lemma_aff_point_mul_neg_mul a b p
// [a]P = [a % S.q]P
val lemma_aff_point_mul_neg_modq (a:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg a p == aff_point_mul (a % S.q) p)
let lemma_aff_point_mul_neg_modq a p =
calc (==) {
aff_point_mul_neg a p;
(==) { Math.Lemmas.euclidean_division_definition a S.q }
aff_point_mul_neg (a / S.q * S.q + a % S.q) p;
(==) { lemma_aff_point_mul_neg_add (a / S.q * S.q) (a % S.q) p }
S.aff_point_add (aff_point_mul_neg (a / S.q * S.q) p) (aff_point_mul_neg (a % S.q) p);
(==) { lemma_aff_point_mul_neg_mul (a / S.q) S.q p }
S.aff_point_add
(aff_point_mul S.q (aff_point_mul_neg (a / S.q) p))
(aff_point_mul (a % S.q) p);
(==) { lemma_order_of_curve_group (aff_point_mul_neg (a / S.q) p) }
S.aff_point_add S.aff_point_at_inf (aff_point_mul (a % S.q) p);
(==) { LS.aff_point_add_comm_lemma S.aff_point_at_inf (aff_point_mul (a % S.q) p) }
S.aff_point_add (aff_point_mul (a % S.q) p) S.aff_point_at_inf;
(==) { LS.aff_point_at_inf_lemma (aff_point_mul (a % S.q) p) }
aff_point_mul (a % S.q) p;
}
// [a]P = [(-a) % q](-P)
val lemma_aff_point_mul_neg: a:S.qelem -> p:S.aff_point ->
Lemma (aff_point_mul ((- a) % S.q) (S.aff_point_negate p) == aff_point_mul a p)
let lemma_aff_point_mul_neg a p =
let cm = S.mk_k256_comm_monoid in
let ag = S.mk_k256_abelian_group in
let p_neg = S.aff_point_negate p in
if a > 0 then begin
calc (==) {
aff_point_mul ((- a) % S.q) p_neg;
(==) { lemma_aff_point_mul_neg_modq (- a) p_neg }
aff_point_mul_neg (- a) p_neg;
(==) { }
S.aff_point_negate (aff_point_mul a p_neg);
(==) { LE.lemma_inverse_pow ag p a }
S.aff_point_negate (S.aff_point_negate (aff_point_mul a p));
(==) { LE.lemma_inverse_id ag (aff_point_mul a p) }
aff_point_mul a p;
} end
else begin
LE.lemma_pow0 cm p;
LE.lemma_pow0 cm p_neg end
//--------------------------------------------
// [a]([b]P) = [b]([a]P)
val aff_point_mul_mul_lemma: a:nat -> b:nat -> p:S.aff_point ->
Lemma (aff_point_mul a (aff_point_mul b p) == aff_point_mul b (aff_point_mul a p))
let aff_point_mul_mul_lemma a b p =
calc (==) {
aff_point_mul a (aff_point_mul b p);
(==) { LE.lemma_pow_mul S.mk_k256_comm_monoid p b a }
aff_point_mul (a * b) p;
(==) { LE.lemma_pow_mul S.mk_k256_comm_monoid p a b }
aff_point_mul b (aff_point_mul a p);
}
// -[a]P = [a](-P)
val aff_point_mul_neg_lemma: a:nat -> p:S.aff_point ->
Lemma (S.aff_point_negate (aff_point_mul a p) == aff_point_mul a (S.aff_point_negate p))
let aff_point_mul_neg_lemma a p =
LE.lemma_inverse_pow S.mk_k256_abelian_group p a
// [a](-[b]P) = [b](-[a]P)
val aff_point_mul_mul_neg_lemma: a:nat -> b:nat -> p:S.aff_point ->
Lemma (aff_point_mul a (S.aff_point_negate (aff_point_mul b p)) ==
aff_point_mul b (S.aff_point_negate (aff_point_mul a p))) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.Lemmas.fsti.checked",
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.ECSM.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256.Lemmas",
"short_module": "LS"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.ECSM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.ECSM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Prims.nat -> b: Prims.nat -> p: Spec.K256.PointOps.aff_point
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul a
(Spec.K256.PointOps.aff_point_negate (Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul b p)) ==
Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul b
(Spec.K256.PointOps.aff_point_negate (Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul a p))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Spec.K256.PointOps.aff_point",
"FStar.Calc.calc_finish",
"Prims.eq2",
"Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul",
"Spec.K256.PointOps.aff_point_negate",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul_neg_lemma",
"Prims.squash",
"Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul_mul_lemma"
] | [] | false | false | true | false | false | let aff_point_mul_mul_neg_lemma a b p =
| let p_neg = S.aff_point_negate p in
calc ( == ) {
aff_point_mul a (S.aff_point_negate (aff_point_mul b p));
( == ) { aff_point_mul_neg_lemma b p }
aff_point_mul a (aff_point_mul b p_neg);
( == ) { aff_point_mul_mul_lemma a b p_neg }
aff_point_mul b (aff_point_mul a p_neg);
( == ) { aff_point_mul_neg_lemma a p }
aff_point_mul b (S.aff_point_negate (aff_point_mul a p));
} | false |
Hacl.Spec.K256.ECSM.Lemmas.fst | Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul_neg_lemma | val aff_point_mul_neg_lemma: a:nat -> p:S.aff_point ->
Lemma (S.aff_point_negate (aff_point_mul a p) == aff_point_mul a (S.aff_point_negate p)) | val aff_point_mul_neg_lemma: a:nat -> p:S.aff_point ->
Lemma (S.aff_point_negate (aff_point_mul a p) == aff_point_mul a (S.aff_point_negate p)) | let aff_point_mul_neg_lemma a p =
LE.lemma_inverse_pow S.mk_k256_abelian_group p a | {
"file_name": "code/k256/Hacl.Spec.K256.ECSM.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 126,
"start_col": 0,
"start_line": 125
} | module Hacl.Spec.K256.ECSM.Lemmas
open FStar.Mul
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module S = Spec.K256
module LS = Spec.K256.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
// [a]P in affine coordinates for a >= 0
let aff_point_mul = S.aff_point_mul
// [a]P in affine coordinates for any a
let aff_point_mul_neg (a:int) (p:S.aff_point) : S.aff_point =
LE.pow_neg S.mk_k256_abelian_group p a
assume
val lemma_order_of_curve_group (p:S.aff_point) :
Lemma (aff_point_mul S.q p == S.aff_point_at_inf)
(**
Properties for Elliptic Curve Scalar Multiplication in affine coordinates
*)
// [a + b]P = [a]P + [b]P
val lemma_aff_point_mul_neg_add (a b:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg (a + b) p ==
S.aff_point_add (aff_point_mul_neg a p) (aff_point_mul_neg b p))
let lemma_aff_point_mul_neg_add a b p =
LE.lemma_pow_neg_add S.mk_k256_abelian_group p a b
// [a * b]P = [b]([a]P)
val lemma_aff_point_mul_neg_mul (a b:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg (a * b) p == aff_point_mul_neg b (aff_point_mul_neg a p))
let lemma_aff_point_mul_neg_mul a b p =
LE.lemma_pow_neg_mul S.mk_k256_abelian_group p a b
// [a * b + c]P = [b]([a]P) + [c]P
val lemma_aff_point_mul_neg_mul_add (a b c:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg (a * b + c) p ==
S.aff_point_add (aff_point_mul_neg b (aff_point_mul_neg a p)) (aff_point_mul_neg c p))
let lemma_aff_point_mul_neg_mul_add a b c p =
lemma_aff_point_mul_neg_add (a * b) c p;
lemma_aff_point_mul_neg_mul a b p
// [a]P = [a % S.q]P
val lemma_aff_point_mul_neg_modq (a:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg a p == aff_point_mul (a % S.q) p)
let lemma_aff_point_mul_neg_modq a p =
calc (==) {
aff_point_mul_neg a p;
(==) { Math.Lemmas.euclidean_division_definition a S.q }
aff_point_mul_neg (a / S.q * S.q + a % S.q) p;
(==) { lemma_aff_point_mul_neg_add (a / S.q * S.q) (a % S.q) p }
S.aff_point_add (aff_point_mul_neg (a / S.q * S.q) p) (aff_point_mul_neg (a % S.q) p);
(==) { lemma_aff_point_mul_neg_mul (a / S.q) S.q p }
S.aff_point_add
(aff_point_mul S.q (aff_point_mul_neg (a / S.q) p))
(aff_point_mul (a % S.q) p);
(==) { lemma_order_of_curve_group (aff_point_mul_neg (a / S.q) p) }
S.aff_point_add S.aff_point_at_inf (aff_point_mul (a % S.q) p);
(==) { LS.aff_point_add_comm_lemma S.aff_point_at_inf (aff_point_mul (a % S.q) p) }
S.aff_point_add (aff_point_mul (a % S.q) p) S.aff_point_at_inf;
(==) { LS.aff_point_at_inf_lemma (aff_point_mul (a % S.q) p) }
aff_point_mul (a % S.q) p;
}
// [a]P = [(-a) % q](-P)
val lemma_aff_point_mul_neg: a:S.qelem -> p:S.aff_point ->
Lemma (aff_point_mul ((- a) % S.q) (S.aff_point_negate p) == aff_point_mul a p)
let lemma_aff_point_mul_neg a p =
let cm = S.mk_k256_comm_monoid in
let ag = S.mk_k256_abelian_group in
let p_neg = S.aff_point_negate p in
if a > 0 then begin
calc (==) {
aff_point_mul ((- a) % S.q) p_neg;
(==) { lemma_aff_point_mul_neg_modq (- a) p_neg }
aff_point_mul_neg (- a) p_neg;
(==) { }
S.aff_point_negate (aff_point_mul a p_neg);
(==) { LE.lemma_inverse_pow ag p a }
S.aff_point_negate (S.aff_point_negate (aff_point_mul a p));
(==) { LE.lemma_inverse_id ag (aff_point_mul a p) }
aff_point_mul a p;
} end
else begin
LE.lemma_pow0 cm p;
LE.lemma_pow0 cm p_neg end
//--------------------------------------------
// [a]([b]P) = [b]([a]P)
val aff_point_mul_mul_lemma: a:nat -> b:nat -> p:S.aff_point ->
Lemma (aff_point_mul a (aff_point_mul b p) == aff_point_mul b (aff_point_mul a p))
let aff_point_mul_mul_lemma a b p =
calc (==) {
aff_point_mul a (aff_point_mul b p);
(==) { LE.lemma_pow_mul S.mk_k256_comm_monoid p b a }
aff_point_mul (a * b) p;
(==) { LE.lemma_pow_mul S.mk_k256_comm_monoid p a b }
aff_point_mul b (aff_point_mul a p);
}
// -[a]P = [a](-P)
val aff_point_mul_neg_lemma: a:nat -> p:S.aff_point ->
Lemma (S.aff_point_negate (aff_point_mul a p) == aff_point_mul a (S.aff_point_negate p)) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.Lemmas.fsti.checked",
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.ECSM.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256.Lemmas",
"short_module": "LS"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.ECSM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.ECSM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Prims.nat -> p: Spec.K256.PointOps.aff_point
-> FStar.Pervasives.Lemma
(ensures
Spec.K256.PointOps.aff_point_negate (Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul a p) ==
Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul a (Spec.K256.PointOps.aff_point_negate p)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Spec.K256.PointOps.aff_point",
"Lib.Exponentiation.Definition.lemma_inverse_pow",
"Spec.K256.mk_k256_abelian_group",
"Prims.unit"
] | [] | true | false | true | false | false | let aff_point_mul_neg_lemma a p =
| LE.lemma_inverse_pow S.mk_k256_abelian_group p a | false |
Hacl.Impl.K256.GLV.Constants.fst | Hacl.Impl.K256.GLV.Constants.scalar_split_lambda_g1g2 | val scalar_split_lambda_g1g2 (tmp1 tmp2 r1 r2 k: qelem) : Stack unit
(requires fun h ->
live h k /\ live h r1 /\ live h r2 /\
live h tmp1 /\ live h tmp2 /\
disjoint k r1 /\ disjoint k r2 /\ disjoint r1 r2 /\
disjoint tmp1 r1 /\ disjoint tmp1 r2 /\ disjoint tmp1 k /\
disjoint tmp2 r1 /\ disjoint tmp2 r2 /\ disjoint tmp2 k /\
disjoint tmp1 tmp2 /\ qas_nat h k < S.q)
(ensures fun h0 _ h1 ->
modifies (loc r1 |+| loc r2 |+| loc tmp1 |+| loc tmp2) h0 h1 /\
(let r1 = qas_nat h1 r1 in let r2 = qas_nat h1 r2 in
r1 < S.q /\ r1 = SG.qmul_shift_384 (qas_nat h0 k) SG.g1 /\
r2 < S.q /\ r2 = SG.qmul_shift_384 (qas_nat h0 k) SG.g2)) | val scalar_split_lambda_g1g2 (tmp1 tmp2 r1 r2 k: qelem) : Stack unit
(requires fun h ->
live h k /\ live h r1 /\ live h r2 /\
live h tmp1 /\ live h tmp2 /\
disjoint k r1 /\ disjoint k r2 /\ disjoint r1 r2 /\
disjoint tmp1 r1 /\ disjoint tmp1 r2 /\ disjoint tmp1 k /\
disjoint tmp2 r1 /\ disjoint tmp2 r2 /\ disjoint tmp2 k /\
disjoint tmp1 tmp2 /\ qas_nat h k < S.q)
(ensures fun h0 _ h1 ->
modifies (loc r1 |+| loc r2 |+| loc tmp1 |+| loc tmp2) h0 h1 /\
(let r1 = qas_nat h1 r1 in let r2 = qas_nat h1 r2 in
r1 < S.q /\ r1 = SG.qmul_shift_384 (qas_nat h0 k) SG.g1 /\
r2 < S.q /\ r2 = SG.qmul_shift_384 (qas_nat h0 k) SG.g2)) | let scalar_split_lambda_g1g2 tmp1 tmp2 r1 r2 k =
make_g1 tmp1; // tmp1 = g1
make_g2 tmp2; // tmp2 = g2
qmul_shift_384 r1 k tmp1; // r1 = c1 = qmul_shift_384 k g1
qmul_shift_384 r2 k tmp2; // r2 = c2 = qmul_shift_384 k g2
let h0 = ST.get () in
SG.qmul_shift_384_lemma (qas_nat h0 k) (qas_nat h0 tmp1);
SG.qmul_shift_384_lemma (qas_nat h0 k) (qas_nat h0 tmp2);
assert (qas_nat h0 r1 < S.q /\ qas_nat h0 r2 < S.q) | {
"file_name": "code/k256/Hacl.Impl.K256.GLV.Constants.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 53,
"end_line": 161,
"start_col": 0,
"start_line": 153
} | module Hacl.Impl.K256.GLV.Constants
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module S = Spec.K256
module SG = Hacl.Spec.K256.GLV
module SGL = Hacl.Spec.K256.GLV.Lemmas
open Hacl.K256.Field
open Hacl.K256.Scalar
open Hacl.Impl.K256.Point
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val make_minus_lambda: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_lambda)
let make_minus_lambda f =
[@inline_let]
let x =
(u64 0xe0cfc810b51283cf,
u64 0xa880b9fc8ec739c2,
u64 0x5ad9e3fd77ed9ba4,
u64 0xac9c52b33fa3cf1f) in
assert_norm (SG.minus_lambda == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_beta: f:felem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
as_nat h1 f == SG.beta /\ inv_fully_reduced h1 f)
let make_beta f =
[@inline_let]
let x =
(u64 0x96c28719501ee,
u64 0x7512f58995c13,
u64 0xc3434e99cf049,
u64 0x7106e64479ea,
u64 0x7ae96a2b657c) in
assert_norm (0x96c28719501ee <= max52);
assert_norm (0x7ae96a2b657c <= max48);
assert_norm (SG.beta == as_nat5 x);
make_u52_5 f x
inline_for_extraction noextract
val make_minus_b1: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_b1)
let make_minus_b1 f =
[@inline_let]
let x =
(u64 0x6f547fa90abfe4c3,
u64 0xe4437ed6010e8828,
u64 0x0,
u64 0x0) in
assert_norm (SG.minus_b1 == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_minus_b2: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_b2)
let make_minus_b2 f =
[@inline_let]
let x =
(u64 0xd765cda83db1562c,
u64 0x8a280ac50774346d,
u64 0xfffffffffffffffe,
u64 0xffffffffffffffff) in
assert_norm (SG.minus_b2 == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_g1: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.g1)
let make_g1 f =
[@inline_let]
let x =
(u64 0xe893209a45dbb031,
u64 0x3daa8a1471e8ca7f,
u64 0xe86c90e49284eb15,
u64 0x3086d221a7d46bcd) in
assert_norm (SG.g1 == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_g2: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.g2)
let make_g2 f =
[@inline_let]
let x =
(u64 0x1571b4ae8ac47f71,
u64 0x221208ac9df506c6,
u64 0x6f547fa90abfe4c4,
u64 0xe4437ed6010e8828) in
assert_norm (SG.g2 == qas_nat4 x);
make_u64_4 f x
(**
Representing a scalar k as (r1 + r2 * lambda) mod S.q,
s.t. r1 and r2 are ~128 bits long
*)
inline_for_extraction noextract
val scalar_split_lambda_g1g2 (tmp1 tmp2 r1 r2 k: qelem) : Stack unit
(requires fun h ->
live h k /\ live h r1 /\ live h r2 /\
live h tmp1 /\ live h tmp2 /\
disjoint k r1 /\ disjoint k r2 /\ disjoint r1 r2 /\
disjoint tmp1 r1 /\ disjoint tmp1 r2 /\ disjoint tmp1 k /\
disjoint tmp2 r1 /\ disjoint tmp2 r2 /\ disjoint tmp2 k /\
disjoint tmp1 tmp2 /\ qas_nat h k < S.q)
(ensures fun h0 _ h1 ->
modifies (loc r1 |+| loc r2 |+| loc tmp1 |+| loc tmp2) h0 h1 /\
(let r1 = qas_nat h1 r1 in let r2 = qas_nat h1 r2 in
r1 < S.q /\ r1 = SG.qmul_shift_384 (qas_nat h0 k) SG.g1 /\
r2 < S.q /\ r2 = SG.qmul_shift_384 (qas_nat h0 k) SG.g2)) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.GLV.Lemmas.fst.checked",
"Hacl.Spec.K256.GLV.fst.checked",
"Hacl.K256.Scalar.fsti.checked",
"Hacl.K256.Field.fsti.checked",
"Hacl.Impl.K256.Point.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": true,
"source_file": "Hacl.Impl.K256.GLV.Constants.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV.Lemmas",
"short_module": "SGL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV",
"short_module": "SG"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV",
"short_module": "SG"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
tmp1: Hacl.K256.Scalar.qelem ->
tmp2: Hacl.K256.Scalar.qelem ->
r1: Hacl.K256.Scalar.qelem ->
r2: Hacl.K256.Scalar.qelem ->
k: Hacl.K256.Scalar.qelem
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.K256.Scalar.qelem",
"Prims._assert",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.K256.Scalar.qas_nat",
"Spec.K256.PointOps.q",
"Prims.unit",
"Hacl.Spec.K256.GLV.qmul_shift_384_lemma",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.K256.Scalar.qmul_shift_384",
"Hacl.Impl.K256.GLV.Constants.make_g2",
"Hacl.Impl.K256.GLV.Constants.make_g1"
] | [] | false | true | false | false | false | let scalar_split_lambda_g1g2 tmp1 tmp2 r1 r2 k =
| make_g1 tmp1;
make_g2 tmp2;
qmul_shift_384 r1 k tmp1;
qmul_shift_384 r2 k tmp2;
let h0 = ST.get () in
SG.qmul_shift_384_lemma (qas_nat h0 k) (qas_nat h0 tmp1);
SG.qmul_shift_384_lemma (qas_nat h0 k) (qas_nat h0 tmp2);
assert (qas_nat h0 r1 < S.q /\ qas_nat h0 r2 < S.q) | false |
Hacl.Impl.K256.GLV.Constants.fst | Hacl.Impl.K256.GLV.Constants.make_beta | val make_beta: f:felem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
as_nat h1 f == SG.beta /\ inv_fully_reduced h1 f) | val make_beta: f:felem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
as_nat h1 f == SG.beta /\ inv_fully_reduced h1 f) | let make_beta f =
[@inline_let]
let x =
(u64 0x96c28719501ee,
u64 0x7512f58995c13,
u64 0xc3434e99cf049,
u64 0x7106e64479ea,
u64 0x7ae96a2b657c) in
assert_norm (0x96c28719501ee <= max52);
assert_norm (0x7ae96a2b657c <= max48);
assert_norm (SG.beta == as_nat5 x);
make_u52_5 f x | {
"file_name": "code/k256/Hacl.Impl.K256.GLV.Constants.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 16,
"end_line": 58,
"start_col": 0,
"start_line": 46
} | module Hacl.Impl.K256.GLV.Constants
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module S = Spec.K256
module SG = Hacl.Spec.K256.GLV
module SGL = Hacl.Spec.K256.GLV.Lemmas
open Hacl.K256.Field
open Hacl.K256.Scalar
open Hacl.Impl.K256.Point
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val make_minus_lambda: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_lambda)
let make_minus_lambda f =
[@inline_let]
let x =
(u64 0xe0cfc810b51283cf,
u64 0xa880b9fc8ec739c2,
u64 0x5ad9e3fd77ed9ba4,
u64 0xac9c52b33fa3cf1f) in
assert_norm (SG.minus_lambda == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_beta: f:felem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
as_nat h1 f == SG.beta /\ inv_fully_reduced h1 f) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.GLV.Lemmas.fst.checked",
"Hacl.Spec.K256.GLV.fst.checked",
"Hacl.K256.Scalar.fsti.checked",
"Hacl.K256.Field.fsti.checked",
"Hacl.Impl.K256.Point.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": true,
"source_file": "Hacl.Impl.K256.GLV.Constants.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV.Lemmas",
"short_module": "SGL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV",
"short_module": "SG"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV",
"short_module": "SG"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Hacl.K256.Field.felem -> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.K256.Field.felem",
"Hacl.K256.Field.make_u52_5",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.nat",
"Hacl.Spec.K256.GLV.beta",
"Hacl.Spec.K256.Field52.Definitions.as_nat5",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.K256.Field52.Definitions.max48",
"Hacl.Spec.K256.Field52.Definitions.max52",
"FStar.Pervasives.Native.tuple5",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"FStar.Pervasives.Native.Mktuple5",
"Lib.IntTypes.uint64",
"Lib.IntTypes.u64"
] | [] | false | true | false | false | false | let make_beta f =
| [@@ inline_let ]let x =
(u64 0x96c28719501ee,
u64 0x7512f58995c13,
u64 0xc3434e99cf049,
u64 0x7106e64479ea,
u64 0x7ae96a2b657c)
in
assert_norm (0x96c28719501ee <= max52);
assert_norm (0x7ae96a2b657c <= max48);
assert_norm (SG.beta == as_nat5 x);
make_u52_5 f x | false |
Hacl.Impl.K256.GLV.Constants.fst | Hacl.Impl.K256.GLV.Constants.make_g1 | val make_g1: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.g1) | val make_g1: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.g1) | let make_g1 f =
[@inline_let]
let x =
(u64 0xe893209a45dbb031,
u64 0x3daa8a1471e8ca7f,
u64 0xe86c90e49284eb15,
u64 0x3086d221a7d46bcd) in
assert_norm (SG.g1 == qas_nat4 x);
make_u64_4 f x | {
"file_name": "code/k256/Hacl.Impl.K256.GLV.Constants.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 16,
"end_line": 112,
"start_col": 0,
"start_line": 103
} | module Hacl.Impl.K256.GLV.Constants
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module S = Spec.K256
module SG = Hacl.Spec.K256.GLV
module SGL = Hacl.Spec.K256.GLV.Lemmas
open Hacl.K256.Field
open Hacl.K256.Scalar
open Hacl.Impl.K256.Point
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val make_minus_lambda: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_lambda)
let make_minus_lambda f =
[@inline_let]
let x =
(u64 0xe0cfc810b51283cf,
u64 0xa880b9fc8ec739c2,
u64 0x5ad9e3fd77ed9ba4,
u64 0xac9c52b33fa3cf1f) in
assert_norm (SG.minus_lambda == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_beta: f:felem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
as_nat h1 f == SG.beta /\ inv_fully_reduced h1 f)
let make_beta f =
[@inline_let]
let x =
(u64 0x96c28719501ee,
u64 0x7512f58995c13,
u64 0xc3434e99cf049,
u64 0x7106e64479ea,
u64 0x7ae96a2b657c) in
assert_norm (0x96c28719501ee <= max52);
assert_norm (0x7ae96a2b657c <= max48);
assert_norm (SG.beta == as_nat5 x);
make_u52_5 f x
inline_for_extraction noextract
val make_minus_b1: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_b1)
let make_minus_b1 f =
[@inline_let]
let x =
(u64 0x6f547fa90abfe4c3,
u64 0xe4437ed6010e8828,
u64 0x0,
u64 0x0) in
assert_norm (SG.minus_b1 == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_minus_b2: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_b2)
let make_minus_b2 f =
[@inline_let]
let x =
(u64 0xd765cda83db1562c,
u64 0x8a280ac50774346d,
u64 0xfffffffffffffffe,
u64 0xffffffffffffffff) in
assert_norm (SG.minus_b2 == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_g1: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.g1) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.GLV.Lemmas.fst.checked",
"Hacl.Spec.K256.GLV.fst.checked",
"Hacl.K256.Scalar.fsti.checked",
"Hacl.K256.Field.fsti.checked",
"Hacl.Impl.K256.Point.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": true,
"source_file": "Hacl.Impl.K256.GLV.Constants.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV.Lemmas",
"short_module": "SGL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV",
"short_module": "SG"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV",
"short_module": "SG"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Hacl.K256.Scalar.qelem -> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.K256.Scalar.qelem",
"Hacl.K256.Scalar.make_u64_4",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"Hacl.Spec.K256.GLV.g1",
"Hacl.K256.Scalar.qas_nat4",
"FStar.Pervasives.Native.tuple4",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"FStar.Pervasives.Native.Mktuple4",
"Lib.IntTypes.uint64",
"Lib.IntTypes.u64"
] | [] | false | true | false | false | false | let make_g1 f =
| [@@ inline_let ]let x =
(u64 0xe893209a45dbb031, u64 0x3daa8a1471e8ca7f, u64 0xe86c90e49284eb15, u64 0x3086d221a7d46bcd)
in
assert_norm (SG.g1 == qas_nat4 x);
make_u64_4 f x | false |
Hacl.Impl.K256.GLV.Constants.fst | Hacl.Impl.K256.GLV.Constants.make_minus_lambda | val make_minus_lambda: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_lambda) | val make_minus_lambda: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_lambda) | let make_minus_lambda f =
[@inline_let]
let x =
(u64 0xe0cfc810b51283cf,
u64 0xa880b9fc8ec739c2,
u64 0x5ad9e3fd77ed9ba4,
u64 0xac9c52b33fa3cf1f) in
assert_norm (SG.minus_lambda == qas_nat4 x);
make_u64_4 f x | {
"file_name": "code/k256/Hacl.Impl.K256.GLV.Constants.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 16,
"end_line": 37,
"start_col": 0,
"start_line": 28
} | module Hacl.Impl.K256.GLV.Constants
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module S = Spec.K256
module SG = Hacl.Spec.K256.GLV
module SGL = Hacl.Spec.K256.GLV.Lemmas
open Hacl.K256.Field
open Hacl.K256.Scalar
open Hacl.Impl.K256.Point
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val make_minus_lambda: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_lambda) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.GLV.Lemmas.fst.checked",
"Hacl.Spec.K256.GLV.fst.checked",
"Hacl.K256.Scalar.fsti.checked",
"Hacl.K256.Field.fsti.checked",
"Hacl.Impl.K256.Point.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": true,
"source_file": "Hacl.Impl.K256.GLV.Constants.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV.Lemmas",
"short_module": "SGL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV",
"short_module": "SG"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV",
"short_module": "SG"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Hacl.K256.Scalar.qelem -> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.K256.Scalar.qelem",
"Hacl.K256.Scalar.make_u64_4",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"Hacl.Spec.K256.GLV.minus_lambda",
"Hacl.K256.Scalar.qas_nat4",
"FStar.Pervasives.Native.tuple4",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"FStar.Pervasives.Native.Mktuple4",
"Lib.IntTypes.uint64",
"Lib.IntTypes.u64"
] | [] | false | true | false | false | false | let make_minus_lambda f =
| [@@ inline_let ]let x =
(u64 0xe0cfc810b51283cf, u64 0xa880b9fc8ec739c2, u64 0x5ad9e3fd77ed9ba4, u64 0xac9c52b33fa3cf1f)
in
assert_norm (SG.minus_lambda == qas_nat4 x);
make_u64_4 f x | false |
Hacl.Spec.K256.ECSM.Lemmas.fst | Hacl.Spec.K256.ECSM.Lemmas.lemma_aff_point_mul_neg | val lemma_aff_point_mul_neg: a:S.qelem -> p:S.aff_point ->
Lemma (aff_point_mul ((- a) % S.q) (S.aff_point_negate p) == aff_point_mul a p) | val lemma_aff_point_mul_neg: a:S.qelem -> p:S.aff_point ->
Lemma (aff_point_mul ((- a) % S.q) (S.aff_point_negate p) == aff_point_mul a p) | let lemma_aff_point_mul_neg a p =
let cm = S.mk_k256_comm_monoid in
let ag = S.mk_k256_abelian_group in
let p_neg = S.aff_point_negate p in
if a > 0 then begin
calc (==) {
aff_point_mul ((- a) % S.q) p_neg;
(==) { lemma_aff_point_mul_neg_modq (- a) p_neg }
aff_point_mul_neg (- a) p_neg;
(==) { }
S.aff_point_negate (aff_point_mul a p_neg);
(==) { LE.lemma_inverse_pow ag p a }
S.aff_point_negate (S.aff_point_negate (aff_point_mul a p));
(==) { LE.lemma_inverse_id ag (aff_point_mul a p) }
aff_point_mul a p;
} end
else begin
LE.lemma_pow0 cm p;
LE.lemma_pow0 cm p_neg end | {
"file_name": "code/k256/Hacl.Spec.K256.ECSM.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 30,
"end_line": 103,
"start_col": 0,
"start_line": 85
} | module Hacl.Spec.K256.ECSM.Lemmas
open FStar.Mul
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module S = Spec.K256
module LS = Spec.K256.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
// [a]P in affine coordinates for a >= 0
let aff_point_mul = S.aff_point_mul
// [a]P in affine coordinates for any a
let aff_point_mul_neg (a:int) (p:S.aff_point) : S.aff_point =
LE.pow_neg S.mk_k256_abelian_group p a
assume
val lemma_order_of_curve_group (p:S.aff_point) :
Lemma (aff_point_mul S.q p == S.aff_point_at_inf)
(**
Properties for Elliptic Curve Scalar Multiplication in affine coordinates
*)
// [a + b]P = [a]P + [b]P
val lemma_aff_point_mul_neg_add (a b:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg (a + b) p ==
S.aff_point_add (aff_point_mul_neg a p) (aff_point_mul_neg b p))
let lemma_aff_point_mul_neg_add a b p =
LE.lemma_pow_neg_add S.mk_k256_abelian_group p a b
// [a * b]P = [b]([a]P)
val lemma_aff_point_mul_neg_mul (a b:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg (a * b) p == aff_point_mul_neg b (aff_point_mul_neg a p))
let lemma_aff_point_mul_neg_mul a b p =
LE.lemma_pow_neg_mul S.mk_k256_abelian_group p a b
// [a * b + c]P = [b]([a]P) + [c]P
val lemma_aff_point_mul_neg_mul_add (a b c:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg (a * b + c) p ==
S.aff_point_add (aff_point_mul_neg b (aff_point_mul_neg a p)) (aff_point_mul_neg c p))
let lemma_aff_point_mul_neg_mul_add a b c p =
lemma_aff_point_mul_neg_add (a * b) c p;
lemma_aff_point_mul_neg_mul a b p
// [a]P = [a % S.q]P
val lemma_aff_point_mul_neg_modq (a:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg a p == aff_point_mul (a % S.q) p)
let lemma_aff_point_mul_neg_modq a p =
calc (==) {
aff_point_mul_neg a p;
(==) { Math.Lemmas.euclidean_division_definition a S.q }
aff_point_mul_neg (a / S.q * S.q + a % S.q) p;
(==) { lemma_aff_point_mul_neg_add (a / S.q * S.q) (a % S.q) p }
S.aff_point_add (aff_point_mul_neg (a / S.q * S.q) p) (aff_point_mul_neg (a % S.q) p);
(==) { lemma_aff_point_mul_neg_mul (a / S.q) S.q p }
S.aff_point_add
(aff_point_mul S.q (aff_point_mul_neg (a / S.q) p))
(aff_point_mul (a % S.q) p);
(==) { lemma_order_of_curve_group (aff_point_mul_neg (a / S.q) p) }
S.aff_point_add S.aff_point_at_inf (aff_point_mul (a % S.q) p);
(==) { LS.aff_point_add_comm_lemma S.aff_point_at_inf (aff_point_mul (a % S.q) p) }
S.aff_point_add (aff_point_mul (a % S.q) p) S.aff_point_at_inf;
(==) { LS.aff_point_at_inf_lemma (aff_point_mul (a % S.q) p) }
aff_point_mul (a % S.q) p;
}
// [a]P = [(-a) % q](-P)
val lemma_aff_point_mul_neg: a:S.qelem -> p:S.aff_point ->
Lemma (aff_point_mul ((- a) % S.q) (S.aff_point_negate p) == aff_point_mul a p) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.Lemmas.fsti.checked",
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.ECSM.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256.Lemmas",
"short_module": "LS"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.ECSM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.ECSM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.K256.PointOps.qelem -> p: Spec.K256.PointOps.aff_point
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul ((- a) % Spec.K256.PointOps.q)
(Spec.K256.PointOps.aff_point_negate p) ==
Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul a p) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.K256.PointOps.qelem",
"Spec.K256.PointOps.aff_point",
"Prims.op_GreaterThan",
"FStar.Calc.calc_finish",
"Prims.eq2",
"Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul",
"Prims.op_Modulus",
"Prims.op_Minus",
"Spec.K256.PointOps.q",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Spec.K256.PointOps.aff_point_negate",
"Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul_neg",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Hacl.Spec.K256.ECSM.Lemmas.lemma_aff_point_mul_neg_modq",
"Prims.squash",
"Lib.Exponentiation.Definition.lemma_inverse_pow",
"Lib.Exponentiation.Definition.lemma_inverse_id",
"Prims.bool",
"Lib.Exponentiation.Definition.lemma_pow0",
"Lib.Exponentiation.Definition.abelian_group",
"Spec.K256.mk_k256_abelian_group",
"Lib.Exponentiation.Definition.comm_monoid",
"Spec.K256.mk_k256_comm_monoid"
] | [] | false | false | true | false | false | let lemma_aff_point_mul_neg a p =
| let cm = S.mk_k256_comm_monoid in
let ag = S.mk_k256_abelian_group in
let p_neg = S.aff_point_negate p in
if a > 0
then
calc ( == ) {
aff_point_mul ((- a) % S.q) p_neg;
( == ) { lemma_aff_point_mul_neg_modq (- a) p_neg }
aff_point_mul_neg (- a) p_neg;
( == ) { () }
S.aff_point_negate (aff_point_mul a p_neg);
( == ) { LE.lemma_inverse_pow ag p a }
S.aff_point_negate (S.aff_point_negate (aff_point_mul a p));
( == ) { LE.lemma_inverse_id ag (aff_point_mul a p) }
aff_point_mul a p;
}
else
(LE.lemma_pow0 cm p;
LE.lemma_pow0 cm p_neg) | false |
Hacl.Impl.K256.GLV.Constants.fst | Hacl.Impl.K256.GLV.Constants.negate_point_and_scalar_cond_vartime | val negate_point_and_scalar_cond_vartime: k:qelem -> p:point -> Stack bool
(requires fun h ->
live h k /\ live h p /\ disjoint k p /\
qas_nat h k < S.q /\ point_inv h p)
(ensures fun h0 b h1 -> modifies (loc k |+| loc p) h0 h1 /\
b == S.scalar_is_high (qas_nat h0 k) /\ point_inv h1 p /\
(let k_s, p_s = SG.negate_point_and_scalar_cond (qas_nat h0 k) (point_eval h0 p) in
qas_nat h1 k == k_s /\ point_eval h1 p == p_s)) | val negate_point_and_scalar_cond_vartime: k:qelem -> p:point -> Stack bool
(requires fun h ->
live h k /\ live h p /\ disjoint k p /\
qas_nat h k < S.q /\ point_inv h p)
(ensures fun h0 b h1 -> modifies (loc k |+| loc p) h0 h1 /\
b == S.scalar_is_high (qas_nat h0 k) /\ point_inv h1 p /\
(let k_s, p_s = SG.negate_point_and_scalar_cond (qas_nat h0 k) (point_eval h0 p) in
qas_nat h1 k == k_s /\ point_eval h1 p == p_s)) | let negate_point_and_scalar_cond_vartime k p =
let b = is_qelem_le_q_halved_vartime k in
[@inline_let] let if_high = not b in
qnegate_conditional_vartime k if_high;
point_negate_conditional_vartime p if_high;
if_high | {
"file_name": "code/k256/Hacl.Impl.K256.GLV.Constants.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 9,
"end_line": 256,
"start_col": 0,
"start_line": 251
} | module Hacl.Impl.K256.GLV.Constants
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module S = Spec.K256
module SG = Hacl.Spec.K256.GLV
module SGL = Hacl.Spec.K256.GLV.Lemmas
open Hacl.K256.Field
open Hacl.K256.Scalar
open Hacl.Impl.K256.Point
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val make_minus_lambda: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_lambda)
let make_minus_lambda f =
[@inline_let]
let x =
(u64 0xe0cfc810b51283cf,
u64 0xa880b9fc8ec739c2,
u64 0x5ad9e3fd77ed9ba4,
u64 0xac9c52b33fa3cf1f) in
assert_norm (SG.minus_lambda == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_beta: f:felem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
as_nat h1 f == SG.beta /\ inv_fully_reduced h1 f)
let make_beta f =
[@inline_let]
let x =
(u64 0x96c28719501ee,
u64 0x7512f58995c13,
u64 0xc3434e99cf049,
u64 0x7106e64479ea,
u64 0x7ae96a2b657c) in
assert_norm (0x96c28719501ee <= max52);
assert_norm (0x7ae96a2b657c <= max48);
assert_norm (SG.beta == as_nat5 x);
make_u52_5 f x
inline_for_extraction noextract
val make_minus_b1: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_b1)
let make_minus_b1 f =
[@inline_let]
let x =
(u64 0x6f547fa90abfe4c3,
u64 0xe4437ed6010e8828,
u64 0x0,
u64 0x0) in
assert_norm (SG.minus_b1 == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_minus_b2: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_b2)
let make_minus_b2 f =
[@inline_let]
let x =
(u64 0xd765cda83db1562c,
u64 0x8a280ac50774346d,
u64 0xfffffffffffffffe,
u64 0xffffffffffffffff) in
assert_norm (SG.minus_b2 == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_g1: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.g1)
let make_g1 f =
[@inline_let]
let x =
(u64 0xe893209a45dbb031,
u64 0x3daa8a1471e8ca7f,
u64 0xe86c90e49284eb15,
u64 0x3086d221a7d46bcd) in
assert_norm (SG.g1 == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_g2: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.g2)
let make_g2 f =
[@inline_let]
let x =
(u64 0x1571b4ae8ac47f71,
u64 0x221208ac9df506c6,
u64 0x6f547fa90abfe4c4,
u64 0xe4437ed6010e8828) in
assert_norm (SG.g2 == qas_nat4 x);
make_u64_4 f x
(**
Representing a scalar k as (r1 + r2 * lambda) mod S.q,
s.t. r1 and r2 are ~128 bits long
*)
inline_for_extraction noextract
val scalar_split_lambda_g1g2 (tmp1 tmp2 r1 r2 k: qelem) : Stack unit
(requires fun h ->
live h k /\ live h r1 /\ live h r2 /\
live h tmp1 /\ live h tmp2 /\
disjoint k r1 /\ disjoint k r2 /\ disjoint r1 r2 /\
disjoint tmp1 r1 /\ disjoint tmp1 r2 /\ disjoint tmp1 k /\
disjoint tmp2 r1 /\ disjoint tmp2 r2 /\ disjoint tmp2 k /\
disjoint tmp1 tmp2 /\ qas_nat h k < S.q)
(ensures fun h0 _ h1 ->
modifies (loc r1 |+| loc r2 |+| loc tmp1 |+| loc tmp2) h0 h1 /\
(let r1 = qas_nat h1 r1 in let r2 = qas_nat h1 r2 in
r1 < S.q /\ r1 = SG.qmul_shift_384 (qas_nat h0 k) SG.g1 /\
r2 < S.q /\ r2 = SG.qmul_shift_384 (qas_nat h0 k) SG.g2))
let scalar_split_lambda_g1g2 tmp1 tmp2 r1 r2 k =
make_g1 tmp1; // tmp1 = g1
make_g2 tmp2; // tmp2 = g2
qmul_shift_384 r1 k tmp1; // r1 = c1 = qmul_shift_384 k g1
qmul_shift_384 r2 k tmp2; // r2 = c2 = qmul_shift_384 k g2
let h0 = ST.get () in
SG.qmul_shift_384_lemma (qas_nat h0 k) (qas_nat h0 tmp1);
SG.qmul_shift_384_lemma (qas_nat h0 k) (qas_nat h0 tmp2);
assert (qas_nat h0 r1 < S.q /\ qas_nat h0 r2 < S.q)
// k = (r1 + lambda * k2) % S.q
val scalar_split_lambda (r1 r2 k: qelem) : Stack unit
(requires fun h ->
live h k /\ live h r1 /\ live h r2 /\
disjoint k r1 /\ disjoint k r2 /\ disjoint r1 r2 /\
qas_nat h k < S.q)
(ensures fun h0 _ h1 -> modifies (loc r1 |+| loc r2) h0 h1 /\
(let r1_s, r2_s = SG.scalar_split_lambda (qas_nat h0 k) in
qas_nat h1 r1 == r1_s /\ qas_nat h1 r2 == r2_s))
[@CInline]
let scalar_split_lambda r1 r2 k =
push_frame ();
let tmp1 = create_qelem () in
let tmp2 = create_qelem () in
scalar_split_lambda_g1g2 tmp1 tmp2 r1 r2 k;
make_minus_b1 tmp1; // tmp1 = minus_b1
make_minus_b2 tmp2; // tmp2 = minus_b2
qmul r1 r1 tmp1; // r1 = c1 = c1 * minus_b1
qmul r2 r2 tmp2; // r2 = c2 = c2 * minus_b2
make_minus_lambda tmp1; // tmp1 = minus_lambda
qadd r2 r1 r2; // r2 = r2 = c1 + c2
qmul tmp2 r2 tmp1; // tmp2 = r2 * minus_lambda
qadd r1 k tmp2; // r1 = r1 = k + r2 * minus_lambda
pop_frame ()
(**
Fast computation of [lambda]P as (beta * px, py, pz) in projective coordinates
*)
[@CInline]
let point_mul_lambda res p =
push_frame ();
let rx, ry, rz = getx res, gety res, getz res in
let px, py, pz = getx p, gety p, getz p in
let beta = create_felem () in
make_beta beta;
fmul rx beta px;
copy_felem ry py;
copy_felem rz pz;
pop_frame ()
[@CInline]
let point_mul_lambda_inplace res =
push_frame ();
let rx, ry, rz = getx res, gety res, getz res in
let beta = create_felem () in
make_beta beta;
fmul rx beta rx;
pop_frame ()
inline_for_extraction noextract
val point_mul_lambda_and_split_lambda:
r1:qelem -> r2:qelem -> lambda_q:point -> scalar:qelem -> q:point -> Stack unit
(requires fun h ->
live h r1 /\ live h r2 /\ live h lambda_q /\ live h scalar /\ live h q /\
disjoint r1 r2 /\ disjoint r1 lambda_q /\ disjoint r1 scalar /\ disjoint r1 q /\
disjoint r2 lambda_q /\ disjoint r2 scalar /\ disjoint r2 q /\
disjoint lambda_q scalar /\ disjoint lambda_q q /\
point_inv h q /\ qas_nat h scalar < S.q)
(ensures fun h0 _ h1 -> modifies (loc r1 |+| loc r2 |+| loc lambda_q) h0 h1 /\
point_inv h1 lambda_q /\
point_eval h1 lambda_q == SG.point_mul_lambda (point_eval h0 q) /\
(let r1_s, r2_s = SG.scalar_split_lambda (qas_nat h0 scalar) in
qas_nat h1 r1 == r1_s /\ qas_nat h1 r2 == r2_s))
let point_mul_lambda_and_split_lambda r1 r2 lambda_q scalar q =
scalar_split_lambda r1 r2 scalar; // (r1 + r2 * lambda) % S.q = scalar
point_mul_lambda lambda_q q // lambda_q = [lambda]Q
inline_for_extraction noextract
val negate_point_and_scalar_cond_vartime: k:qelem -> p:point -> Stack bool
(requires fun h ->
live h k /\ live h p /\ disjoint k p /\
qas_nat h k < S.q /\ point_inv h p)
(ensures fun h0 b h1 -> modifies (loc k |+| loc p) h0 h1 /\
b == S.scalar_is_high (qas_nat h0 k) /\ point_inv h1 p /\
(let k_s, p_s = SG.negate_point_and_scalar_cond (qas_nat h0 k) (point_eval h0 p) in
qas_nat h1 k == k_s /\ point_eval h1 p == p_s)) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.GLV.Lemmas.fst.checked",
"Hacl.Spec.K256.GLV.fst.checked",
"Hacl.K256.Scalar.fsti.checked",
"Hacl.K256.Field.fsti.checked",
"Hacl.Impl.K256.Point.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": true,
"source_file": "Hacl.Impl.K256.GLV.Constants.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV.Lemmas",
"short_module": "SGL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV",
"short_module": "SG"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV",
"short_module": "SG"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | k: Hacl.K256.Scalar.qelem -> p: Hacl.Impl.K256.Point.point -> FStar.HyperStack.ST.Stack Prims.bool | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.K256.Scalar.qelem",
"Hacl.Impl.K256.Point.point",
"Prims.bool",
"Prims.unit",
"Hacl.Impl.K256.Point.point_negate_conditional_vartime",
"Hacl.K256.Scalar.qnegate_conditional_vartime",
"Prims.op_Negation",
"Hacl.K256.Scalar.is_qelem_le_q_halved_vartime"
] | [] | false | true | false | false | false | let negate_point_and_scalar_cond_vartime k p =
| let b = is_qelem_le_q_halved_vartime k in
[@@ inline_let ]let if_high = not b in
qnegate_conditional_vartime k if_high;
point_negate_conditional_vartime p if_high;
if_high | false |
Hacl.Impl.K256.GLV.Constants.fst | Hacl.Impl.K256.GLV.Constants.point_mul_lambda_and_split_lambda | val point_mul_lambda_and_split_lambda:
r1:qelem -> r2:qelem -> lambda_q:point -> scalar:qelem -> q:point -> Stack unit
(requires fun h ->
live h r1 /\ live h r2 /\ live h lambda_q /\ live h scalar /\ live h q /\
disjoint r1 r2 /\ disjoint r1 lambda_q /\ disjoint r1 scalar /\ disjoint r1 q /\
disjoint r2 lambda_q /\ disjoint r2 scalar /\ disjoint r2 q /\
disjoint lambda_q scalar /\ disjoint lambda_q q /\
point_inv h q /\ qas_nat h scalar < S.q)
(ensures fun h0 _ h1 -> modifies (loc r1 |+| loc r2 |+| loc lambda_q) h0 h1 /\
point_inv h1 lambda_q /\
point_eval h1 lambda_q == SG.point_mul_lambda (point_eval h0 q) /\
(let r1_s, r2_s = SG.scalar_split_lambda (qas_nat h0 scalar) in
qas_nat h1 r1 == r1_s /\ qas_nat h1 r2 == r2_s)) | val point_mul_lambda_and_split_lambda:
r1:qelem -> r2:qelem -> lambda_q:point -> scalar:qelem -> q:point -> Stack unit
(requires fun h ->
live h r1 /\ live h r2 /\ live h lambda_q /\ live h scalar /\ live h q /\
disjoint r1 r2 /\ disjoint r1 lambda_q /\ disjoint r1 scalar /\ disjoint r1 q /\
disjoint r2 lambda_q /\ disjoint r2 scalar /\ disjoint r2 q /\
disjoint lambda_q scalar /\ disjoint lambda_q q /\
point_inv h q /\ qas_nat h scalar < S.q)
(ensures fun h0 _ h1 -> modifies (loc r1 |+| loc r2 |+| loc lambda_q) h0 h1 /\
point_inv h1 lambda_q /\
point_eval h1 lambda_q == SG.point_mul_lambda (point_eval h0 q) /\
(let r1_s, r2_s = SG.scalar_split_lambda (qas_nat h0 scalar) in
qas_nat h1 r1 == r1_s /\ qas_nat h1 r2 == r2_s)) | let point_mul_lambda_and_split_lambda r1 r2 lambda_q scalar q =
scalar_split_lambda r1 r2 scalar; // (r1 + r2 * lambda) % S.q = scalar
point_mul_lambda lambda_q q | {
"file_name": "code/k256/Hacl.Impl.K256.GLV.Constants.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 238,
"start_col": 0,
"start_line": 236
} | module Hacl.Impl.K256.GLV.Constants
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module S = Spec.K256
module SG = Hacl.Spec.K256.GLV
module SGL = Hacl.Spec.K256.GLV.Lemmas
open Hacl.K256.Field
open Hacl.K256.Scalar
open Hacl.Impl.K256.Point
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val make_minus_lambda: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_lambda)
let make_minus_lambda f =
[@inline_let]
let x =
(u64 0xe0cfc810b51283cf,
u64 0xa880b9fc8ec739c2,
u64 0x5ad9e3fd77ed9ba4,
u64 0xac9c52b33fa3cf1f) in
assert_norm (SG.minus_lambda == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_beta: f:felem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
as_nat h1 f == SG.beta /\ inv_fully_reduced h1 f)
let make_beta f =
[@inline_let]
let x =
(u64 0x96c28719501ee,
u64 0x7512f58995c13,
u64 0xc3434e99cf049,
u64 0x7106e64479ea,
u64 0x7ae96a2b657c) in
assert_norm (0x96c28719501ee <= max52);
assert_norm (0x7ae96a2b657c <= max48);
assert_norm (SG.beta == as_nat5 x);
make_u52_5 f x
inline_for_extraction noextract
val make_minus_b1: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_b1)
let make_minus_b1 f =
[@inline_let]
let x =
(u64 0x6f547fa90abfe4c3,
u64 0xe4437ed6010e8828,
u64 0x0,
u64 0x0) in
assert_norm (SG.minus_b1 == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_minus_b2: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_b2)
let make_minus_b2 f =
[@inline_let]
let x =
(u64 0xd765cda83db1562c,
u64 0x8a280ac50774346d,
u64 0xfffffffffffffffe,
u64 0xffffffffffffffff) in
assert_norm (SG.minus_b2 == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_g1: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.g1)
let make_g1 f =
[@inline_let]
let x =
(u64 0xe893209a45dbb031,
u64 0x3daa8a1471e8ca7f,
u64 0xe86c90e49284eb15,
u64 0x3086d221a7d46bcd) in
assert_norm (SG.g1 == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_g2: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.g2)
let make_g2 f =
[@inline_let]
let x =
(u64 0x1571b4ae8ac47f71,
u64 0x221208ac9df506c6,
u64 0x6f547fa90abfe4c4,
u64 0xe4437ed6010e8828) in
assert_norm (SG.g2 == qas_nat4 x);
make_u64_4 f x
(**
Representing a scalar k as (r1 + r2 * lambda) mod S.q,
s.t. r1 and r2 are ~128 bits long
*)
inline_for_extraction noextract
val scalar_split_lambda_g1g2 (tmp1 tmp2 r1 r2 k: qelem) : Stack unit
(requires fun h ->
live h k /\ live h r1 /\ live h r2 /\
live h tmp1 /\ live h tmp2 /\
disjoint k r1 /\ disjoint k r2 /\ disjoint r1 r2 /\
disjoint tmp1 r1 /\ disjoint tmp1 r2 /\ disjoint tmp1 k /\
disjoint tmp2 r1 /\ disjoint tmp2 r2 /\ disjoint tmp2 k /\
disjoint tmp1 tmp2 /\ qas_nat h k < S.q)
(ensures fun h0 _ h1 ->
modifies (loc r1 |+| loc r2 |+| loc tmp1 |+| loc tmp2) h0 h1 /\
(let r1 = qas_nat h1 r1 in let r2 = qas_nat h1 r2 in
r1 < S.q /\ r1 = SG.qmul_shift_384 (qas_nat h0 k) SG.g1 /\
r2 < S.q /\ r2 = SG.qmul_shift_384 (qas_nat h0 k) SG.g2))
let scalar_split_lambda_g1g2 tmp1 tmp2 r1 r2 k =
make_g1 tmp1; // tmp1 = g1
make_g2 tmp2; // tmp2 = g2
qmul_shift_384 r1 k tmp1; // r1 = c1 = qmul_shift_384 k g1
qmul_shift_384 r2 k tmp2; // r2 = c2 = qmul_shift_384 k g2
let h0 = ST.get () in
SG.qmul_shift_384_lemma (qas_nat h0 k) (qas_nat h0 tmp1);
SG.qmul_shift_384_lemma (qas_nat h0 k) (qas_nat h0 tmp2);
assert (qas_nat h0 r1 < S.q /\ qas_nat h0 r2 < S.q)
// k = (r1 + lambda * k2) % S.q
val scalar_split_lambda (r1 r2 k: qelem) : Stack unit
(requires fun h ->
live h k /\ live h r1 /\ live h r2 /\
disjoint k r1 /\ disjoint k r2 /\ disjoint r1 r2 /\
qas_nat h k < S.q)
(ensures fun h0 _ h1 -> modifies (loc r1 |+| loc r2) h0 h1 /\
(let r1_s, r2_s = SG.scalar_split_lambda (qas_nat h0 k) in
qas_nat h1 r1 == r1_s /\ qas_nat h1 r2 == r2_s))
[@CInline]
let scalar_split_lambda r1 r2 k =
push_frame ();
let tmp1 = create_qelem () in
let tmp2 = create_qelem () in
scalar_split_lambda_g1g2 tmp1 tmp2 r1 r2 k;
make_minus_b1 tmp1; // tmp1 = minus_b1
make_minus_b2 tmp2; // tmp2 = minus_b2
qmul r1 r1 tmp1; // r1 = c1 = c1 * minus_b1
qmul r2 r2 tmp2; // r2 = c2 = c2 * minus_b2
make_minus_lambda tmp1; // tmp1 = minus_lambda
qadd r2 r1 r2; // r2 = r2 = c1 + c2
qmul tmp2 r2 tmp1; // tmp2 = r2 * minus_lambda
qadd r1 k tmp2; // r1 = r1 = k + r2 * minus_lambda
pop_frame ()
(**
Fast computation of [lambda]P as (beta * px, py, pz) in projective coordinates
*)
[@CInline]
let point_mul_lambda res p =
push_frame ();
let rx, ry, rz = getx res, gety res, getz res in
let px, py, pz = getx p, gety p, getz p in
let beta = create_felem () in
make_beta beta;
fmul rx beta px;
copy_felem ry py;
copy_felem rz pz;
pop_frame ()
[@CInline]
let point_mul_lambda_inplace res =
push_frame ();
let rx, ry, rz = getx res, gety res, getz res in
let beta = create_felem () in
make_beta beta;
fmul rx beta rx;
pop_frame ()
inline_for_extraction noextract
val point_mul_lambda_and_split_lambda:
r1:qelem -> r2:qelem -> lambda_q:point -> scalar:qelem -> q:point -> Stack unit
(requires fun h ->
live h r1 /\ live h r2 /\ live h lambda_q /\ live h scalar /\ live h q /\
disjoint r1 r2 /\ disjoint r1 lambda_q /\ disjoint r1 scalar /\ disjoint r1 q /\
disjoint r2 lambda_q /\ disjoint r2 scalar /\ disjoint r2 q /\
disjoint lambda_q scalar /\ disjoint lambda_q q /\
point_inv h q /\ qas_nat h scalar < S.q)
(ensures fun h0 _ h1 -> modifies (loc r1 |+| loc r2 |+| loc lambda_q) h0 h1 /\
point_inv h1 lambda_q /\
point_eval h1 lambda_q == SG.point_mul_lambda (point_eval h0 q) /\
(let r1_s, r2_s = SG.scalar_split_lambda (qas_nat h0 scalar) in
qas_nat h1 r1 == r1_s /\ qas_nat h1 r2 == r2_s)) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.GLV.Lemmas.fst.checked",
"Hacl.Spec.K256.GLV.fst.checked",
"Hacl.K256.Scalar.fsti.checked",
"Hacl.K256.Field.fsti.checked",
"Hacl.Impl.K256.Point.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": true,
"source_file": "Hacl.Impl.K256.GLV.Constants.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV.Lemmas",
"short_module": "SGL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV",
"short_module": "SG"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV",
"short_module": "SG"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
r1: Hacl.K256.Scalar.qelem ->
r2: Hacl.K256.Scalar.qelem ->
lambda_q: Hacl.Impl.K256.Point.point ->
scalar: Hacl.K256.Scalar.qelem ->
q: Hacl.Impl.K256.Point.point
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.K256.Scalar.qelem",
"Hacl.Impl.K256.Point.point",
"Hacl.Impl.K256.GLV.Constants.point_mul_lambda",
"Prims.unit",
"Hacl.Impl.K256.GLV.Constants.scalar_split_lambda"
] | [] | false | true | false | false | false | let point_mul_lambda_and_split_lambda r1 r2 lambda_q scalar q =
| scalar_split_lambda r1 r2 scalar;
point_mul_lambda lambda_q q | false |
Hacl.Impl.K256.GLV.Constants.fst | Hacl.Impl.K256.GLV.Constants.point_mul_lambda_inplace | val point_mul_lambda_inplace: res:point -> Stack unit
(requires fun h ->
live h res /\ point_inv h res)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
point_inv h1 res /\
point_eval h1 res == SG.point_mul_lambda (point_eval h0 res)) | val point_mul_lambda_inplace: res:point -> Stack unit
(requires fun h ->
live h res /\ point_inv h res)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
point_inv h1 res /\
point_eval h1 res == SG.point_mul_lambda (point_eval h0 res)) | let point_mul_lambda_inplace res =
push_frame ();
let rx, ry, rz = getx res, gety res, getz res in
let beta = create_felem () in
make_beta beta;
fmul rx beta rx;
pop_frame () | {
"file_name": "code/k256/Hacl.Impl.K256.GLV.Constants.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 14,
"end_line": 218,
"start_col": 0,
"start_line": 212
} | module Hacl.Impl.K256.GLV.Constants
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module S = Spec.K256
module SG = Hacl.Spec.K256.GLV
module SGL = Hacl.Spec.K256.GLV.Lemmas
open Hacl.K256.Field
open Hacl.K256.Scalar
open Hacl.Impl.K256.Point
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val make_minus_lambda: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_lambda)
let make_minus_lambda f =
[@inline_let]
let x =
(u64 0xe0cfc810b51283cf,
u64 0xa880b9fc8ec739c2,
u64 0x5ad9e3fd77ed9ba4,
u64 0xac9c52b33fa3cf1f) in
assert_norm (SG.minus_lambda == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_beta: f:felem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
as_nat h1 f == SG.beta /\ inv_fully_reduced h1 f)
let make_beta f =
[@inline_let]
let x =
(u64 0x96c28719501ee,
u64 0x7512f58995c13,
u64 0xc3434e99cf049,
u64 0x7106e64479ea,
u64 0x7ae96a2b657c) in
assert_norm (0x96c28719501ee <= max52);
assert_norm (0x7ae96a2b657c <= max48);
assert_norm (SG.beta == as_nat5 x);
make_u52_5 f x
inline_for_extraction noextract
val make_minus_b1: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_b1)
let make_minus_b1 f =
[@inline_let]
let x =
(u64 0x6f547fa90abfe4c3,
u64 0xe4437ed6010e8828,
u64 0x0,
u64 0x0) in
assert_norm (SG.minus_b1 == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_minus_b2: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_b2)
let make_minus_b2 f =
[@inline_let]
let x =
(u64 0xd765cda83db1562c,
u64 0x8a280ac50774346d,
u64 0xfffffffffffffffe,
u64 0xffffffffffffffff) in
assert_norm (SG.minus_b2 == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_g1: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.g1)
let make_g1 f =
[@inline_let]
let x =
(u64 0xe893209a45dbb031,
u64 0x3daa8a1471e8ca7f,
u64 0xe86c90e49284eb15,
u64 0x3086d221a7d46bcd) in
assert_norm (SG.g1 == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_g2: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.g2)
let make_g2 f =
[@inline_let]
let x =
(u64 0x1571b4ae8ac47f71,
u64 0x221208ac9df506c6,
u64 0x6f547fa90abfe4c4,
u64 0xe4437ed6010e8828) in
assert_norm (SG.g2 == qas_nat4 x);
make_u64_4 f x
(**
Representing a scalar k as (r1 + r2 * lambda) mod S.q,
s.t. r1 and r2 are ~128 bits long
*)
inline_for_extraction noextract
val scalar_split_lambda_g1g2 (tmp1 tmp2 r1 r2 k: qelem) : Stack unit
(requires fun h ->
live h k /\ live h r1 /\ live h r2 /\
live h tmp1 /\ live h tmp2 /\
disjoint k r1 /\ disjoint k r2 /\ disjoint r1 r2 /\
disjoint tmp1 r1 /\ disjoint tmp1 r2 /\ disjoint tmp1 k /\
disjoint tmp2 r1 /\ disjoint tmp2 r2 /\ disjoint tmp2 k /\
disjoint tmp1 tmp2 /\ qas_nat h k < S.q)
(ensures fun h0 _ h1 ->
modifies (loc r1 |+| loc r2 |+| loc tmp1 |+| loc tmp2) h0 h1 /\
(let r1 = qas_nat h1 r1 in let r2 = qas_nat h1 r2 in
r1 < S.q /\ r1 = SG.qmul_shift_384 (qas_nat h0 k) SG.g1 /\
r2 < S.q /\ r2 = SG.qmul_shift_384 (qas_nat h0 k) SG.g2))
let scalar_split_lambda_g1g2 tmp1 tmp2 r1 r2 k =
make_g1 tmp1; // tmp1 = g1
make_g2 tmp2; // tmp2 = g2
qmul_shift_384 r1 k tmp1; // r1 = c1 = qmul_shift_384 k g1
qmul_shift_384 r2 k tmp2; // r2 = c2 = qmul_shift_384 k g2
let h0 = ST.get () in
SG.qmul_shift_384_lemma (qas_nat h0 k) (qas_nat h0 tmp1);
SG.qmul_shift_384_lemma (qas_nat h0 k) (qas_nat h0 tmp2);
assert (qas_nat h0 r1 < S.q /\ qas_nat h0 r2 < S.q)
// k = (r1 + lambda * k2) % S.q
val scalar_split_lambda (r1 r2 k: qelem) : Stack unit
(requires fun h ->
live h k /\ live h r1 /\ live h r2 /\
disjoint k r1 /\ disjoint k r2 /\ disjoint r1 r2 /\
qas_nat h k < S.q)
(ensures fun h0 _ h1 -> modifies (loc r1 |+| loc r2) h0 h1 /\
(let r1_s, r2_s = SG.scalar_split_lambda (qas_nat h0 k) in
qas_nat h1 r1 == r1_s /\ qas_nat h1 r2 == r2_s))
[@CInline]
let scalar_split_lambda r1 r2 k =
push_frame ();
let tmp1 = create_qelem () in
let tmp2 = create_qelem () in
scalar_split_lambda_g1g2 tmp1 tmp2 r1 r2 k;
make_minus_b1 tmp1; // tmp1 = minus_b1
make_minus_b2 tmp2; // tmp2 = minus_b2
qmul r1 r1 tmp1; // r1 = c1 = c1 * minus_b1
qmul r2 r2 tmp2; // r2 = c2 = c2 * minus_b2
make_minus_lambda tmp1; // tmp1 = minus_lambda
qadd r2 r1 r2; // r2 = r2 = c1 + c2
qmul tmp2 r2 tmp1; // tmp2 = r2 * minus_lambda
qadd r1 k tmp2; // r1 = r1 = k + r2 * minus_lambda
pop_frame ()
(**
Fast computation of [lambda]P as (beta * px, py, pz) in projective coordinates
*)
[@CInline]
let point_mul_lambda res p =
push_frame ();
let rx, ry, rz = getx res, gety res, getz res in
let px, py, pz = getx p, gety p, getz p in
let beta = create_felem () in
make_beta beta;
fmul rx beta px;
copy_felem ry py;
copy_felem rz pz;
pop_frame () | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.GLV.Lemmas.fst.checked",
"Hacl.Spec.K256.GLV.fst.checked",
"Hacl.K256.Scalar.fsti.checked",
"Hacl.K256.Field.fsti.checked",
"Hacl.Impl.K256.Point.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": true,
"source_file": "Hacl.Impl.K256.GLV.Constants.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV.Lemmas",
"short_module": "SGL"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV",
"short_module": "SG"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | res: Hacl.Impl.K256.Point.point -> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.K256.Point.point",
"Hacl.K256.Field.felem",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Hacl.K256.Field.fmul",
"Hacl.Impl.K256.GLV.Constants.make_beta",
"Hacl.K256.Field.create_felem",
"FStar.Pervasives.Native.tuple3",
"FStar.Pervasives.Native.Mktuple3",
"Hacl.Impl.K256.Point.getz",
"Hacl.Impl.K256.Point.gety",
"Hacl.Impl.K256.Point.getx",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let point_mul_lambda_inplace res =
| push_frame ();
let rx, ry, rz = getx res, gety res, getz res in
let beta = create_felem () in
make_beta beta;
fmul rx beta rx;
pop_frame () | false |
Hacl.Impl.K256.GLV.Constants.fst | Hacl.Impl.K256.GLV.Constants.ecmult_endo_split | val ecmult_endo_split:
r1:qelem -> r2:qelem
-> q1:point -> q2:point
-> scalar:qelem -> q:point -> Stack (bool & bool)
(requires fun h ->
live h r1 /\ live h r2 /\ live h q1 /\
live h q2 /\ live h scalar /\ live h q /\
disjoint r1 r2 /\ disjoint r1 q1 /\ disjoint r1 q2 /\
disjoint r1 scalar /\ disjoint r1 q /\ disjoint r2 q1 /\
disjoint r2 q2 /\ disjoint r2 scalar /\ disjoint r2 q /\
disjoint q1 q2 /\ disjoint q1 scalar /\ disjoint q1 q /\
disjoint q2 scalar /\ disjoint q2 q /\
point_inv h q /\ qas_nat h scalar < S.q)
(ensures fun h0 (is_high1, is_high2) h1 ->
modifies (loc r1 |+| loc r2 |+| loc q1 |+| loc q2) h0 h1 /\
point_inv h1 q1 /\ point_inv h1 q2 /\
(let r1_s0, r2_s0 = SG.scalar_split_lambda (qas_nat h0 scalar) in
let r1_s, q1_s, r2_s, q2_s = SG.ecmult_endo_split (qas_nat h0 scalar) (point_eval h0 q) in
qas_nat h1 r1 == r1_s /\ qas_nat h1 r2 == r2_s /\
point_eval h1 q1 == q1_s /\ point_eval h1 q2 == q2_s /\
is_high1 == S.scalar_is_high r1_s0 /\
is_high2 == S.scalar_is_high r2_s0)) | val ecmult_endo_split:
r1:qelem -> r2:qelem
-> q1:point -> q2:point
-> scalar:qelem -> q:point -> Stack (bool & bool)
(requires fun h ->
live h r1 /\ live h r2 /\ live h q1 /\
live h q2 /\ live h scalar /\ live h q /\
disjoint r1 r2 /\ disjoint r1 q1 /\ disjoint r1 q2 /\
disjoint r1 scalar /\ disjoint r1 q /\ disjoint r2 q1 /\
disjoint r2 q2 /\ disjoint r2 scalar /\ disjoint r2 q /\
disjoint q1 q2 /\ disjoint q1 scalar /\ disjoint q1 q /\
disjoint q2 scalar /\ disjoint q2 q /\
point_inv h q /\ qas_nat h scalar < S.q)
(ensures fun h0 (is_high1, is_high2) h1 ->
modifies (loc r1 |+| loc r2 |+| loc q1 |+| loc q2) h0 h1 /\
point_inv h1 q1 /\ point_inv h1 q2 /\
(let r1_s0, r2_s0 = SG.scalar_split_lambda (qas_nat h0 scalar) in
let r1_s, q1_s, r2_s, q2_s = SG.ecmult_endo_split (qas_nat h0 scalar) (point_eval h0 q) in
qas_nat h1 r1 == r1_s /\ qas_nat h1 r2 == r2_s /\
point_eval h1 q1 == q1_s /\ point_eval h1 q2 == q2_s /\
is_high1 == S.scalar_is_high r1_s0 /\
is_high2 == S.scalar_is_high r2_s0)) | let ecmult_endo_split r1 r2 q1 q2 scalar q =
let h0 = ST.get () in
// modifies r1, r2, q2 s.t. r1 + r2 * lambda = scalar /\ q2 = [lambda]q
point_mul_lambda_and_split_lambda r1 r2 q2 scalar q;
copy q1 q; // q1 = q
// modifies r1, q1
let is_high1 = negate_point_and_scalar_cond_vartime r1 q1 in
// modifies r2, q2
let is_high2 = negate_point_and_scalar_cond_vartime r2 q2 in
is_high1, is_high2 | {
"file_name": "code/k256/Hacl.Impl.K256.GLV.Constants.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 20,
"end_line": 269,
"start_col": 0,
"start_line": 260
} | module Hacl.Impl.K256.GLV.Constants
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module S = Spec.K256
module SG = Hacl.Spec.K256.GLV
module SGL = Hacl.Spec.K256.GLV.Lemmas
open Hacl.K256.Field
open Hacl.K256.Scalar
open Hacl.Impl.K256.Point
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val make_minus_lambda: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_lambda)
let make_minus_lambda f =
[@inline_let]
let x =
(u64 0xe0cfc810b51283cf,
u64 0xa880b9fc8ec739c2,
u64 0x5ad9e3fd77ed9ba4,
u64 0xac9c52b33fa3cf1f) in
assert_norm (SG.minus_lambda == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_beta: f:felem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
as_nat h1 f == SG.beta /\ inv_fully_reduced h1 f)
let make_beta f =
[@inline_let]
let x =
(u64 0x96c28719501ee,
u64 0x7512f58995c13,
u64 0xc3434e99cf049,
u64 0x7106e64479ea,
u64 0x7ae96a2b657c) in
assert_norm (0x96c28719501ee <= max52);
assert_norm (0x7ae96a2b657c <= max48);
assert_norm (SG.beta == as_nat5 x);
make_u52_5 f x
inline_for_extraction noextract
val make_minus_b1: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_b1)
let make_minus_b1 f =
[@inline_let]
let x =
(u64 0x6f547fa90abfe4c3,
u64 0xe4437ed6010e8828,
u64 0x0,
u64 0x0) in
assert_norm (SG.minus_b1 == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_minus_b2: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_b2)
let make_minus_b2 f =
[@inline_let]
let x =
(u64 0xd765cda83db1562c,
u64 0x8a280ac50774346d,
u64 0xfffffffffffffffe,
u64 0xffffffffffffffff) in
assert_norm (SG.minus_b2 == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_g1: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.g1)
let make_g1 f =
[@inline_let]
let x =
(u64 0xe893209a45dbb031,
u64 0x3daa8a1471e8ca7f,
u64 0xe86c90e49284eb15,
u64 0x3086d221a7d46bcd) in
assert_norm (SG.g1 == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_g2: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.g2)
let make_g2 f =
[@inline_let]
let x =
(u64 0x1571b4ae8ac47f71,
u64 0x221208ac9df506c6,
u64 0x6f547fa90abfe4c4,
u64 0xe4437ed6010e8828) in
assert_norm (SG.g2 == qas_nat4 x);
make_u64_4 f x
(**
Representing a scalar k as (r1 + r2 * lambda) mod S.q,
s.t. r1 and r2 are ~128 bits long
*)
inline_for_extraction noextract
val scalar_split_lambda_g1g2 (tmp1 tmp2 r1 r2 k: qelem) : Stack unit
(requires fun h ->
live h k /\ live h r1 /\ live h r2 /\
live h tmp1 /\ live h tmp2 /\
disjoint k r1 /\ disjoint k r2 /\ disjoint r1 r2 /\
disjoint tmp1 r1 /\ disjoint tmp1 r2 /\ disjoint tmp1 k /\
disjoint tmp2 r1 /\ disjoint tmp2 r2 /\ disjoint tmp2 k /\
disjoint tmp1 tmp2 /\ qas_nat h k < S.q)
(ensures fun h0 _ h1 ->
modifies (loc r1 |+| loc r2 |+| loc tmp1 |+| loc tmp2) h0 h1 /\
(let r1 = qas_nat h1 r1 in let r2 = qas_nat h1 r2 in
r1 < S.q /\ r1 = SG.qmul_shift_384 (qas_nat h0 k) SG.g1 /\
r2 < S.q /\ r2 = SG.qmul_shift_384 (qas_nat h0 k) SG.g2))
let scalar_split_lambda_g1g2 tmp1 tmp2 r1 r2 k =
make_g1 tmp1; // tmp1 = g1
make_g2 tmp2; // tmp2 = g2
qmul_shift_384 r1 k tmp1; // r1 = c1 = qmul_shift_384 k g1
qmul_shift_384 r2 k tmp2; // r2 = c2 = qmul_shift_384 k g2
let h0 = ST.get () in
SG.qmul_shift_384_lemma (qas_nat h0 k) (qas_nat h0 tmp1);
SG.qmul_shift_384_lemma (qas_nat h0 k) (qas_nat h0 tmp2);
assert (qas_nat h0 r1 < S.q /\ qas_nat h0 r2 < S.q)
// k = (r1 + lambda * k2) % S.q
val scalar_split_lambda (r1 r2 k: qelem) : Stack unit
(requires fun h ->
live h k /\ live h r1 /\ live h r2 /\
disjoint k r1 /\ disjoint k r2 /\ disjoint r1 r2 /\
qas_nat h k < S.q)
(ensures fun h0 _ h1 -> modifies (loc r1 |+| loc r2) h0 h1 /\
(let r1_s, r2_s = SG.scalar_split_lambda (qas_nat h0 k) in
qas_nat h1 r1 == r1_s /\ qas_nat h1 r2 == r2_s))
[@CInline]
let scalar_split_lambda r1 r2 k =
push_frame ();
let tmp1 = create_qelem () in
let tmp2 = create_qelem () in
scalar_split_lambda_g1g2 tmp1 tmp2 r1 r2 k;
make_minus_b1 tmp1; // tmp1 = minus_b1
make_minus_b2 tmp2; // tmp2 = minus_b2
qmul r1 r1 tmp1; // r1 = c1 = c1 * minus_b1
qmul r2 r2 tmp2; // r2 = c2 = c2 * minus_b2
make_minus_lambda tmp1; // tmp1 = minus_lambda
qadd r2 r1 r2; // r2 = r2 = c1 + c2
qmul tmp2 r2 tmp1; // tmp2 = r2 * minus_lambda
qadd r1 k tmp2; // r1 = r1 = k + r2 * minus_lambda
pop_frame ()
(**
Fast computation of [lambda]P as (beta * px, py, pz) in projective coordinates
*)
[@CInline]
let point_mul_lambda res p =
push_frame ();
let rx, ry, rz = getx res, gety res, getz res in
let px, py, pz = getx p, gety p, getz p in
let beta = create_felem () in
make_beta beta;
fmul rx beta px;
copy_felem ry py;
copy_felem rz pz;
pop_frame ()
[@CInline]
let point_mul_lambda_inplace res =
push_frame ();
let rx, ry, rz = getx res, gety res, getz res in
let beta = create_felem () in
make_beta beta;
fmul rx beta rx;
pop_frame ()
inline_for_extraction noextract
val point_mul_lambda_and_split_lambda:
r1:qelem -> r2:qelem -> lambda_q:point -> scalar:qelem -> q:point -> Stack unit
(requires fun h ->
live h r1 /\ live h r2 /\ live h lambda_q /\ live h scalar /\ live h q /\
disjoint r1 r2 /\ disjoint r1 lambda_q /\ disjoint r1 scalar /\ disjoint r1 q /\
disjoint r2 lambda_q /\ disjoint r2 scalar /\ disjoint r2 q /\
disjoint lambda_q scalar /\ disjoint lambda_q q /\
point_inv h q /\ qas_nat h scalar < S.q)
(ensures fun h0 _ h1 -> modifies (loc r1 |+| loc r2 |+| loc lambda_q) h0 h1 /\
point_inv h1 lambda_q /\
point_eval h1 lambda_q == SG.point_mul_lambda (point_eval h0 q) /\
(let r1_s, r2_s = SG.scalar_split_lambda (qas_nat h0 scalar) in
qas_nat h1 r1 == r1_s /\ qas_nat h1 r2 == r2_s))
let point_mul_lambda_and_split_lambda r1 r2 lambda_q scalar q =
scalar_split_lambda r1 r2 scalar; // (r1 + r2 * lambda) % S.q = scalar
point_mul_lambda lambda_q q // lambda_q = [lambda]Q
inline_for_extraction noextract
val negate_point_and_scalar_cond_vartime: k:qelem -> p:point -> Stack bool
(requires fun h ->
live h k /\ live h p /\ disjoint k p /\
qas_nat h k < S.q /\ point_inv h p)
(ensures fun h0 b h1 -> modifies (loc k |+| loc p) h0 h1 /\
b == S.scalar_is_high (qas_nat h0 k) /\ point_inv h1 p /\
(let k_s, p_s = SG.negate_point_and_scalar_cond (qas_nat h0 k) (point_eval h0 p) in
qas_nat h1 k == k_s /\ point_eval h1 p == p_s))
let negate_point_and_scalar_cond_vartime k p =
let b = is_qelem_le_q_halved_vartime k in
[@inline_let] let if_high = not b in
qnegate_conditional_vartime k if_high;
point_negate_conditional_vartime p if_high;
if_high | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.GLV.Lemmas.fst.checked",
"Hacl.Spec.K256.GLV.fst.checked",
"Hacl.K256.Scalar.fsti.checked",
"Hacl.K256.Field.fsti.checked",
"Hacl.Impl.K256.Point.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": true,
"source_file": "Hacl.Impl.K256.GLV.Constants.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV.Lemmas",
"short_module": "SGL"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV",
"short_module": "SG"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
r1: Hacl.K256.Scalar.qelem ->
r2: Hacl.K256.Scalar.qelem ->
q1: Hacl.Impl.K256.Point.point ->
q2: Hacl.Impl.K256.Point.point ->
scalar: Hacl.K256.Scalar.qelem ->
q: Hacl.Impl.K256.Point.point
-> FStar.HyperStack.ST.Stack (Prims.bool * Prims.bool) | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.K256.Scalar.qelem",
"Hacl.Impl.K256.Point.point",
"FStar.Pervasives.Native.Mktuple2",
"Prims.bool",
"FStar.Pervasives.Native.tuple2",
"Hacl.Impl.K256.GLV.Constants.negate_point_and_scalar_cond_vartime",
"Prims.unit",
"Lib.Buffer.copy",
"Lib.Buffer.MUT",
"Lib.IntTypes.uint64",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.K256.GLV.Constants.point_mul_lambda_and_split_lambda",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | false | true | false | false | false | let ecmult_endo_split r1 r2 q1 q2 scalar q =
| let h0 = ST.get () in
point_mul_lambda_and_split_lambda r1 r2 q2 scalar q;
copy q1 q;
let is_high1 = negate_point_and_scalar_cond_vartime r1 q1 in
let is_high2 = negate_point_and_scalar_cond_vartime r2 q2 in
is_high1, is_high2 | false |
Hacl.Impl.K256.GLV.Constants.fst | Hacl.Impl.K256.GLV.Constants.point_mul_lambda | val point_mul_lambda: res:point -> p:point -> Stack unit
(requires fun h ->
live h res /\ live h p /\ eq_or_disjoint res p /\
point_inv h p)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
point_inv h1 res /\
point_eval h1 res == SG.point_mul_lambda (point_eval h0 p)) | val point_mul_lambda: res:point -> p:point -> Stack unit
(requires fun h ->
live h res /\ live h p /\ eq_or_disjoint res p /\
point_inv h p)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
point_inv h1 res /\
point_eval h1 res == SG.point_mul_lambda (point_eval h0 p)) | let point_mul_lambda res p =
push_frame ();
let rx, ry, rz = getx res, gety res, getz res in
let px, py, pz = getx p, gety p, getz p in
let beta = create_felem () in
make_beta beta;
fmul rx beta px;
copy_felem ry py;
copy_felem rz pz;
pop_frame () | {
"file_name": "code/k256/Hacl.Impl.K256.GLV.Constants.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 14,
"end_line": 208,
"start_col": 0,
"start_line": 198
} | module Hacl.Impl.K256.GLV.Constants
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module S = Spec.K256
module SG = Hacl.Spec.K256.GLV
module SGL = Hacl.Spec.K256.GLV.Lemmas
open Hacl.K256.Field
open Hacl.K256.Scalar
open Hacl.Impl.K256.Point
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val make_minus_lambda: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_lambda)
let make_minus_lambda f =
[@inline_let]
let x =
(u64 0xe0cfc810b51283cf,
u64 0xa880b9fc8ec739c2,
u64 0x5ad9e3fd77ed9ba4,
u64 0xac9c52b33fa3cf1f) in
assert_norm (SG.minus_lambda == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_beta: f:felem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
as_nat h1 f == SG.beta /\ inv_fully_reduced h1 f)
let make_beta f =
[@inline_let]
let x =
(u64 0x96c28719501ee,
u64 0x7512f58995c13,
u64 0xc3434e99cf049,
u64 0x7106e64479ea,
u64 0x7ae96a2b657c) in
assert_norm (0x96c28719501ee <= max52);
assert_norm (0x7ae96a2b657c <= max48);
assert_norm (SG.beta == as_nat5 x);
make_u52_5 f x
inline_for_extraction noextract
val make_minus_b1: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_b1)
let make_minus_b1 f =
[@inline_let]
let x =
(u64 0x6f547fa90abfe4c3,
u64 0xe4437ed6010e8828,
u64 0x0,
u64 0x0) in
assert_norm (SG.minus_b1 == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_minus_b2: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_b2)
let make_minus_b2 f =
[@inline_let]
let x =
(u64 0xd765cda83db1562c,
u64 0x8a280ac50774346d,
u64 0xfffffffffffffffe,
u64 0xffffffffffffffff) in
assert_norm (SG.minus_b2 == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_g1: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.g1)
let make_g1 f =
[@inline_let]
let x =
(u64 0xe893209a45dbb031,
u64 0x3daa8a1471e8ca7f,
u64 0xe86c90e49284eb15,
u64 0x3086d221a7d46bcd) in
assert_norm (SG.g1 == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_g2: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.g2)
let make_g2 f =
[@inline_let]
let x =
(u64 0x1571b4ae8ac47f71,
u64 0x221208ac9df506c6,
u64 0x6f547fa90abfe4c4,
u64 0xe4437ed6010e8828) in
assert_norm (SG.g2 == qas_nat4 x);
make_u64_4 f x
(**
Representing a scalar k as (r1 + r2 * lambda) mod S.q,
s.t. r1 and r2 are ~128 bits long
*)
inline_for_extraction noextract
val scalar_split_lambda_g1g2 (tmp1 tmp2 r1 r2 k: qelem) : Stack unit
(requires fun h ->
live h k /\ live h r1 /\ live h r2 /\
live h tmp1 /\ live h tmp2 /\
disjoint k r1 /\ disjoint k r2 /\ disjoint r1 r2 /\
disjoint tmp1 r1 /\ disjoint tmp1 r2 /\ disjoint tmp1 k /\
disjoint tmp2 r1 /\ disjoint tmp2 r2 /\ disjoint tmp2 k /\
disjoint tmp1 tmp2 /\ qas_nat h k < S.q)
(ensures fun h0 _ h1 ->
modifies (loc r1 |+| loc r2 |+| loc tmp1 |+| loc tmp2) h0 h1 /\
(let r1 = qas_nat h1 r1 in let r2 = qas_nat h1 r2 in
r1 < S.q /\ r1 = SG.qmul_shift_384 (qas_nat h0 k) SG.g1 /\
r2 < S.q /\ r2 = SG.qmul_shift_384 (qas_nat h0 k) SG.g2))
let scalar_split_lambda_g1g2 tmp1 tmp2 r1 r2 k =
make_g1 tmp1; // tmp1 = g1
make_g2 tmp2; // tmp2 = g2
qmul_shift_384 r1 k tmp1; // r1 = c1 = qmul_shift_384 k g1
qmul_shift_384 r2 k tmp2; // r2 = c2 = qmul_shift_384 k g2
let h0 = ST.get () in
SG.qmul_shift_384_lemma (qas_nat h0 k) (qas_nat h0 tmp1);
SG.qmul_shift_384_lemma (qas_nat h0 k) (qas_nat h0 tmp2);
assert (qas_nat h0 r1 < S.q /\ qas_nat h0 r2 < S.q)
// k = (r1 + lambda * k2) % S.q
val scalar_split_lambda (r1 r2 k: qelem) : Stack unit
(requires fun h ->
live h k /\ live h r1 /\ live h r2 /\
disjoint k r1 /\ disjoint k r2 /\ disjoint r1 r2 /\
qas_nat h k < S.q)
(ensures fun h0 _ h1 -> modifies (loc r1 |+| loc r2) h0 h1 /\
(let r1_s, r2_s = SG.scalar_split_lambda (qas_nat h0 k) in
qas_nat h1 r1 == r1_s /\ qas_nat h1 r2 == r2_s))
[@CInline]
let scalar_split_lambda r1 r2 k =
push_frame ();
let tmp1 = create_qelem () in
let tmp2 = create_qelem () in
scalar_split_lambda_g1g2 tmp1 tmp2 r1 r2 k;
make_minus_b1 tmp1; // tmp1 = minus_b1
make_minus_b2 tmp2; // tmp2 = minus_b2
qmul r1 r1 tmp1; // r1 = c1 = c1 * minus_b1
qmul r2 r2 tmp2; // r2 = c2 = c2 * minus_b2
make_minus_lambda tmp1; // tmp1 = minus_lambda
qadd r2 r1 r2; // r2 = r2 = c1 + c2
qmul tmp2 r2 tmp1; // tmp2 = r2 * minus_lambda
qadd r1 k tmp2; // r1 = r1 = k + r2 * minus_lambda
pop_frame ()
(**
Fast computation of [lambda]P as (beta * px, py, pz) in projective coordinates
*) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.GLV.Lemmas.fst.checked",
"Hacl.Spec.K256.GLV.fst.checked",
"Hacl.K256.Scalar.fsti.checked",
"Hacl.K256.Field.fsti.checked",
"Hacl.Impl.K256.Point.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": true,
"source_file": "Hacl.Impl.K256.GLV.Constants.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV.Lemmas",
"short_module": "SGL"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV",
"short_module": "SG"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | res: Hacl.Impl.K256.Point.point -> p: Hacl.Impl.K256.Point.point
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.K256.Point.point",
"Hacl.K256.Field.felem",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Hacl.K256.Field.copy_felem",
"Hacl.K256.Field.fmul",
"Hacl.Impl.K256.GLV.Constants.make_beta",
"Hacl.K256.Field.create_felem",
"FStar.Pervasives.Native.tuple3",
"FStar.Pervasives.Native.Mktuple3",
"Hacl.Impl.K256.Point.getz",
"Hacl.Impl.K256.Point.gety",
"Hacl.Impl.K256.Point.getx",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let point_mul_lambda res p =
| push_frame ();
let rx, ry, rz = getx res, gety res, getz res in
let px, py, pz = getx p, gety p, getz p in
let beta = create_felem () in
make_beta beta;
fmul rx beta px;
copy_felem ry py;
copy_felem rz pz;
pop_frame () | false |
Vale.Wrapper.X64.Poly.fsti | Vale.Wrapper.X64.Poly.uint64 | val uint64 : Prims.eqtype | let uint64 = UInt64.t | {
"file_name": "vale/code/arch/x64/interop/Vale.Wrapper.X64.Poly.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 21,
"end_line": 19,
"start_col": 0,
"start_line": 19
} | module Vale.Wrapper.X64.Poly
open FStar.HyperStack.ST
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
module HS = FStar.HyperStack
open FStar.Mul
open Vale.Poly1305.Util
open Vale.Poly1305.Math
open Vale.Poly1305.Spec_s
open Vale.Def.Types_s
open Vale.Interop.Base
module MH = Vale.AsLowStar.MemoryHelpers
unfold
let uint8_p = B.buffer UInt8.t | {
"checked_file": "/",
"dependencies": [
"Vale.Poly1305.Util.fsti.checked",
"Vale.Poly1305.Spec_s.fst.checked",
"Vale.Poly1305.Math.fsti.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.AsLowStar.MemoryHelpers.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Wrapper.X64.Poly.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": "MH"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Spec_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.eqtype | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt64.t"
] | [] | false | false | false | true | false | let uint64 =
| UInt64.t | false |
|
Vale.Wrapper.X64.Poly.fsti | Vale.Wrapper.X64.Poly.uint8_p | val uint8_p : Type0 | let uint8_p = B.buffer UInt8.t | {
"file_name": "vale/code/arch/x64/interop/Vale.Wrapper.X64.Poly.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 30,
"end_line": 17,
"start_col": 0,
"start_line": 17
} | module Vale.Wrapper.X64.Poly
open FStar.HyperStack.ST
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
module HS = FStar.HyperStack
open FStar.Mul
open Vale.Poly1305.Util
open Vale.Poly1305.Math
open Vale.Poly1305.Spec_s
open Vale.Def.Types_s
open Vale.Interop.Base
module MH = Vale.AsLowStar.MemoryHelpers | {
"checked_file": "/",
"dependencies": [
"Vale.Poly1305.Util.fsti.checked",
"Vale.Poly1305.Spec_s.fst.checked",
"Vale.Poly1305.Math.fsti.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.AsLowStar.MemoryHelpers.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Wrapper.X64.Poly.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": "MH"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Spec_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"LowStar.Buffer.buffer",
"FStar.UInt8.t"
] | [] | false | false | false | true | true | let uint8_p =
| B.buffer UInt8.t | false |
|
Hacl.Impl.K256.GLV.Constants.fst | Hacl.Impl.K256.GLV.Constants.scalar_split_lambda | val scalar_split_lambda (r1 r2 k: qelem) : Stack unit
(requires fun h ->
live h k /\ live h r1 /\ live h r2 /\
disjoint k r1 /\ disjoint k r2 /\ disjoint r1 r2 /\
qas_nat h k < S.q)
(ensures fun h0 _ h1 -> modifies (loc r1 |+| loc r2) h0 h1 /\
(let r1_s, r2_s = SG.scalar_split_lambda (qas_nat h0 k) in
qas_nat h1 r1 == r1_s /\ qas_nat h1 r2 == r2_s)) | val scalar_split_lambda (r1 r2 k: qelem) : Stack unit
(requires fun h ->
live h k /\ live h r1 /\ live h r2 /\
disjoint k r1 /\ disjoint k r2 /\ disjoint r1 r2 /\
qas_nat h k < S.q)
(ensures fun h0 _ h1 -> modifies (loc r1 |+| loc r2) h0 h1 /\
(let r1_s, r2_s = SG.scalar_split_lambda (qas_nat h0 k) in
qas_nat h1 r1 == r1_s /\ qas_nat h1 r2 == r2_s)) | let scalar_split_lambda r1 r2 k =
push_frame ();
let tmp1 = create_qelem () in
let tmp2 = create_qelem () in
scalar_split_lambda_g1g2 tmp1 tmp2 r1 r2 k;
make_minus_b1 tmp1; // tmp1 = minus_b1
make_minus_b2 tmp2; // tmp2 = minus_b2
qmul r1 r1 tmp1; // r1 = c1 = c1 * minus_b1
qmul r2 r2 tmp2; // r2 = c2 = c2 * minus_b2
make_minus_lambda tmp1; // tmp1 = minus_lambda
qadd r2 r1 r2; // r2 = r2 = c1 + c2
qmul tmp2 r2 tmp1; // tmp2 = r2 * minus_lambda
qadd r1 k tmp2; // r1 = r1 = k + r2 * minus_lambda
pop_frame () | {
"file_name": "code/k256/Hacl.Impl.K256.GLV.Constants.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 14,
"end_line": 190,
"start_col": 0,
"start_line": 175
} | module Hacl.Impl.K256.GLV.Constants
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module S = Spec.K256
module SG = Hacl.Spec.K256.GLV
module SGL = Hacl.Spec.K256.GLV.Lemmas
open Hacl.K256.Field
open Hacl.K256.Scalar
open Hacl.Impl.K256.Point
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val make_minus_lambda: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_lambda)
let make_minus_lambda f =
[@inline_let]
let x =
(u64 0xe0cfc810b51283cf,
u64 0xa880b9fc8ec739c2,
u64 0x5ad9e3fd77ed9ba4,
u64 0xac9c52b33fa3cf1f) in
assert_norm (SG.minus_lambda == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_beta: f:felem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
as_nat h1 f == SG.beta /\ inv_fully_reduced h1 f)
let make_beta f =
[@inline_let]
let x =
(u64 0x96c28719501ee,
u64 0x7512f58995c13,
u64 0xc3434e99cf049,
u64 0x7106e64479ea,
u64 0x7ae96a2b657c) in
assert_norm (0x96c28719501ee <= max52);
assert_norm (0x7ae96a2b657c <= max48);
assert_norm (SG.beta == as_nat5 x);
make_u52_5 f x
inline_for_extraction noextract
val make_minus_b1: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_b1)
let make_minus_b1 f =
[@inline_let]
let x =
(u64 0x6f547fa90abfe4c3,
u64 0xe4437ed6010e8828,
u64 0x0,
u64 0x0) in
assert_norm (SG.minus_b1 == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_minus_b2: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.minus_b2)
let make_minus_b2 f =
[@inline_let]
let x =
(u64 0xd765cda83db1562c,
u64 0x8a280ac50774346d,
u64 0xfffffffffffffffe,
u64 0xffffffffffffffff) in
assert_norm (SG.minus_b2 == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_g1: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.g1)
let make_g1 f =
[@inline_let]
let x =
(u64 0xe893209a45dbb031,
u64 0x3daa8a1471e8ca7f,
u64 0xe86c90e49284eb15,
u64 0x3086d221a7d46bcd) in
assert_norm (SG.g1 == qas_nat4 x);
make_u64_4 f x
inline_for_extraction noextract
val make_g2: f:qelem -> Stack unit
(requires fun h -> live h f)
(ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
qas_nat h1 f == SG.g2)
let make_g2 f =
[@inline_let]
let x =
(u64 0x1571b4ae8ac47f71,
u64 0x221208ac9df506c6,
u64 0x6f547fa90abfe4c4,
u64 0xe4437ed6010e8828) in
assert_norm (SG.g2 == qas_nat4 x);
make_u64_4 f x
(**
Representing a scalar k as (r1 + r2 * lambda) mod S.q,
s.t. r1 and r2 are ~128 bits long
*)
inline_for_extraction noextract
val scalar_split_lambda_g1g2 (tmp1 tmp2 r1 r2 k: qelem) : Stack unit
(requires fun h ->
live h k /\ live h r1 /\ live h r2 /\
live h tmp1 /\ live h tmp2 /\
disjoint k r1 /\ disjoint k r2 /\ disjoint r1 r2 /\
disjoint tmp1 r1 /\ disjoint tmp1 r2 /\ disjoint tmp1 k /\
disjoint tmp2 r1 /\ disjoint tmp2 r2 /\ disjoint tmp2 k /\
disjoint tmp1 tmp2 /\ qas_nat h k < S.q)
(ensures fun h0 _ h1 ->
modifies (loc r1 |+| loc r2 |+| loc tmp1 |+| loc tmp2) h0 h1 /\
(let r1 = qas_nat h1 r1 in let r2 = qas_nat h1 r2 in
r1 < S.q /\ r1 = SG.qmul_shift_384 (qas_nat h0 k) SG.g1 /\
r2 < S.q /\ r2 = SG.qmul_shift_384 (qas_nat h0 k) SG.g2))
let scalar_split_lambda_g1g2 tmp1 tmp2 r1 r2 k =
make_g1 tmp1; // tmp1 = g1
make_g2 tmp2; // tmp2 = g2
qmul_shift_384 r1 k tmp1; // r1 = c1 = qmul_shift_384 k g1
qmul_shift_384 r2 k tmp2; // r2 = c2 = qmul_shift_384 k g2
let h0 = ST.get () in
SG.qmul_shift_384_lemma (qas_nat h0 k) (qas_nat h0 tmp1);
SG.qmul_shift_384_lemma (qas_nat h0 k) (qas_nat h0 tmp2);
assert (qas_nat h0 r1 < S.q /\ qas_nat h0 r2 < S.q)
// k = (r1 + lambda * k2) % S.q
val scalar_split_lambda (r1 r2 k: qelem) : Stack unit
(requires fun h ->
live h k /\ live h r1 /\ live h r2 /\
disjoint k r1 /\ disjoint k r2 /\ disjoint r1 r2 /\
qas_nat h k < S.q)
(ensures fun h0 _ h1 -> modifies (loc r1 |+| loc r2) h0 h1 /\
(let r1_s, r2_s = SG.scalar_split_lambda (qas_nat h0 k) in
qas_nat h1 r1 == r1_s /\ qas_nat h1 r2 == r2_s)) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.GLV.Lemmas.fst.checked",
"Hacl.Spec.K256.GLV.fst.checked",
"Hacl.K256.Scalar.fsti.checked",
"Hacl.K256.Field.fsti.checked",
"Hacl.Impl.K256.Point.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": true,
"source_file": "Hacl.Impl.K256.GLV.Constants.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV.Lemmas",
"short_module": "SGL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV",
"short_module": "SG"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Scalar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.GLV",
"short_module": "SG"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r1: Hacl.K256.Scalar.qelem -> r2: Hacl.K256.Scalar.qelem -> k: Hacl.K256.Scalar.qelem
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.K256.Scalar.qelem",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Hacl.K256.Scalar.qadd",
"Hacl.K256.Scalar.qmul",
"Hacl.Impl.K256.GLV.Constants.make_minus_lambda",
"Hacl.Impl.K256.GLV.Constants.make_minus_b2",
"Hacl.Impl.K256.GLV.Constants.make_minus_b1",
"Hacl.Impl.K256.GLV.Constants.scalar_split_lambda_g1g2",
"Hacl.K256.Scalar.create_qelem",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let scalar_split_lambda r1 r2 k =
| push_frame ();
let tmp1 = create_qelem () in
let tmp2 = create_qelem () in
scalar_split_lambda_g1g2 tmp1 tmp2 r1 r2 k;
make_minus_b1 tmp1;
make_minus_b2 tmp2;
qmul r1 r1 tmp1;
qmul r2 r2 tmp2;
make_minus_lambda tmp1;
qadd r2 r1 r2;
qmul tmp2 r2 tmp1;
qadd r1 k tmp2;
pop_frame () | false |
LowParse.Low.ListUpTo.fst | LowParse.Low.ListUpTo.jump_list_up_to_inv | val jump_list_up_to_inv
(#k #t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p {k.parser_kind_subkind <> Some ParserConsumesAll})
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U32.t)
(h: HS.mem)
(stop: bool)
: GTot Type0 | val jump_list_up_to_inv
(#k #t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p {k.parser_kind_subkind <> Some ParserConsumesAll})
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U32.t)
(h: HS.mem)
(stop: bool)
: GTot Type0 | let jump_list_up_to_inv
(#k: _)
(#t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p { k.parser_kind_subkind <> Some ParserConsumesAll } )
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U32.t)
(h: HS.mem)
(stop: bool)
: GTot Type0
= let pos = B.deref h bpos in
let q = parse_list_up_to cond p prf in
B.live h0 bpos /\
live_slice h0 sl /\
B.loc_disjoint (B.loc_buffer sl.base) (B.loc_buffer bpos) /\
B.modifies (B.loc_buffer bpos) h0 h /\
U32.v pos0 <= U32.v pos /\
valid q h0 sl pos0 /\
begin if stop
then
get_valid_pos q h0 sl pos0 == pos
else
valid q h0 sl pos /\
get_valid_pos q h0 sl pos0 == get_valid_pos q h0 sl pos
end | {
"file_name": "src/lowparse/LowParse.Low.ListUpTo.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 168,
"start_col": 0,
"start_line": 140
} | module LowParse.Low.ListUpTo
include LowParse.Spec.ListUpTo
include LowParse.Low.Base
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
unfold
let validate_list_up_to_inv
(#k: _)
(#t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p { k.parser_kind_subkind <> Some ParserConsumesAll } )
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U64.t)
(h: HS.mem)
(stop: bool)
: GTot Type0
= let pos = B.deref h bpos in
let q = parse_list_up_to cond p prf in
B.live h0 bpos /\
live_slice h0 sl /\
B.loc_disjoint (B.loc_buffer sl.base) (B.loc_buffer bpos) /\
B.modifies (B.loc_buffer bpos) h0 h /\
U32.v pos0 <= U64.v pos /\
begin if is_success pos
then
let pos = uint64_to_uint32 pos in
U32.v pos <= U32.v sl.len /\
begin if stop
then
valid_pos q h0 sl pos0 pos
else
(valid q h0 sl pos0 <==> valid q h0 sl pos) /\
((valid q h0 sl pos0 /\ valid q h0 sl pos) ==>
get_valid_pos q h0 sl pos0 == get_valid_pos q h0 sl pos
)
end
else
stop == true /\
(~ (valid q h0 sl pos0))
end
#push-options "--z3rlimit 16"
inline_for_extraction
let validate_list_up_to_body
(#k: _)
(#t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p { k.parser_kind_subkind <> Some ParserConsumesAll } )
(v: validator p)
(cond_impl: (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
valid p h sl pos /\
res == cond (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U64.t)
: HST.Stack bool
(requires (fun h ->
validate_list_up_to_inv cond prf sl pos0 h0 bpos h false
))
(ensures (fun h stop h' ->
validate_list_up_to_inv cond prf sl pos0 h0 bpos h false /\
validate_list_up_to_inv cond prf sl pos0 h0 bpos h' stop
))
=
let h = HST.get () in
let pos = B.index bpos 0ul in
valid_facts (parse_list_up_to cond p prf) h sl (uint64_to_uint32 pos);
parse_list_up_to_eq cond p prf (bytes_of_slice_from h sl (uint64_to_uint32 pos));
valid_facts p h sl (uint64_to_uint32 pos);
let pos1 = v sl pos in
B.upd bpos 0ul pos1;
if is_error pos1
then
true
else begin
valid_facts (parse_list_up_to cond p prf) h sl (uint64_to_uint32 pos1);
cond_impl sl (uint64_to_uint32 pos)
end
#pop-options
inline_for_extraction
let validate_list_up_to
(#k: _)
(#t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p { k.parser_kind_subkind <> Some ParserConsumesAll } )
(v: validator p)
(cond_impl: (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
valid p h sl pos /\
res == cond (contents p h sl pos)
))
))
: Tot (validator (parse_list_up_to cond p prf))
= fun #rrel #rel sl pos ->
HST.push_frame ();
let bpos = B.alloca pos 1ul in
let h2 = HST.get () in
C.Loops.do_while
(validate_list_up_to_inv cond prf sl (uint64_to_uint32 pos) h2 bpos)
(fun _ -> validate_list_up_to_body cond prf v cond_impl sl (uint64_to_uint32 pos) h2 bpos)
;
let res = B.index bpos 0ul in
HST.pop_frame ();
res | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ListUpTo.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 |
cond: (_: t -> Prims.bool) ->
prf:
LowParse.Spec.ListUpTo.consumes_if_not_cond cond p
{ Mkparser_kind'?.parser_kind_subkind k <>
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserConsumesAll } ->
sl: LowParse.Slice.slice rrel rel ->
pos0: FStar.UInt32.t ->
h0: FStar.Monotonic.HyperStack.mem ->
bpos: LowStar.Buffer.pointer FStar.UInt32.t ->
h: FStar.Monotonic.HyperStack.mem ->
stop: Prims.bool
-> Prims.GTot Type0 | Prims.GTot | [
"sometrivial"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"Prims.bool",
"LowParse.Spec.ListUpTo.consumes_if_not_cond",
"Prims.b2t",
"Prims.op_disEquality",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserConsumesAll",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.Monotonic.HyperStack.mem",
"LowStar.Buffer.pointer",
"Prims.l_and",
"LowStar.Monotonic.Buffer.live",
"LowStar.Buffer.trivial_preorder",
"LowParse.Slice.live_slice",
"LowStar.Monotonic.Buffer.loc_disjoint",
"LowStar.Monotonic.Buffer.loc_buffer",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"LowStar.Monotonic.Buffer.modifies",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"LowParse.Low.Base.Spec.valid",
"LowParse.Spec.ListUpTo.parse_list_up_to_kind",
"LowParse.Spec.ListUpTo.parse_list_up_to_t",
"Prims.eq2",
"LowParse.Low.Base.Spec.get_valid_pos",
"Prims.logical",
"LowParse.Spec.ListUpTo.parse_list_up_to",
"LowStar.Monotonic.Buffer.deref"
] | [] | false | false | false | false | true | let jump_list_up_to_inv
(#k #t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p {k.parser_kind_subkind <> Some ParserConsumesAll})
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U32.t)
(h: HS.mem)
(stop: bool)
: GTot Type0 =
| let pos = B.deref h bpos in
let q = parse_list_up_to cond p prf in
B.live h0 bpos /\ live_slice h0 sl /\ B.loc_disjoint (B.loc_buffer sl.base) (B.loc_buffer bpos) /\
B.modifies (B.loc_buffer bpos) h0 h /\ U32.v pos0 <= U32.v pos /\ valid q h0 sl pos0 /\
(if stop
then get_valid_pos q h0 sl pos0 == pos
else valid q h0 sl pos /\ get_valid_pos q h0 sl pos0 == get_valid_pos q h0 sl pos) | false |
LowParse.Low.ListUpTo.fst | LowParse.Low.ListUpTo.validate_list_up_to_inv | val validate_list_up_to_inv
(#k #t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p {k.parser_kind_subkind <> Some ParserConsumesAll})
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U64.t)
(h: HS.mem)
(stop: bool)
: GTot Type0 | val validate_list_up_to_inv
(#k #t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p {k.parser_kind_subkind <> Some ParserConsumesAll})
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U64.t)
(h: HS.mem)
(stop: bool)
: GTot Type0 | let validate_list_up_to_inv
(#k: _)
(#t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p { k.parser_kind_subkind <> Some ParserConsumesAll } )
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U64.t)
(h: HS.mem)
(stop: bool)
: GTot Type0
= let pos = B.deref h bpos in
let q = parse_list_up_to cond p prf in
B.live h0 bpos /\
live_slice h0 sl /\
B.loc_disjoint (B.loc_buffer sl.base) (B.loc_buffer bpos) /\
B.modifies (B.loc_buffer bpos) h0 h /\
U32.v pos0 <= U64.v pos /\
begin if is_success pos
then
let pos = uint64_to_uint32 pos in
U32.v pos <= U32.v sl.len /\
begin if stop
then
valid_pos q h0 sl pos0 pos
else
(valid q h0 sl pos0 <==> valid q h0 sl pos) /\
((valid q h0 sl pos0 /\ valid q h0 sl pos) ==>
get_valid_pos q h0 sl pos0 == get_valid_pos q h0 sl pos
)
end
else
stop == true /\
(~ (valid q h0 sl pos0))
end | {
"file_name": "src/lowparse/LowParse.Low.ListUpTo.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 49,
"start_col": 0,
"start_line": 12
} | module LowParse.Low.ListUpTo
include LowParse.Spec.ListUpTo
include LowParse.Low.Base
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ListUpTo.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 |
cond: (_: t -> Prims.bool) ->
prf:
LowParse.Spec.ListUpTo.consumes_if_not_cond cond p
{ Mkparser_kind'?.parser_kind_subkind k <>
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserConsumesAll } ->
sl: LowParse.Slice.slice rrel rel ->
pos0: FStar.UInt32.t ->
h0: FStar.Monotonic.HyperStack.mem ->
bpos: LowStar.Buffer.pointer FStar.UInt64.t ->
h: FStar.Monotonic.HyperStack.mem ->
stop: Prims.bool
-> Prims.GTot Type0 | Prims.GTot | [
"sometrivial"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"Prims.bool",
"LowParse.Spec.ListUpTo.consumes_if_not_cond",
"Prims.b2t",
"Prims.op_disEquality",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserConsumesAll",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.Monotonic.HyperStack.mem",
"LowStar.Buffer.pointer",
"FStar.UInt64.t",
"Prims.l_and",
"LowStar.Monotonic.Buffer.live",
"LowStar.Buffer.trivial_preorder",
"LowParse.Slice.live_slice",
"LowStar.Monotonic.Buffer.loc_disjoint",
"LowStar.Monotonic.Buffer.loc_buffer",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"LowStar.Monotonic.Buffer.modifies",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"FStar.UInt64.v",
"LowParse.Low.ErrorCode.is_success",
"LowParse.Slice.__proj__Mkslice__item__len",
"LowParse.Low.Base.Spec.valid_pos",
"LowParse.Spec.ListUpTo.parse_list_up_to_kind",
"LowParse.Spec.ListUpTo.parse_list_up_to_t",
"Prims.l_iff",
"LowParse.Low.Base.Spec.valid",
"Prims.l_imp",
"Prims.eq2",
"LowParse.Low.Base.Spec.get_valid_pos",
"Prims.logical",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"LowParse.Low.ErrorCode.uint64_to_uint32",
"Prims.l_not",
"LowParse.Spec.ListUpTo.parse_list_up_to",
"LowStar.Monotonic.Buffer.deref"
] | [] | false | false | false | false | true | let validate_list_up_to_inv
(#k #t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p {k.parser_kind_subkind <> Some ParserConsumesAll})
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U64.t)
(h: HS.mem)
(stop: bool)
: GTot Type0 =
| let pos = B.deref h bpos in
let q = parse_list_up_to cond p prf in
B.live h0 bpos /\ live_slice h0 sl /\ B.loc_disjoint (B.loc_buffer sl.base) (B.loc_buffer bpos) /\
B.modifies (B.loc_buffer bpos) h0 h /\ U32.v pos0 <= U64.v pos /\
(if is_success pos
then
let pos = uint64_to_uint32 pos in
U32.v pos <= U32.v sl.len /\
(if stop
then valid_pos q h0 sl pos0 pos
else
(valid q h0 sl pos0 <==> valid q h0 sl pos) /\
((valid q h0 sl pos0 /\ valid q h0 sl pos) ==>
get_valid_pos q h0 sl pos0 == get_valid_pos q h0 sl pos))
else stop == true /\ (~(valid q h0 sl pos0))) | false |
MerkleTree.New.High.Correct.Insertion.fst | MerkleTree.New.High.Correct.Insertion.insert_inv_preserved_even | val insert_inv_preserved_even:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
olds:hashess #hsz {S.length olds = 32 /\ mt_olds_inv #hsz lv i olds} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash ->
Lemma (requires (j % 2 <> 1 /\ mt_olds_hs_inv #_ #f lv i j olds hs))
(ensures (mt_olds_hs_inv #_ #f lv i (j + 1) olds (insert_ #_ #f lv i j hs acc)))
(decreases (32 - lv)) | val insert_inv_preserved_even:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
olds:hashess #hsz {S.length olds = 32 /\ mt_olds_inv #hsz lv i olds} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash ->
Lemma (requires (j % 2 <> 1 /\ mt_olds_hs_inv #_ #f lv i j olds hs))
(ensures (mt_olds_hs_inv #_ #f lv i (j + 1) olds (insert_ #_ #f lv i j hs acc)))
(decreases (32 - lv)) | let insert_inv_preserved_even #_ #f lv i j olds hs acc =
let ihs = hashess_insert lv i j hs acc in
mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs;
assert (mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs));
merge_hs_slice_equal #_ #f olds hs olds ihs (lv + 1) 32;
remainder_2_not_1_div j;
insert_base #_ #f lv i j hs acc;
if lv = 31 then ()
else begin
// Facts
assert (S.index (merge_hs #_ #f olds hs) (lv + 1) ==
S.index (merge_hs #_ #f olds ihs) (lv + 1));
// Head proof of `mt_hashes_inv`
mt_hashes_next_rel_insert_even #_ #f j
(S.index (merge_hs #_ #f olds hs) lv) acc
(S.index (merge_hs #_ #f olds hs) (lv + 1));
assert (mt_hashes_next_rel #_ #f (j + 1)
(S.index (merge_hs #_ #f olds ihs) lv)
(S.index (merge_hs #_ #f olds ihs) (lv + 1)));
// Tail proof of `mt_hashes_inv`
mt_hashes_lth_inv_equiv #_ #f (lv + 1) ((j + 1) / 2)
(merge_hs #_ #f olds hs) (merge_hs #_ #f olds ihs);
mt_hashes_inv_equiv #_ #f (lv + 1) ((j + 1) / 2)
(merge_hs #_ #f olds hs) (merge_hs #_ #f olds ihs);
assert (mt_hashes_inv #_ #f (lv + 1) ((j + 1) / 2) (merge_hs #_ #f olds ihs))
end | {
"file_name": "src/MerkleTree.New.High.Correct.Insertion.fst",
"git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} | {
"end_col": 5,
"end_line": 95,
"start_col": 0,
"start_line": 67
} | module MerkleTree.New.High.Correct.Insertion
open EverCrypt
open EverCrypt.Helpers
open FStar.Classical
open FStar.Ghost
open FStar.Seq
module List = FStar.List.Tot
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
type uint32_t = U32.t
type uint8_t = U8.t
module EHS = EverCrypt.Hash
module MTS = MerkleTree.Spec
open MerkleTree.New.High
open MerkleTree.New.High.Correct.Base
/// Correctness of insertion
val mt_hashes_next_rel_insert_odd:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
j:nat{j % 2 = 1} ->
hs:hashes #hsz {S.length hs = j} -> v:hash ->
nhs:hashes #hsz {S.length nhs = j / 2} ->
Lemma (requires (mt_hashes_next_rel #_ #f j hs nhs))
(ensures (mt_hashes_next_rel #_ #f (j + 1)
(S.snoc hs v) (S.snoc nhs (f (S.last hs) v))))
let mt_hashes_next_rel_insert_odd #_ #_ j hs v nhs = ()
val mt_hashes_next_rel_insert_even:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
j:nat{j % 2 <> 1} ->
hs:hashes #hsz {S.length hs = j} -> v:hash ->
nhs:hashes #hsz {S.length nhs = j / 2} ->
Lemma (requires (mt_hashes_next_rel #_ #f j hs nhs))
(ensures (mt_hashes_next_rel #_ #f (j + 1) (S.snoc hs v) nhs))
let mt_hashes_next_rel_insert_even #_ #_ j hs v nhs = ()
val insert_head:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash ->
Lemma (S.equal (S.index (insert_ #_ #f lv i j hs acc) lv)
(S.snoc (S.index hs lv) acc))
let insert_head #_ #_ lv i j hs acc = ()
val insert_inv_preserved_even:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
olds:hashess #hsz {S.length olds = 32 /\ mt_olds_inv #hsz lv i olds} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash ->
Lemma (requires (j % 2 <> 1 /\ mt_olds_hs_inv #_ #f lv i j olds hs))
(ensures (mt_olds_hs_inv #_ #f lv i (j + 1) olds (insert_ #_ #f lv i j hs acc)))
(decreases (32 - lv)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"MerkleTree.New.High.Correct.Base.fst.checked",
"MerkleTree.New.High.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"EverCrypt.Helpers.fsti.checked",
"EverCrypt.Hash.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.Correct.Insertion.fst"
} | [
{
"abbrev": false,
"full_module": "MerkleTree.New.High.Correct.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New.High",
"short_module": null
},
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "EHS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New.High.Correct",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New.High.Correct",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 2,
"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": 120,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
lv: Prims.nat{lv < 32} ->
i: Prims.nat ->
j: Prims.nat{i <= j /\ j < Prims.pow2 (32 - lv) - 1} ->
olds:
MerkleTree.New.High.hashess
{FStar.Seq.Base.length olds = 32 /\ MerkleTree.New.High.Correct.Base.mt_olds_inv lv i olds} ->
hs:
MerkleTree.New.High.hashess
{FStar.Seq.Base.length hs = 32 /\ MerkleTree.New.High.hs_wf_elts lv hs i j} ->
acc: MerkleTree.New.High.hash
-> FStar.Pervasives.Lemma
(requires j % 2 <> 1 /\ MerkleTree.New.High.Correct.Base.mt_olds_hs_inv lv i j olds hs)
(ensures
MerkleTree.New.High.Correct.Base.mt_olds_hs_inv lv
i
(j + 1)
olds
(MerkleTree.New.High.insert_ lv i j hs acc))
(decreases 32 - lv) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.pos",
"MerkleTree.Spec.hash_fun_t",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.pow2",
"MerkleTree.New.High.hashess",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"MerkleTree.New.High.hashes",
"MerkleTree.New.High.Correct.Base.mt_olds_inv",
"MerkleTree.New.High.hs_wf_elts",
"MerkleTree.New.High.hash",
"Prims.bool",
"Prims._assert",
"MerkleTree.New.High.Correct.Base.mt_hashes_inv",
"Prims.op_Addition",
"Prims.op_Division",
"MerkleTree.New.High.Correct.Base.merge_hs",
"Prims.unit",
"MerkleTree.New.High.Correct.Base.mt_hashes_inv_equiv",
"MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_equiv",
"MerkleTree.New.High.Correct.Base.mt_hashes_next_rel",
"FStar.Seq.Base.index",
"MerkleTree.New.High.Correct.Insertion.mt_hashes_next_rel_insert_even",
"Prims.eq2",
"MerkleTree.New.High.insert_base",
"MerkleTree.New.High.remainder_2_not_1_div",
"MerkleTree.New.High.Correct.Base.merge_hs_slice_equal",
"MerkleTree.New.High.Correct.Base.mt_olds_hs_lth_inv_ok",
"MerkleTree.New.High.hashess_insert"
] | [] | false | false | true | false | false | let insert_inv_preserved_even #_ #f lv i j olds hs acc =
| let ihs = hashess_insert lv i j hs acc in
mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs;
assert (mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs));
merge_hs_slice_equal #_ #f olds hs olds ihs (lv + 1) 32;
remainder_2_not_1_div j;
insert_base #_ #f lv i j hs acc;
if lv = 31
then ()
else
(assert (S.index (merge_hs #_ #f olds hs) (lv + 1) == S.index (merge_hs #_ #f olds ihs) (lv + 1));
mt_hashes_next_rel_insert_even #_
#f
j
(S.index (merge_hs #_ #f olds hs) lv)
acc
(S.index (merge_hs #_ #f olds hs) (lv + 1));
assert (mt_hashes_next_rel #_
#f
(j + 1)
(S.index (merge_hs #_ #f olds ihs) lv)
(S.index (merge_hs #_ #f olds ihs) (lv + 1)));
mt_hashes_lth_inv_equiv #_
#f
(lv + 1)
((j + 1) / 2)
(merge_hs #_ #f olds hs)
(merge_hs #_ #f olds ihs);
mt_hashes_inv_equiv #_
#f
(lv + 1)
((j + 1) / 2)
(merge_hs #_ #f olds hs)
(merge_hs #_ #f olds ihs);
assert (mt_hashes_inv #_ #f (lv + 1) ((j + 1) / 2) (merge_hs #_ #f olds ihs))) | false |
LowParse.Low.ListUpTo.fst | LowParse.Low.ListUpTo.jump_list_up_to | val jump_list_up_to
(#k #t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p {k.parser_kind_subkind <> Some ParserConsumesAll})
(j: jumper p)
(cond_impl:
(#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t
-> HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\ valid p h sl pos /\
res == cond (contents p h sl pos)))))
: Tot (jumper (parse_list_up_to cond p prf)) | val jump_list_up_to
(#k #t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p {k.parser_kind_subkind <> Some ParserConsumesAll})
(j: jumper p)
(cond_impl:
(#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t
-> HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\ valid p h sl pos /\
res == cond (contents p h sl pos)))))
: Tot (jumper (parse_list_up_to cond p prf)) | let jump_list_up_to
(#k: _)
(#t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p { k.parser_kind_subkind <> Some ParserConsumesAll } )
(j: jumper p)
(cond_impl: (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
valid p h sl pos /\
res == cond (contents p h sl pos)
))
))
: Tot (jumper (parse_list_up_to cond p prf))
= fun #rrel #rel sl pos ->
HST.push_frame ();
let bpos = B.alloca pos 1ul in
let h2 = HST.get () in
C.Loops.do_while
(jump_list_up_to_inv cond prf sl pos h2 bpos)
(fun _ -> jump_list_up_to_body cond prf j cond_impl sl pos h2 bpos)
;
let res = B.index bpos 0ul in
HST.pop_frame ();
res | {
"file_name": "src/lowparse/LowParse.Low.ListUpTo.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 251,
"start_col": 0,
"start_line": 220
} | module LowParse.Low.ListUpTo
include LowParse.Spec.ListUpTo
include LowParse.Low.Base
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
unfold
let validate_list_up_to_inv
(#k: _)
(#t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p { k.parser_kind_subkind <> Some ParserConsumesAll } )
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U64.t)
(h: HS.mem)
(stop: bool)
: GTot Type0
= let pos = B.deref h bpos in
let q = parse_list_up_to cond p prf in
B.live h0 bpos /\
live_slice h0 sl /\
B.loc_disjoint (B.loc_buffer sl.base) (B.loc_buffer bpos) /\
B.modifies (B.loc_buffer bpos) h0 h /\
U32.v pos0 <= U64.v pos /\
begin if is_success pos
then
let pos = uint64_to_uint32 pos in
U32.v pos <= U32.v sl.len /\
begin if stop
then
valid_pos q h0 sl pos0 pos
else
(valid q h0 sl pos0 <==> valid q h0 sl pos) /\
((valid q h0 sl pos0 /\ valid q h0 sl pos) ==>
get_valid_pos q h0 sl pos0 == get_valid_pos q h0 sl pos
)
end
else
stop == true /\
(~ (valid q h0 sl pos0))
end
#push-options "--z3rlimit 16"
inline_for_extraction
let validate_list_up_to_body
(#k: _)
(#t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p { k.parser_kind_subkind <> Some ParserConsumesAll } )
(v: validator p)
(cond_impl: (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
valid p h sl pos /\
res == cond (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U64.t)
: HST.Stack bool
(requires (fun h ->
validate_list_up_to_inv cond prf sl pos0 h0 bpos h false
))
(ensures (fun h stop h' ->
validate_list_up_to_inv cond prf sl pos0 h0 bpos h false /\
validate_list_up_to_inv cond prf sl pos0 h0 bpos h' stop
))
=
let h = HST.get () in
let pos = B.index bpos 0ul in
valid_facts (parse_list_up_to cond p prf) h sl (uint64_to_uint32 pos);
parse_list_up_to_eq cond p prf (bytes_of_slice_from h sl (uint64_to_uint32 pos));
valid_facts p h sl (uint64_to_uint32 pos);
let pos1 = v sl pos in
B.upd bpos 0ul pos1;
if is_error pos1
then
true
else begin
valid_facts (parse_list_up_to cond p prf) h sl (uint64_to_uint32 pos1);
cond_impl sl (uint64_to_uint32 pos)
end
#pop-options
inline_for_extraction
let validate_list_up_to
(#k: _)
(#t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p { k.parser_kind_subkind <> Some ParserConsumesAll } )
(v: validator p)
(cond_impl: (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
valid p h sl pos /\
res == cond (contents p h sl pos)
))
))
: Tot (validator (parse_list_up_to cond p prf))
= fun #rrel #rel sl pos ->
HST.push_frame ();
let bpos = B.alloca pos 1ul in
let h2 = HST.get () in
C.Loops.do_while
(validate_list_up_to_inv cond prf sl (uint64_to_uint32 pos) h2 bpos)
(fun _ -> validate_list_up_to_body cond prf v cond_impl sl (uint64_to_uint32 pos) h2 bpos)
;
let res = B.index bpos 0ul in
HST.pop_frame ();
res
unfold
let jump_list_up_to_inv
(#k: _)
(#t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p { k.parser_kind_subkind <> Some ParserConsumesAll } )
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U32.t)
(h: HS.mem)
(stop: bool)
: GTot Type0
= let pos = B.deref h bpos in
let q = parse_list_up_to cond p prf in
B.live h0 bpos /\
live_slice h0 sl /\
B.loc_disjoint (B.loc_buffer sl.base) (B.loc_buffer bpos) /\
B.modifies (B.loc_buffer bpos) h0 h /\
U32.v pos0 <= U32.v pos /\
valid q h0 sl pos0 /\
begin if stop
then
get_valid_pos q h0 sl pos0 == pos
else
valid q h0 sl pos /\
get_valid_pos q h0 sl pos0 == get_valid_pos q h0 sl pos
end
#push-options "--z3rlimit 16"
inline_for_extraction
let jump_list_up_to_body
(#k: _)
(#t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p { k.parser_kind_subkind <> Some ParserConsumesAll } )
(j: jumper p)
(cond_impl: (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
valid p h sl pos /\
res == cond (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U32.t)
: HST.Stack bool
(requires (fun h ->
jump_list_up_to_inv cond prf sl pos0 h0 bpos h false
))
(ensures (fun h stop h' ->
jump_list_up_to_inv cond prf sl pos0 h0 bpos h false /\
jump_list_up_to_inv cond prf sl pos0 h0 bpos h' stop
))
=
let h = HST.get () in
let pos = B.index bpos 0ul in
valid_facts (parse_list_up_to cond p prf) h sl pos;
parse_list_up_to_eq cond p prf (bytes_of_slice_from h sl pos);
valid_facts p h sl pos;
let pos1 = j sl pos in
B.upd bpos 0ul pos1;
valid_facts (parse_list_up_to cond p prf) h sl pos1;
cond_impl sl pos
#pop-options | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ListUpTo.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 |
cond: (_: t -> Prims.bool) ->
prf:
LowParse.Spec.ListUpTo.consumes_if_not_cond cond p
{ Mkparser_kind'?.parser_kind_subkind k <>
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserConsumesAll } ->
j: LowParse.Low.Base.jumper p ->
cond_impl:
(sl: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.bool)
-> LowParse.Low.Base.jumper (LowParse.Spec.ListUpTo.parse_list_up_to cond p prf) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"Prims.bool",
"LowParse.Spec.ListUpTo.consumes_if_not_cond",
"Prims.b2t",
"Prims.op_disEquality",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserConsumesAll",
"LowParse.Low.Base.jumper",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Low.Base.Spec.valid",
"Prims.l_and",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_none",
"Prims.eq2",
"LowParse.Low.Base.Spec.contents",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"LowStar.Monotonic.Buffer.index",
"LowStar.Buffer.trivial_preorder",
"FStar.UInt32.__uint_to_t",
"C.Loops.do_while",
"LowParse.Low.ListUpTo.jump_list_up_to_inv",
"LowParse.Low.ListUpTo.jump_list_up_to_body",
"FStar.HyperStack.ST.get",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.nat",
"LowStar.Monotonic.Buffer.length",
"FStar.UInt32.v",
"FStar.UInt32.uint_to_t",
"Prims.op_Negation",
"LowStar.Monotonic.Buffer.g_is_null",
"LowStar.Buffer.alloca",
"FStar.HyperStack.ST.push_frame",
"LowParse.Spec.ListUpTo.parse_list_up_to_kind",
"LowParse.Spec.ListUpTo.parse_list_up_to_t",
"LowParse.Spec.ListUpTo.parse_list_up_to"
] | [] | false | false | false | false | false | let jump_list_up_to
(#k #t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p {k.parser_kind_subkind <> Some ParserConsumesAll})
(j: jumper p)
(cond_impl:
(#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t
-> HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\ valid p h sl pos /\
res == cond (contents p h sl pos)))))
: Tot (jumper (parse_list_up_to cond p prf)) =
| fun #rrel #rel sl pos ->
HST.push_frame ();
let bpos = B.alloca pos 1ul in
let h2 = HST.get () in
C.Loops.do_while (jump_list_up_to_inv cond prf sl pos h2 bpos)
(fun _ -> jump_list_up_to_body cond prf j cond_impl sl pos h2 bpos);
let res = B.index bpos 0ul in
HST.pop_frame ();
res | false |
Vale.Wrapper.X64.Poly.fsti | Vale.Wrapper.X64.Poly.math_aux | val math_aux (b: uint8_p) (n: nat)
: Lemma (requires B.length b = 8 * n) (ensures DV.length (get_downview b) % 8 = 0) | val math_aux (b: uint8_p) (n: nat)
: Lemma (requires B.length b = 8 * n) (ensures DV.length (get_downview b) % 8 = 0) | let math_aux (b:uint8_p) (n:nat) : Lemma
(requires B.length b = 8 * n)
(ensures DV.length (get_downview b) % 8 = 0) =
DV.length_eq (get_downview b) | {
"file_name": "vale/code/arch/x64/interop/Vale.Wrapper.X64.Poly.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 31,
"end_line": 30,
"start_col": 0,
"start_line": 27
} | module Vale.Wrapper.X64.Poly
open FStar.HyperStack.ST
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
module HS = FStar.HyperStack
open FStar.Mul
open Vale.Poly1305.Util
open Vale.Poly1305.Math
open Vale.Poly1305.Spec_s
open Vale.Def.Types_s
open Vale.Interop.Base
module MH = Vale.AsLowStar.MemoryHelpers
unfold
let uint8_p = B.buffer UInt8.t
unfold
let uint64 = UInt64.t
noextract
let uint64_to_nat_seq
(b:Seq.seq UInt64.t)
: Seq.lseq nat64 (Seq.length b)
= Seq.init (Seq.length b) (fun (i:nat{i < Seq.length b}) -> (UInt64.v (Seq.index b i) <: nat64)) | {
"checked_file": "/",
"dependencies": [
"Vale.Poly1305.Util.fsti.checked",
"Vale.Poly1305.Spec_s.fst.checked",
"Vale.Poly1305.Math.fsti.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.AsLowStar.MemoryHelpers.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Wrapper.X64.Poly.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": "MH"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Spec_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Vale.Wrapper.X64.Poly.uint8_p -> n: Prims.nat
-> FStar.Pervasives.Lemma (requires LowStar.Monotonic.Buffer.length b = 8 * n)
(ensures LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview b) % 8 = 0) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Wrapper.X64.Poly.uint8_p",
"Prims.nat",
"LowStar.BufferView.Down.length_eq",
"FStar.UInt8.t",
"Vale.Interop.Types.get_downview",
"Vale.Arch.HeapTypes_s.TUInt8",
"LowStar.Buffer.trivial_preorder",
"Prims.unit",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"LowStar.Monotonic.Buffer.length",
"FStar.Mul.op_Star",
"Prims.squash",
"Prims.op_Modulus",
"LowStar.BufferView.Down.length",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let math_aux (b: uint8_p) (n: nat)
: Lemma (requires B.length b = 8 * n) (ensures DV.length (get_downview b) % 8 = 0) =
| DV.length_eq (get_downview b) | false |
Vale.Wrapper.X64.Poly.fsti | Vale.Wrapper.X64.Poly.uint64_to_nat_seq | val uint64_to_nat_seq (b: Seq.seq UInt64.t) : Seq.lseq nat64 (Seq.length b) | val uint64_to_nat_seq (b: Seq.seq UInt64.t) : Seq.lseq nat64 (Seq.length b) | let uint64_to_nat_seq
(b:Seq.seq UInt64.t)
: Seq.lseq nat64 (Seq.length b)
= Seq.init (Seq.length b) (fun (i:nat{i < Seq.length b}) -> (UInt64.v (Seq.index b i) <: nat64)) | {
"file_name": "vale/code/arch/x64/interop/Vale.Wrapper.X64.Poly.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 100,
"end_line": 25,
"start_col": 0,
"start_line": 22
} | module Vale.Wrapper.X64.Poly
open FStar.HyperStack.ST
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
module HS = FStar.HyperStack
open FStar.Mul
open Vale.Poly1305.Util
open Vale.Poly1305.Math
open Vale.Poly1305.Spec_s
open Vale.Def.Types_s
open Vale.Interop.Base
module MH = Vale.AsLowStar.MemoryHelpers
unfold
let uint8_p = B.buffer UInt8.t
unfold
let uint64 = UInt64.t | {
"checked_file": "/",
"dependencies": [
"Vale.Poly1305.Util.fsti.checked",
"Vale.Poly1305.Spec_s.fst.checked",
"Vale.Poly1305.Math.fsti.checked",
"Vale.Interop.Views.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.AsLowStar.MemoryHelpers.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.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Wrapper.X64.Poly.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": "MH"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Spec_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: FStar.Seq.Base.seq FStar.UInt64.t
-> FStar.Seq.Properties.lseq Vale.Def.Types_s.nat64 (FStar.Seq.Base.length b) | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.seq",
"FStar.UInt64.t",
"FStar.Seq.Base.init",
"Vale.Def.Types_s.nat64",
"FStar.Seq.Base.length",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt64.v",
"FStar.Seq.Base.index",
"FStar.Seq.Properties.lseq"
] | [] | false | false | false | false | false | let uint64_to_nat_seq (b: Seq.seq UInt64.t) : Seq.lseq nat64 (Seq.length b) =
| Seq.init (Seq.length b) (fun (i: nat{i < Seq.length b}) -> (UInt64.v (Seq.index b i) <: nat64)) | false |
LowParse.Low.ListUpTo.fst | LowParse.Low.ListUpTo.validate_list_up_to | val validate_list_up_to
(#k #t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p {k.parser_kind_subkind <> Some ParserConsumesAll})
(v: validator p)
(cond_impl:
(#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t
-> HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\ valid p h sl pos /\
res == cond (contents p h sl pos)))))
: Tot (validator (parse_list_up_to cond p prf)) | val validate_list_up_to
(#k #t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p {k.parser_kind_subkind <> Some ParserConsumesAll})
(v: validator p)
(cond_impl:
(#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t
-> HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\ valid p h sl pos /\
res == cond (contents p h sl pos)))))
: Tot (validator (parse_list_up_to cond p prf)) | let validate_list_up_to
(#k: _)
(#t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p { k.parser_kind_subkind <> Some ParserConsumesAll } )
(v: validator p)
(cond_impl: (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
valid p h sl pos /\
res == cond (contents p h sl pos)
))
))
: Tot (validator (parse_list_up_to cond p prf))
= fun #rrel #rel sl pos ->
HST.push_frame ();
let bpos = B.alloca pos 1ul in
let h2 = HST.get () in
C.Loops.do_while
(validate_list_up_to_inv cond prf sl (uint64_to_uint32 pos) h2 bpos)
(fun _ -> validate_list_up_to_body cond prf v cond_impl sl (uint64_to_uint32 pos) h2 bpos)
;
let res = B.index bpos 0ul in
HST.pop_frame ();
res | {
"file_name": "src/lowparse/LowParse.Low.ListUpTo.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 137,
"start_col": 0,
"start_line": 106
} | module LowParse.Low.ListUpTo
include LowParse.Spec.ListUpTo
include LowParse.Low.Base
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
unfold
let validate_list_up_to_inv
(#k: _)
(#t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p { k.parser_kind_subkind <> Some ParserConsumesAll } )
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U64.t)
(h: HS.mem)
(stop: bool)
: GTot Type0
= let pos = B.deref h bpos in
let q = parse_list_up_to cond p prf in
B.live h0 bpos /\
live_slice h0 sl /\
B.loc_disjoint (B.loc_buffer sl.base) (B.loc_buffer bpos) /\
B.modifies (B.loc_buffer bpos) h0 h /\
U32.v pos0 <= U64.v pos /\
begin if is_success pos
then
let pos = uint64_to_uint32 pos in
U32.v pos <= U32.v sl.len /\
begin if stop
then
valid_pos q h0 sl pos0 pos
else
(valid q h0 sl pos0 <==> valid q h0 sl pos) /\
((valid q h0 sl pos0 /\ valid q h0 sl pos) ==>
get_valid_pos q h0 sl pos0 == get_valid_pos q h0 sl pos
)
end
else
stop == true /\
(~ (valid q h0 sl pos0))
end
#push-options "--z3rlimit 16"
inline_for_extraction
let validate_list_up_to_body
(#k: _)
(#t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p { k.parser_kind_subkind <> Some ParserConsumesAll } )
(v: validator p)
(cond_impl: (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
valid p h sl pos /\
res == cond (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U64.t)
: HST.Stack bool
(requires (fun h ->
validate_list_up_to_inv cond prf sl pos0 h0 bpos h false
))
(ensures (fun h stop h' ->
validate_list_up_to_inv cond prf sl pos0 h0 bpos h false /\
validate_list_up_to_inv cond prf sl pos0 h0 bpos h' stop
))
=
let h = HST.get () in
let pos = B.index bpos 0ul in
valid_facts (parse_list_up_to cond p prf) h sl (uint64_to_uint32 pos);
parse_list_up_to_eq cond p prf (bytes_of_slice_from h sl (uint64_to_uint32 pos));
valid_facts p h sl (uint64_to_uint32 pos);
let pos1 = v sl pos in
B.upd bpos 0ul pos1;
if is_error pos1
then
true
else begin
valid_facts (parse_list_up_to cond p prf) h sl (uint64_to_uint32 pos1);
cond_impl sl (uint64_to_uint32 pos)
end
#pop-options | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ListUpTo.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 |
cond: (_: t -> Prims.bool) ->
prf:
LowParse.Spec.ListUpTo.consumes_if_not_cond cond p
{ Mkparser_kind'?.parser_kind_subkind k <>
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserConsumesAll } ->
v: LowParse.Low.Base.validator p ->
cond_impl:
(sl: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.bool)
-> LowParse.Low.Base.validator (LowParse.Spec.ListUpTo.parse_list_up_to cond p prf) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"Prims.bool",
"LowParse.Spec.ListUpTo.consumes_if_not_cond",
"Prims.b2t",
"Prims.op_disEquality",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserConsumesAll",
"LowParse.Low.Base.validator",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Low.Base.Spec.valid",
"Prims.l_and",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_none",
"Prims.eq2",
"LowParse.Low.Base.Spec.contents",
"FStar.UInt64.t",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"LowStar.Monotonic.Buffer.index",
"LowStar.Buffer.trivial_preorder",
"FStar.UInt32.__uint_to_t",
"C.Loops.do_while",
"LowParse.Low.ListUpTo.validate_list_up_to_inv",
"LowParse.Low.ErrorCode.uint64_to_uint32",
"LowParse.Low.ListUpTo.validate_list_up_to_body",
"FStar.HyperStack.ST.get",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.nat",
"LowStar.Monotonic.Buffer.length",
"FStar.UInt32.v",
"FStar.UInt32.uint_to_t",
"Prims.op_Negation",
"LowStar.Monotonic.Buffer.g_is_null",
"LowStar.Buffer.alloca",
"FStar.HyperStack.ST.push_frame",
"LowParse.Spec.ListUpTo.parse_list_up_to_kind",
"LowParse.Spec.ListUpTo.parse_list_up_to_t",
"LowParse.Spec.ListUpTo.parse_list_up_to"
] | [] | false | false | false | false | false | let validate_list_up_to
(#k #t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p {k.parser_kind_subkind <> Some ParserConsumesAll})
(v: validator p)
(cond_impl:
(#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t
-> HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\ valid p h sl pos /\
res == cond (contents p h sl pos)))))
: Tot (validator (parse_list_up_to cond p prf)) =
| fun #rrel #rel sl pos ->
HST.push_frame ();
let bpos = B.alloca pos 1ul in
let h2 = HST.get () in
C.Loops.do_while (validate_list_up_to_inv cond prf sl (uint64_to_uint32 pos) h2 bpos)
(fun _ -> validate_list_up_to_body cond prf v cond_impl sl (uint64_to_uint32 pos) h2 bpos);
let res = B.index bpos 0ul in
HST.pop_frame ();
res | false |
Vale.AES.GCM_helpers_BE.fsti | Vale.AES.GCM_helpers_BE.bytes_to_quad_size | val bytes_to_quad_size : num_bytes: Prims.nat -> Prims.int | let bytes_to_quad_size (num_bytes:nat) =
((num_bytes + 15) / 16) | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers_BE.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 25,
"end_line": 17,
"start_col": 0,
"start_line": 16
} | module Vale.AES.GCM_helpers_BE
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open FStar.Seq
open Vale.AES.AES_BE_s
open Vale.AES.GCTR_BE_s
open FStar.Math.Lemmas
open Vale.Lib.Seqs | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.GCM_helpers_BE.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | num_bytes: Prims.nat -> Prims.int | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.op_Division",
"Prims.op_Addition",
"Prims.int"
] | [] | false | false | false | true | false | let bytes_to_quad_size (num_bytes: nat) =
| ((num_bytes + 15) / 16) | false |
|
Spec.P256.Lemmas.fst | Spec.P256.Lemmas.lemma_aff_is_point_at_inf | val lemma_aff_is_point_at_inf: p:proj_point ->
Lemma (let px, py, pz = p in
is_aff_point_at_inf (to_aff_point p) == (pz = 0 || (px = 0 && py = 0))) | val lemma_aff_is_point_at_inf: p:proj_point ->
Lemma (let px, py, pz = p in
is_aff_point_at_inf (to_aff_point p) == (pz = 0 || (px = 0 && py = 0))) | let lemma_aff_is_point_at_inf p =
prime_lemma ();
let (px, py, pz) = p in
M.lemma_div_mod_prime_is_zero #prime px pz;
M.lemma_div_mod_prime_is_zero #prime py pz | {
"file_name": "specs/lemmas/Spec.P256.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 16,
"start_col": 0,
"start_line": 12
} | module Spec.P256.Lemmas
open FStar.Mul
open Spec.P256.PointOps
module M = Lib.NatMod
#set-options "--z3rlimit 50 --ifuel 0 --fuel 0"
let prime_lemma () = admit() | {
"checked_file": "/",
"dependencies": [
"Spec.P256.PointOps.fst.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "Spec.P256.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Spec.P256.PointOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Spec.P256.PointOps.proj_point
-> FStar.Pervasives.Lemma
(ensures
(let _ = p in
(let FStar.Pervasives.Native.Mktuple3 #_ #_ #_ px py pz = _ in
Spec.P256.PointOps.is_aff_point_at_inf (Spec.P256.PointOps.to_aff_point p) ==
(pz = 0 || px = 0 && py = 0))
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.P256.PointOps.proj_point",
"Prims.nat",
"Lib.NatMod.lemma_div_mod_prime_is_zero",
"Spec.P256.PointOps.prime",
"Prims.unit",
"Spec.P256.Lemmas.prime_lemma"
] | [] | false | false | true | false | false | let lemma_aff_is_point_at_inf p =
| prime_lemma ();
let px, py, pz = p in
M.lemma_div_mod_prime_is_zero #prime px pz;
M.lemma_div_mod_prime_is_zero #prime py pz | false |
Pulse.C.Types.Fields.fsti | Pulse.C.Types.Fields.field_t | val field_t (#t: Type0) (fd: field_description_t t) : Tot eqtype | val field_t (#t: Type0) (fd: field_description_t t) : Tot eqtype | let field_t (#t: Type0) (fd: field_description_t t) : Tot eqtype = (s: string { fd.fd_def s }) | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Fields.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 94,
"end_line": 30,
"start_col": 0,
"start_line": 30
} | module Pulse.C.Types.Fields
include Pulse.C.Types.Base
open Pulse.C.Typestring
open Pulse.Lib.Pervasives
[@@noextract_to "krml"] // tactic
let norm_fields () : FStar.Tactics.Tac unit =
FStar.Tactics.norm [delta_attr [`%norm_field_attr]; iota; zeta; primops];
FStar.Tactics.trefl ()
[@@noextract_to "krml"] // primitive
val field_t_nil: Type0
[@@noextract_to "krml"] // primitive
val field_t_cons (fn: Type0) (ft: Type0) (fc: Type0): Type0
inline_for_extraction [@@noextract_to "krml"; norm_field_attr]
noeq
type field_description_t (t: Type0) : Type u#1 = {
fd_def: (string -> GTot bool);
fd_empty: (fd_empty: bool { fd_empty == true <==> (forall s . fd_def s == false) });
fd_type: (string -> Type0);
fd_typedef: ((s: string) -> Pure (typedef (fd_type s)) (requires (fd_def s)) (ensures (fun _ -> True)));
}
inline_for_extraction [@@noextract_to "krml"; norm_field_attr]
let nonempty_field_description_t (t: Type0) =
(fd: field_description_t t { fd.fd_empty == false }) | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Typestring.fsti.checked",
"Pulse.C.Types.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Fields.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Typestring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | fd: Pulse.C.Types.Fields.field_description_t t -> Prims.eqtype | Prims.Tot | [
"total"
] | [] | [
"Pulse.C.Types.Fields.field_description_t",
"Prims.string",
"Prims.b2t",
"Pulse.C.Types.Fields.__proj__Mkfield_description_t__item__fd_def",
"Prims.eqtype"
] | [] | false | false | false | true | false | let field_t (#t: Type0) (fd: field_description_t t) : Tot eqtype =
| (s: string{fd.fd_def s}) | false |
Pulse.C.Types.Fields.fsti | Pulse.C.Types.Fields.nonempty_field_description_t | val nonempty_field_description_t : t: Type0 -> Type | let nonempty_field_description_t (t: Type0) =
(fd: field_description_t t { fd.fd_empty == false }) | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Fields.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 54,
"end_line": 27,
"start_col": 0,
"start_line": 26
} | module Pulse.C.Types.Fields
include Pulse.C.Types.Base
open Pulse.C.Typestring
open Pulse.Lib.Pervasives
[@@noextract_to "krml"] // tactic
let norm_fields () : FStar.Tactics.Tac unit =
FStar.Tactics.norm [delta_attr [`%norm_field_attr]; iota; zeta; primops];
FStar.Tactics.trefl ()
[@@noextract_to "krml"] // primitive
val field_t_nil: Type0
[@@noextract_to "krml"] // primitive
val field_t_cons (fn: Type0) (ft: Type0) (fc: Type0): Type0
inline_for_extraction [@@noextract_to "krml"; norm_field_attr]
noeq
type field_description_t (t: Type0) : Type u#1 = {
fd_def: (string -> GTot bool);
fd_empty: (fd_empty: bool { fd_empty == true <==> (forall s . fd_def s == false) });
fd_type: (string -> Type0);
fd_typedef: ((s: string) -> Pure (typedef (fd_type s)) (requires (fd_def s)) (ensures (fun _ -> True)));
} | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Typestring.fsti.checked",
"Pulse.C.Types.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Fields.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Typestring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Type0 -> Type | Prims.Tot | [
"total"
] | [] | [
"Pulse.C.Types.Fields.field_description_t",
"Prims.eq2",
"Prims.bool",
"Pulse.C.Types.Fields.__proj__Mkfield_description_t__item__fd_empty"
] | [] | false | false | false | true | true | let nonempty_field_description_t (t: Type0) =
| (fd: field_description_t t {fd.fd_empty == false}) | false |
|
MerkleTree.New.High.Correct.Insertion.fst | MerkleTree.New.High.Correct.Insertion.insert_inv_preserved | val insert_inv_preserved:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
olds:hashess #hsz {S.length olds = 32 /\ mt_olds_inv #hsz lv i olds} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash ->
Lemma (requires (mt_olds_hs_inv #_ #f lv i j olds hs))
(ensures (mt_olds_hs_inv #_ #f lv i (j + 1) olds (insert_ #_ #f lv i j hs acc)))
(decreases (32 - lv)) | val insert_inv_preserved:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
olds:hashess #hsz {S.length olds = 32 /\ mt_olds_inv #hsz lv i olds} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash ->
Lemma (requires (mt_olds_hs_inv #_ #f lv i j olds hs))
(ensures (mt_olds_hs_inv #_ #f lv i (j + 1) olds (insert_ #_ #f lv i j hs acc)))
(decreases (32 - lv)) | let rec insert_inv_preserved #_ #f lv i j olds hs acc =
if j % 2 = 1
then begin
let ihs = hashess_insert lv i j hs acc in
mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs;
merge_hs_slice_equal #_ #f olds hs olds ihs (lv + 1) 32;
assert (mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs));
remainder_2_1_div j;
insert_rec #_ #f lv i j hs acc;
// Recursion
mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2)
(merge_hs #_ #f olds hs) (merge_hs #_ #f olds ihs);
mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2)
(merge_hs #_ #f olds hs) (merge_hs #_ #f olds ihs);
let nacc = f (S.last (S.index hs lv)) acc in
let rihs = insert_ #_ #f (lv + 1) (i / 2) (j / 2) ihs nacc in
insert_inv_preserved #_ #f (lv + 1) (i / 2) (j / 2) olds ihs nacc;
// Head proof of `mt_hashes_inv`
mt_olds_hs_lth_inv_ok #_ #f lv i (j + 1) olds rihs;
mt_hashes_next_rel_insert_odd #_ #f j
(S.index (merge_hs #_ #f olds hs) lv) acc
(S.index (merge_hs #_ #f olds hs) (lv + 1));
assert (S.equal (S.index rihs lv) (S.index ihs lv));
insert_head #_ #f (lv + 1) (i / 2) (j / 2) ihs nacc;
assert (S.equal (S.index ihs (lv + 1)) (S.index hs (lv + 1)));
assert (mt_hashes_next_rel #_ #f (j + 1)
(S.index (merge_hs #_ #f olds rihs) lv)
(S.index (merge_hs #_ #f olds rihs) (lv + 1)));
// Tail proof of `mt_hashes_inv` by recursion
assert (mt_olds_hs_inv #_ #f (lv + 1) (i / 2) ((j + 1) / 2) olds rihs);
assert (mt_hashes_inv #_ #f lv (j + 1) (merge_hs #_ #f olds rihs));
assert (mt_olds_hs_inv #_ #f lv i (j + 1) olds rihs);
assert (mt_olds_hs_inv #_ #f lv i (j + 1) olds (insert_ #_ #f lv i j hs acc))
end
else begin
insert_inv_preserved_even #_ #f lv i j olds hs acc;
assert (mt_olds_hs_inv #_ #f lv i (j + 1) olds (insert_ #_ #f lv i j hs acc))
end | {
"file_name": "src/MerkleTree.New.High.Correct.Insertion.fst",
"git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} | {
"end_col": 5,
"end_line": 151,
"start_col": 0,
"start_line": 109
} | module MerkleTree.New.High.Correct.Insertion
open EverCrypt
open EverCrypt.Helpers
open FStar.Classical
open FStar.Ghost
open FStar.Seq
module List = FStar.List.Tot
module S = FStar.Seq
module U32 = FStar.UInt32
module U8 = FStar.UInt8
type uint32_t = U32.t
type uint8_t = U8.t
module EHS = EverCrypt.Hash
module MTS = MerkleTree.Spec
open MerkleTree.New.High
open MerkleTree.New.High.Correct.Base
/// Correctness of insertion
val mt_hashes_next_rel_insert_odd:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
j:nat{j % 2 = 1} ->
hs:hashes #hsz {S.length hs = j} -> v:hash ->
nhs:hashes #hsz {S.length nhs = j / 2} ->
Lemma (requires (mt_hashes_next_rel #_ #f j hs nhs))
(ensures (mt_hashes_next_rel #_ #f (j + 1)
(S.snoc hs v) (S.snoc nhs (f (S.last hs) v))))
let mt_hashes_next_rel_insert_odd #_ #_ j hs v nhs = ()
val mt_hashes_next_rel_insert_even:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
j:nat{j % 2 <> 1} ->
hs:hashes #hsz {S.length hs = j} -> v:hash ->
nhs:hashes #hsz {S.length nhs = j / 2} ->
Lemma (requires (mt_hashes_next_rel #_ #f j hs nhs))
(ensures (mt_hashes_next_rel #_ #f (j + 1) (S.snoc hs v) nhs))
let mt_hashes_next_rel_insert_even #_ #_ j hs v nhs = ()
val insert_head:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash ->
Lemma (S.equal (S.index (insert_ #_ #f lv i j hs acc) lv)
(S.snoc (S.index hs lv) acc))
let insert_head #_ #_ lv i j hs acc = ()
val insert_inv_preserved_even:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
olds:hashess #hsz {S.length olds = 32 /\ mt_olds_inv #hsz lv i olds} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash ->
Lemma (requires (j % 2 <> 1 /\ mt_olds_hs_inv #_ #f lv i j olds hs))
(ensures (mt_olds_hs_inv #_ #f lv i (j + 1) olds (insert_ #_ #f lv i j hs acc)))
(decreases (32 - lv))
#reset-options "--z3rlimit 120 --max_fuel 2"
let insert_inv_preserved_even #_ #f lv i j olds hs acc =
let ihs = hashess_insert lv i j hs acc in
mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs;
assert (mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs));
merge_hs_slice_equal #_ #f olds hs olds ihs (lv + 1) 32;
remainder_2_not_1_div j;
insert_base #_ #f lv i j hs acc;
if lv = 31 then ()
else begin
// Facts
assert (S.index (merge_hs #_ #f olds hs) (lv + 1) ==
S.index (merge_hs #_ #f olds ihs) (lv + 1));
// Head proof of `mt_hashes_inv`
mt_hashes_next_rel_insert_even #_ #f j
(S.index (merge_hs #_ #f olds hs) lv) acc
(S.index (merge_hs #_ #f olds hs) (lv + 1));
assert (mt_hashes_next_rel #_ #f (j + 1)
(S.index (merge_hs #_ #f olds ihs) lv)
(S.index (merge_hs #_ #f olds ihs) (lv + 1)));
// Tail proof of `mt_hashes_inv`
mt_hashes_lth_inv_equiv #_ #f (lv + 1) ((j + 1) / 2)
(merge_hs #_ #f olds hs) (merge_hs #_ #f olds ihs);
mt_hashes_inv_equiv #_ #f (lv + 1) ((j + 1) / 2)
(merge_hs #_ #f olds hs) (merge_hs #_ #f olds ihs);
assert (mt_hashes_inv #_ #f (lv + 1) ((j + 1) / 2) (merge_hs #_ #f olds ihs))
end
val insert_inv_preserved:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv < 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv) - 1} ->
olds:hashess #hsz {S.length olds = 32 /\ mt_olds_inv #hsz lv i olds} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
acc:hash ->
Lemma (requires (mt_olds_hs_inv #_ #f lv i j olds hs))
(ensures (mt_olds_hs_inv #_ #f lv i (j + 1) olds (insert_ #_ #f lv i j hs acc)))
(decreases (32 - lv)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"MerkleTree.New.High.Correct.Base.fst.checked",
"MerkleTree.New.High.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"EverCrypt.Helpers.fsti.checked",
"EverCrypt.Hash.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.Correct.Insertion.fst"
} | [
{
"abbrev": false,
"full_module": "MerkleTree.New.High.Correct.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New.High",
"short_module": null
},
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "EHS"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "List"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New.High.Correct",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New.High.Correct",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 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": 240,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
lv: Prims.nat{lv < 32} ->
i: Prims.nat ->
j: Prims.nat{i <= j /\ j < Prims.pow2 (32 - lv) - 1} ->
olds:
MerkleTree.New.High.hashess
{FStar.Seq.Base.length olds = 32 /\ MerkleTree.New.High.Correct.Base.mt_olds_inv lv i olds} ->
hs:
MerkleTree.New.High.hashess
{FStar.Seq.Base.length hs = 32 /\ MerkleTree.New.High.hs_wf_elts lv hs i j} ->
acc: MerkleTree.New.High.hash
-> FStar.Pervasives.Lemma
(requires MerkleTree.New.High.Correct.Base.mt_olds_hs_inv lv i j olds hs)
(ensures
MerkleTree.New.High.Correct.Base.mt_olds_hs_inv lv
i
(j + 1)
olds
(MerkleTree.New.High.insert_ lv i j hs acc))
(decreases 32 - lv) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.pos",
"MerkleTree.Spec.hash_fun_t",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.pow2",
"MerkleTree.New.High.hashess",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"MerkleTree.New.High.hashes",
"MerkleTree.New.High.Correct.Base.mt_olds_inv",
"MerkleTree.New.High.hs_wf_elts",
"MerkleTree.New.High.hash",
"Prims.op_Modulus",
"Prims._assert",
"MerkleTree.New.High.Correct.Base.mt_olds_hs_inv",
"Prims.op_Addition",
"MerkleTree.New.High.insert_",
"Prims.unit",
"MerkleTree.New.High.Correct.Base.mt_hashes_inv",
"MerkleTree.New.High.Correct.Base.merge_hs",
"Prims.op_Division",
"MerkleTree.New.High.Correct.Base.mt_hashes_next_rel",
"FStar.Seq.Base.index",
"FStar.Seq.Base.equal",
"MerkleTree.New.High.Correct.Insertion.insert_head",
"MerkleTree.New.High.Correct.Insertion.mt_hashes_next_rel_insert_odd",
"MerkleTree.New.High.Correct.Base.mt_olds_hs_lth_inv_ok",
"MerkleTree.New.High.Correct.Insertion.insert_inv_preserved",
"FStar.Seq.Base.slice",
"MerkleTree.Spec.hash",
"FStar.Seq.Properties.last",
"MerkleTree.New.High.Correct.Base.mt_hashes_inv_equiv",
"MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_equiv",
"MerkleTree.New.High.insert_rec",
"MerkleTree.New.High.remainder_2_1_div",
"MerkleTree.New.High.Correct.Base.merge_hs_slice_equal",
"MerkleTree.New.High.hashess_insert",
"Prims.bool",
"MerkleTree.New.High.Correct.Insertion.insert_inv_preserved_even"
] | [
"recursion"
] | false | false | true | false | false | let rec insert_inv_preserved #_ #f lv i j olds hs acc =
| if j % 2 = 1
then
let ihs = hashess_insert lv i j hs acc in
mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs;
merge_hs_slice_equal #_ #f olds hs olds ihs (lv + 1) 32;
assert (mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs));
remainder_2_1_div j;
insert_rec #_ #f lv i j hs acc;
mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) (merge_hs #_ #f olds hs) (merge_hs #_ #f olds ihs);
mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) (merge_hs #_ #f olds hs) (merge_hs #_ #f olds ihs);
let nacc = f (S.last (S.index hs lv)) acc in
let rihs = insert_ #_ #f (lv + 1) (i / 2) (j / 2) ihs nacc in
insert_inv_preserved #_ #f (lv + 1) (i / 2) (j / 2) olds ihs nacc;
mt_olds_hs_lth_inv_ok #_ #f lv i (j + 1) olds rihs;
mt_hashes_next_rel_insert_odd #_
#f
j
(S.index (merge_hs #_ #f olds hs) lv)
acc
(S.index (merge_hs #_ #f olds hs) (lv + 1));
assert (S.equal (S.index rihs lv) (S.index ihs lv));
insert_head #_ #f (lv + 1) (i / 2) (j / 2) ihs nacc;
assert (S.equal (S.index ihs (lv + 1)) (S.index hs (lv + 1)));
assert (mt_hashes_next_rel #_
#f
(j + 1)
(S.index (merge_hs #_ #f olds rihs) lv)
(S.index (merge_hs #_ #f olds rihs) (lv + 1)));
assert (mt_olds_hs_inv #_ #f (lv + 1) (i / 2) ((j + 1) / 2) olds rihs);
assert (mt_hashes_inv #_ #f lv (j + 1) (merge_hs #_ #f olds rihs));
assert (mt_olds_hs_inv #_ #f lv i (j + 1) olds rihs);
assert (mt_olds_hs_inv #_ #f lv i (j + 1) olds (insert_ #_ #f lv i j hs acc))
else
(insert_inv_preserved_even #_ #f lv i j olds hs acc;
assert (mt_olds_hs_inv #_ #f lv i (j + 1) olds (insert_ #_ #f lv i j hs acc))) | false |
Pulse.C.Types.Fields.fsti | Pulse.C.Types.Fields.field_description_nil | val field_description_nil:field_description_t field_t_nil | val field_description_nil:field_description_t field_t_nil | let field_description_nil : field_description_t field_t_nil = {
fd_def = (fun _ -> false);
fd_empty = true;
fd_type = (fun _ -> unit);
fd_typedef = (fun _ -> false_elim ());
} | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Fields.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 1,
"end_line": 38,
"start_col": 0,
"start_line": 33
} | module Pulse.C.Types.Fields
include Pulse.C.Types.Base
open Pulse.C.Typestring
open Pulse.Lib.Pervasives
[@@noextract_to "krml"] // tactic
let norm_fields () : FStar.Tactics.Tac unit =
FStar.Tactics.norm [delta_attr [`%norm_field_attr]; iota; zeta; primops];
FStar.Tactics.trefl ()
[@@noextract_to "krml"] // primitive
val field_t_nil: Type0
[@@noextract_to "krml"] // primitive
val field_t_cons (fn: Type0) (ft: Type0) (fc: Type0): Type0
inline_for_extraction [@@noextract_to "krml"; norm_field_attr]
noeq
type field_description_t (t: Type0) : Type u#1 = {
fd_def: (string -> GTot bool);
fd_empty: (fd_empty: bool { fd_empty == true <==> (forall s . fd_def s == false) });
fd_type: (string -> Type0);
fd_typedef: ((s: string) -> Pure (typedef (fd_type s)) (requires (fd_def s)) (ensures (fun _ -> True)));
}
inline_for_extraction [@@noextract_to "krml"; norm_field_attr]
let nonempty_field_description_t (t: Type0) =
(fd: field_description_t t { fd.fd_empty == false })
[@@noextract_to "krml"] // proof-only
let field_t (#t: Type0) (fd: field_description_t t) : Tot eqtype = (s: string { fd.fd_def s }) | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Typestring.fsti.checked",
"Pulse.C.Types.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Fields.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Typestring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | Pulse.C.Types.Fields.field_description_t Pulse.C.Types.Fields.field_t_nil | Prims.Tot | [
"total"
] | [] | [
"Pulse.C.Types.Fields.Mkfield_description_t",
"Pulse.C.Types.Fields.field_t_nil",
"Prims.string",
"Prims.bool",
"Prims.unit",
"FStar.Pervasives.false_elim",
"Pulse.C.Types.Base.typedef"
] | [] | false | false | false | true | false | let field_description_nil:field_description_t field_t_nil =
| {
fd_def = (fun _ -> false);
fd_empty = true;
fd_type = (fun _ -> unit);
fd_typedef = (fun _ -> false_elim ())
} | false |
LowParse.Low.ListUpTo.fst | LowParse.Low.ListUpTo.jump_list_up_to_body | val jump_list_up_to_body
(#k #t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p {k.parser_kind_subkind <> Some ParserConsumesAll})
(j: jumper p)
(cond_impl:
(#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t
-> HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\ valid p h sl pos /\
res == cond (contents p h sl pos)))))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U32.t)
: HST.Stack bool
(requires (fun h -> jump_list_up_to_inv cond prf sl pos0 h0 bpos h false))
(ensures
(fun h stop h' ->
jump_list_up_to_inv cond prf sl pos0 h0 bpos h false /\
jump_list_up_to_inv cond prf sl pos0 h0 bpos h' stop)) | val jump_list_up_to_body
(#k #t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p {k.parser_kind_subkind <> Some ParserConsumesAll})
(j: jumper p)
(cond_impl:
(#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t
-> HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\ valid p h sl pos /\
res == cond (contents p h sl pos)))))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U32.t)
: HST.Stack bool
(requires (fun h -> jump_list_up_to_inv cond prf sl pos0 h0 bpos h false))
(ensures
(fun h stop h' ->
jump_list_up_to_inv cond prf sl pos0 h0 bpos h false /\
jump_list_up_to_inv cond prf sl pos0 h0 bpos h' stop)) | let jump_list_up_to_body
(#k: _)
(#t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p { k.parser_kind_subkind <> Some ParserConsumesAll } )
(j: jumper p)
(cond_impl: (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
valid p h sl pos /\
res == cond (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U32.t)
: HST.Stack bool
(requires (fun h ->
jump_list_up_to_inv cond prf sl pos0 h0 bpos h false
))
(ensures (fun h stop h' ->
jump_list_up_to_inv cond prf sl pos0 h0 bpos h false /\
jump_list_up_to_inv cond prf sl pos0 h0 bpos h' stop
))
=
let h = HST.get () in
let pos = B.index bpos 0ul in
valid_facts (parse_list_up_to cond p prf) h sl pos;
parse_list_up_to_eq cond p prf (bytes_of_slice_from h sl pos);
valid_facts p h sl pos;
let pos1 = j sl pos in
B.upd bpos 0ul pos1;
valid_facts (parse_list_up_to cond p prf) h sl pos1;
cond_impl sl pos | {
"file_name": "src/lowparse/LowParse.Low.ListUpTo.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 18,
"end_line": 215,
"start_col": 0,
"start_line": 173
} | module LowParse.Low.ListUpTo
include LowParse.Spec.ListUpTo
include LowParse.Low.Base
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
unfold
let validate_list_up_to_inv
(#k: _)
(#t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p { k.parser_kind_subkind <> Some ParserConsumesAll } )
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U64.t)
(h: HS.mem)
(stop: bool)
: GTot Type0
= let pos = B.deref h bpos in
let q = parse_list_up_to cond p prf in
B.live h0 bpos /\
live_slice h0 sl /\
B.loc_disjoint (B.loc_buffer sl.base) (B.loc_buffer bpos) /\
B.modifies (B.loc_buffer bpos) h0 h /\
U32.v pos0 <= U64.v pos /\
begin if is_success pos
then
let pos = uint64_to_uint32 pos in
U32.v pos <= U32.v sl.len /\
begin if stop
then
valid_pos q h0 sl pos0 pos
else
(valid q h0 sl pos0 <==> valid q h0 sl pos) /\
((valid q h0 sl pos0 /\ valid q h0 sl pos) ==>
get_valid_pos q h0 sl pos0 == get_valid_pos q h0 sl pos
)
end
else
stop == true /\
(~ (valid q h0 sl pos0))
end
#push-options "--z3rlimit 16"
inline_for_extraction
let validate_list_up_to_body
(#k: _)
(#t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p { k.parser_kind_subkind <> Some ParserConsumesAll } )
(v: validator p)
(cond_impl: (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
valid p h sl pos /\
res == cond (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U64.t)
: HST.Stack bool
(requires (fun h ->
validate_list_up_to_inv cond prf sl pos0 h0 bpos h false
))
(ensures (fun h stop h' ->
validate_list_up_to_inv cond prf sl pos0 h0 bpos h false /\
validate_list_up_to_inv cond prf sl pos0 h0 bpos h' stop
))
=
let h = HST.get () in
let pos = B.index bpos 0ul in
valid_facts (parse_list_up_to cond p prf) h sl (uint64_to_uint32 pos);
parse_list_up_to_eq cond p prf (bytes_of_slice_from h sl (uint64_to_uint32 pos));
valid_facts p h sl (uint64_to_uint32 pos);
let pos1 = v sl pos in
B.upd bpos 0ul pos1;
if is_error pos1
then
true
else begin
valid_facts (parse_list_up_to cond p prf) h sl (uint64_to_uint32 pos1);
cond_impl sl (uint64_to_uint32 pos)
end
#pop-options
inline_for_extraction
let validate_list_up_to
(#k: _)
(#t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p { k.parser_kind_subkind <> Some ParserConsumesAll } )
(v: validator p)
(cond_impl: (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
valid p h sl pos /\
res == cond (contents p h sl pos)
))
))
: Tot (validator (parse_list_up_to cond p prf))
= fun #rrel #rel sl pos ->
HST.push_frame ();
let bpos = B.alloca pos 1ul in
let h2 = HST.get () in
C.Loops.do_while
(validate_list_up_to_inv cond prf sl (uint64_to_uint32 pos) h2 bpos)
(fun _ -> validate_list_up_to_body cond prf v cond_impl sl (uint64_to_uint32 pos) h2 bpos)
;
let res = B.index bpos 0ul in
HST.pop_frame ();
res
unfold
let jump_list_up_to_inv
(#k: _)
(#t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p { k.parser_kind_subkind <> Some ParserConsumesAll } )
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U32.t)
(h: HS.mem)
(stop: bool)
: GTot Type0
= let pos = B.deref h bpos in
let q = parse_list_up_to cond p prf in
B.live h0 bpos /\
live_slice h0 sl /\
B.loc_disjoint (B.loc_buffer sl.base) (B.loc_buffer bpos) /\
B.modifies (B.loc_buffer bpos) h0 h /\
U32.v pos0 <= U32.v pos /\
valid q h0 sl pos0 /\
begin if stop
then
get_valid_pos q h0 sl pos0 == pos
else
valid q h0 sl pos /\
get_valid_pos q h0 sl pos0 == get_valid_pos q h0 sl pos
end
#push-options "--z3rlimit 16" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ListUpTo.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
cond: (_: t -> Prims.bool) ->
prf:
LowParse.Spec.ListUpTo.consumes_if_not_cond cond p
{ Mkparser_kind'?.parser_kind_subkind k <>
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserConsumesAll } ->
j: LowParse.Low.Base.jumper p ->
cond_impl:
(sl: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.bool) ->
sl: LowParse.Slice.slice rrel rel ->
pos0: FStar.UInt32.t ->
h0: FStar.Monotonic.HyperStack.mem ->
bpos: LowStar.Buffer.pointer FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.bool | FStar.HyperStack.ST.Stack | [] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"Prims.bool",
"LowParse.Spec.ListUpTo.consumes_if_not_cond",
"Prims.b2t",
"Prims.op_disEquality",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserConsumesAll",
"LowParse.Low.Base.jumper",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Low.Base.Spec.valid",
"Prims.l_and",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_none",
"Prims.eq2",
"LowParse.Low.Base.Spec.contents",
"LowStar.Buffer.pointer",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.ListUpTo.parse_list_up_to_kind",
"LowParse.Spec.ListUpTo.parse_list_up_to_t",
"LowParse.Spec.ListUpTo.parse_list_up_to",
"LowStar.Monotonic.Buffer.upd",
"LowStar.Buffer.trivial_preorder",
"FStar.UInt32.__uint_to_t",
"LowParse.Spec.ListUpTo.parse_list_up_to_eq",
"LowParse.Slice.bytes_of_slice_from",
"LowStar.Monotonic.Buffer.index",
"FStar.HyperStack.ST.get",
"LowParse.Low.ListUpTo.jump_list_up_to_inv"
] | [] | false | true | false | false | false | let jump_list_up_to_body
(#k #t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p {k.parser_kind_subkind <> Some ParserConsumesAll})
(j: jumper p)
(cond_impl:
(#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t
-> HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\ valid p h sl pos /\
res == cond (contents p h sl pos)))))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U32.t)
: HST.Stack bool
(requires (fun h -> jump_list_up_to_inv cond prf sl pos0 h0 bpos h false))
(ensures
(fun h stop h' ->
jump_list_up_to_inv cond prf sl pos0 h0 bpos h false /\
jump_list_up_to_inv cond prf sl pos0 h0 bpos h' stop)) =
| let h = HST.get () in
let pos = B.index bpos 0ul in
valid_facts (parse_list_up_to cond p prf) h sl pos;
parse_list_up_to_eq cond p prf (bytes_of_slice_from h sl pos);
valid_facts p h sl pos;
let pos1 = j sl pos in
B.upd bpos 0ul pos1;
valid_facts (parse_list_up_to cond p prf) h sl pos1;
cond_impl sl pos | false |
Pulse.C.Types.Fields.fsti | Pulse.C.Types.Fields.norm_fields | val norm_fields: Prims.unit -> FStar.Tactics.Tac unit | val norm_fields: Prims.unit -> FStar.Tactics.Tac unit | let norm_fields () : FStar.Tactics.Tac unit =
FStar.Tactics.norm [delta_attr [`%norm_field_attr]; iota; zeta; primops];
FStar.Tactics.trefl () | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Fields.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 24,
"end_line": 9,
"start_col": 0,
"start_line": 7
} | module Pulse.C.Types.Fields
include Pulse.C.Types.Base
open Pulse.C.Typestring
open Pulse.Lib.Pervasives | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Typestring.fsti.checked",
"Pulse.C.Types.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Fields.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Typestring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"FStar.Tactics.V1.Derived.trefl",
"FStar.Stubs.Tactics.V1.Builtins.norm",
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.delta_attr",
"Prims.string",
"Prims.Nil",
"FStar.Pervasives.iota",
"FStar.Pervasives.zeta",
"FStar.Pervasives.primops"
] | [] | false | true | false | false | false | let norm_fields () : FStar.Tactics.Tac unit =
| FStar.Tactics.norm [delta_attr [`%norm_field_attr]; iota; zeta; primops];
FStar.Tactics.trefl () | false |
LowParse.Low.ListUpTo.fst | LowParse.Low.ListUpTo.validate_list_up_to_body | val validate_list_up_to_body
(#k #t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p {k.parser_kind_subkind <> Some ParserConsumesAll})
(v: validator p)
(cond_impl:
(#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t
-> HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\ valid p h sl pos /\
res == cond (contents p h sl pos)))))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U64.t)
: HST.Stack bool
(requires (fun h -> validate_list_up_to_inv cond prf sl pos0 h0 bpos h false))
(ensures
(fun h stop h' ->
validate_list_up_to_inv cond prf sl pos0 h0 bpos h false /\
validate_list_up_to_inv cond prf sl pos0 h0 bpos h' stop)) | val validate_list_up_to_body
(#k #t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p {k.parser_kind_subkind <> Some ParserConsumesAll})
(v: validator p)
(cond_impl:
(#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t
-> HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\ valid p h sl pos /\
res == cond (contents p h sl pos)))))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U64.t)
: HST.Stack bool
(requires (fun h -> validate_list_up_to_inv cond prf sl pos0 h0 bpos h false))
(ensures
(fun h stop h' ->
validate_list_up_to_inv cond prf sl pos0 h0 bpos h false /\
validate_list_up_to_inv cond prf sl pos0 h0 bpos h' stop)) | let validate_list_up_to_body
(#k: _)
(#t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p { k.parser_kind_subkind <> Some ParserConsumesAll } )
(v: validator p)
(cond_impl: (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
valid p h sl pos /\
res == cond (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U64.t)
: HST.Stack bool
(requires (fun h ->
validate_list_up_to_inv cond prf sl pos0 h0 bpos h false
))
(ensures (fun h stop h' ->
validate_list_up_to_inv cond prf sl pos0 h0 bpos h false /\
validate_list_up_to_inv cond prf sl pos0 h0 bpos h' stop
))
=
let h = HST.get () in
let pos = B.index bpos 0ul in
valid_facts (parse_list_up_to cond p prf) h sl (uint64_to_uint32 pos);
parse_list_up_to_eq cond p prf (bytes_of_slice_from h sl (uint64_to_uint32 pos));
valid_facts p h sl (uint64_to_uint32 pos);
let pos1 = v sl pos in
B.upd bpos 0ul pos1;
if is_error pos1
then
true
else begin
valid_facts (parse_list_up_to cond p prf) h sl (uint64_to_uint32 pos1);
cond_impl sl (uint64_to_uint32 pos)
end | {
"file_name": "src/lowparse/LowParse.Low.ListUpTo.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 101,
"start_col": 0,
"start_line": 54
} | module LowParse.Low.ListUpTo
include LowParse.Spec.ListUpTo
include LowParse.Low.Base
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module B = LowStar.Buffer
unfold
let validate_list_up_to_inv
(#k: _)
(#t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p { k.parser_kind_subkind <> Some ParserConsumesAll } )
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U64.t)
(h: HS.mem)
(stop: bool)
: GTot Type0
= let pos = B.deref h bpos in
let q = parse_list_up_to cond p prf in
B.live h0 bpos /\
live_slice h0 sl /\
B.loc_disjoint (B.loc_buffer sl.base) (B.loc_buffer bpos) /\
B.modifies (B.loc_buffer bpos) h0 h /\
U32.v pos0 <= U64.v pos /\
begin if is_success pos
then
let pos = uint64_to_uint32 pos in
U32.v pos <= U32.v sl.len /\
begin if stop
then
valid_pos q h0 sl pos0 pos
else
(valid q h0 sl pos0 <==> valid q h0 sl pos) /\
((valid q h0 sl pos0 /\ valid q h0 sl pos) ==>
get_valid_pos q h0 sl pos0 == get_valid_pos q h0 sl pos
)
end
else
stop == true /\
(~ (valid q h0 sl pos0))
end
#push-options "--z3rlimit 16" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.ListUpTo.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ListUpTo.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.ListUpTo",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
cond: (_: t -> Prims.bool) ->
prf:
LowParse.Spec.ListUpTo.consumes_if_not_cond cond p
{ Mkparser_kind'?.parser_kind_subkind k <>
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserConsumesAll } ->
v: LowParse.Low.Base.validator p ->
cond_impl:
(sl: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.bool) ->
sl: LowParse.Slice.slice rrel rel ->
pos0: FStar.UInt32.t ->
h0: FStar.Monotonic.HyperStack.mem ->
bpos: LowStar.Buffer.pointer FStar.UInt64.t
-> FStar.HyperStack.ST.Stack Prims.bool | FStar.HyperStack.ST.Stack | [] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"Prims.bool",
"LowParse.Spec.ListUpTo.consumes_if_not_cond",
"Prims.b2t",
"Prims.op_disEquality",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserConsumesAll",
"LowParse.Low.Base.validator",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Low.Base.Spec.valid",
"Prims.l_and",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_none",
"Prims.eq2",
"LowParse.Low.Base.Spec.contents",
"LowStar.Buffer.pointer",
"FStar.UInt64.t",
"LowParse.Low.ErrorCode.is_error",
"LowParse.Low.ErrorCode.uint64_to_uint32",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.ListUpTo.parse_list_up_to_kind",
"LowParse.Spec.ListUpTo.parse_list_up_to_t",
"LowParse.Spec.ListUpTo.parse_list_up_to",
"LowStar.Monotonic.Buffer.upd",
"LowStar.Buffer.trivial_preorder",
"FStar.UInt32.__uint_to_t",
"LowParse.Spec.ListUpTo.parse_list_up_to_eq",
"LowParse.Slice.bytes_of_slice_from",
"LowStar.Monotonic.Buffer.index",
"FStar.HyperStack.ST.get",
"LowParse.Low.ListUpTo.validate_list_up_to_inv"
] | [] | false | true | false | false | false | let validate_list_up_to_body
(#k #t: _)
(#p: parser k t)
(cond: (t -> Tot bool))
(prf: consumes_if_not_cond cond p {k.parser_kind_subkind <> Some ParserConsumesAll})
(v: validator p)
(cond_impl:
(#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t
-> HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\ valid p h sl pos /\
res == cond (contents p h sl pos)))))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos0: U32.t)
(h0: HS.mem)
(bpos: B.pointer U64.t)
: HST.Stack bool
(requires (fun h -> validate_list_up_to_inv cond prf sl pos0 h0 bpos h false))
(ensures
(fun h stop h' ->
validate_list_up_to_inv cond prf sl pos0 h0 bpos h false /\
validate_list_up_to_inv cond prf sl pos0 h0 bpos h' stop)) =
| let h = HST.get () in
let pos = B.index bpos 0ul in
valid_facts (parse_list_up_to cond p prf) h sl (uint64_to_uint32 pos);
parse_list_up_to_eq cond p prf (bytes_of_slice_from h sl (uint64_to_uint32 pos));
valid_facts p h sl (uint64_to_uint32 pos);
let pos1 = v sl pos in
B.upd bpos 0ul pos1;
if is_error pos1
then true
else
(valid_facts (parse_list_up_to cond p prf) h sl (uint64_to_uint32 pos1);
cond_impl sl (uint64_to_uint32 pos)) | false |
Hacl.Spec.K256.ECSM.Lemmas.fst | Hacl.Spec.K256.ECSM.Lemmas.lemma_aff_point_mul_neg_modq | val lemma_aff_point_mul_neg_modq (a:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg a p == aff_point_mul (a % S.q) p) | val lemma_aff_point_mul_neg_modq (a:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg a p == aff_point_mul (a % S.q) p) | let lemma_aff_point_mul_neg_modq a p =
calc (==) {
aff_point_mul_neg a p;
(==) { Math.Lemmas.euclidean_division_definition a S.q }
aff_point_mul_neg (a / S.q * S.q + a % S.q) p;
(==) { lemma_aff_point_mul_neg_add (a / S.q * S.q) (a % S.q) p }
S.aff_point_add (aff_point_mul_neg (a / S.q * S.q) p) (aff_point_mul_neg (a % S.q) p);
(==) { lemma_aff_point_mul_neg_mul (a / S.q) S.q p }
S.aff_point_add
(aff_point_mul S.q (aff_point_mul_neg (a / S.q) p))
(aff_point_mul (a % S.q) p);
(==) { lemma_order_of_curve_group (aff_point_mul_neg (a / S.q) p) }
S.aff_point_add S.aff_point_at_inf (aff_point_mul (a % S.q) p);
(==) { LS.aff_point_add_comm_lemma S.aff_point_at_inf (aff_point_mul (a % S.q) p) }
S.aff_point_add (aff_point_mul (a % S.q) p) S.aff_point_at_inf;
(==) { LS.aff_point_at_inf_lemma (aff_point_mul (a % S.q) p) }
aff_point_mul (a % S.q) p;
} | {
"file_name": "code/k256/Hacl.Spec.K256.ECSM.Lemmas.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 78,
"start_col": 0,
"start_line": 61
} | module Hacl.Spec.K256.ECSM.Lemmas
open FStar.Mul
module M = Lib.NatMod
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module S = Spec.K256
module LS = Spec.K256.Lemmas
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
// [a]P in affine coordinates for a >= 0
let aff_point_mul = S.aff_point_mul
// [a]P in affine coordinates for any a
let aff_point_mul_neg (a:int) (p:S.aff_point) : S.aff_point =
LE.pow_neg S.mk_k256_abelian_group p a
assume
val lemma_order_of_curve_group (p:S.aff_point) :
Lemma (aff_point_mul S.q p == S.aff_point_at_inf)
(**
Properties for Elliptic Curve Scalar Multiplication in affine coordinates
*)
// [a + b]P = [a]P + [b]P
val lemma_aff_point_mul_neg_add (a b:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg (a + b) p ==
S.aff_point_add (aff_point_mul_neg a p) (aff_point_mul_neg b p))
let lemma_aff_point_mul_neg_add a b p =
LE.lemma_pow_neg_add S.mk_k256_abelian_group p a b
// [a * b]P = [b]([a]P)
val lemma_aff_point_mul_neg_mul (a b:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg (a * b) p == aff_point_mul_neg b (aff_point_mul_neg a p))
let lemma_aff_point_mul_neg_mul a b p =
LE.lemma_pow_neg_mul S.mk_k256_abelian_group p a b
// [a * b + c]P = [b]([a]P) + [c]P
val lemma_aff_point_mul_neg_mul_add (a b c:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg (a * b + c) p ==
S.aff_point_add (aff_point_mul_neg b (aff_point_mul_neg a p)) (aff_point_mul_neg c p))
let lemma_aff_point_mul_neg_mul_add a b c p =
lemma_aff_point_mul_neg_add (a * b) c p;
lemma_aff_point_mul_neg_mul a b p
// [a]P = [a % S.q]P
val lemma_aff_point_mul_neg_modq (a:int) (p:S.aff_point) :
Lemma (aff_point_mul_neg a p == aff_point_mul (a % S.q) p) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.Lemmas.fsti.checked",
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.ECSM.Lemmas.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256.Lemmas",
"short_module": "LS"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.ECSM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.ECSM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Prims.int -> p: Spec.K256.PointOps.aff_point
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul_neg a p ==
Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul (a % Spec.K256.PointOps.q) p) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.int",
"Spec.K256.PointOps.aff_point",
"FStar.Calc.calc_finish",
"Prims.eq2",
"Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul_neg",
"Hacl.Spec.K256.ECSM.Lemmas.aff_point_mul",
"Prims.op_Modulus",
"Spec.K256.PointOps.q",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Spec.K256.PointOps.aff_point_add",
"Spec.K256.PointOps.aff_point_at_inf",
"Prims.op_Division",
"FStar.Mul.op_Star",
"Prims.op_Addition",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.euclidean_division_definition",
"Prims.squash",
"Hacl.Spec.K256.ECSM.Lemmas.lemma_aff_point_mul_neg_add",
"Hacl.Spec.K256.ECSM.Lemmas.lemma_aff_point_mul_neg_mul",
"Hacl.Spec.K256.ECSM.Lemmas.lemma_order_of_curve_group",
"Spec.K256.Lemmas.aff_point_add_comm_lemma",
"Spec.K256.Lemmas.aff_point_at_inf_lemma"
] | [] | false | false | true | false | false | let lemma_aff_point_mul_neg_modq a p =
| calc ( == ) {
aff_point_mul_neg a p;
( == ) { Math.Lemmas.euclidean_division_definition a S.q }
aff_point_mul_neg ((a / S.q) * S.q + a % S.q) p;
( == ) { lemma_aff_point_mul_neg_add ((a / S.q) * S.q) (a % S.q) p }
S.aff_point_add (aff_point_mul_neg ((a / S.q) * S.q) p) (aff_point_mul_neg (a % S.q) p);
( == ) { lemma_aff_point_mul_neg_mul (a / S.q) S.q p }
S.aff_point_add (aff_point_mul S.q (aff_point_mul_neg (a / S.q) p)) (aff_point_mul (a % S.q) p);
( == ) { lemma_order_of_curve_group (aff_point_mul_neg (a / S.q) p) }
S.aff_point_add S.aff_point_at_inf (aff_point_mul (a % S.q) p);
( == ) { LS.aff_point_add_comm_lemma S.aff_point_at_inf (aff_point_mul (a % S.q) p) }
S.aff_point_add (aff_point_mul (a % S.q) p) S.aff_point_at_inf;
( == ) { LS.aff_point_at_inf_lemma (aff_point_mul (a % S.q) p) }
aff_point_mul (a % S.q) p;
} | false |
Pulse.C.Types.Fields.fsti | Pulse.C.Types.Fields.field_description_cons | val field_description_cons
(#ft #fc: Type0)
(n: string)
(#fn: Type0)
(#[solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == fn)))
(t: typedef ft)
(fd: field_description_t fc)
: Tot (nonempty_field_description_t (field_t_cons fn ft fc)) | val field_description_cons
(#ft #fc: Type0)
(n: string)
(#fn: Type0)
(#[solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == fn)))
(t: typedef ft)
(fd: field_description_t fc)
: Tot (nonempty_field_description_t (field_t_cons fn ft fc)) | let field_description_cons (#ft: Type0) (#fc: Type0) (n: string) (#fn: Type0) (# [ solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == fn))) (t: typedef ft) (fd: field_description_t fc) : Tot (nonempty_field_description_t (field_t_cons fn ft fc)) =
field_description_cons0 fn #ft #fc n t fd | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Fields.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 43,
"end_line": 53,
"start_col": 0,
"start_line": 52
} | module Pulse.C.Types.Fields
include Pulse.C.Types.Base
open Pulse.C.Typestring
open Pulse.Lib.Pervasives
[@@noextract_to "krml"] // tactic
let norm_fields () : FStar.Tactics.Tac unit =
FStar.Tactics.norm [delta_attr [`%norm_field_attr]; iota; zeta; primops];
FStar.Tactics.trefl ()
[@@noextract_to "krml"] // primitive
val field_t_nil: Type0
[@@noextract_to "krml"] // primitive
val field_t_cons (fn: Type0) (ft: Type0) (fc: Type0): Type0
inline_for_extraction [@@noextract_to "krml"; norm_field_attr]
noeq
type field_description_t (t: Type0) : Type u#1 = {
fd_def: (string -> GTot bool);
fd_empty: (fd_empty: bool { fd_empty == true <==> (forall s . fd_def s == false) });
fd_type: (string -> Type0);
fd_typedef: ((s: string) -> Pure (typedef (fd_type s)) (requires (fd_def s)) (ensures (fun _ -> True)));
}
inline_for_extraction [@@noextract_to "krml"; norm_field_attr]
let nonempty_field_description_t (t: Type0) =
(fd: field_description_t t { fd.fd_empty == false })
[@@noextract_to "krml"] // proof-only
let field_t (#t: Type0) (fd: field_description_t t) : Tot eqtype = (s: string { fd.fd_def s })
inline_for_extraction [@@noextract_to "krml"]
let field_description_nil : field_description_t field_t_nil = {
fd_def = (fun _ -> false);
fd_empty = true;
fd_type = (fun _ -> unit);
fd_typedef = (fun _ -> false_elim ());
}
inline_for_extraction [@@noextract_to "krml"; norm_field_attr]
let field_description_cons0
(fn: Type0) (#ft: Type0) (#fc: Type0) (n: string) (t: typedef ft) (fd: field_description_t fc)
: Tot (nonempty_field_description_t (field_t_cons fn ft fc))
= {
fd_def = (fun n' -> n = n' || fd.fd_def n');
fd_empty = false;
fd_type = (fun n' -> if n = n' then ft else fd.fd_type n');
fd_typedef = (fun n' -> if n = n' then t else fd.fd_typedef n');
} | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Typestring.fsti.checked",
"Pulse.C.Types.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Fields.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Typestring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
n: Prims.string ->
t: Pulse.C.Types.Base.typedef ft ->
fd: Pulse.C.Types.Fields.field_description_t fc
-> Pulse.C.Types.Fields.nonempty_field_description_t (Pulse.C.Types.Fields.field_t_cons fn ft fc) | Prims.Tot | [
"total"
] | [] | [
"Prims.string",
"Prims.squash",
"FStar.Pervasives.norm",
"Pulse.C.Typestring.norm_typestring",
"Prims.eq2",
"Pulse.C.Typestring.mk_string_t",
"Pulse.C.Types.Base.typedef",
"Pulse.C.Types.Fields.field_description_t",
"Pulse.C.Types.Fields.field_description_cons0",
"Pulse.C.Types.Fields.nonempty_field_description_t",
"Pulse.C.Types.Fields.field_t_cons"
] | [] | false | false | false | false | false | let field_description_cons
(#ft #fc: Type0)
(n: string)
(#fn: Type0)
(#[solve_mk_string_t ()] prf: squash (norm norm_typestring (mk_string_t n == fn)))
(t: typedef ft)
(fd: field_description_t fc)
: Tot (nonempty_field_description_t (field_t_cons fn ft fc)) =
| field_description_cons0 fn #ft #fc n t fd | false |
FStar.DM4F.Random.fst | FStar.DM4F.Random.return | val return (a: Type) (x: a) : rand a | val return (a: Type) (x: a) : rand a | let return (a:Type) (x:a) : rand a = fun (next,_) -> Some x, next | {
"file_name": "examples/dm4free/FStar.DM4F.Random.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 65,
"end_line": 26,
"start_col": 0,
"start_line": 26
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.DM4F.Random
open FStar.DM4F.Heap.Random
(* for some reason this `unfold` makes everything 25% faster *)
unfold type store = id * tape
(** Read-only tape with a pointer to the next unread position *)
type rand (a:Type) = (id * tape) -> M (option a * id) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.DM4F.Heap.Random.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.DM4F.Random.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.DM4F.Heap.Random",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 -> FStar.DM4F.Random.rand a | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.tuple2",
"FStar.DM4F.Heap.Random.id",
"FStar.DM4F.Heap.Random.tape",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.Some",
"FStar.DM4F.Random.rand"
] | [] | false | false | false | true | false | let return (a: Type) (x: a) : rand a =
| fun (next, _) -> Some x, next | false |
FStar.DM4F.Random.fst | FStar.DM4F.Random.get | val get: Prims.unit -> rand store | val get: Prims.unit -> rand store | let get () : rand store = fun s -> Some s, fst s | {
"file_name": "examples/dm4free/FStar.DM4F.Random.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 48,
"end_line": 46,
"start_col": 0,
"start_line": 46
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.DM4F.Random
open FStar.DM4F.Heap.Random
(* for some reason this `unfold` makes everything 25% faster *)
unfold type store = id * tape
(** Read-only tape with a pointer to the next unread position *)
type rand (a:Type) = (id * tape) -> M (option a * id)
let return (a:Type) (x:a) : rand a = fun (next,_) -> Some x, next
let bind (a b:Type) (c:rand a) (f:a -> rand b) : rand b =
fun s ->
let r, next' = c s in
match r with
| None -> None, next'
| Some x -> f x (next', snd s)
(*
// Tm_refine is outside of the definition language: ...
let sample () : rand elem = fun store ->
let next, t = store in
if incrementable next then
(Some (index t next), incr next)
else
(None, next)
*) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.DM4F.Heap.Random.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.DM4F.Random.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.DM4F.Heap.Random",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 -> FStar.DM4F.Random.rand FStar.DM4F.Random.store | Prims.Tot | [
"total"
] | [] | [
"Prims.unit",
"FStar.Pervasives.Native.tuple2",
"FStar.DM4F.Heap.Random.id",
"FStar.DM4F.Heap.Random.tape",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.option",
"FStar.DM4F.Random.store",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.fst",
"FStar.DM4F.Random.rand"
] | [] | false | false | false | true | false | let get () : rand store =
| fun s -> Some s, fst s | false |
FStar.DM4F.Random.fst | FStar.DM4F.Random.raise | val raise: a: Type -> Prims.unit -> rand a | val raise: a: Type -> Prims.unit -> rand a | let raise (a:Type) () : rand a = fun s -> None, fst s | {
"file_name": "examples/dm4free/FStar.DM4F.Random.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 53,
"end_line": 52,
"start_col": 0,
"start_line": 52
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.DM4F.Random
open FStar.DM4F.Heap.Random
(* for some reason this `unfold` makes everything 25% faster *)
unfold type store = id * tape
(** Read-only tape with a pointer to the next unread position *)
type rand (a:Type) = (id * tape) -> M (option a * id)
let return (a:Type) (x:a) : rand a = fun (next,_) -> Some x, next
let bind (a b:Type) (c:rand a) (f:a -> rand b) : rand b =
fun s ->
let r, next' = c s in
match r with
| None -> None, next'
| Some x -> f x (next', snd s)
(*
// Tm_refine is outside of the definition language: ...
let sample () : rand elem = fun store ->
let next, t = store in
if incrementable next then
(Some (index t next), incr next)
else
(None, next)
*)
(** Get store *)
let get () : rand store = fun s -> Some s, fst s
(** Update tape pointer *)
let put i : rand unit = fun _ -> Some (), i | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.DM4F.Heap.Random.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.DM4F.Random.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.DM4F.Heap.Random",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> _: Prims.unit -> FStar.DM4F.Random.rand a | Prims.Tot | [
"total"
] | [] | [
"Prims.unit",
"FStar.Pervasives.Native.tuple2",
"FStar.DM4F.Heap.Random.id",
"FStar.DM4F.Heap.Random.tape",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.fst",
"FStar.DM4F.Random.rand"
] | [] | false | false | false | true | false | let raise (a: Type) () : rand a =
| fun s -> None, fst s | false |
FStar.DM4F.Random.fst | FStar.DM4F.Random.bind | val bind (a b: Type) (c: rand a) (f: (a -> rand b)) : rand b | val bind (a b: Type) (c: rand a) (f: (a -> rand b)) : rand b | let bind (a b:Type) (c:rand a) (f:a -> rand b) : rand b =
fun s ->
let r, next' = c s in
match r with
| None -> None, next'
| Some x -> f x (next', snd s) | {
"file_name": "examples/dm4free/FStar.DM4F.Random.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 34,
"end_line": 33,
"start_col": 0,
"start_line": 28
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.DM4F.Random
open FStar.DM4F.Heap.Random
(* for some reason this `unfold` makes everything 25% faster *)
unfold type store = id * tape
(** Read-only tape with a pointer to the next unread position *)
type rand (a:Type) = (id * tape) -> M (option a * id)
let return (a:Type) (x:a) : rand a = fun (next,_) -> Some x, next | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.DM4F.Heap.Random.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.DM4F.Random.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.DM4F.Heap.Random",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 -> c: FStar.DM4F.Random.rand a -> f: (_: a -> FStar.DM4F.Random.rand b)
-> FStar.DM4F.Random.rand b | Prims.Tot | [
"total"
] | [] | [
"FStar.DM4F.Random.rand",
"FStar.Pervasives.Native.tuple2",
"FStar.DM4F.Heap.Random.id",
"FStar.DM4F.Heap.Random.tape",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.snd"
] | [] | false | false | false | true | false | let bind (a b: Type) (c: rand a) (f: (a -> rand b)) : rand b =
| fun s ->
let r, next' = c s in
match r with
| None -> None, next'
| Some x -> f x (next', snd s) | false |
FStar.DM4F.Random.fst | FStar.DM4F.Random.mass | val mass: #a:Type -> f:(store -> M (a * id)) -> p:(a -> nat) -> nat | val mass: #a:Type -> f:(store -> M (a * id)) -> p:(a -> nat) -> nat | let mass #a f p = sum (fun h -> let r,_ = f (to_id 0,h) in p r) | {
"file_name": "examples/dm4free/FStar.DM4F.Random.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 63,
"end_line": 134,
"start_col": 0,
"start_line": 134
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.DM4F.Random
open FStar.DM4F.Heap.Random
(* for some reason this `unfold` makes everything 25% faster *)
unfold type store = id * tape
(** Read-only tape with a pointer to the next unread position *)
type rand (a:Type) = (id * tape) -> M (option a * id)
let return (a:Type) (x:a) : rand a = fun (next,_) -> Some x, next
let bind (a b:Type) (c:rand a) (f:a -> rand b) : rand b =
fun s ->
let r, next' = c s in
match r with
| None -> None, next'
| Some x -> f x (next', snd s)
(*
// Tm_refine is outside of the definition language: ...
let sample () : rand elem = fun store ->
let next, t = store in
if incrementable next then
(Some (index t next), incr next)
else
(None, next)
*)
(** Get store *)
let get () : rand store = fun s -> Some s, fst s
(** Update tape pointer *)
let put i : rand unit = fun _ -> Some (), i
(** Raise exception *)
let raise (a:Type) () : rand a = fun s -> None, fst s
total reifiable reflectable new_effect {
RAND: a:Type -> Effect
with repr = rand
; bind = bind
; return = return
; get = get
; put = put
; raise = raise
}
effect Rand (a:Type) =
RAND a (fun initial_tape post -> forall (x:option a * id). post x)
(** If not past the end of the tape, read a value and advance pointer *)
reifiable val sample: unit -> RAND elem (fun (next,t) p ->
if incrementable next then p (Some (index t next), incr next)
else p (None, next))
let sample () =
let next, t = RAND?.get () in
if incrementable next then
begin
RAND?.put (incr next);
index t next
end
else
RAND?.raise elem ()
(* GM: This is failing now... I couldn't make it go through even trying to
* manually trigger reification. *)
let test_sample_some (v:elem) (t:tape{sel t (to_id 0) == v}) =
let f = reify (sample ()) in
admit ();
assert (f (to_id 0,t) == (Some v, to_id 1))
let test_sample_none (v:elem) (t:tape) =
let f = reify (sample ()) in
admit ();
assert (f (to_id 9,t) == (None, to_id 9))
(** Bijection over tapes, the inverse function acts as a witness *)
noeq type bijection =
| Bijection:
f:(tape -> tape) ->
finv:(tape -> tape){forall (h:tape). equal (f (finv h)) h /\ equal (finv (f h)) h} ->
bijection
(** Inverse of a bijection *)
let inverse (bij:bijection) : bijection =
Bijection bij.finv bij.f
(** Assume `sum` over `tape`. Definable as long as tape is finite *)
assume val sum: f:(tape -> nat) -> nat
(** Reordering terms in a sum doesn't change the result *)
assume val sum_bijection: f:(tape -> nat) -> bij:bijection -> Lemma
(sum f == sum (fun h -> f (bij.f h)))
(** The sum of non-negative function is monotonic *)
assume val sum_monotonic: f:(tape -> nat) -> g:(tape -> nat) -> Lemma
(requires (forall h. f h <= g h))
(ensures (sum f <= sum g))
(** Corollary *)
val sum_extensional: f:(tape -> nat) -> g:(tape -> nat) -> Lemma
(requires (forall h. f h == g h))
(ensures (sum f == sum g))
let sum_extensional f g =
sum_monotonic f g;
sum_monotonic g f
(** Unnormalized measure of a function `p` wrt the denotation of a probabilistic
computation `f`.
Assumes that the initial random tape is uniformly distributed
When `p:a -> {0,1}` and `tape` is finite
Pr[f : p] == 1/|tape| * sum_{h:tape} p (f h) == 1/|tape| * mass f p
*) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.DM4F.Heap.Random.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.DM4F.Random.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.DM4F.Heap.Random",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: (_: FStar.DM4F.Random.store -> Prims.M (a * FStar.DM4F.Heap.Random.id)) -> p: (_: a -> Prims.nat)
-> Prims.nat | Prims.Tot | [
"total"
] | [] | [
"FStar.DM4F.Random.store",
"FStar.Pervasives.Native.tuple2",
"FStar.DM4F.Heap.Random.id",
"Prims.nat",
"FStar.DM4F.Random.sum",
"FStar.DM4F.Heap.Random.tape",
"FStar.Pervasives.Native.Mktuple2",
"FStar.DM4F.Heap.Random.to_id"
] | [] | false | false | false | true | false | let mass #a f p =
| sum (fun h ->
let r, _ = f (to_id 0, h) in
p r) | false |
FStar.DM4F.Random.fst | FStar.DM4F.Random.inverse | val inverse (bij: bijection) : bijection | val inverse (bij: bijection) : bijection | let inverse (bij:bijection) : bijection =
Bijection bij.finv bij.f | {
"file_name": "examples/dm4free/FStar.DM4F.Random.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 26,
"end_line": 104,
"start_col": 0,
"start_line": 103
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.DM4F.Random
open FStar.DM4F.Heap.Random
(* for some reason this `unfold` makes everything 25% faster *)
unfold type store = id * tape
(** Read-only tape with a pointer to the next unread position *)
type rand (a:Type) = (id * tape) -> M (option a * id)
let return (a:Type) (x:a) : rand a = fun (next,_) -> Some x, next
let bind (a b:Type) (c:rand a) (f:a -> rand b) : rand b =
fun s ->
let r, next' = c s in
match r with
| None -> None, next'
| Some x -> f x (next', snd s)
(*
// Tm_refine is outside of the definition language: ...
let sample () : rand elem = fun store ->
let next, t = store in
if incrementable next then
(Some (index t next), incr next)
else
(None, next)
*)
(** Get store *)
let get () : rand store = fun s -> Some s, fst s
(** Update tape pointer *)
let put i : rand unit = fun _ -> Some (), i
(** Raise exception *)
let raise (a:Type) () : rand a = fun s -> None, fst s
total reifiable reflectable new_effect {
RAND: a:Type -> Effect
with repr = rand
; bind = bind
; return = return
; get = get
; put = put
; raise = raise
}
effect Rand (a:Type) =
RAND a (fun initial_tape post -> forall (x:option a * id). post x)
(** If not past the end of the tape, read a value and advance pointer *)
reifiable val sample: unit -> RAND elem (fun (next,t) p ->
if incrementable next then p (Some (index t next), incr next)
else p (None, next))
let sample () =
let next, t = RAND?.get () in
if incrementable next then
begin
RAND?.put (incr next);
index t next
end
else
RAND?.raise elem ()
(* GM: This is failing now... I couldn't make it go through even trying to
* manually trigger reification. *)
let test_sample_some (v:elem) (t:tape{sel t (to_id 0) == v}) =
let f = reify (sample ()) in
admit ();
assert (f (to_id 0,t) == (Some v, to_id 1))
let test_sample_none (v:elem) (t:tape) =
let f = reify (sample ()) in
admit ();
assert (f (to_id 9,t) == (None, to_id 9))
(** Bijection over tapes, the inverse function acts as a witness *)
noeq type bijection =
| Bijection:
f:(tape -> tape) ->
finv:(tape -> tape){forall (h:tape). equal (f (finv h)) h /\ equal (finv (f h)) h} ->
bijection | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.DM4F.Heap.Random.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.DM4F.Random.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.DM4F.Heap.Random",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | bij: FStar.DM4F.Random.bijection -> FStar.DM4F.Random.bijection | Prims.Tot | [
"total"
] | [] | [
"FStar.DM4F.Random.bijection",
"FStar.DM4F.Random.Bijection",
"FStar.DM4F.Random.__proj__Bijection__item__finv",
"FStar.DM4F.Random.__proj__Bijection__item__f"
] | [] | false | false | false | true | false | let inverse (bij: bijection) : bijection =
| Bijection bij.finv bij.f | false |
FStar.DM4F.Random.fst | FStar.DM4F.Random.point | val point: #a:eqtype -> x:a -> y:option a -> nat | val point: #a:eqtype -> x:a -> y:option a -> nat | let point #a x = fun y -> if y = Some x then 1 else 0 | {
"file_name": "examples/dm4free/FStar.DM4F.Random.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 53,
"end_line": 137,
"start_col": 0,
"start_line": 137
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.DM4F.Random
open FStar.DM4F.Heap.Random
(* for some reason this `unfold` makes everything 25% faster *)
unfold type store = id * tape
(** Read-only tape with a pointer to the next unread position *)
type rand (a:Type) = (id * tape) -> M (option a * id)
let return (a:Type) (x:a) : rand a = fun (next,_) -> Some x, next
let bind (a b:Type) (c:rand a) (f:a -> rand b) : rand b =
fun s ->
let r, next' = c s in
match r with
| None -> None, next'
| Some x -> f x (next', snd s)
(*
// Tm_refine is outside of the definition language: ...
let sample () : rand elem = fun store ->
let next, t = store in
if incrementable next then
(Some (index t next), incr next)
else
(None, next)
*)
(** Get store *)
let get () : rand store = fun s -> Some s, fst s
(** Update tape pointer *)
let put i : rand unit = fun _ -> Some (), i
(** Raise exception *)
let raise (a:Type) () : rand a = fun s -> None, fst s
total reifiable reflectable new_effect {
RAND: a:Type -> Effect
with repr = rand
; bind = bind
; return = return
; get = get
; put = put
; raise = raise
}
effect Rand (a:Type) =
RAND a (fun initial_tape post -> forall (x:option a * id). post x)
(** If not past the end of the tape, read a value and advance pointer *)
reifiable val sample: unit -> RAND elem (fun (next,t) p ->
if incrementable next then p (Some (index t next), incr next)
else p (None, next))
let sample () =
let next, t = RAND?.get () in
if incrementable next then
begin
RAND?.put (incr next);
index t next
end
else
RAND?.raise elem ()
(* GM: This is failing now... I couldn't make it go through even trying to
* manually trigger reification. *)
let test_sample_some (v:elem) (t:tape{sel t (to_id 0) == v}) =
let f = reify (sample ()) in
admit ();
assert (f (to_id 0,t) == (Some v, to_id 1))
let test_sample_none (v:elem) (t:tape) =
let f = reify (sample ()) in
admit ();
assert (f (to_id 9,t) == (None, to_id 9))
(** Bijection over tapes, the inverse function acts as a witness *)
noeq type bijection =
| Bijection:
f:(tape -> tape) ->
finv:(tape -> tape){forall (h:tape). equal (f (finv h)) h /\ equal (finv (f h)) h} ->
bijection
(** Inverse of a bijection *)
let inverse (bij:bijection) : bijection =
Bijection bij.finv bij.f
(** Assume `sum` over `tape`. Definable as long as tape is finite *)
assume val sum: f:(tape -> nat) -> nat
(** Reordering terms in a sum doesn't change the result *)
assume val sum_bijection: f:(tape -> nat) -> bij:bijection -> Lemma
(sum f == sum (fun h -> f (bij.f h)))
(** The sum of non-negative function is monotonic *)
assume val sum_monotonic: f:(tape -> nat) -> g:(tape -> nat) -> Lemma
(requires (forall h. f h <= g h))
(ensures (sum f <= sum g))
(** Corollary *)
val sum_extensional: f:(tape -> nat) -> g:(tape -> nat) -> Lemma
(requires (forall h. f h == g h))
(ensures (sum f == sum g))
let sum_extensional f g =
sum_monotonic f g;
sum_monotonic g f
(** Unnormalized measure of a function `p` wrt the denotation of a probabilistic
computation `f`.
Assumes that the initial random tape is uniformly distributed
When `p:a -> {0,1}` and `tape` is finite
Pr[f : p] == 1/|tape| * sum_{h:tape} p (f h) == 1/|tape| * mass f p
*)
val mass: #a:Type -> f:(store -> M (a * id)) -> p:(a -> nat) -> nat
let mass #a f p = sum (fun h -> let r,_ = f (to_id 0,h) in p r) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.DM4F.Heap.Random.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.DM4F.Random.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.DM4F.Heap.Random",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: a -> y: FStar.Pervasives.Native.option a -> Prims.nat | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"FStar.Pervasives.Native.option",
"Prims.op_Equality",
"FStar.Pervasives.Native.Some",
"Prims.bool",
"Prims.nat"
] | [] | false | false | false | false | false | let point #a x =
| fun y -> if y = Some x then 1 else 0 | false |
FStar.DM4F.Random.fst | FStar.DM4F.Random.sum_extensional | val sum_extensional: f:(tape -> nat) -> g:(tape -> nat) -> Lemma
(requires (forall h. f h == g h))
(ensures (sum f == sum g)) | val sum_extensional: f:(tape -> nat) -> g:(tape -> nat) -> Lemma
(requires (forall h. f h == g h))
(ensures (sum f == sum g)) | let sum_extensional f g =
sum_monotonic f g;
sum_monotonic g f | {
"file_name": "examples/dm4free/FStar.DM4F.Random.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 19,
"end_line": 125,
"start_col": 0,
"start_line": 123
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.DM4F.Random
open FStar.DM4F.Heap.Random
(* for some reason this `unfold` makes everything 25% faster *)
unfold type store = id * tape
(** Read-only tape with a pointer to the next unread position *)
type rand (a:Type) = (id * tape) -> M (option a * id)
let return (a:Type) (x:a) : rand a = fun (next,_) -> Some x, next
let bind (a b:Type) (c:rand a) (f:a -> rand b) : rand b =
fun s ->
let r, next' = c s in
match r with
| None -> None, next'
| Some x -> f x (next', snd s)
(*
// Tm_refine is outside of the definition language: ...
let sample () : rand elem = fun store ->
let next, t = store in
if incrementable next then
(Some (index t next), incr next)
else
(None, next)
*)
(** Get store *)
let get () : rand store = fun s -> Some s, fst s
(** Update tape pointer *)
let put i : rand unit = fun _ -> Some (), i
(** Raise exception *)
let raise (a:Type) () : rand a = fun s -> None, fst s
total reifiable reflectable new_effect {
RAND: a:Type -> Effect
with repr = rand
; bind = bind
; return = return
; get = get
; put = put
; raise = raise
}
effect Rand (a:Type) =
RAND a (fun initial_tape post -> forall (x:option a * id). post x)
(** If not past the end of the tape, read a value and advance pointer *)
reifiable val sample: unit -> RAND elem (fun (next,t) p ->
if incrementable next then p (Some (index t next), incr next)
else p (None, next))
let sample () =
let next, t = RAND?.get () in
if incrementable next then
begin
RAND?.put (incr next);
index t next
end
else
RAND?.raise elem ()
(* GM: This is failing now... I couldn't make it go through even trying to
* manually trigger reification. *)
let test_sample_some (v:elem) (t:tape{sel t (to_id 0) == v}) =
let f = reify (sample ()) in
admit ();
assert (f (to_id 0,t) == (Some v, to_id 1))
let test_sample_none (v:elem) (t:tape) =
let f = reify (sample ()) in
admit ();
assert (f (to_id 9,t) == (None, to_id 9))
(** Bijection over tapes, the inverse function acts as a witness *)
noeq type bijection =
| Bijection:
f:(tape -> tape) ->
finv:(tape -> tape){forall (h:tape). equal (f (finv h)) h /\ equal (finv (f h)) h} ->
bijection
(** Inverse of a bijection *)
let inverse (bij:bijection) : bijection =
Bijection bij.finv bij.f
(** Assume `sum` over `tape`. Definable as long as tape is finite *)
assume val sum: f:(tape -> nat) -> nat
(** Reordering terms in a sum doesn't change the result *)
assume val sum_bijection: f:(tape -> nat) -> bij:bijection -> Lemma
(sum f == sum (fun h -> f (bij.f h)))
(** The sum of non-negative function is monotonic *)
assume val sum_monotonic: f:(tape -> nat) -> g:(tape -> nat) -> Lemma
(requires (forall h. f h <= g h))
(ensures (sum f <= sum g))
(** Corollary *)
val sum_extensional: f:(tape -> nat) -> g:(tape -> nat) -> Lemma
(requires (forall h. f h == g h)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.DM4F.Heap.Random.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.DM4F.Random.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.DM4F.Heap.Random",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: (_: FStar.DM4F.Heap.Random.tape -> Prims.nat) -> g: (_: FStar.DM4F.Heap.Random.tape -> Prims.nat)
-> FStar.Pervasives.Lemma (requires forall (h: FStar.DM4F.Heap.Random.tape). f h == g h)
(ensures FStar.DM4F.Random.sum f == FStar.DM4F.Random.sum g) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.DM4F.Heap.Random.tape",
"Prims.nat",
"FStar.DM4F.Random.sum_monotonic",
"Prims.unit"
] | [] | true | false | true | false | false | let sum_extensional f g =
| sum_monotonic f g;
sum_monotonic g f | false |
FStar.DM4F.Random.fst | FStar.DM4F.Random.pr_leq | val pr_leq: #a:Type -> #b:Type ->
c1:(store -> M (a * id)) ->
c2:(store -> M (b * id)) ->
p1:(a -> nat) ->
p2:(b -> nat) ->
bij:bijection -> Lemma
(requires
(forall t.
let r1,_ = c1 (to_id 0,t) in
let r2,_ = c2 (to_id 0,bij.f t) in
p1 r1 <= p2 r2))
(ensures (mass c1 p1 <= mass c2 p2)) | val pr_leq: #a:Type -> #b:Type ->
c1:(store -> M (a * id)) ->
c2:(store -> M (b * id)) ->
p1:(a -> nat) ->
p2:(b -> nat) ->
bij:bijection -> Lemma
(requires
(forall t.
let r1,_ = c1 (to_id 0,t) in
let r2,_ = c2 (to_id 0,bij.f t) in
p1 r1 <= p2 r2))
(ensures (mass c1 p1 <= mass c2 p2)) | let pr_leq #a #b c1 c2 p1 p2 bij =
let bij' = inverse bij in
let f1 = (fun h -> let r1,_ = c1 (to_id 0,h) in p1 r1) in
let f2 = (fun h -> let r2,_ = c2 (to_id 0,h) in p2 r2) in
sum_monotonic f1 (fun h -> let r2,_ = c2 (to_id 0,bij.f h) in p2 r2);
sum_bijection (fun h -> let r2,_ = c2 (to_id 0,bij.f h) in p2 r2) bij';
sum_extensional (fun h -> let r2,_ = c2 (to_id 0,bij.f (bij'.f h)) in p2 r2) f2 | {
"file_name": "examples/dm4free/FStar.DM4F.Random.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 81,
"end_line": 162,
"start_col": 0,
"start_line": 156
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.DM4F.Random
open FStar.DM4F.Heap.Random
(* for some reason this `unfold` makes everything 25% faster *)
unfold type store = id * tape
(** Read-only tape with a pointer to the next unread position *)
type rand (a:Type) = (id * tape) -> M (option a * id)
let return (a:Type) (x:a) : rand a = fun (next,_) -> Some x, next
let bind (a b:Type) (c:rand a) (f:a -> rand b) : rand b =
fun s ->
let r, next' = c s in
match r with
| None -> None, next'
| Some x -> f x (next', snd s)
(*
// Tm_refine is outside of the definition language: ...
let sample () : rand elem = fun store ->
let next, t = store in
if incrementable next then
(Some (index t next), incr next)
else
(None, next)
*)
(** Get store *)
let get () : rand store = fun s -> Some s, fst s
(** Update tape pointer *)
let put i : rand unit = fun _ -> Some (), i
(** Raise exception *)
let raise (a:Type) () : rand a = fun s -> None, fst s
total reifiable reflectable new_effect {
RAND: a:Type -> Effect
with repr = rand
; bind = bind
; return = return
; get = get
; put = put
; raise = raise
}
effect Rand (a:Type) =
RAND a (fun initial_tape post -> forall (x:option a * id). post x)
(** If not past the end of the tape, read a value and advance pointer *)
reifiable val sample: unit -> RAND elem (fun (next,t) p ->
if incrementable next then p (Some (index t next), incr next)
else p (None, next))
let sample () =
let next, t = RAND?.get () in
if incrementable next then
begin
RAND?.put (incr next);
index t next
end
else
RAND?.raise elem ()
(* GM: This is failing now... I couldn't make it go through even trying to
* manually trigger reification. *)
let test_sample_some (v:elem) (t:tape{sel t (to_id 0) == v}) =
let f = reify (sample ()) in
admit ();
assert (f (to_id 0,t) == (Some v, to_id 1))
let test_sample_none (v:elem) (t:tape) =
let f = reify (sample ()) in
admit ();
assert (f (to_id 9,t) == (None, to_id 9))
(** Bijection over tapes, the inverse function acts as a witness *)
noeq type bijection =
| Bijection:
f:(tape -> tape) ->
finv:(tape -> tape){forall (h:tape). equal (f (finv h)) h /\ equal (finv (f h)) h} ->
bijection
(** Inverse of a bijection *)
let inverse (bij:bijection) : bijection =
Bijection bij.finv bij.f
(** Assume `sum` over `tape`. Definable as long as tape is finite *)
assume val sum: f:(tape -> nat) -> nat
(** Reordering terms in a sum doesn't change the result *)
assume val sum_bijection: f:(tape -> nat) -> bij:bijection -> Lemma
(sum f == sum (fun h -> f (bij.f h)))
(** The sum of non-negative function is monotonic *)
assume val sum_monotonic: f:(tape -> nat) -> g:(tape -> nat) -> Lemma
(requires (forall h. f h <= g h))
(ensures (sum f <= sum g))
(** Corollary *)
val sum_extensional: f:(tape -> nat) -> g:(tape -> nat) -> Lemma
(requires (forall h. f h == g h))
(ensures (sum f == sum g))
let sum_extensional f g =
sum_monotonic f g;
sum_monotonic g f
(** Unnormalized measure of a function `p` wrt the denotation of a probabilistic
computation `f`.
Assumes that the initial random tape is uniformly distributed
When `p:a -> {0,1}` and `tape` is finite
Pr[f : p] == 1/|tape| * sum_{h:tape} p (f h) == 1/|tape| * mass f p
*)
val mass: #a:Type -> f:(store -> M (a * id)) -> p:(a -> nat) -> nat
let mass #a f p = sum (fun h -> let r,_ = f (to_id 0,h) in p r)
val point: #a:eqtype -> x:a -> y:option a -> nat
let point #a x = fun y -> if y = Some x then 1 else 0
(** If there exists a bijection over tapes such that `p1` evaluated
on the result of `c1` is less than or equal to `p2` evaluated
on the result of `c2`, then the measure of `p1` wrt `c1` is less than or
equal to the measure of `p2` wrt `c2` *)
val pr_leq: #a:Type -> #b:Type ->
c1:(store -> M (a * id)) ->
c2:(store -> M (b * id)) ->
p1:(a -> nat) ->
p2:(b -> nat) ->
bij:bijection -> Lemma
(requires
(forall t.
let r1,_ = c1 (to_id 0,t) in
let r2,_ = c2 (to_id 0,bij.f t) in
p1 r1 <= p2 r2)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.DM4F.Heap.Random.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.DM4F.Random.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.DM4F.Heap.Random",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
c1: (_: FStar.DM4F.Random.store -> Prims.M (a * FStar.DM4F.Heap.Random.id)) ->
c2: (_: FStar.DM4F.Random.store -> Prims.M (b * FStar.DM4F.Heap.Random.id)) ->
p1: (_: a -> Prims.nat) ->
p2: (_: b -> Prims.nat) ->
bij: FStar.DM4F.Random.bijection
-> FStar.Pervasives.Lemma
(requires
forall (t: FStar.DM4F.Heap.Random.tape).
let _ = c1 (FStar.DM4F.Heap.Random.to_id 0, t) in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ r1 _ = _ in
let _ = c2 (FStar.DM4F.Heap.Random.to_id 0, Bijection?.f bij t) in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ r2 _ = _ in
p1 r1 <= p2 r2)
<:
Type0)
<:
Type0) (ensures FStar.DM4F.Random.mass c1 p1 <= FStar.DM4F.Random.mass c2 p2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.DM4F.Random.store",
"FStar.Pervasives.Native.tuple2",
"FStar.DM4F.Heap.Random.id",
"Prims.nat",
"FStar.DM4F.Random.bijection",
"FStar.DM4F.Random.sum_extensional",
"FStar.DM4F.Heap.Random.tape",
"FStar.Pervasives.Native.Mktuple2",
"FStar.DM4F.Heap.Random.to_id",
"FStar.DM4F.Random.__proj__Bijection__item__f",
"Prims.unit",
"FStar.DM4F.Random.sum_bijection",
"FStar.DM4F.Random.sum_monotonic",
"FStar.DM4F.Random.inverse"
] | [] | false | false | true | false | false | let pr_leq #a #b c1 c2 p1 p2 bij =
| let bij' = inverse bij in
let f1 =
(fun h ->
let r1, _ = c1 (to_id 0, h) in
p1 r1)
in
let f2 =
(fun h ->
let r2, _ = c2 (to_id 0, h) in
p2 r2)
in
sum_monotonic f1
(fun h ->
let r2, _ = c2 (to_id 0, bij.f h) in
p2 r2);
sum_bijection (fun h ->
let r2, _ = c2 (to_id 0, bij.f h) in
p2 r2)
bij';
sum_extensional (fun h ->
let r2, _ = c2 (to_id 0, bij.f (bij'.f h)) in
p2 r2)
f2 | false |
FStar.DM4F.Random.fst | FStar.DM4F.Random.pr_eq | val pr_eq: #a:Type -> #b:Type ->
c1:(store -> M (a * id)) ->
c2:(store -> M (b * id)) ->
p1:(a -> nat) ->
p2:(b -> nat) ->
bij:bijection -> Lemma
(requires
(forall h. let r1,_ = c1 (to_id 0, h) in
let r2,_ = c2 (to_id 0, bij.f h) in
p1 r1 == p2 r2))
(ensures (mass c1 p1 == mass c2 p2)) | val pr_eq: #a:Type -> #b:Type ->
c1:(store -> M (a * id)) ->
c2:(store -> M (b * id)) ->
p1:(a -> nat) ->
p2:(b -> nat) ->
bij:bijection -> Lemma
(requires
(forall h. let r1,_ = c1 (to_id 0, h) in
let r2,_ = c2 (to_id 0, bij.f h) in
p1 r1 == p2 r2))
(ensures (mass c1 p1 == mass c2 p2)) | let pr_eq #a #b c1 c2 p1 p2 bij =
pr_leq c1 c2 p1 p2 bij;
pr_leq c2 c1 p2 p1 (inverse bij) | {
"file_name": "examples/dm4free/FStar.DM4F.Random.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 34,
"end_line": 178,
"start_col": 0,
"start_line": 176
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.DM4F.Random
open FStar.DM4F.Heap.Random
(* for some reason this `unfold` makes everything 25% faster *)
unfold type store = id * tape
(** Read-only tape with a pointer to the next unread position *)
type rand (a:Type) = (id * tape) -> M (option a * id)
let return (a:Type) (x:a) : rand a = fun (next,_) -> Some x, next
let bind (a b:Type) (c:rand a) (f:a -> rand b) : rand b =
fun s ->
let r, next' = c s in
match r with
| None -> None, next'
| Some x -> f x (next', snd s)
(*
// Tm_refine is outside of the definition language: ...
let sample () : rand elem = fun store ->
let next, t = store in
if incrementable next then
(Some (index t next), incr next)
else
(None, next)
*)
(** Get store *)
let get () : rand store = fun s -> Some s, fst s
(** Update tape pointer *)
let put i : rand unit = fun _ -> Some (), i
(** Raise exception *)
let raise (a:Type) () : rand a = fun s -> None, fst s
total reifiable reflectable new_effect {
RAND: a:Type -> Effect
with repr = rand
; bind = bind
; return = return
; get = get
; put = put
; raise = raise
}
effect Rand (a:Type) =
RAND a (fun initial_tape post -> forall (x:option a * id). post x)
(** If not past the end of the tape, read a value and advance pointer *)
reifiable val sample: unit -> RAND elem (fun (next,t) p ->
if incrementable next then p (Some (index t next), incr next)
else p (None, next))
let sample () =
let next, t = RAND?.get () in
if incrementable next then
begin
RAND?.put (incr next);
index t next
end
else
RAND?.raise elem ()
(* GM: This is failing now... I couldn't make it go through even trying to
* manually trigger reification. *)
let test_sample_some (v:elem) (t:tape{sel t (to_id 0) == v}) =
let f = reify (sample ()) in
admit ();
assert (f (to_id 0,t) == (Some v, to_id 1))
let test_sample_none (v:elem) (t:tape) =
let f = reify (sample ()) in
admit ();
assert (f (to_id 9,t) == (None, to_id 9))
(** Bijection over tapes, the inverse function acts as a witness *)
noeq type bijection =
| Bijection:
f:(tape -> tape) ->
finv:(tape -> tape){forall (h:tape). equal (f (finv h)) h /\ equal (finv (f h)) h} ->
bijection
(** Inverse of a bijection *)
let inverse (bij:bijection) : bijection =
Bijection bij.finv bij.f
(** Assume `sum` over `tape`. Definable as long as tape is finite *)
assume val sum: f:(tape -> nat) -> nat
(** Reordering terms in a sum doesn't change the result *)
assume val sum_bijection: f:(tape -> nat) -> bij:bijection -> Lemma
(sum f == sum (fun h -> f (bij.f h)))
(** The sum of non-negative function is monotonic *)
assume val sum_monotonic: f:(tape -> nat) -> g:(tape -> nat) -> Lemma
(requires (forall h. f h <= g h))
(ensures (sum f <= sum g))
(** Corollary *)
val sum_extensional: f:(tape -> nat) -> g:(tape -> nat) -> Lemma
(requires (forall h. f h == g h))
(ensures (sum f == sum g))
let sum_extensional f g =
sum_monotonic f g;
sum_monotonic g f
(** Unnormalized measure of a function `p` wrt the denotation of a probabilistic
computation `f`.
Assumes that the initial random tape is uniformly distributed
When `p:a -> {0,1}` and `tape` is finite
Pr[f : p] == 1/|tape| * sum_{h:tape} p (f h) == 1/|tape| * mass f p
*)
val mass: #a:Type -> f:(store -> M (a * id)) -> p:(a -> nat) -> nat
let mass #a f p = sum (fun h -> let r,_ = f (to_id 0,h) in p r)
val point: #a:eqtype -> x:a -> y:option a -> nat
let point #a x = fun y -> if y = Some x then 1 else 0
(** If there exists a bijection over tapes such that `p1` evaluated
on the result of `c1` is less than or equal to `p2` evaluated
on the result of `c2`, then the measure of `p1` wrt `c1` is less than or
equal to the measure of `p2` wrt `c2` *)
val pr_leq: #a:Type -> #b:Type ->
c1:(store -> M (a * id)) ->
c2:(store -> M (b * id)) ->
p1:(a -> nat) ->
p2:(b -> nat) ->
bij:bijection -> Lemma
(requires
(forall t.
let r1,_ = c1 (to_id 0,t) in
let r2,_ = c2 (to_id 0,bij.f t) in
p1 r1 <= p2 r2))
(ensures (mass c1 p1 <= mass c2 p2))
let pr_leq #a #b c1 c2 p1 p2 bij =
let bij' = inverse bij in
let f1 = (fun h -> let r1,_ = c1 (to_id 0,h) in p1 r1) in
let f2 = (fun h -> let r2,_ = c2 (to_id 0,h) in p2 r2) in
sum_monotonic f1 (fun h -> let r2,_ = c2 (to_id 0,bij.f h) in p2 r2);
sum_bijection (fun h -> let r2,_ = c2 (to_id 0,bij.f h) in p2 r2) bij';
sum_extensional (fun h -> let r2,_ = c2 (to_id 0,bij.f (bij'.f h)) in p2 r2) f2
(** Corollary *)
val pr_eq: #a:Type -> #b:Type ->
c1:(store -> M (a * id)) ->
c2:(store -> M (b * id)) ->
p1:(a -> nat) ->
p2:(b -> nat) ->
bij:bijection -> Lemma
(requires
(forall h. let r1,_ = c1 (to_id 0, h) in
let r2,_ = c2 (to_id 0, bij.f h) in
p1 r1 == p2 r2)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.DM4F.Heap.Random.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.DM4F.Random.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.DM4F.Heap.Random",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
c1: (_: FStar.DM4F.Random.store -> Prims.M (a * FStar.DM4F.Heap.Random.id)) ->
c2: (_: FStar.DM4F.Random.store -> Prims.M (b * FStar.DM4F.Heap.Random.id)) ->
p1: (_: a -> Prims.nat) ->
p2: (_: b -> Prims.nat) ->
bij: FStar.DM4F.Random.bijection
-> FStar.Pervasives.Lemma
(requires
forall (h: FStar.DM4F.Heap.Random.tape).
let _ = c1 (FStar.DM4F.Heap.Random.to_id 0, h) in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ r1 _ = _ in
let _ = c2 (FStar.DM4F.Heap.Random.to_id 0, Bijection?.f bij h) in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ r2 _ = _ in
p1 r1 == p2 r2)
<:
Type0)
<:
Type0) (ensures FStar.DM4F.Random.mass c1 p1 == FStar.DM4F.Random.mass c2 p2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.DM4F.Random.store",
"FStar.Pervasives.Native.tuple2",
"FStar.DM4F.Heap.Random.id",
"Prims.nat",
"FStar.DM4F.Random.bijection",
"FStar.DM4F.Random.pr_leq",
"FStar.DM4F.Random.inverse",
"Prims.unit"
] | [] | true | false | true | false | false | let pr_eq #a #b c1 c2 p1 p2 bij =
| pr_leq c1 c2 p1 p2 bij;
pr_leq c2 c1 p2 p1 (inverse bij) | false |
Pulse.C.Types.Fields.fsti | Pulse.C.Types.Fields.field_description_cons0 | val field_description_cons0
(fn #ft #fc: Type0)
(n: string)
(t: typedef ft)
(fd: field_description_t fc)
: Tot (nonempty_field_description_t (field_t_cons fn ft fc)) | val field_description_cons0
(fn #ft #fc: Type0)
(n: string)
(t: typedef ft)
(fd: field_description_t fc)
: Tot (nonempty_field_description_t (field_t_cons fn ft fc)) | let field_description_cons0
(fn: Type0) (#ft: Type0) (#fc: Type0) (n: string) (t: typedef ft) (fd: field_description_t fc)
: Tot (nonempty_field_description_t (field_t_cons fn ft fc))
= {
fd_def = (fun n' -> n = n' || fd.fd_def n');
fd_empty = false;
fd_type = (fun n' -> if n = n' then ft else fd.fd_type n');
fd_typedef = (fun n' -> if n = n' then t else fd.fd_typedef n');
} | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Fields.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 3,
"end_line": 49,
"start_col": 0,
"start_line": 41
} | module Pulse.C.Types.Fields
include Pulse.C.Types.Base
open Pulse.C.Typestring
open Pulse.Lib.Pervasives
[@@noextract_to "krml"] // tactic
let norm_fields () : FStar.Tactics.Tac unit =
FStar.Tactics.norm [delta_attr [`%norm_field_attr]; iota; zeta; primops];
FStar.Tactics.trefl ()
[@@noextract_to "krml"] // primitive
val field_t_nil: Type0
[@@noextract_to "krml"] // primitive
val field_t_cons (fn: Type0) (ft: Type0) (fc: Type0): Type0
inline_for_extraction [@@noextract_to "krml"; norm_field_attr]
noeq
type field_description_t (t: Type0) : Type u#1 = {
fd_def: (string -> GTot bool);
fd_empty: (fd_empty: bool { fd_empty == true <==> (forall s . fd_def s == false) });
fd_type: (string -> Type0);
fd_typedef: ((s: string) -> Pure (typedef (fd_type s)) (requires (fd_def s)) (ensures (fun _ -> True)));
}
inline_for_extraction [@@noextract_to "krml"; norm_field_attr]
let nonempty_field_description_t (t: Type0) =
(fd: field_description_t t { fd.fd_empty == false })
[@@noextract_to "krml"] // proof-only
let field_t (#t: Type0) (fd: field_description_t t) : Tot eqtype = (s: string { fd.fd_def s })
inline_for_extraction [@@noextract_to "krml"]
let field_description_nil : field_description_t field_t_nil = {
fd_def = (fun _ -> false);
fd_empty = true;
fd_type = (fun _ -> unit);
fd_typedef = (fun _ -> false_elim ());
} | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.C.Typestring.fsti.checked",
"Pulse.C.Types.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Fields.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Typestring",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
fn: Type0 ->
n: Prims.string ->
t: Pulse.C.Types.Base.typedef ft ->
fd: Pulse.C.Types.Fields.field_description_t fc
-> Pulse.C.Types.Fields.nonempty_field_description_t (Pulse.C.Types.Fields.field_t_cons fn ft fc) | Prims.Tot | [
"total"
] | [] | [
"Prims.string",
"Pulse.C.Types.Base.typedef",
"Pulse.C.Types.Fields.field_description_t",
"Pulse.C.Types.Fields.Mkfield_description_t",
"Pulse.C.Types.Fields.field_t_cons",
"Prims.op_BarBar",
"Prims.op_Equality",
"Pulse.C.Types.Fields.__proj__Mkfield_description_t__item__fd_def",
"Prims.bool",
"Pulse.C.Types.Fields.__proj__Mkfield_description_t__item__fd_type",
"Pulse.C.Types.Fields.__proj__Mkfield_description_t__item__fd_typedef",
"Pulse.C.Types.Fields.nonempty_field_description_t"
] | [] | false | false | false | true | false | let field_description_cons0
(fn #ft #fc: Type0)
(n: string)
(t: typedef ft)
(fd: field_description_t fc)
: Tot (nonempty_field_description_t (field_t_cons fn ft fc)) =
| {
fd_def = (fun n' -> n = n' || fd.fd_def n');
fd_empty = false;
fd_type = (fun n' -> if n = n' then ft else fd.fd_type n');
fd_typedef = (fun n' -> if n = n' then t else fd.fd_typedef n')
} | false |
Pulse.Checker.Admit.fst | Pulse.Checker.Admit.check | val check
(g:env)
(pre:term)
(pre_typing:tot_typing g pre tm_vprop)
(post_hint:post_hint_opt g)
(res_ppname:ppname)
(t:st_term { Tm_Admit? t.term })
: T.Tac (checker_result_t g pre post_hint) | val check
(g:env)
(pre:term)
(pre_typing:tot_typing g pre tm_vprop)
(post_hint:post_hint_opt g)
(res_ppname:ppname)
(t:st_term { Tm_Admit? t.term })
: T.Tac (checker_result_t g pre post_hint) | let check
(g:env)
(pre:term)
(pre_typing:tot_typing g pre tm_vprop)
(post_hint:post_hint_opt g)
(res_ppname:ppname)
(t:st_term { Tm_Admit? t.term })
: T.Tac (checker_result_t g pre post_hint)
= let Tm_Admit r = t.term in
match post_hint with
| Some p ->
let ct = ctag_of_effect_annot p.effect_annot in
check_core g pre pre_typing post_hint res_ppname ({ t with term=Tm_Admit {r with ctag=ct}})
| _ ->
check_core g pre pre_typing post_hint res_ppname t | {
"file_name": "lib/steel/pulse/Pulse.Checker.Admit.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 56,
"end_line": 111,
"start_col": 0,
"start_line": 96
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Admit
module T = FStar.Tactics.V2
open Pulse.Syntax
open Pulse.Typing
open Pulse.Checker.Pure
open Pulse.Checker.Base
open Pulse.Checker.Prover
module P = Pulse.Syntax.Printer
let post_hint_compatible (p:option post_hint_t) (x:var) (t:term) (u:universe) (post:vprop) =
match p with
| None -> True
| Some p ->
p.post== close_term post x /\
p.u == u /\
p.ret_ty == t
let check_core
(g:env)
(pre:term)
(pre_typing:tot_typing g pre tm_vprop)
(post_hint:post_hint_opt g)
(res_ppname:ppname)
(t:st_term { Tm_Admit? t.term })
: T.Tac (checker_result_t g pre post_hint) =
let g = Pulse.Typing.Env.push_context g "check_admit" t.range in
let Tm_Admit { ctag = c; typ=t; post } = t.term in
let x = fresh g in
let px = v_as_nv x in
let res
: (t:term &
u:universe &
universe_of g t u &
post:vprop { post_hint_compatible post_hint x t u post } &
tot_typing (push_binding g x (fst px) t) post tm_vprop)
= match post, post_hint with
| None, None ->
fail g None "could not find a post annotation on admit, please add one"
| Some post1, Some post2 ->
fail g None
(Printf.sprintf "found two post annotations on admit: %s and %s, please remove one"
(P.term_to_string post1)
(P.term_to_string post2.post))
| Some post, _ ->
let (| u, t_typing |) = check_universe g t in
let post_opened = open_term_nv post px in
let (| post, post_typing |) =
check_tot_term (push_binding g x (fst px) t) post_opened tm_vprop
in
(| t, u, t_typing, post, post_typing |)
| _, Some post ->
let post : post_hint_t = post in
if x `Set.mem` freevars post.post
then fail g None "Impossible: unexpected freevar clash in Tm_Admit, please file a bug-report"
else (
let post_typing_rec = post_hint_typing g post x in
let post_opened = open_term_nv post.post px in
assume (close_term post_opened x == post.post);
(| post.ret_ty, post.u, post_typing_rec.ty_typing, post_opened, post_typing_rec.post_typing |)
)
in
let (| t, u, t_typing, post_opened, post_typing |) = res in
let post = close_term post_opened x in
let s : st_comp = {u;res=t;pre;post} in
assume (open_term (close_term post_opened x) x == post_opened);
let d = T_Admit _ _ c (STC _ s x t_typing pre_typing post_typing) in
prove_post_hint (try_frame_pre pre_typing (match_comp_res_with_post_hint d post_hint) res_ppname) post_hint t.range | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Checker.Pure.fsti.checked",
"Pulse.Checker.Prover.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Admit.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
g: Pulse.Typing.Env.env ->
pre: Pulse.Syntax.Base.term ->
pre_typing: Pulse.Typing.tot_typing g pre Pulse.Syntax.Base.tm_vprop ->
post_hint: Pulse.Typing.post_hint_opt g ->
res_ppname: Pulse.Syntax.Base.ppname ->
t: Pulse.Syntax.Base.st_term{Tm_Admit? (Mkst_term?.term t)}
-> FStar.Tactics.Effect.Tac (Pulse.Checker.Base.checker_result_t g pre post_hint) | FStar.Tactics.Effect.Tac | [] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.term",
"Pulse.Typing.tot_typing",
"Pulse.Syntax.Base.tm_vprop",
"Pulse.Typing.post_hint_opt",
"Pulse.Syntax.Base.ppname",
"Pulse.Syntax.Base.st_term",
"Prims.b2t",
"Pulse.Syntax.Base.uu___is_Tm_Admit",
"Pulse.Syntax.Base.__proj__Mkst_term__item__term",
"Pulse.Syntax.Base.st_term'__Tm_Admit__payload",
"Pulse.Typing.post_hint_t",
"Pulse.Checker.Admit.check_core",
"Pulse.Syntax.Base.Mkst_term",
"Pulse.Syntax.Base.Tm_Admit",
"Pulse.Syntax.Base.Mkst_term'__Tm_Admit__payload",
"Pulse.Syntax.Base.__proj__Mkst_term'__Tm_Admit__payload__item__u",
"Pulse.Syntax.Base.__proj__Mkst_term'__Tm_Admit__payload__item__typ",
"Pulse.Syntax.Base.__proj__Mkst_term'__Tm_Admit__payload__item__post",
"Pulse.Syntax.Base.__proj__Mkst_term__item__range",
"Pulse.Syntax.Base.__proj__Mkst_term__item__effect_tag",
"Pulse.Checker.Base.checker_result_t",
"Pulse.Syntax.Base.ctag",
"Pulse.Syntax.Base.ctag_of_effect_annot",
"Pulse.Typing.__proj__Mkpost_hint_t__item__effect_annot",
"FStar.Pervasives.Native.option",
"Pulse.Syntax.Base.st_term'"
] | [] | false | true | false | false | false | let check
(g: env)
(pre: term)
(pre_typing: tot_typing g pre tm_vprop)
(post_hint: post_hint_opt g)
(res_ppname: ppname)
(t: st_term{Tm_Admit? t.term})
: T.Tac (checker_result_t g pre post_hint) =
| let Tm_Admit r = t.term in
match post_hint with
| Some p ->
let ct = ctag_of_effect_annot p.effect_annot in
check_core g
pre
pre_typing
post_hint
res_ppname
({ t with term = Tm_Admit ({ r with ctag = ct }) })
| _ -> check_core g pre pre_typing post_hint res_ppname t | false |
C.Compat.Loops.fst | C.Compat.Loops.for | val for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish))) | val for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish))) | let rec for start finish inv f =
if start = finish then
()
else begin
f start;
for (UInt32.(start +^ 1ul)) finish inv f
end | {
"file_name": "krmllib/compat/C.Compat.Loops.fst",
"git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321",
"git_url": "https://github.com/FStarLang/karamel.git",
"project_name": "karamel"
} | {
"end_col": 5,
"end_line": 57,
"start_col": 0,
"start_line": 51
} | (* This module exposes a series of combinators; they are modeled using
* higher-order functions and specifications, and extracted, using a
* meta-theoretic argument, to actual C loops. *)
module C.Compat.Loops
open FStar.HyperStack.ST
open FStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module UInt32 = FStar.UInt32
module UInt64 = FStar.UInt64
include Spec.Loops
#set-options "--initial_fuel 0 --max_fuel 0 --z3rlimit 20"
(** The functions in this module use the following convention:
* - the first arguments are buffers;
* - the destination buffer comes first, followed by the input buffer (as in
* C's memcpy)
* - each buffer is followed by its length; if several buffers share the same
* length, there is a single length argument after the buffers
* - the function-specific arguments come next (e.g. the number of times one
* may want to call the function in [repeat])
* - the second to last argument is the loop invariant (which may have
* dependencies on all the parameters before)
* - the last argument is the loop body (that will depend on the invariant, and
* possibly all the other parameters before. *)
(* Generic-purpose for-loop combinators ***************************************)
(* These combinators enjoy first-class support in KaRaMeL. (See [combinators] in
* src/Simplify.ml *)
(* Currently extracting as:
for (int i = <start>; i != <finish>; ++i)
<f> i;
*)
val for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start))) | {
"checked_file": "/",
"dependencies": [
"Spec.Loops.fst.checked",
"prims.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Buffer.fst.checked"
],
"interface_file": false,
"source_file": "C.Compat.Loops.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.Loops",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "UInt64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "UInt32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
start: FStar.UInt32.t ->
finish: FStar.UInt32.t{FStar.UInt32.v finish >= FStar.UInt32.v start} ->
inv: (_: FStar.Monotonic.HyperStack.mem -> _: Prims.nat -> Type0) ->
f:
(
i:
FStar.UInt32.t
{ FStar.UInt32.v start <= FStar.UInt32.v i /\
FStar.UInt32.v i < FStar.UInt32.v finish }
-> FStar.HyperStack.ST.Stack Prims.unit)
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt32.v",
"FStar.Monotonic.HyperStack.mem",
"Prims.nat",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.unit",
"Prims.op_Addition",
"Prims.op_Equality",
"Prims.bool",
"C.Compat.Loops.for",
"FStar.UInt32.op_Plus_Hat",
"FStar.UInt32.__uint_to_t"
] | [
"recursion"
] | false | true | false | false | false | let rec for start finish inv f =
| if start = finish
then ()
else
(f start;
for (let open UInt32 in start +^ 1ul) finish inv f) | false |
Pulse.Checker.Admit.fst | Pulse.Checker.Admit.post_hint_compatible | val post_hint_compatible : p: FStar.Pervasives.Native.option Pulse.Typing.post_hint_t ->
x: Pulse.Syntax.Base.var ->
t: Pulse.Syntax.Base.term ->
u13: Pulse.Syntax.Base.universe ->
post: Pulse.Syntax.Base.vprop
-> Prims.logical | let post_hint_compatible (p:option post_hint_t) (x:var) (t:term) (u:universe) (post:vprop) =
match p with
| None -> True
| Some p ->
p.post== close_term post x /\
p.u == u /\
p.ret_ty == t | {
"file_name": "lib/steel/pulse/Pulse.Checker.Admit.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 17,
"end_line": 35,
"start_col": 0,
"start_line": 29
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Admit
module T = FStar.Tactics.V2
open Pulse.Syntax
open Pulse.Typing
open Pulse.Checker.Pure
open Pulse.Checker.Base
open Pulse.Checker.Prover
module P = Pulse.Syntax.Printer | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Env.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Checker.Pure.fsti.checked",
"Pulse.Checker.Prover.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Admit.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: FStar.Pervasives.Native.option Pulse.Typing.post_hint_t ->
x: Pulse.Syntax.Base.var ->
t: Pulse.Syntax.Base.term ->
u13: Pulse.Syntax.Base.universe ->
post: Pulse.Syntax.Base.vprop
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"Pulse.Typing.post_hint_t",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.vprop",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2",
"Pulse.Typing.__proj__Mkpost_hint_t__item__post",
"Pulse.Syntax.Naming.close_term",
"Pulse.Typing.__proj__Mkpost_hint_t__item__u",
"Pulse.Typing.__proj__Mkpost_hint_t__item__ret_ty",
"Prims.logical"
] | [] | false | false | false | true | true | let post_hint_compatible (p: option post_hint_t) (x: var) (t: term) (u: universe) (post: vprop) =
| match p with
| None -> True
| Some p -> p.post == close_term post x /\ p.u == u /\ p.ret_ty == t | false |
|
C.Compat.Loops.fst | C.Compat.Loops.reverse_for | val reverse_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish <= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start >= v i /\ v i > v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i - 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish))) | val reverse_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish <= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start >= v i /\ v i > v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i - 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish))) | let rec reverse_for start finish inv f =
if start = finish then
()
else begin
f start;
reverse_for (UInt32.(start -^ 1ul)) finish inv f
end | {
"file_name": "krmllib/compat/C.Compat.Loops.fst",
"git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321",
"git_url": "https://github.com/FStarLang/karamel.git",
"project_name": "karamel"
} | {
"end_col": 5,
"end_line": 98,
"start_col": 0,
"start_line": 92
} | (* This module exposes a series of combinators; they are modeled using
* higher-order functions and specifications, and extracted, using a
* meta-theoretic argument, to actual C loops. *)
module C.Compat.Loops
open FStar.HyperStack.ST
open FStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module UInt32 = FStar.UInt32
module UInt64 = FStar.UInt64
include Spec.Loops
#set-options "--initial_fuel 0 --max_fuel 0 --z3rlimit 20"
(** The functions in this module use the following convention:
* - the first arguments are buffers;
* - the destination buffer comes first, followed by the input buffer (as in
* C's memcpy)
* - each buffer is followed by its length; if several buffers share the same
* length, there is a single length argument after the buffers
* - the function-specific arguments come next (e.g. the number of times one
* may want to call the function in [repeat])
* - the second to last argument is the loop invariant (which may have
* dependencies on all the parameters before)
* - the last argument is the loop body (that will depend on the invariant, and
* possibly all the other parameters before. *)
(* Generic-purpose for-loop combinators ***************************************)
(* These combinators enjoy first-class support in KaRaMeL. (See [combinators] in
* src/Simplify.ml *)
(* Currently extracting as:
for (int i = <start>; i != <finish>; ++i)
<f> i;
*)
val for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish)))
let rec for start finish inv f =
if start = finish then
()
else begin
f start;
for (UInt32.(start +^ 1ul)) finish inv f
end
val for64:
start:UInt64.t ->
finish:UInt64.t{UInt64.v finish >= UInt64.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt64.t{UInt64.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt64.v i)))
(ensures (fun h_1 _ h_2 -> UInt64.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt64.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt64.v finish)))
let rec for64 start finish inv f =
if start = finish then
()
else begin
f start;
for64 (UInt64.(start +^ 1UL)) finish inv f
end
(* To be extracted as:
for (int i = <start>; i != <finish>; --i)
<f> i;
*)
val reverse_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish <= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start >= v i /\ v i > v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i - 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start))) | {
"checked_file": "/",
"dependencies": [
"Spec.Loops.fst.checked",
"prims.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Buffer.fst.checked"
],
"interface_file": false,
"source_file": "C.Compat.Loops.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.Loops",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "UInt64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "UInt32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
start: FStar.UInt32.t ->
finish: FStar.UInt32.t{FStar.UInt32.v finish <= FStar.UInt32.v start} ->
inv: (_: FStar.Monotonic.HyperStack.mem -> _: Prims.nat -> Type0) ->
f:
(
i:
FStar.UInt32.t
{ FStar.UInt32.v start >= FStar.UInt32.v i /\
FStar.UInt32.v i > FStar.UInt32.v finish }
-> FStar.HyperStack.ST.Stack Prims.unit)
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"FStar.Monotonic.HyperStack.mem",
"Prims.nat",
"Prims.l_and",
"Prims.op_GreaterThanOrEqual",
"Prims.op_GreaterThan",
"Prims.unit",
"Prims.op_Subtraction",
"Prims.op_Equality",
"Prims.bool",
"C.Compat.Loops.reverse_for",
"FStar.UInt32.op_Subtraction_Hat",
"FStar.UInt32.__uint_to_t"
] | [
"recursion"
] | false | true | false | false | false | let rec reverse_for start finish inv f =
| if start = finish
then ()
else
(f start;
reverse_for (let open UInt32 in start -^ 1ul) finish inv f) | false |
C.Compat.Loops.fst | C.Compat.Loops.for64 | val for64:
start:UInt64.t ->
finish:UInt64.t{UInt64.v finish >= UInt64.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt64.t{UInt64.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt64.v i)))
(ensures (fun h_1 _ h_2 -> UInt64.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt64.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt64.v finish))) | val for64:
start:UInt64.t ->
finish:UInt64.t{UInt64.v finish >= UInt64.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt64.t{UInt64.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt64.v i)))
(ensures (fun h_1 _ h_2 -> UInt64.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt64.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt64.v finish))) | let rec for64 start finish inv f =
if start = finish then
()
else begin
f start;
for64 (UInt64.(start +^ 1UL)) finish inv f
end | {
"file_name": "krmllib/compat/C.Compat.Loops.fst",
"git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321",
"git_url": "https://github.com/FStarLang/karamel.git",
"project_name": "karamel"
} | {
"end_col": 5,
"end_line": 75,
"start_col": 0,
"start_line": 69
} | (* This module exposes a series of combinators; they are modeled using
* higher-order functions and specifications, and extracted, using a
* meta-theoretic argument, to actual C loops. *)
module C.Compat.Loops
open FStar.HyperStack.ST
open FStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module UInt32 = FStar.UInt32
module UInt64 = FStar.UInt64
include Spec.Loops
#set-options "--initial_fuel 0 --max_fuel 0 --z3rlimit 20"
(** The functions in this module use the following convention:
* - the first arguments are buffers;
* - the destination buffer comes first, followed by the input buffer (as in
* C's memcpy)
* - each buffer is followed by its length; if several buffers share the same
* length, there is a single length argument after the buffers
* - the function-specific arguments come next (e.g. the number of times one
* may want to call the function in [repeat])
* - the second to last argument is the loop invariant (which may have
* dependencies on all the parameters before)
* - the last argument is the loop body (that will depend on the invariant, and
* possibly all the other parameters before. *)
(* Generic-purpose for-loop combinators ***************************************)
(* These combinators enjoy first-class support in KaRaMeL. (See [combinators] in
* src/Simplify.ml *)
(* Currently extracting as:
for (int i = <start>; i != <finish>; ++i)
<f> i;
*)
val for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish)))
let rec for start finish inv f =
if start = finish then
()
else begin
f start;
for (UInt32.(start +^ 1ul)) finish inv f
end
val for64:
start:UInt64.t ->
finish:UInt64.t{UInt64.v finish >= UInt64.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt64.t{UInt64.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt64.v i)))
(ensures (fun h_1 _ h_2 -> UInt64.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt64.v start))) | {
"checked_file": "/",
"dependencies": [
"Spec.Loops.fst.checked",
"prims.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Buffer.fst.checked"
],
"interface_file": false,
"source_file": "C.Compat.Loops.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.Loops",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "UInt64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "UInt32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
start: FStar.UInt64.t ->
finish: FStar.UInt64.t{FStar.UInt64.v finish >= FStar.UInt64.v start} ->
inv: (_: FStar.Monotonic.HyperStack.mem -> _: Prims.nat -> Type0) ->
f:
(
i:
FStar.UInt64.t
{ FStar.UInt64.v start <= FStar.UInt64.v i /\
FStar.UInt64.v i < FStar.UInt64.v finish }
-> FStar.HyperStack.ST.Stack Prims.unit)
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.UInt64.t",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt64.v",
"FStar.Monotonic.HyperStack.mem",
"Prims.nat",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.unit",
"Prims.op_Addition",
"Prims.op_Equality",
"Prims.bool",
"C.Compat.Loops.for64",
"FStar.UInt64.op_Plus_Hat",
"FStar.UInt64.__uint_to_t"
] | [
"recursion"
] | false | true | false | false | false | let rec for64 start finish inv f =
| if start = finish
then ()
else
(f start;
for64 (let open UInt64 in start +^ 1uL) finish inv f) | false |
C.Compat.Loops.fst | C.Compat.Loops.while | val while:
#test_pre: (HS.mem -> GTot Type0) ->
#test_post: (bool -> HS.mem -> GTot Type0) ->
$test: (unit -> Stack bool
(requires (fun h -> test_pre h))
(ensures (fun h0 x h1 -> test_post x h1))) ->
body: (unit -> Stack unit
(requires (fun h -> test_post true h))
(ensures (fun h0 _ h1 -> test_pre h1))) ->
Stack unit
(requires (fun h -> test_pre h))
(ensures (fun h0 _ h1 -> test_post false h1)) | val while:
#test_pre: (HS.mem -> GTot Type0) ->
#test_post: (bool -> HS.mem -> GTot Type0) ->
$test: (unit -> Stack bool
(requires (fun h -> test_pre h))
(ensures (fun h0 x h1 -> test_post x h1))) ->
body: (unit -> Stack unit
(requires (fun h -> test_post true h))
(ensures (fun h0 _ h1 -> test_pre h1))) ->
Stack unit
(requires (fun h -> test_pre h))
(ensures (fun h0 _ h1 -> test_post false h1)) | let rec while #test_pre #test_post test body =
if test () then begin
body ();
while #test_pre #test_post test body
end | {
"file_name": "krmllib/compat/C.Compat.Loops.fst",
"git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321",
"git_url": "https://github.com/FStarLang/karamel.git",
"project_name": "karamel"
} | {
"end_col": 5,
"end_line": 169,
"start_col": 0,
"start_line": 165
} | (* This module exposes a series of combinators; they are modeled using
* higher-order functions and specifications, and extracted, using a
* meta-theoretic argument, to actual C loops. *)
module C.Compat.Loops
open FStar.HyperStack.ST
open FStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module UInt32 = FStar.UInt32
module UInt64 = FStar.UInt64
include Spec.Loops
#set-options "--initial_fuel 0 --max_fuel 0 --z3rlimit 20"
(** The functions in this module use the following convention:
* - the first arguments are buffers;
* - the destination buffer comes first, followed by the input buffer (as in
* C's memcpy)
* - each buffer is followed by its length; if several buffers share the same
* length, there is a single length argument after the buffers
* - the function-specific arguments come next (e.g. the number of times one
* may want to call the function in [repeat])
* - the second to last argument is the loop invariant (which may have
* dependencies on all the parameters before)
* - the last argument is the loop body (that will depend on the invariant, and
* possibly all the other parameters before. *)
(* Generic-purpose for-loop combinators ***************************************)
(* These combinators enjoy first-class support in KaRaMeL. (See [combinators] in
* src/Simplify.ml *)
(* Currently extracting as:
for (int i = <start>; i != <finish>; ++i)
<f> i;
*)
val for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish)))
let rec for start finish inv f =
if start = finish then
()
else begin
f start;
for (UInt32.(start +^ 1ul)) finish inv f
end
val for64:
start:UInt64.t ->
finish:UInt64.t{UInt64.v finish >= UInt64.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt64.t{UInt64.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt64.v i)))
(ensures (fun h_1 _ h_2 -> UInt64.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt64.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt64.v finish)))
let rec for64 start finish inv f =
if start = finish then
()
else begin
f start;
for64 (UInt64.(start +^ 1UL)) finish inv f
end
(* To be extracted as:
for (int i = <start>; i != <finish>; --i)
<f> i;
*)
val reverse_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish <= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start >= v i /\ v i > v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i - 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish)))
let rec reverse_for start finish inv f =
if start = finish then
()
else begin
f start;
reverse_for (UInt32.(start -^ 1ul)) finish inv f
end
(* To be extracted as:
bool b = false;
int i = <start>;
for (; (!b) && (i != <end>); ++i) {
b = <f> i;
}
(i, b)
*)
val interruptible_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> bool -> GTot Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack bool
(requires (fun h -> inv h (UInt32.v i) false))
(ensures (fun h_1 b h_2 -> inv h_1 (UInt32.v i) false /\ inv h_2 UInt32.(v i + 1) b)) ) ->
Stack (UInt32.t * bool)
(requires (fun h -> inv h (UInt32.v start) false))
(ensures (fun _ res h_2 -> let (i, b) = res in ((if b then True else i == finish) /\ inv h_2 (UInt32.v i) b)))
let rec interruptible_for start finish inv f =
if start = finish then
(finish, false)
else
let start' = UInt32.(start +^ 1ul) in
if f start
then (start', true)
else interruptible_for start' finish inv f
(* To be extracted as:
while (true) {
bool b = <f> i;
if (b) {
break;
}
}
*)
val do_while:
inv:(HS.mem -> bool -> GTot Type0) ->
f:(unit -> Stack bool
(requires (fun h -> inv h false))
(ensures (fun h_1 b h_2 -> inv h_1 false /\ inv h_2 b)) ) ->
Stack unit
(requires (fun h -> inv h false))
(ensures (fun _ _ h_2 -> inv h_2 true))
let rec do_while inv f =
if not (f ()) then
do_while inv f
(* Extracted as:
while (test ()) {
body ();
}
*)
val while:
#test_pre: (HS.mem -> GTot Type0) ->
#test_post: (bool -> HS.mem -> GTot Type0) ->
$test: (unit -> Stack bool
(requires (fun h -> test_pre h))
(ensures (fun h0 x h1 -> test_post x h1))) ->
body: (unit -> Stack unit
(requires (fun h -> test_post true h))
(ensures (fun h0 _ h1 -> test_pre h1))) ->
Stack unit
(requires (fun h -> test_pre h)) | {
"checked_file": "/",
"dependencies": [
"Spec.Loops.fst.checked",
"prims.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Buffer.fst.checked"
],
"interface_file": false,
"source_file": "C.Compat.Loops.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.Loops",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "UInt64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "UInt32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
$test: (_: Prims.unit -> FStar.HyperStack.ST.Stack Prims.bool) ->
body: (_: Prims.unit -> FStar.HyperStack.ST.Stack Prims.unit)
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.Monotonic.HyperStack.mem",
"Prims.bool",
"Prims.unit",
"C.Compat.Loops.while"
] | [
"recursion"
] | false | true | false | false | false | let rec while #test_pre #test_post test body =
| if test ()
then
(body ();
while #test_pre #test_post test body) | false |
C.Compat.Loops.fst | C.Compat.Loops.interruptible_for | val interruptible_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> bool -> GTot Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack bool
(requires (fun h -> inv h (UInt32.v i) false))
(ensures (fun h_1 b h_2 -> inv h_1 (UInt32.v i) false /\ inv h_2 UInt32.(v i + 1) b)) ) ->
Stack (UInt32.t * bool)
(requires (fun h -> inv h (UInt32.v start) false))
(ensures (fun _ res h_2 -> let (i, b) = res in ((if b then True else i == finish) /\ inv h_2 (UInt32.v i) b))) | val interruptible_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> bool -> GTot Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack bool
(requires (fun h -> inv h (UInt32.v i) false))
(ensures (fun h_1 b h_2 -> inv h_1 (UInt32.v i) false /\ inv h_2 UInt32.(v i + 1) b)) ) ->
Stack (UInt32.t * bool)
(requires (fun h -> inv h (UInt32.v start) false))
(ensures (fun _ res h_2 -> let (i, b) = res in ((if b then True else i == finish) /\ inv h_2 (UInt32.v i) b))) | let rec interruptible_for start finish inv f =
if start = finish then
(finish, false)
else
let start' = UInt32.(start +^ 1ul) in
if f start
then (start', true)
else interruptible_for start' finish inv f | {
"file_name": "krmllib/compat/C.Compat.Loops.fst",
"git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321",
"git_url": "https://github.com/FStarLang/karamel.git",
"project_name": "karamel"
} | {
"end_col": 46,
"end_line": 125,
"start_col": 0,
"start_line": 118
} | (* This module exposes a series of combinators; they are modeled using
* higher-order functions and specifications, and extracted, using a
* meta-theoretic argument, to actual C loops. *)
module C.Compat.Loops
open FStar.HyperStack.ST
open FStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module UInt32 = FStar.UInt32
module UInt64 = FStar.UInt64
include Spec.Loops
#set-options "--initial_fuel 0 --max_fuel 0 --z3rlimit 20"
(** The functions in this module use the following convention:
* - the first arguments are buffers;
* - the destination buffer comes first, followed by the input buffer (as in
* C's memcpy)
* - each buffer is followed by its length; if several buffers share the same
* length, there is a single length argument after the buffers
* - the function-specific arguments come next (e.g. the number of times one
* may want to call the function in [repeat])
* - the second to last argument is the loop invariant (which may have
* dependencies on all the parameters before)
* - the last argument is the loop body (that will depend on the invariant, and
* possibly all the other parameters before. *)
(* Generic-purpose for-loop combinators ***************************************)
(* These combinators enjoy first-class support in KaRaMeL. (See [combinators] in
* src/Simplify.ml *)
(* Currently extracting as:
for (int i = <start>; i != <finish>; ++i)
<f> i;
*)
val for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish)))
let rec for start finish inv f =
if start = finish then
()
else begin
f start;
for (UInt32.(start +^ 1ul)) finish inv f
end
val for64:
start:UInt64.t ->
finish:UInt64.t{UInt64.v finish >= UInt64.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt64.t{UInt64.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt64.v i)))
(ensures (fun h_1 _ h_2 -> UInt64.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt64.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt64.v finish)))
let rec for64 start finish inv f =
if start = finish then
()
else begin
f start;
for64 (UInt64.(start +^ 1UL)) finish inv f
end
(* To be extracted as:
for (int i = <start>; i != <finish>; --i)
<f> i;
*)
val reverse_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish <= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start >= v i /\ v i > v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i - 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish)))
let rec reverse_for start finish inv f =
if start = finish then
()
else begin
f start;
reverse_for (UInt32.(start -^ 1ul)) finish inv f
end
(* To be extracted as:
bool b = false;
int i = <start>;
for (; (!b) && (i != <end>); ++i) {
b = <f> i;
}
(i, b)
*)
val interruptible_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> bool -> GTot Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack bool
(requires (fun h -> inv h (UInt32.v i) false))
(ensures (fun h_1 b h_2 -> inv h_1 (UInt32.v i) false /\ inv h_2 UInt32.(v i + 1) b)) ) ->
Stack (UInt32.t * bool)
(requires (fun h -> inv h (UInt32.v start) false)) | {
"checked_file": "/",
"dependencies": [
"Spec.Loops.fst.checked",
"prims.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Buffer.fst.checked"
],
"interface_file": false,
"source_file": "C.Compat.Loops.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.Loops",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "UInt64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "UInt32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
start: FStar.UInt32.t ->
finish: FStar.UInt32.t{FStar.UInt32.v finish >= FStar.UInt32.v start} ->
inv: (_: FStar.Monotonic.HyperStack.mem -> _: Prims.nat -> _: Prims.bool -> Prims.GTot Type0) ->
f:
(
i:
FStar.UInt32.t
{ FStar.UInt32.v start <= FStar.UInt32.v i /\
FStar.UInt32.v i < FStar.UInt32.v finish }
-> FStar.HyperStack.ST.Stack Prims.bool)
-> FStar.HyperStack.ST.Stack (FStar.UInt32.t * Prims.bool) | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt32.v",
"FStar.Monotonic.HyperStack.mem",
"Prims.nat",
"Prims.bool",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Addition",
"Prims.op_Equality",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.tuple2",
"C.Compat.Loops.interruptible_for",
"FStar.UInt32.op_Plus_Hat",
"FStar.UInt32.__uint_to_t"
] | [
"recursion"
] | false | true | false | false | false | let rec interruptible_for start finish inv f =
| if start = finish
then (finish, false)
else
let start' = let open UInt32 in start +^ 1ul in
if f start then (start', true) else interruptible_for start' finish inv f | false |
C.Compat.Loops.fst | C.Compat.Loops.do_while | val do_while:
inv:(HS.mem -> bool -> GTot Type0) ->
f:(unit -> Stack bool
(requires (fun h -> inv h false))
(ensures (fun h_1 b h_2 -> inv h_1 false /\ inv h_2 b)) ) ->
Stack unit
(requires (fun h -> inv h false))
(ensures (fun _ _ h_2 -> inv h_2 true)) | val do_while:
inv:(HS.mem -> bool -> GTot Type0) ->
f:(unit -> Stack bool
(requires (fun h -> inv h false))
(ensures (fun h_1 b h_2 -> inv h_1 false /\ inv h_2 b)) ) ->
Stack unit
(requires (fun h -> inv h false))
(ensures (fun _ _ h_2 -> inv h_2 true)) | let rec do_while inv f =
if not (f ()) then
do_while inv f | {
"file_name": "krmllib/compat/C.Compat.Loops.fst",
"git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321",
"git_url": "https://github.com/FStarLang/karamel.git",
"project_name": "karamel"
} | {
"end_col": 18,
"end_line": 145,
"start_col": 0,
"start_line": 143
} | (* This module exposes a series of combinators; they are modeled using
* higher-order functions and specifications, and extracted, using a
* meta-theoretic argument, to actual C loops. *)
module C.Compat.Loops
open FStar.HyperStack.ST
open FStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module UInt32 = FStar.UInt32
module UInt64 = FStar.UInt64
include Spec.Loops
#set-options "--initial_fuel 0 --max_fuel 0 --z3rlimit 20"
(** The functions in this module use the following convention:
* - the first arguments are buffers;
* - the destination buffer comes first, followed by the input buffer (as in
* C's memcpy)
* - each buffer is followed by its length; if several buffers share the same
* length, there is a single length argument after the buffers
* - the function-specific arguments come next (e.g. the number of times one
* may want to call the function in [repeat])
* - the second to last argument is the loop invariant (which may have
* dependencies on all the parameters before)
* - the last argument is the loop body (that will depend on the invariant, and
* possibly all the other parameters before. *)
(* Generic-purpose for-loop combinators ***************************************)
(* These combinators enjoy first-class support in KaRaMeL. (See [combinators] in
* src/Simplify.ml *)
(* Currently extracting as:
for (int i = <start>; i != <finish>; ++i)
<f> i;
*)
val for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish)))
let rec for start finish inv f =
if start = finish then
()
else begin
f start;
for (UInt32.(start +^ 1ul)) finish inv f
end
val for64:
start:UInt64.t ->
finish:UInt64.t{UInt64.v finish >= UInt64.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt64.t{UInt64.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt64.v i)))
(ensures (fun h_1 _ h_2 -> UInt64.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt64.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt64.v finish)))
let rec for64 start finish inv f =
if start = finish then
()
else begin
f start;
for64 (UInt64.(start +^ 1UL)) finish inv f
end
(* To be extracted as:
for (int i = <start>; i != <finish>; --i)
<f> i;
*)
val reverse_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish <= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start >= v i /\ v i > v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i - 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish)))
let rec reverse_for start finish inv f =
if start = finish then
()
else begin
f start;
reverse_for (UInt32.(start -^ 1ul)) finish inv f
end
(* To be extracted as:
bool b = false;
int i = <start>;
for (; (!b) && (i != <end>); ++i) {
b = <f> i;
}
(i, b)
*)
val interruptible_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> bool -> GTot Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack bool
(requires (fun h -> inv h (UInt32.v i) false))
(ensures (fun h_1 b h_2 -> inv h_1 (UInt32.v i) false /\ inv h_2 UInt32.(v i + 1) b)) ) ->
Stack (UInt32.t * bool)
(requires (fun h -> inv h (UInt32.v start) false))
(ensures (fun _ res h_2 -> let (i, b) = res in ((if b then True else i == finish) /\ inv h_2 (UInt32.v i) b)))
let rec interruptible_for start finish inv f =
if start = finish then
(finish, false)
else
let start' = UInt32.(start +^ 1ul) in
if f start
then (start', true)
else interruptible_for start' finish inv f
(* To be extracted as:
while (true) {
bool b = <f> i;
if (b) {
break;
}
}
*)
val do_while:
inv:(HS.mem -> bool -> GTot Type0) ->
f:(unit -> Stack bool
(requires (fun h -> inv h false))
(ensures (fun h_1 b h_2 -> inv h_1 false /\ inv h_2 b)) ) ->
Stack unit
(requires (fun h -> inv h false)) | {
"checked_file": "/",
"dependencies": [
"Spec.Loops.fst.checked",
"prims.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Buffer.fst.checked"
],
"interface_file": false,
"source_file": "C.Compat.Loops.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.Loops",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "UInt64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "UInt32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
inv: (_: FStar.Monotonic.HyperStack.mem -> _: Prims.bool -> Prims.GTot Type0) ->
f: (_: Prims.unit -> FStar.HyperStack.ST.Stack Prims.bool)
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.Monotonic.HyperStack.mem",
"Prims.bool",
"Prims.unit",
"Prims.l_and",
"C.Compat.Loops.do_while",
"Prims.op_Negation"
] | [
"recursion"
] | false | true | false | false | false | let rec do_while inv f =
| if not (f ()) then do_while inv f | false |
Hacl.Impl.Curve25519.AddAndDouble.fst | Hacl.Impl.Curve25519.AddAndDouble.point_add_and_double | val point_add_and_double:
#s:field_spec
-> q:point s
-> p01_tmp1:lbuffer (limb s) (8ul *! nlimb s)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
let nq = gsub p01_tmp1 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1 (2ul *! nlimb s) (2ul *! nlimb s) in
live h0 q /\ live h0 p01_tmp1 /\ live h0 tmp2 /\
disjoint q p01_tmp1 /\ disjoint q tmp2 /\ disjoint p01_tmp1 tmp2 /\
state_inv_t h0 (get_x q) /\ state_inv_t h0 (get_z q) /\
state_inv_t h0 (get_x nq) /\ state_inv_t h0 (get_z nq) /\
state_inv_t h0 (get_x nq_p1) /\ state_inv_t h0 (get_z nq_p1))
(ensures fun h0 _ h1 -> (
let nq = gsub p01_tmp1 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1 (2ul *! nlimb s) (2ul *! nlimb s) in
modifies (loc p01_tmp1 |+| loc tmp2) h0 h1 /\
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
state_inv_t h1 (get_x nq_p1) /\ state_inv_t h1 (get_z nq_p1) /\
(let p2, p3 = P.add_and_double (fget_xz h0 q) (fget_xz h0 nq) (fget_xz h0 nq_p1) in
fget_xz h1 nq == p2 /\ fget_xz h1 nq_p1 == p3))) | val point_add_and_double:
#s:field_spec
-> q:point s
-> p01_tmp1:lbuffer (limb s) (8ul *! nlimb s)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
let nq = gsub p01_tmp1 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1 (2ul *! nlimb s) (2ul *! nlimb s) in
live h0 q /\ live h0 p01_tmp1 /\ live h0 tmp2 /\
disjoint q p01_tmp1 /\ disjoint q tmp2 /\ disjoint p01_tmp1 tmp2 /\
state_inv_t h0 (get_x q) /\ state_inv_t h0 (get_z q) /\
state_inv_t h0 (get_x nq) /\ state_inv_t h0 (get_z nq) /\
state_inv_t h0 (get_x nq_p1) /\ state_inv_t h0 (get_z nq_p1))
(ensures fun h0 _ h1 -> (
let nq = gsub p01_tmp1 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1 (2ul *! nlimb s) (2ul *! nlimb s) in
modifies (loc p01_tmp1 |+| loc tmp2) h0 h1 /\
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
state_inv_t h1 (get_x nq_p1) /\ state_inv_t h1 (get_z nq_p1) /\
(let p2, p3 = P.add_and_double (fget_xz h0 q) (fget_xz h0 nq) (fget_xz h0 nq_p1) in
fget_xz h1 nq == p2 /\ fget_xz h1 nq_p1 == p3))) | let point_add_and_double #s q p01_tmp1 tmp2 =
let h0 = ST.get () in
let nq : point s = sub p01_tmp1 0ul (2ul *! nlimb s) in
let nq_p1 : point s = sub p01_tmp1 (2ul *! nlimb s) (2ul *! nlimb s) in
let tmp1 = sub p01_tmp1 (4ul *! nlimb s) (4ul *! nlimb s) in
let x1 = sub q 0ul (nlimb s) in
let x2 = sub nq 0ul (nlimb s) in
let z2 = sub nq (nlimb s) (nlimb s) in
let z3 = sub nq_p1 (nlimb s) (nlimb s) in
let a : felem s = sub tmp1 0ul (nlimb s) in
let b : felem s = sub tmp1 (nlimb s) (nlimb s) in
let ab : felem2 s = sub tmp1 0ul (2ul *! nlimb s) in
let dc : felem2 s = sub tmp1 (2ul *! nlimb s) (2ul *! nlimb s) in
fadd a x2 z2; // a = x2 + z2
fsub b x2 z2; // b = x2 - z2
point_add_and_double0 #s nq_p1 ab dc tmp2;
point_add_and_double1 #s nq nq_p1 tmp1 tmp2;
fmul z3 z3 x1 tmp2; // z3 = x1 * (da - cb) ^ 2
S.lemma_add_and_double (fget_xz h0 q) (fget_xz h0 nq) (fget_xz h0 nq_p1) | {
"file_name": "code/curve25519/Hacl.Impl.Curve25519.AddAndDouble.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 74,
"end_line": 192,
"start_col": 0,
"start_line": 170
} | module Hacl.Impl.Curve25519.AddAndDouble
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Curve25519.Fields
module ST = FStar.HyperStack.ST
module F51 = Hacl.Impl.Curve25519.Field51
module F64 = Hacl.Impl.Curve25519.Field64
module P = Spec.Curve25519
module S = Hacl.Spec.Curve25519.AddAndDouble
#reset-options "--z3rlimit 300 --fuel 0 --ifuel 1 --using_facts_from '* -FStar.Seq' --record_options"
inline_for_extraction noextract
let point (s:field_spec) = lbuffer (limb s) (nlimb s +! nlimb s)
(* NEEDED ONLY FOR WRAPPERS *)
inline_for_extraction noextract
let point51 = lbuffer uint64 10ul
inline_for_extraction noextract
let point64 = lbuffer uint64 8ul
(* NEEDED ONLY FOR WRAPPERS *)
let get_x #s (p:point s) = gsub p 0ul (nlimb s)
let get_z #s (p:point s) = gsub p (nlimb s) (nlimb s)
let fget_x (#s:field_spec) (h:mem) (p:point s) = feval h (gsub p 0ul (nlimb s))
let fget_z (#s:field_spec) (h:mem) (p:point s) = feval h (gsub p (nlimb s) (nlimb s))
let fget_xz (#s:field_spec) (h:mem) (p:point s) = fget_x h p, fget_z h p
val point_post_sub_t:#s:field_spec -> h:mem -> f:felem s -> Type0
let point_post_sub_t #s h f =
match s with
| M51 -> F51.felem_fits h f (9, 10, 9, 9, 9)
| M64 -> True
val point_post_add_t:#s:field_spec -> h:mem -> f:felem s -> Type0
let point_post_add_t #s h f =
match s with
| M51 -> F51.felem_fits h f (2, 4, 2, 2, 2)
| M64 -> True
val point_add_and_double0:
#s:field_spec
-> nq_p1:point s
-> ab:lbuffer (limb s) (2ul *! nlimb s)
-> dc:lbuffer (limb s) (2ul *! nlimb s)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
live h0 nq_p1 /\ live h0 ab /\ live h0 dc /\ live h0 tmp2 /\
disjoint nq_p1 ab /\ disjoint nq_p1 dc /\ disjoint nq_p1 tmp2 /\
disjoint ab dc /\ disjoint ab tmp2 /\ disjoint dc tmp2 /\
state_inv_t h0 (get_x nq_p1) /\ state_inv_t h0 (get_z nq_p1) /\
point_post_add_t h0 (gsub ab 0ul (nlimb s)) /\
point_post_sub_t h0 (gsub ab (nlimb s) (nlimb s)))
(ensures fun h0 _ h1 ->
modifies (loc nq_p1 |+| loc dc |+| loc tmp2) h0 h1 /\
point_post_add_t h1 (get_x nq_p1) /\ point_post_sub_t h1 (get_z nq_p1) /\
fget_xz h1 nq_p1 == S.add_and_double1_0 (fget_x h0 ab) (fget_z h0 ab) (fget_xz h0 nq_p1))
[@ Meta.Attribute.inline_ ]
let point_add_and_double0 #s nq_p1 ab dc tmp2 =
let x3 = sub nq_p1 0ul (nlimb s) in
let z3 = sub nq_p1 (nlimb s) (nlimb s) in
let a : felem s = sub ab 0ul (nlimb s) in
let b : felem s = sub ab (nlimb s) (nlimb s) in
let d : felem s = sub dc 0ul (nlimb s) in
let c : felem s = sub dc (nlimb s) (nlimb s) in
fadd c x3 z3; // c = x3 + z3
fsub d x3 z3; // d = x3 - z3
(* CAN RUN IN PARALLEL *)
//fmul d d a; // d = da = d * a
//fmul c c b; // c = cb = c * b
fmul2 dc dc ab tmp2; // d|c = d*a|c*b
fadd x3 d c; // x3 = da + cb
fsub z3 d c // z3 = da - cb
val point_add_and_double1:
#s:field_spec
-> nq:point s
-> nq_p1:point s
-> tmp1:lbuffer (limb s) (4ul *! nlimb s)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
live h0 nq /\ live h0 nq_p1 /\ live h0 tmp1 /\ live h0 tmp2 /\
disjoint nq nq_p1 /\ disjoint nq tmp1 /\ disjoint nq tmp2 /\
disjoint nq_p1 tmp1 /\ disjoint nq_p1 tmp2 /\ disjoint tmp1 tmp2 /\
state_inv_t h0 (get_x nq) /\ state_inv_t h0 (get_z nq) /\
point_post_add_t h0 (gsub tmp1 0ul (nlimb s)) /\
point_post_sub_t h0 (gsub tmp1 (nlimb s) (nlimb s)) /\
point_post_add_t h0 (get_x nq_p1) /\ point_post_sub_t h0 (get_z nq_p1))
(ensures fun h0 _ h1 ->
modifies (loc nq |+| loc nq_p1 |+| loc tmp1 |+| loc tmp2) h0 h1 /\
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
state_inv_t h1 (get_x nq_p1) /\ state_inv_t h1 (get_z nq_p1) /\
(fget_xz h1 nq, fget_xz h1 nq_p1) ==
S.add_and_double1_1 (feval h0 (gsub tmp1 0ul (nlimb s)))
(feval h0 (gsub tmp1 (nlimb s) (nlimb s))) (fget_xz h0 nq_p1))
[@ Meta.Attribute.inline_ ]
let point_add_and_double1 #s nq nq_p1 tmp1 tmp2 =
let x2 = sub nq 0ul (nlimb s) in
let z2 = sub nq (nlimb s) (nlimb s) in
let x3 = sub nq_p1 0ul (nlimb s) in
let z3 = sub nq_p1 (nlimb s) (nlimb s) in
let a : felem s = sub tmp1 0ul (nlimb s) in
let b : felem s = sub tmp1 (nlimb s) (nlimb s) in
let d : felem s = sub tmp1 (2ul *! nlimb s) (nlimb s) in
let c : felem s = sub tmp1 (3ul *! nlimb s) (nlimb s) in
let ab : felem2 s = sub tmp1 0ul (2ul *! nlimb s) in
let dc : felem2 s = sub tmp1 (2ul *! nlimb s) (2ul *! nlimb s) in
(* CAN RUN IN PARALLEL *)
//fsqr d a; // d = aa = a^2
//fsqr c b; // c = bb = b^2
fsqr2 dc ab tmp2; // d|c = aa | bb
(* CAN RUN IN PARALLEL *)
//fsqr x3 x3; // x3 = (da + cb) ^ 2
//fsqr z3 z3; // z3 = (da - cb) ^ 2
fsqr2 nq_p1 nq_p1 tmp2; // x3|z3 = x3*x3|z3*z3
copy_felem a c; // a = bb
fsub c d c; // c = e = aa - bb
assert_norm (121665 < pow2 17);
fmul1 b c (u64 121665); // b = e * 121665
fadd b b d; // b = (e * 121665) + aa
(* CAN RUN IN PARALLEL *)
//fmul x2 d a; // x2 = aa * bb
//fmul z2 c b; // z2 = e * (aa + (e * 121665))
fmul2 nq dc ab tmp2 // x2|z2 = aa * bb | e * (aa + (e * 121665))
val point_add_and_double:
#s:field_spec
-> q:point s
-> p01_tmp1:lbuffer (limb s) (8ul *! nlimb s)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
let nq = gsub p01_tmp1 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1 (2ul *! nlimb s) (2ul *! nlimb s) in
live h0 q /\ live h0 p01_tmp1 /\ live h0 tmp2 /\
disjoint q p01_tmp1 /\ disjoint q tmp2 /\ disjoint p01_tmp1 tmp2 /\
state_inv_t h0 (get_x q) /\ state_inv_t h0 (get_z q) /\
state_inv_t h0 (get_x nq) /\ state_inv_t h0 (get_z nq) /\
state_inv_t h0 (get_x nq_p1) /\ state_inv_t h0 (get_z nq_p1))
(ensures fun h0 _ h1 -> (
let nq = gsub p01_tmp1 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1 (2ul *! nlimb s) (2ul *! nlimb s) in
modifies (loc p01_tmp1 |+| loc tmp2) h0 h1 /\
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
state_inv_t h1 (get_x nq_p1) /\ state_inv_t h1 (get_z nq_p1) /\
(let p2, p3 = P.add_and_double (fget_xz h0 q) (fget_xz h0 nq) (fget_xz h0 nq_p1) in
fget_xz h1 nq == p2 /\ fget_xz h1 nq_p1 == p3)))
#push-options "--z3rlimit 450" | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Curve25519.AddAndDouble.fst.checked",
"Hacl.Impl.Curve25519.Fields.fst.checked",
"Hacl.Impl.Curve25519.Field64.fst.checked",
"Hacl.Impl.Curve25519.Field51.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Curve25519.AddAndDouble.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.AddAndDouble",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": "F64"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Curve25519.Field51",
"short_module": "F51"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"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": 450,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
q: Hacl.Impl.Curve25519.AddAndDouble.point s ->
p01_tmp1:
Lib.Buffer.lbuffer (Hacl.Impl.Curve25519.Fields.Core.limb s)
(8ul *! Hacl.Impl.Curve25519.Fields.Core.nlimb s) ->
tmp2: Hacl.Impl.Curve25519.Fields.Core.felem_wide2 s
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Curve25519.Fields.Core.field_spec",
"Hacl.Impl.Curve25519.AddAndDouble.point",
"Lib.Buffer.lbuffer",
"Hacl.Impl.Curve25519.Fields.Core.limb",
"Lib.IntTypes.op_Star_Bang",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.Curve25519.Fields.Core.nlimb",
"Hacl.Impl.Curve25519.Fields.Core.felem_wide2",
"Hacl.Spec.Curve25519.AddAndDouble.lemma_add_and_double",
"Hacl.Impl.Curve25519.AddAndDouble.fget_xz",
"Prims.unit",
"Hacl.Impl.Curve25519.Fields.Core.fmul",
"Hacl.Impl.Curve25519.AddAndDouble.point_add_and_double1",
"Hacl.Impl.Curve25519.AddAndDouble.point_add_and_double0",
"Hacl.Impl.Curve25519.Fields.Core.fsub",
"Hacl.Impl.Curve25519.Fields.Core.fadd",
"Hacl.Impl.Curve25519.Fields.Core.felem2",
"Lib.Buffer.sub",
"Lib.Buffer.MUT",
"Lib.Buffer.lbuffer_t",
"Hacl.Impl.Curve25519.Fields.Core.felem",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.IntTypes.op_Plus_Bang",
"Lib.IntTypes.mul",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | false | true | false | false | false | let point_add_and_double #s q p01_tmp1 tmp2 =
| let h0 = ST.get () in
let nq:point s = sub p01_tmp1 0ul (2ul *! nlimb s) in
let nq_p1:point s = sub p01_tmp1 (2ul *! nlimb s) (2ul *! nlimb s) in
let tmp1 = sub p01_tmp1 (4ul *! nlimb s) (4ul *! nlimb s) in
let x1 = sub q 0ul (nlimb s) in
let x2 = sub nq 0ul (nlimb s) in
let z2 = sub nq (nlimb s) (nlimb s) in
let z3 = sub nq_p1 (nlimb s) (nlimb s) in
let a:felem s = sub tmp1 0ul (nlimb s) in
let b:felem s = sub tmp1 (nlimb s) (nlimb s) in
let ab:felem2 s = sub tmp1 0ul (2ul *! nlimb s) in
let dc:felem2 s = sub tmp1 (2ul *! nlimb s) (2ul *! nlimb s) in
fadd a x2 z2;
fsub b x2 z2;
point_add_and_double0 #s nq_p1 ab dc tmp2;
point_add_and_double1 #s nq nq_p1 tmp1 tmp2;
fmul z3 z3 x1 tmp2;
S.lemma_add_and_double (fget_xz h0 q) (fget_xz h0 nq) (fget_xz h0 nq_p1) | false |
C.Compat.Loops.fst | C.Compat.Loops.interruptible_reverse_for | val interruptible_reverse_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish <= UInt32.v start} ->
inv:(HS.mem -> nat -> bool -> GTot Type0) ->
f:(i:UInt32.t{UInt32.(v start >= v i /\ v i > v finish)} -> Stack bool
(requires (fun h -> inv h (UInt32.v i) false))
(ensures (fun h_1 b h_2 -> inv h_1 (UInt32.v i) false /\ inv h_2 UInt32.(v i - 1) b)) ) ->
Stack (UInt32.t * bool)
(requires (fun h -> inv h (UInt32.v start) false))
(ensures (fun _ res h_2 -> let (i, b) = res in ((if b then True else i == finish) /\ inv h_2 (UInt32.v i) b))) | val interruptible_reverse_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish <= UInt32.v start} ->
inv:(HS.mem -> nat -> bool -> GTot Type0) ->
f:(i:UInt32.t{UInt32.(v start >= v i /\ v i > v finish)} -> Stack bool
(requires (fun h -> inv h (UInt32.v i) false))
(ensures (fun h_1 b h_2 -> inv h_1 (UInt32.v i) false /\ inv h_2 UInt32.(v i - 1) b)) ) ->
Stack (UInt32.t * bool)
(requires (fun h -> inv h (UInt32.v start) false))
(ensures (fun _ res h_2 -> let (i, b) = res in ((if b then True else i == finish) /\ inv h_2 (UInt32.v i) b))) | let rec interruptible_reverse_for start finish inv f =
if start = finish then
(finish, false)
else
let start' = UInt32.(start -^ 1ul) in
if f start
then (start', true)
else interruptible_reverse_for start' finish inv f | {
"file_name": "krmllib/compat/C.Compat.Loops.fst",
"git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321",
"git_url": "https://github.com/FStarLang/karamel.git",
"project_name": "karamel"
} | {
"end_col": 54,
"end_line": 197,
"start_col": 0,
"start_line": 190
} | (* This module exposes a series of combinators; they are modeled using
* higher-order functions and specifications, and extracted, using a
* meta-theoretic argument, to actual C loops. *)
module C.Compat.Loops
open FStar.HyperStack.ST
open FStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module UInt32 = FStar.UInt32
module UInt64 = FStar.UInt64
include Spec.Loops
#set-options "--initial_fuel 0 --max_fuel 0 --z3rlimit 20"
(** The functions in this module use the following convention:
* - the first arguments are buffers;
* - the destination buffer comes first, followed by the input buffer (as in
* C's memcpy)
* - each buffer is followed by its length; if several buffers share the same
* length, there is a single length argument after the buffers
* - the function-specific arguments come next (e.g. the number of times one
* may want to call the function in [repeat])
* - the second to last argument is the loop invariant (which may have
* dependencies on all the parameters before)
* - the last argument is the loop body (that will depend on the invariant, and
* possibly all the other parameters before. *)
(* Generic-purpose for-loop combinators ***************************************)
(* These combinators enjoy first-class support in KaRaMeL. (See [combinators] in
* src/Simplify.ml *)
(* Currently extracting as:
for (int i = <start>; i != <finish>; ++i)
<f> i;
*)
val for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish)))
let rec for start finish inv f =
if start = finish then
()
else begin
f start;
for (UInt32.(start +^ 1ul)) finish inv f
end
val for64:
start:UInt64.t ->
finish:UInt64.t{UInt64.v finish >= UInt64.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt64.t{UInt64.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt64.v i)))
(ensures (fun h_1 _ h_2 -> UInt64.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt64.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt64.v finish)))
let rec for64 start finish inv f =
if start = finish then
()
else begin
f start;
for64 (UInt64.(start +^ 1UL)) finish inv f
end
(* To be extracted as:
for (int i = <start>; i != <finish>; --i)
<f> i;
*)
val reverse_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish <= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start >= v i /\ v i > v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i - 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish)))
let rec reverse_for start finish inv f =
if start = finish then
()
else begin
f start;
reverse_for (UInt32.(start -^ 1ul)) finish inv f
end
(* To be extracted as:
bool b = false;
int i = <start>;
for (; (!b) && (i != <end>); ++i) {
b = <f> i;
}
(i, b)
*)
val interruptible_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> bool -> GTot Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack bool
(requires (fun h -> inv h (UInt32.v i) false))
(ensures (fun h_1 b h_2 -> inv h_1 (UInt32.v i) false /\ inv h_2 UInt32.(v i + 1) b)) ) ->
Stack (UInt32.t * bool)
(requires (fun h -> inv h (UInt32.v start) false))
(ensures (fun _ res h_2 -> let (i, b) = res in ((if b then True else i == finish) /\ inv h_2 (UInt32.v i) b)))
let rec interruptible_for start finish inv f =
if start = finish then
(finish, false)
else
let start' = UInt32.(start +^ 1ul) in
if f start
then (start', true)
else interruptible_for start' finish inv f
(* To be extracted as:
while (true) {
bool b = <f> i;
if (b) {
break;
}
}
*)
val do_while:
inv:(HS.mem -> bool -> GTot Type0) ->
f:(unit -> Stack bool
(requires (fun h -> inv h false))
(ensures (fun h_1 b h_2 -> inv h_1 false /\ inv h_2 b)) ) ->
Stack unit
(requires (fun h -> inv h false))
(ensures (fun _ _ h_2 -> inv h_2 true))
let rec do_while inv f =
if not (f ()) then
do_while inv f
(* Extracted as:
while (test ()) {
body ();
}
*)
val while:
#test_pre: (HS.mem -> GTot Type0) ->
#test_post: (bool -> HS.mem -> GTot Type0) ->
$test: (unit -> Stack bool
(requires (fun h -> test_pre h))
(ensures (fun h0 x h1 -> test_post x h1))) ->
body: (unit -> Stack unit
(requires (fun h -> test_post true h))
(ensures (fun h0 _ h1 -> test_pre h1))) ->
Stack unit
(requires (fun h -> test_pre h))
(ensures (fun h0 _ h1 -> test_post false h1))
let rec while #test_pre #test_post test body =
if test () then begin
body ();
while #test_pre #test_post test body
end
(* To be extracted as:
int i = <start>;
bool b = false;
for (; (!b) && (i != <end>); --i) {
b = <f> i;
}
// i and b must be in scope after the loop
*)
val interruptible_reverse_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish <= UInt32.v start} ->
inv:(HS.mem -> nat -> bool -> GTot Type0) ->
f:(i:UInt32.t{UInt32.(v start >= v i /\ v i > v finish)} -> Stack bool
(requires (fun h -> inv h (UInt32.v i) false))
(ensures (fun h_1 b h_2 -> inv h_1 (UInt32.v i) false /\ inv h_2 UInt32.(v i - 1) b)) ) ->
Stack (UInt32.t * bool)
(requires (fun h -> inv h (UInt32.v start) false)) | {
"checked_file": "/",
"dependencies": [
"Spec.Loops.fst.checked",
"prims.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Buffer.fst.checked"
],
"interface_file": false,
"source_file": "C.Compat.Loops.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.Loops",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "UInt64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "UInt32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
start: FStar.UInt32.t ->
finish: FStar.UInt32.t{FStar.UInt32.v finish <= FStar.UInt32.v start} ->
inv: (_: FStar.Monotonic.HyperStack.mem -> _: Prims.nat -> _: Prims.bool -> Prims.GTot Type0) ->
f:
(
i:
FStar.UInt32.t
{ FStar.UInt32.v start >= FStar.UInt32.v i /\
FStar.UInt32.v i > FStar.UInt32.v finish }
-> FStar.HyperStack.ST.Stack Prims.bool)
-> FStar.HyperStack.ST.Stack (FStar.UInt32.t * Prims.bool) | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"FStar.Monotonic.HyperStack.mem",
"Prims.nat",
"Prims.bool",
"Prims.l_and",
"Prims.op_GreaterThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_Subtraction",
"Prims.op_Equality",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.tuple2",
"C.Compat.Loops.interruptible_reverse_for",
"FStar.UInt32.op_Subtraction_Hat",
"FStar.UInt32.__uint_to_t"
] | [
"recursion"
] | false | true | false | false | false | let rec interruptible_reverse_for start finish inv f =
| if start = finish
then (finish, false)
else
let start' = let open UInt32 in start -^ 1ul in
if f start then (start', true) else interruptible_reverse_for start' finish inv f | false |
C.Compat.Loops.fst | C.Compat.Loops.total_while_gen | val total_while_gen
(#t: Type)
(#a: (t -> Type))
(tmes: (x: t -> GTot (a x)))
(tinv: (bool -> t -> GTot Type0))
(tcontinue: (t -> Tot bool))
(body:
(x: t
-> Pure t
(requires (tinv true x))
(ensures
(fun y ->
tinv (tcontinue y) y /\ (if tcontinue y then tmes y << tmes x else True)))))
(x: t)
: Pure t (requires (tinv true x)) (ensures (fun y -> tinv false y)) (decreases (tmes x)) | val total_while_gen
(#t: Type)
(#a: (t -> Type))
(tmes: (x: t -> GTot (a x)))
(tinv: (bool -> t -> GTot Type0))
(tcontinue: (t -> Tot bool))
(body:
(x: t
-> Pure t
(requires (tinv true x))
(ensures
(fun y ->
tinv (tcontinue y) y /\ (if tcontinue y then tmes y << tmes x else True)))))
(x: t)
: Pure t (requires (tinv true x)) (ensures (fun y -> tinv false y)) (decreases (tmes x)) | let rec total_while_gen
(#t: Type)
(#a:t -> Type)
(tmes: (x:t -> GTot (a x)))
(tinv: (bool -> t -> GTot Type0))
(tcontinue: (t -> Tot bool))
(body:
(x: t) ->
Pure t
(requires (tinv true x))
(ensures (fun y ->
tinv (tcontinue y) y /\ (
if tcontinue y then tmes y << tmes x else True)
)))
(x: t)
: Pure t
(requires (tinv true x))
(ensures (fun y -> tinv false y))
(decreases (tmes x))
= let y = body x in
let continue = tcontinue y in
if continue
then total_while_gen tmes tinv tcontinue body y
else y | {
"file_name": "krmllib/compat/C.Compat.Loops.fst",
"git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321",
"git_url": "https://github.com/FStarLang/karamel.git",
"project_name": "karamel"
} | {
"end_col": 8,
"end_line": 469,
"start_col": 0,
"start_line": 446
} | (* This module exposes a series of combinators; they are modeled using
* higher-order functions and specifications, and extracted, using a
* meta-theoretic argument, to actual C loops. *)
module C.Compat.Loops
open FStar.HyperStack.ST
open FStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module UInt32 = FStar.UInt32
module UInt64 = FStar.UInt64
include Spec.Loops
#set-options "--initial_fuel 0 --max_fuel 0 --z3rlimit 20"
(** The functions in this module use the following convention:
* - the first arguments are buffers;
* - the destination buffer comes first, followed by the input buffer (as in
* C's memcpy)
* - each buffer is followed by its length; if several buffers share the same
* length, there is a single length argument after the buffers
* - the function-specific arguments come next (e.g. the number of times one
* may want to call the function in [repeat])
* - the second to last argument is the loop invariant (which may have
* dependencies on all the parameters before)
* - the last argument is the loop body (that will depend on the invariant, and
* possibly all the other parameters before. *)
(* Generic-purpose for-loop combinators ***************************************)
(* These combinators enjoy first-class support in KaRaMeL. (See [combinators] in
* src/Simplify.ml *)
(* Currently extracting as:
for (int i = <start>; i != <finish>; ++i)
<f> i;
*)
val for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish)))
let rec for start finish inv f =
if start = finish then
()
else begin
f start;
for (UInt32.(start +^ 1ul)) finish inv f
end
val for64:
start:UInt64.t ->
finish:UInt64.t{UInt64.v finish >= UInt64.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt64.t{UInt64.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt64.v i)))
(ensures (fun h_1 _ h_2 -> UInt64.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt64.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt64.v finish)))
let rec for64 start finish inv f =
if start = finish then
()
else begin
f start;
for64 (UInt64.(start +^ 1UL)) finish inv f
end
(* To be extracted as:
for (int i = <start>; i != <finish>; --i)
<f> i;
*)
val reverse_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish <= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start >= v i /\ v i > v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i - 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish)))
let rec reverse_for start finish inv f =
if start = finish then
()
else begin
f start;
reverse_for (UInt32.(start -^ 1ul)) finish inv f
end
(* To be extracted as:
bool b = false;
int i = <start>;
for (; (!b) && (i != <end>); ++i) {
b = <f> i;
}
(i, b)
*)
val interruptible_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> bool -> GTot Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack bool
(requires (fun h -> inv h (UInt32.v i) false))
(ensures (fun h_1 b h_2 -> inv h_1 (UInt32.v i) false /\ inv h_2 UInt32.(v i + 1) b)) ) ->
Stack (UInt32.t * bool)
(requires (fun h -> inv h (UInt32.v start) false))
(ensures (fun _ res h_2 -> let (i, b) = res in ((if b then True else i == finish) /\ inv h_2 (UInt32.v i) b)))
let rec interruptible_for start finish inv f =
if start = finish then
(finish, false)
else
let start' = UInt32.(start +^ 1ul) in
if f start
then (start', true)
else interruptible_for start' finish inv f
(* To be extracted as:
while (true) {
bool b = <f> i;
if (b) {
break;
}
}
*)
val do_while:
inv:(HS.mem -> bool -> GTot Type0) ->
f:(unit -> Stack bool
(requires (fun h -> inv h false))
(ensures (fun h_1 b h_2 -> inv h_1 false /\ inv h_2 b)) ) ->
Stack unit
(requires (fun h -> inv h false))
(ensures (fun _ _ h_2 -> inv h_2 true))
let rec do_while inv f =
if not (f ()) then
do_while inv f
(* Extracted as:
while (test ()) {
body ();
}
*)
val while:
#test_pre: (HS.mem -> GTot Type0) ->
#test_post: (bool -> HS.mem -> GTot Type0) ->
$test: (unit -> Stack bool
(requires (fun h -> test_pre h))
(ensures (fun h0 x h1 -> test_post x h1))) ->
body: (unit -> Stack unit
(requires (fun h -> test_post true h))
(ensures (fun h0 _ h1 -> test_pre h1))) ->
Stack unit
(requires (fun h -> test_pre h))
(ensures (fun h0 _ h1 -> test_post false h1))
let rec while #test_pre #test_post test body =
if test () then begin
body ();
while #test_pre #test_post test body
end
(* To be extracted as:
int i = <start>;
bool b = false;
for (; (!b) && (i != <end>); --i) {
b = <f> i;
}
// i and b must be in scope after the loop
*)
val interruptible_reverse_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish <= UInt32.v start} ->
inv:(HS.mem -> nat -> bool -> GTot Type0) ->
f:(i:UInt32.t{UInt32.(v start >= v i /\ v i > v finish)} -> Stack bool
(requires (fun h -> inv h (UInt32.v i) false))
(ensures (fun h_1 b h_2 -> inv h_1 (UInt32.v i) false /\ inv h_2 UInt32.(v i - 1) b)) ) ->
Stack (UInt32.t * bool)
(requires (fun h -> inv h (UInt32.v start) false))
(ensures (fun _ res h_2 -> let (i, b) = res in ((if b then True else i == finish) /\ inv h_2 (UInt32.v i) b)))
let rec interruptible_reverse_for start finish inv f =
if start = finish then
(finish, false)
else
let start' = UInt32.(start -^ 1ul) in
if f start
then (start', true)
else interruptible_reverse_for start' finish inv f
(* Non-primitive combinators that can be expressed in terms of the above ******)
(** Extracts as:
* for (int i = 0; i < <l>; ++i)
* out[i] = <f>(in[i]);
*)
inline_for_extraction
val map:
#a:Type0 -> #b:Type0 ->
output: buffer b ->
input: buffer a{disjoint input output} ->
l: UInt32.t{ UInt32.v l = Buffer.length output /\ UInt32.v l = Buffer.length input } ->
f:(a -> Tot b) ->
Stack unit
(requires (fun h -> live h input /\ live h output ))
(ensures (fun h_1 r h_2 -> modifies_1 output h_1 h_2 /\ live h_2 input /\ live h_1 input /\ live h_2 output
/\ live h_2 output
/\ (let s1 = as_seq h_1 input in
let s2 = as_seq h_2 output in
s2 == seq_map f s1) ))
inline_for_extraction
let map #a #b output input l f =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 output /\ live h1 input /\ modifies_1 output h0 h1 /\ i <= UInt32.v l
/\ (forall (j:nat). (j >= i /\ j < UInt32.v l) ==> get h1 output j == get h0 output j)
/\ (forall (j:nat). j < i ==> get h1 output j == f (get h0 input j))
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v l ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
let xi = input.(i) in
output.(i) <- f xi
in
for 0ul l inv f';
let h1 = HST.get() in
Seq.lemma_eq_intro (as_seq h1 output) (seq_map f (as_seq h0 input))
(** Extracts as:
* for (int i = 0; i < <l>; ++i)
* out[i] = <f>(in1[i], in2[i]);
*)
inline_for_extraction
val map2:
#a:Type0 -> #b:Type0 -> #c:Type0 ->
output: buffer c ->
in1: buffer a{disjoint output in1} -> in2: buffer b{disjoint output in2} ->
l: UInt32.t{ UInt32.v l = Buffer.length output /\ UInt32.v l = Buffer.length in1
/\ UInt32.v l = Buffer.length in2 } ->
f:(a -> b -> Tot c) ->
Stack unit
(requires (fun h -> live h in1 /\ live h in2 /\ live h output ))
(ensures (fun h_1 r h_2 -> modifies_1 output h_1 h_2 /\ live h_2 in1 /\ live h_2 in2
/\ live h_1 in1 /\ live h_1 in2 /\ live h_2 output
/\ (let s1 = as_seq h_1 in1 in
let s2 = as_seq h_1 in2 in
let s = as_seq h_2 output in
s == seq_map2 f s1 s2) ))
inline_for_extraction
let map2 #a #b #c output in1 in2 l f =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 output /\ live h1 in1 /\ live h1 in2 /\ modifies_1 output h0 h1 /\ i <= UInt32.v l
/\ (forall (j:nat). (j >= i /\ j < UInt32.v l) ==> get h1 output j == get h0 output j)
/\ (forall (j:nat). j < i ==> get h1 output j == f (get h0 in1 j) (get h0 in2 j))
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v l ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
let xi = in1.(i) in
let yi = in2.(i) in
output.(i) <- f xi yi
in
for 0ul l inv f';
let h1 = HST.get() in
Seq.lemma_eq_intro (as_seq h1 output) (seq_map2 f (as_seq h0 in1) (as_seq h0 in2))
(** Extracts as:
* for (int i = 0; i < <l>; ++i)
* b[i] = <f>(b[i]);
*)
inline_for_extraction
val in_place_map:
#a:Type0 ->
b: buffer a ->
l: UInt32.t{ UInt32.v l = Buffer.length b } ->
f:(a -> Tot a) ->
Stack unit
(requires (fun h -> live h b))
(ensures (fun h_1 r h_2 -> modifies_1 b h_1 h_2 /\ live h_2 b /\ live h_1 b
/\ (let s1 = as_seq h_1 b in
let s2 = as_seq h_2 b in
s2 == seq_map f s1) ))
inline_for_extraction
let in_place_map #a b l f =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 b /\ modifies_1 b h0 h1 /\ i <= UInt32.v l
/\ (forall (j:nat). (j >= i /\ j < UInt32.v l) ==> get h1 b j == get h0 b j)
/\ (forall (j:nat). j < i ==> get h1 b j == f (get h0 b j))
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v l ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
let xi = b.(i) in
b.(i) <- f xi
in
for 0ul l inv f';
let h1 = HST.get() in
Seq.lemma_eq_intro (as_seq h1 b) (seq_map f (as_seq h0 b))
(** Extracts as (destination buffer comes first):
* for (int i = 0; i < <l>; ++i)
* in1[i] = <f>(in1[i], in2[i]);
*)
inline_for_extraction
val in_place_map2:
#a:Type0 -> #b:Type0 ->
in1: buffer a ->
in2: buffer b{disjoint in1 in2} ->
l: UInt32.t{ UInt32.v l = Buffer.length in1 /\ UInt32.v l = Buffer.length in2} ->
f:(a -> b -> Tot a) ->
Stack unit
(requires (fun h -> live h in1 /\ live h in2))
(ensures (fun h_1 r h_2 -> modifies_1 in1 h_1 h_2 /\ live h_2 in1 /\ live h_2 in2
/\ live h_1 in1 /\ live h_1 in2
/\ (let s1 = as_seq h_1 in1 in
let s2 = as_seq h_1 in2 in
let s = as_seq h_2 in1 in
s == seq_map2 f s1 s2) ))
inline_for_extraction
let in_place_map2 #a #b in1 in2 l f =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 in1 /\ live h1 in2 /\ modifies_1 in1 h0 h1 /\ i <= UInt32.v l
/\ (forall (j:nat). (j >= i /\ j < UInt32.v l) ==> get h1 in1 j == get h0 in1 j)
/\ (forall (j:nat). j < i ==> get h1 in1 j == f (get h0 in1 j) (get h0 in2 j))
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v l ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
let xi = in1.(i) in
let yi = in2.(i) in
in1.(i) <- f xi yi
in
for 0ul l inv f';
let h1 = HST.get() in
Seq.lemma_eq_intro (as_seq h1 in1) (seq_map2 f (as_seq h0 in1) (as_seq h0 in2))
#reset-options "--initial_fuel 2 --max_fuel 2 --z3rlimit 20"
(* Repeating the same operation a number of times over a buffer ***************)
#reset-options "--initial_fuel 0 --max_fuel 0 --z3rlimit 20"
(** To be extracted as:
* for (int i = 0; i < n; ++i)
* f(b[i]);
*)
inline_for_extraction
val repeat:
#a:Type0 ->
l: UInt32.t ->
f:(s:Seq.seq a{Seq.length s = UInt32.v l} -> Tot (s':Seq.seq a{Seq.length s' = Seq.length s})) ->
b: buffer a{Buffer.length b = UInt32.v l} ->
max:UInt32.t ->
fc:(b:buffer a{length b = UInt32.v l} -> Stack unit
(requires (fun h -> live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ modifies_1 b h0 h1
/\ (let b0 = as_seq h0 b in
let b1 = as_seq h1 b in
b1 == f b0)))) ->
Stack unit
(requires (fun h -> live h b ))
(ensures (fun h_1 r h_2 -> modifies_1 b h_1 h_2 /\ live h_1 b /\ live h_2 b
/\ (let s = as_seq h_1 b in
let s' = as_seq h_2 b in
s' == repeat_spec (UInt32.v max) f s) ))
inline_for_extraction
let repeat #a l f b max fc =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 b /\ modifies_1 b h0 h1 /\ i <= UInt32.v max
/\ as_seq h1 b == repeat_spec i f (as_seq h0 b)
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v max ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
fc b;
lemma_repeat (UInt32.v i + 1) f (as_seq h0 b)
in
lemma_repeat_0 0 f (as_seq h0 b);
for 0ul max inv f'
(** To be extracted as:
* for (int i = min; i < max; ++i)
* f(b[i], i);
*)
inline_for_extraction
val repeat_range:
#a:Type0 ->
l: UInt32.t ->
min:UInt32.t ->
max:UInt32.t{UInt32.v min <= UInt32.v max} ->
f:(s:Seq.seq a{Seq.length s = UInt32.v l} -> i:nat{i < UInt32.v max} -> Tot (s':Seq.seq a{Seq.length s' = Seq.length s})) ->
b: buffer a{Buffer.length b = UInt32.v l} ->
fc:(b:buffer a{length b = UInt32.v l} -> i:UInt32.t{UInt32.v i < UInt32.v max} -> Stack unit
(requires (fun h -> live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ modifies_1 b h0 h1
/\ (let b0 = as_seq h0 b in
let b1 = as_seq h1 b in
b1 == f b0 (UInt32.v i))))) ->
Stack unit
(requires (fun h -> live h b ))
(ensures (fun h_1 r h_2 -> modifies_1 b h_1 h_2 /\ live h_1 b /\ live h_2 b
/\ (let s = as_seq h_1 b in
let s' = as_seq h_2 b in
s' == repeat_range_spec (UInt32.v min) (UInt32.v max) f s) ))
inline_for_extraction
let repeat_range #a l min max f b fc =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 b /\ modifies_1 b h0 h1 /\ i <= UInt32.v max /\ UInt32.v min <= i
/\ as_seq h1 b == repeat_range_spec (UInt32.v min) i f (as_seq h0 b)
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v max ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
fc b i;
lemma_repeat_range_spec (UInt32.v min) (UInt32.v i + 1) f (as_seq h0 b)
in
lemma_repeat_range_0 (UInt32.v min) f (as_seq h0 b);
for min max inv f' | {
"checked_file": "/",
"dependencies": [
"Spec.Loops.fst.checked",
"prims.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Buffer.fst.checked"
],
"interface_file": false,
"source_file": "C.Compat.Loops.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.Loops",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "UInt64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "UInt32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
tmes: (x: t -> Prims.GTot (a x)) ->
tinv: (_: Prims.bool -> _: t -> Prims.GTot Type0) ->
tcontinue: (_: t -> Prims.bool) ->
body: (x: t -> Prims.Pure t) ->
x: t
-> Prims.Pure t | Prims.Pure | [
""
] | [] | [
"Prims.bool",
"Prims.l_and",
"Prims.precedes",
"Prims.l_True",
"Prims.logical",
"C.Compat.Loops.total_while_gen"
] | [
"recursion"
] | false | false | false | false | false | let rec total_while_gen
(#t: Type)
(#a: (t -> Type))
(tmes: (x: t -> GTot (a x)))
(tinv: (bool -> t -> GTot Type0))
(tcontinue: (t -> Tot bool))
(body:
(x: t
-> Pure t
(requires (tinv true x))
(ensures
(fun y ->
tinv (tcontinue y) y /\ (if tcontinue y then tmes y << tmes x else True)))))
(x: t)
: Pure t (requires (tinv true x)) (ensures (fun y -> tinv false y)) (decreases (tmes x)) =
| let y = body x in
let continue = tcontinue y in
if continue then total_while_gen tmes tinv tcontinue body y else y | false |
C.Compat.Loops.fst | C.Compat.Loops.total_while | val total_while
(#t: Type)
(tmes: (t -> GTot nat))
(tinv: (bool -> t -> GTot Type0))
(body:
(x: t
-> Pure (bool * t)
(requires (tinv true x))
(ensures
(fun (continue, y) ->
tinv continue y /\ (if continue then tmes y < tmes x else True)))))
(x: t)
: Pure t (requires (tinv true x)) (ensures (fun y -> tinv false y)) (decreases (tmes x)) | val total_while
(#t: Type)
(tmes: (t -> GTot nat))
(tinv: (bool -> t -> GTot Type0))
(body:
(x: t
-> Pure (bool * t)
(requires (tinv true x))
(ensures
(fun (continue, y) ->
tinv continue y /\ (if continue then tmes y < tmes x else True)))))
(x: t)
: Pure t (requires (tinv true x)) (ensures (fun y -> tinv false y)) (decreases (tmes x)) | let total_while
(#t: Type)
(tmes: (t -> GTot nat))
(tinv: (bool -> t -> GTot Type0))
(body:
(x: t) ->
Pure (bool * t)
(requires (tinv true x))
(ensures (fun (continue, y) ->
tinv continue y /\ (
if continue then tmes y < tmes x else True)
)))
(x: t)
: Pure t
(requires (tinv true x))
(ensures (fun y -> tinv false y))
(decreases (tmes x))
= let (_, res) =
total_while_gen
(fun (_, x) -> tmes x)
(fun b (b_, x) -> b == b_ /\ tinv b x)
(fun (x, _) -> x)
(fun (_, x) -> body x)
(true, x)
in
res | {
"file_name": "krmllib/compat/C.Compat.Loops.fst",
"git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321",
"git_url": "https://github.com/FStarLang/karamel.git",
"project_name": "karamel"
} | {
"end_col": 5,
"end_line": 497,
"start_col": 0,
"start_line": 472
} | (* This module exposes a series of combinators; they are modeled using
* higher-order functions and specifications, and extracted, using a
* meta-theoretic argument, to actual C loops. *)
module C.Compat.Loops
open FStar.HyperStack.ST
open FStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module UInt32 = FStar.UInt32
module UInt64 = FStar.UInt64
include Spec.Loops
#set-options "--initial_fuel 0 --max_fuel 0 --z3rlimit 20"
(** The functions in this module use the following convention:
* - the first arguments are buffers;
* - the destination buffer comes first, followed by the input buffer (as in
* C's memcpy)
* - each buffer is followed by its length; if several buffers share the same
* length, there is a single length argument after the buffers
* - the function-specific arguments come next (e.g. the number of times one
* may want to call the function in [repeat])
* - the second to last argument is the loop invariant (which may have
* dependencies on all the parameters before)
* - the last argument is the loop body (that will depend on the invariant, and
* possibly all the other parameters before. *)
(* Generic-purpose for-loop combinators ***************************************)
(* These combinators enjoy first-class support in KaRaMeL. (See [combinators] in
* src/Simplify.ml *)
(* Currently extracting as:
for (int i = <start>; i != <finish>; ++i)
<f> i;
*)
val for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish)))
let rec for start finish inv f =
if start = finish then
()
else begin
f start;
for (UInt32.(start +^ 1ul)) finish inv f
end
val for64:
start:UInt64.t ->
finish:UInt64.t{UInt64.v finish >= UInt64.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt64.t{UInt64.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt64.v i)))
(ensures (fun h_1 _ h_2 -> UInt64.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt64.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt64.v finish)))
let rec for64 start finish inv f =
if start = finish then
()
else begin
f start;
for64 (UInt64.(start +^ 1UL)) finish inv f
end
(* To be extracted as:
for (int i = <start>; i != <finish>; --i)
<f> i;
*)
val reverse_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish <= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start >= v i /\ v i > v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i - 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish)))
let rec reverse_for start finish inv f =
if start = finish then
()
else begin
f start;
reverse_for (UInt32.(start -^ 1ul)) finish inv f
end
(* To be extracted as:
bool b = false;
int i = <start>;
for (; (!b) && (i != <end>); ++i) {
b = <f> i;
}
(i, b)
*)
val interruptible_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> bool -> GTot Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack bool
(requires (fun h -> inv h (UInt32.v i) false))
(ensures (fun h_1 b h_2 -> inv h_1 (UInt32.v i) false /\ inv h_2 UInt32.(v i + 1) b)) ) ->
Stack (UInt32.t * bool)
(requires (fun h -> inv h (UInt32.v start) false))
(ensures (fun _ res h_2 -> let (i, b) = res in ((if b then True else i == finish) /\ inv h_2 (UInt32.v i) b)))
let rec interruptible_for start finish inv f =
if start = finish then
(finish, false)
else
let start' = UInt32.(start +^ 1ul) in
if f start
then (start', true)
else interruptible_for start' finish inv f
(* To be extracted as:
while (true) {
bool b = <f> i;
if (b) {
break;
}
}
*)
val do_while:
inv:(HS.mem -> bool -> GTot Type0) ->
f:(unit -> Stack bool
(requires (fun h -> inv h false))
(ensures (fun h_1 b h_2 -> inv h_1 false /\ inv h_2 b)) ) ->
Stack unit
(requires (fun h -> inv h false))
(ensures (fun _ _ h_2 -> inv h_2 true))
let rec do_while inv f =
if not (f ()) then
do_while inv f
(* Extracted as:
while (test ()) {
body ();
}
*)
val while:
#test_pre: (HS.mem -> GTot Type0) ->
#test_post: (bool -> HS.mem -> GTot Type0) ->
$test: (unit -> Stack bool
(requires (fun h -> test_pre h))
(ensures (fun h0 x h1 -> test_post x h1))) ->
body: (unit -> Stack unit
(requires (fun h -> test_post true h))
(ensures (fun h0 _ h1 -> test_pre h1))) ->
Stack unit
(requires (fun h -> test_pre h))
(ensures (fun h0 _ h1 -> test_post false h1))
let rec while #test_pre #test_post test body =
if test () then begin
body ();
while #test_pre #test_post test body
end
(* To be extracted as:
int i = <start>;
bool b = false;
for (; (!b) && (i != <end>); --i) {
b = <f> i;
}
// i and b must be in scope after the loop
*)
val interruptible_reverse_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish <= UInt32.v start} ->
inv:(HS.mem -> nat -> bool -> GTot Type0) ->
f:(i:UInt32.t{UInt32.(v start >= v i /\ v i > v finish)} -> Stack bool
(requires (fun h -> inv h (UInt32.v i) false))
(ensures (fun h_1 b h_2 -> inv h_1 (UInt32.v i) false /\ inv h_2 UInt32.(v i - 1) b)) ) ->
Stack (UInt32.t * bool)
(requires (fun h -> inv h (UInt32.v start) false))
(ensures (fun _ res h_2 -> let (i, b) = res in ((if b then True else i == finish) /\ inv h_2 (UInt32.v i) b)))
let rec interruptible_reverse_for start finish inv f =
if start = finish then
(finish, false)
else
let start' = UInt32.(start -^ 1ul) in
if f start
then (start', true)
else interruptible_reverse_for start' finish inv f
(* Non-primitive combinators that can be expressed in terms of the above ******)
(** Extracts as:
* for (int i = 0; i < <l>; ++i)
* out[i] = <f>(in[i]);
*)
inline_for_extraction
val map:
#a:Type0 -> #b:Type0 ->
output: buffer b ->
input: buffer a{disjoint input output} ->
l: UInt32.t{ UInt32.v l = Buffer.length output /\ UInt32.v l = Buffer.length input } ->
f:(a -> Tot b) ->
Stack unit
(requires (fun h -> live h input /\ live h output ))
(ensures (fun h_1 r h_2 -> modifies_1 output h_1 h_2 /\ live h_2 input /\ live h_1 input /\ live h_2 output
/\ live h_2 output
/\ (let s1 = as_seq h_1 input in
let s2 = as_seq h_2 output in
s2 == seq_map f s1) ))
inline_for_extraction
let map #a #b output input l f =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 output /\ live h1 input /\ modifies_1 output h0 h1 /\ i <= UInt32.v l
/\ (forall (j:nat). (j >= i /\ j < UInt32.v l) ==> get h1 output j == get h0 output j)
/\ (forall (j:nat). j < i ==> get h1 output j == f (get h0 input j))
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v l ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
let xi = input.(i) in
output.(i) <- f xi
in
for 0ul l inv f';
let h1 = HST.get() in
Seq.lemma_eq_intro (as_seq h1 output) (seq_map f (as_seq h0 input))
(** Extracts as:
* for (int i = 0; i < <l>; ++i)
* out[i] = <f>(in1[i], in2[i]);
*)
inline_for_extraction
val map2:
#a:Type0 -> #b:Type0 -> #c:Type0 ->
output: buffer c ->
in1: buffer a{disjoint output in1} -> in2: buffer b{disjoint output in2} ->
l: UInt32.t{ UInt32.v l = Buffer.length output /\ UInt32.v l = Buffer.length in1
/\ UInt32.v l = Buffer.length in2 } ->
f:(a -> b -> Tot c) ->
Stack unit
(requires (fun h -> live h in1 /\ live h in2 /\ live h output ))
(ensures (fun h_1 r h_2 -> modifies_1 output h_1 h_2 /\ live h_2 in1 /\ live h_2 in2
/\ live h_1 in1 /\ live h_1 in2 /\ live h_2 output
/\ (let s1 = as_seq h_1 in1 in
let s2 = as_seq h_1 in2 in
let s = as_seq h_2 output in
s == seq_map2 f s1 s2) ))
inline_for_extraction
let map2 #a #b #c output in1 in2 l f =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 output /\ live h1 in1 /\ live h1 in2 /\ modifies_1 output h0 h1 /\ i <= UInt32.v l
/\ (forall (j:nat). (j >= i /\ j < UInt32.v l) ==> get h1 output j == get h0 output j)
/\ (forall (j:nat). j < i ==> get h1 output j == f (get h0 in1 j) (get h0 in2 j))
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v l ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
let xi = in1.(i) in
let yi = in2.(i) in
output.(i) <- f xi yi
in
for 0ul l inv f';
let h1 = HST.get() in
Seq.lemma_eq_intro (as_seq h1 output) (seq_map2 f (as_seq h0 in1) (as_seq h0 in2))
(** Extracts as:
* for (int i = 0; i < <l>; ++i)
* b[i] = <f>(b[i]);
*)
inline_for_extraction
val in_place_map:
#a:Type0 ->
b: buffer a ->
l: UInt32.t{ UInt32.v l = Buffer.length b } ->
f:(a -> Tot a) ->
Stack unit
(requires (fun h -> live h b))
(ensures (fun h_1 r h_2 -> modifies_1 b h_1 h_2 /\ live h_2 b /\ live h_1 b
/\ (let s1 = as_seq h_1 b in
let s2 = as_seq h_2 b in
s2 == seq_map f s1) ))
inline_for_extraction
let in_place_map #a b l f =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 b /\ modifies_1 b h0 h1 /\ i <= UInt32.v l
/\ (forall (j:nat). (j >= i /\ j < UInt32.v l) ==> get h1 b j == get h0 b j)
/\ (forall (j:nat). j < i ==> get h1 b j == f (get h0 b j))
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v l ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
let xi = b.(i) in
b.(i) <- f xi
in
for 0ul l inv f';
let h1 = HST.get() in
Seq.lemma_eq_intro (as_seq h1 b) (seq_map f (as_seq h0 b))
(** Extracts as (destination buffer comes first):
* for (int i = 0; i < <l>; ++i)
* in1[i] = <f>(in1[i], in2[i]);
*)
inline_for_extraction
val in_place_map2:
#a:Type0 -> #b:Type0 ->
in1: buffer a ->
in2: buffer b{disjoint in1 in2} ->
l: UInt32.t{ UInt32.v l = Buffer.length in1 /\ UInt32.v l = Buffer.length in2} ->
f:(a -> b -> Tot a) ->
Stack unit
(requires (fun h -> live h in1 /\ live h in2))
(ensures (fun h_1 r h_2 -> modifies_1 in1 h_1 h_2 /\ live h_2 in1 /\ live h_2 in2
/\ live h_1 in1 /\ live h_1 in2
/\ (let s1 = as_seq h_1 in1 in
let s2 = as_seq h_1 in2 in
let s = as_seq h_2 in1 in
s == seq_map2 f s1 s2) ))
inline_for_extraction
let in_place_map2 #a #b in1 in2 l f =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 in1 /\ live h1 in2 /\ modifies_1 in1 h0 h1 /\ i <= UInt32.v l
/\ (forall (j:nat). (j >= i /\ j < UInt32.v l) ==> get h1 in1 j == get h0 in1 j)
/\ (forall (j:nat). j < i ==> get h1 in1 j == f (get h0 in1 j) (get h0 in2 j))
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v l ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
let xi = in1.(i) in
let yi = in2.(i) in
in1.(i) <- f xi yi
in
for 0ul l inv f';
let h1 = HST.get() in
Seq.lemma_eq_intro (as_seq h1 in1) (seq_map2 f (as_seq h0 in1) (as_seq h0 in2))
#reset-options "--initial_fuel 2 --max_fuel 2 --z3rlimit 20"
(* Repeating the same operation a number of times over a buffer ***************)
#reset-options "--initial_fuel 0 --max_fuel 0 --z3rlimit 20"
(** To be extracted as:
* for (int i = 0; i < n; ++i)
* f(b[i]);
*)
inline_for_extraction
val repeat:
#a:Type0 ->
l: UInt32.t ->
f:(s:Seq.seq a{Seq.length s = UInt32.v l} -> Tot (s':Seq.seq a{Seq.length s' = Seq.length s})) ->
b: buffer a{Buffer.length b = UInt32.v l} ->
max:UInt32.t ->
fc:(b:buffer a{length b = UInt32.v l} -> Stack unit
(requires (fun h -> live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ modifies_1 b h0 h1
/\ (let b0 = as_seq h0 b in
let b1 = as_seq h1 b in
b1 == f b0)))) ->
Stack unit
(requires (fun h -> live h b ))
(ensures (fun h_1 r h_2 -> modifies_1 b h_1 h_2 /\ live h_1 b /\ live h_2 b
/\ (let s = as_seq h_1 b in
let s' = as_seq h_2 b in
s' == repeat_spec (UInt32.v max) f s) ))
inline_for_extraction
let repeat #a l f b max fc =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 b /\ modifies_1 b h0 h1 /\ i <= UInt32.v max
/\ as_seq h1 b == repeat_spec i f (as_seq h0 b)
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v max ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
fc b;
lemma_repeat (UInt32.v i + 1) f (as_seq h0 b)
in
lemma_repeat_0 0 f (as_seq h0 b);
for 0ul max inv f'
(** To be extracted as:
* for (int i = min; i < max; ++i)
* f(b[i], i);
*)
inline_for_extraction
val repeat_range:
#a:Type0 ->
l: UInt32.t ->
min:UInt32.t ->
max:UInt32.t{UInt32.v min <= UInt32.v max} ->
f:(s:Seq.seq a{Seq.length s = UInt32.v l} -> i:nat{i < UInt32.v max} -> Tot (s':Seq.seq a{Seq.length s' = Seq.length s})) ->
b: buffer a{Buffer.length b = UInt32.v l} ->
fc:(b:buffer a{length b = UInt32.v l} -> i:UInt32.t{UInt32.v i < UInt32.v max} -> Stack unit
(requires (fun h -> live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ modifies_1 b h0 h1
/\ (let b0 = as_seq h0 b in
let b1 = as_seq h1 b in
b1 == f b0 (UInt32.v i))))) ->
Stack unit
(requires (fun h -> live h b ))
(ensures (fun h_1 r h_2 -> modifies_1 b h_1 h_2 /\ live h_1 b /\ live h_2 b
/\ (let s = as_seq h_1 b in
let s' = as_seq h_2 b in
s' == repeat_range_spec (UInt32.v min) (UInt32.v max) f s) ))
inline_for_extraction
let repeat_range #a l min max f b fc =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 b /\ modifies_1 b h0 h1 /\ i <= UInt32.v max /\ UInt32.v min <= i
/\ as_seq h1 b == repeat_range_spec (UInt32.v min) i f (as_seq h0 b)
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v max ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
fc b i;
lemma_repeat_range_spec (UInt32.v min) (UInt32.v i + 1) f (as_seq h0 b)
in
lemma_repeat_range_0 (UInt32.v min) f (as_seq h0 b);
for min max inv f'
let rec total_while_gen
(#t: Type)
(#a:t -> Type)
(tmes: (x:t -> GTot (a x)))
(tinv: (bool -> t -> GTot Type0))
(tcontinue: (t -> Tot bool))
(body:
(x: t) ->
Pure t
(requires (tinv true x))
(ensures (fun y ->
tinv (tcontinue y) y /\ (
if tcontinue y then tmes y << tmes x else True)
)))
(x: t)
: Pure t
(requires (tinv true x))
(ensures (fun y -> tinv false y))
(decreases (tmes x))
= let y = body x in
let continue = tcontinue y in
if continue
then total_while_gen tmes tinv tcontinue body y
else y | {
"checked_file": "/",
"dependencies": [
"Spec.Loops.fst.checked",
"prims.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Buffer.fst.checked"
],
"interface_file": false,
"source_file": "C.Compat.Loops.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.Loops",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "UInt64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "UInt32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
tmes: (_: t -> Prims.GTot Prims.nat) ->
tinv: (_: Prims.bool -> _: t -> Prims.GTot Type0) ->
body: (x: t -> Prims.Pure (Prims.bool * t)) ->
x: t
-> Prims.Pure t | Prims.Pure | [
""
] | [] | [
"Prims.nat",
"Prims.bool",
"FStar.Pervasives.Native.tuple2",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.l_True",
"Prims.logical",
"C.Compat.Loops.total_while_gen",
"Prims.eq2",
"FStar.Pervasives.Native.Mktuple2"
] | [] | false | false | false | false | false | let total_while
(#t: Type)
(tmes: (t -> GTot nat))
(tinv: (bool -> t -> GTot Type0))
(body:
(x: t
-> Pure (bool * t)
(requires (tinv true x))
(ensures
(fun (continue, y) ->
tinv continue y /\ (if continue then tmes y < tmes x else True)))))
(x: t)
: Pure t (requires (tinv true x)) (ensures (fun y -> tinv false y)) (decreases (tmes x)) =
| let _, res =
total_while_gen (fun (_, x) -> tmes x)
(fun b (b_, x) -> b == b_ /\ tinv b x)
(fun (x, _) -> x)
(fun (_, x) -> body x)
(true, x)
in
res | false |
C.Compat.Loops.fst | C.Compat.Loops.in_place_map | val in_place_map:
#a:Type0 ->
b: buffer a ->
l: UInt32.t{ UInt32.v l = Buffer.length b } ->
f:(a -> Tot a) ->
Stack unit
(requires (fun h -> live h b))
(ensures (fun h_1 r h_2 -> modifies_1 b h_1 h_2 /\ live h_2 b /\ live h_1 b
/\ (let s1 = as_seq h_1 b in
let s2 = as_seq h_2 b in
s2 == seq_map f s1) )) | val in_place_map:
#a:Type0 ->
b: buffer a ->
l: UInt32.t{ UInt32.v l = Buffer.length b } ->
f:(a -> Tot a) ->
Stack unit
(requires (fun h -> live h b))
(ensures (fun h_1 r h_2 -> modifies_1 b h_1 h_2 /\ live h_2 b /\ live h_1 b
/\ (let s1 = as_seq h_1 b in
let s2 = as_seq h_2 b in
s2 == seq_map f s1) )) | let in_place_map #a b l f =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 b /\ modifies_1 b h0 h1 /\ i <= UInt32.v l
/\ (forall (j:nat). (j >= i /\ j < UInt32.v l) ==> get h1 b j == get h0 b j)
/\ (forall (j:nat). j < i ==> get h1 b j == f (get h0 b j))
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v l ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
let xi = b.(i) in
b.(i) <- f xi
in
for 0ul l inv f';
let h1 = HST.get() in
Seq.lemma_eq_intro (as_seq h1 b) (seq_map f (as_seq h0 b)) | {
"file_name": "krmllib/compat/C.Compat.Loops.fst",
"git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321",
"git_url": "https://github.com/FStarLang/karamel.git",
"project_name": "karamel"
} | {
"end_col": 60,
"end_line": 314,
"start_col": 0,
"start_line": 298
} | (* This module exposes a series of combinators; they are modeled using
* higher-order functions and specifications, and extracted, using a
* meta-theoretic argument, to actual C loops. *)
module C.Compat.Loops
open FStar.HyperStack.ST
open FStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module UInt32 = FStar.UInt32
module UInt64 = FStar.UInt64
include Spec.Loops
#set-options "--initial_fuel 0 --max_fuel 0 --z3rlimit 20"
(** The functions in this module use the following convention:
* - the first arguments are buffers;
* - the destination buffer comes first, followed by the input buffer (as in
* C's memcpy)
* - each buffer is followed by its length; if several buffers share the same
* length, there is a single length argument after the buffers
* - the function-specific arguments come next (e.g. the number of times one
* may want to call the function in [repeat])
* - the second to last argument is the loop invariant (which may have
* dependencies on all the parameters before)
* - the last argument is the loop body (that will depend on the invariant, and
* possibly all the other parameters before. *)
(* Generic-purpose for-loop combinators ***************************************)
(* These combinators enjoy first-class support in KaRaMeL. (See [combinators] in
* src/Simplify.ml *)
(* Currently extracting as:
for (int i = <start>; i != <finish>; ++i)
<f> i;
*)
val for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish)))
let rec for start finish inv f =
if start = finish then
()
else begin
f start;
for (UInt32.(start +^ 1ul)) finish inv f
end
val for64:
start:UInt64.t ->
finish:UInt64.t{UInt64.v finish >= UInt64.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt64.t{UInt64.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt64.v i)))
(ensures (fun h_1 _ h_2 -> UInt64.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt64.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt64.v finish)))
let rec for64 start finish inv f =
if start = finish then
()
else begin
f start;
for64 (UInt64.(start +^ 1UL)) finish inv f
end
(* To be extracted as:
for (int i = <start>; i != <finish>; --i)
<f> i;
*)
val reverse_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish <= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start >= v i /\ v i > v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i - 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish)))
let rec reverse_for start finish inv f =
if start = finish then
()
else begin
f start;
reverse_for (UInt32.(start -^ 1ul)) finish inv f
end
(* To be extracted as:
bool b = false;
int i = <start>;
for (; (!b) && (i != <end>); ++i) {
b = <f> i;
}
(i, b)
*)
val interruptible_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> bool -> GTot Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack bool
(requires (fun h -> inv h (UInt32.v i) false))
(ensures (fun h_1 b h_2 -> inv h_1 (UInt32.v i) false /\ inv h_2 UInt32.(v i + 1) b)) ) ->
Stack (UInt32.t * bool)
(requires (fun h -> inv h (UInt32.v start) false))
(ensures (fun _ res h_2 -> let (i, b) = res in ((if b then True else i == finish) /\ inv h_2 (UInt32.v i) b)))
let rec interruptible_for start finish inv f =
if start = finish then
(finish, false)
else
let start' = UInt32.(start +^ 1ul) in
if f start
then (start', true)
else interruptible_for start' finish inv f
(* To be extracted as:
while (true) {
bool b = <f> i;
if (b) {
break;
}
}
*)
val do_while:
inv:(HS.mem -> bool -> GTot Type0) ->
f:(unit -> Stack bool
(requires (fun h -> inv h false))
(ensures (fun h_1 b h_2 -> inv h_1 false /\ inv h_2 b)) ) ->
Stack unit
(requires (fun h -> inv h false))
(ensures (fun _ _ h_2 -> inv h_2 true))
let rec do_while inv f =
if not (f ()) then
do_while inv f
(* Extracted as:
while (test ()) {
body ();
}
*)
val while:
#test_pre: (HS.mem -> GTot Type0) ->
#test_post: (bool -> HS.mem -> GTot Type0) ->
$test: (unit -> Stack bool
(requires (fun h -> test_pre h))
(ensures (fun h0 x h1 -> test_post x h1))) ->
body: (unit -> Stack unit
(requires (fun h -> test_post true h))
(ensures (fun h0 _ h1 -> test_pre h1))) ->
Stack unit
(requires (fun h -> test_pre h))
(ensures (fun h0 _ h1 -> test_post false h1))
let rec while #test_pre #test_post test body =
if test () then begin
body ();
while #test_pre #test_post test body
end
(* To be extracted as:
int i = <start>;
bool b = false;
for (; (!b) && (i != <end>); --i) {
b = <f> i;
}
// i and b must be in scope after the loop
*)
val interruptible_reverse_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish <= UInt32.v start} ->
inv:(HS.mem -> nat -> bool -> GTot Type0) ->
f:(i:UInt32.t{UInt32.(v start >= v i /\ v i > v finish)} -> Stack bool
(requires (fun h -> inv h (UInt32.v i) false))
(ensures (fun h_1 b h_2 -> inv h_1 (UInt32.v i) false /\ inv h_2 UInt32.(v i - 1) b)) ) ->
Stack (UInt32.t * bool)
(requires (fun h -> inv h (UInt32.v start) false))
(ensures (fun _ res h_2 -> let (i, b) = res in ((if b then True else i == finish) /\ inv h_2 (UInt32.v i) b)))
let rec interruptible_reverse_for start finish inv f =
if start = finish then
(finish, false)
else
let start' = UInt32.(start -^ 1ul) in
if f start
then (start', true)
else interruptible_reverse_for start' finish inv f
(* Non-primitive combinators that can be expressed in terms of the above ******)
(** Extracts as:
* for (int i = 0; i < <l>; ++i)
* out[i] = <f>(in[i]);
*)
inline_for_extraction
val map:
#a:Type0 -> #b:Type0 ->
output: buffer b ->
input: buffer a{disjoint input output} ->
l: UInt32.t{ UInt32.v l = Buffer.length output /\ UInt32.v l = Buffer.length input } ->
f:(a -> Tot b) ->
Stack unit
(requires (fun h -> live h input /\ live h output ))
(ensures (fun h_1 r h_2 -> modifies_1 output h_1 h_2 /\ live h_2 input /\ live h_1 input /\ live h_2 output
/\ live h_2 output
/\ (let s1 = as_seq h_1 input in
let s2 = as_seq h_2 output in
s2 == seq_map f s1) ))
inline_for_extraction
let map #a #b output input l f =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 output /\ live h1 input /\ modifies_1 output h0 h1 /\ i <= UInt32.v l
/\ (forall (j:nat). (j >= i /\ j < UInt32.v l) ==> get h1 output j == get h0 output j)
/\ (forall (j:nat). j < i ==> get h1 output j == f (get h0 input j))
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v l ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
let xi = input.(i) in
output.(i) <- f xi
in
for 0ul l inv f';
let h1 = HST.get() in
Seq.lemma_eq_intro (as_seq h1 output) (seq_map f (as_seq h0 input))
(** Extracts as:
* for (int i = 0; i < <l>; ++i)
* out[i] = <f>(in1[i], in2[i]);
*)
inline_for_extraction
val map2:
#a:Type0 -> #b:Type0 -> #c:Type0 ->
output: buffer c ->
in1: buffer a{disjoint output in1} -> in2: buffer b{disjoint output in2} ->
l: UInt32.t{ UInt32.v l = Buffer.length output /\ UInt32.v l = Buffer.length in1
/\ UInt32.v l = Buffer.length in2 } ->
f:(a -> b -> Tot c) ->
Stack unit
(requires (fun h -> live h in1 /\ live h in2 /\ live h output ))
(ensures (fun h_1 r h_2 -> modifies_1 output h_1 h_2 /\ live h_2 in1 /\ live h_2 in2
/\ live h_1 in1 /\ live h_1 in2 /\ live h_2 output
/\ (let s1 = as_seq h_1 in1 in
let s2 = as_seq h_1 in2 in
let s = as_seq h_2 output in
s == seq_map2 f s1 s2) ))
inline_for_extraction
let map2 #a #b #c output in1 in2 l f =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 output /\ live h1 in1 /\ live h1 in2 /\ modifies_1 output h0 h1 /\ i <= UInt32.v l
/\ (forall (j:nat). (j >= i /\ j < UInt32.v l) ==> get h1 output j == get h0 output j)
/\ (forall (j:nat). j < i ==> get h1 output j == f (get h0 in1 j) (get h0 in2 j))
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v l ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
let xi = in1.(i) in
let yi = in2.(i) in
output.(i) <- f xi yi
in
for 0ul l inv f';
let h1 = HST.get() in
Seq.lemma_eq_intro (as_seq h1 output) (seq_map2 f (as_seq h0 in1) (as_seq h0 in2))
(** Extracts as:
* for (int i = 0; i < <l>; ++i)
* b[i] = <f>(b[i]);
*)
inline_for_extraction
val in_place_map:
#a:Type0 ->
b: buffer a ->
l: UInt32.t{ UInt32.v l = Buffer.length b } ->
f:(a -> Tot a) ->
Stack unit
(requires (fun h -> live h b))
(ensures (fun h_1 r h_2 -> modifies_1 b h_1 h_2 /\ live h_2 b /\ live h_1 b
/\ (let s1 = as_seq h_1 b in
let s2 = as_seq h_2 b in
s2 == seq_map f s1) )) | {
"checked_file": "/",
"dependencies": [
"Spec.Loops.fst.checked",
"prims.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Buffer.fst.checked"
],
"interface_file": false,
"source_file": "C.Compat.Loops.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.Loops",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "UInt64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "UInt32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: FStar.Buffer.buffer a ->
l: FStar.UInt32.t{FStar.UInt32.v l = FStar.Buffer.length b} ->
f: (_: a -> a)
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.Buffer.buffer",
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt32.v",
"FStar.Buffer.length",
"FStar.Seq.Base.lemma_eq_intro",
"FStar.Buffer.as_seq",
"Spec.Loops.seq_map",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"C.Compat.Loops.for",
"FStar.UInt32.__uint_to_t",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Addition",
"FStar.Buffer.op_Array_Assignment",
"FStar.Buffer.op_Array_Access",
"Prims.nat",
"FStar.Buffer.live",
"FStar.Buffer.modifies_1",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.eq2",
"FStar.Buffer.get"
] | [] | false | true | false | false | false | let in_place_map #a b l f =
| let h0 = HST.get () in
let inv (h1: HS.mem) (i: nat) : Type0 =
live h1 b /\ modifies_1 b h0 h1 /\ i <= UInt32.v l /\
(forall (j: nat). (j >= i /\ j < UInt32.v l) ==> get h1 b j == get h0 b j) /\
(forall (j: nat). j < i ==> get h1 b j == f (get h0 b j))
in
let f' (i: UInt32.t{let open UInt32 in 0 <= v i /\ v i < v l})
: Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> let open UInt32 in inv h_2 (v i + 1))) =
let xi = b.(i) in
b.(i) <- f xi
in
for 0ul l inv f';
let h1 = HST.get () in
Seq.lemma_eq_intro (as_seq h1 b) (seq_map f (as_seq h0 b)) | false |
C.Compat.Loops.fst | C.Compat.Loops.repeat | val repeat:
#a:Type0 ->
l: UInt32.t ->
f:(s:Seq.seq a{Seq.length s = UInt32.v l} -> Tot (s':Seq.seq a{Seq.length s' = Seq.length s})) ->
b: buffer a{Buffer.length b = UInt32.v l} ->
max:UInt32.t ->
fc:(b:buffer a{length b = UInt32.v l} -> Stack unit
(requires (fun h -> live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ modifies_1 b h0 h1
/\ (let b0 = as_seq h0 b in
let b1 = as_seq h1 b in
b1 == f b0)))) ->
Stack unit
(requires (fun h -> live h b ))
(ensures (fun h_1 r h_2 -> modifies_1 b h_1 h_2 /\ live h_1 b /\ live h_2 b
/\ (let s = as_seq h_1 b in
let s' = as_seq h_2 b in
s' == repeat_spec (UInt32.v max) f s) )) | val repeat:
#a:Type0 ->
l: UInt32.t ->
f:(s:Seq.seq a{Seq.length s = UInt32.v l} -> Tot (s':Seq.seq a{Seq.length s' = Seq.length s})) ->
b: buffer a{Buffer.length b = UInt32.v l} ->
max:UInt32.t ->
fc:(b:buffer a{length b = UInt32.v l} -> Stack unit
(requires (fun h -> live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ modifies_1 b h0 h1
/\ (let b0 = as_seq h0 b in
let b1 = as_seq h1 b in
b1 == f b0)))) ->
Stack unit
(requires (fun h -> live h b ))
(ensures (fun h_1 r h_2 -> modifies_1 b h_1 h_2 /\ live h_1 b /\ live h_2 b
/\ (let s = as_seq h_1 b in
let s' = as_seq h_2 b in
s' == repeat_spec (UInt32.v max) f s) )) | let repeat #a l f b max fc =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 b /\ modifies_1 b h0 h1 /\ i <= UInt32.v max
/\ as_seq h1 b == repeat_spec i f (as_seq h0 b)
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v max ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
fc b;
lemma_repeat (UInt32.v i + 1) f (as_seq h0 b)
in
lemma_repeat_0 0 f (as_seq h0 b);
for 0ul max inv f' | {
"file_name": "krmllib/compat/C.Compat.Loops.fst",
"git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321",
"git_url": "https://github.com/FStarLang/karamel.git",
"project_name": "karamel"
} | {
"end_col": 20,
"end_line": 402,
"start_col": 0,
"start_line": 388
} | (* This module exposes a series of combinators; they are modeled using
* higher-order functions and specifications, and extracted, using a
* meta-theoretic argument, to actual C loops. *)
module C.Compat.Loops
open FStar.HyperStack.ST
open FStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module UInt32 = FStar.UInt32
module UInt64 = FStar.UInt64
include Spec.Loops
#set-options "--initial_fuel 0 --max_fuel 0 --z3rlimit 20"
(** The functions in this module use the following convention:
* - the first arguments are buffers;
* - the destination buffer comes first, followed by the input buffer (as in
* C's memcpy)
* - each buffer is followed by its length; if several buffers share the same
* length, there is a single length argument after the buffers
* - the function-specific arguments come next (e.g. the number of times one
* may want to call the function in [repeat])
* - the second to last argument is the loop invariant (which may have
* dependencies on all the parameters before)
* - the last argument is the loop body (that will depend on the invariant, and
* possibly all the other parameters before. *)
(* Generic-purpose for-loop combinators ***************************************)
(* These combinators enjoy first-class support in KaRaMeL. (See [combinators] in
* src/Simplify.ml *)
(* Currently extracting as:
for (int i = <start>; i != <finish>; ++i)
<f> i;
*)
val for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish)))
let rec for start finish inv f =
if start = finish then
()
else begin
f start;
for (UInt32.(start +^ 1ul)) finish inv f
end
val for64:
start:UInt64.t ->
finish:UInt64.t{UInt64.v finish >= UInt64.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt64.t{UInt64.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt64.v i)))
(ensures (fun h_1 _ h_2 -> UInt64.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt64.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt64.v finish)))
let rec for64 start finish inv f =
if start = finish then
()
else begin
f start;
for64 (UInt64.(start +^ 1UL)) finish inv f
end
(* To be extracted as:
for (int i = <start>; i != <finish>; --i)
<f> i;
*)
val reverse_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish <= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start >= v i /\ v i > v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i - 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish)))
let rec reverse_for start finish inv f =
if start = finish then
()
else begin
f start;
reverse_for (UInt32.(start -^ 1ul)) finish inv f
end
(* To be extracted as:
bool b = false;
int i = <start>;
for (; (!b) && (i != <end>); ++i) {
b = <f> i;
}
(i, b)
*)
val interruptible_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> bool -> GTot Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack bool
(requires (fun h -> inv h (UInt32.v i) false))
(ensures (fun h_1 b h_2 -> inv h_1 (UInt32.v i) false /\ inv h_2 UInt32.(v i + 1) b)) ) ->
Stack (UInt32.t * bool)
(requires (fun h -> inv h (UInt32.v start) false))
(ensures (fun _ res h_2 -> let (i, b) = res in ((if b then True else i == finish) /\ inv h_2 (UInt32.v i) b)))
let rec interruptible_for start finish inv f =
if start = finish then
(finish, false)
else
let start' = UInt32.(start +^ 1ul) in
if f start
then (start', true)
else interruptible_for start' finish inv f
(* To be extracted as:
while (true) {
bool b = <f> i;
if (b) {
break;
}
}
*)
val do_while:
inv:(HS.mem -> bool -> GTot Type0) ->
f:(unit -> Stack bool
(requires (fun h -> inv h false))
(ensures (fun h_1 b h_2 -> inv h_1 false /\ inv h_2 b)) ) ->
Stack unit
(requires (fun h -> inv h false))
(ensures (fun _ _ h_2 -> inv h_2 true))
let rec do_while inv f =
if not (f ()) then
do_while inv f
(* Extracted as:
while (test ()) {
body ();
}
*)
val while:
#test_pre: (HS.mem -> GTot Type0) ->
#test_post: (bool -> HS.mem -> GTot Type0) ->
$test: (unit -> Stack bool
(requires (fun h -> test_pre h))
(ensures (fun h0 x h1 -> test_post x h1))) ->
body: (unit -> Stack unit
(requires (fun h -> test_post true h))
(ensures (fun h0 _ h1 -> test_pre h1))) ->
Stack unit
(requires (fun h -> test_pre h))
(ensures (fun h0 _ h1 -> test_post false h1))
let rec while #test_pre #test_post test body =
if test () then begin
body ();
while #test_pre #test_post test body
end
(* To be extracted as:
int i = <start>;
bool b = false;
for (; (!b) && (i != <end>); --i) {
b = <f> i;
}
// i and b must be in scope after the loop
*)
val interruptible_reverse_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish <= UInt32.v start} ->
inv:(HS.mem -> nat -> bool -> GTot Type0) ->
f:(i:UInt32.t{UInt32.(v start >= v i /\ v i > v finish)} -> Stack bool
(requires (fun h -> inv h (UInt32.v i) false))
(ensures (fun h_1 b h_2 -> inv h_1 (UInt32.v i) false /\ inv h_2 UInt32.(v i - 1) b)) ) ->
Stack (UInt32.t * bool)
(requires (fun h -> inv h (UInt32.v start) false))
(ensures (fun _ res h_2 -> let (i, b) = res in ((if b then True else i == finish) /\ inv h_2 (UInt32.v i) b)))
let rec interruptible_reverse_for start finish inv f =
if start = finish then
(finish, false)
else
let start' = UInt32.(start -^ 1ul) in
if f start
then (start', true)
else interruptible_reverse_for start' finish inv f
(* Non-primitive combinators that can be expressed in terms of the above ******)
(** Extracts as:
* for (int i = 0; i < <l>; ++i)
* out[i] = <f>(in[i]);
*)
inline_for_extraction
val map:
#a:Type0 -> #b:Type0 ->
output: buffer b ->
input: buffer a{disjoint input output} ->
l: UInt32.t{ UInt32.v l = Buffer.length output /\ UInt32.v l = Buffer.length input } ->
f:(a -> Tot b) ->
Stack unit
(requires (fun h -> live h input /\ live h output ))
(ensures (fun h_1 r h_2 -> modifies_1 output h_1 h_2 /\ live h_2 input /\ live h_1 input /\ live h_2 output
/\ live h_2 output
/\ (let s1 = as_seq h_1 input in
let s2 = as_seq h_2 output in
s2 == seq_map f s1) ))
inline_for_extraction
let map #a #b output input l f =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 output /\ live h1 input /\ modifies_1 output h0 h1 /\ i <= UInt32.v l
/\ (forall (j:nat). (j >= i /\ j < UInt32.v l) ==> get h1 output j == get h0 output j)
/\ (forall (j:nat). j < i ==> get h1 output j == f (get h0 input j))
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v l ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
let xi = input.(i) in
output.(i) <- f xi
in
for 0ul l inv f';
let h1 = HST.get() in
Seq.lemma_eq_intro (as_seq h1 output) (seq_map f (as_seq h0 input))
(** Extracts as:
* for (int i = 0; i < <l>; ++i)
* out[i] = <f>(in1[i], in2[i]);
*)
inline_for_extraction
val map2:
#a:Type0 -> #b:Type0 -> #c:Type0 ->
output: buffer c ->
in1: buffer a{disjoint output in1} -> in2: buffer b{disjoint output in2} ->
l: UInt32.t{ UInt32.v l = Buffer.length output /\ UInt32.v l = Buffer.length in1
/\ UInt32.v l = Buffer.length in2 } ->
f:(a -> b -> Tot c) ->
Stack unit
(requires (fun h -> live h in1 /\ live h in2 /\ live h output ))
(ensures (fun h_1 r h_2 -> modifies_1 output h_1 h_2 /\ live h_2 in1 /\ live h_2 in2
/\ live h_1 in1 /\ live h_1 in2 /\ live h_2 output
/\ (let s1 = as_seq h_1 in1 in
let s2 = as_seq h_1 in2 in
let s = as_seq h_2 output in
s == seq_map2 f s1 s2) ))
inline_for_extraction
let map2 #a #b #c output in1 in2 l f =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 output /\ live h1 in1 /\ live h1 in2 /\ modifies_1 output h0 h1 /\ i <= UInt32.v l
/\ (forall (j:nat). (j >= i /\ j < UInt32.v l) ==> get h1 output j == get h0 output j)
/\ (forall (j:nat). j < i ==> get h1 output j == f (get h0 in1 j) (get h0 in2 j))
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v l ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
let xi = in1.(i) in
let yi = in2.(i) in
output.(i) <- f xi yi
in
for 0ul l inv f';
let h1 = HST.get() in
Seq.lemma_eq_intro (as_seq h1 output) (seq_map2 f (as_seq h0 in1) (as_seq h0 in2))
(** Extracts as:
* for (int i = 0; i < <l>; ++i)
* b[i] = <f>(b[i]);
*)
inline_for_extraction
val in_place_map:
#a:Type0 ->
b: buffer a ->
l: UInt32.t{ UInt32.v l = Buffer.length b } ->
f:(a -> Tot a) ->
Stack unit
(requires (fun h -> live h b))
(ensures (fun h_1 r h_2 -> modifies_1 b h_1 h_2 /\ live h_2 b /\ live h_1 b
/\ (let s1 = as_seq h_1 b in
let s2 = as_seq h_2 b in
s2 == seq_map f s1) ))
inline_for_extraction
let in_place_map #a b l f =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 b /\ modifies_1 b h0 h1 /\ i <= UInt32.v l
/\ (forall (j:nat). (j >= i /\ j < UInt32.v l) ==> get h1 b j == get h0 b j)
/\ (forall (j:nat). j < i ==> get h1 b j == f (get h0 b j))
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v l ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
let xi = b.(i) in
b.(i) <- f xi
in
for 0ul l inv f';
let h1 = HST.get() in
Seq.lemma_eq_intro (as_seq h1 b) (seq_map f (as_seq h0 b))
(** Extracts as (destination buffer comes first):
* for (int i = 0; i < <l>; ++i)
* in1[i] = <f>(in1[i], in2[i]);
*)
inline_for_extraction
val in_place_map2:
#a:Type0 -> #b:Type0 ->
in1: buffer a ->
in2: buffer b{disjoint in1 in2} ->
l: UInt32.t{ UInt32.v l = Buffer.length in1 /\ UInt32.v l = Buffer.length in2} ->
f:(a -> b -> Tot a) ->
Stack unit
(requires (fun h -> live h in1 /\ live h in2))
(ensures (fun h_1 r h_2 -> modifies_1 in1 h_1 h_2 /\ live h_2 in1 /\ live h_2 in2
/\ live h_1 in1 /\ live h_1 in2
/\ (let s1 = as_seq h_1 in1 in
let s2 = as_seq h_1 in2 in
let s = as_seq h_2 in1 in
s == seq_map2 f s1 s2) ))
inline_for_extraction
let in_place_map2 #a #b in1 in2 l f =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 in1 /\ live h1 in2 /\ modifies_1 in1 h0 h1 /\ i <= UInt32.v l
/\ (forall (j:nat). (j >= i /\ j < UInt32.v l) ==> get h1 in1 j == get h0 in1 j)
/\ (forall (j:nat). j < i ==> get h1 in1 j == f (get h0 in1 j) (get h0 in2 j))
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v l ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
let xi = in1.(i) in
let yi = in2.(i) in
in1.(i) <- f xi yi
in
for 0ul l inv f';
let h1 = HST.get() in
Seq.lemma_eq_intro (as_seq h1 in1) (seq_map2 f (as_seq h0 in1) (as_seq h0 in2))
#reset-options "--initial_fuel 2 --max_fuel 2 --z3rlimit 20"
(* Repeating the same operation a number of times over a buffer ***************)
#reset-options "--initial_fuel 0 --max_fuel 0 --z3rlimit 20"
(** To be extracted as:
* for (int i = 0; i < n; ++i)
* f(b[i]);
*)
inline_for_extraction
val repeat:
#a:Type0 ->
l: UInt32.t ->
f:(s:Seq.seq a{Seq.length s = UInt32.v l} -> Tot (s':Seq.seq a{Seq.length s' = Seq.length s})) ->
b: buffer a{Buffer.length b = UInt32.v l} ->
max:UInt32.t ->
fc:(b:buffer a{length b = UInt32.v l} -> Stack unit
(requires (fun h -> live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ modifies_1 b h0 h1
/\ (let b0 = as_seq h0 b in
let b1 = as_seq h1 b in
b1 == f b0)))) ->
Stack unit
(requires (fun h -> live h b ))
(ensures (fun h_1 r h_2 -> modifies_1 b h_1 h_2 /\ live h_1 b /\ live h_2 b
/\ (let s = as_seq h_1 b in
let s' = as_seq h_2 b in
s' == repeat_spec (UInt32.v max) f s) )) | {
"checked_file": "/",
"dependencies": [
"Spec.Loops.fst.checked",
"prims.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Buffer.fst.checked"
],
"interface_file": false,
"source_file": "C.Compat.Loops.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.Loops",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "UInt64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "UInt32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
l: FStar.UInt32.t ->
f:
(s: FStar.Seq.Base.seq a {FStar.Seq.Base.length s = FStar.UInt32.v l}
-> s': FStar.Seq.Base.seq a {FStar.Seq.Base.length s' = FStar.Seq.Base.length s}) ->
b: FStar.Buffer.buffer a {FStar.Buffer.length b = FStar.UInt32.v l} ->
max: FStar.UInt32.t ->
fc:
(b: FStar.Buffer.buffer a {FStar.Buffer.length b = FStar.UInt32.v l}
-> FStar.HyperStack.ST.Stack Prims.unit)
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.UInt32.t",
"FStar.Seq.Base.seq",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"FStar.Seq.Base.length",
"FStar.UInt32.v",
"Prims.nat",
"FStar.Buffer.buffer",
"FStar.Buffer.length",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"FStar.Buffer.live",
"Prims.l_and",
"FStar.Buffer.modifies_1",
"Prims.eq2",
"FStar.Buffer.as_seq",
"C.Compat.Loops.for",
"FStar.UInt32.__uint_to_t",
"Spec.Loops.lemma_repeat_0",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Addition",
"Spec.Loops.lemma_repeat",
"Spec.Loops.repeat_spec",
"FStar.HyperStack.ST.get"
] | [] | false | true | false | false | false | let repeat #a l f b max fc =
| let h0 = HST.get () in
let inv (h1: HS.mem) (i: nat) : Type0 =
live h1 b /\ modifies_1 b h0 h1 /\ i <= UInt32.v max /\
as_seq h1 b == repeat_spec i f (as_seq h0 b)
in
let f' (i: UInt32.t{let open UInt32 in 0 <= v i /\ v i < v max})
: Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> let open UInt32 in inv h_2 (v i + 1))) =
fc b;
lemma_repeat (UInt32.v i + 1) f (as_seq h0 b)
in
lemma_repeat_0 0 f (as_seq h0 b);
for 0ul max inv f' | false |
C.Compat.Loops.fst | C.Compat.Loops.repeat_range | val repeat_range:
#a:Type0 ->
l: UInt32.t ->
min:UInt32.t ->
max:UInt32.t{UInt32.v min <= UInt32.v max} ->
f:(s:Seq.seq a{Seq.length s = UInt32.v l} -> i:nat{i < UInt32.v max} -> Tot (s':Seq.seq a{Seq.length s' = Seq.length s})) ->
b: buffer a{Buffer.length b = UInt32.v l} ->
fc:(b:buffer a{length b = UInt32.v l} -> i:UInt32.t{UInt32.v i < UInt32.v max} -> Stack unit
(requires (fun h -> live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ modifies_1 b h0 h1
/\ (let b0 = as_seq h0 b in
let b1 = as_seq h1 b in
b1 == f b0 (UInt32.v i))))) ->
Stack unit
(requires (fun h -> live h b ))
(ensures (fun h_1 r h_2 -> modifies_1 b h_1 h_2 /\ live h_1 b /\ live h_2 b
/\ (let s = as_seq h_1 b in
let s' = as_seq h_2 b in
s' == repeat_range_spec (UInt32.v min) (UInt32.v max) f s) )) | val repeat_range:
#a:Type0 ->
l: UInt32.t ->
min:UInt32.t ->
max:UInt32.t{UInt32.v min <= UInt32.v max} ->
f:(s:Seq.seq a{Seq.length s = UInt32.v l} -> i:nat{i < UInt32.v max} -> Tot (s':Seq.seq a{Seq.length s' = Seq.length s})) ->
b: buffer a{Buffer.length b = UInt32.v l} ->
fc:(b:buffer a{length b = UInt32.v l} -> i:UInt32.t{UInt32.v i < UInt32.v max} -> Stack unit
(requires (fun h -> live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ modifies_1 b h0 h1
/\ (let b0 = as_seq h0 b in
let b1 = as_seq h1 b in
b1 == f b0 (UInt32.v i))))) ->
Stack unit
(requires (fun h -> live h b ))
(ensures (fun h_1 r h_2 -> modifies_1 b h_1 h_2 /\ live h_1 b /\ live h_2 b
/\ (let s = as_seq h_1 b in
let s' = as_seq h_2 b in
s' == repeat_range_spec (UInt32.v min) (UInt32.v max) f s) )) | let repeat_range #a l min max f b fc =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 b /\ modifies_1 b h0 h1 /\ i <= UInt32.v max /\ UInt32.v min <= i
/\ as_seq h1 b == repeat_range_spec (UInt32.v min) i f (as_seq h0 b)
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v max ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
fc b i;
lemma_repeat_range_spec (UInt32.v min) (UInt32.v i + 1) f (as_seq h0 b)
in
lemma_repeat_range_0 (UInt32.v min) f (as_seq h0 b);
for min max inv f' | {
"file_name": "krmllib/compat/C.Compat.Loops.fst",
"git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321",
"git_url": "https://github.com/FStarLang/karamel.git",
"project_name": "karamel"
} | {
"end_col": 20,
"end_line": 444,
"start_col": 0,
"start_line": 430
} | (* This module exposes a series of combinators; they are modeled using
* higher-order functions and specifications, and extracted, using a
* meta-theoretic argument, to actual C loops. *)
module C.Compat.Loops
open FStar.HyperStack.ST
open FStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module UInt32 = FStar.UInt32
module UInt64 = FStar.UInt64
include Spec.Loops
#set-options "--initial_fuel 0 --max_fuel 0 --z3rlimit 20"
(** The functions in this module use the following convention:
* - the first arguments are buffers;
* - the destination buffer comes first, followed by the input buffer (as in
* C's memcpy)
* - each buffer is followed by its length; if several buffers share the same
* length, there is a single length argument after the buffers
* - the function-specific arguments come next (e.g. the number of times one
* may want to call the function in [repeat])
* - the second to last argument is the loop invariant (which may have
* dependencies on all the parameters before)
* - the last argument is the loop body (that will depend on the invariant, and
* possibly all the other parameters before. *)
(* Generic-purpose for-loop combinators ***************************************)
(* These combinators enjoy first-class support in KaRaMeL. (See [combinators] in
* src/Simplify.ml *)
(* Currently extracting as:
for (int i = <start>; i != <finish>; ++i)
<f> i;
*)
val for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish)))
let rec for start finish inv f =
if start = finish then
()
else begin
f start;
for (UInt32.(start +^ 1ul)) finish inv f
end
val for64:
start:UInt64.t ->
finish:UInt64.t{UInt64.v finish >= UInt64.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt64.t{UInt64.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt64.v i)))
(ensures (fun h_1 _ h_2 -> UInt64.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt64.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt64.v finish)))
let rec for64 start finish inv f =
if start = finish then
()
else begin
f start;
for64 (UInt64.(start +^ 1UL)) finish inv f
end
(* To be extracted as:
for (int i = <start>; i != <finish>; --i)
<f> i;
*)
val reverse_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish <= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start >= v i /\ v i > v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i - 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish)))
let rec reverse_for start finish inv f =
if start = finish then
()
else begin
f start;
reverse_for (UInt32.(start -^ 1ul)) finish inv f
end
(* To be extracted as:
bool b = false;
int i = <start>;
for (; (!b) && (i != <end>); ++i) {
b = <f> i;
}
(i, b)
*)
val interruptible_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> bool -> GTot Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack bool
(requires (fun h -> inv h (UInt32.v i) false))
(ensures (fun h_1 b h_2 -> inv h_1 (UInt32.v i) false /\ inv h_2 UInt32.(v i + 1) b)) ) ->
Stack (UInt32.t * bool)
(requires (fun h -> inv h (UInt32.v start) false))
(ensures (fun _ res h_2 -> let (i, b) = res in ((if b then True else i == finish) /\ inv h_2 (UInt32.v i) b)))
let rec interruptible_for start finish inv f =
if start = finish then
(finish, false)
else
let start' = UInt32.(start +^ 1ul) in
if f start
then (start', true)
else interruptible_for start' finish inv f
(* To be extracted as:
while (true) {
bool b = <f> i;
if (b) {
break;
}
}
*)
val do_while:
inv:(HS.mem -> bool -> GTot Type0) ->
f:(unit -> Stack bool
(requires (fun h -> inv h false))
(ensures (fun h_1 b h_2 -> inv h_1 false /\ inv h_2 b)) ) ->
Stack unit
(requires (fun h -> inv h false))
(ensures (fun _ _ h_2 -> inv h_2 true))
let rec do_while inv f =
if not (f ()) then
do_while inv f
(* Extracted as:
while (test ()) {
body ();
}
*)
val while:
#test_pre: (HS.mem -> GTot Type0) ->
#test_post: (bool -> HS.mem -> GTot Type0) ->
$test: (unit -> Stack bool
(requires (fun h -> test_pre h))
(ensures (fun h0 x h1 -> test_post x h1))) ->
body: (unit -> Stack unit
(requires (fun h -> test_post true h))
(ensures (fun h0 _ h1 -> test_pre h1))) ->
Stack unit
(requires (fun h -> test_pre h))
(ensures (fun h0 _ h1 -> test_post false h1))
let rec while #test_pre #test_post test body =
if test () then begin
body ();
while #test_pre #test_post test body
end
(* To be extracted as:
int i = <start>;
bool b = false;
for (; (!b) && (i != <end>); --i) {
b = <f> i;
}
// i and b must be in scope after the loop
*)
val interruptible_reverse_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish <= UInt32.v start} ->
inv:(HS.mem -> nat -> bool -> GTot Type0) ->
f:(i:UInt32.t{UInt32.(v start >= v i /\ v i > v finish)} -> Stack bool
(requires (fun h -> inv h (UInt32.v i) false))
(ensures (fun h_1 b h_2 -> inv h_1 (UInt32.v i) false /\ inv h_2 UInt32.(v i - 1) b)) ) ->
Stack (UInt32.t * bool)
(requires (fun h -> inv h (UInt32.v start) false))
(ensures (fun _ res h_2 -> let (i, b) = res in ((if b then True else i == finish) /\ inv h_2 (UInt32.v i) b)))
let rec interruptible_reverse_for start finish inv f =
if start = finish then
(finish, false)
else
let start' = UInt32.(start -^ 1ul) in
if f start
then (start', true)
else interruptible_reverse_for start' finish inv f
(* Non-primitive combinators that can be expressed in terms of the above ******)
(** Extracts as:
* for (int i = 0; i < <l>; ++i)
* out[i] = <f>(in[i]);
*)
inline_for_extraction
val map:
#a:Type0 -> #b:Type0 ->
output: buffer b ->
input: buffer a{disjoint input output} ->
l: UInt32.t{ UInt32.v l = Buffer.length output /\ UInt32.v l = Buffer.length input } ->
f:(a -> Tot b) ->
Stack unit
(requires (fun h -> live h input /\ live h output ))
(ensures (fun h_1 r h_2 -> modifies_1 output h_1 h_2 /\ live h_2 input /\ live h_1 input /\ live h_2 output
/\ live h_2 output
/\ (let s1 = as_seq h_1 input in
let s2 = as_seq h_2 output in
s2 == seq_map f s1) ))
inline_for_extraction
let map #a #b output input l f =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 output /\ live h1 input /\ modifies_1 output h0 h1 /\ i <= UInt32.v l
/\ (forall (j:nat). (j >= i /\ j < UInt32.v l) ==> get h1 output j == get h0 output j)
/\ (forall (j:nat). j < i ==> get h1 output j == f (get h0 input j))
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v l ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
let xi = input.(i) in
output.(i) <- f xi
in
for 0ul l inv f';
let h1 = HST.get() in
Seq.lemma_eq_intro (as_seq h1 output) (seq_map f (as_seq h0 input))
(** Extracts as:
* for (int i = 0; i < <l>; ++i)
* out[i] = <f>(in1[i], in2[i]);
*)
inline_for_extraction
val map2:
#a:Type0 -> #b:Type0 -> #c:Type0 ->
output: buffer c ->
in1: buffer a{disjoint output in1} -> in2: buffer b{disjoint output in2} ->
l: UInt32.t{ UInt32.v l = Buffer.length output /\ UInt32.v l = Buffer.length in1
/\ UInt32.v l = Buffer.length in2 } ->
f:(a -> b -> Tot c) ->
Stack unit
(requires (fun h -> live h in1 /\ live h in2 /\ live h output ))
(ensures (fun h_1 r h_2 -> modifies_1 output h_1 h_2 /\ live h_2 in1 /\ live h_2 in2
/\ live h_1 in1 /\ live h_1 in2 /\ live h_2 output
/\ (let s1 = as_seq h_1 in1 in
let s2 = as_seq h_1 in2 in
let s = as_seq h_2 output in
s == seq_map2 f s1 s2) ))
inline_for_extraction
let map2 #a #b #c output in1 in2 l f =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 output /\ live h1 in1 /\ live h1 in2 /\ modifies_1 output h0 h1 /\ i <= UInt32.v l
/\ (forall (j:nat). (j >= i /\ j < UInt32.v l) ==> get h1 output j == get h0 output j)
/\ (forall (j:nat). j < i ==> get h1 output j == f (get h0 in1 j) (get h0 in2 j))
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v l ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
let xi = in1.(i) in
let yi = in2.(i) in
output.(i) <- f xi yi
in
for 0ul l inv f';
let h1 = HST.get() in
Seq.lemma_eq_intro (as_seq h1 output) (seq_map2 f (as_seq h0 in1) (as_seq h0 in2))
(** Extracts as:
* for (int i = 0; i < <l>; ++i)
* b[i] = <f>(b[i]);
*)
inline_for_extraction
val in_place_map:
#a:Type0 ->
b: buffer a ->
l: UInt32.t{ UInt32.v l = Buffer.length b } ->
f:(a -> Tot a) ->
Stack unit
(requires (fun h -> live h b))
(ensures (fun h_1 r h_2 -> modifies_1 b h_1 h_2 /\ live h_2 b /\ live h_1 b
/\ (let s1 = as_seq h_1 b in
let s2 = as_seq h_2 b in
s2 == seq_map f s1) ))
inline_for_extraction
let in_place_map #a b l f =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 b /\ modifies_1 b h0 h1 /\ i <= UInt32.v l
/\ (forall (j:nat). (j >= i /\ j < UInt32.v l) ==> get h1 b j == get h0 b j)
/\ (forall (j:nat). j < i ==> get h1 b j == f (get h0 b j))
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v l ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
let xi = b.(i) in
b.(i) <- f xi
in
for 0ul l inv f';
let h1 = HST.get() in
Seq.lemma_eq_intro (as_seq h1 b) (seq_map f (as_seq h0 b))
(** Extracts as (destination buffer comes first):
* for (int i = 0; i < <l>; ++i)
* in1[i] = <f>(in1[i], in2[i]);
*)
inline_for_extraction
val in_place_map2:
#a:Type0 -> #b:Type0 ->
in1: buffer a ->
in2: buffer b{disjoint in1 in2} ->
l: UInt32.t{ UInt32.v l = Buffer.length in1 /\ UInt32.v l = Buffer.length in2} ->
f:(a -> b -> Tot a) ->
Stack unit
(requires (fun h -> live h in1 /\ live h in2))
(ensures (fun h_1 r h_2 -> modifies_1 in1 h_1 h_2 /\ live h_2 in1 /\ live h_2 in2
/\ live h_1 in1 /\ live h_1 in2
/\ (let s1 = as_seq h_1 in1 in
let s2 = as_seq h_1 in2 in
let s = as_seq h_2 in1 in
s == seq_map2 f s1 s2) ))
inline_for_extraction
let in_place_map2 #a #b in1 in2 l f =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 in1 /\ live h1 in2 /\ modifies_1 in1 h0 h1 /\ i <= UInt32.v l
/\ (forall (j:nat). (j >= i /\ j < UInt32.v l) ==> get h1 in1 j == get h0 in1 j)
/\ (forall (j:nat). j < i ==> get h1 in1 j == f (get h0 in1 j) (get h0 in2 j))
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v l ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
let xi = in1.(i) in
let yi = in2.(i) in
in1.(i) <- f xi yi
in
for 0ul l inv f';
let h1 = HST.get() in
Seq.lemma_eq_intro (as_seq h1 in1) (seq_map2 f (as_seq h0 in1) (as_seq h0 in2))
#reset-options "--initial_fuel 2 --max_fuel 2 --z3rlimit 20"
(* Repeating the same operation a number of times over a buffer ***************)
#reset-options "--initial_fuel 0 --max_fuel 0 --z3rlimit 20"
(** To be extracted as:
* for (int i = 0; i < n; ++i)
* f(b[i]);
*)
inline_for_extraction
val repeat:
#a:Type0 ->
l: UInt32.t ->
f:(s:Seq.seq a{Seq.length s = UInt32.v l} -> Tot (s':Seq.seq a{Seq.length s' = Seq.length s})) ->
b: buffer a{Buffer.length b = UInt32.v l} ->
max:UInt32.t ->
fc:(b:buffer a{length b = UInt32.v l} -> Stack unit
(requires (fun h -> live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ modifies_1 b h0 h1
/\ (let b0 = as_seq h0 b in
let b1 = as_seq h1 b in
b1 == f b0)))) ->
Stack unit
(requires (fun h -> live h b ))
(ensures (fun h_1 r h_2 -> modifies_1 b h_1 h_2 /\ live h_1 b /\ live h_2 b
/\ (let s = as_seq h_1 b in
let s' = as_seq h_2 b in
s' == repeat_spec (UInt32.v max) f s) ))
inline_for_extraction
let repeat #a l f b max fc =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 b /\ modifies_1 b h0 h1 /\ i <= UInt32.v max
/\ as_seq h1 b == repeat_spec i f (as_seq h0 b)
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v max ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
fc b;
lemma_repeat (UInt32.v i + 1) f (as_seq h0 b)
in
lemma_repeat_0 0 f (as_seq h0 b);
for 0ul max inv f'
(** To be extracted as:
* for (int i = min; i < max; ++i)
* f(b[i], i);
*)
inline_for_extraction
val repeat_range:
#a:Type0 ->
l: UInt32.t ->
min:UInt32.t ->
max:UInt32.t{UInt32.v min <= UInt32.v max} ->
f:(s:Seq.seq a{Seq.length s = UInt32.v l} -> i:nat{i < UInt32.v max} -> Tot (s':Seq.seq a{Seq.length s' = Seq.length s})) ->
b: buffer a{Buffer.length b = UInt32.v l} ->
fc:(b:buffer a{length b = UInt32.v l} -> i:UInt32.t{UInt32.v i < UInt32.v max} -> Stack unit
(requires (fun h -> live h b))
(ensures (fun h0 _ h1 -> live h0 b /\ live h1 b /\ modifies_1 b h0 h1
/\ (let b0 = as_seq h0 b in
let b1 = as_seq h1 b in
b1 == f b0 (UInt32.v i))))) ->
Stack unit
(requires (fun h -> live h b ))
(ensures (fun h_1 r h_2 -> modifies_1 b h_1 h_2 /\ live h_1 b /\ live h_2 b
/\ (let s = as_seq h_1 b in
let s' = as_seq h_2 b in
s' == repeat_range_spec (UInt32.v min) (UInt32.v max) f s) )) | {
"checked_file": "/",
"dependencies": [
"Spec.Loops.fst.checked",
"prims.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Buffer.fst.checked"
],
"interface_file": false,
"source_file": "C.Compat.Loops.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.Loops",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "UInt64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "UInt32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
l: FStar.UInt32.t ->
min: FStar.UInt32.t ->
max: FStar.UInt32.t{FStar.UInt32.v min <= FStar.UInt32.v max} ->
f:
(
s: FStar.Seq.Base.seq a {FStar.Seq.Base.length s = FStar.UInt32.v l} ->
i: Prims.nat{i < FStar.UInt32.v max}
-> s': FStar.Seq.Base.seq a {FStar.Seq.Base.length s' = FStar.Seq.Base.length s}) ->
b: FStar.Buffer.buffer a {FStar.Buffer.length b = FStar.UInt32.v l} ->
fc:
(
b: FStar.Buffer.buffer a {FStar.Buffer.length b = FStar.UInt32.v l} ->
i: FStar.UInt32.t{FStar.UInt32.v i < FStar.UInt32.v max}
-> FStar.HyperStack.ST.Stack Prims.unit)
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.UInt32.t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"FStar.Seq.Base.seq",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"FStar.Seq.Base.length",
"Prims.nat",
"Prims.op_LessThan",
"FStar.Buffer.buffer",
"FStar.Buffer.length",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"FStar.Buffer.live",
"Prims.l_and",
"FStar.Buffer.modifies_1",
"Prims.eq2",
"FStar.Buffer.as_seq",
"C.Compat.Loops.for",
"Spec.Loops.lemma_repeat_range_0",
"Prims.op_Addition",
"Spec.Loops.lemma_repeat_range_spec",
"Spec.Loops.repeat_range_spec",
"FStar.HyperStack.ST.get"
] | [] | false | true | false | false | false | let repeat_range #a l min max f b fc =
| let h0 = HST.get () in
let inv (h1: HS.mem) (i: nat) : Type0 =
live h1 b /\ modifies_1 b h0 h1 /\ i <= UInt32.v max /\ UInt32.v min <= i /\
as_seq h1 b == repeat_range_spec (UInt32.v min) i f (as_seq h0 b)
in
let f' (i: UInt32.t{let open UInt32 in 0 <= v i /\ v i < v max})
: Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> let open UInt32 in inv h_2 (v i + 1))) =
fc b i;
lemma_repeat_range_spec (UInt32.v min) (UInt32.v i + 1) f (as_seq h0 b)
in
lemma_repeat_range_0 (UInt32.v min) f (as_seq h0 b);
for min max inv f' | false |
Spec.AES.Test.fst | Spec.AES.Test.test_counter | val test_counter : Prims.int | let test_counter = 0xfcfdfeff | {
"file_name": "specs/tests/Spec.AES.Test.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 29,
"start_col": 0,
"start_line": 29
} | module Spec.AES.Test
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
module PS = Lib.PrintSequence
open Spec.AES
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let test_key : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x2buy; 0x7euy; 0x15uy; 0x16uy; 0x28uy; 0xaeuy; 0xd2uy; 0xa6uy;
0xabuy; 0xf7uy; 0x15uy; 0x88uy; 0x09uy; 0xcfuy; 0x4fuy; 0x3cuy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_nonce : lbytes 12 =
let l = List.Tot.map u8_from_UInt8 [
0xf0uy; 0xf1uy; 0xf2uy; 0xf3uy; 0xf4uy; 0xf5uy; 0xf6uy; 0xf7uy;
0xf8uy; 0xf9uy; 0xfauy; 0xfbuy ] in
assert_norm (List.Tot.length l == 12);
of_list l | {
"checked_file": "/",
"dependencies": [
"Spec.AES.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.PrintSequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.Test.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.PrintSequence",
"short_module": "PS"
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"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": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.int | Prims.Tot | [
"total"
] | [] | [] | [] | false | false | false | true | false | let test_counter =
| 0xfcfdfeff | false |
|
C.Compat.Loops.fst | C.Compat.Loops.in_place_map2 | val in_place_map2:
#a:Type0 -> #b:Type0 ->
in1: buffer a ->
in2: buffer b{disjoint in1 in2} ->
l: UInt32.t{ UInt32.v l = Buffer.length in1 /\ UInt32.v l = Buffer.length in2} ->
f:(a -> b -> Tot a) ->
Stack unit
(requires (fun h -> live h in1 /\ live h in2))
(ensures (fun h_1 r h_2 -> modifies_1 in1 h_1 h_2 /\ live h_2 in1 /\ live h_2 in2
/\ live h_1 in1 /\ live h_1 in2
/\ (let s1 = as_seq h_1 in1 in
let s2 = as_seq h_1 in2 in
let s = as_seq h_2 in1 in
s == seq_map2 f s1 s2) )) | val in_place_map2:
#a:Type0 -> #b:Type0 ->
in1: buffer a ->
in2: buffer b{disjoint in1 in2} ->
l: UInt32.t{ UInt32.v l = Buffer.length in1 /\ UInt32.v l = Buffer.length in2} ->
f:(a -> b -> Tot a) ->
Stack unit
(requires (fun h -> live h in1 /\ live h in2))
(ensures (fun h_1 r h_2 -> modifies_1 in1 h_1 h_2 /\ live h_2 in1 /\ live h_2 in2
/\ live h_1 in1 /\ live h_1 in2
/\ (let s1 = as_seq h_1 in1 in
let s2 = as_seq h_1 in2 in
let s = as_seq h_2 in1 in
s == seq_map2 f s1 s2) )) | let in_place_map2 #a #b in1 in2 l f =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 in1 /\ live h1 in2 /\ modifies_1 in1 h0 h1 /\ i <= UInt32.v l
/\ (forall (j:nat). (j >= i /\ j < UInt32.v l) ==> get h1 in1 j == get h0 in1 j)
/\ (forall (j:nat). j < i ==> get h1 in1 j == f (get h0 in1 j) (get h0 in2 j))
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v l ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
let xi = in1.(i) in
let yi = in2.(i) in
in1.(i) <- f xi yi
in
for 0ul l inv f';
let h1 = HST.get() in
Seq.lemma_eq_intro (as_seq h1 in1) (seq_map2 f (as_seq h0 in1) (as_seq h0 in2)) | {
"file_name": "krmllib/compat/C.Compat.Loops.fst",
"git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321",
"git_url": "https://github.com/FStarLang/karamel.git",
"project_name": "karamel"
} | {
"end_col": 81,
"end_line": 354,
"start_col": 0,
"start_line": 337
} | (* This module exposes a series of combinators; they are modeled using
* higher-order functions and specifications, and extracted, using a
* meta-theoretic argument, to actual C loops. *)
module C.Compat.Loops
open FStar.HyperStack.ST
open FStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module UInt32 = FStar.UInt32
module UInt64 = FStar.UInt64
include Spec.Loops
#set-options "--initial_fuel 0 --max_fuel 0 --z3rlimit 20"
(** The functions in this module use the following convention:
* - the first arguments are buffers;
* - the destination buffer comes first, followed by the input buffer (as in
* C's memcpy)
* - each buffer is followed by its length; if several buffers share the same
* length, there is a single length argument after the buffers
* - the function-specific arguments come next (e.g. the number of times one
* may want to call the function in [repeat])
* - the second to last argument is the loop invariant (which may have
* dependencies on all the parameters before)
* - the last argument is the loop body (that will depend on the invariant, and
* possibly all the other parameters before. *)
(* Generic-purpose for-loop combinators ***************************************)
(* These combinators enjoy first-class support in KaRaMeL. (See [combinators] in
* src/Simplify.ml *)
(* Currently extracting as:
for (int i = <start>; i != <finish>; ++i)
<f> i;
*)
val for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish)))
let rec for start finish inv f =
if start = finish then
()
else begin
f start;
for (UInt32.(start +^ 1ul)) finish inv f
end
val for64:
start:UInt64.t ->
finish:UInt64.t{UInt64.v finish >= UInt64.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt64.t{UInt64.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt64.v i)))
(ensures (fun h_1 _ h_2 -> UInt64.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt64.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt64.v finish)))
let rec for64 start finish inv f =
if start = finish then
()
else begin
f start;
for64 (UInt64.(start +^ 1UL)) finish inv f
end
(* To be extracted as:
for (int i = <start>; i != <finish>; --i)
<f> i;
*)
val reverse_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish <= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start >= v i /\ v i > v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i - 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish)))
let rec reverse_for start finish inv f =
if start = finish then
()
else begin
f start;
reverse_for (UInt32.(start -^ 1ul)) finish inv f
end
(* To be extracted as:
bool b = false;
int i = <start>;
for (; (!b) && (i != <end>); ++i) {
b = <f> i;
}
(i, b)
*)
val interruptible_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> bool -> GTot Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack bool
(requires (fun h -> inv h (UInt32.v i) false))
(ensures (fun h_1 b h_2 -> inv h_1 (UInt32.v i) false /\ inv h_2 UInt32.(v i + 1) b)) ) ->
Stack (UInt32.t * bool)
(requires (fun h -> inv h (UInt32.v start) false))
(ensures (fun _ res h_2 -> let (i, b) = res in ((if b then True else i == finish) /\ inv h_2 (UInt32.v i) b)))
let rec interruptible_for start finish inv f =
if start = finish then
(finish, false)
else
let start' = UInt32.(start +^ 1ul) in
if f start
then (start', true)
else interruptible_for start' finish inv f
(* To be extracted as:
while (true) {
bool b = <f> i;
if (b) {
break;
}
}
*)
val do_while:
inv:(HS.mem -> bool -> GTot Type0) ->
f:(unit -> Stack bool
(requires (fun h -> inv h false))
(ensures (fun h_1 b h_2 -> inv h_1 false /\ inv h_2 b)) ) ->
Stack unit
(requires (fun h -> inv h false))
(ensures (fun _ _ h_2 -> inv h_2 true))
let rec do_while inv f =
if not (f ()) then
do_while inv f
(* Extracted as:
while (test ()) {
body ();
}
*)
val while:
#test_pre: (HS.mem -> GTot Type0) ->
#test_post: (bool -> HS.mem -> GTot Type0) ->
$test: (unit -> Stack bool
(requires (fun h -> test_pre h))
(ensures (fun h0 x h1 -> test_post x h1))) ->
body: (unit -> Stack unit
(requires (fun h -> test_post true h))
(ensures (fun h0 _ h1 -> test_pre h1))) ->
Stack unit
(requires (fun h -> test_pre h))
(ensures (fun h0 _ h1 -> test_post false h1))
let rec while #test_pre #test_post test body =
if test () then begin
body ();
while #test_pre #test_post test body
end
(* To be extracted as:
int i = <start>;
bool b = false;
for (; (!b) && (i != <end>); --i) {
b = <f> i;
}
// i and b must be in scope after the loop
*)
val interruptible_reverse_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish <= UInt32.v start} ->
inv:(HS.mem -> nat -> bool -> GTot Type0) ->
f:(i:UInt32.t{UInt32.(v start >= v i /\ v i > v finish)} -> Stack bool
(requires (fun h -> inv h (UInt32.v i) false))
(ensures (fun h_1 b h_2 -> inv h_1 (UInt32.v i) false /\ inv h_2 UInt32.(v i - 1) b)) ) ->
Stack (UInt32.t * bool)
(requires (fun h -> inv h (UInt32.v start) false))
(ensures (fun _ res h_2 -> let (i, b) = res in ((if b then True else i == finish) /\ inv h_2 (UInt32.v i) b)))
let rec interruptible_reverse_for start finish inv f =
if start = finish then
(finish, false)
else
let start' = UInt32.(start -^ 1ul) in
if f start
then (start', true)
else interruptible_reverse_for start' finish inv f
(* Non-primitive combinators that can be expressed in terms of the above ******)
(** Extracts as:
* for (int i = 0; i < <l>; ++i)
* out[i] = <f>(in[i]);
*)
inline_for_extraction
val map:
#a:Type0 -> #b:Type0 ->
output: buffer b ->
input: buffer a{disjoint input output} ->
l: UInt32.t{ UInt32.v l = Buffer.length output /\ UInt32.v l = Buffer.length input } ->
f:(a -> Tot b) ->
Stack unit
(requires (fun h -> live h input /\ live h output ))
(ensures (fun h_1 r h_2 -> modifies_1 output h_1 h_2 /\ live h_2 input /\ live h_1 input /\ live h_2 output
/\ live h_2 output
/\ (let s1 = as_seq h_1 input in
let s2 = as_seq h_2 output in
s2 == seq_map f s1) ))
inline_for_extraction
let map #a #b output input l f =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 output /\ live h1 input /\ modifies_1 output h0 h1 /\ i <= UInt32.v l
/\ (forall (j:nat). (j >= i /\ j < UInt32.v l) ==> get h1 output j == get h0 output j)
/\ (forall (j:nat). j < i ==> get h1 output j == f (get h0 input j))
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v l ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
let xi = input.(i) in
output.(i) <- f xi
in
for 0ul l inv f';
let h1 = HST.get() in
Seq.lemma_eq_intro (as_seq h1 output) (seq_map f (as_seq h0 input))
(** Extracts as:
* for (int i = 0; i < <l>; ++i)
* out[i] = <f>(in1[i], in2[i]);
*)
inline_for_extraction
val map2:
#a:Type0 -> #b:Type0 -> #c:Type0 ->
output: buffer c ->
in1: buffer a{disjoint output in1} -> in2: buffer b{disjoint output in2} ->
l: UInt32.t{ UInt32.v l = Buffer.length output /\ UInt32.v l = Buffer.length in1
/\ UInt32.v l = Buffer.length in2 } ->
f:(a -> b -> Tot c) ->
Stack unit
(requires (fun h -> live h in1 /\ live h in2 /\ live h output ))
(ensures (fun h_1 r h_2 -> modifies_1 output h_1 h_2 /\ live h_2 in1 /\ live h_2 in2
/\ live h_1 in1 /\ live h_1 in2 /\ live h_2 output
/\ (let s1 = as_seq h_1 in1 in
let s2 = as_seq h_1 in2 in
let s = as_seq h_2 output in
s == seq_map2 f s1 s2) ))
inline_for_extraction
let map2 #a #b #c output in1 in2 l f =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 output /\ live h1 in1 /\ live h1 in2 /\ modifies_1 output h0 h1 /\ i <= UInt32.v l
/\ (forall (j:nat). (j >= i /\ j < UInt32.v l) ==> get h1 output j == get h0 output j)
/\ (forall (j:nat). j < i ==> get h1 output j == f (get h0 in1 j) (get h0 in2 j))
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v l ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
let xi = in1.(i) in
let yi = in2.(i) in
output.(i) <- f xi yi
in
for 0ul l inv f';
let h1 = HST.get() in
Seq.lemma_eq_intro (as_seq h1 output) (seq_map2 f (as_seq h0 in1) (as_seq h0 in2))
(** Extracts as:
* for (int i = 0; i < <l>; ++i)
* b[i] = <f>(b[i]);
*)
inline_for_extraction
val in_place_map:
#a:Type0 ->
b: buffer a ->
l: UInt32.t{ UInt32.v l = Buffer.length b } ->
f:(a -> Tot a) ->
Stack unit
(requires (fun h -> live h b))
(ensures (fun h_1 r h_2 -> modifies_1 b h_1 h_2 /\ live h_2 b /\ live h_1 b
/\ (let s1 = as_seq h_1 b in
let s2 = as_seq h_2 b in
s2 == seq_map f s1) ))
inline_for_extraction
let in_place_map #a b l f =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 b /\ modifies_1 b h0 h1 /\ i <= UInt32.v l
/\ (forall (j:nat). (j >= i /\ j < UInt32.v l) ==> get h1 b j == get h0 b j)
/\ (forall (j:nat). j < i ==> get h1 b j == f (get h0 b j))
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v l ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
let xi = b.(i) in
b.(i) <- f xi
in
for 0ul l inv f';
let h1 = HST.get() in
Seq.lemma_eq_intro (as_seq h1 b) (seq_map f (as_seq h0 b))
(** Extracts as (destination buffer comes first):
* for (int i = 0; i < <l>; ++i)
* in1[i] = <f>(in1[i], in2[i]);
*)
inline_for_extraction
val in_place_map2:
#a:Type0 -> #b:Type0 ->
in1: buffer a ->
in2: buffer b{disjoint in1 in2} ->
l: UInt32.t{ UInt32.v l = Buffer.length in1 /\ UInt32.v l = Buffer.length in2} ->
f:(a -> b -> Tot a) ->
Stack unit
(requires (fun h -> live h in1 /\ live h in2))
(ensures (fun h_1 r h_2 -> modifies_1 in1 h_1 h_2 /\ live h_2 in1 /\ live h_2 in2
/\ live h_1 in1 /\ live h_1 in2
/\ (let s1 = as_seq h_1 in1 in
let s2 = as_seq h_1 in2 in
let s = as_seq h_2 in1 in
s == seq_map2 f s1 s2) )) | {
"checked_file": "/",
"dependencies": [
"Spec.Loops.fst.checked",
"prims.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Buffer.fst.checked"
],
"interface_file": false,
"source_file": "C.Compat.Loops.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.Loops",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "UInt64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "UInt32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
in1: FStar.Buffer.buffer a ->
in2: FStar.Buffer.buffer b {FStar.Buffer.disjoint in1 in2} ->
l:
FStar.UInt32.t
{FStar.UInt32.v l = FStar.Buffer.length in1 /\ FStar.UInt32.v l = FStar.Buffer.length in2} ->
f: (_: a -> _: b -> a)
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.Buffer.buffer",
"FStar.Buffer.disjoint",
"FStar.UInt32.t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt32.v",
"FStar.Buffer.length",
"FStar.Seq.Base.lemma_eq_intro",
"FStar.Buffer.as_seq",
"Spec.Loops.seq_map2",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"C.Compat.Loops.for",
"FStar.UInt32.__uint_to_t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Addition",
"FStar.Buffer.op_Array_Assignment",
"FStar.Buffer.op_Array_Access",
"Prims.nat",
"FStar.Buffer.live",
"FStar.Buffer.modifies_1",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.eq2",
"FStar.Buffer.get"
] | [] | false | true | false | false | false | let in_place_map2 #a #b in1 in2 l f =
| let h0 = HST.get () in
let inv (h1: HS.mem) (i: nat) : Type0 =
live h1 in1 /\ live h1 in2 /\ modifies_1 in1 h0 h1 /\ i <= UInt32.v l /\
(forall (j: nat). (j >= i /\ j < UInt32.v l) ==> get h1 in1 j == get h0 in1 j) /\
(forall (j: nat). j < i ==> get h1 in1 j == f (get h0 in1 j) (get h0 in2 j))
in
let f' (i: UInt32.t{let open UInt32 in 0 <= v i /\ v i < v l})
: Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> let open UInt32 in inv h_2 (v i + 1))) =
let xi = in1.(i) in
let yi = in2.(i) in
in1.(i) <- f xi yi
in
for 0ul l inv f';
let h1 = HST.get () in
Seq.lemma_eq_intro (as_seq h1 in1) (seq_map2 f (as_seq h0 in1) (as_seq h0 in2)) | false |
C.Compat.Loops.fst | C.Compat.Loops.map | val map:
#a:Type0 -> #b:Type0 ->
output: buffer b ->
input: buffer a{disjoint input output} ->
l: UInt32.t{ UInt32.v l = Buffer.length output /\ UInt32.v l = Buffer.length input } ->
f:(a -> Tot b) ->
Stack unit
(requires (fun h -> live h input /\ live h output ))
(ensures (fun h_1 r h_2 -> modifies_1 output h_1 h_2 /\ live h_2 input /\ live h_1 input /\ live h_2 output
/\ live h_2 output
/\ (let s1 = as_seq h_1 input in
let s2 = as_seq h_2 output in
s2 == seq_map f s1) )) | val map:
#a:Type0 -> #b:Type0 ->
output: buffer b ->
input: buffer a{disjoint input output} ->
l: UInt32.t{ UInt32.v l = Buffer.length output /\ UInt32.v l = Buffer.length input } ->
f:(a -> Tot b) ->
Stack unit
(requires (fun h -> live h input /\ live h output ))
(ensures (fun h_1 r h_2 -> modifies_1 output h_1 h_2 /\ live h_2 input /\ live h_1 input /\ live h_2 output
/\ live h_2 output
/\ (let s1 = as_seq h_1 input in
let s2 = as_seq h_2 output in
s2 == seq_map f s1) )) | let map #a #b output input l f =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 output /\ live h1 input /\ modifies_1 output h0 h1 /\ i <= UInt32.v l
/\ (forall (j:nat). (j >= i /\ j < UInt32.v l) ==> get h1 output j == get h0 output j)
/\ (forall (j:nat). j < i ==> get h1 output j == f (get h0 input j))
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v l ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
let xi = input.(i) in
output.(i) <- f xi
in
for 0ul l inv f';
let h1 = HST.get() in
Seq.lemma_eq_intro (as_seq h1 output) (seq_map f (as_seq h0 input)) | {
"file_name": "krmllib/compat/C.Compat.Loops.fst",
"git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321",
"git_url": "https://github.com/FStarLang/karamel.git",
"project_name": "karamel"
} | {
"end_col": 69,
"end_line": 237,
"start_col": 0,
"start_line": 221
} | (* This module exposes a series of combinators; they are modeled using
* higher-order functions and specifications, and extracted, using a
* meta-theoretic argument, to actual C loops. *)
module C.Compat.Loops
open FStar.HyperStack.ST
open FStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module UInt32 = FStar.UInt32
module UInt64 = FStar.UInt64
include Spec.Loops
#set-options "--initial_fuel 0 --max_fuel 0 --z3rlimit 20"
(** The functions in this module use the following convention:
* - the first arguments are buffers;
* - the destination buffer comes first, followed by the input buffer (as in
* C's memcpy)
* - each buffer is followed by its length; if several buffers share the same
* length, there is a single length argument after the buffers
* - the function-specific arguments come next (e.g. the number of times one
* may want to call the function in [repeat])
* - the second to last argument is the loop invariant (which may have
* dependencies on all the parameters before)
* - the last argument is the loop body (that will depend on the invariant, and
* possibly all the other parameters before. *)
(* Generic-purpose for-loop combinators ***************************************)
(* These combinators enjoy first-class support in KaRaMeL. (See [combinators] in
* src/Simplify.ml *)
(* Currently extracting as:
for (int i = <start>; i != <finish>; ++i)
<f> i;
*)
val for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish)))
let rec for start finish inv f =
if start = finish then
()
else begin
f start;
for (UInt32.(start +^ 1ul)) finish inv f
end
val for64:
start:UInt64.t ->
finish:UInt64.t{UInt64.v finish >= UInt64.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt64.t{UInt64.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt64.v i)))
(ensures (fun h_1 _ h_2 -> UInt64.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt64.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt64.v finish)))
let rec for64 start finish inv f =
if start = finish then
()
else begin
f start;
for64 (UInt64.(start +^ 1UL)) finish inv f
end
(* To be extracted as:
for (int i = <start>; i != <finish>; --i)
<f> i;
*)
val reverse_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish <= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start >= v i /\ v i > v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i - 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish)))
let rec reverse_for start finish inv f =
if start = finish then
()
else begin
f start;
reverse_for (UInt32.(start -^ 1ul)) finish inv f
end
(* To be extracted as:
bool b = false;
int i = <start>;
for (; (!b) && (i != <end>); ++i) {
b = <f> i;
}
(i, b)
*)
val interruptible_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> bool -> GTot Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack bool
(requires (fun h -> inv h (UInt32.v i) false))
(ensures (fun h_1 b h_2 -> inv h_1 (UInt32.v i) false /\ inv h_2 UInt32.(v i + 1) b)) ) ->
Stack (UInt32.t * bool)
(requires (fun h -> inv h (UInt32.v start) false))
(ensures (fun _ res h_2 -> let (i, b) = res in ((if b then True else i == finish) /\ inv h_2 (UInt32.v i) b)))
let rec interruptible_for start finish inv f =
if start = finish then
(finish, false)
else
let start' = UInt32.(start +^ 1ul) in
if f start
then (start', true)
else interruptible_for start' finish inv f
(* To be extracted as:
while (true) {
bool b = <f> i;
if (b) {
break;
}
}
*)
val do_while:
inv:(HS.mem -> bool -> GTot Type0) ->
f:(unit -> Stack bool
(requires (fun h -> inv h false))
(ensures (fun h_1 b h_2 -> inv h_1 false /\ inv h_2 b)) ) ->
Stack unit
(requires (fun h -> inv h false))
(ensures (fun _ _ h_2 -> inv h_2 true))
let rec do_while inv f =
if not (f ()) then
do_while inv f
(* Extracted as:
while (test ()) {
body ();
}
*)
val while:
#test_pre: (HS.mem -> GTot Type0) ->
#test_post: (bool -> HS.mem -> GTot Type0) ->
$test: (unit -> Stack bool
(requires (fun h -> test_pre h))
(ensures (fun h0 x h1 -> test_post x h1))) ->
body: (unit -> Stack unit
(requires (fun h -> test_post true h))
(ensures (fun h0 _ h1 -> test_pre h1))) ->
Stack unit
(requires (fun h -> test_pre h))
(ensures (fun h0 _ h1 -> test_post false h1))
let rec while #test_pre #test_post test body =
if test () then begin
body ();
while #test_pre #test_post test body
end
(* To be extracted as:
int i = <start>;
bool b = false;
for (; (!b) && (i != <end>); --i) {
b = <f> i;
}
// i and b must be in scope after the loop
*)
val interruptible_reverse_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish <= UInt32.v start} ->
inv:(HS.mem -> nat -> bool -> GTot Type0) ->
f:(i:UInt32.t{UInt32.(v start >= v i /\ v i > v finish)} -> Stack bool
(requires (fun h -> inv h (UInt32.v i) false))
(ensures (fun h_1 b h_2 -> inv h_1 (UInt32.v i) false /\ inv h_2 UInt32.(v i - 1) b)) ) ->
Stack (UInt32.t * bool)
(requires (fun h -> inv h (UInt32.v start) false))
(ensures (fun _ res h_2 -> let (i, b) = res in ((if b then True else i == finish) /\ inv h_2 (UInt32.v i) b)))
let rec interruptible_reverse_for start finish inv f =
if start = finish then
(finish, false)
else
let start' = UInt32.(start -^ 1ul) in
if f start
then (start', true)
else interruptible_reverse_for start' finish inv f
(* Non-primitive combinators that can be expressed in terms of the above ******)
(** Extracts as:
* for (int i = 0; i < <l>; ++i)
* out[i] = <f>(in[i]);
*)
inline_for_extraction
val map:
#a:Type0 -> #b:Type0 ->
output: buffer b ->
input: buffer a{disjoint input output} ->
l: UInt32.t{ UInt32.v l = Buffer.length output /\ UInt32.v l = Buffer.length input } ->
f:(a -> Tot b) ->
Stack unit
(requires (fun h -> live h input /\ live h output ))
(ensures (fun h_1 r h_2 -> modifies_1 output h_1 h_2 /\ live h_2 input /\ live h_1 input /\ live h_2 output
/\ live h_2 output
/\ (let s1 = as_seq h_1 input in
let s2 = as_seq h_2 output in
s2 == seq_map f s1) )) | {
"checked_file": "/",
"dependencies": [
"Spec.Loops.fst.checked",
"prims.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Buffer.fst.checked"
],
"interface_file": false,
"source_file": "C.Compat.Loops.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.Loops",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "UInt64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "UInt32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
output: FStar.Buffer.buffer b ->
input: FStar.Buffer.buffer a {FStar.Buffer.disjoint input output} ->
l:
FStar.UInt32.t
{ FStar.UInt32.v l = FStar.Buffer.length output /\
FStar.UInt32.v l = FStar.Buffer.length input } ->
f: (_: a -> b)
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.Buffer.buffer",
"FStar.Buffer.disjoint",
"FStar.UInt32.t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt32.v",
"FStar.Buffer.length",
"FStar.Seq.Base.lemma_eq_intro",
"FStar.Buffer.as_seq",
"Spec.Loops.seq_map",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"C.Compat.Loops.for",
"FStar.UInt32.__uint_to_t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Addition",
"FStar.Buffer.op_Array_Assignment",
"FStar.Buffer.op_Array_Access",
"Prims.nat",
"FStar.Buffer.live",
"FStar.Buffer.modifies_1",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.eq2",
"FStar.Buffer.get"
] | [] | false | true | false | false | false | let map #a #b output input l f =
| let h0 = HST.get () in
let inv (h1: HS.mem) (i: nat) : Type0 =
live h1 output /\ live h1 input /\ modifies_1 output h0 h1 /\ i <= UInt32.v l /\
(forall (j: nat). (j >= i /\ j < UInt32.v l) ==> get h1 output j == get h0 output j) /\
(forall (j: nat). j < i ==> get h1 output j == f (get h0 input j))
in
let f' (i: UInt32.t{let open UInt32 in 0 <= v i /\ v i < v l})
: Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> let open UInt32 in inv h_2 (v i + 1))) =
let xi = input.(i) in
output.(i) <- f xi
in
for 0ul l inv f';
let h1 = HST.get () in
Seq.lemma_eq_intro (as_seq h1 output) (seq_map f (as_seq h0 input)) | false |
C.Compat.Loops.fst | C.Compat.Loops.map2 | val map2:
#a:Type0 -> #b:Type0 -> #c:Type0 ->
output: buffer c ->
in1: buffer a{disjoint output in1} -> in2: buffer b{disjoint output in2} ->
l: UInt32.t{ UInt32.v l = Buffer.length output /\ UInt32.v l = Buffer.length in1
/\ UInt32.v l = Buffer.length in2 } ->
f:(a -> b -> Tot c) ->
Stack unit
(requires (fun h -> live h in1 /\ live h in2 /\ live h output ))
(ensures (fun h_1 r h_2 -> modifies_1 output h_1 h_2 /\ live h_2 in1 /\ live h_2 in2
/\ live h_1 in1 /\ live h_1 in2 /\ live h_2 output
/\ (let s1 = as_seq h_1 in1 in
let s2 = as_seq h_1 in2 in
let s = as_seq h_2 output in
s == seq_map2 f s1 s2) )) | val map2:
#a:Type0 -> #b:Type0 -> #c:Type0 ->
output: buffer c ->
in1: buffer a{disjoint output in1} -> in2: buffer b{disjoint output in2} ->
l: UInt32.t{ UInt32.v l = Buffer.length output /\ UInt32.v l = Buffer.length in1
/\ UInt32.v l = Buffer.length in2 } ->
f:(a -> b -> Tot c) ->
Stack unit
(requires (fun h -> live h in1 /\ live h in2 /\ live h output ))
(ensures (fun h_1 r h_2 -> modifies_1 output h_1 h_2 /\ live h_2 in1 /\ live h_2 in2
/\ live h_1 in1 /\ live h_1 in2 /\ live h_2 output
/\ (let s1 = as_seq h_1 in1 in
let s2 = as_seq h_1 in2 in
let s = as_seq h_2 output in
s == seq_map2 f s1 s2) )) | let map2 #a #b #c output in1 in2 l f =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 output /\ live h1 in1 /\ live h1 in2 /\ modifies_1 output h0 h1 /\ i <= UInt32.v l
/\ (forall (j:nat). (j >= i /\ j < UInt32.v l) ==> get h1 output j == get h0 output j)
/\ (forall (j:nat). j < i ==> get h1 output j == f (get h0 in1 j) (get h0 in2 j))
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v l ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
let xi = in1.(i) in
let yi = in2.(i) in
output.(i) <- f xi yi
in
for 0ul l inv f';
let h1 = HST.get() in
Seq.lemma_eq_intro (as_seq h1 output) (seq_map2 f (as_seq h0 in1) (as_seq h0 in2)) | {
"file_name": "krmllib/compat/C.Compat.Loops.fst",
"git_rev": "da1e941b2fcb196aa5d1e34941aa00b4c67ac321",
"git_url": "https://github.com/FStarLang/karamel.git",
"project_name": "karamel"
} | {
"end_col": 84,
"end_line": 278,
"start_col": 0,
"start_line": 261
} | (* This module exposes a series of combinators; they are modeled using
* higher-order functions and specifications, and extracted, using a
* meta-theoretic argument, to actual C loops. *)
module C.Compat.Loops
open FStar.HyperStack.ST
open FStar.Buffer
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module UInt32 = FStar.UInt32
module UInt64 = FStar.UInt64
include Spec.Loops
#set-options "--initial_fuel 0 --max_fuel 0 --z3rlimit 20"
(** The functions in this module use the following convention:
* - the first arguments are buffers;
* - the destination buffer comes first, followed by the input buffer (as in
* C's memcpy)
* - each buffer is followed by its length; if several buffers share the same
* length, there is a single length argument after the buffers
* - the function-specific arguments come next (e.g. the number of times one
* may want to call the function in [repeat])
* - the second to last argument is the loop invariant (which may have
* dependencies on all the parameters before)
* - the last argument is the loop body (that will depend on the invariant, and
* possibly all the other parameters before. *)
(* Generic-purpose for-loop combinators ***************************************)
(* These combinators enjoy first-class support in KaRaMeL. (See [combinators] in
* src/Simplify.ml *)
(* Currently extracting as:
for (int i = <start>; i != <finish>; ++i)
<f> i;
*)
val for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish)))
let rec for start finish inv f =
if start = finish then
()
else begin
f start;
for (UInt32.(start +^ 1ul)) finish inv f
end
val for64:
start:UInt64.t ->
finish:UInt64.t{UInt64.v finish >= UInt64.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt64.t{UInt64.(v start <= v i /\ v i < v finish)} -> Stack unit
(requires (fun h -> inv h (UInt64.v i)))
(ensures (fun h_1 _ h_2 -> UInt64.(inv h_1 (v i) /\ inv h_2 (v i + 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt64.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt64.v finish)))
let rec for64 start finish inv f =
if start = finish then
()
else begin
f start;
for64 (UInt64.(start +^ 1UL)) finish inv f
end
(* To be extracted as:
for (int i = <start>; i != <finish>; --i)
<f> i;
*)
val reverse_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish <= UInt32.v start} ->
inv:(HS.mem -> nat -> Type0) ->
f:(i:UInt32.t{UInt32.(v start >= v i /\ v i > v finish)} -> Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_1 (v i) /\ inv h_2 (v i - 1)))) ) ->
Stack unit
(requires (fun h -> inv h (UInt32.v start)))
(ensures (fun _ _ h_2 -> inv h_2 (UInt32.v finish)))
let rec reverse_for start finish inv f =
if start = finish then
()
else begin
f start;
reverse_for (UInt32.(start -^ 1ul)) finish inv f
end
(* To be extracted as:
bool b = false;
int i = <start>;
for (; (!b) && (i != <end>); ++i) {
b = <f> i;
}
(i, b)
*)
val interruptible_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish >= UInt32.v start} ->
inv:(HS.mem -> nat -> bool -> GTot Type0) ->
f:(i:UInt32.t{UInt32.(v start <= v i /\ v i < v finish)} -> Stack bool
(requires (fun h -> inv h (UInt32.v i) false))
(ensures (fun h_1 b h_2 -> inv h_1 (UInt32.v i) false /\ inv h_2 UInt32.(v i + 1) b)) ) ->
Stack (UInt32.t * bool)
(requires (fun h -> inv h (UInt32.v start) false))
(ensures (fun _ res h_2 -> let (i, b) = res in ((if b then True else i == finish) /\ inv h_2 (UInt32.v i) b)))
let rec interruptible_for start finish inv f =
if start = finish then
(finish, false)
else
let start' = UInt32.(start +^ 1ul) in
if f start
then (start', true)
else interruptible_for start' finish inv f
(* To be extracted as:
while (true) {
bool b = <f> i;
if (b) {
break;
}
}
*)
val do_while:
inv:(HS.mem -> bool -> GTot Type0) ->
f:(unit -> Stack bool
(requires (fun h -> inv h false))
(ensures (fun h_1 b h_2 -> inv h_1 false /\ inv h_2 b)) ) ->
Stack unit
(requires (fun h -> inv h false))
(ensures (fun _ _ h_2 -> inv h_2 true))
let rec do_while inv f =
if not (f ()) then
do_while inv f
(* Extracted as:
while (test ()) {
body ();
}
*)
val while:
#test_pre: (HS.mem -> GTot Type0) ->
#test_post: (bool -> HS.mem -> GTot Type0) ->
$test: (unit -> Stack bool
(requires (fun h -> test_pre h))
(ensures (fun h0 x h1 -> test_post x h1))) ->
body: (unit -> Stack unit
(requires (fun h -> test_post true h))
(ensures (fun h0 _ h1 -> test_pre h1))) ->
Stack unit
(requires (fun h -> test_pre h))
(ensures (fun h0 _ h1 -> test_post false h1))
let rec while #test_pre #test_post test body =
if test () then begin
body ();
while #test_pre #test_post test body
end
(* To be extracted as:
int i = <start>;
bool b = false;
for (; (!b) && (i != <end>); --i) {
b = <f> i;
}
// i and b must be in scope after the loop
*)
val interruptible_reverse_for:
start:UInt32.t ->
finish:UInt32.t{UInt32.v finish <= UInt32.v start} ->
inv:(HS.mem -> nat -> bool -> GTot Type0) ->
f:(i:UInt32.t{UInt32.(v start >= v i /\ v i > v finish)} -> Stack bool
(requires (fun h -> inv h (UInt32.v i) false))
(ensures (fun h_1 b h_2 -> inv h_1 (UInt32.v i) false /\ inv h_2 UInt32.(v i - 1) b)) ) ->
Stack (UInt32.t * bool)
(requires (fun h -> inv h (UInt32.v start) false))
(ensures (fun _ res h_2 -> let (i, b) = res in ((if b then True else i == finish) /\ inv h_2 (UInt32.v i) b)))
let rec interruptible_reverse_for start finish inv f =
if start = finish then
(finish, false)
else
let start' = UInt32.(start -^ 1ul) in
if f start
then (start', true)
else interruptible_reverse_for start' finish inv f
(* Non-primitive combinators that can be expressed in terms of the above ******)
(** Extracts as:
* for (int i = 0; i < <l>; ++i)
* out[i] = <f>(in[i]);
*)
inline_for_extraction
val map:
#a:Type0 -> #b:Type0 ->
output: buffer b ->
input: buffer a{disjoint input output} ->
l: UInt32.t{ UInt32.v l = Buffer.length output /\ UInt32.v l = Buffer.length input } ->
f:(a -> Tot b) ->
Stack unit
(requires (fun h -> live h input /\ live h output ))
(ensures (fun h_1 r h_2 -> modifies_1 output h_1 h_2 /\ live h_2 input /\ live h_1 input /\ live h_2 output
/\ live h_2 output
/\ (let s1 = as_seq h_1 input in
let s2 = as_seq h_2 output in
s2 == seq_map f s1) ))
inline_for_extraction
let map #a #b output input l f =
let h0 = HST.get() in
let inv (h1: HS.mem) (i: nat): Type0 =
live h1 output /\ live h1 input /\ modifies_1 output h0 h1 /\ i <= UInt32.v l
/\ (forall (j:nat). (j >= i /\ j < UInt32.v l) ==> get h1 output j == get h0 output j)
/\ (forall (j:nat). j < i ==> get h1 output j == f (get h0 input j))
in
let f' (i:UInt32.t{ UInt32.( 0 <= v i /\ v i < v l ) }): Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> UInt32.(inv h_2 (v i + 1))))
=
let xi = input.(i) in
output.(i) <- f xi
in
for 0ul l inv f';
let h1 = HST.get() in
Seq.lemma_eq_intro (as_seq h1 output) (seq_map f (as_seq h0 input))
(** Extracts as:
* for (int i = 0; i < <l>; ++i)
* out[i] = <f>(in1[i], in2[i]);
*)
inline_for_extraction
val map2:
#a:Type0 -> #b:Type0 -> #c:Type0 ->
output: buffer c ->
in1: buffer a{disjoint output in1} -> in2: buffer b{disjoint output in2} ->
l: UInt32.t{ UInt32.v l = Buffer.length output /\ UInt32.v l = Buffer.length in1
/\ UInt32.v l = Buffer.length in2 } ->
f:(a -> b -> Tot c) ->
Stack unit
(requires (fun h -> live h in1 /\ live h in2 /\ live h output ))
(ensures (fun h_1 r h_2 -> modifies_1 output h_1 h_2 /\ live h_2 in1 /\ live h_2 in2
/\ live h_1 in1 /\ live h_1 in2 /\ live h_2 output
/\ (let s1 = as_seq h_1 in1 in
let s2 = as_seq h_1 in2 in
let s = as_seq h_2 output in
s == seq_map2 f s1 s2) )) | {
"checked_file": "/",
"dependencies": [
"Spec.Loops.fst.checked",
"prims.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Buffer.fst.checked"
],
"interface_file": false,
"source_file": "C.Compat.Loops.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.Loops",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "UInt64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "UInt32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "C.Compat",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 1,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
output: FStar.Buffer.buffer c ->
in1: FStar.Buffer.buffer a {FStar.Buffer.disjoint output in1} ->
in2: FStar.Buffer.buffer b {FStar.Buffer.disjoint output in2} ->
l:
FStar.UInt32.t
{ FStar.UInt32.v l = FStar.Buffer.length output /\
FStar.UInt32.v l = FStar.Buffer.length in1 /\ FStar.UInt32.v l = FStar.Buffer.length in2 } ->
f: (_: a -> _: b -> c)
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.Buffer.buffer",
"FStar.Buffer.disjoint",
"FStar.UInt32.t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt32.v",
"FStar.Buffer.length",
"FStar.Seq.Base.lemma_eq_intro",
"FStar.Buffer.as_seq",
"Spec.Loops.seq_map2",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"C.Compat.Loops.for",
"FStar.UInt32.__uint_to_t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Addition",
"FStar.Buffer.op_Array_Assignment",
"FStar.Buffer.op_Array_Access",
"Prims.nat",
"FStar.Buffer.live",
"FStar.Buffer.modifies_1",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.eq2",
"FStar.Buffer.get"
] | [] | false | true | false | false | false | let map2 #a #b #c output in1 in2 l f =
| let h0 = HST.get () in
let inv (h1: HS.mem) (i: nat) : Type0 =
live h1 output /\ live h1 in1 /\ live h1 in2 /\ modifies_1 output h0 h1 /\ i <= UInt32.v l /\
(forall (j: nat). (j >= i /\ j < UInt32.v l) ==> get h1 output j == get h0 output j) /\
(forall (j: nat). j < i ==> get h1 output j == f (get h0 in1 j) (get h0 in2 j))
in
let f' (i: UInt32.t{let open UInt32 in 0 <= v i /\ v i < v l})
: Stack unit
(requires (fun h -> inv h (UInt32.v i)))
(ensures (fun h_1 _ h_2 -> let open UInt32 in inv h_2 (v i + 1))) =
let xi = in1.(i) in
let yi = in2.(i) in
output.(i) <- f xi yi
in
for 0ul l inv f';
let h1 = HST.get () in
Seq.lemma_eq_intro (as_seq h1 output) (seq_map2 f (as_seq h0 in1) (as_seq h0 in2)) | false |
Spec.AES.Test.fst | Spec.AES.Test.test_counter1 | val test_counter1 : Prims.int | let test_counter1 = 1 | {
"file_name": "specs/tests/Spec.AES.Test.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 21,
"end_line": 62,
"start_col": 0,
"start_line": 62
} | module Spec.AES.Test
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
module PS = Lib.PrintSequence
open Spec.AES
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let test_key : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x2buy; 0x7euy; 0x15uy; 0x16uy; 0x28uy; 0xaeuy; 0xd2uy; 0xa6uy;
0xabuy; 0xf7uy; 0x15uy; 0x88uy; 0x09uy; 0xcfuy; 0x4fuy; 0x3cuy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_nonce : lbytes 12 =
let l = List.Tot.map u8_from_UInt8 [
0xf0uy; 0xf1uy; 0xf2uy; 0xf3uy; 0xf4uy; 0xf5uy; 0xf6uy; 0xf7uy;
0xf8uy; 0xf9uy; 0xfauy; 0xfbuy ] in
assert_norm (List.Tot.length l == 12);
of_list l
let test_counter = 0xfcfdfeff
let test_plaintext : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x6buy; 0xc1uy; 0xbeuy; 0xe2uy; 0x2euy; 0x40uy; 0x9fuy; 0x96uy;
0xe9uy; 0x3duy; 0x7euy; 0x11uy; 0x73uy; 0x93uy; 0x17uy; 0x2auy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_ciphertext : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x87uy; 0x4duy; 0x61uy; 0x91uy; 0xb6uy; 0x20uy; 0xe3uy; 0x26uy;
0x1buy; 0xefuy; 0x68uy; 0x64uy; 0x99uy; 0x0duy; 0xb6uy; 0xceuy ] in
assert_norm (List.Tot.length l == 16);
of_list l
(* From RFC 3686 *)
let test_key1 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0xAEuy; 0x68uy; 0x52uy; 0xF8uy; 0x12uy; 0x10uy; 0x67uy; 0xCCuy;
0x4Buy; 0xF7uy; 0xA5uy; 0x76uy; 0x55uy; 0x77uy; 0xF3uy; 0x9Euy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_nonce1 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x00uy; 0x00uy; 0x00uy; 0x30uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy;
0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy ] in
assert_norm (List.Tot.length l == 16);
of_list l | {
"checked_file": "/",
"dependencies": [
"Spec.AES.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.PrintSequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.Test.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.PrintSequence",
"short_module": "PS"
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"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": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.int | Prims.Tot | [
"total"
] | [] | [] | [] | false | false | false | true | false | let test_counter1 =
| 1 | false |
|
Spec.AES.Test.fst | Spec.AES.Test.test_counter2 | val test_counter2 : Prims.int | let test_counter2 = 1 | {
"file_name": "specs/tests/Spec.AES.Test.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 21,
"end_line": 95,
"start_col": 0,
"start_line": 95
} | module Spec.AES.Test
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
module PS = Lib.PrintSequence
open Spec.AES
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let test_key : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x2buy; 0x7euy; 0x15uy; 0x16uy; 0x28uy; 0xaeuy; 0xd2uy; 0xa6uy;
0xabuy; 0xf7uy; 0x15uy; 0x88uy; 0x09uy; 0xcfuy; 0x4fuy; 0x3cuy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_nonce : lbytes 12 =
let l = List.Tot.map u8_from_UInt8 [
0xf0uy; 0xf1uy; 0xf2uy; 0xf3uy; 0xf4uy; 0xf5uy; 0xf6uy; 0xf7uy;
0xf8uy; 0xf9uy; 0xfauy; 0xfbuy ] in
assert_norm (List.Tot.length l == 12);
of_list l
let test_counter = 0xfcfdfeff
let test_plaintext : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x6buy; 0xc1uy; 0xbeuy; 0xe2uy; 0x2euy; 0x40uy; 0x9fuy; 0x96uy;
0xe9uy; 0x3duy; 0x7euy; 0x11uy; 0x73uy; 0x93uy; 0x17uy; 0x2auy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_ciphertext : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x87uy; 0x4duy; 0x61uy; 0x91uy; 0xb6uy; 0x20uy; 0xe3uy; 0x26uy;
0x1buy; 0xefuy; 0x68uy; 0x64uy; 0x99uy; 0x0duy; 0xb6uy; 0xceuy ] in
assert_norm (List.Tot.length l == 16);
of_list l
(* From RFC 3686 *)
let test_key1 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0xAEuy; 0x68uy; 0x52uy; 0xF8uy; 0x12uy; 0x10uy; 0x67uy; 0xCCuy;
0x4Buy; 0xF7uy; 0xA5uy; 0x76uy; 0x55uy; 0x77uy; 0xF3uy; 0x9Euy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_nonce1 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x00uy; 0x00uy; 0x00uy; 0x30uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy;
0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_counter1 = 1
let test_plaintext1 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x53uy; 0x69uy; 0x6Euy; 0x67uy; 0x6Cuy; 0x65uy; 0x20uy; 0x62uy;
0x6Cuy; 0x6Fuy; 0x63uy; 0x6Buy; 0x20uy; 0x6Duy; 0x73uy; 0x67uy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_ciphertext1 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0xE4uy; 0x09uy; 0x5Duy; 0x4Fuy; 0xB7uy; 0xA7uy; 0xB3uy; 0x79uy;
0x2Duy; 0x61uy; 0x75uy; 0xA3uy; 0x26uy; 0x13uy; 0x11uy; 0xB8uy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_key2 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x7Euy; 0x24uy; 0x06uy; 0x78uy; 0x17uy; 0xFAuy; 0xE0uy; 0xD7uy;
0x43uy; 0xD6uy; 0xCEuy; 0x1Fuy; 0x32uy; 0x53uy; 0x91uy; 0x63uy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_nonce2 : lbytes 12 =
let l = List.Tot.map u8_from_UInt8 [
0x00uy; 0x6Cuy; 0xB6uy; 0xDBuy; 0xC0uy; 0x54uy; 0x3Buy; 0x59uy;
0xDAuy; 0x48uy; 0xD9uy; 0x0Buy ] in
assert_norm (List.Tot.length l == 12);
of_list l | {
"checked_file": "/",
"dependencies": [
"Spec.AES.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.PrintSequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.Test.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.PrintSequence",
"short_module": "PS"
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"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": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.int | Prims.Tot | [
"total"
] | [] | [] | [] | false | false | false | true | false | let test_counter2 =
| 1 | false |
|
Spec.AES.Test.fst | Spec.AES.Test.test_plaintext | val test_plaintext:lbytes 16 | val test_plaintext:lbytes 16 | let test_plaintext : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x6buy; 0xc1uy; 0xbeuy; 0xe2uy; 0x2euy; 0x40uy; 0x9fuy; 0x96uy;
0xe9uy; 0x3duy; 0x7euy; 0x11uy; 0x73uy; 0x93uy; 0x17uy; 0x2auy ] in
assert_norm (List.Tot.length l == 16);
of_list l | {
"file_name": "specs/tests/Spec.AES.Test.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 36,
"start_col": 0,
"start_line": 31
} | module Spec.AES.Test
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
module PS = Lib.PrintSequence
open Spec.AES
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let test_key : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x2buy; 0x7euy; 0x15uy; 0x16uy; 0x28uy; 0xaeuy; 0xd2uy; 0xa6uy;
0xabuy; 0xf7uy; 0x15uy; 0x88uy; 0x09uy; 0xcfuy; 0x4fuy; 0x3cuy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_nonce : lbytes 12 =
let l = List.Tot.map u8_from_UInt8 [
0xf0uy; 0xf1uy; 0xf2uy; 0xf3uy; 0xf4uy; 0xf5uy; 0xf6uy; 0xf7uy;
0xf8uy; 0xf9uy; 0xfauy; 0xfbuy ] in
assert_norm (List.Tot.length l == 12);
of_list l
let test_counter = 0xfcfdfeff | {
"checked_file": "/",
"dependencies": [
"Spec.AES.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.PrintSequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.Test.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.PrintSequence",
"short_module": "PS"
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"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": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Lib.Sequence.lseq (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) 16 | Prims.Tot | [
"total"
] | [] | [
"Lib.Sequence.of_list",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"FStar.List.Tot.Base.length",
"Prims.list",
"FStar.List.Tot.Base.map",
"FStar.UInt8.t",
"Lib.RawIntTypes.u8_from_UInt8",
"Prims.Cons",
"FStar.UInt8.__uint_to_t",
"Prims.Nil"
] | [] | false | false | false | false | false | let test_plaintext:lbytes 16 =
| let l =
List.Tot.map u8_from_UInt8
[
0x6buy; 0xc1uy; 0xbeuy; 0xe2uy; 0x2euy; 0x40uy; 0x9fuy; 0x96uy; 0xe9uy; 0x3duy; 0x7euy; 0x11uy;
0x73uy; 0x93uy; 0x17uy; 0x2auy
]
in
assert_norm (List.Tot.length l == 16);
of_list l | false |
Spec.AES.Test.fst | Spec.AES.Test.test_nonce | val test_nonce:lbytes 12 | val test_nonce:lbytes 12 | let test_nonce : lbytes 12 =
let l = List.Tot.map u8_from_UInt8 [
0xf0uy; 0xf1uy; 0xf2uy; 0xf3uy; 0xf4uy; 0xf5uy; 0xf6uy; 0xf7uy;
0xf8uy; 0xf9uy; 0xfauy; 0xfbuy ] in
assert_norm (List.Tot.length l == 12);
of_list l | {
"file_name": "specs/tests/Spec.AES.Test.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 27,
"start_col": 0,
"start_line": 22
} | module Spec.AES.Test
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
module PS = Lib.PrintSequence
open Spec.AES
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let test_key : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x2buy; 0x7euy; 0x15uy; 0x16uy; 0x28uy; 0xaeuy; 0xd2uy; 0xa6uy;
0xabuy; 0xf7uy; 0x15uy; 0x88uy; 0x09uy; 0xcfuy; 0x4fuy; 0x3cuy ] in
assert_norm (List.Tot.length l == 16);
of_list l | {
"checked_file": "/",
"dependencies": [
"Spec.AES.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.PrintSequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.Test.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.PrintSequence",
"short_module": "PS"
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"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": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Lib.Sequence.lseq (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) 12 | Prims.Tot | [
"total"
] | [] | [
"Lib.Sequence.of_list",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"FStar.List.Tot.Base.length",
"Prims.list",
"FStar.List.Tot.Base.map",
"FStar.UInt8.t",
"Lib.RawIntTypes.u8_from_UInt8",
"Prims.Cons",
"FStar.UInt8.__uint_to_t",
"Prims.Nil"
] | [] | false | false | false | false | false | let test_nonce:lbytes 12 =
| let l =
List.Tot.map u8_from_UInt8
[0xf0uy; 0xf1uy; 0xf2uy; 0xf3uy; 0xf4uy; 0xf5uy; 0xf6uy; 0xf7uy; 0xf8uy; 0xf9uy; 0xfauy; 0xfbuy]
in
assert_norm (List.Tot.length l == 12);
of_list l | false |
Spec.AES.Test.fst | Spec.AES.Test.test_key | val test_key:lbytes 16 | val test_key:lbytes 16 | let test_key : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x2buy; 0x7euy; 0x15uy; 0x16uy; 0x28uy; 0xaeuy; 0xd2uy; 0xa6uy;
0xabuy; 0xf7uy; 0x15uy; 0x88uy; 0x09uy; 0xcfuy; 0x4fuy; 0x3cuy ] in
assert_norm (List.Tot.length l == 16);
of_list l | {
"file_name": "specs/tests/Spec.AES.Test.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 19,
"start_col": 0,
"start_line": 14
} | module Spec.AES.Test
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
module PS = Lib.PrintSequence
open Spec.AES
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0" | {
"checked_file": "/",
"dependencies": [
"Spec.AES.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.PrintSequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.Test.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.PrintSequence",
"short_module": "PS"
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"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": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Lib.Sequence.lseq (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) 16 | Prims.Tot | [
"total"
] | [] | [
"Lib.Sequence.of_list",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"FStar.List.Tot.Base.length",
"Prims.list",
"FStar.List.Tot.Base.map",
"FStar.UInt8.t",
"Lib.RawIntTypes.u8_from_UInt8",
"Prims.Cons",
"FStar.UInt8.__uint_to_t",
"Prims.Nil"
] | [] | false | false | false | false | false | let test_key:lbytes 16 =
| let l =
List.Tot.map u8_from_UInt8
[
0x2buy; 0x7euy; 0x15uy; 0x16uy; 0x28uy; 0xaeuy; 0xd2uy; 0xa6uy; 0xabuy; 0xf7uy; 0x15uy; 0x88uy;
0x09uy; 0xcfuy; 0x4fuy; 0x3cuy
]
in
assert_norm (List.Tot.length l == 16);
of_list l | false |
Spec.AES.Test.fst | Spec.AES.Test.test_ciphertext | val test_ciphertext:lbytes 16 | val test_ciphertext:lbytes 16 | let test_ciphertext : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x87uy; 0x4duy; 0x61uy; 0x91uy; 0xb6uy; 0x20uy; 0xe3uy; 0x26uy;
0x1buy; 0xefuy; 0x68uy; 0x64uy; 0x99uy; 0x0duy; 0xb6uy; 0xceuy ] in
assert_norm (List.Tot.length l == 16);
of_list l | {
"file_name": "specs/tests/Spec.AES.Test.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 44,
"start_col": 0,
"start_line": 39
} | module Spec.AES.Test
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
module PS = Lib.PrintSequence
open Spec.AES
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let test_key : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x2buy; 0x7euy; 0x15uy; 0x16uy; 0x28uy; 0xaeuy; 0xd2uy; 0xa6uy;
0xabuy; 0xf7uy; 0x15uy; 0x88uy; 0x09uy; 0xcfuy; 0x4fuy; 0x3cuy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_nonce : lbytes 12 =
let l = List.Tot.map u8_from_UInt8 [
0xf0uy; 0xf1uy; 0xf2uy; 0xf3uy; 0xf4uy; 0xf5uy; 0xf6uy; 0xf7uy;
0xf8uy; 0xf9uy; 0xfauy; 0xfbuy ] in
assert_norm (List.Tot.length l == 12);
of_list l
let test_counter = 0xfcfdfeff
let test_plaintext : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x6buy; 0xc1uy; 0xbeuy; 0xe2uy; 0x2euy; 0x40uy; 0x9fuy; 0x96uy;
0xe9uy; 0x3duy; 0x7euy; 0x11uy; 0x73uy; 0x93uy; 0x17uy; 0x2auy ] in
assert_norm (List.Tot.length l == 16);
of_list l | {
"checked_file": "/",
"dependencies": [
"Spec.AES.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.PrintSequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.Test.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.PrintSequence",
"short_module": "PS"
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"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": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Lib.Sequence.lseq (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) 16 | Prims.Tot | [
"total"
] | [] | [
"Lib.Sequence.of_list",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"FStar.List.Tot.Base.length",
"Prims.list",
"FStar.List.Tot.Base.map",
"FStar.UInt8.t",
"Lib.RawIntTypes.u8_from_UInt8",
"Prims.Cons",
"FStar.UInt8.__uint_to_t",
"Prims.Nil"
] | [] | false | false | false | false | false | let test_ciphertext:lbytes 16 =
| let l =
List.Tot.map u8_from_UInt8
[
0x87uy; 0x4duy; 0x61uy; 0x91uy; 0xb6uy; 0x20uy; 0xe3uy; 0x26uy; 0x1buy; 0xefuy; 0x68uy; 0x64uy;
0x99uy; 0x0duy; 0xb6uy; 0xceuy
]
in
assert_norm (List.Tot.length l == 16);
of_list l | false |
Spec.AES.Test.fst | Spec.AES.Test.test_key1 | val test_key1:lbytes 16 | val test_key1:lbytes 16 | let test_key1 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0xAEuy; 0x68uy; 0x52uy; 0xF8uy; 0x12uy; 0x10uy; 0x67uy; 0xCCuy;
0x4Buy; 0xF7uy; 0xA5uy; 0x76uy; 0x55uy; 0x77uy; 0xF3uy; 0x9Euy ] in
assert_norm (List.Tot.length l == 16);
of_list l | {
"file_name": "specs/tests/Spec.AES.Test.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 52,
"start_col": 0,
"start_line": 47
} | module Spec.AES.Test
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
module PS = Lib.PrintSequence
open Spec.AES
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let test_key : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x2buy; 0x7euy; 0x15uy; 0x16uy; 0x28uy; 0xaeuy; 0xd2uy; 0xa6uy;
0xabuy; 0xf7uy; 0x15uy; 0x88uy; 0x09uy; 0xcfuy; 0x4fuy; 0x3cuy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_nonce : lbytes 12 =
let l = List.Tot.map u8_from_UInt8 [
0xf0uy; 0xf1uy; 0xf2uy; 0xf3uy; 0xf4uy; 0xf5uy; 0xf6uy; 0xf7uy;
0xf8uy; 0xf9uy; 0xfauy; 0xfbuy ] in
assert_norm (List.Tot.length l == 12);
of_list l
let test_counter = 0xfcfdfeff
let test_plaintext : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x6buy; 0xc1uy; 0xbeuy; 0xe2uy; 0x2euy; 0x40uy; 0x9fuy; 0x96uy;
0xe9uy; 0x3duy; 0x7euy; 0x11uy; 0x73uy; 0x93uy; 0x17uy; 0x2auy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_ciphertext : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x87uy; 0x4duy; 0x61uy; 0x91uy; 0xb6uy; 0x20uy; 0xe3uy; 0x26uy;
0x1buy; 0xefuy; 0x68uy; 0x64uy; 0x99uy; 0x0duy; 0xb6uy; 0xceuy ] in
assert_norm (List.Tot.length l == 16);
of_list l | {
"checked_file": "/",
"dependencies": [
"Spec.AES.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.PrintSequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.Test.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.PrintSequence",
"short_module": "PS"
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"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": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Lib.Sequence.lseq (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) 16 | Prims.Tot | [
"total"
] | [] | [
"Lib.Sequence.of_list",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"FStar.List.Tot.Base.length",
"Prims.list",
"FStar.List.Tot.Base.map",
"FStar.UInt8.t",
"Lib.RawIntTypes.u8_from_UInt8",
"Prims.Cons",
"FStar.UInt8.__uint_to_t",
"Prims.Nil"
] | [] | false | false | false | false | false | let test_key1:lbytes 16 =
| let l =
List.Tot.map u8_from_UInt8
[
0xAEuy; 0x68uy; 0x52uy; 0xF8uy; 0x12uy; 0x10uy; 0x67uy; 0xCCuy; 0x4Buy; 0xF7uy; 0xA5uy; 0x76uy;
0x55uy; 0x77uy; 0xF3uy; 0x9Euy
]
in
assert_norm (List.Tot.length l == 16);
of_list l | false |
Spec.AES.Test.fst | Spec.AES.Test.test_key2 | val test_key2:lbytes 16 | val test_key2:lbytes 16 | let test_key2 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x7Euy; 0x24uy; 0x06uy; 0x78uy; 0x17uy; 0xFAuy; 0xE0uy; 0xD7uy;
0x43uy; 0xD6uy; 0xCEuy; 0x1Fuy; 0x32uy; 0x53uy; 0x91uy; 0x63uy ] in
assert_norm (List.Tot.length l == 16);
of_list l | {
"file_name": "specs/tests/Spec.AES.Test.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 85,
"start_col": 0,
"start_line": 80
} | module Spec.AES.Test
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
module PS = Lib.PrintSequence
open Spec.AES
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let test_key : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x2buy; 0x7euy; 0x15uy; 0x16uy; 0x28uy; 0xaeuy; 0xd2uy; 0xa6uy;
0xabuy; 0xf7uy; 0x15uy; 0x88uy; 0x09uy; 0xcfuy; 0x4fuy; 0x3cuy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_nonce : lbytes 12 =
let l = List.Tot.map u8_from_UInt8 [
0xf0uy; 0xf1uy; 0xf2uy; 0xf3uy; 0xf4uy; 0xf5uy; 0xf6uy; 0xf7uy;
0xf8uy; 0xf9uy; 0xfauy; 0xfbuy ] in
assert_norm (List.Tot.length l == 12);
of_list l
let test_counter = 0xfcfdfeff
let test_plaintext : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x6buy; 0xc1uy; 0xbeuy; 0xe2uy; 0x2euy; 0x40uy; 0x9fuy; 0x96uy;
0xe9uy; 0x3duy; 0x7euy; 0x11uy; 0x73uy; 0x93uy; 0x17uy; 0x2auy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_ciphertext : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x87uy; 0x4duy; 0x61uy; 0x91uy; 0xb6uy; 0x20uy; 0xe3uy; 0x26uy;
0x1buy; 0xefuy; 0x68uy; 0x64uy; 0x99uy; 0x0duy; 0xb6uy; 0xceuy ] in
assert_norm (List.Tot.length l == 16);
of_list l
(* From RFC 3686 *)
let test_key1 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0xAEuy; 0x68uy; 0x52uy; 0xF8uy; 0x12uy; 0x10uy; 0x67uy; 0xCCuy;
0x4Buy; 0xF7uy; 0xA5uy; 0x76uy; 0x55uy; 0x77uy; 0xF3uy; 0x9Euy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_nonce1 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x00uy; 0x00uy; 0x00uy; 0x30uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy;
0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_counter1 = 1
let test_plaintext1 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x53uy; 0x69uy; 0x6Euy; 0x67uy; 0x6Cuy; 0x65uy; 0x20uy; 0x62uy;
0x6Cuy; 0x6Fuy; 0x63uy; 0x6Buy; 0x20uy; 0x6Duy; 0x73uy; 0x67uy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_ciphertext1 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0xE4uy; 0x09uy; 0x5Duy; 0x4Fuy; 0xB7uy; 0xA7uy; 0xB3uy; 0x79uy;
0x2Duy; 0x61uy; 0x75uy; 0xA3uy; 0x26uy; 0x13uy; 0x11uy; 0xB8uy ] in
assert_norm (List.Tot.length l == 16);
of_list l | {
"checked_file": "/",
"dependencies": [
"Spec.AES.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.PrintSequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.Test.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.PrintSequence",
"short_module": "PS"
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"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": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Lib.Sequence.lseq (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) 16 | Prims.Tot | [
"total"
] | [] | [
"Lib.Sequence.of_list",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"FStar.List.Tot.Base.length",
"Prims.list",
"FStar.List.Tot.Base.map",
"FStar.UInt8.t",
"Lib.RawIntTypes.u8_from_UInt8",
"Prims.Cons",
"FStar.UInt8.__uint_to_t",
"Prims.Nil"
] | [] | false | false | false | false | false | let test_key2:lbytes 16 =
| let l =
List.Tot.map u8_from_UInt8
[
0x7Euy; 0x24uy; 0x06uy; 0x78uy; 0x17uy; 0xFAuy; 0xE0uy; 0xD7uy; 0x43uy; 0xD6uy; 0xCEuy; 0x1Fuy;
0x32uy; 0x53uy; 0x91uy; 0x63uy
]
in
assert_norm (List.Tot.length l == 16);
of_list l | false |
Spec.AES.Test.fst | Spec.AES.Test.test_nonce1 | val test_nonce1:lbytes 16 | val test_nonce1:lbytes 16 | let test_nonce1 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x00uy; 0x00uy; 0x00uy; 0x30uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy;
0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy ] in
assert_norm (List.Tot.length l == 16);
of_list l | {
"file_name": "specs/tests/Spec.AES.Test.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 60,
"start_col": 0,
"start_line": 55
} | module Spec.AES.Test
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
module PS = Lib.PrintSequence
open Spec.AES
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let test_key : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x2buy; 0x7euy; 0x15uy; 0x16uy; 0x28uy; 0xaeuy; 0xd2uy; 0xa6uy;
0xabuy; 0xf7uy; 0x15uy; 0x88uy; 0x09uy; 0xcfuy; 0x4fuy; 0x3cuy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_nonce : lbytes 12 =
let l = List.Tot.map u8_from_UInt8 [
0xf0uy; 0xf1uy; 0xf2uy; 0xf3uy; 0xf4uy; 0xf5uy; 0xf6uy; 0xf7uy;
0xf8uy; 0xf9uy; 0xfauy; 0xfbuy ] in
assert_norm (List.Tot.length l == 12);
of_list l
let test_counter = 0xfcfdfeff
let test_plaintext : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x6buy; 0xc1uy; 0xbeuy; 0xe2uy; 0x2euy; 0x40uy; 0x9fuy; 0x96uy;
0xe9uy; 0x3duy; 0x7euy; 0x11uy; 0x73uy; 0x93uy; 0x17uy; 0x2auy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_ciphertext : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x87uy; 0x4duy; 0x61uy; 0x91uy; 0xb6uy; 0x20uy; 0xe3uy; 0x26uy;
0x1buy; 0xefuy; 0x68uy; 0x64uy; 0x99uy; 0x0duy; 0xb6uy; 0xceuy ] in
assert_norm (List.Tot.length l == 16);
of_list l
(* From RFC 3686 *)
let test_key1 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0xAEuy; 0x68uy; 0x52uy; 0xF8uy; 0x12uy; 0x10uy; 0x67uy; 0xCCuy;
0x4Buy; 0xF7uy; 0xA5uy; 0x76uy; 0x55uy; 0x77uy; 0xF3uy; 0x9Euy ] in
assert_norm (List.Tot.length l == 16);
of_list l | {
"checked_file": "/",
"dependencies": [
"Spec.AES.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.PrintSequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.Test.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.PrintSequence",
"short_module": "PS"
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"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": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Lib.Sequence.lseq (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) 16 | Prims.Tot | [
"total"
] | [] | [
"Lib.Sequence.of_list",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"FStar.List.Tot.Base.length",
"Prims.list",
"FStar.List.Tot.Base.map",
"FStar.UInt8.t",
"Lib.RawIntTypes.u8_from_UInt8",
"Prims.Cons",
"FStar.UInt8.__uint_to_t",
"Prims.Nil"
] | [] | false | false | false | false | false | let test_nonce1:lbytes 16 =
| let l =
List.Tot.map u8_from_UInt8
[
0x00uy; 0x00uy; 0x00uy; 0x30uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy;
0x00uy; 0x00uy; 0x00uy; 0x00uy
]
in
assert_norm (List.Tot.length l == 16);
of_list l | false |
Spec.AES.Test.fst | Spec.AES.Test.test_nonce2 | val test_nonce2:lbytes 12 | val test_nonce2:lbytes 12 | let test_nonce2 : lbytes 12 =
let l = List.Tot.map u8_from_UInt8 [
0x00uy; 0x6Cuy; 0xB6uy; 0xDBuy; 0xC0uy; 0x54uy; 0x3Buy; 0x59uy;
0xDAuy; 0x48uy; 0xD9uy; 0x0Buy ] in
assert_norm (List.Tot.length l == 12);
of_list l | {
"file_name": "specs/tests/Spec.AES.Test.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 93,
"start_col": 0,
"start_line": 88
} | module Spec.AES.Test
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
module PS = Lib.PrintSequence
open Spec.AES
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let test_key : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x2buy; 0x7euy; 0x15uy; 0x16uy; 0x28uy; 0xaeuy; 0xd2uy; 0xa6uy;
0xabuy; 0xf7uy; 0x15uy; 0x88uy; 0x09uy; 0xcfuy; 0x4fuy; 0x3cuy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_nonce : lbytes 12 =
let l = List.Tot.map u8_from_UInt8 [
0xf0uy; 0xf1uy; 0xf2uy; 0xf3uy; 0xf4uy; 0xf5uy; 0xf6uy; 0xf7uy;
0xf8uy; 0xf9uy; 0xfauy; 0xfbuy ] in
assert_norm (List.Tot.length l == 12);
of_list l
let test_counter = 0xfcfdfeff
let test_plaintext : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x6buy; 0xc1uy; 0xbeuy; 0xe2uy; 0x2euy; 0x40uy; 0x9fuy; 0x96uy;
0xe9uy; 0x3duy; 0x7euy; 0x11uy; 0x73uy; 0x93uy; 0x17uy; 0x2auy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_ciphertext : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x87uy; 0x4duy; 0x61uy; 0x91uy; 0xb6uy; 0x20uy; 0xe3uy; 0x26uy;
0x1buy; 0xefuy; 0x68uy; 0x64uy; 0x99uy; 0x0duy; 0xb6uy; 0xceuy ] in
assert_norm (List.Tot.length l == 16);
of_list l
(* From RFC 3686 *)
let test_key1 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0xAEuy; 0x68uy; 0x52uy; 0xF8uy; 0x12uy; 0x10uy; 0x67uy; 0xCCuy;
0x4Buy; 0xF7uy; 0xA5uy; 0x76uy; 0x55uy; 0x77uy; 0xF3uy; 0x9Euy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_nonce1 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x00uy; 0x00uy; 0x00uy; 0x30uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy;
0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_counter1 = 1
let test_plaintext1 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x53uy; 0x69uy; 0x6Euy; 0x67uy; 0x6Cuy; 0x65uy; 0x20uy; 0x62uy;
0x6Cuy; 0x6Fuy; 0x63uy; 0x6Buy; 0x20uy; 0x6Duy; 0x73uy; 0x67uy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_ciphertext1 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0xE4uy; 0x09uy; 0x5Duy; 0x4Fuy; 0xB7uy; 0xA7uy; 0xB3uy; 0x79uy;
0x2Duy; 0x61uy; 0x75uy; 0xA3uy; 0x26uy; 0x13uy; 0x11uy; 0xB8uy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_key2 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x7Euy; 0x24uy; 0x06uy; 0x78uy; 0x17uy; 0xFAuy; 0xE0uy; 0xD7uy;
0x43uy; 0xD6uy; 0xCEuy; 0x1Fuy; 0x32uy; 0x53uy; 0x91uy; 0x63uy ] in
assert_norm (List.Tot.length l == 16);
of_list l | {
"checked_file": "/",
"dependencies": [
"Spec.AES.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.PrintSequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.Test.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.PrintSequence",
"short_module": "PS"
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"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": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Lib.Sequence.lseq (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) 12 | Prims.Tot | [
"total"
] | [] | [
"Lib.Sequence.of_list",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"FStar.List.Tot.Base.length",
"Prims.list",
"FStar.List.Tot.Base.map",
"FStar.UInt8.t",
"Lib.RawIntTypes.u8_from_UInt8",
"Prims.Cons",
"FStar.UInt8.__uint_to_t",
"Prims.Nil"
] | [] | false | false | false | false | false | let test_nonce2:lbytes 12 =
| let l =
List.Tot.map u8_from_UInt8
[0x00uy; 0x6Cuy; 0xB6uy; 0xDBuy; 0xC0uy; 0x54uy; 0x3Buy; 0x59uy; 0xDAuy; 0x48uy; 0xD9uy; 0x0Buy]
in
assert_norm (List.Tot.length l == 12);
of_list l | false |
Spec.AES.Test.fst | Spec.AES.Test.test2_key_block | val test2_key_block:lbytes 16 | val test2_key_block:lbytes 16 | let test2_key_block : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0xffuy; 0xffuy; 0xffuy; 0xffuy; 0xffuy; 0xf0uy; 0x00uy; 0x00uy;
0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy ] in
assert_norm (List.Tot.length l == 16);
of_list l | {
"file_name": "specs/tests/Spec.AES.Test.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 146,
"start_col": 0,
"start_line": 141
} | module Spec.AES.Test
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
module PS = Lib.PrintSequence
open Spec.AES
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let test_key : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x2buy; 0x7euy; 0x15uy; 0x16uy; 0x28uy; 0xaeuy; 0xd2uy; 0xa6uy;
0xabuy; 0xf7uy; 0x15uy; 0x88uy; 0x09uy; 0xcfuy; 0x4fuy; 0x3cuy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_nonce : lbytes 12 =
let l = List.Tot.map u8_from_UInt8 [
0xf0uy; 0xf1uy; 0xf2uy; 0xf3uy; 0xf4uy; 0xf5uy; 0xf6uy; 0xf7uy;
0xf8uy; 0xf9uy; 0xfauy; 0xfbuy ] in
assert_norm (List.Tot.length l == 12);
of_list l
let test_counter = 0xfcfdfeff
let test_plaintext : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x6buy; 0xc1uy; 0xbeuy; 0xe2uy; 0x2euy; 0x40uy; 0x9fuy; 0x96uy;
0xe9uy; 0x3duy; 0x7euy; 0x11uy; 0x73uy; 0x93uy; 0x17uy; 0x2auy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_ciphertext : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x87uy; 0x4duy; 0x61uy; 0x91uy; 0xb6uy; 0x20uy; 0xe3uy; 0x26uy;
0x1buy; 0xefuy; 0x68uy; 0x64uy; 0x99uy; 0x0duy; 0xb6uy; 0xceuy ] in
assert_norm (List.Tot.length l == 16);
of_list l
(* From RFC 3686 *)
let test_key1 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0xAEuy; 0x68uy; 0x52uy; 0xF8uy; 0x12uy; 0x10uy; 0x67uy; 0xCCuy;
0x4Buy; 0xF7uy; 0xA5uy; 0x76uy; 0x55uy; 0x77uy; 0xF3uy; 0x9Euy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_nonce1 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x00uy; 0x00uy; 0x00uy; 0x30uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy;
0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_counter1 = 1
let test_plaintext1 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x53uy; 0x69uy; 0x6Euy; 0x67uy; 0x6Cuy; 0x65uy; 0x20uy; 0x62uy;
0x6Cuy; 0x6Fuy; 0x63uy; 0x6Buy; 0x20uy; 0x6Duy; 0x73uy; 0x67uy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_ciphertext1 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0xE4uy; 0x09uy; 0x5Duy; 0x4Fuy; 0xB7uy; 0xA7uy; 0xB3uy; 0x79uy;
0x2Duy; 0x61uy; 0x75uy; 0xA3uy; 0x26uy; 0x13uy; 0x11uy; 0xB8uy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_key2 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x7Euy; 0x24uy; 0x06uy; 0x78uy; 0x17uy; 0xFAuy; 0xE0uy; 0xD7uy;
0x43uy; 0xD6uy; 0xCEuy; 0x1Fuy; 0x32uy; 0x53uy; 0x91uy; 0x63uy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_nonce2 : lbytes 12 =
let l = List.Tot.map u8_from_UInt8 [
0x00uy; 0x6Cuy; 0xB6uy; 0xDBuy; 0xC0uy; 0x54uy; 0x3Buy; 0x59uy;
0xDAuy; 0x48uy; 0xD9uy; 0x0Buy ] in
assert_norm (List.Tot.length l == 12);
of_list l
let test_counter2 = 1
let test_plaintext2 : lbytes 32 =
let l = List.Tot.map u8_from_UInt8 [
0x00uy; 0x01uy; 0x02uy; 0x03uy; 0x04uy; 0x05uy; 0x06uy; 0x07uy;
0x08uy; 0x09uy; 0x0Auy; 0x0Buy; 0x0Cuy; 0x0Duy; 0x0Euy; 0x0Fuy;
0x10uy; 0x11uy; 0x12uy; 0x13uy; 0x14uy; 0x15uy; 0x16uy; 0x17uy;
0x18uy; 0x19uy; 0x1Auy; 0x1Buy; 0x1Cuy; 0x1Duy; 0x1Euy; 0x1Fuy ] in
assert_norm (List.Tot.length l == 32);
of_list l
let test_ciphertext2 : lbytes 32 =
let l = List.Tot.map u8_from_UInt8 [
0x51uy; 0x04uy; 0xA1uy; 0x06uy; 0x16uy; 0x8Auy; 0x72uy; 0xD9uy;
0x79uy; 0x0Duy; 0x41uy; 0xEEuy; 0x8Euy; 0xDAuy; 0xD3uy; 0x88uy;
0xEBuy; 0x2Euy; 0x1Euy; 0xFCuy; 0x46uy; 0xDAuy; 0x57uy; 0xC8uy;
0xFCuy; 0xE6uy; 0x30uy; 0xDFuy; 0x91uy; 0x41uy; 0xBEuy; 0x28uy ] in
assert_norm (List.Tot.length l == 32);
of_list l
let test1_key_block : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x80uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy;
0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test1_plaintext_block : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy;
0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test1_ciphertext_block : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x0euy; 0xdduy; 0x33uy; 0xd3uy; 0xc6uy; 0x21uy; 0xe5uy; 0x46uy;
0x45uy; 0x5buy; 0xd8uy; 0xbauy; 0x14uy; 0x18uy; 0xbeuy; 0xc8uy ] in
assert_norm (List.Tot.length l == 16);
of_list l | {
"checked_file": "/",
"dependencies": [
"Spec.AES.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.PrintSequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.Test.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.PrintSequence",
"short_module": "PS"
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"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": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Lib.Sequence.lseq (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) 16 | Prims.Tot | [
"total"
] | [] | [
"Lib.Sequence.of_list",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"FStar.List.Tot.Base.length",
"Prims.list",
"FStar.List.Tot.Base.map",
"FStar.UInt8.t",
"Lib.RawIntTypes.u8_from_UInt8",
"Prims.Cons",
"FStar.UInt8.__uint_to_t",
"Prims.Nil"
] | [] | false | false | false | false | false | let test2_key_block:lbytes 16 =
| let l =
List.Tot.map u8_from_UInt8
[
0xffuy; 0xffuy; 0xffuy; 0xffuy; 0xffuy; 0xf0uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy;
0x00uy; 0x00uy; 0x00uy; 0x00uy
]
in
assert_norm (List.Tot.length l == 16);
of_list l | false |
Spec.AES.Test.fst | Spec.AES.Test.test_ciphertext1 | val test_ciphertext1:lbytes 16 | val test_ciphertext1:lbytes 16 | let test_ciphertext1 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0xE4uy; 0x09uy; 0x5Duy; 0x4Fuy; 0xB7uy; 0xA7uy; 0xB3uy; 0x79uy;
0x2Duy; 0x61uy; 0x75uy; 0xA3uy; 0x26uy; 0x13uy; 0x11uy; 0xB8uy ] in
assert_norm (List.Tot.length l == 16);
of_list l | {
"file_name": "specs/tests/Spec.AES.Test.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 77,
"start_col": 0,
"start_line": 72
} | module Spec.AES.Test
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
module PS = Lib.PrintSequence
open Spec.AES
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let test_key : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x2buy; 0x7euy; 0x15uy; 0x16uy; 0x28uy; 0xaeuy; 0xd2uy; 0xa6uy;
0xabuy; 0xf7uy; 0x15uy; 0x88uy; 0x09uy; 0xcfuy; 0x4fuy; 0x3cuy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_nonce : lbytes 12 =
let l = List.Tot.map u8_from_UInt8 [
0xf0uy; 0xf1uy; 0xf2uy; 0xf3uy; 0xf4uy; 0xf5uy; 0xf6uy; 0xf7uy;
0xf8uy; 0xf9uy; 0xfauy; 0xfbuy ] in
assert_norm (List.Tot.length l == 12);
of_list l
let test_counter = 0xfcfdfeff
let test_plaintext : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x6buy; 0xc1uy; 0xbeuy; 0xe2uy; 0x2euy; 0x40uy; 0x9fuy; 0x96uy;
0xe9uy; 0x3duy; 0x7euy; 0x11uy; 0x73uy; 0x93uy; 0x17uy; 0x2auy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_ciphertext : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x87uy; 0x4duy; 0x61uy; 0x91uy; 0xb6uy; 0x20uy; 0xe3uy; 0x26uy;
0x1buy; 0xefuy; 0x68uy; 0x64uy; 0x99uy; 0x0duy; 0xb6uy; 0xceuy ] in
assert_norm (List.Tot.length l == 16);
of_list l
(* From RFC 3686 *)
let test_key1 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0xAEuy; 0x68uy; 0x52uy; 0xF8uy; 0x12uy; 0x10uy; 0x67uy; 0xCCuy;
0x4Buy; 0xF7uy; 0xA5uy; 0x76uy; 0x55uy; 0x77uy; 0xF3uy; 0x9Euy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_nonce1 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x00uy; 0x00uy; 0x00uy; 0x30uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy;
0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy; 0x00uy ] in
assert_norm (List.Tot.length l == 16);
of_list l
let test_counter1 = 1
let test_plaintext1 : lbytes 16 =
let l = List.Tot.map u8_from_UInt8 [
0x53uy; 0x69uy; 0x6Euy; 0x67uy; 0x6Cuy; 0x65uy; 0x20uy; 0x62uy;
0x6Cuy; 0x6Fuy; 0x63uy; 0x6Buy; 0x20uy; 0x6Duy; 0x73uy; 0x67uy ] in
assert_norm (List.Tot.length l == 16);
of_list l | {
"checked_file": "/",
"dependencies": [
"Spec.AES.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.PrintSequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked"
],
"interface_file": false,
"source_file": "Spec.AES.Test.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.PrintSequence",
"short_module": "PS"
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"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": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Lib.Sequence.lseq (Lib.IntTypes.int_t Lib.IntTypes.U8 Lib.IntTypes.SEC) 16 | Prims.Tot | [
"total"
] | [] | [
"Lib.Sequence.of_list",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"FStar.List.Tot.Base.length",
"Prims.list",
"FStar.List.Tot.Base.map",
"FStar.UInt8.t",
"Lib.RawIntTypes.u8_from_UInt8",
"Prims.Cons",
"FStar.UInt8.__uint_to_t",
"Prims.Nil"
] | [] | false | false | false | false | false | let test_ciphertext1:lbytes 16 =
| let l =
List.Tot.map u8_from_UInt8
[
0xE4uy; 0x09uy; 0x5Duy; 0x4Fuy; 0xB7uy; 0xA7uy; 0xB3uy; 0x79uy; 0x2Duy; 0x61uy; 0x75uy; 0xA3uy;
0x26uy; 0x13uy; 0x11uy; 0xB8uy
]
in
assert_norm (List.Tot.length l == 16);
of_list l | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.