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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
LowStar.PrefixFreezableBuffer.fsti | LowStar.PrefixFreezableBuffer.malloc_pre | val malloc_pre : r: FStar.Monotonic.HyperHeap.rid -> len: LowStar.PrefixFreezableBuffer.u32 -> Prims.logical | let malloc_pre (r:HS.rid) (len:u32) =
UInt.size (U32.v len + 4) 32 /\ malloc_pre r len | {
"file_name": "ulib/LowStar.PrefixFreezableBuffer.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 50,
"end_line": 121,
"start_col": 7,
"start_line": 120
} | (*
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 LowStar.PrefixFreezableBuffer
open FStar.HyperStack.ST
include LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
(*
* A library for prefix freezable buffers of elements of type u8
*
* Our monotonicity theory does not easily support preorders and predicates over
* multiple references. So instead of keeping the frozen-until counter in a
* separate (ghost) reference, the library maintains the frozen-until counter (a u32)
* in the first four bytes of the buffer itself
*
* Buffer contents up to the frozen-until counter are stable and clients can witness
* and recall them
*
*)
type u8 = UInt8.t
type u32 = U32.t
#set-options "--max_fuel 0 --max_ifuel 0"
/// This is the frozen until index in the sequence representation of a PrefixFreezableBuffer
val le_to_n (s:Seq.seq u8) : Tot nat
let frozen_until (s:Seq.seq u8{Seq.length s >= 4}) = le_to_n (Seq.slice s 0 4)
/// Preorder for PrefixFreezableBuffers
private unfold let pre (s1 s2:Seq.seq u8) =
Seq.length s1 == Seq.length s2 /\ //lengths are same
(let len = Seq.length s1 in
len >= 4 ==> //if length >= 4 then
(let frozen_until1 = frozen_until s1 in
let frozen_until2 = frozen_until s2 in
(4 <= frozen_until1 /\ frozen_until1 <= len) ==> //if frozen_until1 is in the range [4, len] then
(frozen_until1 <= frozen_until2 /\ frozen_until2 <= len /\ //frozen until index increases monotonically, but remains <= len
(forall (i:nat).{:pattern Seq.index s2 i}
(4 <= i /\ i < frozen_until1) ==> Seq.index s2 i == Seq.index s1 i)))) //and the contents until frozen_until1 remain same
val prefix_freezable_preorder : srel u8
/// Clients can call the following lemma to reveal the preorder
val prefix_freezable_preorder_elim (s1 s2:Seq.seq u8)
: Lemma (prefix_freezable_preorder s1 s2 <==> pre s1 s2)
/// Predicate for the frozen_until index being at least n
///
/// It is stable w.r.t. the prefix_freezable_preorder
let frozen_until_at_least (n:nat) : spred u8 =
fun s -> Seq.length s >= 4 /\ //it follows from the inequalities below, but we need it for typing of frozen_until
4 <= n /\ n <= frozen_until s /\ frozen_until s <= Seq.length s
/// Predicate for the frozen slice with indices in the [4, frozen_until) range
///
/// It is stable w.r.t. the prefix_freezable_preorder
let slice_is (i j:u32) (snap:G.erased (Seq.seq u8)) : spred u8 =
fun s -> let len = Seq.length s in len >= 4 /\ //for typing of frozen_until
(let frozen_until = frozen_until s in
let i = U32.v i in
let j = U32.v j in
let snap = G.reveal snap in
4 <= i /\ i <= j /\ j <= frozen_until /\ frozen_until <= len /\
Seq.length snap == j - i /\
Seq.equal (Seq.slice s i j) snap)
/// Buffer type for PrefixfreezableBuffers
///
/// And abbreviation for the length indexed version
type buffer =
b:mbuffer u8 (prefix_freezable_preorder) (prefix_freezable_preorder)
{length b >= 4 /\ b `witnessed` frozen_until_at_least 4}
unfold let lbuffer (len:u32) =
b:buffer{length b == U32.v len + 4}
/// Allocation precondition for prefix freezable buffers adds an additional constraint
/// that the input length + 4 must fit in u32 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.PrefixFreezableBuffer.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: FStar.Monotonic.HyperHeap.rid -> len: LowStar.PrefixFreezableBuffer.u32 -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.HyperHeap.rid",
"LowStar.PrefixFreezableBuffer.u32",
"Prims.l_and",
"FStar.UInt.size",
"Prims.op_Addition",
"FStar.UInt32.v",
"LowStar.Monotonic.Buffer.malloc_pre",
"Prims.logical"
] | [] | false | false | false | true | true | let malloc_pre (r: HS.rid) (len: u32) =
| UInt.size (U32.v len + 4) 32 /\ malloc_pre r len | false |
|
LowStar.PrefixFreezableBuffer.fsti | LowStar.PrefixFreezableBuffer.alloca_pre | val alloca_pre : len: FStar.UInt32.t -> Prims.logical | let alloca_pre (len:U32.t) = //precondition for stack allocated prefix freezable buffers
UInt.size (U32.v len + 4) 32 /\ alloca_pre len | {
"file_name": "ulib/LowStar.PrefixFreezableBuffer.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 48,
"end_line": 151,
"start_col": 7,
"start_line": 150
} | (*
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 LowStar.PrefixFreezableBuffer
open FStar.HyperStack.ST
include LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
(*
* A library for prefix freezable buffers of elements of type u8
*
* Our monotonicity theory does not easily support preorders and predicates over
* multiple references. So instead of keeping the frozen-until counter in a
* separate (ghost) reference, the library maintains the frozen-until counter (a u32)
* in the first four bytes of the buffer itself
*
* Buffer contents up to the frozen-until counter are stable and clients can witness
* and recall them
*
*)
type u8 = UInt8.t
type u32 = U32.t
#set-options "--max_fuel 0 --max_ifuel 0"
/// This is the frozen until index in the sequence representation of a PrefixFreezableBuffer
val le_to_n (s:Seq.seq u8) : Tot nat
let frozen_until (s:Seq.seq u8{Seq.length s >= 4}) = le_to_n (Seq.slice s 0 4)
/// Preorder for PrefixFreezableBuffers
private unfold let pre (s1 s2:Seq.seq u8) =
Seq.length s1 == Seq.length s2 /\ //lengths are same
(let len = Seq.length s1 in
len >= 4 ==> //if length >= 4 then
(let frozen_until1 = frozen_until s1 in
let frozen_until2 = frozen_until s2 in
(4 <= frozen_until1 /\ frozen_until1 <= len) ==> //if frozen_until1 is in the range [4, len] then
(frozen_until1 <= frozen_until2 /\ frozen_until2 <= len /\ //frozen until index increases monotonically, but remains <= len
(forall (i:nat).{:pattern Seq.index s2 i}
(4 <= i /\ i < frozen_until1) ==> Seq.index s2 i == Seq.index s1 i)))) //and the contents until frozen_until1 remain same
val prefix_freezable_preorder : srel u8
/// Clients can call the following lemma to reveal the preorder
val prefix_freezable_preorder_elim (s1 s2:Seq.seq u8)
: Lemma (prefix_freezable_preorder s1 s2 <==> pre s1 s2)
/// Predicate for the frozen_until index being at least n
///
/// It is stable w.r.t. the prefix_freezable_preorder
let frozen_until_at_least (n:nat) : spred u8 =
fun s -> Seq.length s >= 4 /\ //it follows from the inequalities below, but we need it for typing of frozen_until
4 <= n /\ n <= frozen_until s /\ frozen_until s <= Seq.length s
/// Predicate for the frozen slice with indices in the [4, frozen_until) range
///
/// It is stable w.r.t. the prefix_freezable_preorder
let slice_is (i j:u32) (snap:G.erased (Seq.seq u8)) : spred u8 =
fun s -> let len = Seq.length s in len >= 4 /\ //for typing of frozen_until
(let frozen_until = frozen_until s in
let i = U32.v i in
let j = U32.v j in
let snap = G.reveal snap in
4 <= i /\ i <= j /\ j <= frozen_until /\ frozen_until <= len /\
Seq.length snap == j - i /\
Seq.equal (Seq.slice s i j) snap)
/// Buffer type for PrefixfreezableBuffers
///
/// And abbreviation for the length indexed version
type buffer =
b:mbuffer u8 (prefix_freezable_preorder) (prefix_freezable_preorder)
{length b >= 4 /\ b `witnessed` frozen_until_at_least 4}
unfold let lbuffer (len:u32) =
b:buffer{length b == U32.v len + 4}
/// Allocation precondition for prefix freezable buffers adds an additional constraint
/// that the input length + 4 must fit in u32
unfold let malloc_pre (r:HS.rid) (len:u32) =
UInt.size (U32.v len + 4) 32 /\ malloc_pre r len
/// The postcondition is also different in that there is no initializer
/// and an additional predicate for the initial value of the frozen_until_index
unfold let alloc_post_mem_common
(h0:HS.mem) (b:buffer) (h1:HS.mem)
= live h1 b /\
unused_in b h0 /\
Map.domain (HS.get_hmap h1) `Set.equal` Map.domain (HS.get_hmap h0) /\
HS.get_tip h1 == HS.get_tip h0 /\
modifies loc_none h0 h1 /\
frozen_until (as_seq h1 b) == 4
/// Allocation functions
val gcmalloc (r:HS.rid) (len:u32)
: ST (b:lbuffer len{frameOf b == r /\ recallable b})
(requires fun _ -> malloc_pre r len)
(ensures alloc_post_mem_common)
val malloc (r:HS.rid) (len:u32)
: ST
(b:lbuffer len{frameOf b == r /\ freeable b})
(requires fun _ -> malloc_pre r len)
(ensures alloc_post_mem_common) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.PrefixFreezableBuffer.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | len: FStar.UInt32.t -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.t",
"Prims.l_and",
"FStar.UInt.size",
"Prims.op_Addition",
"FStar.UInt32.v",
"Prims.b2t",
"LowStar.Monotonic.Buffer.alloca_pre",
"Prims.logical"
] | [] | false | false | false | true | true | let alloca_pre (len: U32.t) =
| UInt.size (U32.v len + 4) 32 /\ alloca_pre len | false |
|
Steel.ST.HigherArray.fst | Steel.ST.HigherArray.free0 | val free0 (#elt: Type) (#s: Ghost.erased (Seq.seq elt)) (a: array elt)
: ST unit
(pts_to a P.full_perm s)
(fun _ -> emp)
(length a == base_len (base (ptr_of a)))
(fun _ -> True) | val free0 (#elt: Type) (#s: Ghost.erased (Seq.seq elt)) (a: array elt)
: ST unit
(pts_to a P.full_perm s)
(fun _ -> emp)
(length a == base_len (base (ptr_of a)))
(fun _ -> True) | let free0
(#elt: Type)
(#s: Ghost.erased (Seq.seq elt))
(a: array elt)
: ST unit
(pts_to a P.full_perm s)
(fun _ -> emp)
(
length a == base_len (base (ptr_of a))
)
(fun _ -> True)
= drop (pts_to a _ _) | {
"file_name": "lib/steel/Steel.ST.HigherArray.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 21,
"end_line": 311,
"start_col": 0,
"start_line": 300
} | (*
Copyright 2022 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.ST.HigherArray
module P = Steel.PCMFrac
module R = Steel.ST.PCMReference
module M = FStar.Map
module PM = Steel.PCMMap
[@@noextract_to "krml"]
let index_t (len: Ghost.erased nat) : Tot Type0 =
(i: nat { i < len })
[@@noextract_to "krml"]
let carrier (elt: Type u#a) (len: Ghost.erased nat) : Tot Type =
PM.map (index_t len) (P.fractional elt)
[@@noextract_to "krml"]
let pcm (elt: Type u#a) (len: Ghost.erased nat) : Tot (P.pcm (carrier elt len)) =
PM.pointwise (index_t len) (P.pcm_frac #elt)
[@@noextract_to "krml"]
let one (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.one
let composable (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.composable
[@@noextract_to "krml"]
let compose (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.op
[@@noextract_to "krml"]
let mk_carrier
(#elt: Type)
(len: nat)
(offset: nat)
(s: Seq.seq elt)
(p: P.perm)
: Tot (carrier elt len)
= let f (i: nat) : Tot (P.fractional elt) =
if offset + Seq.length s > len || i < offset || i >= offset + Seq.length s
then None
else Some (Seq.index s (i - offset), p)
in
M.map_literal f
let mk_carrier_inj
(#elt: Type)
(len: nat)
(offset: nat)
(s1 s2: Seq.seq elt)
(p1 p2: P.perm)
: Lemma
(requires (
mk_carrier len offset s1 p1 == mk_carrier len offset s2 p2 /\
offset + Seq.length s1 <= len /\
offset + Seq.length s2 <= len
))
(ensures (
s1 `Seq.equal` s2 /\
(Seq.length s1 > 0 ==> p1 == p2)
))
= assert (forall (i: nat) . i < Seq.length s1 ==>
(M.sel (mk_carrier len offset s1 p1) (offset + i) == Some (Seq.index s1 i, p1)));
assert (forall (i: nat) . i < Seq.length s2 ==>
M.sel (mk_carrier len offset s2 p2) (offset + i) == Some (Seq.index s2 i, p2))
[@@erasable]
let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: US.t & ref _ (pcm elt (US.v base_len)))
let base_len (#elt: Type) (b: base_t elt) : GTot nat = US.v (dfst b)
[@@noextract_to "krml"]
noeq
type ptr (elt: Type u#a) : Type0 = {
base_len: Ghost.erased US.t;
// U32.t to prove that A.read, A.write offset computation does not overflow. TODO: replace U32.t with size_t
base: (r: ref _ (pcm elt (US.v base_len)) { core_ref_is_null r ==> US.v base_len == 0 });
offset: (offset: nat { offset <= US.v base_len });
}
let null_ptr a = { base_len = 0sz; base = null #_ #(pcm a 0) ; offset = 0 }
let is_null_ptr p = is_null p.base
let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |)
let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset
let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma
(requires (
base p1 == base p2 /\
offset p1 == offset p2
))
(ensures (
p1 == p2
))
= ()
let base_len_null_ptr _ = ()
let length_fits #elt a = ()
let valid_perm
(len: nat)
(offset: nat)
(slice_len: nat)
(p: P.perm) : Tot prop =
let open FStar.Real in
((offset + slice_len <= len /\ slice_len > 0) ==> (p.P.v <=. one))
[@__reduce__]
let pts_to0 (#elt: Type u#1) (a: array elt) (p: P.perm) (s: Seq.seq elt) : Tot vprop =
R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p) `star`
pure (
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\
Seq.length s == length a
)
let pts_to (#elt: Type u#1) (a: array elt) ([@@@ smt_fallback ] p: P.perm) ([@@@ smt_fallback ] s: Seq.seq elt) : Tot vprop =
pts_to0 a p s
// this lemma is necessary because Steel.PCMReference is marked unfold
let change_r_pts_to
(#opened: _)
(#carrier: Type u#1)
(#pcm: P.pcm carrier)
(p: ref carrier pcm)
(v: carrier)
(#carrier': Type u#1)
(#pcm': P.pcm carrier')
(p': ref carrier' pcm')
(v': carrier')
: STGhost unit opened
(R.pts_to p v)
(fun _ -> R.pts_to p' v')
(// keep on distinct lines for error messages
carrier == carrier' /\
pcm == pcm' /\
p == p' /\
v == v')
(fun _ -> True)
= rewrite
(R.pts_to p v)
(R.pts_to p' v')
let intro_pts_to (#opened: _) (#elt: Type u#1) (a: array elt) (#v: _) (p: P.perm) (s: Seq.seq elt) : STGhost unit opened
(R.pts_to (ptr_of a).base v)
(fun _ -> pts_to a p s)
(
v == mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p /\
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\
Seq.length s == length a
)
(fun _ -> True)
= change_r_pts_to (ptr_of a).base v (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p);
intro_pure _;
rewrite
(pts_to0 a p s)
(pts_to a p s)
let elim_pts_to (#opened: _) (#elt: Type u#1) (a: array elt) (p: P.perm) (s: Seq.seq elt) : STGhost unit opened
(pts_to a p s)
(fun _ -> R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p))
(True)
(fun _ ->
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\
Seq.length s == length a
)
= rewrite
(pts_to a p s)
(pts_to0 a p s);
elim_pure _
let pts_to_length
a s
=
elim_pts_to a _ s;
intro_pts_to a _ s
let pts_to_not_null
a s
= elim_pts_to a _ s;
R.pts_to_not_null _ _;
intro_pts_to a _ s
let mk_carrier_joinable
(#elt: Type)
(len: nat)
(offset: nat)
(s1: Seq.seq elt)
(p1: P.perm)
(s2: Seq.seq elt)
(p2: P.perm)
: Lemma
(requires (
offset + Seq.length s1 <= len /\
Seq.length s1 == Seq.length s2 /\
P.joinable (pcm elt len) (mk_carrier len offset s1 p1) (mk_carrier len offset s2 p2)
))
(ensures (
s1 `Seq.equal` s2
))
=
let lem
(i: nat { 0 <= i /\ i < Seq.length s1 })
: Lemma
(Seq.index s1 i == Seq.index s2 i)
[SMTPat (Seq.index s1 i); SMTPat (Seq.index s2 i)]
= assert (
forall z . (
P.compatible (pcm elt len) (mk_carrier len offset s1 p1) z /\
P.compatible (pcm elt len) (mk_carrier len offset s2 p2) z
) ==>
begin match M.sel z (offset + i) with
| None -> False
| Some (v, _) -> v == Seq.index s1 i /\ v == Seq.index s2 i
end
)
in
()
let pure_star_interp' (p:slprop u#a) (q:prop) (m:mem)
: Lemma (interp (p `Steel.Memory.star` Steel.Memory.pure q) m <==>
interp p m /\ q)
= pure_star_interp p q m;
emp_unit p
let pts_to_inj
a p1 s1 p2 s2 m
=
Classical.forall_intro reveal_pure;
pure_star_interp'
(hp_of (R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s1 p1)))
(
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s1) p1 /\
Seq.length s1 == length a
)
m;
pure_star_interp'
(hp_of (R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s2 p2)))
(
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s2) p2 /\
Seq.length s2 == length a
)
m;
pts_to_join
(ptr_of a).base
(mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s1 p1)
(mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s2 p2)
m;
mk_carrier_joinable (US.v (ptr_of a).base_len) (ptr_of a).offset s1 p1 s2 p2
[@@noextract_to "krml"]
let malloc0
(#elt: Type)
(x: elt)
(n: US.t)
: ST (array elt)
emp
(fun a -> pts_to a P.full_perm (Seq.create (US.v n) x))
(True)
(fun a ->
length a == US.v n /\
base_len (base (ptr_of a)) == US.v n
)
=
let c : carrier elt (US.v n) = mk_carrier (US.v n) 0 (Seq.create (US.v n) x) P.full_perm in
let base : ref (carrier elt (US.v n)) (pcm elt (US.v n)) = R.alloc c in
R.pts_to_not_null base _;
let p = {
base_len = n;
base = base;
offset = 0;
}
in
let a = (| p, Ghost.hide (US.v n) |) in
change_r_pts_to
base c
(ptr_of a).base c;
intro_pts_to a P.full_perm (Seq.create (US.v n) x);
return a
let malloc_ptr
x n
=
let a = malloc0 x n in
let (| p, _ |) = a in
rewrite
(pts_to _ _ _)
(pts_to (| p, Ghost.hide (US.v n) |) _ _);
return p | {
"checked_file": "/",
"dependencies": [
"Steel.ST.PCMReference.fsti.checked",
"Steel.ST.Loops.fsti.checked",
"Steel.PCMMap.fst.checked",
"Steel.PCMFrac.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.HigherArray.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.PCMMap",
"short_module": "PM"
},
{
"abbrev": true,
"full_module": "FStar.Map",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Steel.ST.PCMReference",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "Steel.PCMFrac",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Steel.ST.HigherArray.array elt -> Steel.ST.Effect.ST Prims.unit | Steel.ST.Effect.ST | [] | [] | [
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Steel.ST.HigherArray.array",
"Steel.ST.Util.drop",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.ST.HigherArray.pts_to",
"Steel.FractionalPermission.full_perm",
"FStar.Ghost.reveal",
"Prims.unit",
"Steel.Effect.Common.emp",
"Steel.Effect.Common.vprop",
"Prims.eq2",
"Prims.nat",
"Steel.ST.HigherArray.length",
"Steel.ST.HigherArray.base_len",
"Steel.ST.HigherArray.base",
"Steel.ST.HigherArray.ptr_of",
"Prims.l_True"
] | [] | false | true | false | false | false | let free0 (#elt: Type) (#s: Ghost.erased (Seq.seq elt)) (a: array elt)
: ST unit
(pts_to a P.full_perm s)
(fun _ -> emp)
(length a == base_len (base (ptr_of a)))
(fun _ -> True) =
| drop (pts_to a _ _) | false |
LowStar.PrefixFreezableBuffer.fsti | LowStar.PrefixFreezableBuffer.frozen_until | val frozen_until : s: FStar.Seq.Base.seq LowStar.PrefixFreezableBuffer.u8 {FStar.Seq.Base.length s >= 4} -> Prims.nat | let frozen_until (s:Seq.seq u8{Seq.length s >= 4}) = le_to_n (Seq.slice s 0 4) | {
"file_name": "ulib/LowStar.PrefixFreezableBuffer.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 78,
"end_line": 55,
"start_col": 0,
"start_line": 55
} | (*
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 LowStar.PrefixFreezableBuffer
open FStar.HyperStack.ST
include LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
(*
* A library for prefix freezable buffers of elements of type u8
*
* Our monotonicity theory does not easily support preorders and predicates over
* multiple references. So instead of keeping the frozen-until counter in a
* separate (ghost) reference, the library maintains the frozen-until counter (a u32)
* in the first four bytes of the buffer itself
*
* Buffer contents up to the frozen-until counter are stable and clients can witness
* and recall them
*
*)
type u8 = UInt8.t
type u32 = U32.t
#set-options "--max_fuel 0 --max_ifuel 0"
/// This is the frozen until index in the sequence representation of a PrefixFreezableBuffer
val le_to_n (s:Seq.seq u8) : Tot nat | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.PrefixFreezableBuffer.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq LowStar.PrefixFreezableBuffer.u8 {FStar.Seq.Base.length s >= 4} -> Prims.nat | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.seq",
"LowStar.PrefixFreezableBuffer.u8",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.Seq.Base.length",
"LowStar.PrefixFreezableBuffer.le_to_n",
"FStar.Seq.Base.slice",
"Prims.nat"
] | [] | false | false | false | false | false | let frozen_until (s: Seq.seq u8 {Seq.length s >= 4}) =
| le_to_n (Seq.slice s 0 4) | false |
|
LowStar.PrefixFreezableBuffer.fsti | LowStar.PrefixFreezableBuffer.pre | val pre : s1: FStar.Seq.Base.seq LowStar.PrefixFreezableBuffer.u8 ->
s2: FStar.Seq.Base.seq LowStar.PrefixFreezableBuffer.u8
-> Prims.logical | let pre (s1 s2:Seq.seq u8) =
Seq.length s1 == Seq.length s2 /\ //lengths are same
(let len = Seq.length s1 in
len >= 4 ==> //if length >= 4 then
(let frozen_until1 = frozen_until s1 in
let frozen_until2 = frozen_until s2 in
(4 <= frozen_until1 /\ frozen_until1 <= len) ==> //if frozen_until1 is in the range [4, len] then
(frozen_until1 <= frozen_until2 /\ frozen_until2 <= len /\ //frozen until index increases monotonically, but remains <= len
(forall (i:nat).{:pattern Seq.index s2 i}
(4 <= i /\ i < frozen_until1) ==> Seq.index s2 i == Seq.index s1 i)))) | {
"file_name": "ulib/LowStar.PrefixFreezableBuffer.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 78,
"end_line": 69,
"start_col": 15,
"start_line": 60
} | (*
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 LowStar.PrefixFreezableBuffer
open FStar.HyperStack.ST
include LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
(*
* A library for prefix freezable buffers of elements of type u8
*
* Our monotonicity theory does not easily support preorders and predicates over
* multiple references. So instead of keeping the frozen-until counter in a
* separate (ghost) reference, the library maintains the frozen-until counter (a u32)
* in the first four bytes of the buffer itself
*
* Buffer contents up to the frozen-until counter are stable and clients can witness
* and recall them
*
*)
type u8 = UInt8.t
type u32 = U32.t
#set-options "--max_fuel 0 --max_ifuel 0"
/// This is the frozen until index in the sequence representation of a PrefixFreezableBuffer
val le_to_n (s:Seq.seq u8) : Tot nat
let frozen_until (s:Seq.seq u8{Seq.length s >= 4}) = le_to_n (Seq.slice s 0 4)
/// Preorder for PrefixFreezableBuffers | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.PrefixFreezableBuffer.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s1: FStar.Seq.Base.seq LowStar.PrefixFreezableBuffer.u8 ->
s2: FStar.Seq.Base.seq LowStar.PrefixFreezableBuffer.u8
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.seq",
"LowStar.PrefixFreezableBuffer.u8",
"Prims.l_and",
"Prims.eq2",
"Prims.nat",
"FStar.Seq.Base.length",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThanOrEqual",
"Prims.l_Forall",
"Prims.op_LessThan",
"FStar.Seq.Base.index",
"LowStar.PrefixFreezableBuffer.frozen_until",
"Prims.logical"
] | [] | false | false | false | true | true | let pre (s1 s2: Seq.seq u8) =
| Seq.length s1 == Seq.length s2 /\
(let len = Seq.length s1 in
len >= 4 ==>
(let frozen_until1 = frozen_until s1 in
let frozen_until2 = frozen_until s2 in
(4 <= frozen_until1 /\ frozen_until1 <= len) ==>
(frozen_until1 <= frozen_until2 /\ frozen_until2 <= len /\
(forall (i: nat). {:pattern Seq.index s2 i}
(4 <= i /\ i < frozen_until1) ==> Seq.index s2 i == Seq.index s1 i)))) | false |
|
LowStar.PrefixFreezableBuffer.fsti | LowStar.PrefixFreezableBuffer.frozen_until_at_least | val frozen_until_at_least (n: nat) : spred u8 | val frozen_until_at_least (n: nat) : spred u8 | let frozen_until_at_least (n:nat) : spred u8 =
fun s -> Seq.length s >= 4 /\ //it follows from the inequalities below, but we need it for typing of frozen_until
4 <= n /\ n <= frozen_until s /\ frozen_until s <= Seq.length s | {
"file_name": "ulib/LowStar.PrefixFreezableBuffer.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 65,
"end_line": 87,
"start_col": 0,
"start_line": 84
} | (*
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 LowStar.PrefixFreezableBuffer
open FStar.HyperStack.ST
include LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
(*
* A library for prefix freezable buffers of elements of type u8
*
* Our monotonicity theory does not easily support preorders and predicates over
* multiple references. So instead of keeping the frozen-until counter in a
* separate (ghost) reference, the library maintains the frozen-until counter (a u32)
* in the first four bytes of the buffer itself
*
* Buffer contents up to the frozen-until counter are stable and clients can witness
* and recall them
*
*)
type u8 = UInt8.t
type u32 = U32.t
#set-options "--max_fuel 0 --max_ifuel 0"
/// This is the frozen until index in the sequence representation of a PrefixFreezableBuffer
val le_to_n (s:Seq.seq u8) : Tot nat
let frozen_until (s:Seq.seq u8{Seq.length s >= 4}) = le_to_n (Seq.slice s 0 4)
/// Preorder for PrefixFreezableBuffers
private unfold let pre (s1 s2:Seq.seq u8) =
Seq.length s1 == Seq.length s2 /\ //lengths are same
(let len = Seq.length s1 in
len >= 4 ==> //if length >= 4 then
(let frozen_until1 = frozen_until s1 in
let frozen_until2 = frozen_until s2 in
(4 <= frozen_until1 /\ frozen_until1 <= len) ==> //if frozen_until1 is in the range [4, len] then
(frozen_until1 <= frozen_until2 /\ frozen_until2 <= len /\ //frozen until index increases monotonically, but remains <= len
(forall (i:nat).{:pattern Seq.index s2 i}
(4 <= i /\ i < frozen_until1) ==> Seq.index s2 i == Seq.index s1 i)))) //and the contents until frozen_until1 remain same
val prefix_freezable_preorder : srel u8
/// Clients can call the following lemma to reveal the preorder
val prefix_freezable_preorder_elim (s1 s2:Seq.seq u8)
: Lemma (prefix_freezable_preorder s1 s2 <==> pre s1 s2)
/// Predicate for the frozen_until index being at least n
///
/// It is stable w.r.t. the prefix_freezable_preorder | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.PrefixFreezableBuffer.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Prims.nat -> LowStar.Monotonic.Buffer.spred LowStar.PrefixFreezableBuffer.u8 | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"FStar.Seq.Base.seq",
"LowStar.PrefixFreezableBuffer.u8",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.Seq.Base.length",
"Prims.op_LessThanOrEqual",
"LowStar.PrefixFreezableBuffer.frozen_until",
"LowStar.Monotonic.Buffer.spred"
] | [] | false | false | false | true | false | let frozen_until_at_least (n: nat) : spred u8 =
| fun s -> Seq.length s >= 4 /\ 4 <= n /\ n <= frozen_until s /\ frozen_until s <= Seq.length s | false |
Steel.ST.HigherArray.fst | Steel.ST.HigherArray.change_r_pts_to | val change_r_pts_to
(#opened: _)
(#carrier: Type u#1)
(#pcm: P.pcm carrier)
(p: ref carrier pcm)
(v: carrier)
(#carrier': Type u#1)
(#pcm': P.pcm carrier')
(p': ref carrier' pcm')
(v': carrier')
: STGhost unit
opened
(R.pts_to p v)
(fun _ -> R.pts_to p' v')
(carrier == carrier' /\ pcm == pcm' /\ p == p' /\ v == v')
(fun _ -> True) | val change_r_pts_to
(#opened: _)
(#carrier: Type u#1)
(#pcm: P.pcm carrier)
(p: ref carrier pcm)
(v: carrier)
(#carrier': Type u#1)
(#pcm': P.pcm carrier')
(p': ref carrier' pcm')
(v': carrier')
: STGhost unit
opened
(R.pts_to p v)
(fun _ -> R.pts_to p' v')
(carrier == carrier' /\ pcm == pcm' /\ p == p' /\ v == v')
(fun _ -> True) | let change_r_pts_to
(#opened: _)
(#carrier: Type u#1)
(#pcm: P.pcm carrier)
(p: ref carrier pcm)
(v: carrier)
(#carrier': Type u#1)
(#pcm': P.pcm carrier')
(p': ref carrier' pcm')
(v': carrier')
: STGhost unit opened
(R.pts_to p v)
(fun _ -> R.pts_to p' v')
(// keep on distinct lines for error messages
carrier == carrier' /\
pcm == pcm' /\
p == p' /\
v == v')
(fun _ -> True)
= rewrite
(R.pts_to p v)
(R.pts_to p' v') | {
"file_name": "lib/steel/Steel.ST.HigherArray.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 20,
"end_line": 150,
"start_col": 0,
"start_line": 129
} | (*
Copyright 2022 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.ST.HigherArray
module P = Steel.PCMFrac
module R = Steel.ST.PCMReference
module M = FStar.Map
module PM = Steel.PCMMap
[@@noextract_to "krml"]
let index_t (len: Ghost.erased nat) : Tot Type0 =
(i: nat { i < len })
[@@noextract_to "krml"]
let carrier (elt: Type u#a) (len: Ghost.erased nat) : Tot Type =
PM.map (index_t len) (P.fractional elt)
[@@noextract_to "krml"]
let pcm (elt: Type u#a) (len: Ghost.erased nat) : Tot (P.pcm (carrier elt len)) =
PM.pointwise (index_t len) (P.pcm_frac #elt)
[@@noextract_to "krml"]
let one (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.one
let composable (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.composable
[@@noextract_to "krml"]
let compose (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.op
[@@noextract_to "krml"]
let mk_carrier
(#elt: Type)
(len: nat)
(offset: nat)
(s: Seq.seq elt)
(p: P.perm)
: Tot (carrier elt len)
= let f (i: nat) : Tot (P.fractional elt) =
if offset + Seq.length s > len || i < offset || i >= offset + Seq.length s
then None
else Some (Seq.index s (i - offset), p)
in
M.map_literal f
let mk_carrier_inj
(#elt: Type)
(len: nat)
(offset: nat)
(s1 s2: Seq.seq elt)
(p1 p2: P.perm)
: Lemma
(requires (
mk_carrier len offset s1 p1 == mk_carrier len offset s2 p2 /\
offset + Seq.length s1 <= len /\
offset + Seq.length s2 <= len
))
(ensures (
s1 `Seq.equal` s2 /\
(Seq.length s1 > 0 ==> p1 == p2)
))
= assert (forall (i: nat) . i < Seq.length s1 ==>
(M.sel (mk_carrier len offset s1 p1) (offset + i) == Some (Seq.index s1 i, p1)));
assert (forall (i: nat) . i < Seq.length s2 ==>
M.sel (mk_carrier len offset s2 p2) (offset + i) == Some (Seq.index s2 i, p2))
[@@erasable]
let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: US.t & ref _ (pcm elt (US.v base_len)))
let base_len (#elt: Type) (b: base_t elt) : GTot nat = US.v (dfst b)
[@@noextract_to "krml"]
noeq
type ptr (elt: Type u#a) : Type0 = {
base_len: Ghost.erased US.t;
// U32.t to prove that A.read, A.write offset computation does not overflow. TODO: replace U32.t with size_t
base: (r: ref _ (pcm elt (US.v base_len)) { core_ref_is_null r ==> US.v base_len == 0 });
offset: (offset: nat { offset <= US.v base_len });
}
let null_ptr a = { base_len = 0sz; base = null #_ #(pcm a 0) ; offset = 0 }
let is_null_ptr p = is_null p.base
let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |)
let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset
let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma
(requires (
base p1 == base p2 /\
offset p1 == offset p2
))
(ensures (
p1 == p2
))
= ()
let base_len_null_ptr _ = ()
let length_fits #elt a = ()
let valid_perm
(len: nat)
(offset: nat)
(slice_len: nat)
(p: P.perm) : Tot prop =
let open FStar.Real in
((offset + slice_len <= len /\ slice_len > 0) ==> (p.P.v <=. one))
[@__reduce__]
let pts_to0 (#elt: Type u#1) (a: array elt) (p: P.perm) (s: Seq.seq elt) : Tot vprop =
R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p) `star`
pure (
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\
Seq.length s == length a
)
let pts_to (#elt: Type u#1) (a: array elt) ([@@@ smt_fallback ] p: P.perm) ([@@@ smt_fallback ] s: Seq.seq elt) : Tot vprop =
pts_to0 a p s | {
"checked_file": "/",
"dependencies": [
"Steel.ST.PCMReference.fsti.checked",
"Steel.ST.Loops.fsti.checked",
"Steel.PCMMap.fst.checked",
"Steel.PCMFrac.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.HigherArray.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.PCMMap",
"short_module": "PM"
},
{
"abbrev": true,
"full_module": "FStar.Map",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Steel.ST.PCMReference",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "Steel.PCMFrac",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Steel.Memory.ref carrier pcm -> v: carrier -> p': Steel.Memory.ref carrier' pcm' -> v': carrier'
-> Steel.ST.Effect.Ghost.STGhost Prims.unit | Steel.ST.Effect.Ghost.STGhost | [] | [] | [
"Steel.Memory.inames",
"FStar.PCM.pcm",
"Steel.Memory.ref",
"Steel.ST.Util.rewrite",
"Steel.ST.PCMReference.pts_to",
"Prims.unit",
"Steel.Effect.Common.vprop",
"Prims.l_and",
"Prims.eq2",
"Prims.l_True"
] | [] | false | true | false | false | false | let change_r_pts_to
(#opened: _)
(#carrier: Type u#1)
(#pcm: P.pcm carrier)
(p: ref carrier pcm)
(v: carrier)
(#carrier': Type u#1)
(#pcm': P.pcm carrier')
(p': ref carrier' pcm')
(v': carrier')
: STGhost unit
opened
(R.pts_to p v)
(fun _ -> R.pts_to p' v')
(carrier == carrier' /\ pcm == pcm' /\ p == p' /\ v == v')
(fun _ -> True) =
| rewrite (R.pts_to p v) (R.pts_to p' v') | false |
LowStar.PrefixFreezableBuffer.fsti | LowStar.PrefixFreezableBuffer.slice_is | val slice_is (i j: u32) (snap: G.erased (Seq.seq u8)) : spred u8 | val slice_is (i j: u32) (snap: G.erased (Seq.seq u8)) : spred u8 | let slice_is (i j:u32) (snap:G.erased (Seq.seq u8)) : spred u8 =
fun s -> let len = Seq.length s in len >= 4 /\ //for typing of frozen_until
(let frozen_until = frozen_until s in
let i = U32.v i in
let j = U32.v j in
let snap = G.reveal snap in
4 <= i /\ i <= j /\ j <= frozen_until /\ frozen_until <= len /\
Seq.length snap == j - i /\
Seq.equal (Seq.slice s i j) snap) | {
"file_name": "ulib/LowStar.PrefixFreezableBuffer.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 36,
"end_line": 102,
"start_col": 0,
"start_line": 94
} | (*
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 LowStar.PrefixFreezableBuffer
open FStar.HyperStack.ST
include LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
(*
* A library for prefix freezable buffers of elements of type u8
*
* Our monotonicity theory does not easily support preorders and predicates over
* multiple references. So instead of keeping the frozen-until counter in a
* separate (ghost) reference, the library maintains the frozen-until counter (a u32)
* in the first four bytes of the buffer itself
*
* Buffer contents up to the frozen-until counter are stable and clients can witness
* and recall them
*
*)
type u8 = UInt8.t
type u32 = U32.t
#set-options "--max_fuel 0 --max_ifuel 0"
/// This is the frozen until index in the sequence representation of a PrefixFreezableBuffer
val le_to_n (s:Seq.seq u8) : Tot nat
let frozen_until (s:Seq.seq u8{Seq.length s >= 4}) = le_to_n (Seq.slice s 0 4)
/// Preorder for PrefixFreezableBuffers
private unfold let pre (s1 s2:Seq.seq u8) =
Seq.length s1 == Seq.length s2 /\ //lengths are same
(let len = Seq.length s1 in
len >= 4 ==> //if length >= 4 then
(let frozen_until1 = frozen_until s1 in
let frozen_until2 = frozen_until s2 in
(4 <= frozen_until1 /\ frozen_until1 <= len) ==> //if frozen_until1 is in the range [4, len] then
(frozen_until1 <= frozen_until2 /\ frozen_until2 <= len /\ //frozen until index increases monotonically, but remains <= len
(forall (i:nat).{:pattern Seq.index s2 i}
(4 <= i /\ i < frozen_until1) ==> Seq.index s2 i == Seq.index s1 i)))) //and the contents until frozen_until1 remain same
val prefix_freezable_preorder : srel u8
/// Clients can call the following lemma to reveal the preorder
val prefix_freezable_preorder_elim (s1 s2:Seq.seq u8)
: Lemma (prefix_freezable_preorder s1 s2 <==> pre s1 s2)
/// Predicate for the frozen_until index being at least n
///
/// It is stable w.r.t. the prefix_freezable_preorder
let frozen_until_at_least (n:nat) : spred u8 =
fun s -> Seq.length s >= 4 /\ //it follows from the inequalities below, but we need it for typing of frozen_until
4 <= n /\ n <= frozen_until s /\ frozen_until s <= Seq.length s
/// Predicate for the frozen slice with indices in the [4, frozen_until) range
///
/// It is stable w.r.t. the prefix_freezable_preorder | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.PrefixFreezableBuffer.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
i: LowStar.PrefixFreezableBuffer.u32 ->
j: LowStar.PrefixFreezableBuffer.u32 ->
snap: FStar.Ghost.erased (FStar.Seq.Base.seq LowStar.PrefixFreezableBuffer.u8)
-> LowStar.Monotonic.Buffer.spred LowStar.PrefixFreezableBuffer.u8 | Prims.Tot | [
"total"
] | [] | [
"LowStar.PrefixFreezableBuffer.u32",
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"LowStar.PrefixFreezableBuffer.u8",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThanOrEqual",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"Prims.op_Subtraction",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.slice",
"FStar.Ghost.reveal",
"FStar.UInt.uint_t",
"FStar.UInt32.v",
"Prims.nat",
"LowStar.PrefixFreezableBuffer.frozen_until",
"LowStar.Monotonic.Buffer.spred"
] | [] | false | false | false | true | false | let slice_is (i j: u32) (snap: G.erased (Seq.seq u8)) : spred u8 =
| fun s ->
let len = Seq.length s in
len >= 4 /\
(let frozen_until = frozen_until s in
let i = U32.v i in
let j = U32.v j in
let snap = G.reveal snap in
4 <= i /\ i <= j /\ j <= frozen_until /\ frozen_until <= len /\ Seq.length snap == j - i /\
Seq.equal (Seq.slice s i j) snap) | false |
LowStar.PrefixFreezableBuffer.fsti | LowStar.PrefixFreezableBuffer.alloc_post_mem_common | val alloc_post_mem_common : h0: FStar.Monotonic.HyperStack.mem ->
b: LowStar.PrefixFreezableBuffer.buffer ->
h1: FStar.Monotonic.HyperStack.mem
-> Prims.logical | let alloc_post_mem_common
(h0:HS.mem) (b:buffer) (h1:HS.mem)
= live h1 b /\
unused_in b h0 /\
Map.domain (HS.get_hmap h1) `Set.equal` Map.domain (HS.get_hmap h0) /\
HS.get_tip h1 == HS.get_tip h0 /\
modifies loc_none h0 h1 /\
frozen_until (as_seq h1 b) == 4 | {
"file_name": "ulib/LowStar.PrefixFreezableBuffer.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 35,
"end_line": 134,
"start_col": 7,
"start_line": 127
} | (*
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 LowStar.PrefixFreezableBuffer
open FStar.HyperStack.ST
include LowStar.Monotonic.Buffer
module P = FStar.Preorder
module G = FStar.Ghost
module U32 = FStar.UInt32
module Seq = FStar.Seq
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
(*
* A library for prefix freezable buffers of elements of type u8
*
* Our monotonicity theory does not easily support preorders and predicates over
* multiple references. So instead of keeping the frozen-until counter in a
* separate (ghost) reference, the library maintains the frozen-until counter (a u32)
* in the first four bytes of the buffer itself
*
* Buffer contents up to the frozen-until counter are stable and clients can witness
* and recall them
*
*)
type u8 = UInt8.t
type u32 = U32.t
#set-options "--max_fuel 0 --max_ifuel 0"
/// This is the frozen until index in the sequence representation of a PrefixFreezableBuffer
val le_to_n (s:Seq.seq u8) : Tot nat
let frozen_until (s:Seq.seq u8{Seq.length s >= 4}) = le_to_n (Seq.slice s 0 4)
/// Preorder for PrefixFreezableBuffers
private unfold let pre (s1 s2:Seq.seq u8) =
Seq.length s1 == Seq.length s2 /\ //lengths are same
(let len = Seq.length s1 in
len >= 4 ==> //if length >= 4 then
(let frozen_until1 = frozen_until s1 in
let frozen_until2 = frozen_until s2 in
(4 <= frozen_until1 /\ frozen_until1 <= len) ==> //if frozen_until1 is in the range [4, len] then
(frozen_until1 <= frozen_until2 /\ frozen_until2 <= len /\ //frozen until index increases monotonically, but remains <= len
(forall (i:nat).{:pattern Seq.index s2 i}
(4 <= i /\ i < frozen_until1) ==> Seq.index s2 i == Seq.index s1 i)))) //and the contents until frozen_until1 remain same
val prefix_freezable_preorder : srel u8
/// Clients can call the following lemma to reveal the preorder
val prefix_freezable_preorder_elim (s1 s2:Seq.seq u8)
: Lemma (prefix_freezable_preorder s1 s2 <==> pre s1 s2)
/// Predicate for the frozen_until index being at least n
///
/// It is stable w.r.t. the prefix_freezable_preorder
let frozen_until_at_least (n:nat) : spred u8 =
fun s -> Seq.length s >= 4 /\ //it follows from the inequalities below, but we need it for typing of frozen_until
4 <= n /\ n <= frozen_until s /\ frozen_until s <= Seq.length s
/// Predicate for the frozen slice with indices in the [4, frozen_until) range
///
/// It is stable w.r.t. the prefix_freezable_preorder
let slice_is (i j:u32) (snap:G.erased (Seq.seq u8)) : spred u8 =
fun s -> let len = Seq.length s in len >= 4 /\ //for typing of frozen_until
(let frozen_until = frozen_until s in
let i = U32.v i in
let j = U32.v j in
let snap = G.reveal snap in
4 <= i /\ i <= j /\ j <= frozen_until /\ frozen_until <= len /\
Seq.length snap == j - i /\
Seq.equal (Seq.slice s i j) snap)
/// Buffer type for PrefixfreezableBuffers
///
/// And abbreviation for the length indexed version
type buffer =
b:mbuffer u8 (prefix_freezable_preorder) (prefix_freezable_preorder)
{length b >= 4 /\ b `witnessed` frozen_until_at_least 4}
unfold let lbuffer (len:u32) =
b:buffer{length b == U32.v len + 4}
/// Allocation precondition for prefix freezable buffers adds an additional constraint
/// that the input length + 4 must fit in u32
unfold let malloc_pre (r:HS.rid) (len:u32) =
UInt.size (U32.v len + 4) 32 /\ malloc_pre r len
/// The postcondition is also different in that there is no initializer
/// and an additional predicate for the initial value of the frozen_until_index | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "LowStar.PrefixFreezableBuffer.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h0: FStar.Monotonic.HyperStack.mem ->
b: LowStar.PrefixFreezableBuffer.buffer ->
h1: FStar.Monotonic.HyperStack.mem
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.HyperStack.mem",
"LowStar.PrefixFreezableBuffer.buffer",
"Prims.l_and",
"LowStar.Monotonic.Buffer.live",
"LowStar.PrefixFreezableBuffer.u8",
"LowStar.PrefixFreezableBuffer.prefix_freezable_preorder",
"LowStar.Monotonic.Buffer.unused_in",
"FStar.Set.equal",
"FStar.Monotonic.HyperHeap.rid",
"FStar.Map.domain",
"FStar.Monotonic.Heap.heap",
"FStar.Monotonic.HyperStack.get_hmap",
"Prims.eq2",
"FStar.Monotonic.HyperStack.get_tip",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_none",
"Prims.int",
"LowStar.PrefixFreezableBuffer.frozen_until",
"LowStar.Monotonic.Buffer.as_seq",
"Prims.logical"
] | [] | false | false | false | true | true | let alloc_post_mem_common (h0: HS.mem) (b: buffer) (h1: HS.mem) =
| live h1 b /\ unused_in b h0 /\
(Map.domain (HS.get_hmap h1)) `Set.equal` (Map.domain (HS.get_hmap h0)) /\
HS.get_tip h1 == HS.get_tip h0 /\ modifies loc_none h0 h1 /\ frozen_until (as_seq h1 b) == 4 | false |
|
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_add | val bn_add:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen <= aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
carry t & lbignum t aLen | val bn_add:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen <= aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
carry t & lbignum t aLen | let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 38,
"end_line": 21,
"start_col": 0,
"start_line": 20
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b: Hacl.Spec.Bignum.Definitions.lbignum t bLen
-> Hacl.Spec.Bignum.Base.carry t * Hacl.Spec.Bignum.Definitions.lbignum t aLen | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Addition.bn_add",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Base.carry"
] | [] | false | false | false | false | false | let bn_add #t #aLen #bLen a b =
| Hacl.Spec.Bignum.Addition.bn_add a b | false |
Steel.MonotonicHigherReference.fst | Steel.MonotonicHigherReference.read_refine | val read_refine (#a:Type) (#q:perm) (#p:Preorder.preorder a) (#frame:a -> vprop)
(r:ref a p)
: SteelT a (h_exists (fun (v:a) -> pts_to r q v `star` frame v))
(fun v -> pts_to r q v `star` frame v) | val read_refine (#a:Type) (#q:perm) (#p:Preorder.preorder a) (#frame:a -> vprop)
(r:ref a p)
: SteelT a (h_exists (fun (v:a) -> pts_to r q v `star` frame v))
(fun v -> pts_to r q v `star` frame v) | let read_refine (#a:Type) (#q:perm) (#p:Preorder.preorder a) (#f:a -> vprop)
(r:ref a p)
: SteelT a (h_exists (fun (v:a) -> pts_to r q v `star` f v))
(fun v -> pts_to r q v `star` f v)
= let v = witness_exists () in
rewrite_slprop (pts_to r q (Ghost.hide (Ghost.reveal v)) `star` f v) (h_exists (pts_to_body r q v) `star` f v) (fun _ -> ());
let h = witness_exists () in
let _ = elim_pure r v h in
let hv = read r h in
let _:squash (compatible pcm_history h hv) = () in
rewrite_slprop (PR.pts_to r h) (pts_to_body r q v h) (fun m ->
emp_unit (M.pts_to r h);
pure_star_interp (M.pts_to r h) (history_val h v q) m);
intro_exists_erased h (pts_to_body r q v);
rewrite_erased (fun v -> (pts_to r q v `star` f v)) v (hval_tot hv);
let v = hval_tot hv in
rewrite_slprop
(pts_to r q (hval_tot hv) `star` f (Ghost.reveal (Ghost.hide (hval_tot hv))))
(pts_to r q v `star` f v)
(fun _ -> ());
return v | {
"file_name": "lib/steel/Steel.MonotonicHigherReference.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 12,
"end_line": 142,
"start_col": 0,
"start_line": 116
} | (*
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.MonotonicHigherReference
open FStar.Ghost
open FStar.PCM
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
open Steel.PCMReference
open Steel.FractionalPermission
open Steel.Preorder
module Preorder = FStar.Preorder
module Q = Steel.Preorder
module M = Steel.Memory
module PR = Steel.PCMReference
open FStar.Real
#set-options "--ide_id_info_off"
let ref a p = M.ref (history a p) pcm_history
[@@__reduce__]
let pts_to_body #a #p (r:ref a p) (f:perm) (v:Ghost.erased a) (h:history a p) =
PR.pts_to r h `star`
pure (history_val h v f)
let pts_to' (#a:Type) (#p:Preorder.preorder a) (r:ref a p) (f:perm) (v:Ghost.erased a) =
h_exists (pts_to_body r f v)
let pts_to_sl r f v = hp_of (pts_to' r f v)
let intro_pure #a #p #f
(r:ref a p)
(v:a)
(h:history a p { history_val h v f })
: SteelT unit
(PR.pts_to r h)
(fun _ -> pts_to_body r f v h)
= rewrite_slprop (PR.pts_to r h) (pts_to_body _ _ _ _) (fun m ->
emp_unit (M.pts_to r h);
pure_star_interp (M.pts_to r h) (history_val h v f) m)
let intro_pure_full #a #p #f
(r:ref a p)
(v:a)
(h:history a p { history_val h v f })
: SteelT unit
(PR.pts_to r h)
(fun _ -> pts_to r f v)
= intro_pure #a #p #f r v h;
intro_exists h (pts_to_body r f v)
let alloc (#a:Type) (p:Preorder.preorder a) (v:a)
= let h = Current [v] full_perm in
assert (compatible pcm_history h h);
let x : ref a p = alloc h in
intro_pure_full x v h;
x
let extract_pure #a #uses #p #f
(r:ref a p)
(v:Ghost.erased a)
(h:Ghost.erased (history a p))
: SteelGhostT (_:unit{history_val h v f})
uses
(pts_to_body r f v h)
(fun _ -> pts_to_body r f v h)
= rewrite_slprop
(pts_to_body r f v h)
(PR.pts_to r h `star` pure (history_val h v f))
(fun _ -> ());
elim_pure (history_val h v f);
rewrite_slprop (PR.pts_to r h) (pts_to_body r f v h) (fun m ->
emp_unit (M.pts_to r h);
pure_star_interp (M.pts_to r h) (history_val h v f) m
)
let elim_pure #a #uses #p #f
(r:ref a p)
(v:Ghost.erased a)
(h:Ghost.erased (history a p))
: SteelGhostT (_:unit{history_val h v f})
uses
(pts_to_body r f v h)
(fun _ -> PR.pts_to r h)
= let _ = extract_pure r v h in
drop (pure (history_val h v f))
let rewrite_erased #a (p:erased a -> vprop) (x:erased a) (y:a)
: Steel unit (p x) (fun _ -> p (Ghost.hide y))
(requires fun _ -> reveal x == y)
(ensures fun _ _ _ -> True)
= rewrite_slprop (p x) (p (Ghost.hide y)) (fun _ -> ())
let rewrite_reveal_hide #a (x:a) (p:a -> vprop) ()
: SteelT unit (p (Ghost.reveal (Ghost.hide x))) (fun _ -> p x)
= rewrite_slprop (p (Ghost.reveal (Ghost.hide x))) (p x) (fun _ -> ()) | {
"checked_file": "/",
"dependencies": [
"Steel.Preorder.fst.checked",
"Steel.PCMReference.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.MonotonicHigherReference.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Real",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.PCMReference",
"short_module": "PR"
},
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Steel.Preorder",
"short_module": "Q"
},
{
"abbrev": false,
"full_module": "Steel.Preorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.PCMReference",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "Preorder"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: Steel.MonotonicHigherReference.ref a p -> Steel.Effect.SteelT a | Steel.Effect.SteelT | [] | [] | [
"Steel.FractionalPermission.perm",
"FStar.Preorder.preorder",
"Steel.Effect.Common.vprop",
"Steel.MonotonicHigherReference.ref",
"Steel.Effect.Atomic.return",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.Effect.Common.VStar",
"Steel.MonotonicHigherReference.pts_to",
"Prims.unit",
"Steel.Effect.Atomic.rewrite_slprop",
"Steel.Effect.Common.star",
"Steel.Preorder.hval_tot",
"FStar.Ghost.reveal",
"Steel.Memory.mem",
"Steel.MonotonicHigherReference.rewrite_erased",
"FStar.Ghost.erased",
"Steel.Effect.Atomic.intro_exists_erased",
"Steel.Preorder.history",
"Steel.MonotonicHigherReference.pts_to_body",
"Steel.PCMReference.pts_to",
"Steel.Preorder.pcm_history",
"Steel.Memory.pure_star_interp",
"Steel.Memory.pts_to",
"Steel.Preorder.history_val",
"Steel.Memory.emp_unit",
"Prims.squash",
"FStar.PCM.compatible",
"Steel.PCMReference.read",
"Steel.MonotonicHigherReference.elim_pure",
"Steel.Effect.Atomic.witness_exists",
"Steel.Effect.Atomic.h_exists"
] | [] | false | true | false | false | false | let read_refine (#a: Type) (#q: perm) (#p: Preorder.preorder a) (#f: (a -> vprop)) (r: ref a p)
: SteelT a
(h_exists (fun (v: a) -> (pts_to r q v) `star` (f v)))
(fun v -> (pts_to r q v) `star` (f v)) =
| let v = witness_exists () in
rewrite_slprop ((pts_to r q (Ghost.hide (Ghost.reveal v))) `star` (f v))
((h_exists (pts_to_body r q v)) `star` (f v))
(fun _ -> ());
let h = witness_exists () in
let _ = elim_pure r v h in
let hv = read r h in
let _:squash (compatible pcm_history h hv) = () in
rewrite_slprop (PR.pts_to r h)
(pts_to_body r q v h)
(fun m ->
emp_unit (M.pts_to r h);
pure_star_interp (M.pts_to r h) (history_val h v q) m);
intro_exists_erased h (pts_to_body r q v);
rewrite_erased (fun v -> ((pts_to r q v) `star` (f v))) v (hval_tot hv);
let v = hval_tot hv in
rewrite_slprop ((pts_to r q (hval_tot hv)) `star` (f (Ghost.reveal (Ghost.hide (hval_tot hv)))))
((pts_to r q v) `star` (f v))
(fun _ -> ());
return v | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_sub | val bn_sub:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen <= aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
carry t & lbignum t aLen | val bn_sub:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen <= aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
carry t & lbignum t aLen | let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 38,
"end_line": 27,
"start_col": 0,
"start_line": 26
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b: Hacl.Spec.Bignum.Definitions.lbignum t bLen
-> Hacl.Spec.Bignum.Base.carry t * Hacl.Spec.Bignum.Definitions.lbignum t aLen | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Addition.bn_sub",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Base.carry"
] | [] | false | false | false | false | false | let bn_sub #t #aLen #bLen a b =
| Hacl.Spec.Bignum.Addition.bn_sub a b | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_add1 | val bn_add1:
#t:limb_t
-> #aLen:size_pos
-> a:lbignum t aLen
-> b1:limb t ->
carry t & lbignum t aLen | val bn_add1:
#t:limb_t
-> #aLen:size_pos
-> a:lbignum t aLen
-> b1:limb t ->
carry t & lbignum t aLen | let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1 | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 40,
"end_line": 9,
"start_col": 0,
"start_line": 8
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b1: Hacl.Spec.Bignum.Definitions.limb t
-> Hacl.Spec.Bignum.Base.carry t * Hacl.Spec.Bignum.Definitions.lbignum t aLen | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_pos",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Addition.bn_add1",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Base.carry"
] | [] | false | false | false | false | false | let bn_add1 #t #aLen a b1 =
| Hacl.Spec.Bignum.Addition.bn_add1 a b1 | false |
LList.ST.fst | LList.ST.cons | val cons (#a:Type0) (#l:G.erased (list a)) (x:a) (ll:llist a)
: STT (llist a)
(ll `is_list` l)
(fun ll -> ll `is_list` (x::l)) | val cons (#a:Type0) (#l:G.erased (list a)) (x:a) (ll:llist a)
: STT (llist a)
(ll `is_list` l)
(fun ll -> ll `is_list` (x::l)) | let cons #_ #l x ll =
let node = {
data = x;
next = ll;
} in
let head = alloc node in
rewrite (ll `is_list` l)
(node.next `is_list` l);
intro (x::l) node head ();
return head | {
"file_name": "share/steel/examples/steel/LList.ST.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 13,
"end_line": 120,
"start_col": 0,
"start_line": 111
} | (*
Copyright 2021 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Author: Aseem Rastogi
*)
module LList.ST
open Steel.Memory
open Steel.ST.Effect
open Steel.ST.Util
open Steel.ST.Reference
#set-options "--ide_id_info_off"
let rec is_list #a ll l : Tot vprop (decreases l) =
match l with
| [] -> pure (ll == null)
| hd::tl ->
exists_ (fun (node:llist_node a) ->
pts_to ll full_perm node
`star`
pure (node.data == hd)
`star`
is_list node.next tl)
let empty a = null
module T = FStar.Tactics
let intro #_ #_ l node ll _ =
intro_pure (node.data == Cons?.hd l);
intro_exists
node
(fun node -> pts_to ll full_perm node
`star`
pure (node.data == Cons?.hd l)
`star`
is_list node.next (Cons?.tl l));
assert (exists_ (fun node -> pts_to ll full_perm node
`star`
pure (node.data == Cons?.hd l)
`star`
is_list node.next (Cons?.tl l)) ==
is_list ll (Cons?.hd l::Cons?.tl l))
by (T.norm [delta_only [`%is_list]; zeta; iota]);
rewrite
(exists_ (fun node -> pts_to ll full_perm node
`star`
pure (node.data == Cons?.hd l)
`star`
is_list node.next (Cons?.tl l)))
(is_list ll l)
let elim_aux (#opened:_) (#a:Type0)
(hd:G.erased a)
(tl:G.erased (list a))
(ll:llist a)
: STGhost (G.erased (llist_node a)) opened
(is_list ll (G.reveal hd::tl))
(fun node ->
pts_to ll full_perm node
`star`
is_list node.next tl)
(requires True)
(ensures fun node -> eq2 #a node.data hd)
= assert (is_list ll (G.reveal hd::tl) ==
exists_ (fun node -> pts_to ll full_perm node
`star`
pure (eq2 #a node.data hd)
`star`
is_list node.next tl))
by (T.norm [delta_only [`%is_list]; zeta; iota]);
rewrite (is_list ll (G.reveal hd::tl))
(exists_ (fun node -> pts_to ll full_perm node
`star`
pure (eq2 #a node.data hd)
`star`
is_list node.next tl));
let node = elim_exists () in
elim_pure (eq2 _ _);
node
let elim #opened #a l ll p =
rewrite
(is_list ll l)
(is_list ll (Cons?.hd l::Cons?.tl l));
elim_aux (Cons?.hd l) (Cons?.tl l) ll
let empty_pts_to #_ a =
intro_pure (empty a == null);
rewrite (pure _)
(is_list (empty a) []) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Reference.fsti.checked",
"Steel.ST.Effect.fsti.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "LList.ST.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.Reference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Steel.ST.Reference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "LList",
"short_module": null
},
{
"abbrev": false,
"full_module": "LList",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 -> ll: LList.ST.llist a -> Steel.ST.Effect.STT (LList.ST.llist a) | Steel.ST.Effect.STT | [] | [] | [
"FStar.Ghost.erased",
"Prims.list",
"LList.ST.llist",
"Steel.ST.Util.return",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"LList.ST.is_list",
"Prims.Cons",
"FStar.Ghost.reveal",
"Steel.Effect.Common.vprop",
"Prims.unit",
"LList.ST.intro",
"Steel.ST.Util.rewrite",
"LList.ST.__proj__Mkllist_node__item__next",
"Steel.ST.Reference.ref",
"LList.ST.llist_node",
"Steel.ST.Reference.alloc",
"LList.ST.Mkllist_node"
] | [] | false | true | false | false | false | let cons #_ #l x ll =
| let node = { data = x; next = ll } in
let head = alloc node in
rewrite (ll `is_list` l) (node.next `is_list` l);
intro (x :: l) node head ();
return head | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_add1_lemma | val bn_add1_lemma:
#t:limb_t
-> #aLen:size_pos
-> a:lbignum t aLen
-> b1:limb t ->
Lemma (let (c, res) = bn_add1 a b1 in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a + v b1) | val bn_add1_lemma:
#t:limb_t
-> #aLen:size_pos
-> a:lbignum t aLen
-> b1:limb t ->
Lemma (let (c, res) = bn_add1 a b1 in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a + v b1) | let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1 | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 46,
"end_line": 12,
"start_col": 0,
"start_line": 11
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b1: Hacl.Spec.Bignum.Definitions.limb t
-> FStar.Pervasives.Lemma
(ensures
(let _ = Hacl.Spec.Bignum.bn_add1 a b1 in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in
Lib.IntTypes.v c * Prims.pow2 (Lib.IntTypes.bits t * aLen) +
Hacl.Spec.Bignum.Definitions.bn_v res ==
Hacl.Spec.Bignum.Definitions.bn_v a + Lib.IntTypes.v b1)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_pos",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Addition.bn_add1_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let bn_add1_lemma #t #aLen a b1 =
| Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1 | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_sub1 | val bn_sub1:
#t:limb_t
-> #aLen:size_pos
-> a:lbignum t aLen
-> b1:limb t ->
carry t & lbignum t aLen | val bn_sub1:
#t:limb_t
-> #aLen:size_pos
-> a:lbignum t aLen
-> b1:limb t ->
carry t & lbignum t aLen | let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1 | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 40,
"end_line": 15,
"start_col": 0,
"start_line": 14
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b1: Hacl.Spec.Bignum.Definitions.limb t
-> Hacl.Spec.Bignum.Base.carry t * Hacl.Spec.Bignum.Definitions.lbignum t aLen | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_pos",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Addition.bn_sub1",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Base.carry"
] | [] | false | false | false | false | false | let bn_sub1 #t #aLen a b1 =
| Hacl.Spec.Bignum.Addition.bn_sub1 a b1 | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_mul1 | val bn_mul1:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b1:limb t ->
limb t & lbignum t aLen | val bn_mul1:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b1:limb t ->
limb t & lbignum t aLen | let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1 | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 46,
"end_line": 118,
"start_col": 0,
"start_line": 117
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b1: Hacl.Spec.Bignum.Definitions.limb t
-> Hacl.Spec.Bignum.Definitions.limb t * Hacl.Spec.Bignum.Definitions.lbignum t aLen | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Multiplication.bn_mul1",
"FStar.Pervasives.Native.tuple2"
] | [] | false | false | false | false | false | let bn_mul1 #t #aLen a b1 =
| Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1 | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_sub1_lemma | val bn_sub1_lemma:
#t:limb_t
-> #aLen:size_pos
-> a:lbignum t aLen
-> b1:limb t ->
Lemma (let (c, res) = bn_sub1 a b1 in
bn_v res - v c * pow2 (bits t * aLen) == bn_v a - v b1) | val bn_sub1_lemma:
#t:limb_t
-> #aLen:size_pos
-> a:lbignum t aLen
-> b1:limb t ->
Lemma (let (c, res) = bn_sub1 a b1 in
bn_v res - v c * pow2 (bits t * aLen) == bn_v a - v b1) | let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1 | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 46,
"end_line": 18,
"start_col": 0,
"start_line": 17
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b1: Hacl.Spec.Bignum.Definitions.limb t
-> FStar.Pervasives.Lemma
(ensures
(let _ = Hacl.Spec.Bignum.bn_sub1 a b1 in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in
Hacl.Spec.Bignum.Definitions.bn_v res -
Lib.IntTypes.v c * Prims.pow2 (Lib.IntTypes.bits t * aLen) ==
Hacl.Spec.Bignum.Definitions.bn_v a - Lib.IntTypes.v b1)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_pos",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Addition.bn_sub1_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let bn_sub1_lemma #t #aLen a b1 =
| Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1 | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_add_lemma | val bn_add_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen <= aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
Lemma (let (c_out, res) = bn_add a b in
bn_v res + v c_out * pow2 (bits t * aLen) == bn_v a + bn_v b) | val bn_add_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen <= aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
Lemma (let (c_out, res) = bn_add a b in
bn_v res + v c_out * pow2 (bits t * aLen) == bn_v a + bn_v b) | let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 24,
"start_col": 0,
"start_line": 23
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b: Hacl.Spec.Bignum.Definitions.lbignum t bLen
-> FStar.Pervasives.Lemma
(ensures
(let _ = Hacl.Spec.Bignum.bn_add a b in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c_out res = _ in
Hacl.Spec.Bignum.Definitions.bn_v res +
Lib.IntTypes.v c_out * Prims.pow2 (Lib.IntTypes.bits t * aLen) ==
Hacl.Spec.Bignum.Definitions.bn_v a + Hacl.Spec.Bignum.Definitions.bn_v b)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Addition.bn_add_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let bn_add_lemma #t #aLen #bLen a b =
| Hacl.Spec.Bignum.Addition.bn_add_lemma a b | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_add_mod_n | val bn_add_mod_n:
#t:limb_t
-> #len:size_nat
-> n:lbignum t len
-> a:lbignum t len
-> b:lbignum t len ->
lbignum t len | val bn_add_mod_n:
#t:limb_t
-> #len:size_nat
-> n:lbignum t len
-> a:lbignum t len
-> b:lbignum t len ->
lbignum t len | let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0 | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 70,
"start_col": 0,
"start_line": 68
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
n: Hacl.Spec.Bignum.Definitions.lbignum t len ->
a: Hacl.Spec.Bignum.Definitions.lbignum t len ->
b: Hacl.Spec.Bignum.Definitions.lbignum t len
-> Hacl.Spec.Bignum.Definitions.lbignum t len | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"Hacl.Spec.Bignum.bn_reduce_once",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.bn_add"
] | [] | false | false | false | false | false | let bn_add_mod_n #t #len n a b =
| let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0 | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_sub_lemma | val bn_sub_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen <= aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
Lemma (let (c_out, res) = bn_sub a b in
bn_v res - v c_out * pow2 (bits t * aLen) == bn_v a - bn_v b) | val bn_sub_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen <= aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
Lemma (let (c_out, res) = bn_sub a b in
bn_v res - v c_out * pow2 (bits t * aLen) == bn_v a - bn_v b) | let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 30,
"start_col": 0,
"start_line": 29
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b: Hacl.Spec.Bignum.Definitions.lbignum t bLen
-> FStar.Pervasives.Lemma
(ensures
(let _ = Hacl.Spec.Bignum.bn_sub a b in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c_out res = _ in
Hacl.Spec.Bignum.Definitions.bn_v res -
Lib.IntTypes.v c_out * Prims.pow2 (Lib.IntTypes.bits t * aLen) ==
Hacl.Spec.Bignum.Definitions.bn_v a - Hacl.Spec.Bignum.Definitions.bn_v b)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Addition.bn_sub_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let bn_sub_lemma #t #aLen #bLen a b =
| Hacl.Spec.Bignum.Addition.bn_sub_lemma a b | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_reduce_once | val bn_reduce_once:
#t:limb_t
-> #len:size_nat
-> n:lbignum t len
-> c:carry t
-> a:lbignum t len ->
lbignum t len | val bn_reduce_once:
#t:limb_t
-> #len:size_nat
-> n:lbignum t len
-> c:carry t
-> a:lbignum t len ->
lbignum t len | let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 28,
"end_line": 35,
"start_col": 0,
"start_line": 32
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
n: Hacl.Spec.Bignum.Definitions.lbignum t len ->
c: Hacl.Spec.Bignum.Base.carry t ->
a: Hacl.Spec.Bignum.Definitions.lbignum t len
-> Hacl.Spec.Bignum.Definitions.lbignum t len | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"Lib.Sequence.map2",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Base.mask_select",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Lib.IntTypes.op_Subtraction_Dot",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.bn_sub"
] | [] | false | false | false | false | false | let bn_reduce_once #t #len n c0 a =
| let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_sub_mod_n | val bn_sub_mod_n:
#t:limb_t
-> #len:size_nat
-> n:lbignum t len
-> a:lbignum t len
-> b:lbignum t len ->
lbignum t len | val bn_sub_mod_n:
#t:limb_t
-> #len:size_nat
-> n:lbignum t len
-> a:lbignum t len
-> b:lbignum t len ->
lbignum t len | let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0 | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 83,
"start_col": 0,
"start_line": 79
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
n: Hacl.Spec.Bignum.Definitions.lbignum t len ->
a: Hacl.Spec.Bignum.Definitions.lbignum t len ->
b: Hacl.Spec.Bignum.Definitions.lbignum t len
-> Hacl.Spec.Bignum.Definitions.lbignum t len | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"Lib.Sequence.map2",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Base.mask_select",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Lib.IntTypes.op_Subtraction_Dot",
"Lib.IntTypes.uint",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.bn_add",
"Hacl.Spec.Bignum.bn_sub"
] | [] | false | false | false | false | false | let bn_sub_mod_n #t #len n a b =
| let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0 | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_add_mod_n_lemma | val bn_add_mod_n_lemma:
#t:limb_t
-> #len:size_nat
-> n:lbignum t len
-> a:lbignum t len
-> b:lbignum t len -> Lemma
(requires bn_v a < bn_v n /\ bn_v b < bn_v n)
(ensures bn_v (bn_add_mod_n n a b) == (bn_v a + bn_v b) % bn_v n) | val bn_add_mod_n_lemma:
#t:limb_t
-> #len:size_nat
-> n:lbignum t len
-> a:lbignum t len
-> b:lbignum t len -> Lemma
(requires bn_v a < bn_v n /\ bn_v b < bn_v n)
(ensures bn_v (bn_add_mod_n n a b) == (bn_v a + bn_v b) % bn_v n) | let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0 | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 76,
"start_col": 0,
"start_line": 73
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
n: Hacl.Spec.Bignum.Definitions.lbignum t len ->
a: Hacl.Spec.Bignum.Definitions.lbignum t len ->
b: Hacl.Spec.Bignum.Definitions.lbignum t len
-> FStar.Pervasives.Lemma
(requires
Hacl.Spec.Bignum.Definitions.bn_v a < Hacl.Spec.Bignum.Definitions.bn_v n /\
Hacl.Spec.Bignum.Definitions.bn_v b < Hacl.Spec.Bignum.Definitions.bn_v n)
(ensures
Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.Bignum.bn_add_mod_n n a b) ==
(Hacl.Spec.Bignum.Definitions.bn_v a + Hacl.Spec.Bignum.Definitions.bn_v b) %
Hacl.Spec.Bignum.Definitions.bn_v n) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"Hacl.Spec.Bignum.bn_reduce_once_lemma",
"Prims.unit",
"Hacl.Spec.Bignum.bn_add_lemma",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.bn_add"
] | [] | false | false | true | false | false | let bn_add_mod_n_lemma #t #len n a b =
| let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0 | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_mul | val bn_mul:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{aLen + bLen <= max_size_t}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
lbignum t (aLen + bLen) | val bn_mul:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{aLen + bLen <= max_size_t}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
lbignum t (aLen + bLen) | let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 124,
"start_col": 0,
"start_line": 123
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b: Hacl.Spec.Bignum.Definitions.lbignum t bLen
-> Hacl.Spec.Bignum.Definitions.lbignum t (aLen + bLen) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.max_size_t",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Multiplication.bn_mul"
] | [] | false | false | false | false | false | let bn_mul #t #aLen #bLen a b =
| Hacl.Spec.Bignum.Multiplication.bn_mul a b | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_mul1_lshift_add | val bn_mul1_lshift_add:
#t:limb_t
-> #aLen:size_nat
-> #resLen:size_nat
-> a:lbignum t aLen
-> b:limb t
-> j:size_nat{j + aLen <= resLen}
-> acc:lbignum t resLen ->
limb t & lbignum t resLen | val bn_mul1_lshift_add:
#t:limb_t
-> #aLen:size_nat
-> #resLen:size_nat
-> a:lbignum t aLen
-> b:limb t
-> j:size_nat{j + aLen <= resLen}
-> acc:lbignum t resLen ->
limb t & lbignum t resLen | let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 62,
"end_line": 148,
"start_col": 0,
"start_line": 147
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen ->
b: Hacl.Spec.Bignum.Definitions.limb t ->
j: Lib.IntTypes.size_nat{j + aLen <= resLen} ->
acc: Hacl.Spec.Bignum.Definitions.lbignum t resLen
-> Hacl.Spec.Bignum.Definitions.limb t * Hacl.Spec.Bignum.Definitions.lbignum t resLen | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add",
"FStar.Pervasives.Native.tuple2"
] | [] | false | false | false | false | false | let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
| Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc | false |
Steel.ST.HigherArray.fst | Steel.ST.HigherArray.pts_to_length | val pts_to_length
(#opened: _)
(#elt: Type u#1)
(#p: P.perm)
(a: array elt)
(s: Seq.seq elt)
: STGhost unit opened
(pts_to a p s)
(fun _ -> pts_to a p s)
(True)
(fun _ -> Seq.length s == length a) | val pts_to_length
(#opened: _)
(#elt: Type u#1)
(#p: P.perm)
(a: array elt)
(s: Seq.seq elt)
: STGhost unit opened
(pts_to a p s)
(fun _ -> pts_to a p s)
(True)
(fun _ -> Seq.length s == length a) | let pts_to_length
a s
=
elim_pts_to a _ s;
intro_pts_to a _ s | {
"file_name": "lib/steel/Steel.ST.HigherArray.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 20,
"end_line": 184,
"start_col": 0,
"start_line": 180
} | (*
Copyright 2022 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.ST.HigherArray
module P = Steel.PCMFrac
module R = Steel.ST.PCMReference
module M = FStar.Map
module PM = Steel.PCMMap
[@@noextract_to "krml"]
let index_t (len: Ghost.erased nat) : Tot Type0 =
(i: nat { i < len })
[@@noextract_to "krml"]
let carrier (elt: Type u#a) (len: Ghost.erased nat) : Tot Type =
PM.map (index_t len) (P.fractional elt)
[@@noextract_to "krml"]
let pcm (elt: Type u#a) (len: Ghost.erased nat) : Tot (P.pcm (carrier elt len)) =
PM.pointwise (index_t len) (P.pcm_frac #elt)
[@@noextract_to "krml"]
let one (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.one
let composable (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.composable
[@@noextract_to "krml"]
let compose (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.op
[@@noextract_to "krml"]
let mk_carrier
(#elt: Type)
(len: nat)
(offset: nat)
(s: Seq.seq elt)
(p: P.perm)
: Tot (carrier elt len)
= let f (i: nat) : Tot (P.fractional elt) =
if offset + Seq.length s > len || i < offset || i >= offset + Seq.length s
then None
else Some (Seq.index s (i - offset), p)
in
M.map_literal f
let mk_carrier_inj
(#elt: Type)
(len: nat)
(offset: nat)
(s1 s2: Seq.seq elt)
(p1 p2: P.perm)
: Lemma
(requires (
mk_carrier len offset s1 p1 == mk_carrier len offset s2 p2 /\
offset + Seq.length s1 <= len /\
offset + Seq.length s2 <= len
))
(ensures (
s1 `Seq.equal` s2 /\
(Seq.length s1 > 0 ==> p1 == p2)
))
= assert (forall (i: nat) . i < Seq.length s1 ==>
(M.sel (mk_carrier len offset s1 p1) (offset + i) == Some (Seq.index s1 i, p1)));
assert (forall (i: nat) . i < Seq.length s2 ==>
M.sel (mk_carrier len offset s2 p2) (offset + i) == Some (Seq.index s2 i, p2))
[@@erasable]
let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: US.t & ref _ (pcm elt (US.v base_len)))
let base_len (#elt: Type) (b: base_t elt) : GTot nat = US.v (dfst b)
[@@noextract_to "krml"]
noeq
type ptr (elt: Type u#a) : Type0 = {
base_len: Ghost.erased US.t;
// U32.t to prove that A.read, A.write offset computation does not overflow. TODO: replace U32.t with size_t
base: (r: ref _ (pcm elt (US.v base_len)) { core_ref_is_null r ==> US.v base_len == 0 });
offset: (offset: nat { offset <= US.v base_len });
}
let null_ptr a = { base_len = 0sz; base = null #_ #(pcm a 0) ; offset = 0 }
let is_null_ptr p = is_null p.base
let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |)
let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset
let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma
(requires (
base p1 == base p2 /\
offset p1 == offset p2
))
(ensures (
p1 == p2
))
= ()
let base_len_null_ptr _ = ()
let length_fits #elt a = ()
let valid_perm
(len: nat)
(offset: nat)
(slice_len: nat)
(p: P.perm) : Tot prop =
let open FStar.Real in
((offset + slice_len <= len /\ slice_len > 0) ==> (p.P.v <=. one))
[@__reduce__]
let pts_to0 (#elt: Type u#1) (a: array elt) (p: P.perm) (s: Seq.seq elt) : Tot vprop =
R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p) `star`
pure (
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\
Seq.length s == length a
)
let pts_to (#elt: Type u#1) (a: array elt) ([@@@ smt_fallback ] p: P.perm) ([@@@ smt_fallback ] s: Seq.seq elt) : Tot vprop =
pts_to0 a p s
// this lemma is necessary because Steel.PCMReference is marked unfold
let change_r_pts_to
(#opened: _)
(#carrier: Type u#1)
(#pcm: P.pcm carrier)
(p: ref carrier pcm)
(v: carrier)
(#carrier': Type u#1)
(#pcm': P.pcm carrier')
(p': ref carrier' pcm')
(v': carrier')
: STGhost unit opened
(R.pts_to p v)
(fun _ -> R.pts_to p' v')
(// keep on distinct lines for error messages
carrier == carrier' /\
pcm == pcm' /\
p == p' /\
v == v')
(fun _ -> True)
= rewrite
(R.pts_to p v)
(R.pts_to p' v')
let intro_pts_to (#opened: _) (#elt: Type u#1) (a: array elt) (#v: _) (p: P.perm) (s: Seq.seq elt) : STGhost unit opened
(R.pts_to (ptr_of a).base v)
(fun _ -> pts_to a p s)
(
v == mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p /\
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\
Seq.length s == length a
)
(fun _ -> True)
= change_r_pts_to (ptr_of a).base v (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p);
intro_pure _;
rewrite
(pts_to0 a p s)
(pts_to a p s)
let elim_pts_to (#opened: _) (#elt: Type u#1) (a: array elt) (p: P.perm) (s: Seq.seq elt) : STGhost unit opened
(pts_to a p s)
(fun _ -> R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p))
(True)
(fun _ ->
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\
Seq.length s == length a
)
= rewrite
(pts_to a p s)
(pts_to0 a p s);
elim_pure _ | {
"checked_file": "/",
"dependencies": [
"Steel.ST.PCMReference.fsti.checked",
"Steel.ST.Loops.fsti.checked",
"Steel.PCMMap.fst.checked",
"Steel.PCMFrac.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.HigherArray.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.PCMMap",
"short_module": "PM"
},
{
"abbrev": true,
"full_module": "FStar.Map",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Steel.ST.PCMReference",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "Steel.PCMFrac",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Steel.ST.HigherArray.array elt -> s: FStar.Seq.Base.seq elt
-> Steel.ST.Effect.Ghost.STGhost Prims.unit | Steel.ST.Effect.Ghost.STGhost | [] | [] | [
"Steel.Memory.inames",
"Steel.FractionalPermission.perm",
"Steel.ST.HigherArray.array",
"FStar.Seq.Base.seq",
"Steel.ST.HigherArray.intro_pts_to",
"Steel.ST.HigherArray.mk_carrier",
"FStar.SizeT.v",
"FStar.Ghost.reveal",
"FStar.SizeT.t",
"Steel.ST.HigherArray.__proj__Mkptr__item__base_len",
"Steel.ST.HigherArray.ptr_of",
"Steel.ST.HigherArray.__proj__Mkptr__item__offset",
"Prims.unit",
"Steel.ST.HigherArray.elim_pts_to"
] | [] | false | true | false | false | false | let pts_to_length a s =
| elim_pts_to a _ s;
intro_pts_to a _ s | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_mul1_lemma | val bn_mul1_lemma:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b1:limb t ->
Lemma (let (c, res) = bn_mul1 a b1 in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a * v b1) | val bn_mul1_lemma:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b1:limb t ->
Lemma (let (c, res) = bn_mul1 a b1 in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a * v b1) | let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1 | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 52,
"end_line": 121,
"start_col": 0,
"start_line": 120
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b1: Hacl.Spec.Bignum.Definitions.limb t
-> FStar.Pervasives.Lemma
(ensures
(let _ = Hacl.Spec.Bignum.bn_mul1 a b1 in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in
Lib.IntTypes.v c * Prims.pow2 (Lib.IntTypes.bits t * aLen) +
Hacl.Spec.Bignum.Definitions.bn_v res ==
Hacl.Spec.Bignum.Definitions.bn_v a * Lib.IntTypes.v b1)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let bn_mul1_lemma #t #aLen a b1 =
| Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1 | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_sub_mod_n_lemma | val bn_sub_mod_n_lemma:
#t:limb_t
-> #len:size_nat
-> n:lbignum t len
-> a:lbignum t len
-> b:lbignum t len -> Lemma
(requires bn_v a < bn_v n /\ bn_v b < bn_v n)
(ensures bn_v (bn_sub_mod_n n a b) == (bn_v a - bn_v b) % bn_v n) | val bn_sub_mod_n_lemma:
#t:limb_t
-> #len:size_nat
-> n:lbignum t len
-> a:lbignum t len
-> b:lbignum t len -> Lemma
(requires bn_v a < bn_v n /\ bn_v b < bn_v n)
(ensures bn_v (bn_sub_mod_n n a b) == (bn_v a - bn_v b) % bn_v n) | let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 114,
"start_col": 0,
"start_line": 86
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
n: Hacl.Spec.Bignum.Definitions.lbignum t len ->
a: Hacl.Spec.Bignum.Definitions.lbignum t len ->
b: Hacl.Spec.Bignum.Definitions.lbignum t len
-> FStar.Pervasives.Lemma
(requires
Hacl.Spec.Bignum.Definitions.bn_v a < Hacl.Spec.Bignum.Definitions.bn_v n /\
Hacl.Spec.Bignum.Definitions.bn_v b < Hacl.Spec.Bignum.Definitions.bn_v n)
(ensures
Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.Bignum.bn_sub_mod_n n a b) ==
(Hacl.Spec.Bignum.Definitions.bn_v a - Hacl.Spec.Bignum.Definitions.bn_v b) %
Hacl.Spec.Bignum.Definitions.bn_v n) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"Prims.op_Equality",
"Prims.int",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Prims.op_Modulus",
"Prims.op_Subtraction",
"FStar.Math.Lemmas.small_mod",
"Prims.bool",
"FStar.Math.Lemmas.modulo_addition_lemma",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Addition",
"Hacl.Spec.Bignum.Definitions.bn_eval_bound",
"FStar.Mul.op_Star",
"Prims.pow2",
"Lib.IntTypes.bits",
"Hacl.Spec.Bignum.bn_add_lemma",
"Hacl.Spec.Bignum.Base.lseq_mask_select_lemma",
"Lib.Sequence.lseq",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Lib.Sequence.index",
"Hacl.Spec.Bignum.Base.mask_select",
"Lib.Sequence.map2",
"Prims.l_or",
"Lib.IntTypes.range_t",
"Lib.IntTypes.ones",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Subtraction_Dot",
"Lib.IntTypes.uint",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.bn_add",
"Hacl.Spec.Bignum.bn_sub_lemma",
"Hacl.Spec.Bignum.bn_sub"
] | [] | false | false | true | false | false | let bn_sub_mod_n_lemma #t #len n a b =
| let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0
then
(assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
())
else
(bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
()) | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_mul_lemma | val bn_mul_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{aLen + bLen <= max_size_t}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
Lemma (bn_v (bn_mul a b) == bn_v a * bn_v b) | val bn_mul_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{aLen + bLen <= max_size_t}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
Lemma (bn_v (bn_mul a b) == bn_v a * bn_v b) | let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 127,
"start_col": 0,
"start_line": 126
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b: Hacl.Spec.Bignum.Definitions.lbignum t bLen
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.Bignum.bn_mul a b) ==
Hacl.Spec.Bignum.Definitions.bn_v a * Hacl.Spec.Bignum.Definitions.bn_v b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.max_size_t",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Multiplication.bn_mul_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let bn_mul_lemma #t #aLen #bLen a b =
| Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_karatsuba_mul | val bn_karatsuba_mul:
#t:limb_t
-> #aLen:size_nat{aLen + aLen <= max_size_t}
-> a:lbignum t aLen
-> b:lbignum t aLen ->
lbignum t (aLen + aLen) | val bn_karatsuba_mul:
#t:limb_t
-> #aLen:size_nat{aLen + aLen <= max_size_t}
-> a:lbignum t aLen
-> b:lbignum t aLen ->
lbignum t (aLen + aLen) | let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 49,
"end_line": 130,
"start_col": 0,
"start_line": 129
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b: Hacl.Spec.Bignum.Definitions.lbignum t aLen
-> Hacl.Spec.Bignum.Definitions.lbignum t (aLen + aLen) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.max_size_t",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul"
] | [] | false | false | false | false | false | let bn_karatsuba_mul #t #aLen a b =
| Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_sqr | val bn_sqr:
#t:limb_t
-> #aLen:size_nat{aLen + aLen <= max_size_t}
-> a:lbignum t aLen ->
lbignum t (aLen + aLen) | val bn_sqr:
#t:limb_t
-> #aLen:size_nat{aLen + aLen <= max_size_t}
-> a:lbignum t aLen ->
lbignum t (aLen + aLen) | let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 36,
"end_line": 136,
"start_col": 0,
"start_line": 135
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen
-> Hacl.Spec.Bignum.Definitions.lbignum t (aLen + aLen) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.max_size_t",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Squaring.bn_sqr"
] | [] | false | false | false | false | false | let bn_sqr #t #aLen a =
| Hacl.Spec.Bignum.Squaring.bn_sqr a | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_reduce_once_lemma | val bn_reduce_once_lemma:
#t:limb_t
-> #len:size_nat
-> n:lbignum t len
-> c:carry t
-> a:lbignum t len -> Lemma
(requires v c * pow2 (bits t * len) + bn_v a < 2 * bn_v n)
(ensures bn_v (bn_reduce_once n c a) == (v c * pow2 (bits t * len) + bn_v a) % bn_v n) | val bn_reduce_once_lemma:
#t:limb_t
-> #len:size_nat
-> n:lbignum t len
-> c:carry t
-> a:lbignum t len -> Lemma
(requires v c * pow2 (bits t * len) + bn_v a < 2 * bn_v n)
(ensures bn_v (bn_reduce_once n c a) == (v c * pow2 (bits t * len) + bn_v a) % bn_v n) | let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 49,
"end_line": 65,
"start_col": 0,
"start_line": 38
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
n: Hacl.Spec.Bignum.Definitions.lbignum t len ->
c: Hacl.Spec.Bignum.Base.carry t ->
a: Hacl.Spec.Bignum.Definitions.lbignum t len
-> FStar.Pervasives.Lemma
(requires
Lib.IntTypes.v c * Prims.pow2 (Lib.IntTypes.bits t * len) +
Hacl.Spec.Bignum.Definitions.bn_v a <
2 * Hacl.Spec.Bignum.Definitions.bn_v n)
(ensures
Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.Bignum.bn_reduce_once n c a) ==
(Lib.IntTypes.v c * Prims.pow2 (Lib.IntTypes.bits t * len) +
Hacl.Spec.Bignum.Definitions.bn_v a) %
Hacl.Spec.Bignum.Definitions.bn_v n) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"Prims.op_LessThan",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"Prims.unit",
"FStar.Math.Lemmas.small_mod",
"Prims.nat",
"Hacl.Spec.Bignum.Base.lseq_mask_select_lemma",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Prims.op_Subtraction",
"Prims.pow2",
"Prims.bool",
"FStar.Math.Lemmas.modulo_addition_lemma",
"Prims.op_Minus",
"Hacl.Spec.Bignum.Definitions.bn_eval_bound",
"Prims.b2t",
"Lib.Sequence.lseq",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.l_Forall",
"Prims.l_imp",
"Lib.Sequence.index",
"Hacl.Spec.Bignum.Base.mask_select",
"Lib.Sequence.map2",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Subtraction_Dot",
"Hacl.Spec.Bignum.bn_sub_lemma",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.bn_sub",
"Lib.IntTypes.bits"
] | [] | false | false | true | false | false | let bn_reduce_once_lemma #t #len n c0 res0 =
| let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n
then
(assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n))
else
(assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n)) | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_karatsuba_sqr | val bn_karatsuba_sqr:
#t:limb_t
-> #aLen:size_nat{aLen + aLen <= max_size_t}
-> a:lbignum t aLen ->
lbignum t (aLen + aLen) | val bn_karatsuba_sqr:
#t:limb_t
-> #aLen:size_nat{aLen + aLen <= max_size_t}
-> a:lbignum t aLen ->
lbignum t (aLen + aLen) | let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 142,
"start_col": 0,
"start_line": 141
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen
-> Hacl.Spec.Bignum.Definitions.lbignum t (aLen + aLen) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.max_size_t",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr"
] | [] | false | false | false | false | false | let bn_karatsuba_sqr #t #aLen a =
| Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_sqr_lemma | val bn_sqr_lemma:
#t:limb_t
-> #aLen:size_nat{aLen + aLen <= max_size_t}
-> a:lbignum t aLen ->
Lemma (bn_sqr a == bn_mul a a /\ bn_v (bn_sqr a) == bn_v a * bn_v a) | val bn_sqr_lemma:
#t:limb_t
-> #aLen:size_nat{aLen + aLen <= max_size_t}
-> a:lbignum t aLen ->
Lemma (bn_sqr a == bn_mul a a /\ bn_v (bn_sqr a) == bn_v a * bn_v a) | let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 42,
"end_line": 139,
"start_col": 0,
"start_line": 138
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Bignum.bn_sqr a == Hacl.Spec.Bignum.bn_mul a a /\
Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.Bignum.bn_sqr a) ==
Hacl.Spec.Bignum.Definitions.bn_v a * Hacl.Spec.Bignum.Definitions.bn_v a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.max_size_t",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Squaring.bn_sqr_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let bn_sqr_lemma #t #aLen a =
| Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_karatsuba_mul_lemma | val bn_karatsuba_mul_lemma:
#t:limb_t
-> #aLen:size_nat{aLen + aLen <= max_size_t}
-> a:lbignum t aLen
-> b:lbignum t aLen ->
Lemma (bn_karatsuba_mul a b == bn_mul a b /\
bn_v (bn_karatsuba_mul a b) == bn_v a * bn_v b) | val bn_karatsuba_mul_lemma:
#t:limb_t
-> #aLen:size_nat{aLen + aLen <= max_size_t}
-> a:lbignum t aLen
-> b:lbignum t aLen ->
Lemma (bn_karatsuba_mul a b == bn_mul a b /\
bn_v (bn_karatsuba_mul a b) == bn_v a * bn_v b) | let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 133,
"start_col": 0,
"start_line": 132
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b: Hacl.Spec.Bignum.Definitions.lbignum t aLen
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Bignum.bn_karatsuba_mul a b == Hacl.Spec.Bignum.bn_mul a b /\
Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.Bignum.bn_karatsuba_mul a b) ==
Hacl.Spec.Bignum.Definitions.bn_v a * Hacl.Spec.Bignum.Definitions.bn_v b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.max_size_t",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let bn_karatsuba_mul_lemma #t #aLen a b =
| Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b | false |
Steel.ST.HigherArray.fst | Steel.ST.HigherArray.blit_ptr | val blit_ptr (#t:_) (#p0:perm) (#s0 #s1:Ghost.erased (Seq.seq t))
(src:ptr t)
(len_src: Ghost.erased nat { offset src + len_src <= base_len (base src) })
(idx_src: US.t)
(dst:ptr t)
(len_dst: Ghost.erased nat { offset dst + len_dst <= base_len (base dst) })
(idx_dst: US.t)
(len: US.t)
: ST unit
(pts_to (| src, len_src |) p0 s0 `star` pts_to (| dst, len_dst |) full_perm s1)
(fun _ -> pts_to (| src, len_src |) p0 s0 `star` exists_ (fun s1' ->
pts_to (| dst, len_dst |) full_perm s1' `star`
pure (blit_post s0 s1 (| src, len_src |) idx_src (| dst, len_dst |) idx_dst len s1')
))
(
US.v idx_src + US.v len <= len_src /\
US.v idx_dst + US.v len <= len_dst
)
(fun _ -> True) | val blit_ptr (#t:_) (#p0:perm) (#s0 #s1:Ghost.erased (Seq.seq t))
(src:ptr t)
(len_src: Ghost.erased nat { offset src + len_src <= base_len (base src) })
(idx_src: US.t)
(dst:ptr t)
(len_dst: Ghost.erased nat { offset dst + len_dst <= base_len (base dst) })
(idx_dst: US.t)
(len: US.t)
: ST unit
(pts_to (| src, len_src |) p0 s0 `star` pts_to (| dst, len_dst |) full_perm s1)
(fun _ -> pts_to (| src, len_src |) p0 s0 `star` exists_ (fun s1' ->
pts_to (| dst, len_dst |) full_perm s1' `star`
pure (blit_post s0 s1 (| src, len_src |) idx_src (| dst, len_dst |) idx_dst len s1')
))
(
US.v idx_src + US.v len <= len_src /\
US.v idx_dst + US.v len <= len_dst
)
(fun _ -> True) | let blit_ptr
src len_src idx_src dst len_dst idx_dst len
= blit0 _ idx_src _ idx_dst len | {
"file_name": "lib/steel/Steel.ST.HigherArray.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 31,
"end_line": 690,
"start_col": 0,
"start_line": 688
} | (*
Copyright 2022 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.ST.HigherArray
module P = Steel.PCMFrac
module R = Steel.ST.PCMReference
module M = FStar.Map
module PM = Steel.PCMMap
[@@noextract_to "krml"]
let index_t (len: Ghost.erased nat) : Tot Type0 =
(i: nat { i < len })
[@@noextract_to "krml"]
let carrier (elt: Type u#a) (len: Ghost.erased nat) : Tot Type =
PM.map (index_t len) (P.fractional elt)
[@@noextract_to "krml"]
let pcm (elt: Type u#a) (len: Ghost.erased nat) : Tot (P.pcm (carrier elt len)) =
PM.pointwise (index_t len) (P.pcm_frac #elt)
[@@noextract_to "krml"]
let one (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.one
let composable (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.composable
[@@noextract_to "krml"]
let compose (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.op
[@@noextract_to "krml"]
let mk_carrier
(#elt: Type)
(len: nat)
(offset: nat)
(s: Seq.seq elt)
(p: P.perm)
: Tot (carrier elt len)
= let f (i: nat) : Tot (P.fractional elt) =
if offset + Seq.length s > len || i < offset || i >= offset + Seq.length s
then None
else Some (Seq.index s (i - offset), p)
in
M.map_literal f
let mk_carrier_inj
(#elt: Type)
(len: nat)
(offset: nat)
(s1 s2: Seq.seq elt)
(p1 p2: P.perm)
: Lemma
(requires (
mk_carrier len offset s1 p1 == mk_carrier len offset s2 p2 /\
offset + Seq.length s1 <= len /\
offset + Seq.length s2 <= len
))
(ensures (
s1 `Seq.equal` s2 /\
(Seq.length s1 > 0 ==> p1 == p2)
))
= assert (forall (i: nat) . i < Seq.length s1 ==>
(M.sel (mk_carrier len offset s1 p1) (offset + i) == Some (Seq.index s1 i, p1)));
assert (forall (i: nat) . i < Seq.length s2 ==>
M.sel (mk_carrier len offset s2 p2) (offset + i) == Some (Seq.index s2 i, p2))
[@@erasable]
let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: US.t & ref _ (pcm elt (US.v base_len)))
let base_len (#elt: Type) (b: base_t elt) : GTot nat = US.v (dfst b)
[@@noextract_to "krml"]
noeq
type ptr (elt: Type u#a) : Type0 = {
base_len: Ghost.erased US.t;
// U32.t to prove that A.read, A.write offset computation does not overflow. TODO: replace U32.t with size_t
base: (r: ref _ (pcm elt (US.v base_len)) { core_ref_is_null r ==> US.v base_len == 0 });
offset: (offset: nat { offset <= US.v base_len });
}
let null_ptr a = { base_len = 0sz; base = null #_ #(pcm a 0) ; offset = 0 }
let is_null_ptr p = is_null p.base
let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |)
let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset
let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma
(requires (
base p1 == base p2 /\
offset p1 == offset p2
))
(ensures (
p1 == p2
))
= ()
let base_len_null_ptr _ = ()
let length_fits #elt a = ()
let valid_perm
(len: nat)
(offset: nat)
(slice_len: nat)
(p: P.perm) : Tot prop =
let open FStar.Real in
((offset + slice_len <= len /\ slice_len > 0) ==> (p.P.v <=. one))
[@__reduce__]
let pts_to0 (#elt: Type u#1) (a: array elt) (p: P.perm) (s: Seq.seq elt) : Tot vprop =
R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p) `star`
pure (
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\
Seq.length s == length a
)
let pts_to (#elt: Type u#1) (a: array elt) ([@@@ smt_fallback ] p: P.perm) ([@@@ smt_fallback ] s: Seq.seq elt) : Tot vprop =
pts_to0 a p s
// this lemma is necessary because Steel.PCMReference is marked unfold
let change_r_pts_to
(#opened: _)
(#carrier: Type u#1)
(#pcm: P.pcm carrier)
(p: ref carrier pcm)
(v: carrier)
(#carrier': Type u#1)
(#pcm': P.pcm carrier')
(p': ref carrier' pcm')
(v': carrier')
: STGhost unit opened
(R.pts_to p v)
(fun _ -> R.pts_to p' v')
(// keep on distinct lines for error messages
carrier == carrier' /\
pcm == pcm' /\
p == p' /\
v == v')
(fun _ -> True)
= rewrite
(R.pts_to p v)
(R.pts_to p' v')
let intro_pts_to (#opened: _) (#elt: Type u#1) (a: array elt) (#v: _) (p: P.perm) (s: Seq.seq elt) : STGhost unit opened
(R.pts_to (ptr_of a).base v)
(fun _ -> pts_to a p s)
(
v == mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p /\
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\
Seq.length s == length a
)
(fun _ -> True)
= change_r_pts_to (ptr_of a).base v (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p);
intro_pure _;
rewrite
(pts_to0 a p s)
(pts_to a p s)
let elim_pts_to (#opened: _) (#elt: Type u#1) (a: array elt) (p: P.perm) (s: Seq.seq elt) : STGhost unit opened
(pts_to a p s)
(fun _ -> R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p))
(True)
(fun _ ->
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\
Seq.length s == length a
)
= rewrite
(pts_to a p s)
(pts_to0 a p s);
elim_pure _
let pts_to_length
a s
=
elim_pts_to a _ s;
intro_pts_to a _ s
let pts_to_not_null
a s
= elim_pts_to a _ s;
R.pts_to_not_null _ _;
intro_pts_to a _ s
let mk_carrier_joinable
(#elt: Type)
(len: nat)
(offset: nat)
(s1: Seq.seq elt)
(p1: P.perm)
(s2: Seq.seq elt)
(p2: P.perm)
: Lemma
(requires (
offset + Seq.length s1 <= len /\
Seq.length s1 == Seq.length s2 /\
P.joinable (pcm elt len) (mk_carrier len offset s1 p1) (mk_carrier len offset s2 p2)
))
(ensures (
s1 `Seq.equal` s2
))
=
let lem
(i: nat { 0 <= i /\ i < Seq.length s1 })
: Lemma
(Seq.index s1 i == Seq.index s2 i)
[SMTPat (Seq.index s1 i); SMTPat (Seq.index s2 i)]
= assert (
forall z . (
P.compatible (pcm elt len) (mk_carrier len offset s1 p1) z /\
P.compatible (pcm elt len) (mk_carrier len offset s2 p2) z
) ==>
begin match M.sel z (offset + i) with
| None -> False
| Some (v, _) -> v == Seq.index s1 i /\ v == Seq.index s2 i
end
)
in
()
let pure_star_interp' (p:slprop u#a) (q:prop) (m:mem)
: Lemma (interp (p `Steel.Memory.star` Steel.Memory.pure q) m <==>
interp p m /\ q)
= pure_star_interp p q m;
emp_unit p
let pts_to_inj
a p1 s1 p2 s2 m
=
Classical.forall_intro reveal_pure;
pure_star_interp'
(hp_of (R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s1 p1)))
(
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s1) p1 /\
Seq.length s1 == length a
)
m;
pure_star_interp'
(hp_of (R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s2 p2)))
(
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s2) p2 /\
Seq.length s2 == length a
)
m;
pts_to_join
(ptr_of a).base
(mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s1 p1)
(mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s2 p2)
m;
mk_carrier_joinable (US.v (ptr_of a).base_len) (ptr_of a).offset s1 p1 s2 p2
[@@noextract_to "krml"]
let malloc0
(#elt: Type)
(x: elt)
(n: US.t)
: ST (array elt)
emp
(fun a -> pts_to a P.full_perm (Seq.create (US.v n) x))
(True)
(fun a ->
length a == US.v n /\
base_len (base (ptr_of a)) == US.v n
)
=
let c : carrier elt (US.v n) = mk_carrier (US.v n) 0 (Seq.create (US.v n) x) P.full_perm in
let base : ref (carrier elt (US.v n)) (pcm elt (US.v n)) = R.alloc c in
R.pts_to_not_null base _;
let p = {
base_len = n;
base = base;
offset = 0;
}
in
let a = (| p, Ghost.hide (US.v n) |) in
change_r_pts_to
base c
(ptr_of a).base c;
intro_pts_to a P.full_perm (Seq.create (US.v n) x);
return a
let malloc_ptr
x n
=
let a = malloc0 x n in
let (| p, _ |) = a in
rewrite
(pts_to _ _ _)
(pts_to (| p, Ghost.hide (US.v n) |) _ _);
return p
[@@noextract_to "krml"]
let free0
(#elt: Type)
(#s: Ghost.erased (Seq.seq elt))
(a: array elt)
: ST unit
(pts_to a P.full_perm s)
(fun _ -> emp)
(
length a == base_len (base (ptr_of a))
)
(fun _ -> True)
= drop (pts_to a _ _)
let free_ptr a =
free0 _
let valid_sum_perm
(len: nat)
(offset: nat)
(slice_len: nat)
(p1 p2: P.perm)
: Tot prop
= let open FStar.Real in
valid_perm len offset slice_len (P.sum_perm p1 p2)
let mk_carrier_share
(#elt: Type)
(len: nat)
(offset: nat)
(s: Seq.seq elt)
(p1 p2: P.perm)
: Lemma
(requires (valid_sum_perm len offset (Seq.length s) p1 p2))
(ensures (
let c1 = mk_carrier len offset s p1 in
let c2 = mk_carrier len offset s p2 in
composable c1 c2 /\
mk_carrier len offset s (p1 `P.sum_perm` p2) `M.equal` (c1 `compose` c2)
))
= ()
let share
#_ #_ #x a p p1 p2
= elim_pts_to a p x;
mk_carrier_share (US.v (ptr_of a).base_len) (ptr_of a).offset x p1 p2;
R.split (ptr_of a).base _
(mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset x p1)
(mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset x p2);
intro_pts_to a p1 x;
intro_pts_to a p2 x
let mk_carrier_gather
(#elt: Type)
(len: nat)
(offset: nat)
(s1 s2: Seq.seq elt)
(p1 p2: P.perm)
: Lemma
(requires (
let c1 = mk_carrier len offset s1 p1 in
let c2 = mk_carrier len offset s2 p2 in
composable c1 c2 /\
Seq.length s1 == Seq.length s2 /\
offset + Seq.length s1 <= len
))
(ensures (
let c1 = mk_carrier len offset s1 p1 in
let c2 = mk_carrier len offset s2 p2 in
composable c1 c2 /\
mk_carrier len offset s1 (p1 `P.sum_perm` p2) == (c1 `compose` c2) /\
mk_carrier len offset s2 (p1 `P.sum_perm` p2) == (c1 `compose` c2) /\
s1 == s2
))
=
let c1 = mk_carrier len offset s1 p1 in
let c2 = mk_carrier len offset s2 p2 in
assert (composable c1 c2);
assert (mk_carrier len offset s1 (p1 `P.sum_perm` p2) `M.equal` (c1 `compose` c2));
assert (mk_carrier len offset s2 (p1 `P.sum_perm` p2) `M.equal` (c1 `compose` c2));
mk_carrier_inj len offset s1 s2 (p1 `P.sum_perm` p2) (p1 `P.sum_perm` p2)
let mk_carrier_valid_sum_perm
(#elt: Type)
(len: nat)
(offset: nat)
(s: Seq.seq elt)
(p1 p2: P.perm)
: Lemma
(let c1 = mk_carrier len offset s p1 in
let c2 = mk_carrier len offset s p2 in
composable c1 c2 <==> valid_sum_perm len offset (Seq.length s) p1 p2)
= let c1 = mk_carrier len offset s p1 in
let c2 = mk_carrier len offset s p2 in
if Seq.length s > 0 && offset + Seq.length s <= len
then
let open FStar.Real in
assert (P.composable (M.sel c1 offset) (M.sel c2 offset) <==> valid_perm len offset (Seq.length s) (P.sum_perm p1 p2))
else ()
let gather
a #x1 p1 #x2 p2
= elim_pts_to a p1 x1;
elim_pts_to a p2 x2;
let _ = R.gather (ptr_of a).base
(mk_carrier (US.v (ptr_of a).base_len) ((ptr_of a).offset) x1 p1)
(mk_carrier (US.v (ptr_of a).base_len) ((ptr_of a).offset) x2 p2)
in
mk_carrier_gather (US.v (ptr_of a).base_len) ((ptr_of a).offset) x1 x2 p1 p2;
mk_carrier_valid_sum_perm (US.v (ptr_of a).base_len) ((ptr_of a).offset) x1 p1 p2;
intro_pts_to a (p1 `P.sum_perm` p2) x1
#push-options "--z3rlimit 16"
[@@noextract_to "krml"]
let index0
(#t: Type) (#p: P.perm)
(a: array t)
(#s: Ghost.erased (Seq.seq t))
(i: US.t)
: ST t
(pts_to a p s)
(fun _ -> pts_to a p s)
(US.v i < length a \/ US.v i < Seq.length s)
(fun res -> Seq.length s == length a /\ US.v i < Seq.length s /\ res == Seq.index s (US.v i))
= elim_pts_to a p s;
let s' = R.read (ptr_of a).base _ in
let res = fst (Some?.v (M.sel s' ((ptr_of a).offset + US.v i))) in
intro_pts_to a p s;
return res
#pop-options
let index_ptr a i =
index0 _ i
let mk_carrier_upd
(#elt: Type)
(len: nat)
(offset: nat)
(s: Seq.seq elt)
(i: nat)
(v: elt)
(_: squash (
offset + Seq.length s <= len /\
i < Seq.length s
))
: Lemma
(ensures (
let o = mk_carrier len offset s P.full_perm in
let o' = mk_carrier len offset (Seq.upd s i v) P.full_perm in
o' `Map.equal` Map.upd o (offset + i) (Some (v, P.full_perm))
))
= ()
#push-options "--z3rlimit 20"
[@@noextract_to "krml"]
let upd0
(#t: Type)
(a: array t)
(#s: Ghost.erased (Seq.seq t))
(i: US.t { US.v i < Seq.length s })
(v: t)
: STT unit
(pts_to a P.full_perm s)
(fun res -> pts_to a P.full_perm (Seq.upd s (US.v i) v))
= elim_pts_to a _ _;
mk_carrier_upd (US.v (ptr_of a).base_len) ((ptr_of a).offset) s (US.v i) v ();
R.upd_gen
(ptr_of a).base
_ _
(PM.lift_frame_preserving_upd
_ _
(P.mk_frame_preserving_upd
(Seq.index s (US.v i))
v
)
_ ((ptr_of a).offset + US.v i)
);
intro_pts_to a _ _
#pop-options
let upd_ptr a i v =
upd0 _ i v;
rewrite
(pts_to _ _ _)
(pts_to _ _ _)
let mk_carrier_merge
(#elt: Type)
(len: nat)
(offset: nat)
(s1 s2: Seq.seq elt)
(p: P.perm)
: Lemma
(requires (
offset + Seq.length s1 + Seq.length s2 <= len
))
(ensures (
let c1 = mk_carrier len offset s1 p in
let c2 = mk_carrier len (offset + Seq.length s1) s2 p in
composable c1 c2 /\
mk_carrier len offset (s1 `Seq.append` s2) p `M.equal` (c1 `compose` c2)
))
= ()
let ghost_join
#_ #_ #x1 #x2 #p a1 a2 h
= elim_pts_to a1 p x1;
elim_pts_to a2 p x2;
mk_carrier_merge (US.v (ptr_of a1).base_len) ((ptr_of a1).offset) x1 x2 (p);
change_r_pts_to
(ptr_of a2).base _
(ptr_of a1).base (mk_carrier (US.v (ptr_of a1).base_len) ((ptr_of a1).offset + Seq.length x1) x2 p);
R.gather (ptr_of a1).base
(mk_carrier (US.v (ptr_of a1).base_len) ((ptr_of a1).offset) x1 (p))
(mk_carrier (US.v (ptr_of a1).base_len) ((ptr_of a1).offset + Seq.length x1) x2 (p));
change_r_pts_to
(ptr_of a1).base _
(ptr_of (merge a1 a2)).base (mk_carrier (US.v (ptr_of (merge a1 a2)).base_len) ((ptr_of (merge a1 a2)).offset) (x1 `Seq.append` x2) (p));
intro_pts_to (merge a1 a2) p (Seq.append x1 x2)
let mk_carrier_split
(#elt: Type)
(len: nat)
(offset: nat)
(s: Seq.seq elt)
(p: P.perm)
(i: nat)
: Lemma
(requires (
offset + Seq.length s <= len /\
i <= Seq.length s
))
(ensures (
let c1 = mk_carrier len offset (Seq.slice s 0 i) p in
let c2 = mk_carrier len (offset + i) (Seq.slice s i (Seq.length s)) p in
composable c1 c2 /\
mk_carrier len offset s p `M.equal` (c1 `compose` c2)
))
= ()
// TODO: replace with Ghost, introduce pointer shifting operations in SteelAtomicBase Unobservable
[@@noextract_to "krml"]
let ptr_shift
(#elt: Type)
(p: ptr elt)
(off: US.t)
: Pure (ptr elt)
(requires (offset p + US.v off <= base_len (base p)))
(ensures (fun p' ->
base p' == base p /\
offset p' == offset p + US.v off
))
= {
base_len = p.base_len;
base = p.base;
offset = p.offset + US.v off;
}
let ghost_split
#_ #_ #x #p a i
=
elim_pts_to a p x;
mk_carrier_split
(US.v (ptr_of a).base_len)
((ptr_of a).offset)
x
(p)
(US.v i);
Seq.lemma_split x (US.v i);
let xl = Seq.slice x 0 (US.v i) in
let xr = Seq.slice x (US.v i) (Seq.length x) in
let vl = mk_carrier (US.v (ptr_of a).base_len) ((ptr_of a).offset) xl (p) in
let vr = mk_carrier (US.v (ptr_of a).base_len) ((ptr_of a).offset + US.v i) xr (p) in
R.split (ptr_of a).base _ vl vr;
change_r_pts_to
(ptr_of a).base vl
(ptr_of (split_l a i)).base vl;
intro_pts_to (split_l a i) #vl p (Seq.slice x 0 (US.v i));
change_r_pts_to
(ptr_of a).base vr
(ptr_of (split_r a i)).base vr;
intro_pts_to (split_r a i) #vr p (Seq.slice x (US.v i) (Seq.length x))
////////////////////////////////////////////////////////////////////////////////
// memcpy
////////////////////////////////////////////////////////////////////////////////
let prefix_copied #t
(e0:Seq.seq t)
(e1:Seq.seq t)
(i:nat { i <= Seq.length e0 /\ Seq.length e0 == Seq.length e1})
: Seq.seq t
= (Seq.append (Seq.slice e0 0 i) (Seq.slice e1 i (Seq.length e1)))
#push-options "--z3rlimit 32"
val memcpy0 (#t:_) (#p0:perm)
(a0 a1:array t)
(#s0 #s1:Ghost.erased (Seq.seq t))
(l:US.t { US.v l == length a0 /\ length a0 == length a1 } )
: STT unit
(pts_to a0 p0 s0 `star` pts_to a1 full_perm s1)
(fun _ -> pts_to a0 p0 s0 `star` pts_to a1 full_perm s0)
let memcpy0
#t #p0 a0 a1 #e0 #e1 i
=
pts_to_length a0 _;
pts_to_length a1 _;
let inv (j:Steel.ST.Loops.nat_at_most i)
: vprop
= pts_to a0 p0 e0 `star`
pts_to a1 full_perm (prefix_copied e0 e1 j)
in
assert (prefix_copied e0 e1 0 `Seq.equal` e1);
rewrite (pts_to a1 full_perm e1)
(pts_to a1 full_perm (prefix_copied e0 e1 0));
rewrite (pts_to a0 _ e0 `star` pts_to a1 full_perm (prefix_copied e0 e1 0))
(inv (US.v 0sz));
let body (j:Steel.ST.Loops.u32_between 0sz i)
: STT unit
(inv (US.v j))
(fun _ -> inv (US.v j + 1))
= rewrite
(inv (US.v j))
(pts_to a0 p0 e0 `star`
pts_to a1 full_perm (prefix_copied e0 e1 (US.v j)));
let z = index a0 j in
upd a1 j z;
assert (Seq.upd (prefix_copied e0 e1 (US.v j)) (US.v j) z `Seq.equal`
prefix_copied e0 e1 (US.v j + 1));
rewrite (pts_to a0 _ e0 `star` pts_to a1 _ _)
(inv (US.v j + 1));
return ()
in
Steel.ST.Loops.for_loop 0sz i inv body;
assert_ (inv (US.v i));
rewrite (inv (US.v i))
(pts_to a0 p0 e0 `star`
pts_to a1 full_perm (prefix_copied e0 e1 (US.v i)));
assert (prefix_copied e0 e1 (US.v i) `Seq.equal` e0);
rewrite (pts_to a1 _ (prefix_copied e0 e1 (US.v i)))
(pts_to a1 _ e0);
return ()
#pop-options
#push-options "--z3rlimit 48"
#push-options "--z3rlimit 75"
let blit0 (#t:_) (#p0:perm) (#s0 #s1:Ghost.erased (Seq.seq t))
(src:array t)
(idx_src: US.t)
(dst:array t)
(idx_dst: US.t)
(len: US.t)
: ST unit
(pts_to src p0 s0 `star` pts_to dst full_perm s1)
(fun _ -> pts_to src p0 s0 `star` exists_ (fun s1' ->
pts_to dst full_perm s1' `star`
pure (blit_post s0 s1 src idx_src dst idx_dst len s1')
))
(
US.v idx_src + US.v len <= length src /\
US.v idx_dst + US.v len <= length dst
)
(fun _ -> True)
= pts_to_length src s0;
pts_to_length dst s1;
let _ = ghost_split src idx_src in
let _ = ghost_split (split_r src idx_src) len in
let _ = ghost_split dst idx_dst in
let _ = ghost_split (split_r dst idx_dst) len in
memcpy0 (split_l (split_r src idx_src) len) (split_l (split_r dst idx_dst) len) len;
ghost_join (split_l (split_r dst _) _) (split_r (split_r dst _) _) ();
ghost_join (split_l dst _) (merge _ _) ();
vpattern_rewrite #_ #_ #(merge _ _) (fun a -> pts_to a _ _) dst;
ghost_join (split_l (split_r src _) _) (split_r (split_r src _) _) ();
ghost_join (split_l src _) (merge _ _) ();
vpattern_rewrite #_ #_ #(merge _ _) (fun a -> pts_to a _ _) src;
vpattern_rewrite (pts_to src _) (Ghost.reveal s0);
noop ()
#pop-options
#pop-options | {
"checked_file": "/",
"dependencies": [
"Steel.ST.PCMReference.fsti.checked",
"Steel.ST.Loops.fsti.checked",
"Steel.PCMMap.fst.checked",
"Steel.PCMFrac.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.HigherArray.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.PCMMap",
"short_module": "PM"
},
{
"abbrev": true,
"full_module": "FStar.Map",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Steel.ST.PCMReference",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "Steel.PCMFrac",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
src: Steel.ST.HigherArray.ptr t ->
len_src:
FStar.Ghost.erased Prims.nat
{ Steel.ST.HigherArray.offset src + FStar.Ghost.reveal len_src <=
Steel.ST.HigherArray.base_len (Steel.ST.HigherArray.base src) } ->
idx_src: FStar.SizeT.t ->
dst: Steel.ST.HigherArray.ptr t ->
len_dst:
FStar.Ghost.erased Prims.nat
{ Steel.ST.HigherArray.offset dst + FStar.Ghost.reveal len_dst <=
Steel.ST.HigherArray.base_len (Steel.ST.HigherArray.base dst) } ->
idx_dst: FStar.SizeT.t ->
len: FStar.SizeT.t
-> Steel.ST.Effect.ST Prims.unit | Steel.ST.Effect.ST | [] | [] | [
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Steel.ST.HigherArray.ptr",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Steel.ST.HigherArray.offset",
"FStar.Ghost.reveal",
"Steel.ST.HigherArray.base_len",
"Steel.ST.HigherArray.base",
"FStar.SizeT.t",
"Steel.ST.HigherArray.blit0",
"Prims.Mkdtuple2",
"Prims.unit"
] | [] | false | true | false | false | false | let blit_ptr src len_src idx_src dst len_dst idx_dst len =
| blit0 _ idx_src _ idx_dst len | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_karatsuba_sqr_lemma | val bn_karatsuba_sqr_lemma:
#t:limb_t
-> #aLen:size_nat{aLen + aLen <= max_size_t}
-> a:lbignum t aLen ->
Lemma (bn_karatsuba_sqr a == bn_mul a a /\
bn_v (bn_karatsuba_sqr a) == bn_v a * bn_v a) | val bn_karatsuba_sqr_lemma:
#t:limb_t
-> #aLen:size_nat{aLen + aLen <= max_size_t}
-> a:lbignum t aLen ->
Lemma (bn_karatsuba_sqr a == bn_mul a a /\
bn_v (bn_karatsuba_sqr a) == bn_v a * bn_v a) | let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 53,
"end_line": 145,
"start_col": 0,
"start_line": 144
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Bignum.bn_karatsuba_sqr a == Hacl.Spec.Bignum.bn_mul a a /\
Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.Bignum.bn_karatsuba_sqr a) ==
Hacl.Spec.Bignum.Definitions.bn_v a * Hacl.Spec.Bignum.Definitions.bn_v a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.max_size_t",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let bn_karatsuba_sqr_lemma #t #aLen a =
| Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a | false |
Steel.ST.HigherArray.fst | Steel.ST.HigherArray.ptrdiff_ptr | val ptrdiff_ptr (#t:_) (#p0 #p1:perm) (#s0 #s1:Ghost.erased (Seq.seq t))
(a0:ptr t)
(len0: Ghost.erased nat { offset a0 + len0 <= base_len (base a0) })
(a1:ptr t)
(len1: Ghost.erased nat { offset a1 + len1 <= base_len (base a1) })
: ST UP.t
(pts_to (| a0, len0 |) p0 s0 `star` pts_to (| a1, len1 |) p1 s1)
(fun _ -> pts_to (| a0, len0 |) p0 s0 `star` pts_to (| a1, len1 |) p1 s1)
(base a0 == base a1 /\ UP.fits (offset a0 - offset a1))
(fun r -> UP.v r == offset a0 - offset a1) | val ptrdiff_ptr (#t:_) (#p0 #p1:perm) (#s0 #s1:Ghost.erased (Seq.seq t))
(a0:ptr t)
(len0: Ghost.erased nat { offset a0 + len0 <= base_len (base a0) })
(a1:ptr t)
(len1: Ghost.erased nat { offset a1 + len1 <= base_len (base a1) })
: ST UP.t
(pts_to (| a0, len0 |) p0 s0 `star` pts_to (| a1, len1 |) p1 s1)
(fun _ -> pts_to (| a0, len0 |) p0 s0 `star` pts_to (| a1, len1 |) p1 s1)
(base a0 == base a1 /\ UP.fits (offset a0 - offset a1))
(fun r -> UP.v r == offset a0 - offset a1) | let ptrdiff_ptr a0 len0 a1 len1 =
let res = a0.offset - a1.offset in
return (UP.int_to_t res) | {
"file_name": "lib/steel/Steel.ST.HigherArray.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 26,
"end_line": 700,
"start_col": 0,
"start_line": 698
} | (*
Copyright 2022 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.ST.HigherArray
module P = Steel.PCMFrac
module R = Steel.ST.PCMReference
module M = FStar.Map
module PM = Steel.PCMMap
[@@noextract_to "krml"]
let index_t (len: Ghost.erased nat) : Tot Type0 =
(i: nat { i < len })
[@@noextract_to "krml"]
let carrier (elt: Type u#a) (len: Ghost.erased nat) : Tot Type =
PM.map (index_t len) (P.fractional elt)
[@@noextract_to "krml"]
let pcm (elt: Type u#a) (len: Ghost.erased nat) : Tot (P.pcm (carrier elt len)) =
PM.pointwise (index_t len) (P.pcm_frac #elt)
[@@noextract_to "krml"]
let one (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.one
let composable (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.composable
[@@noextract_to "krml"]
let compose (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.op
[@@noextract_to "krml"]
let mk_carrier
(#elt: Type)
(len: nat)
(offset: nat)
(s: Seq.seq elt)
(p: P.perm)
: Tot (carrier elt len)
= let f (i: nat) : Tot (P.fractional elt) =
if offset + Seq.length s > len || i < offset || i >= offset + Seq.length s
then None
else Some (Seq.index s (i - offset), p)
in
M.map_literal f
let mk_carrier_inj
(#elt: Type)
(len: nat)
(offset: nat)
(s1 s2: Seq.seq elt)
(p1 p2: P.perm)
: Lemma
(requires (
mk_carrier len offset s1 p1 == mk_carrier len offset s2 p2 /\
offset + Seq.length s1 <= len /\
offset + Seq.length s2 <= len
))
(ensures (
s1 `Seq.equal` s2 /\
(Seq.length s1 > 0 ==> p1 == p2)
))
= assert (forall (i: nat) . i < Seq.length s1 ==>
(M.sel (mk_carrier len offset s1 p1) (offset + i) == Some (Seq.index s1 i, p1)));
assert (forall (i: nat) . i < Seq.length s2 ==>
M.sel (mk_carrier len offset s2 p2) (offset + i) == Some (Seq.index s2 i, p2))
[@@erasable]
let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: US.t & ref _ (pcm elt (US.v base_len)))
let base_len (#elt: Type) (b: base_t elt) : GTot nat = US.v (dfst b)
[@@noextract_to "krml"]
noeq
type ptr (elt: Type u#a) : Type0 = {
base_len: Ghost.erased US.t;
// U32.t to prove that A.read, A.write offset computation does not overflow. TODO: replace U32.t with size_t
base: (r: ref _ (pcm elt (US.v base_len)) { core_ref_is_null r ==> US.v base_len == 0 });
offset: (offset: nat { offset <= US.v base_len });
}
let null_ptr a = { base_len = 0sz; base = null #_ #(pcm a 0) ; offset = 0 }
let is_null_ptr p = is_null p.base
let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |)
let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset
let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma
(requires (
base p1 == base p2 /\
offset p1 == offset p2
))
(ensures (
p1 == p2
))
= ()
let base_len_null_ptr _ = ()
let length_fits #elt a = ()
let valid_perm
(len: nat)
(offset: nat)
(slice_len: nat)
(p: P.perm) : Tot prop =
let open FStar.Real in
((offset + slice_len <= len /\ slice_len > 0) ==> (p.P.v <=. one))
[@__reduce__]
let pts_to0 (#elt: Type u#1) (a: array elt) (p: P.perm) (s: Seq.seq elt) : Tot vprop =
R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p) `star`
pure (
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\
Seq.length s == length a
)
let pts_to (#elt: Type u#1) (a: array elt) ([@@@ smt_fallback ] p: P.perm) ([@@@ smt_fallback ] s: Seq.seq elt) : Tot vprop =
pts_to0 a p s
// this lemma is necessary because Steel.PCMReference is marked unfold
let change_r_pts_to
(#opened: _)
(#carrier: Type u#1)
(#pcm: P.pcm carrier)
(p: ref carrier pcm)
(v: carrier)
(#carrier': Type u#1)
(#pcm': P.pcm carrier')
(p': ref carrier' pcm')
(v': carrier')
: STGhost unit opened
(R.pts_to p v)
(fun _ -> R.pts_to p' v')
(// keep on distinct lines for error messages
carrier == carrier' /\
pcm == pcm' /\
p == p' /\
v == v')
(fun _ -> True)
= rewrite
(R.pts_to p v)
(R.pts_to p' v')
let intro_pts_to (#opened: _) (#elt: Type u#1) (a: array elt) (#v: _) (p: P.perm) (s: Seq.seq elt) : STGhost unit opened
(R.pts_to (ptr_of a).base v)
(fun _ -> pts_to a p s)
(
v == mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p /\
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\
Seq.length s == length a
)
(fun _ -> True)
= change_r_pts_to (ptr_of a).base v (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p);
intro_pure _;
rewrite
(pts_to0 a p s)
(pts_to a p s)
let elim_pts_to (#opened: _) (#elt: Type u#1) (a: array elt) (p: P.perm) (s: Seq.seq elt) : STGhost unit opened
(pts_to a p s)
(fun _ -> R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p))
(True)
(fun _ ->
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\
Seq.length s == length a
)
= rewrite
(pts_to a p s)
(pts_to0 a p s);
elim_pure _
let pts_to_length
a s
=
elim_pts_to a _ s;
intro_pts_to a _ s
let pts_to_not_null
a s
= elim_pts_to a _ s;
R.pts_to_not_null _ _;
intro_pts_to a _ s
let mk_carrier_joinable
(#elt: Type)
(len: nat)
(offset: nat)
(s1: Seq.seq elt)
(p1: P.perm)
(s2: Seq.seq elt)
(p2: P.perm)
: Lemma
(requires (
offset + Seq.length s1 <= len /\
Seq.length s1 == Seq.length s2 /\
P.joinable (pcm elt len) (mk_carrier len offset s1 p1) (mk_carrier len offset s2 p2)
))
(ensures (
s1 `Seq.equal` s2
))
=
let lem
(i: nat { 0 <= i /\ i < Seq.length s1 })
: Lemma
(Seq.index s1 i == Seq.index s2 i)
[SMTPat (Seq.index s1 i); SMTPat (Seq.index s2 i)]
= assert (
forall z . (
P.compatible (pcm elt len) (mk_carrier len offset s1 p1) z /\
P.compatible (pcm elt len) (mk_carrier len offset s2 p2) z
) ==>
begin match M.sel z (offset + i) with
| None -> False
| Some (v, _) -> v == Seq.index s1 i /\ v == Seq.index s2 i
end
)
in
()
let pure_star_interp' (p:slprop u#a) (q:prop) (m:mem)
: Lemma (interp (p `Steel.Memory.star` Steel.Memory.pure q) m <==>
interp p m /\ q)
= pure_star_interp p q m;
emp_unit p
let pts_to_inj
a p1 s1 p2 s2 m
=
Classical.forall_intro reveal_pure;
pure_star_interp'
(hp_of (R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s1 p1)))
(
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s1) p1 /\
Seq.length s1 == length a
)
m;
pure_star_interp'
(hp_of (R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s2 p2)))
(
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s2) p2 /\
Seq.length s2 == length a
)
m;
pts_to_join
(ptr_of a).base
(mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s1 p1)
(mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s2 p2)
m;
mk_carrier_joinable (US.v (ptr_of a).base_len) (ptr_of a).offset s1 p1 s2 p2
[@@noextract_to "krml"]
let malloc0
(#elt: Type)
(x: elt)
(n: US.t)
: ST (array elt)
emp
(fun a -> pts_to a P.full_perm (Seq.create (US.v n) x))
(True)
(fun a ->
length a == US.v n /\
base_len (base (ptr_of a)) == US.v n
)
=
let c : carrier elt (US.v n) = mk_carrier (US.v n) 0 (Seq.create (US.v n) x) P.full_perm in
let base : ref (carrier elt (US.v n)) (pcm elt (US.v n)) = R.alloc c in
R.pts_to_not_null base _;
let p = {
base_len = n;
base = base;
offset = 0;
}
in
let a = (| p, Ghost.hide (US.v n) |) in
change_r_pts_to
base c
(ptr_of a).base c;
intro_pts_to a P.full_perm (Seq.create (US.v n) x);
return a
let malloc_ptr
x n
=
let a = malloc0 x n in
let (| p, _ |) = a in
rewrite
(pts_to _ _ _)
(pts_to (| p, Ghost.hide (US.v n) |) _ _);
return p
[@@noextract_to "krml"]
let free0
(#elt: Type)
(#s: Ghost.erased (Seq.seq elt))
(a: array elt)
: ST unit
(pts_to a P.full_perm s)
(fun _ -> emp)
(
length a == base_len (base (ptr_of a))
)
(fun _ -> True)
= drop (pts_to a _ _)
let free_ptr a =
free0 _
let valid_sum_perm
(len: nat)
(offset: nat)
(slice_len: nat)
(p1 p2: P.perm)
: Tot prop
= let open FStar.Real in
valid_perm len offset slice_len (P.sum_perm p1 p2)
let mk_carrier_share
(#elt: Type)
(len: nat)
(offset: nat)
(s: Seq.seq elt)
(p1 p2: P.perm)
: Lemma
(requires (valid_sum_perm len offset (Seq.length s) p1 p2))
(ensures (
let c1 = mk_carrier len offset s p1 in
let c2 = mk_carrier len offset s p2 in
composable c1 c2 /\
mk_carrier len offset s (p1 `P.sum_perm` p2) `M.equal` (c1 `compose` c2)
))
= ()
let share
#_ #_ #x a p p1 p2
= elim_pts_to a p x;
mk_carrier_share (US.v (ptr_of a).base_len) (ptr_of a).offset x p1 p2;
R.split (ptr_of a).base _
(mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset x p1)
(mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset x p2);
intro_pts_to a p1 x;
intro_pts_to a p2 x
let mk_carrier_gather
(#elt: Type)
(len: nat)
(offset: nat)
(s1 s2: Seq.seq elt)
(p1 p2: P.perm)
: Lemma
(requires (
let c1 = mk_carrier len offset s1 p1 in
let c2 = mk_carrier len offset s2 p2 in
composable c1 c2 /\
Seq.length s1 == Seq.length s2 /\
offset + Seq.length s1 <= len
))
(ensures (
let c1 = mk_carrier len offset s1 p1 in
let c2 = mk_carrier len offset s2 p2 in
composable c1 c2 /\
mk_carrier len offset s1 (p1 `P.sum_perm` p2) == (c1 `compose` c2) /\
mk_carrier len offset s2 (p1 `P.sum_perm` p2) == (c1 `compose` c2) /\
s1 == s2
))
=
let c1 = mk_carrier len offset s1 p1 in
let c2 = mk_carrier len offset s2 p2 in
assert (composable c1 c2);
assert (mk_carrier len offset s1 (p1 `P.sum_perm` p2) `M.equal` (c1 `compose` c2));
assert (mk_carrier len offset s2 (p1 `P.sum_perm` p2) `M.equal` (c1 `compose` c2));
mk_carrier_inj len offset s1 s2 (p1 `P.sum_perm` p2) (p1 `P.sum_perm` p2)
let mk_carrier_valid_sum_perm
(#elt: Type)
(len: nat)
(offset: nat)
(s: Seq.seq elt)
(p1 p2: P.perm)
: Lemma
(let c1 = mk_carrier len offset s p1 in
let c2 = mk_carrier len offset s p2 in
composable c1 c2 <==> valid_sum_perm len offset (Seq.length s) p1 p2)
= let c1 = mk_carrier len offset s p1 in
let c2 = mk_carrier len offset s p2 in
if Seq.length s > 0 && offset + Seq.length s <= len
then
let open FStar.Real in
assert (P.composable (M.sel c1 offset) (M.sel c2 offset) <==> valid_perm len offset (Seq.length s) (P.sum_perm p1 p2))
else ()
let gather
a #x1 p1 #x2 p2
= elim_pts_to a p1 x1;
elim_pts_to a p2 x2;
let _ = R.gather (ptr_of a).base
(mk_carrier (US.v (ptr_of a).base_len) ((ptr_of a).offset) x1 p1)
(mk_carrier (US.v (ptr_of a).base_len) ((ptr_of a).offset) x2 p2)
in
mk_carrier_gather (US.v (ptr_of a).base_len) ((ptr_of a).offset) x1 x2 p1 p2;
mk_carrier_valid_sum_perm (US.v (ptr_of a).base_len) ((ptr_of a).offset) x1 p1 p2;
intro_pts_to a (p1 `P.sum_perm` p2) x1
#push-options "--z3rlimit 16"
[@@noextract_to "krml"]
let index0
(#t: Type) (#p: P.perm)
(a: array t)
(#s: Ghost.erased (Seq.seq t))
(i: US.t)
: ST t
(pts_to a p s)
(fun _ -> pts_to a p s)
(US.v i < length a \/ US.v i < Seq.length s)
(fun res -> Seq.length s == length a /\ US.v i < Seq.length s /\ res == Seq.index s (US.v i))
= elim_pts_to a p s;
let s' = R.read (ptr_of a).base _ in
let res = fst (Some?.v (M.sel s' ((ptr_of a).offset + US.v i))) in
intro_pts_to a p s;
return res
#pop-options
let index_ptr a i =
index0 _ i
let mk_carrier_upd
(#elt: Type)
(len: nat)
(offset: nat)
(s: Seq.seq elt)
(i: nat)
(v: elt)
(_: squash (
offset + Seq.length s <= len /\
i < Seq.length s
))
: Lemma
(ensures (
let o = mk_carrier len offset s P.full_perm in
let o' = mk_carrier len offset (Seq.upd s i v) P.full_perm in
o' `Map.equal` Map.upd o (offset + i) (Some (v, P.full_perm))
))
= ()
#push-options "--z3rlimit 20"
[@@noextract_to "krml"]
let upd0
(#t: Type)
(a: array t)
(#s: Ghost.erased (Seq.seq t))
(i: US.t { US.v i < Seq.length s })
(v: t)
: STT unit
(pts_to a P.full_perm s)
(fun res -> pts_to a P.full_perm (Seq.upd s (US.v i) v))
= elim_pts_to a _ _;
mk_carrier_upd (US.v (ptr_of a).base_len) ((ptr_of a).offset) s (US.v i) v ();
R.upd_gen
(ptr_of a).base
_ _
(PM.lift_frame_preserving_upd
_ _
(P.mk_frame_preserving_upd
(Seq.index s (US.v i))
v
)
_ ((ptr_of a).offset + US.v i)
);
intro_pts_to a _ _
#pop-options
let upd_ptr a i v =
upd0 _ i v;
rewrite
(pts_to _ _ _)
(pts_to _ _ _)
let mk_carrier_merge
(#elt: Type)
(len: nat)
(offset: nat)
(s1 s2: Seq.seq elt)
(p: P.perm)
: Lemma
(requires (
offset + Seq.length s1 + Seq.length s2 <= len
))
(ensures (
let c1 = mk_carrier len offset s1 p in
let c2 = mk_carrier len (offset + Seq.length s1) s2 p in
composable c1 c2 /\
mk_carrier len offset (s1 `Seq.append` s2) p `M.equal` (c1 `compose` c2)
))
= ()
let ghost_join
#_ #_ #x1 #x2 #p a1 a2 h
= elim_pts_to a1 p x1;
elim_pts_to a2 p x2;
mk_carrier_merge (US.v (ptr_of a1).base_len) ((ptr_of a1).offset) x1 x2 (p);
change_r_pts_to
(ptr_of a2).base _
(ptr_of a1).base (mk_carrier (US.v (ptr_of a1).base_len) ((ptr_of a1).offset + Seq.length x1) x2 p);
R.gather (ptr_of a1).base
(mk_carrier (US.v (ptr_of a1).base_len) ((ptr_of a1).offset) x1 (p))
(mk_carrier (US.v (ptr_of a1).base_len) ((ptr_of a1).offset + Seq.length x1) x2 (p));
change_r_pts_to
(ptr_of a1).base _
(ptr_of (merge a1 a2)).base (mk_carrier (US.v (ptr_of (merge a1 a2)).base_len) ((ptr_of (merge a1 a2)).offset) (x1 `Seq.append` x2) (p));
intro_pts_to (merge a1 a2) p (Seq.append x1 x2)
let mk_carrier_split
(#elt: Type)
(len: nat)
(offset: nat)
(s: Seq.seq elt)
(p: P.perm)
(i: nat)
: Lemma
(requires (
offset + Seq.length s <= len /\
i <= Seq.length s
))
(ensures (
let c1 = mk_carrier len offset (Seq.slice s 0 i) p in
let c2 = mk_carrier len (offset + i) (Seq.slice s i (Seq.length s)) p in
composable c1 c2 /\
mk_carrier len offset s p `M.equal` (c1 `compose` c2)
))
= ()
// TODO: replace with Ghost, introduce pointer shifting operations in SteelAtomicBase Unobservable
[@@noextract_to "krml"]
let ptr_shift
(#elt: Type)
(p: ptr elt)
(off: US.t)
: Pure (ptr elt)
(requires (offset p + US.v off <= base_len (base p)))
(ensures (fun p' ->
base p' == base p /\
offset p' == offset p + US.v off
))
= {
base_len = p.base_len;
base = p.base;
offset = p.offset + US.v off;
}
let ghost_split
#_ #_ #x #p a i
=
elim_pts_to a p x;
mk_carrier_split
(US.v (ptr_of a).base_len)
((ptr_of a).offset)
x
(p)
(US.v i);
Seq.lemma_split x (US.v i);
let xl = Seq.slice x 0 (US.v i) in
let xr = Seq.slice x (US.v i) (Seq.length x) in
let vl = mk_carrier (US.v (ptr_of a).base_len) ((ptr_of a).offset) xl (p) in
let vr = mk_carrier (US.v (ptr_of a).base_len) ((ptr_of a).offset + US.v i) xr (p) in
R.split (ptr_of a).base _ vl vr;
change_r_pts_to
(ptr_of a).base vl
(ptr_of (split_l a i)).base vl;
intro_pts_to (split_l a i) #vl p (Seq.slice x 0 (US.v i));
change_r_pts_to
(ptr_of a).base vr
(ptr_of (split_r a i)).base vr;
intro_pts_to (split_r a i) #vr p (Seq.slice x (US.v i) (Seq.length x))
////////////////////////////////////////////////////////////////////////////////
// memcpy
////////////////////////////////////////////////////////////////////////////////
let prefix_copied #t
(e0:Seq.seq t)
(e1:Seq.seq t)
(i:nat { i <= Seq.length e0 /\ Seq.length e0 == Seq.length e1})
: Seq.seq t
= (Seq.append (Seq.slice e0 0 i) (Seq.slice e1 i (Seq.length e1)))
#push-options "--z3rlimit 32"
val memcpy0 (#t:_) (#p0:perm)
(a0 a1:array t)
(#s0 #s1:Ghost.erased (Seq.seq t))
(l:US.t { US.v l == length a0 /\ length a0 == length a1 } )
: STT unit
(pts_to a0 p0 s0 `star` pts_to a1 full_perm s1)
(fun _ -> pts_to a0 p0 s0 `star` pts_to a1 full_perm s0)
let memcpy0
#t #p0 a0 a1 #e0 #e1 i
=
pts_to_length a0 _;
pts_to_length a1 _;
let inv (j:Steel.ST.Loops.nat_at_most i)
: vprop
= pts_to a0 p0 e0 `star`
pts_to a1 full_perm (prefix_copied e0 e1 j)
in
assert (prefix_copied e0 e1 0 `Seq.equal` e1);
rewrite (pts_to a1 full_perm e1)
(pts_to a1 full_perm (prefix_copied e0 e1 0));
rewrite (pts_to a0 _ e0 `star` pts_to a1 full_perm (prefix_copied e0 e1 0))
(inv (US.v 0sz));
let body (j:Steel.ST.Loops.u32_between 0sz i)
: STT unit
(inv (US.v j))
(fun _ -> inv (US.v j + 1))
= rewrite
(inv (US.v j))
(pts_to a0 p0 e0 `star`
pts_to a1 full_perm (prefix_copied e0 e1 (US.v j)));
let z = index a0 j in
upd a1 j z;
assert (Seq.upd (prefix_copied e0 e1 (US.v j)) (US.v j) z `Seq.equal`
prefix_copied e0 e1 (US.v j + 1));
rewrite (pts_to a0 _ e0 `star` pts_to a1 _ _)
(inv (US.v j + 1));
return ()
in
Steel.ST.Loops.for_loop 0sz i inv body;
assert_ (inv (US.v i));
rewrite (inv (US.v i))
(pts_to a0 p0 e0 `star`
pts_to a1 full_perm (prefix_copied e0 e1 (US.v i)));
assert (prefix_copied e0 e1 (US.v i) `Seq.equal` e0);
rewrite (pts_to a1 _ (prefix_copied e0 e1 (US.v i)))
(pts_to a1 _ e0);
return ()
#pop-options
#push-options "--z3rlimit 48"
#push-options "--z3rlimit 75"
let blit0 (#t:_) (#p0:perm) (#s0 #s1:Ghost.erased (Seq.seq t))
(src:array t)
(idx_src: US.t)
(dst:array t)
(idx_dst: US.t)
(len: US.t)
: ST unit
(pts_to src p0 s0 `star` pts_to dst full_perm s1)
(fun _ -> pts_to src p0 s0 `star` exists_ (fun s1' ->
pts_to dst full_perm s1' `star`
pure (blit_post s0 s1 src idx_src dst idx_dst len s1')
))
(
US.v idx_src + US.v len <= length src /\
US.v idx_dst + US.v len <= length dst
)
(fun _ -> True)
= pts_to_length src s0;
pts_to_length dst s1;
let _ = ghost_split src idx_src in
let _ = ghost_split (split_r src idx_src) len in
let _ = ghost_split dst idx_dst in
let _ = ghost_split (split_r dst idx_dst) len in
memcpy0 (split_l (split_r src idx_src) len) (split_l (split_r dst idx_dst) len) len;
ghost_join (split_l (split_r dst _) _) (split_r (split_r dst _) _) ();
ghost_join (split_l dst _) (merge _ _) ();
vpattern_rewrite #_ #_ #(merge _ _) (fun a -> pts_to a _ _) dst;
ghost_join (split_l (split_r src _) _) (split_r (split_r src _) _) ();
ghost_join (split_l src _) (merge _ _) ();
vpattern_rewrite #_ #_ #(merge _ _) (fun a -> pts_to a _ _) src;
vpattern_rewrite (pts_to src _) (Ghost.reveal s0);
noop ()
#pop-options
#pop-options
let blit_ptr
src len_src idx_src dst len_dst idx_dst len
= blit0 _ idx_src _ idx_dst len
/// These functions will be natively extracted, we can simply admit them
let intro_fits_u32 () = admit_ ()
let intro_fits_u64 () = admit_ ()
let intro_fits_ptrdiff32 () = admit_ ()
let intro_fits_ptrdiff64 () = admit_ () | {
"checked_file": "/",
"dependencies": [
"Steel.ST.PCMReference.fsti.checked",
"Steel.ST.Loops.fsti.checked",
"Steel.PCMMap.fst.checked",
"Steel.PCMFrac.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.HigherArray.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.PCMMap",
"short_module": "PM"
},
{
"abbrev": true,
"full_module": "FStar.Map",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Steel.ST.PCMReference",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "Steel.PCMFrac",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a0: Steel.ST.HigherArray.ptr t ->
len0:
FStar.Ghost.erased Prims.nat
{ Steel.ST.HigherArray.offset a0 + FStar.Ghost.reveal len0 <=
Steel.ST.HigherArray.base_len (Steel.ST.HigherArray.base a0) } ->
a1: Steel.ST.HigherArray.ptr t ->
len1:
FStar.Ghost.erased Prims.nat
{ Steel.ST.HigherArray.offset a1 + FStar.Ghost.reveal len1 <=
Steel.ST.HigherArray.base_len (Steel.ST.HigherArray.base a1) }
-> Steel.ST.Effect.ST FStar.PtrdiffT.t | Steel.ST.Effect.ST | [] | [] | [
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Steel.ST.HigherArray.ptr",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Steel.ST.HigherArray.offset",
"FStar.Ghost.reveal",
"Steel.ST.HigherArray.base_len",
"Steel.ST.HigherArray.base",
"Steel.ST.Util.return",
"FStar.PtrdiffT.t",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.Effect.Common.VStar",
"Steel.ST.HigherArray.pts_to",
"Prims.Mkdtuple2",
"Steel.Effect.Common.vprop",
"FStar.PtrdiffT.int_to_t",
"Prims.int",
"Prims.op_Subtraction",
"Steel.ST.HigherArray.__proj__Mkptr__item__offset"
] | [] | false | true | false | false | false | let ptrdiff_ptr a0 len0 a1 len1 =
| let res = a0.offset - a1.offset in
return (UP.int_to_t res) | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_rshift | val bn_rshift:
#t:limb_t
-> #len:size_nat
-> b:lbignum t len
-> i:size_nat{i < len} ->
lbignum t (len - i) | val bn_rshift:
#t:limb_t
-> #len:size_nat
-> b:lbignum t len
-> i:size_nat{i < len} ->
lbignum t (len - i) | let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 38,
"end_line": 154,
"start_col": 0,
"start_line": 153
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | b: Hacl.Spec.Bignum.Definitions.lbignum t len -> i: Lib.IntTypes.size_nat{i < len}
-> Hacl.Spec.Bignum.Definitions.lbignum t (len - i) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.Bignum.Lib.bn_div_pow2",
"Prims.op_Subtraction"
] | [] | false | false | false | false | false | let bn_rshift #t #len b i =
| Hacl.Spec.Bignum.Lib.bn_div_pow2 b i | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.cswap2 | val cswap2:
#t:limb_t
-> #len:size_nat
-> bit:limb t
-> b1:lbignum t len
-> b2:lbignum t len ->
tuple2 (lbignum t len) (lbignum t len) | val cswap2:
#t:limb_t
-> #len:size_nat
-> bit:limb t
-> b1:lbignum t len
-> b2:lbignum t len ->
tuple2 (lbignum t len) (lbignum t len) | let cswap2 #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2 bit b1 b2 | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 205,
"start_col": 0,
"start_line": 204
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind
let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l
let bn_get_bits_lemma #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l
let bn_set_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit input ind
let bn_set_ith_bit_lemma #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma input ind
(* conditional swap *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
bit: Hacl.Spec.Bignum.Definitions.limb t ->
b1: Hacl.Spec.Bignum.Definitions.lbignum t len ->
b2: Hacl.Spec.Bignum.Definitions.lbignum t len
-> Hacl.Spec.Bignum.Definitions.lbignum t len * Hacl.Spec.Bignum.Definitions.lbignum t len | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Lib.cswap2",
"FStar.Pervasives.Native.tuple2"
] | [] | false | false | false | false | false | let cswap2 #t #len bit b1 b2 =
| Hacl.Spec.Bignum.Lib.cswap2 bit b1 b2 | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_eq_mask | val bn_eq_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t | val bn_eq_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t | let bn_eq_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask a b | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 219,
"start_col": 0,
"start_line": 218
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind
let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l
let bn_get_bits_lemma #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l
let bn_set_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit input ind
let bn_set_ith_bit_lemma #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma input ind
(* conditional swap *)
let cswap2 #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2 bit b1 b2
let cswap2_lemma #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2_lemma bit b1 b2
(* Bignum comparison and test functions *)
let bn_is_odd #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd b
let bn_is_odd_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd_lemma b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t len -> b: Hacl.Spec.Bignum.Definitions.lbignum t len
-> Hacl.Spec.Bignum.Definitions.limb t | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Comparison.bn_eq_mask",
"Hacl.Spec.Bignum.Definitions.limb"
] | [] | false | false | false | false | false | let bn_eq_mask #t #len a b =
| Hacl.Spec.Bignum.Comparison.bn_eq_mask a b | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_rshift_lemma | val bn_rshift_lemma:
#t:limb_t
-> #len:size_nat
-> b:lbignum t len
-> i:size_nat{i < len} ->
Lemma (bn_v (bn_rshift b i) == bn_v b / pow2 (bits t * i)) | val bn_rshift_lemma:
#t:limb_t
-> #len:size_nat
-> b:lbignum t len
-> i:size_nat{i < len} ->
Lemma (bn_v (bn_rshift b i) == bn_v b / pow2 (bits t * i)) | let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 157,
"start_col": 0,
"start_line": 156
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | b: Hacl.Spec.Bignum.Definitions.lbignum t len -> i: Lib.IntTypes.size_nat{i < len}
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.Bignum.bn_rshift b i) ==
Hacl.Spec.Bignum.Definitions.bn_v b / Prims.pow2 (Lib.IntTypes.bits t * i)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let bn_rshift_lemma #t #len c i =
| Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_is_zero_mask | val bn_is_zero_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> limb t | val bn_is_zero_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> limb t | let bn_is_zero_mask #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask b | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 225,
"start_col": 0,
"start_line": 224
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind
let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l
let bn_get_bits_lemma #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l
let bn_set_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit input ind
let bn_set_ith_bit_lemma #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma input ind
(* conditional swap *)
let cswap2 #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2 bit b1 b2
let cswap2_lemma #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2_lemma bit b1 b2
(* Bignum comparison and test functions *)
let bn_is_odd #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd b
let bn_is_odd_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd_lemma b
let bn_eq_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask a b
let bn_eq_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask_lemma a b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t len -> Hacl.Spec.Bignum.Definitions.limb t | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Comparison.bn_is_zero_mask",
"Hacl.Spec.Bignum.Definitions.limb"
] | [] | false | false | false | false | false | let bn_is_zero_mask #t #len b =
| Hacl.Spec.Bignum.Comparison.bn_is_zero_mask b | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_mul1_lshift_add_lemma | val bn_mul1_lshift_add_lemma:
#t:limb_t
-> #aLen:size_nat
-> #resLen:size_nat
-> a:lbignum t aLen
-> b:limb t
-> j:size_nat{j + aLen <= resLen}
-> acc:lbignum t resLen ->
Lemma (let (c_out, res) = bn_mul1_lshift_add a b j acc in
v c_out * pow2 (bits t * (aLen + j)) + eval_ resLen res (aLen + j) ==
eval_ resLen acc (aLen + j) + bn_v a * v b * pow2 (bits t * j) /\
slice res (aLen + j) resLen == slice acc (aLen + j) resLen) | val bn_mul1_lshift_add_lemma:
#t:limb_t
-> #aLen:size_nat
-> #resLen:size_nat
-> a:lbignum t aLen
-> b:limb t
-> j:size_nat{j + aLen <= resLen}
-> acc:lbignum t resLen ->
Lemma (let (c_out, res) = bn_mul1_lshift_add a b j acc in
v c_out * pow2 (bits t * (aLen + j)) + eval_ resLen res (aLen + j) ==
eval_ resLen acc (aLen + j) + bn_v a * v b * pow2 (bits t * j) /\
slice res (aLen + j) resLen == slice acc (aLen + j) resLen) | let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 68,
"end_line": 151,
"start_col": 0,
"start_line": 150
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen ->
b: Hacl.Spec.Bignum.Definitions.limb t ->
j: Lib.IntTypes.size_nat{j + aLen <= resLen} ->
acc: Hacl.Spec.Bignum.Definitions.lbignum t resLen
-> FStar.Pervasives.Lemma
(ensures
(let _ = Hacl.Spec.Bignum.bn_mul1_lshift_add a b j acc in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c_out res = _ in
Lib.IntTypes.v c_out * Prims.pow2 (Lib.IntTypes.bits t * (aLen + j)) +
Hacl.Spec.Bignum.Definitions.eval_ resLen res (aLen + j) ==
Hacl.Spec.Bignum.Definitions.eval_ resLen acc (aLen + j) +
(Hacl.Spec.Bignum.Definitions.bn_v a * Lib.IntTypes.v b) *
Prims.pow2 (Lib.IntTypes.bits t * j) /\
Lib.Sequence.slice res (aLen + j) resLen == Lib.Sequence.slice acc (aLen + j) resLen)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
| Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_lt_mask | val bn_lt_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t | val bn_lt_mask: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len -> limb t | let bn_lt_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask a b | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 231,
"start_col": 0,
"start_line": 230
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind
let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l
let bn_get_bits_lemma #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l
let bn_set_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit input ind
let bn_set_ith_bit_lemma #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma input ind
(* conditional swap *)
let cswap2 #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2 bit b1 b2
let cswap2_lemma #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2_lemma bit b1 b2
(* Bignum comparison and test functions *)
let bn_is_odd #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd b
let bn_is_odd_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd_lemma b
let bn_eq_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask a b
let bn_eq_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask_lemma a b
let bn_is_zero_mask #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask b
let bn_is_zero_mask_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask_lemma b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t len -> b: Hacl.Spec.Bignum.Definitions.lbignum t len
-> Hacl.Spec.Bignum.Definitions.limb t | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Comparison.bn_lt_mask",
"Hacl.Spec.Bignum.Definitions.limb"
] | [] | false | false | false | false | false | let bn_lt_mask #t #len a b =
| Hacl.Spec.Bignum.Comparison.bn_lt_mask a b | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_sub_mask | val bn_sub_mask:
#t:limb_t
-> #len:size_nat
-> n:lbignum t len
-> a:lbignum t len ->
lbignum t len | val bn_sub_mask:
#t:limb_t
-> #len:size_nat
-> n:lbignum t len
-> a:lbignum t len ->
lbignum t len | let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 163,
"start_col": 0,
"start_line": 159
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | n: Hacl.Spec.Bignum.Definitions.lbignum t len -> a: Hacl.Spec.Bignum.Definitions.lbignum t len
-> Hacl.Spec.Bignum.Definitions.lbignum t len | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Addition.bn_sub",
"Lib.Sequence.lseq",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.eq2",
"Lib.Sequence.index",
"Lib.IntTypes.logand",
"Lib.IntTypes.SEC",
"Lib.Sequence.map",
"Lib.IntTypes.int_t",
"Prims.l_and",
"Prims.l_or",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.slice",
"Prims.op_Addition",
"FStar.Seq.Base.index",
"Lib.Sequence.sub",
"Prims.int",
"Lib.IntTypes.range",
"Lib.IntTypes.v",
"Lib.IntTypes.ones",
"Prims.l_not",
"Lib.IntTypes.zeros",
"Lib.ByteSequence.seq_eq_mask"
] | [] | false | false | false | false | false | let bn_sub_mask #t #len n a =
| let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_get_bits | val bn_get_bits:
#t:limb_t
-> #nLen:size_nat
-> n:lbignum t nLen
-> i:size_nat
-> l:size_nat{l < bits t /\ i / bits t < nLen} ->
limb t | val bn_get_bits:
#t:limb_t
-> #nLen:size_nat
-> n:lbignum t nLen
-> i:size_nat
-> l:size_nat{l < bits t /\ i / bits t < nLen} ->
limb t | let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 49,
"end_line": 191,
"start_col": 0,
"start_line": 190
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
n: Hacl.Spec.Bignum.Definitions.lbignum t nLen ->
i: Lib.IntTypes.size_nat ->
l: Lib.IntTypes.size_nat{l < Lib.IntTypes.bits t /\ i / Lib.IntTypes.bits t < nLen}
-> Hacl.Spec.Bignum.Definitions.limb t | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.bits",
"Prims.op_Division",
"Hacl.Spec.Bignum.Lib.bn_get_bits",
"Hacl.Spec.Bignum.Definitions.limb"
] | [] | false | false | false | false | false | let bn_get_bits #t #nLen n i l =
| Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_get_ith_bit_lemma | val bn_get_ith_bit_lemma:
#t:limb_t
-> #len:size_nat
-> b:lbignum t len
-> i:size_nat{i / bits t < len} ->
Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2)) | val bn_get_ith_bit_lemma:
#t:limb_t
-> #len:size_nat
-> b:lbignum t len
-> i:size_nat{i / bits t < len} ->
Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2)) | let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 49,
"end_line": 188,
"start_col": 0,
"start_line": 187
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
b: Hacl.Spec.Bignum.Definitions.lbignum t len ->
i: Lib.IntTypes.size_nat{i / Lib.IntTypes.bits t < len}
-> FStar.Pervasives.Lemma
(ensures
Lib.IntTypes.v (Hacl.Spec.Bignum.bn_get_ith_bit b i) ==
Hacl.Spec.Bignum.Definitions.bn_v b / Prims.pow2 i % 2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Division",
"Lib.IntTypes.bits",
"Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let bn_get_ith_bit_lemma #t #len b ind =
| Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_lt_pow2_mask | val bn_lt_pow2_mask: #t:limb_t -> #len:size_nat -> b:lbignum t len -> x:size_nat{x < bits t * len} -> limb t | val bn_lt_pow2_mask: #t:limb_t -> #len:size_nat -> b:lbignum t len -> x:size_nat{x < bits t * len} -> limb t | let bn_lt_pow2_mask #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask b x | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 49,
"end_line": 237,
"start_col": 0,
"start_line": 236
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind
let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l
let bn_get_bits_lemma #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l
let bn_set_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit input ind
let bn_set_ith_bit_lemma #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma input ind
(* conditional swap *)
let cswap2 #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2 bit b1 b2
let cswap2_lemma #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2_lemma bit b1 b2
(* Bignum comparison and test functions *)
let bn_is_odd #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd b
let bn_is_odd_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd_lemma b
let bn_eq_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask a b
let bn_eq_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask_lemma a b
let bn_is_zero_mask #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask b
let bn_is_zero_mask_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask_lemma b
let bn_lt_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask a b
let bn_lt_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask_lemma a b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
b: Hacl.Spec.Bignum.Definitions.lbignum t len ->
x: Lib.IntTypes.size_nat{x < Lib.IntTypes.bits t * len}
-> Hacl.Spec.Bignum.Definitions.limb t | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Mul.op_Star",
"Lib.IntTypes.bits",
"Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask",
"Hacl.Spec.Bignum.Definitions.limb"
] | [] | false | false | false | false | false | let bn_lt_pow2_mask #t #len b x =
| Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask b x | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_is_odd | val bn_is_odd: #t:limb_t -> #len:size_pos -> a:lbignum t len -> limb t | val bn_is_odd: #t:limb_t -> #len:size_pos -> a:lbignum t len -> limb t | let bn_is_odd #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd b | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 41,
"end_line": 213,
"start_col": 0,
"start_line": 212
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind
let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l
let bn_get_bits_lemma #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l
let bn_set_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit input ind
let bn_set_ith_bit_lemma #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma input ind
(* conditional swap *)
let cswap2 #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2 bit b1 b2
let cswap2_lemma #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2_lemma bit b1 b2
(* Bignum comparison and test functions *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t len -> Hacl.Spec.Bignum.Definitions.limb t | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_pos",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Comparison.bn_is_odd",
"Hacl.Spec.Bignum.Definitions.limb"
] | [] | false | false | false | false | false | let bn_is_odd #t #len b =
| Hacl.Spec.Bignum.Comparison.bn_is_odd b | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.cswap2_lemma | val cswap2_lemma:
#t:limb_t
-> #len:size_nat
-> bit:limb t{v bit <= 1}
-> b1:lbignum t len
-> b2:lbignum t len ->
Lemma (let (p1, p2) = cswap2 bit b1 b2 in
(if v bit = 1 then p1 == b2 /\ p2 == b1 else p1 == b1 /\ p2 == b2)) | val cswap2_lemma:
#t:limb_t
-> #len:size_nat
-> bit:limb t{v bit <= 1}
-> b1:lbignum t len
-> b2:lbignum t len ->
Lemma (let (p1, p2) = cswap2 bit b1 b2 in
(if v bit = 1 then p1 == b2 /\ p2 == b1 else p1 == b1 /\ p2 == b2)) | let cswap2_lemma #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2_lemma bit b1 b2 | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 208,
"start_col": 0,
"start_line": 207
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind
let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l
let bn_get_bits_lemma #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l
let bn_set_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit input ind
let bn_set_ith_bit_lemma #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma input ind
(* conditional swap *)
let cswap2 #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2 bit b1 b2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
bit: Hacl.Spec.Bignum.Definitions.limb t {Lib.IntTypes.v bit <= 1} ->
b1: Hacl.Spec.Bignum.Definitions.lbignum t len ->
b2: Hacl.Spec.Bignum.Definitions.lbignum t len
-> FStar.Pervasives.Lemma
(ensures
(let _ = Hacl.Spec.Bignum.cswap2 bit b1 b2 in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ p1 p2 = _ in
(match Lib.IntTypes.v bit = 1 with
| true -> p1 == b2 /\ p2 == b1
| _ -> p1 == b1 /\ p2 == b2)
<:
Type0)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Lib.cswap2_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let cswap2_lemma #t #len bit b1 b2 =
| Hacl.Spec.Bignum.Lib.cswap2_lemma bit b1 b2 | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_get_ith_bit | val bn_get_ith_bit:
#t:limb_t
-> #len:size_nat
-> b:lbignum t len
-> i:size_nat{i / bits t < len} ->
limb t | val bn_get_ith_bit:
#t:limb_t
-> #len:size_nat
-> b:lbignum t len
-> i:size_nat{i / bits t < len} ->
limb t | let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 185,
"start_col": 0,
"start_line": 184
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
b: Hacl.Spec.Bignum.Definitions.lbignum t len ->
i: Lib.IntTypes.size_nat{i / Lib.IntTypes.bits t < len}
-> Hacl.Spec.Bignum.Definitions.limb t | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Division",
"Lib.IntTypes.bits",
"Hacl.Spec.Bignum.Lib.bn_get_ith_bit",
"Hacl.Spec.Bignum.Definitions.limb"
] | [] | false | false | false | false | false | let bn_get_ith_bit #t #len input ind =
| Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_gt_pow2_mask | val bn_gt_pow2_mask: #t:limb_t -> #len:size_nat -> b:lbignum t len -> x:size_nat{x < bits t * len} -> limb t | val bn_gt_pow2_mask: #t:limb_t -> #len:size_nat -> b:lbignum t len -> x:size_nat{x < bits t * len} -> limb t | let bn_gt_pow2_mask #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask b x | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 49,
"end_line": 243,
"start_col": 0,
"start_line": 242
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind
let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l
let bn_get_bits_lemma #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l
let bn_set_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit input ind
let bn_set_ith_bit_lemma #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma input ind
(* conditional swap *)
let cswap2 #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2 bit b1 b2
let cswap2_lemma #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2_lemma bit b1 b2
(* Bignum comparison and test functions *)
let bn_is_odd #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd b
let bn_is_odd_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd_lemma b
let bn_eq_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask a b
let bn_eq_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask_lemma a b
let bn_is_zero_mask #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask b
let bn_is_zero_mask_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask_lemma b
let bn_lt_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask a b
let bn_lt_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask_lemma a b
let bn_lt_pow2_mask #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask b x
let bn_lt_pow2_mask_lemma #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask_lemma b x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
b: Hacl.Spec.Bignum.Definitions.lbignum t len ->
x: Lib.IntTypes.size_nat{x < Lib.IntTypes.bits t * len}
-> Hacl.Spec.Bignum.Definitions.limb t | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Mul.op_Star",
"Lib.IntTypes.bits",
"Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask",
"Hacl.Spec.Bignum.Definitions.limb"
] | [] | false | false | false | false | false | let bn_gt_pow2_mask #t #len b x =
| Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask b x | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_is_odd_lemma | val bn_is_odd_lemma: #t:limb_t -> #len:size_pos -> a:lbignum t len ->
Lemma (v (bn_is_odd a) == (bn_v a % 2)) | val bn_is_odd_lemma: #t:limb_t -> #len:size_pos -> a:lbignum t len ->
Lemma (v (bn_is_odd a) == (bn_v a % 2)) | let bn_is_odd_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd_lemma b | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 216,
"start_col": 0,
"start_line": 215
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind
let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l
let bn_get_bits_lemma #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l
let bn_set_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit input ind
let bn_set_ith_bit_lemma #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma input ind
(* conditional swap *)
let cswap2 #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2 bit b1 b2
let cswap2_lemma #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2_lemma bit b1 b2
(* Bignum comparison and test functions *)
let bn_is_odd #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t len
-> FStar.Pervasives.Lemma
(ensures
Lib.IntTypes.v (Hacl.Spec.Bignum.bn_is_odd a) == Hacl.Spec.Bignum.Definitions.bn_v a % 2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_pos",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Comparison.bn_is_odd_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let bn_is_odd_lemma #t #len b =
| Hacl.Spec.Bignum.Comparison.bn_is_odd_lemma b | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_eq_mask_lemma | val bn_eq_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len ->
Lemma (mask_values (bn_eq_mask a b) /\
(if v (bn_eq_mask a b) = 0 then bn_v a <> bn_v b else bn_v a = bn_v b)) | val bn_eq_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len ->
Lemma (mask_values (bn_eq_mask a b) /\
(if v (bn_eq_mask a b) = 0 then bn_v a <> bn_v b else bn_v a = bn_v b)) | let bn_eq_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask_lemma a b | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 222,
"start_col": 0,
"start_line": 221
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind
let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l
let bn_get_bits_lemma #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l
let bn_set_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit input ind
let bn_set_ith_bit_lemma #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma input ind
(* conditional swap *)
let cswap2 #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2 bit b1 b2
let cswap2_lemma #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2_lemma bit b1 b2
(* Bignum comparison and test functions *)
let bn_is_odd #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd b
let bn_is_odd_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd_lemma b
let bn_eq_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask a b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t len -> b: Hacl.Spec.Bignum.Definitions.lbignum t len
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Bignum.Base.mask_values (Hacl.Spec.Bignum.bn_eq_mask a b) /\
(match Lib.IntTypes.v (Hacl.Spec.Bignum.bn_eq_mask a b) = 0 with
| true -> Hacl.Spec.Bignum.Definitions.bn_v a <> Hacl.Spec.Bignum.Definitions.bn_v b
| _ -> Hacl.Spec.Bignum.Definitions.bn_v a = Hacl.Spec.Bignum.Definitions.bn_v b)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Comparison.bn_eq_mask_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let bn_eq_mask_lemma #t #len a b =
| Hacl.Spec.Bignum.Comparison.bn_eq_mask_lemma a b | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_set_ith_bit_lemma | val bn_set_ith_bit_lemma:
#t:limb_t
-> #len:size_nat
-> b:lbignum t len
-> i:size_nat{i / bits t < len} -> Lemma
(requires bn_v b < pow2 i)
(ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i) | val bn_set_ith_bit_lemma:
#t:limb_t
-> #len:size_nat
-> b:lbignum t len
-> i:size_nat{i / bits t < len} -> Lemma
(requires bn_v b < pow2 i)
(ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i) | let bn_set_ith_bit_lemma #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma input ind | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 53,
"end_line": 200,
"start_col": 0,
"start_line": 199
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind
let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l
let bn_get_bits_lemma #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l
let bn_set_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit input ind | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
b: Hacl.Spec.Bignum.Definitions.lbignum t len ->
i: Lib.IntTypes.size_nat{i / Lib.IntTypes.bits t < len}
-> FStar.Pervasives.Lemma (requires Hacl.Spec.Bignum.Definitions.bn_v b < Prims.pow2 i)
(ensures
Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.Bignum.bn_set_ith_bit b i) ==
Hacl.Spec.Bignum.Definitions.bn_v b + Prims.pow2 i) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Division",
"Lib.IntTypes.bits",
"Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let bn_set_ith_bit_lemma #t #len input ind =
| Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma input ind | false |
LList.ST.fst | LList.ST.peek | val peek (#a:Type0) (#l:G.erased (list a))
(ll:llist a)
(_:squash (Cons? l))
: ST a
(ll `is_list` l)
(fun _ -> ll `is_list` l)
(requires True)
(ensures fun x -> x == Cons?.hd l) | val peek (#a:Type0) (#l:G.erased (list a))
(ll:llist a)
(_:squash (Cons? l))
: ST a
(ll `is_list` l)
(fun _ -> ll `is_list` l)
(requires True)
(ensures fun x -> x == Cons?.hd l) | let peek #_ #l ll p =
let w = elim l ll p in
let node = read ll in
intro l w ll p;
return node.data | {
"file_name": "share/steel/examples/steel/LList.ST.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 18,
"end_line": 126,
"start_col": 0,
"start_line": 122
} | (*
Copyright 2021 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Author: Aseem Rastogi
*)
module LList.ST
open Steel.Memory
open Steel.ST.Effect
open Steel.ST.Util
open Steel.ST.Reference
#set-options "--ide_id_info_off"
let rec is_list #a ll l : Tot vprop (decreases l) =
match l with
| [] -> pure (ll == null)
| hd::tl ->
exists_ (fun (node:llist_node a) ->
pts_to ll full_perm node
`star`
pure (node.data == hd)
`star`
is_list node.next tl)
let empty a = null
module T = FStar.Tactics
let intro #_ #_ l node ll _ =
intro_pure (node.data == Cons?.hd l);
intro_exists
node
(fun node -> pts_to ll full_perm node
`star`
pure (node.data == Cons?.hd l)
`star`
is_list node.next (Cons?.tl l));
assert (exists_ (fun node -> pts_to ll full_perm node
`star`
pure (node.data == Cons?.hd l)
`star`
is_list node.next (Cons?.tl l)) ==
is_list ll (Cons?.hd l::Cons?.tl l))
by (T.norm [delta_only [`%is_list]; zeta; iota]);
rewrite
(exists_ (fun node -> pts_to ll full_perm node
`star`
pure (node.data == Cons?.hd l)
`star`
is_list node.next (Cons?.tl l)))
(is_list ll l)
let elim_aux (#opened:_) (#a:Type0)
(hd:G.erased a)
(tl:G.erased (list a))
(ll:llist a)
: STGhost (G.erased (llist_node a)) opened
(is_list ll (G.reveal hd::tl))
(fun node ->
pts_to ll full_perm node
`star`
is_list node.next tl)
(requires True)
(ensures fun node -> eq2 #a node.data hd)
= assert (is_list ll (G.reveal hd::tl) ==
exists_ (fun node -> pts_to ll full_perm node
`star`
pure (eq2 #a node.data hd)
`star`
is_list node.next tl))
by (T.norm [delta_only [`%is_list]; zeta; iota]);
rewrite (is_list ll (G.reveal hd::tl))
(exists_ (fun node -> pts_to ll full_perm node
`star`
pure (eq2 #a node.data hd)
`star`
is_list node.next tl));
let node = elim_exists () in
elim_pure (eq2 _ _);
node
let elim #opened #a l ll p =
rewrite
(is_list ll l)
(is_list ll (Cons?.hd l::Cons?.tl l));
elim_aux (Cons?.hd l) (Cons?.tl l) ll
let empty_pts_to #_ a =
intro_pure (empty a == null);
rewrite (pure _)
(is_list (empty a) [])
let cons #_ #l x ll =
let node = {
data = x;
next = ll;
} in
let head = alloc node in
rewrite (ll `is_list` l)
(node.next `is_list` l);
intro (x::l) node head ();
return head | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Reference.fsti.checked",
"Steel.ST.Effect.fsti.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "LList.ST.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.Reference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Steel.ST.Reference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "LList",
"short_module": null
},
{
"abbrev": false,
"full_module": "LList",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | ll: LList.ST.llist a -> p: Prims.squash (Cons? (FStar.Ghost.reveal l)) -> Steel.ST.Effect.ST a | Steel.ST.Effect.ST | [] | [] | [
"FStar.Ghost.erased",
"Prims.list",
"LList.ST.llist",
"Prims.squash",
"Prims.b2t",
"Prims.uu___is_Cons",
"FStar.Ghost.reveal",
"Steel.ST.Util.return",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"LList.ST.is_list",
"Steel.Effect.Common.vprop",
"LList.ST.__proj__Mkllist_node__item__data",
"Prims.unit",
"LList.ST.intro",
"LList.ST.llist_node",
"Steel.ST.Reference.read",
"Steel.FractionalPermission.full_perm",
"LList.ST.elim"
] | [] | false | true | false | false | false | let peek #_ #l ll p =
| let w = elim l ll p in
let node = read ll in
intro l w ll p;
return node.data | false |
SteelFramingTestSuite.fst | SteelFramingTestSuite.test8 | val test8 (b1 b2 b3: ref)
: SteelT unit
(((ptr b1) `star` (ptr b2)) `star` (ptr b3))
(fun _ -> ((ptr b2) `star` (ptr b1)) `star` (ptr b3)) | val test8 (b1 b2 b3: ref)
: SteelT unit
(((ptr b1) `star` (ptr b2)) `star` (ptr b3))
(fun _ -> ((ptr b2) `star` (ptr b1)) `star` (ptr b3)) | let test8 (b1 b2 b3:ref) : SteelT unit
(ptr b1 `star` ptr b2 `star` ptr b3)
(fun _ -> ptr b2 `star` ptr b1 `star` ptr b3)
= write b2 0 | {
"file_name": "share/steel/tests/SteelFramingTestSuite.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 14,
"end_line": 108,
"start_col": 0,
"start_line": 105
} | (*
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 SteelFramingTestSuite
open Steel.Memory
open Steel.Effect
/// A collection of small unit tests for the framing tactic
assume val p : vprop
assume val f (x:int) : SteelT unit p (fun _ -> p)
let test () : SteelT unit (p `star` p `star` p) (fun _ -> p `star` p `star` p)
= f 0; ()
assume val ref : Type0
assume val ptr (_:ref) : vprop
assume val alloc (x:int) : SteelT ref emp (fun y -> ptr y)
assume val free (r:ref) : SteelT unit (ptr r) (fun _ -> emp)
assume val read (r:ref) : SteelT int (ptr r) (fun _ -> ptr r)
assume val write (r:ref) (v: int) : SteelT unit (ptr r) (fun _ -> ptr r)
let unused x = x // work around another gensym heisenbug
let test0 (b1 b2 b3: ref) : SteelT int
(ptr b1 `star` ptr b2 `star` ptr b3)
(fun _ -> ptr b1 `star` ptr b2 `star` ptr b3)
=
let x = read b1 in
x
let test1 (b1 b2 b3: ref) : SteelT int
(ptr b1 `star` ptr b2 `star` ptr b3)
(fun _ -> ptr b1 `star` ptr b2 `star` ptr b3)
=
let x = (let y = read b1 in y) in
x
let test2 (b1 b2 b3: ref) : SteelT int
(ptr b1 `star` ptr b2 `star` ptr b3)
(fun _ -> ptr b3 `star` ptr b2 `star` ptr b1)
=
let x = read b1 in
x
let test3 (b1 b2 b3: ref) : SteelT int
(ptr b1 `star` ptr b2 `star` ptr b3)
(fun _ -> ptr b2 `star` ptr b1 `star` ptr b3)
=
let x = read b3 in
x
let test4 (b1 b2 b3: ref) : SteelT unit
(ptr b1 `star` ptr b2 `star` ptr b3)
(fun _ -> ptr b2 `star` ptr b1 `star` ptr b3)
=
let x = read b3 in
write b2 x
let test5 (b1 b2 b3: ref) : SteelT unit
(ptr b1 `star` ptr b2 `star` ptr b3)
(fun _ -> ptr b2 `star` ptr b1 `star` ptr b3)
=
let x = read b3 in
write b2 (x + 1)
let test6 (b1 b2 b3: ref) : SteelT unit
(ptr b1 `star` ptr b2 `star` ptr b3)
(fun _ -> ptr b2 `star` ptr b1 `star` ptr b3)
=
let x = read b3 in
let b4 = alloc x in
write b2 (x + 1);
free b4
// With the formalism relying on can_be_split_post, this example fails if we normalize return_pre eqs goals before unification
// When solving this equality, we have the goal
// (*?u19*) _ _ == return_pre ((fun x -> (fun x -> (*?u758*) _ x x) x) r)
// with x and r in the context of ?u19
// Not normalizing allows us to solve it as a function applied to x and r
// Normalizing would lead to solve it to an slprop with x and r in the context,
// but which would later fail when trying to prove the equivalence with (fun r -> ptr r)
// in the postcondition
let test7 (_:unit) : SteelT ref emp ptr
= let r = alloc 0 in
let x = read r in
write r 0;
r | {
"checked_file": "/",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "SteelFramingTestSuite.fst"
} | [
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | b1: SteelFramingTestSuite.ref -> b2: SteelFramingTestSuite.ref -> b3: SteelFramingTestSuite.ref
-> Steel.Effect.SteelT Prims.unit | Steel.Effect.SteelT | [] | [] | [
"SteelFramingTestSuite.ref",
"SteelFramingTestSuite.write",
"Prims.unit",
"Steel.Effect.Common.star",
"SteelFramingTestSuite.ptr",
"Steel.Effect.Common.vprop"
] | [] | false | true | false | false | false | let test8 (b1 b2 b3: ref)
: SteelT unit
(((ptr b1) `star` (ptr b2)) `star` (ptr b3))
(fun _ -> ((ptr b2) `star` (ptr b1)) `star` (ptr b3)) =
| write b2 0 | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_is_zero_mask_lemma | val bn_is_zero_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len ->
Lemma (mask_values (bn_is_zero_mask a) /\
(if v (bn_is_zero_mask a) = 0 then bn_v a <> 0 else bn_v a = 0)) | val bn_is_zero_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len ->
Lemma (mask_values (bn_is_zero_mask a) /\
(if v (bn_is_zero_mask a) = 0 then bn_v a <> 0 else bn_v a = 0)) | let bn_is_zero_mask_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask_lemma b | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 53,
"end_line": 228,
"start_col": 0,
"start_line": 227
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind
let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l
let bn_get_bits_lemma #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l
let bn_set_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit input ind
let bn_set_ith_bit_lemma #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma input ind
(* conditional swap *)
let cswap2 #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2 bit b1 b2
let cswap2_lemma #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2_lemma bit b1 b2
(* Bignum comparison and test functions *)
let bn_is_odd #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd b
let bn_is_odd_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd_lemma b
let bn_eq_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask a b
let bn_eq_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask_lemma a b
let bn_is_zero_mask #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t len
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Bignum.Base.mask_values (Hacl.Spec.Bignum.bn_is_zero_mask a) /\
(match Lib.IntTypes.v (Hacl.Spec.Bignum.bn_is_zero_mask a) = 0 with
| true -> Hacl.Spec.Bignum.Definitions.bn_v a <> 0
| _ -> Hacl.Spec.Bignum.Definitions.bn_v a = 0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Comparison.bn_is_zero_mask_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let bn_is_zero_mask_lemma #t #len b =
| Hacl.Spec.Bignum.Comparison.bn_is_zero_mask_lemma b | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_get_bits_lemma | val bn_get_bits_lemma:
#t:limb_t
-> #nLen:size_nat
-> n:lbignum t nLen
-> i:size_nat
-> l:size_nat{l < bits t /\ i / bits t < nLen} ->
Lemma (v (bn_get_bits n i l) == (bn_v n / pow2 i) % pow2 l) | val bn_get_bits_lemma:
#t:limb_t
-> #nLen:size_nat
-> n:lbignum t nLen
-> i:size_nat
-> l:size_nat{l < bits t /\ i / bits t < nLen} ->
Lemma (v (bn_get_bits n i l) == (bn_v n / pow2 i) % pow2 l) | let bn_get_bits_lemma #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 194,
"start_col": 0,
"start_line": 193
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind
let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
n: Hacl.Spec.Bignum.Definitions.lbignum t nLen ->
i: Lib.IntTypes.size_nat ->
l: Lib.IntTypes.size_nat{l < Lib.IntTypes.bits t /\ i / Lib.IntTypes.bits t < nLen}
-> FStar.Pervasives.Lemma
(ensures
Lib.IntTypes.v (Hacl.Spec.Bignum.bn_get_bits n i l) ==
Hacl.Spec.Bignum.Definitions.bn_v n / Prims.pow2 i % Prims.pow2 l) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.bits",
"Prims.op_Division",
"Hacl.Spec.Bignum.Lib.bn_get_bits_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let bn_get_bits_lemma #t #nLen n i l =
| Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_set_ith_bit | val bn_set_ith_bit:
#t:limb_t
-> #len:size_nat
-> b:lbignum t len
-> i:size_nat{i / bits t < len} ->
lbignum t len | val bn_set_ith_bit:
#t:limb_t
-> #len:size_nat
-> b:lbignum t len
-> i:size_nat{i / bits t < len} ->
lbignum t len | let bn_set_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit input ind | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 197,
"start_col": 0,
"start_line": 196
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind
let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l
let bn_get_bits_lemma #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
b: Hacl.Spec.Bignum.Definitions.lbignum t len ->
i: Lib.IntTypes.size_nat{i / Lib.IntTypes.bits t < len}
-> Hacl.Spec.Bignum.Definitions.lbignum t len | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Division",
"Lib.IntTypes.bits",
"Hacl.Spec.Bignum.Lib.bn_set_ith_bit"
] | [] | false | false | false | false | false | let bn_set_ith_bit #t #len input ind =
| Hacl.Spec.Bignum.Lib.bn_set_ith_bit input ind | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_lt_mask_lemma | val bn_lt_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len ->
Lemma (mask_values (bn_lt_mask a b) /\
(if v (bn_lt_mask a b) = 0 then bn_v a >= bn_v b else bn_v a < bn_v b)) | val bn_lt_mask_lemma: #t:limb_t -> #len:size_nat -> a:lbignum t len -> b:lbignum t len ->
Lemma (mask_values (bn_lt_mask a b) /\
(if v (bn_lt_mask a b) = 0 then bn_v a >= bn_v b else bn_v a < bn_v b)) | let bn_lt_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask_lemma a b | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 234,
"start_col": 0,
"start_line": 233
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind
let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l
let bn_get_bits_lemma #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l
let bn_set_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit input ind
let bn_set_ith_bit_lemma #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma input ind
(* conditional swap *)
let cswap2 #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2 bit b1 b2
let cswap2_lemma #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2_lemma bit b1 b2
(* Bignum comparison and test functions *)
let bn_is_odd #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd b
let bn_is_odd_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd_lemma b
let bn_eq_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask a b
let bn_eq_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask_lemma a b
let bn_is_zero_mask #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask b
let bn_is_zero_mask_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask_lemma b
let bn_lt_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask a b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Spec.Bignum.Definitions.lbignum t len -> b: Hacl.Spec.Bignum.Definitions.lbignum t len
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Bignum.Base.mask_values (Hacl.Spec.Bignum.bn_lt_mask a b) /\
(match Lib.IntTypes.v (Hacl.Spec.Bignum.bn_lt_mask a b) = 0 with
| true -> Hacl.Spec.Bignum.Definitions.bn_v a >= Hacl.Spec.Bignum.Definitions.bn_v b
| _ -> Hacl.Spec.Bignum.Definitions.bn_v a < Hacl.Spec.Bignum.Definitions.bn_v b)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Comparison.bn_lt_mask_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let bn_lt_mask_lemma #t #len a b =
| Hacl.Spec.Bignum.Comparison.bn_lt_mask_lemma a b | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_lt_pow2_mask_lemma | val bn_lt_pow2_mask_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> x:size_nat{x < bits t * len} ->
Lemma (mask_values (bn_lt_pow2_mask b x) /\
(if v (bn_lt_pow2_mask b x) = 0 then bn_v b >= pow2 x else bn_v b < pow2 x)) | val bn_lt_pow2_mask_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> x:size_nat{x < bits t * len} ->
Lemma (mask_values (bn_lt_pow2_mask b x) /\
(if v (bn_lt_pow2_mask b x) = 0 then bn_v b >= pow2 x else bn_v b < pow2 x)) | let bn_lt_pow2_mask_lemma #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask_lemma b x | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 240,
"start_col": 0,
"start_line": 239
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind
let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l
let bn_get_bits_lemma #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l
let bn_set_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit input ind
let bn_set_ith_bit_lemma #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma input ind
(* conditional swap *)
let cswap2 #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2 bit b1 b2
let cswap2_lemma #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2_lemma bit b1 b2
(* Bignum comparison and test functions *)
let bn_is_odd #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd b
let bn_is_odd_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd_lemma b
let bn_eq_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask a b
let bn_eq_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask_lemma a b
let bn_is_zero_mask #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask b
let bn_is_zero_mask_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask_lemma b
let bn_lt_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask a b
let bn_lt_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask_lemma a b
let bn_lt_pow2_mask #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask b x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
b: Hacl.Spec.Bignum.Definitions.lbignum t len ->
x: Lib.IntTypes.size_nat{x < Lib.IntTypes.bits t * len}
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Bignum.Base.mask_values (Hacl.Spec.Bignum.bn_lt_pow2_mask b x) /\
(match Lib.IntTypes.v (Hacl.Spec.Bignum.bn_lt_pow2_mask b x) = 0 with
| true -> Hacl.Spec.Bignum.Definitions.bn_v b >= Prims.pow2 x
| _ -> Hacl.Spec.Bignum.Definitions.bn_v b < Prims.pow2 x)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Mul.op_Star",
"Lib.IntTypes.bits",
"Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let bn_lt_pow2_mask_lemma #t #len b x =
| Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask_lemma b x | false |
Bane.Test.fst | Bane.Test.test | val test : Prims.unit | let test =
assert for_you by Bane.Lib.mytac () | {
"file_name": "examples/tactics/Bane.Test.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 38,
"end_line": 21,
"start_col": 0,
"start_line": 20
} | (*
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 Bane.Test
open FStar.Tactics.V2
open Bane.Lib | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Pervasives.fsti.checked",
"Bane.Lib.fst.checked"
],
"interface_file": false,
"source_file": "Bane.Test.fst"
} | [
{
"abbrev": false,
"full_module": "Bane.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Bane",
"short_module": null
},
{
"abbrev": false,
"full_module": "Bane",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | Prims.Tot | [
"total"
] | [] | [
"FStar.Tactics.Effect.assert_by_tactic",
"Bane.Lib.for_you",
"Prims.unit",
"Bane.Lib.mytac"
] | [] | false | false | false | true | false | let test =
| FStar.Tactics.Effect.assert_by_tactic for_you
(fun _ ->
();
Bane.Lib.mytac ()) | false |
|
LList.Invariant.fsti | LList.Invariant.t | val t : a: Type0 -> Type0 | let t (a:Type0) = ref (cell a) | {
"file_name": "share/steel/examples/steel/LList.Invariant.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 30,
"end_line": 26,
"start_col": 0,
"start_line": 26
} | (*
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.
Author(s): N. Swamy, A. Fromherz
*)
module LList.Invariant
open Steel.Memory
open Steel.Effect
open Steel.FractionalPermission
open Steel.Reference
module L = FStar.List.Tot | {
"checked_file": "/",
"dependencies": [
"Steel.Reference.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "LList.Invariant.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.Reference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.Reference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "LList",
"short_module": null
},
{
"abbrev": false,
"full_module": "LList",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: Type0 -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Steel.Reference.ref",
"LList.Invariant.cell"
] | [] | false | false | false | true | true | let t (a: Type0) =
| ref (cell a) | false |
|
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_gt_pow2_mask_lemma | val bn_gt_pow2_mask_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> x:size_nat{x < bits t * len} ->
Lemma (mask_values (bn_gt_pow2_mask b x) /\
(if v (bn_gt_pow2_mask b x) = 0 then pow2 x >= bn_v b else pow2 x < bn_v b)) | val bn_gt_pow2_mask_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> x:size_nat{x < bits t * len} ->
Lemma (mask_values (bn_gt_pow2_mask b x) /\
(if v (bn_gt_pow2_mask b x) = 0 then pow2 x >= bn_v b else pow2 x < bn_v b)) | let bn_gt_pow2_mask_lemma #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask_lemma b x | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 246,
"start_col": 0,
"start_line": 245
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind
let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l
let bn_get_bits_lemma #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l
let bn_set_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit input ind
let bn_set_ith_bit_lemma #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma input ind
(* conditional swap *)
let cswap2 #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2 bit b1 b2
let cswap2_lemma #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2_lemma bit b1 b2
(* Bignum comparison and test functions *)
let bn_is_odd #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd b
let bn_is_odd_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd_lemma b
let bn_eq_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask a b
let bn_eq_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask_lemma a b
let bn_is_zero_mask #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask b
let bn_is_zero_mask_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask_lemma b
let bn_lt_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask a b
let bn_lt_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask_lemma a b
let bn_lt_pow2_mask #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask b x
let bn_lt_pow2_mask_lemma #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask_lemma b x
let bn_gt_pow2_mask #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask b x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
b: Hacl.Spec.Bignum.Definitions.lbignum t len ->
x: Lib.IntTypes.size_nat{x < Lib.IntTypes.bits t * len}
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Bignum.Base.mask_values (Hacl.Spec.Bignum.bn_gt_pow2_mask b x) /\
(match Lib.IntTypes.v (Hacl.Spec.Bignum.bn_gt_pow2_mask b x) = 0 with
| true -> Prims.pow2 x >= Hacl.Spec.Bignum.Definitions.bn_v b
| _ -> Prims.pow2 x < Hacl.Spec.Bignum.Definitions.bn_v b)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Mul.op_Star",
"Lib.IntTypes.bits",
"Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let bn_gt_pow2_mask_lemma #t #len b x =
| Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask_lemma b x | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_from_uint | val bn_from_uint: #t:limb_t -> len:size_pos -> x:limb t -> lbignum t len | val bn_from_uint: #t:limb_t -> len:size_pos -> x:limb t -> lbignum t len | let bn_from_uint #t len x =
Hacl.Spec.Bignum.Convert.bn_from_uint len x | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 251,
"start_col": 0,
"start_line": 250
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind
let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l
let bn_get_bits_lemma #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l
let bn_set_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit input ind
let bn_set_ith_bit_lemma #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma input ind
(* conditional swap *)
let cswap2 #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2 bit b1 b2
let cswap2_lemma #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2_lemma bit b1 b2
(* Bignum comparison and test functions *)
let bn_is_odd #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd b
let bn_is_odd_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd_lemma b
let bn_eq_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask a b
let bn_eq_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask_lemma a b
let bn_is_zero_mask #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask b
let bn_is_zero_mask_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask_lemma b
let bn_lt_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask a b
let bn_lt_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask_lemma a b
let bn_lt_pow2_mask #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask b x
let bn_lt_pow2_mask_lemma #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask_lemma b x
let bn_gt_pow2_mask #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask b x
let bn_gt_pow2_mask_lemma #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask_lemma b x
(* Conversion functions *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | len: Lib.IntTypes.size_pos -> x: Hacl.Spec.Bignum.Definitions.limb t
-> Hacl.Spec.Bignum.Definitions.lbignum t len | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_pos",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Convert.bn_from_uint",
"Hacl.Spec.Bignum.Definitions.lbignum"
] | [] | false | false | false | false | false | let bn_from_uint #t len x =
| Hacl.Spec.Bignum.Convert.bn_from_uint len x | false |
Vale.Transformers.PrefetchElim.fst | Vale.Transformers.PrefetchElim.prefetch_elim_ph | val prefetch_elim_ph : Vale.Transformers.PeepHole.pre_peephole | let prefetch_elim_ph = {
ph = (function
| [Instr i oprs (AnnotatePrefetchnta ())] ->
Some []
| _ -> None);
input_hint = 1;
} | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.PrefetchElim.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 1,
"end_line": 20,
"start_col": 0,
"start_line": 14
} | module Vale.Transformers.PrefetchElim
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Transformers.InstructionReorder
open Vale.X64.InsLemmas
open Vale.Transformers.PeepHole | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.InsLemmas.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.PeepHole.fsti.checked",
"Vale.Transformers.InstructionReorder.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Transformers.PrefetchElim.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Transformers.PeepHole",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers.InstructionReorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Vale.Transformers.PeepHole.pre_peephole | Prims.Tot | [
"total"
] | [] | [
"Vale.Transformers.PeepHole.Mkpre_peephole",
"Prims.list",
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Instruction_s.instr_t_record",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args",
"FStar.Pervasives.Native.Some",
"Prims.Nil",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.option"
] | [] | false | false | false | true | false | let prefetch_elim_ph =
| {
ph
=
(function
| [Instr i oprs (AnnotatePrefetchnta ())] -> Some []
| _ -> None);
input_hint = 1
} | false |
|
Steel.ST.HigherArray.fst | Steel.ST.HigherArray.upd_ptr | val upd_ptr
(#t: Type)
(a: ptr t)
(#len: Ghost.erased nat { offset a + len <= base_len (base a) })
(#s: Ghost.erased (Seq.seq t))
(i: US.t { US.v i < Seq.length s })
(v: t)
: STT unit
(pts_to (| a, len |) P.full_perm s)
(fun res -> pts_to (| a, len |) P.full_perm (Seq.upd s (US.v i) v)) | val upd_ptr
(#t: Type)
(a: ptr t)
(#len: Ghost.erased nat { offset a + len <= base_len (base a) })
(#s: Ghost.erased (Seq.seq t))
(i: US.t { US.v i < Seq.length s })
(v: t)
: STT unit
(pts_to (| a, len |) P.full_perm s)
(fun res -> pts_to (| a, len |) P.full_perm (Seq.upd s (US.v i) v)) | let upd_ptr a i v =
upd0 _ i v;
rewrite
(pts_to _ _ _)
(pts_to _ _ _) | {
"file_name": "lib/steel/Steel.ST.HigherArray.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 18,
"end_line": 487,
"start_col": 0,
"start_line": 483
} | (*
Copyright 2022 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.ST.HigherArray
module P = Steel.PCMFrac
module R = Steel.ST.PCMReference
module M = FStar.Map
module PM = Steel.PCMMap
[@@noextract_to "krml"]
let index_t (len: Ghost.erased nat) : Tot Type0 =
(i: nat { i < len })
[@@noextract_to "krml"]
let carrier (elt: Type u#a) (len: Ghost.erased nat) : Tot Type =
PM.map (index_t len) (P.fractional elt)
[@@noextract_to "krml"]
let pcm (elt: Type u#a) (len: Ghost.erased nat) : Tot (P.pcm (carrier elt len)) =
PM.pointwise (index_t len) (P.pcm_frac #elt)
[@@noextract_to "krml"]
let one (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.one
let composable (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.composable
[@@noextract_to "krml"]
let compose (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.op
[@@noextract_to "krml"]
let mk_carrier
(#elt: Type)
(len: nat)
(offset: nat)
(s: Seq.seq elt)
(p: P.perm)
: Tot (carrier elt len)
= let f (i: nat) : Tot (P.fractional elt) =
if offset + Seq.length s > len || i < offset || i >= offset + Seq.length s
then None
else Some (Seq.index s (i - offset), p)
in
M.map_literal f
let mk_carrier_inj
(#elt: Type)
(len: nat)
(offset: nat)
(s1 s2: Seq.seq elt)
(p1 p2: P.perm)
: Lemma
(requires (
mk_carrier len offset s1 p1 == mk_carrier len offset s2 p2 /\
offset + Seq.length s1 <= len /\
offset + Seq.length s2 <= len
))
(ensures (
s1 `Seq.equal` s2 /\
(Seq.length s1 > 0 ==> p1 == p2)
))
= assert (forall (i: nat) . i < Seq.length s1 ==>
(M.sel (mk_carrier len offset s1 p1) (offset + i) == Some (Seq.index s1 i, p1)));
assert (forall (i: nat) . i < Seq.length s2 ==>
M.sel (mk_carrier len offset s2 p2) (offset + i) == Some (Seq.index s2 i, p2))
[@@erasable]
let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: US.t & ref _ (pcm elt (US.v base_len)))
let base_len (#elt: Type) (b: base_t elt) : GTot nat = US.v (dfst b)
[@@noextract_to "krml"]
noeq
type ptr (elt: Type u#a) : Type0 = {
base_len: Ghost.erased US.t;
// U32.t to prove that A.read, A.write offset computation does not overflow. TODO: replace U32.t with size_t
base: (r: ref _ (pcm elt (US.v base_len)) { core_ref_is_null r ==> US.v base_len == 0 });
offset: (offset: nat { offset <= US.v base_len });
}
let null_ptr a = { base_len = 0sz; base = null #_ #(pcm a 0) ; offset = 0 }
let is_null_ptr p = is_null p.base
let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |)
let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset
let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma
(requires (
base p1 == base p2 /\
offset p1 == offset p2
))
(ensures (
p1 == p2
))
= ()
let base_len_null_ptr _ = ()
let length_fits #elt a = ()
let valid_perm
(len: nat)
(offset: nat)
(slice_len: nat)
(p: P.perm) : Tot prop =
let open FStar.Real in
((offset + slice_len <= len /\ slice_len > 0) ==> (p.P.v <=. one))
[@__reduce__]
let pts_to0 (#elt: Type u#1) (a: array elt) (p: P.perm) (s: Seq.seq elt) : Tot vprop =
R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p) `star`
pure (
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\
Seq.length s == length a
)
let pts_to (#elt: Type u#1) (a: array elt) ([@@@ smt_fallback ] p: P.perm) ([@@@ smt_fallback ] s: Seq.seq elt) : Tot vprop =
pts_to0 a p s
// this lemma is necessary because Steel.PCMReference is marked unfold
let change_r_pts_to
(#opened: _)
(#carrier: Type u#1)
(#pcm: P.pcm carrier)
(p: ref carrier pcm)
(v: carrier)
(#carrier': Type u#1)
(#pcm': P.pcm carrier')
(p': ref carrier' pcm')
(v': carrier')
: STGhost unit opened
(R.pts_to p v)
(fun _ -> R.pts_to p' v')
(// keep on distinct lines for error messages
carrier == carrier' /\
pcm == pcm' /\
p == p' /\
v == v')
(fun _ -> True)
= rewrite
(R.pts_to p v)
(R.pts_to p' v')
let intro_pts_to (#opened: _) (#elt: Type u#1) (a: array elt) (#v: _) (p: P.perm) (s: Seq.seq elt) : STGhost unit opened
(R.pts_to (ptr_of a).base v)
(fun _ -> pts_to a p s)
(
v == mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p /\
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\
Seq.length s == length a
)
(fun _ -> True)
= change_r_pts_to (ptr_of a).base v (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p);
intro_pure _;
rewrite
(pts_to0 a p s)
(pts_to a p s)
let elim_pts_to (#opened: _) (#elt: Type u#1) (a: array elt) (p: P.perm) (s: Seq.seq elt) : STGhost unit opened
(pts_to a p s)
(fun _ -> R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p))
(True)
(fun _ ->
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\
Seq.length s == length a
)
= rewrite
(pts_to a p s)
(pts_to0 a p s);
elim_pure _
let pts_to_length
a s
=
elim_pts_to a _ s;
intro_pts_to a _ s
let pts_to_not_null
a s
= elim_pts_to a _ s;
R.pts_to_not_null _ _;
intro_pts_to a _ s
let mk_carrier_joinable
(#elt: Type)
(len: nat)
(offset: nat)
(s1: Seq.seq elt)
(p1: P.perm)
(s2: Seq.seq elt)
(p2: P.perm)
: Lemma
(requires (
offset + Seq.length s1 <= len /\
Seq.length s1 == Seq.length s2 /\
P.joinable (pcm elt len) (mk_carrier len offset s1 p1) (mk_carrier len offset s2 p2)
))
(ensures (
s1 `Seq.equal` s2
))
=
let lem
(i: nat { 0 <= i /\ i < Seq.length s1 })
: Lemma
(Seq.index s1 i == Seq.index s2 i)
[SMTPat (Seq.index s1 i); SMTPat (Seq.index s2 i)]
= assert (
forall z . (
P.compatible (pcm elt len) (mk_carrier len offset s1 p1) z /\
P.compatible (pcm elt len) (mk_carrier len offset s2 p2) z
) ==>
begin match M.sel z (offset + i) with
| None -> False
| Some (v, _) -> v == Seq.index s1 i /\ v == Seq.index s2 i
end
)
in
()
let pure_star_interp' (p:slprop u#a) (q:prop) (m:mem)
: Lemma (interp (p `Steel.Memory.star` Steel.Memory.pure q) m <==>
interp p m /\ q)
= pure_star_interp p q m;
emp_unit p
let pts_to_inj
a p1 s1 p2 s2 m
=
Classical.forall_intro reveal_pure;
pure_star_interp'
(hp_of (R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s1 p1)))
(
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s1) p1 /\
Seq.length s1 == length a
)
m;
pure_star_interp'
(hp_of (R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s2 p2)))
(
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s2) p2 /\
Seq.length s2 == length a
)
m;
pts_to_join
(ptr_of a).base
(mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s1 p1)
(mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s2 p2)
m;
mk_carrier_joinable (US.v (ptr_of a).base_len) (ptr_of a).offset s1 p1 s2 p2
[@@noextract_to "krml"]
let malloc0
(#elt: Type)
(x: elt)
(n: US.t)
: ST (array elt)
emp
(fun a -> pts_to a P.full_perm (Seq.create (US.v n) x))
(True)
(fun a ->
length a == US.v n /\
base_len (base (ptr_of a)) == US.v n
)
=
let c : carrier elt (US.v n) = mk_carrier (US.v n) 0 (Seq.create (US.v n) x) P.full_perm in
let base : ref (carrier elt (US.v n)) (pcm elt (US.v n)) = R.alloc c in
R.pts_to_not_null base _;
let p = {
base_len = n;
base = base;
offset = 0;
}
in
let a = (| p, Ghost.hide (US.v n) |) in
change_r_pts_to
base c
(ptr_of a).base c;
intro_pts_to a P.full_perm (Seq.create (US.v n) x);
return a
let malloc_ptr
x n
=
let a = malloc0 x n in
let (| p, _ |) = a in
rewrite
(pts_to _ _ _)
(pts_to (| p, Ghost.hide (US.v n) |) _ _);
return p
[@@noextract_to "krml"]
let free0
(#elt: Type)
(#s: Ghost.erased (Seq.seq elt))
(a: array elt)
: ST unit
(pts_to a P.full_perm s)
(fun _ -> emp)
(
length a == base_len (base (ptr_of a))
)
(fun _ -> True)
= drop (pts_to a _ _)
let free_ptr a =
free0 _
let valid_sum_perm
(len: nat)
(offset: nat)
(slice_len: nat)
(p1 p2: P.perm)
: Tot prop
= let open FStar.Real in
valid_perm len offset slice_len (P.sum_perm p1 p2)
let mk_carrier_share
(#elt: Type)
(len: nat)
(offset: nat)
(s: Seq.seq elt)
(p1 p2: P.perm)
: Lemma
(requires (valid_sum_perm len offset (Seq.length s) p1 p2))
(ensures (
let c1 = mk_carrier len offset s p1 in
let c2 = mk_carrier len offset s p2 in
composable c1 c2 /\
mk_carrier len offset s (p1 `P.sum_perm` p2) `M.equal` (c1 `compose` c2)
))
= ()
let share
#_ #_ #x a p p1 p2
= elim_pts_to a p x;
mk_carrier_share (US.v (ptr_of a).base_len) (ptr_of a).offset x p1 p2;
R.split (ptr_of a).base _
(mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset x p1)
(mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset x p2);
intro_pts_to a p1 x;
intro_pts_to a p2 x
let mk_carrier_gather
(#elt: Type)
(len: nat)
(offset: nat)
(s1 s2: Seq.seq elt)
(p1 p2: P.perm)
: Lemma
(requires (
let c1 = mk_carrier len offset s1 p1 in
let c2 = mk_carrier len offset s2 p2 in
composable c1 c2 /\
Seq.length s1 == Seq.length s2 /\
offset + Seq.length s1 <= len
))
(ensures (
let c1 = mk_carrier len offset s1 p1 in
let c2 = mk_carrier len offset s2 p2 in
composable c1 c2 /\
mk_carrier len offset s1 (p1 `P.sum_perm` p2) == (c1 `compose` c2) /\
mk_carrier len offset s2 (p1 `P.sum_perm` p2) == (c1 `compose` c2) /\
s1 == s2
))
=
let c1 = mk_carrier len offset s1 p1 in
let c2 = mk_carrier len offset s2 p2 in
assert (composable c1 c2);
assert (mk_carrier len offset s1 (p1 `P.sum_perm` p2) `M.equal` (c1 `compose` c2));
assert (mk_carrier len offset s2 (p1 `P.sum_perm` p2) `M.equal` (c1 `compose` c2));
mk_carrier_inj len offset s1 s2 (p1 `P.sum_perm` p2) (p1 `P.sum_perm` p2)
let mk_carrier_valid_sum_perm
(#elt: Type)
(len: nat)
(offset: nat)
(s: Seq.seq elt)
(p1 p2: P.perm)
: Lemma
(let c1 = mk_carrier len offset s p1 in
let c2 = mk_carrier len offset s p2 in
composable c1 c2 <==> valid_sum_perm len offset (Seq.length s) p1 p2)
= let c1 = mk_carrier len offset s p1 in
let c2 = mk_carrier len offset s p2 in
if Seq.length s > 0 && offset + Seq.length s <= len
then
let open FStar.Real in
assert (P.composable (M.sel c1 offset) (M.sel c2 offset) <==> valid_perm len offset (Seq.length s) (P.sum_perm p1 p2))
else ()
let gather
a #x1 p1 #x2 p2
= elim_pts_to a p1 x1;
elim_pts_to a p2 x2;
let _ = R.gather (ptr_of a).base
(mk_carrier (US.v (ptr_of a).base_len) ((ptr_of a).offset) x1 p1)
(mk_carrier (US.v (ptr_of a).base_len) ((ptr_of a).offset) x2 p2)
in
mk_carrier_gather (US.v (ptr_of a).base_len) ((ptr_of a).offset) x1 x2 p1 p2;
mk_carrier_valid_sum_perm (US.v (ptr_of a).base_len) ((ptr_of a).offset) x1 p1 p2;
intro_pts_to a (p1 `P.sum_perm` p2) x1
#push-options "--z3rlimit 16"
[@@noextract_to "krml"]
let index0
(#t: Type) (#p: P.perm)
(a: array t)
(#s: Ghost.erased (Seq.seq t))
(i: US.t)
: ST t
(pts_to a p s)
(fun _ -> pts_to a p s)
(US.v i < length a \/ US.v i < Seq.length s)
(fun res -> Seq.length s == length a /\ US.v i < Seq.length s /\ res == Seq.index s (US.v i))
= elim_pts_to a p s;
let s' = R.read (ptr_of a).base _ in
let res = fst (Some?.v (M.sel s' ((ptr_of a).offset + US.v i))) in
intro_pts_to a p s;
return res
#pop-options
let index_ptr a i =
index0 _ i
let mk_carrier_upd
(#elt: Type)
(len: nat)
(offset: nat)
(s: Seq.seq elt)
(i: nat)
(v: elt)
(_: squash (
offset + Seq.length s <= len /\
i < Seq.length s
))
: Lemma
(ensures (
let o = mk_carrier len offset s P.full_perm in
let o' = mk_carrier len offset (Seq.upd s i v) P.full_perm in
o' `Map.equal` Map.upd o (offset + i) (Some (v, P.full_perm))
))
= ()
#push-options "--z3rlimit 20"
[@@noextract_to "krml"]
let upd0
(#t: Type)
(a: array t)
(#s: Ghost.erased (Seq.seq t))
(i: US.t { US.v i < Seq.length s })
(v: t)
: STT unit
(pts_to a P.full_perm s)
(fun res -> pts_to a P.full_perm (Seq.upd s (US.v i) v))
= elim_pts_to a _ _;
mk_carrier_upd (US.v (ptr_of a).base_len) ((ptr_of a).offset) s (US.v i) v ();
R.upd_gen
(ptr_of a).base
_ _
(PM.lift_frame_preserving_upd
_ _
(P.mk_frame_preserving_upd
(Seq.index s (US.v i))
v
)
_ ((ptr_of a).offset + US.v i)
);
intro_pts_to a _ _
#pop-options | {
"checked_file": "/",
"dependencies": [
"Steel.ST.PCMReference.fsti.checked",
"Steel.ST.Loops.fsti.checked",
"Steel.PCMMap.fst.checked",
"Steel.PCMFrac.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.HigherArray.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.PCMMap",
"short_module": "PM"
},
{
"abbrev": true,
"full_module": "FStar.Map",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Steel.ST.PCMReference",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "Steel.PCMFrac",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Steel.ST.HigherArray.ptr t ->
i: FStar.SizeT.t{FStar.SizeT.v i < FStar.Seq.Base.length (FStar.Ghost.reveal s)} ->
v: t
-> Steel.ST.Effect.STT Prims.unit | Steel.ST.Effect.STT | [] | [] | [
"Steel.ST.HigherArray.ptr",
"FStar.Ghost.erased",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Steel.ST.HigherArray.offset",
"FStar.Ghost.reveal",
"Steel.ST.HigherArray.base_len",
"Steel.ST.HigherArray.base",
"FStar.Seq.Base.seq",
"FStar.SizeT.t",
"Prims.op_LessThan",
"FStar.SizeT.v",
"FStar.Seq.Base.length",
"Steel.ST.Util.rewrite",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.ST.HigherArray.pts_to",
"Prims.Mkdtuple2",
"Steel.FractionalPermission.full_perm",
"FStar.Seq.Base.upd",
"Prims.unit",
"Steel.ST.HigherArray.upd0"
] | [] | false | true | false | false | false | let upd_ptr a i v =
| upd0 _ i v;
rewrite (pts_to _ _ _) (pts_to _ _ _) | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_from_uint_lemma | val bn_from_uint_lemma: #t:limb_t -> len:size_pos -> x:limb t ->
Lemma (bn_v (bn_from_uint len x) == uint_v x) | val bn_from_uint_lemma: #t:limb_t -> len:size_pos -> x:limb t ->
Lemma (bn_v (bn_from_uint len x) == uint_v x) | let bn_from_uint_lemma #t len x =
Hacl.Spec.Bignum.Convert.bn_from_uint_lemma len x | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 51,
"end_line": 254,
"start_col": 0,
"start_line": 253
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind
let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l
let bn_get_bits_lemma #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l
let bn_set_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit input ind
let bn_set_ith_bit_lemma #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma input ind
(* conditional swap *)
let cswap2 #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2 bit b1 b2
let cswap2_lemma #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2_lemma bit b1 b2
(* Bignum comparison and test functions *)
let bn_is_odd #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd b
let bn_is_odd_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd_lemma b
let bn_eq_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask a b
let bn_eq_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask_lemma a b
let bn_is_zero_mask #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask b
let bn_is_zero_mask_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask_lemma b
let bn_lt_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask a b
let bn_lt_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask_lemma a b
let bn_lt_pow2_mask #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask b x
let bn_lt_pow2_mask_lemma #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask_lemma b x
let bn_gt_pow2_mask #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask b x
let bn_gt_pow2_mask_lemma #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask_lemma b x
(* Conversion functions *)
let bn_from_uint #t len x =
Hacl.Spec.Bignum.Convert.bn_from_uint len x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | len: Lib.IntTypes.size_pos -> x: Hacl.Spec.Bignum.Definitions.limb t
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.Bignum.bn_from_uint len x) ==
Lib.IntTypes.uint_v x) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_pos",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Convert.bn_from_uint_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let bn_from_uint_lemma #t len x =
| Hacl.Spec.Bignum.Convert.bn_from_uint_lemma len x | false |
Selectors.LList2.fst | Selectors.LList2.intro_llist_cons | val intro_llist_cons (#a:Type0) (ptr1 ptr2:t a)
: Steel unit (vptr ptr1 `star` llist ptr2)
(fun _ -> llist ptr1)
(requires fun h -> next (sel ptr1 h) == ptr2)
(ensures fun h0 _ h1 -> v_llist ptr1 h1 == (data (sel ptr1 h0)) :: v_llist ptr2 h0) | val intro_llist_cons (#a:Type0) (ptr1 ptr2:t a)
: Steel unit (vptr ptr1 `star` llist ptr2)
(fun _ -> llist ptr1)
(requires fun h -> next (sel ptr1 h) == ptr2)
(ensures fun h0 _ h1 -> v_llist ptr1 h1 == (data (sel ptr1 h0)) :: v_llist ptr2 h0) | let intro_llist_cons
#a ptr1 ptr2
=
llist0_of_llist ptr2;
let n = nllist_of_llist0 ptr2 in
(* set the fuel of the new cons cell *)
let c = read ptr1 in
let c' = {c with tail_fuel = n} in
write ptr1 c' ;
(* actually cons the cell *)
vptr_not_null ptr1;
intro_vdep
(vptr ptr1)
(nllist a n ptr2)
(llist_vdep ptr1);
intro_vrewrite
(vptr ptr1 `vdep` llist_vdep ptr1)
(llist_vrewrite ptr1);
change_equal_slprop
((vptr ptr1 `vdep` llist_vdep ptr1) `vrewrite` llist_vrewrite ptr1)
(llist0 ptr1);
llist_of_llist0 ptr1 | {
"file_name": "share/steel/examples/steel/Selectors.LList2.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 22,
"end_line": 293,
"start_col": 0,
"start_line": 272
} | module Selectors.LList2
open Steel.FractionalPermission
module Mem = Steel.Memory
#push-options "--__no_positivity"
noeq
type cell (a: Type0) = {
tail_fuel: Ghost.erased nat;
next: ref (cell a);
data: a;
}
#pop-options
let next #a (c:cell a) : t a = c.next
let data #a (c:cell a) : a = c.data
let mk_cell #a (n: t a) (d:a) = {
tail_fuel = Ghost.hide 0;
next = n;
data = d
}
let null_llist #a = null
let is_null #a ptr = is_null ptr
let v_null_rewrite
(a: Type0)
(_: t_of emp)
: GTot (list a)
= []
let v_c
(n: Ghost.erased nat)
(#a: Type0)
(r: t a)
(c: normal (t_of (vptr r)))
: GTot prop
= (Ghost.reveal c.tail_fuel < Ghost.reveal n) == true // to ensure vprop termination
let v_c_dep
(n: Ghost.erased nat)
(#a: Type0)
(r: t a)
(nllist: (n': Ghost.erased nat) -> (r: t a { Ghost.reveal n' < Ghost.reveal n }) -> Pure vprop (requires True) (ensures (fun y -> t_of y == list a)))
(c: normal (t_of (vrefine (vptr r) (v_c n r))))
: Tot vprop
= nllist c.tail_fuel c.next
let v_c_l_rewrite
(n: Ghost.erased nat)
(#a: Type0)
(r: t a)
(nllist: (n': Ghost.erased nat) -> (r: t a { Ghost.reveal n' < Ghost.reveal n }) -> Pure vprop (requires True) (ensures (fun y -> t_of y == list a)))
(res: normal (t_of ((vptr r `vrefine` v_c n r) `vdep` v_c_dep n r nllist)))
: Tot (list a)
= let (| c, l |) = res in
c.data :: l
let rec nllist
(a: Type0)
(n: Ghost.erased nat)
(r: t a)
: Pure vprop
(requires True)
(ensures (fun y -> t_of y == list a))
(decreases (Ghost.reveal n))
= if is_null r
then emp `vrewrite` v_null_rewrite a
else ((vptr r `vrefine` v_c n r) `vdep` v_c_dep n r (nllist a)) `vrewrite` v_c_l_rewrite n r (nllist a)
let nllist_eq_not_null
(a: Type0)
(n: Ghost.erased nat)
(r: t a)
: Lemma
(requires (is_null r == false))
(ensures (
nllist a n r == ((vptr r `vrefine` v_c n r) `vdep` v_c_dep n r (nllist a)) `vrewrite` v_c_l_rewrite n r (nllist a)
))
= assert_norm (nllist a n r ==
begin if is_null r
then emp `vrewrite` v_null_rewrite a
else ((vptr r `vrefine` v_c n r) `vdep` v_c_dep n r (nllist a)) `vrewrite` v_c_l_rewrite n r (nllist a)
end
)
let llist_vdep
(#a: Type0)
(r: t a)
(c: normal (t_of (vptr r)))
: Tot vprop
= nllist a c.tail_fuel c.next
let llist_vrewrite
(#a: Type0)
(r: t a)
(cl: normal (t_of (vptr r `vdep` llist_vdep r)))
: GTot (list a)
= (dfst cl).data :: dsnd cl
let llist0
(#a: Type0)
(r: t a)
: Pure vprop
(requires True)
(ensures (fun y -> t_of y == list a))
= if is_null r
then emp `vrewrite` v_null_rewrite a
else (vptr r `vdep` llist_vdep r) `vrewrite` llist_vrewrite r
let nllist_of_llist0
(#opened: _)
(#a: Type0)
(r: t a)
: SteelGhost (Ghost.erased nat) opened
(llist0 r)
(fun res -> nllist a res r)
(fun _ -> True)
(fun h0 res h1 ->
h0 (llist0 r) == h1 (nllist a res r)
)
=
if is_null r
then begin
let res = Ghost.hide 0 in
change_equal_slprop
(llist0 r)
(nllist a res r);
res
end else begin
change_equal_slprop
(llist0 r)
((vptr r `vdep` llist_vdep r) `vrewrite` llist_vrewrite r);
elim_vrewrite (vptr r `vdep` llist_vdep r) (llist_vrewrite r);
let gk : normal (Ghost.erased (t_of (vptr r))) = elim_vdep (vptr r) (llist_vdep r) in
let res = Ghost.hide (Ghost.reveal (Ghost.reveal gk).tail_fuel + 1) in
intro_vrefine (vptr r) (v_c res r);
intro_vdep
(vptr r `vrefine` v_c res r)
(llist_vdep r (Ghost.reveal gk))
(v_c_dep res r (nllist a));
intro_vrewrite ((vptr r `vrefine` v_c res r) `vdep` v_c_dep res r (nllist a)) (v_c_l_rewrite res r (nllist a));
nllist_eq_not_null a res r;
change_equal_slprop
(((vptr r `vrefine` v_c res r) `vdep` v_c_dep res r (nllist a)) `vrewrite` v_c_l_rewrite res r (nllist a))
(nllist a res r);
res
end
let llist0_of_nllist
(#opened: _)
(#a: Type0)
(n: Ghost.erased nat)
(r: t a)
: SteelGhost unit opened
(nllist a n r)
(fun _ -> llist0 r)
(fun _ -> True)
(fun h0 res h1 ->
h1 (llist0 r) == h0 (nllist a n r)
)
=
if is_null r
then begin
change_equal_slprop
(nllist a n r)
(llist0 r);
()
end else begin
nllist_eq_not_null a n r;
change_equal_slprop
(nllist a n r)
(((vptr r `vrefine` v_c n r) `vdep` v_c_dep n r (nllist a)) `vrewrite` v_c_l_rewrite n r (nllist a));
elim_vrewrite ((vptr r `vrefine` v_c n r) `vdep` v_c_dep n r (nllist a)) (v_c_l_rewrite n r (nllist a));
let gk = elim_vdep (vptr r `vrefine` v_c n r) (v_c_dep n r (nllist a)) in
elim_vrefine (vptr r) (v_c n r);
intro_vdep
(vptr r)
(v_c_dep n r (nllist a) (Ghost.reveal gk))
(llist_vdep r);
intro_vrewrite (vptr r `vdep` llist_vdep r) (llist_vrewrite r);
change_equal_slprop
((vptr r `vdep` llist_vdep r) `vrewrite` llist_vrewrite r)
(llist0 r)
end
let llist_sl
#a r
= hp_of (llist0 r)
let llist_sel
#a r
= fun m -> sel_of (llist0 r) m // eta necessary because sel_of is GTot
let llist_of_llist0
(#opened: _)
(#a: Type)
(r: t a)
: SteelGhost unit opened
(llist0 r)
(fun _ -> llist r)
(fun _ -> True)
(fun h0 _ h1 -> h1 (llist r) == h0 (llist0 r))
=
change_slprop_rel
(llist0 r)
(llist r)
(fun x y -> x == y)
(fun _ -> ())
let llist0_of_llist
(#opened: _)
(#a: Type)
(r: t a)
: SteelGhost unit opened
(llist r)
(fun _ -> llist0 r)
(fun _ -> True)
(fun h0 _ h1 -> h1 (llist0 r) == h0 (llist r))
=
change_slprop_rel
(llist r)
(llist0 r)
(fun x y -> x == y)
(fun _ -> ())
let intro_llist_nil a =
intro_vrewrite emp (v_null_rewrite a);
change_equal_slprop
(emp `vrewrite` v_null_rewrite a)
(llist0 (null_llist #a));
llist_of_llist0 (null_llist #a)
let is_nil' (#opened: _) (#a:Type0) (ptr:t a)
: SteelGhost unit opened (llist ptr) (fun _ -> llist ptr)
(requires fun _ -> True)
(ensures fun h0 _ h1 ->
let res = is_null ptr in
(res == true <==> ptr == null_llist #a) /\
v_llist ptr h0 == v_llist ptr h1 /\
res == Nil? (v_llist ptr h1))
=
let res = is_null ptr in
llist0_of_llist ptr;
if res
then begin
change_equal_slprop
(llist0 ptr)
(emp `vrewrite` v_null_rewrite a);
elim_vrewrite emp (v_null_rewrite a);
intro_vrewrite emp (v_null_rewrite a);
change_equal_slprop
(emp `vrewrite` v_null_rewrite a)
(llist0 ptr)
end else begin
change_equal_slprop
(llist0 ptr)
((vptr ptr `vdep` llist_vdep ptr) `vrewrite` llist_vrewrite ptr);
elim_vrewrite (vptr ptr `vdep` llist_vdep ptr) (llist_vrewrite ptr);
intro_vrewrite (vptr ptr `vdep` llist_vdep ptr) (llist_vrewrite ptr);
change_equal_slprop
((vptr ptr `vdep` llist_vdep ptr) `vrewrite` llist_vrewrite ptr)
(llist0 ptr)
end;
llist_of_llist0 ptr
let is_nil
#a ptr
= is_nil' ptr;
return (is_null ptr) | {
"checked_file": "/",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Selectors.LList2.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.Memory",
"short_module": "Mem"
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.Reference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Selectors",
"short_module": null
},
{
"abbrev": false,
"full_module": "Selectors",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | ptr1: Selectors.LList2.t a -> ptr2: Selectors.LList2.t a -> Steel.Effect.Steel Prims.unit | Steel.Effect.Steel | [] | [] | [
"Selectors.LList2.t",
"Selectors.LList2.llist_of_llist0",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Prims.unit",
"Steel.Effect.Atomic.change_equal_slprop",
"Steel.Effect.Common.vrewrite",
"Steel.Effect.Common.vdep",
"Steel.Reference.vptr",
"Selectors.LList2.cell",
"Selectors.LList2.llist_vdep",
"Prims.list",
"Selectors.LList2.llist_vrewrite",
"Selectors.LList2.llist0",
"Steel.Effect.Atomic.intro_vrewrite",
"Steel.Effect.Atomic.intro_vdep",
"Selectors.LList2.nllist",
"Steel.Reference.vptr_not_null",
"Steel.Reference.write",
"Selectors.LList2.Mkcell",
"Selectors.LList2.__proj__Mkcell__item__next",
"Selectors.LList2.__proj__Mkcell__item__data",
"Steel.Reference.read",
"FStar.Ghost.erased",
"Prims.nat",
"Selectors.LList2.nllist_of_llist0",
"Selectors.LList2.llist0_of_llist"
] | [] | false | true | false | false | false | let intro_llist_cons #a ptr1 ptr2 =
| llist0_of_llist ptr2;
let n = nllist_of_llist0 ptr2 in
let c = read ptr1 in
let c' = { c with tail_fuel = n } in
write ptr1 c';
vptr_not_null ptr1;
intro_vdep (vptr ptr1) (nllist a n ptr2) (llist_vdep ptr1);
intro_vrewrite ((vptr ptr1) `vdep` (llist_vdep ptr1)) (llist_vrewrite ptr1);
change_equal_slprop (((vptr ptr1) `vdep` (llist_vdep ptr1)) `vrewrite` (llist_vrewrite ptr1))
(llist0 ptr1);
llist_of_llist0 ptr1 | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_from_bytes_be_lemma | val bn_from_bytes_be_lemma:
#t:limb_t
-> len:size_pos{numbytes t * (blocks len (numbytes t)) <= max_size_t}
-> b:lseq uint8 len ->
Lemma (bn_v (bn_from_bytes_be #t len b) == BSeq.nat_from_bytes_be b) | val bn_from_bytes_be_lemma:
#t:limb_t
-> len:size_pos{numbytes t * (blocks len (numbytes t)) <= max_size_t}
-> b:lseq uint8 len ->
Lemma (bn_v (bn_from_bytes_be #t len b) == BSeq.nat_from_bytes_be b) | let bn_from_bytes_be_lemma #t len b =
Hacl.Spec.Bignum.Convert.bn_from_bytes_be_lemma #t len b | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 58,
"end_line": 260,
"start_col": 0,
"start_line": 259
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind
let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l
let bn_get_bits_lemma #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l
let bn_set_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit input ind
let bn_set_ith_bit_lemma #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma input ind
(* conditional swap *)
let cswap2 #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2 bit b1 b2
let cswap2_lemma #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2_lemma bit b1 b2
(* Bignum comparison and test functions *)
let bn_is_odd #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd b
let bn_is_odd_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd_lemma b
let bn_eq_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask a b
let bn_eq_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask_lemma a b
let bn_is_zero_mask #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask b
let bn_is_zero_mask_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask_lemma b
let bn_lt_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask a b
let bn_lt_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask_lemma a b
let bn_lt_pow2_mask #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask b x
let bn_lt_pow2_mask_lemma #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask_lemma b x
let bn_gt_pow2_mask #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask b x
let bn_gt_pow2_mask_lemma #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask_lemma b x
(* Conversion functions *)
let bn_from_uint #t len x =
Hacl.Spec.Bignum.Convert.bn_from_uint len x
let bn_from_uint_lemma #t len x =
Hacl.Spec.Bignum.Convert.bn_from_uint_lemma len x
let bn_from_bytes_be #t len b =
Hacl.Spec.Bignum.Convert.bn_from_bytes_be len b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
len:
Lib.IntTypes.size_pos
{ Lib.IntTypes.numbytes t *
Hacl.Spec.Bignum.Definitions.blocks len (Lib.IntTypes.numbytes t) <=
Lib.IntTypes.max_size_t } ->
b: Lib.Sequence.lseq Lib.IntTypes.uint8 len
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.Bignum.bn_from_bytes_be len b) ==
Lib.ByteSequence.nat_from_bytes_be b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.numbytes",
"Hacl.Spec.Bignum.Definitions.blocks",
"Lib.IntTypes.max_size_t",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint8",
"Hacl.Spec.Bignum.Convert.bn_from_bytes_be_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let bn_from_bytes_be_lemma #t len b =
| Hacl.Spec.Bignum.Convert.bn_from_bytes_be_lemma #t len b | false |
LowParse.SLow.Enum.fst | LowParse.SLow.Enum.parse32_maybe_enum_key | val parse32_maybe_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(p32: parser32 p)
(e: enum key repr)
(f: maybe_enum_key_of_repr'_t e)
: Tot (parser32 (parse_maybe_enum_key p e)) | val parse32_maybe_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(p32: parser32 p)
(e: enum key repr)
(f: maybe_enum_key_of_repr'_t e)
: Tot (parser32 (parse_maybe_enum_key p e)) | let parse32_maybe_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(p32: parser32 p)
(e: enum key repr)
(f: maybe_enum_key_of_repr'_t e)
: Tot (parser32 (parse_maybe_enum_key p e))
= parse32_maybe_enum_key_gen p32 e _ _ (parse_maybe_enum_key p e) () () () f | {
"file_name": "src/lowparse/LowParse.SLow.Enum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 76,
"end_line": 36,
"start_col": 0,
"start_line": 28
} | module LowParse.SLow.Enum
include LowParse.Spec.Enum
include LowParse.SLow.Combinators
module L = FStar.List.Tot
module U32 = FStar.UInt32
(* Parser for enums *)
inline_for_extraction
let parse32_maybe_enum_key_gen
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(p32: parser32 p)
(e: enum key repr)
(k' : parser_kind)
(t' : Type)
(p' : parser k' t')
(u1: unit { k' == k })
(u15: unit { t' == maybe_enum_key e } )
(u2: unit { p' == parse_maybe_enum_key p e } )
(f: maybe_enum_key_of_repr'_t e)
: Tot (parser32 p')
= parse32_synth p (maybe_enum_key_of_repr e) f p32 () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.SLow.Combinators.fst.checked",
"LowParse.Bytes32.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.Enum.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.SLow.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p32: LowParse.SLow.Base.parser32 p ->
e: LowParse.Spec.Enum.enum key repr ->
f: LowParse.Spec.Enum.maybe_enum_key_of_repr'_t e
-> LowParse.SLow.Base.parser32 (LowParse.Spec.Enum.parse_maybe_enum_key p e) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"Prims.eqtype",
"LowParse.Spec.Base.parser",
"LowParse.SLow.Base.parser32",
"LowParse.Spec.Enum.enum",
"LowParse.Spec.Enum.maybe_enum_key_of_repr'_t",
"LowParse.SLow.Enum.parse32_maybe_enum_key_gen",
"LowParse.Spec.Enum.maybe_enum_key",
"LowParse.Spec.Enum.parse_maybe_enum_key"
] | [] | false | false | false | false | false | let parse32_maybe_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(p32: parser32 p)
(e: enum key repr)
(f: maybe_enum_key_of_repr'_t e)
: Tot (parser32 (parse_maybe_enum_key p e)) =
| parse32_maybe_enum_key_gen p32 e _ _ (parse_maybe_enum_key p e) () () () f | false |
Pulse.Lib.PCM.Array.fst | Pulse.Lib.PCM.Array.index_t | val index_t (len: Ghost.erased nat) : Type0 | val index_t (len: Ghost.erased nat) : Type0 | let index_t (len: Ghost.erased nat)
: Type0
= i: nat { i < len } | {
"file_name": "share/steel/examples/pulse/lib/Pulse.Lib.PCM.Array.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 20,
"end_line": 10,
"start_col": 0,
"start_line": 8
} | module Pulse.Lib.PCM.Array
module P = Pulse.Lib.PCM.Fraction
module M = FStar.Map
module PM = Pulse.Lib.PCM.Map
module Seq = FStar.Seq
open PulseCore.FractionalPermission | {
"checked_file": "/",
"dependencies": [
"PulseCore.FractionalPermission.fst.checked",
"Pulse.Lib.PCM.Map.fst.checked",
"Pulse.Lib.PCM.Fraction.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Lib.PCM.Array.fst"
} | [
{
"abbrev": false,
"full_module": "PulseCore.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.PCM.Map",
"short_module": "PM"
},
{
"abbrev": true,
"full_module": "FStar.Map",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.PCM.Fraction",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | len: FStar.Ghost.erased Prims.nat -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Ghost.reveal"
] | [] | false | false | false | true | true | let index_t (len: Ghost.erased nat) : Type0 =
| i: nat{i < len} | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_to_bytes_be | val bn_to_bytes_be:
#t:limb_t
-> len:size_pos{numbytes t * (blocks len (numbytes t)) <= max_size_t}
-> b:lbignum t (blocks len (numbytes t)) ->
lseq uint8 len | val bn_to_bytes_be:
#t:limb_t
-> len:size_pos{numbytes t * (blocks len (numbytes t)) <= max_size_t}
-> b:lbignum t (blocks len (numbytes t)) ->
lseq uint8 len | let bn_to_bytes_be #t len b =
Hacl.Spec.Bignum.Convert.bn_to_bytes_be len b | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 269,
"start_col": 0,
"start_line": 268
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind
let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l
let bn_get_bits_lemma #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l
let bn_set_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit input ind
let bn_set_ith_bit_lemma #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma input ind
(* conditional swap *)
let cswap2 #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2 bit b1 b2
let cswap2_lemma #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2_lemma bit b1 b2
(* Bignum comparison and test functions *)
let bn_is_odd #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd b
let bn_is_odd_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd_lemma b
let bn_eq_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask a b
let bn_eq_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask_lemma a b
let bn_is_zero_mask #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask b
let bn_is_zero_mask_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask_lemma b
let bn_lt_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask a b
let bn_lt_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask_lemma a b
let bn_lt_pow2_mask #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask b x
let bn_lt_pow2_mask_lemma #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask_lemma b x
let bn_gt_pow2_mask #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask b x
let bn_gt_pow2_mask_lemma #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask_lemma b x
(* Conversion functions *)
let bn_from_uint #t len x =
Hacl.Spec.Bignum.Convert.bn_from_uint len x
let bn_from_uint_lemma #t len x =
Hacl.Spec.Bignum.Convert.bn_from_uint_lemma len x
let bn_from_bytes_be #t len b =
Hacl.Spec.Bignum.Convert.bn_from_bytes_be len b
let bn_from_bytes_be_lemma #t len b =
Hacl.Spec.Bignum.Convert.bn_from_bytes_be_lemma #t len b
let bn_from_bytes_le #t len b =
Hacl.Spec.Bignum.Convert.bn_from_bytes_le #t len b
let bn_from_bytes_le_lemma #t len b =
Hacl.Spec.Bignum.Convert.bn_from_bytes_le_lemma #t len b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
len:
Lib.IntTypes.size_pos
{ Lib.IntTypes.numbytes t *
Hacl.Spec.Bignum.Definitions.blocks len (Lib.IntTypes.numbytes t) <=
Lib.IntTypes.max_size_t } ->
b:
Hacl.Spec.Bignum.Definitions.lbignum t
(Hacl.Spec.Bignum.Definitions.blocks len (Lib.IntTypes.numbytes t))
-> Lib.Sequence.lseq Lib.IntTypes.uint8 len | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.numbytes",
"Hacl.Spec.Bignum.Definitions.blocks",
"Lib.IntTypes.max_size_t",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Convert.bn_to_bytes_be",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint8"
] | [] | false | false | false | false | false | let bn_to_bytes_be #t len b =
| Hacl.Spec.Bignum.Convert.bn_to_bytes_be len b | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_from_bytes_be | val bn_from_bytes_be:
#t:limb_t
-> len:size_pos{numbytes t * (blocks len (numbytes t)) <= max_size_t}
-> b:lseq uint8 len ->
lbignum t (blocks len (numbytes t)) | val bn_from_bytes_be:
#t:limb_t
-> len:size_pos{numbytes t * (blocks len (numbytes t)) <= max_size_t}
-> b:lseq uint8 len ->
lbignum t (blocks len (numbytes t)) | let bn_from_bytes_be #t len b =
Hacl.Spec.Bignum.Convert.bn_from_bytes_be len b | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 49,
"end_line": 257,
"start_col": 0,
"start_line": 256
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind
let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l
let bn_get_bits_lemma #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l
let bn_set_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit input ind
let bn_set_ith_bit_lemma #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma input ind
(* conditional swap *)
let cswap2 #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2 bit b1 b2
let cswap2_lemma #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2_lemma bit b1 b2
(* Bignum comparison and test functions *)
let bn_is_odd #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd b
let bn_is_odd_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd_lemma b
let bn_eq_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask a b
let bn_eq_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask_lemma a b
let bn_is_zero_mask #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask b
let bn_is_zero_mask_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask_lemma b
let bn_lt_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask a b
let bn_lt_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask_lemma a b
let bn_lt_pow2_mask #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask b x
let bn_lt_pow2_mask_lemma #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask_lemma b x
let bn_gt_pow2_mask #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask b x
let bn_gt_pow2_mask_lemma #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask_lemma b x
(* Conversion functions *)
let bn_from_uint #t len x =
Hacl.Spec.Bignum.Convert.bn_from_uint len x
let bn_from_uint_lemma #t len x =
Hacl.Spec.Bignum.Convert.bn_from_uint_lemma len x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
len:
Lib.IntTypes.size_pos
{ Lib.IntTypes.numbytes t *
Hacl.Spec.Bignum.Definitions.blocks len (Lib.IntTypes.numbytes t) <=
Lib.IntTypes.max_size_t } ->
b: Lib.Sequence.lseq Lib.IntTypes.uint8 len
-> Hacl.Spec.Bignum.Definitions.lbignum t
(Hacl.Spec.Bignum.Definitions.blocks len (Lib.IntTypes.numbytes t)) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.numbytes",
"Hacl.Spec.Bignum.Definitions.blocks",
"Lib.IntTypes.max_size_t",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint8",
"Hacl.Spec.Bignum.Convert.bn_from_bytes_be",
"Hacl.Spec.Bignum.Definitions.lbignum"
] | [] | false | false | false | false | false | let bn_from_bytes_be #t len b =
| Hacl.Spec.Bignum.Convert.bn_from_bytes_be len b | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_from_bytes_le_lemma | val bn_from_bytes_le_lemma:
#t:limb_t
-> len:size_pos{numbytes t * (blocks len (numbytes t)) <= max_size_t}
-> b:lseq uint8 len ->
Lemma (bn_v (bn_from_bytes_le #t len b) == BSeq.nat_from_bytes_le b) | val bn_from_bytes_le_lemma:
#t:limb_t
-> len:size_pos{numbytes t * (blocks len (numbytes t)) <= max_size_t}
-> b:lseq uint8 len ->
Lemma (bn_v (bn_from_bytes_le #t len b) == BSeq.nat_from_bytes_le b) | let bn_from_bytes_le_lemma #t len b =
Hacl.Spec.Bignum.Convert.bn_from_bytes_le_lemma #t len b | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 58,
"end_line": 266,
"start_col": 0,
"start_line": 265
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind
let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l
let bn_get_bits_lemma #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l
let bn_set_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit input ind
let bn_set_ith_bit_lemma #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma input ind
(* conditional swap *)
let cswap2 #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2 bit b1 b2
let cswap2_lemma #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2_lemma bit b1 b2
(* Bignum comparison and test functions *)
let bn_is_odd #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd b
let bn_is_odd_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd_lemma b
let bn_eq_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask a b
let bn_eq_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask_lemma a b
let bn_is_zero_mask #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask b
let bn_is_zero_mask_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask_lemma b
let bn_lt_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask a b
let bn_lt_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask_lemma a b
let bn_lt_pow2_mask #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask b x
let bn_lt_pow2_mask_lemma #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask_lemma b x
let bn_gt_pow2_mask #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask b x
let bn_gt_pow2_mask_lemma #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask_lemma b x
(* Conversion functions *)
let bn_from_uint #t len x =
Hacl.Spec.Bignum.Convert.bn_from_uint len x
let bn_from_uint_lemma #t len x =
Hacl.Spec.Bignum.Convert.bn_from_uint_lemma len x
let bn_from_bytes_be #t len b =
Hacl.Spec.Bignum.Convert.bn_from_bytes_be len b
let bn_from_bytes_be_lemma #t len b =
Hacl.Spec.Bignum.Convert.bn_from_bytes_be_lemma #t len b
let bn_from_bytes_le #t len b =
Hacl.Spec.Bignum.Convert.bn_from_bytes_le #t len b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
len:
Lib.IntTypes.size_pos
{ Lib.IntTypes.numbytes t *
Hacl.Spec.Bignum.Definitions.blocks len (Lib.IntTypes.numbytes t) <=
Lib.IntTypes.max_size_t } ->
b: Lib.Sequence.lseq Lib.IntTypes.uint8 len
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.Bignum.bn_from_bytes_le len b) ==
Lib.ByteSequence.nat_from_bytes_le b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.numbytes",
"Hacl.Spec.Bignum.Definitions.blocks",
"Lib.IntTypes.max_size_t",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint8",
"Hacl.Spec.Bignum.Convert.bn_from_bytes_le_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let bn_from_bytes_le_lemma #t len b =
| Hacl.Spec.Bignum.Convert.bn_from_bytes_le_lemma #t len b | false |
LowParse.SLow.Enum.fst | LowParse.SLow.Enum.parse32_enum_key | val parse32_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(p32: parser32 p)
(e: enum key repr)
(f: maybe_enum_key_of_repr'_t e)
: Tot (parser32 (parse_enum_key p e)) | val parse32_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(p32: parser32 p)
(e: enum key repr)
(f: maybe_enum_key_of_repr'_t e)
: Tot (parser32 (parse_enum_key p e)) | let parse32_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(p32: parser32 p)
(e: enum key repr)
(f: maybe_enum_key_of_repr'_t e)
: Tot (parser32 (parse_enum_key p e))
= parse32_enum_key_gen p e _ _ (parse_enum_key p e) () () () (parse32_maybe_enum_key p32 e f) | {
"file_name": "src/lowparse/LowParse.SLow.Enum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 93,
"end_line": 78,
"start_col": 0,
"start_line": 70
} | module LowParse.SLow.Enum
include LowParse.Spec.Enum
include LowParse.SLow.Combinators
module L = FStar.List.Tot
module U32 = FStar.UInt32
(* Parser for enums *)
inline_for_extraction
let parse32_maybe_enum_key_gen
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(p32: parser32 p)
(e: enum key repr)
(k' : parser_kind)
(t' : Type)
(p' : parser k' t')
(u1: unit { k' == k })
(u15: unit { t' == maybe_enum_key e } )
(u2: unit { p' == parse_maybe_enum_key p e } )
(f: maybe_enum_key_of_repr'_t e)
: Tot (parser32 p')
= parse32_synth p (maybe_enum_key_of_repr e) f p32 ()
inline_for_extraction
let parse32_maybe_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(p32: parser32 p)
(e: enum key repr)
(f: maybe_enum_key_of_repr'_t e)
: Tot (parser32 (parse_maybe_enum_key p e))
= parse32_maybe_enum_key_gen p32 e _ _ (parse_maybe_enum_key p e) () () () f
module B32 = LowParse.Bytes32
inline_for_extraction
let parse32_enum_key_gen
(#k: parser_kind)
(#key #repr: eqtype)
(p: parser k repr)
(e: enum key repr)
(k' : parser_kind)
(t' : Type)
(p' : parser k' t')
(u1: unit { k' == parse_filter_kind k } )
(u15: unit { t' == enum_key e } )
(u2: unit { p' == parse_enum_key p e } )
(pe: parser32 (parse_maybe_enum_key p e))
: Tot (parser32 p')
= (fun (input: bytes32) -> ((
[@inline_let]
let _ =
parse_enum_key_eq p e (B32.reveal input);
parse_maybe_enum_key_eq p e (B32.reveal input)
in
match pe input with
| Some (k, consumed) ->
begin match k with
| Known k' -> Some (k', consumed)
| _ -> None
end
| _ -> None
) <: (res: option (enum_key e * U32.t) { parser32_correct (parse_enum_key p e) input res } ))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.SLow.Combinators.fst.checked",
"LowParse.Bytes32.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.Enum.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Bytes32",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.SLow.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p32: LowParse.SLow.Base.parser32 p ->
e: LowParse.Spec.Enum.enum key repr ->
f: LowParse.Spec.Enum.maybe_enum_key_of_repr'_t e
-> LowParse.SLow.Base.parser32 (LowParse.Spec.Enum.parse_enum_key p e) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"Prims.eqtype",
"LowParse.Spec.Base.parser",
"LowParse.SLow.Base.parser32",
"LowParse.Spec.Enum.enum",
"LowParse.Spec.Enum.maybe_enum_key_of_repr'_t",
"LowParse.SLow.Enum.parse32_enum_key_gen",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.Enum.parse_enum_key",
"LowParse.SLow.Enum.parse32_maybe_enum_key"
] | [] | false | false | false | false | false | let parse32_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(p32: parser32 p)
(e: enum key repr)
(f: maybe_enum_key_of_repr'_t e)
: Tot (parser32 (parse_enum_key p e)) =
| parse32_enum_key_gen p e _ _ (parse_enum_key p e) () () () (parse32_maybe_enum_key p32 e f) | false |
LowParse.SLow.Enum.fst | LowParse.SLow.Enum.serialize32_enum_key | val serialize32_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: serializer32 s)
(e: enum key repr)
(f: enum_repr_of_key'_t e)
: Tot (serializer32 (serialize_enum_key p s e)) | val serialize32_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: serializer32 s)
(e: enum key repr)
(f: enum_repr_of_key'_t e)
: Tot (serializer32 (serialize_enum_key p s e)) | let serialize32_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: serializer32 s)
(e: enum key repr)
(f: enum_repr_of_key'_t e)
: Tot (serializer32 (serialize_enum_key p s e))
= serialize32_enum_key_gen s32 e _ _ _ (serialize_enum_key p s e) () () () () f | {
"file_name": "src/lowparse/LowParse.SLow.Enum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 79,
"end_line": 113,
"start_col": 0,
"start_line": 104
} | module LowParse.SLow.Enum
include LowParse.Spec.Enum
include LowParse.SLow.Combinators
module L = FStar.List.Tot
module U32 = FStar.UInt32
(* Parser for enums *)
inline_for_extraction
let parse32_maybe_enum_key_gen
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(p32: parser32 p)
(e: enum key repr)
(k' : parser_kind)
(t' : Type)
(p' : parser k' t')
(u1: unit { k' == k })
(u15: unit { t' == maybe_enum_key e } )
(u2: unit { p' == parse_maybe_enum_key p e } )
(f: maybe_enum_key_of_repr'_t e)
: Tot (parser32 p')
= parse32_synth p (maybe_enum_key_of_repr e) f p32 ()
inline_for_extraction
let parse32_maybe_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(p32: parser32 p)
(e: enum key repr)
(f: maybe_enum_key_of_repr'_t e)
: Tot (parser32 (parse_maybe_enum_key p e))
= parse32_maybe_enum_key_gen p32 e _ _ (parse_maybe_enum_key p e) () () () f
module B32 = LowParse.Bytes32
inline_for_extraction
let parse32_enum_key_gen
(#k: parser_kind)
(#key #repr: eqtype)
(p: parser k repr)
(e: enum key repr)
(k' : parser_kind)
(t' : Type)
(p' : parser k' t')
(u1: unit { k' == parse_filter_kind k } )
(u15: unit { t' == enum_key e } )
(u2: unit { p' == parse_enum_key p e } )
(pe: parser32 (parse_maybe_enum_key p e))
: Tot (parser32 p')
= (fun (input: bytes32) -> ((
[@inline_let]
let _ =
parse_enum_key_eq p e (B32.reveal input);
parse_maybe_enum_key_eq p e (B32.reveal input)
in
match pe input with
| Some (k, consumed) ->
begin match k with
| Known k' -> Some (k', consumed)
| _ -> None
end
| _ -> None
) <: (res: option (enum_key e * U32.t) { parser32_correct (parse_enum_key p e) input res } )))
inline_for_extraction
let parse32_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(p32: parser32 p)
(e: enum key repr)
(f: maybe_enum_key_of_repr'_t e)
: Tot (parser32 (parse_enum_key p e))
= parse32_enum_key_gen p e _ _ (parse_enum_key p e) () () () (parse32_maybe_enum_key p32 e f)
inline_for_extraction
let serialize32_enum_key_gen
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: serializer32 s)
(e: enum key repr)
(k' : parser_kind)
(t' : Type)
(p' : parser k' t')
(s' : serializer p')
(u1: unit { k' == parse_filter_kind k } )
(u15: unit { t' == enum_key e } )
(u2: unit { p' == parse_enum_key p e } )
(u3: unit { s' == serialize_enum_key p s e } )
(f: enum_repr_of_key'_t e)
: Tot (serializer32 s')
= fun (input: enum_key e) -> (
[@inline_let]
let _ = serialize_enum_key_eq s e input in
(s32 (f input)) <: (r: bytes32 { serializer32_correct (serialize_enum_key p s e) input r } )) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.SLow.Combinators.fst.checked",
"LowParse.Bytes32.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.Enum.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Bytes32",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.SLow.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s32: LowParse.SLow.Base.serializer32 s ->
e: LowParse.Spec.Enum.enum key repr ->
f: LowParse.Spec.Enum.enum_repr_of_key'_t e
-> LowParse.SLow.Base.serializer32 (LowParse.Spec.Enum.serialize_enum_key p s e) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"Prims.eqtype",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.SLow.Base.serializer32",
"LowParse.Spec.Enum.enum",
"LowParse.Spec.Enum.enum_repr_of_key'_t",
"LowParse.SLow.Enum.serialize32_enum_key_gen",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.Enum.parse_enum_key",
"LowParse.Spec.Enum.serialize_enum_key"
] | [] | false | false | false | false | false | let serialize32_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: serializer32 s)
(e: enum key repr)
(f: enum_repr_of_key'_t e)
: Tot (serializer32 (serialize_enum_key p s e)) =
| serialize32_enum_key_gen s32 e _ _ _ (serialize_enum_key p s e) () () () () f | false |
Pulse.Lib.PCM.Array.fst | Pulse.Lib.PCM.Array.one | val one : Pulse.Lib.PCM.Array.carrier elt len | let one (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).p.one | {
"file_name": "share/steel/examples/pulse/lib/Pulse.Lib.PCM.Array.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 67,
"end_line": 20,
"start_col": 0,
"start_line": 20
} | module Pulse.Lib.PCM.Array
module P = Pulse.Lib.PCM.Fraction
module M = FStar.Map
module PM = Pulse.Lib.PCM.Map
module Seq = FStar.Seq
open PulseCore.FractionalPermission
let index_t (len: Ghost.erased nat)
: Type0
= i: nat { i < len }
let carrier (elt: Type u#a) (len: Ghost.erased nat)
: Type u#a
= PM.map (index_t len) (P.fractional elt)
let pcm (elt: Type u#a) (len: Ghost.erased nat)
: FStar.PCM.pcm (carrier elt len)
= PM.pointwise (index_t len) (P.pcm_frac #elt) | {
"checked_file": "/",
"dependencies": [
"PulseCore.FractionalPermission.fst.checked",
"Pulse.Lib.PCM.Map.fst.checked",
"Pulse.Lib.PCM.Fraction.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Lib.PCM.Array.fst"
} | [
{
"abbrev": false,
"full_module": "PulseCore.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.PCM.Map",
"short_module": "PM"
},
{
"abbrev": true,
"full_module": "FStar.Map",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.PCM.Fraction",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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.Lib.PCM.Array.carrier elt len | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"Prims.nat",
"FStar.PCM.__proj__Mkpcm'__item__one",
"Pulse.Lib.PCM.Array.carrier",
"FStar.PCM.__proj__Mkpcm__item__p",
"Pulse.Lib.PCM.Array.pcm"
] | [] | false | false | false | false | false | let one (#elt: Type) (#len: Ghost.erased nat) =
| (pcm elt len).p.one | false |
|
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_to_bytes_le | val bn_to_bytes_le:
#t:limb_t
-> len:size_pos{numbytes t * (blocks len (numbytes t)) <= max_size_t}
-> b:lbignum t (blocks len (numbytes t)) ->
lseq uint8 len | val bn_to_bytes_le:
#t:limb_t
-> len:size_pos{numbytes t * (blocks len (numbytes t)) <= max_size_t}
-> b:lbignum t (blocks len (numbytes t)) ->
lseq uint8 len | let bn_to_bytes_le #t len b =
Hacl.Spec.Bignum.Convert.bn_to_bytes_le len b | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 275,
"start_col": 0,
"start_line": 274
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind
let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l
let bn_get_bits_lemma #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l
let bn_set_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit input ind
let bn_set_ith_bit_lemma #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma input ind
(* conditional swap *)
let cswap2 #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2 bit b1 b2
let cswap2_lemma #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2_lemma bit b1 b2
(* Bignum comparison and test functions *)
let bn_is_odd #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd b
let bn_is_odd_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd_lemma b
let bn_eq_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask a b
let bn_eq_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask_lemma a b
let bn_is_zero_mask #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask b
let bn_is_zero_mask_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask_lemma b
let bn_lt_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask a b
let bn_lt_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask_lemma a b
let bn_lt_pow2_mask #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask b x
let bn_lt_pow2_mask_lemma #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask_lemma b x
let bn_gt_pow2_mask #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask b x
let bn_gt_pow2_mask_lemma #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask_lemma b x
(* Conversion functions *)
let bn_from_uint #t len x =
Hacl.Spec.Bignum.Convert.bn_from_uint len x
let bn_from_uint_lemma #t len x =
Hacl.Spec.Bignum.Convert.bn_from_uint_lemma len x
let bn_from_bytes_be #t len b =
Hacl.Spec.Bignum.Convert.bn_from_bytes_be len b
let bn_from_bytes_be_lemma #t len b =
Hacl.Spec.Bignum.Convert.bn_from_bytes_be_lemma #t len b
let bn_from_bytes_le #t len b =
Hacl.Spec.Bignum.Convert.bn_from_bytes_le #t len b
let bn_from_bytes_le_lemma #t len b =
Hacl.Spec.Bignum.Convert.bn_from_bytes_le_lemma #t len b
let bn_to_bytes_be #t len b =
Hacl.Spec.Bignum.Convert.bn_to_bytes_be len b
let bn_to_bytes_be_lemma #t len b =
Hacl.Spec.Bignum.Convert.bn_to_bytes_be_lemma len b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
len:
Lib.IntTypes.size_pos
{ Lib.IntTypes.numbytes t *
Hacl.Spec.Bignum.Definitions.blocks len (Lib.IntTypes.numbytes t) <=
Lib.IntTypes.max_size_t } ->
b:
Hacl.Spec.Bignum.Definitions.lbignum t
(Hacl.Spec.Bignum.Definitions.blocks len (Lib.IntTypes.numbytes t))
-> Lib.Sequence.lseq Lib.IntTypes.uint8 len | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.numbytes",
"Hacl.Spec.Bignum.Definitions.blocks",
"Lib.IntTypes.max_size_t",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Convert.bn_to_bytes_le",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint8"
] | [] | false | false | false | false | false | let bn_to_bytes_le #t len b =
| Hacl.Spec.Bignum.Convert.bn_to_bytes_le len b | false |
Pulse.Lib.PCM.Array.fst | Pulse.Lib.PCM.Array.compose | val compose : x: Pulse.Lib.PCM.Array.carrier elt len ->
y:
Pulse.Lib.PCM.Array.carrier elt len
{Mkpcm'?.composable (Mkpcm?.p (Pulse.Lib.PCM.Array.pcm elt len)) x y}
-> Pulse.Lib.PCM.Array.carrier elt len | let compose (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).p.op | {
"file_name": "share/steel/examples/pulse/lib/Pulse.Lib.PCM.Array.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 70,
"end_line": 24,
"start_col": 0,
"start_line": 24
} | module Pulse.Lib.PCM.Array
module P = Pulse.Lib.PCM.Fraction
module M = FStar.Map
module PM = Pulse.Lib.PCM.Map
module Seq = FStar.Seq
open PulseCore.FractionalPermission
let index_t (len: Ghost.erased nat)
: Type0
= i: nat { i < len }
let carrier (elt: Type u#a) (len: Ghost.erased nat)
: Type u#a
= PM.map (index_t len) (P.fractional elt)
let pcm (elt: Type u#a) (len: Ghost.erased nat)
: FStar.PCM.pcm (carrier elt len)
= PM.pointwise (index_t len) (P.pcm_frac #elt)
let one (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).p.one
let composable (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).p.composable | {
"checked_file": "/",
"dependencies": [
"PulseCore.FractionalPermission.fst.checked",
"Pulse.Lib.PCM.Map.fst.checked",
"Pulse.Lib.PCM.Fraction.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Lib.PCM.Array.fst"
} | [
{
"abbrev": false,
"full_module": "PulseCore.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.PCM.Map",
"short_module": "PM"
},
{
"abbrev": true,
"full_module": "FStar.Map",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.PCM.Fraction",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: Pulse.Lib.PCM.Array.carrier elt len ->
y:
Pulse.Lib.PCM.Array.carrier elt len
{Mkpcm'?.composable (Mkpcm?.p (Pulse.Lib.PCM.Array.pcm elt len)) x y}
-> Pulse.Lib.PCM.Array.carrier elt len | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"Prims.nat",
"FStar.PCM.__proj__Mkpcm'__item__op",
"Pulse.Lib.PCM.Array.carrier",
"FStar.PCM.__proj__Mkpcm__item__p",
"Pulse.Lib.PCM.Array.pcm",
"FStar.PCM.__proj__Mkpcm'__item__composable"
] | [] | false | false | false | false | false | let compose (#elt: Type) (#len: Ghost.erased nat) =
| (pcm elt len).p.op | false |
|
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_from_bytes_le | val bn_from_bytes_le:
#t:limb_t
-> len:size_pos{numbytes t * (blocks len (numbytes t)) <= max_size_t}
-> b:lseq uint8 len ->
lbignum t (blocks len (numbytes t)) | val bn_from_bytes_le:
#t:limb_t
-> len:size_pos{numbytes t * (blocks len (numbytes t)) <= max_size_t}
-> b:lseq uint8 len ->
lbignum t (blocks len (numbytes t)) | let bn_from_bytes_le #t len b =
Hacl.Spec.Bignum.Convert.bn_from_bytes_le #t len b | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 52,
"end_line": 263,
"start_col": 0,
"start_line": 262
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind
let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l
let bn_get_bits_lemma #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l
let bn_set_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit input ind
let bn_set_ith_bit_lemma #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma input ind
(* conditional swap *)
let cswap2 #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2 bit b1 b2
let cswap2_lemma #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2_lemma bit b1 b2
(* Bignum comparison and test functions *)
let bn_is_odd #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd b
let bn_is_odd_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd_lemma b
let bn_eq_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask a b
let bn_eq_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask_lemma a b
let bn_is_zero_mask #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask b
let bn_is_zero_mask_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask_lemma b
let bn_lt_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask a b
let bn_lt_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask_lemma a b
let bn_lt_pow2_mask #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask b x
let bn_lt_pow2_mask_lemma #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask_lemma b x
let bn_gt_pow2_mask #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask b x
let bn_gt_pow2_mask_lemma #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask_lemma b x
(* Conversion functions *)
let bn_from_uint #t len x =
Hacl.Spec.Bignum.Convert.bn_from_uint len x
let bn_from_uint_lemma #t len x =
Hacl.Spec.Bignum.Convert.bn_from_uint_lemma len x
let bn_from_bytes_be #t len b =
Hacl.Spec.Bignum.Convert.bn_from_bytes_be len b
let bn_from_bytes_be_lemma #t len b =
Hacl.Spec.Bignum.Convert.bn_from_bytes_be_lemma #t len b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
len:
Lib.IntTypes.size_pos
{ Lib.IntTypes.numbytes t *
Hacl.Spec.Bignum.Definitions.blocks len (Lib.IntTypes.numbytes t) <=
Lib.IntTypes.max_size_t } ->
b: Lib.Sequence.lseq Lib.IntTypes.uint8 len
-> Hacl.Spec.Bignum.Definitions.lbignum t
(Hacl.Spec.Bignum.Definitions.blocks len (Lib.IntTypes.numbytes t)) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.numbytes",
"Hacl.Spec.Bignum.Definitions.blocks",
"Lib.IntTypes.max_size_t",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint8",
"Hacl.Spec.Bignum.Convert.bn_from_bytes_le",
"Hacl.Spec.Bignum.Definitions.lbignum"
] | [] | false | false | false | false | false | let bn_from_bytes_le #t len b =
| Hacl.Spec.Bignum.Convert.bn_from_bytes_le #t len b | false |
Pulse.Lib.PCM.Array.fst | Pulse.Lib.PCM.Array.composable | val composable : FStar.PCM.symrel (Pulse.Lib.PCM.Array.carrier elt len) | let composable (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).p.composable | {
"file_name": "share/steel/examples/pulse/lib/Pulse.Lib.PCM.Array.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 81,
"end_line": 22,
"start_col": 0,
"start_line": 22
} | module Pulse.Lib.PCM.Array
module P = Pulse.Lib.PCM.Fraction
module M = FStar.Map
module PM = Pulse.Lib.PCM.Map
module Seq = FStar.Seq
open PulseCore.FractionalPermission
let index_t (len: Ghost.erased nat)
: Type0
= i: nat { i < len }
let carrier (elt: Type u#a) (len: Ghost.erased nat)
: Type u#a
= PM.map (index_t len) (P.fractional elt)
let pcm (elt: Type u#a) (len: Ghost.erased nat)
: FStar.PCM.pcm (carrier elt len)
= PM.pointwise (index_t len) (P.pcm_frac #elt)
let one (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).p.one | {
"checked_file": "/",
"dependencies": [
"PulseCore.FractionalPermission.fst.checked",
"Pulse.Lib.PCM.Map.fst.checked",
"Pulse.Lib.PCM.Fraction.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Lib.PCM.Array.fst"
} | [
{
"abbrev": false,
"full_module": "PulseCore.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.PCM.Map",
"short_module": "PM"
},
{
"abbrev": true,
"full_module": "FStar.Map",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.PCM.Fraction",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | FStar.PCM.symrel (Pulse.Lib.PCM.Array.carrier elt len) | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"Prims.nat",
"FStar.PCM.__proj__Mkpcm'__item__composable",
"Pulse.Lib.PCM.Array.carrier",
"FStar.PCM.__proj__Mkpcm__item__p",
"Pulse.Lib.PCM.Array.pcm",
"FStar.PCM.symrel"
] | [] | false | false | false | false | false | let composable (#elt: Type) (#len: Ghost.erased nat) =
| (pcm elt len).p.composable | false |
|
LowParse.SLow.Enum.fst | LowParse.SLow.Enum.serialize32_maybe_enum_key | val serialize32_maybe_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: serializer32 s)
(e: enum key repr)
(f: enum_repr_of_key'_t e)
: Tot (serializer32 (serialize_maybe_enum_key p s e)) | val serialize32_maybe_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: serializer32 s)
(e: enum key repr)
(f: enum_repr_of_key'_t e)
: Tot (serializer32 (serialize_maybe_enum_key p s e)) | let serialize32_maybe_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: serializer32 s)
(e: enum key repr)
(f: enum_repr_of_key'_t e)
: Tot (serializer32 (serialize_maybe_enum_key p s e))
= serialize32_maybe_enum_key_gen s32 e _ _ _ (serialize_maybe_enum_key p s e) () () () () f | {
"file_name": "src/lowparse/LowParse.SLow.Enum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 91,
"end_line": 202,
"start_col": 0,
"start_line": 193
} | module LowParse.SLow.Enum
include LowParse.Spec.Enum
include LowParse.SLow.Combinators
module L = FStar.List.Tot
module U32 = FStar.UInt32
(* Parser for enums *)
inline_for_extraction
let parse32_maybe_enum_key_gen
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(p32: parser32 p)
(e: enum key repr)
(k' : parser_kind)
(t' : Type)
(p' : parser k' t')
(u1: unit { k' == k })
(u15: unit { t' == maybe_enum_key e } )
(u2: unit { p' == parse_maybe_enum_key p e } )
(f: maybe_enum_key_of_repr'_t e)
: Tot (parser32 p')
= parse32_synth p (maybe_enum_key_of_repr e) f p32 ()
inline_for_extraction
let parse32_maybe_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(p32: parser32 p)
(e: enum key repr)
(f: maybe_enum_key_of_repr'_t e)
: Tot (parser32 (parse_maybe_enum_key p e))
= parse32_maybe_enum_key_gen p32 e _ _ (parse_maybe_enum_key p e) () () () f
module B32 = LowParse.Bytes32
inline_for_extraction
let parse32_enum_key_gen
(#k: parser_kind)
(#key #repr: eqtype)
(p: parser k repr)
(e: enum key repr)
(k' : parser_kind)
(t' : Type)
(p' : parser k' t')
(u1: unit { k' == parse_filter_kind k } )
(u15: unit { t' == enum_key e } )
(u2: unit { p' == parse_enum_key p e } )
(pe: parser32 (parse_maybe_enum_key p e))
: Tot (parser32 p')
= (fun (input: bytes32) -> ((
[@inline_let]
let _ =
parse_enum_key_eq p e (B32.reveal input);
parse_maybe_enum_key_eq p e (B32.reveal input)
in
match pe input with
| Some (k, consumed) ->
begin match k with
| Known k' -> Some (k', consumed)
| _ -> None
end
| _ -> None
) <: (res: option (enum_key e * U32.t) { parser32_correct (parse_enum_key p e) input res } )))
inline_for_extraction
let parse32_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(p32: parser32 p)
(e: enum key repr)
(f: maybe_enum_key_of_repr'_t e)
: Tot (parser32 (parse_enum_key p e))
= parse32_enum_key_gen p e _ _ (parse_enum_key p e) () () () (parse32_maybe_enum_key p32 e f)
inline_for_extraction
let serialize32_enum_key_gen
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: serializer32 s)
(e: enum key repr)
(k' : parser_kind)
(t' : Type)
(p' : parser k' t')
(s' : serializer p')
(u1: unit { k' == parse_filter_kind k } )
(u15: unit { t' == enum_key e } )
(u2: unit { p' == parse_enum_key p e } )
(u3: unit { s' == serialize_enum_key p s e } )
(f: enum_repr_of_key'_t e)
: Tot (serializer32 s')
= fun (input: enum_key e) -> (
[@inline_let]
let _ = serialize_enum_key_eq s e input in
(s32 (f input)) <: (r: bytes32 { serializer32_correct (serialize_enum_key p s e) input r } ))
inline_for_extraction
let serialize32_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: serializer32 s)
(e: enum key repr)
(f: enum_repr_of_key'_t e)
: Tot (serializer32 (serialize_enum_key p s e))
= serialize32_enum_key_gen s32 e _ _ _ (serialize_enum_key p s e) () () () () f
inline_for_extraction
let size32_enum_key_gen
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: size32 s)
(e: enum key repr)
(k' : parser_kind)
(t' : Type)
(p' : parser k' t')
(s' : serializer p')
(u1: unit { k' == parse_filter_kind k } )
(u15: unit { t' == enum_key e } )
(u2: unit { p' == parse_enum_key p e } )
(u3: unit { s' == serialize_enum_key p s e } )
(f: enum_repr_of_key'_t e)
: Tot (size32 s')
= fun (input: enum_key e) -> (
[@inline_let]
let _ = serialize_enum_key_eq s e input in
(s32 (f input)) <: (r: UInt32.t { size32_postcond (serialize_enum_key p s e) input r } ))
inline_for_extraction
let size32_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: size32 s)
(e: enum key repr)
(f: enum_repr_of_key'_t e)
: Tot (size32 (serialize_enum_key p s e))
= size32_enum_key_gen s32 e _ _ _ (serialize_enum_key p s e) () () () () f
inline_for_extraction
let serialize32_maybe_enum_key_gen'
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: serializer32 s)
(e: enum key repr)
(f: serializer32 (serialize_enum_key p s e))
: Tot (serializer32 (serialize_maybe_enum_key p s e))
= fun (input: maybe_enum_key e) -> ((
[@inline_let]
let _ = serialize_maybe_enum_key_eq s e input in
match input with
| Known k ->
[@inline_let]
let _ = serialize_enum_key_eq s e k in
f k
| Unknown r -> s32 r
) <: (r: bytes32 { serializer32_correct (serialize_maybe_enum_key p s e) input r } ))
inline_for_extraction
let serialize32_maybe_enum_key_gen
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: serializer32 s)
(e: enum key repr)
(k' : parser_kind)
(t' : Type)
(p' : parser k' t')
(s' : serializer p')
(u1: unit { k == k' } )
(u15: unit { t' == maybe_enum_key e } )
(u2: unit { p' == parse_maybe_enum_key p e } )
(u3: unit { s' == serialize_maybe_enum_key p s e } )
(f: enum_repr_of_key'_t e)
: Tot (serializer32 s')
= serialize32_maybe_enum_key_gen' s32 e
(serialize32_enum_key_gen s32 e _ _ _ (serialize_enum_key _ s e) () () () () f) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.SLow.Combinators.fst.checked",
"LowParse.Bytes32.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.Enum.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Bytes32",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.SLow.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s32: LowParse.SLow.Base.serializer32 s ->
e: LowParse.Spec.Enum.enum key repr ->
f: LowParse.Spec.Enum.enum_repr_of_key'_t e
-> LowParse.SLow.Base.serializer32 (LowParse.Spec.Enum.serialize_maybe_enum_key p s e) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"Prims.eqtype",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.SLow.Base.serializer32",
"LowParse.Spec.Enum.enum",
"LowParse.Spec.Enum.enum_repr_of_key'_t",
"LowParse.SLow.Enum.serialize32_maybe_enum_key_gen",
"LowParse.Spec.Enum.maybe_enum_key",
"LowParse.Spec.Enum.parse_maybe_enum_key",
"LowParse.Spec.Enum.serialize_maybe_enum_key"
] | [] | false | false | false | false | false | let serialize32_maybe_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: serializer32 s)
(e: enum key repr)
(f: enum_repr_of_key'_t e)
: Tot (serializer32 (serialize_maybe_enum_key p s e)) =
| serialize32_maybe_enum_key_gen s32 e _ _ _ (serialize_maybe_enum_key p s e) () () () () f | false |
LowParse.SLow.Enum.fst | LowParse.SLow.Enum.size32_enum_key | val size32_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: size32 s)
(e: enum key repr)
(f: enum_repr_of_key'_t e)
: Tot (size32 (serialize_enum_key p s e)) | val size32_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: size32 s)
(e: enum key repr)
(f: enum_repr_of_key'_t e)
: Tot (size32 (serialize_enum_key p s e)) | let size32_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: size32 s)
(e: enum key repr)
(f: enum_repr_of_key'_t e)
: Tot (size32 (serialize_enum_key p s e))
= size32_enum_key_gen s32 e _ _ _ (serialize_enum_key p s e) () () () () f | {
"file_name": "src/lowparse/LowParse.SLow.Enum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 74,
"end_line": 148,
"start_col": 0,
"start_line": 139
} | module LowParse.SLow.Enum
include LowParse.Spec.Enum
include LowParse.SLow.Combinators
module L = FStar.List.Tot
module U32 = FStar.UInt32
(* Parser for enums *)
inline_for_extraction
let parse32_maybe_enum_key_gen
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(p32: parser32 p)
(e: enum key repr)
(k' : parser_kind)
(t' : Type)
(p' : parser k' t')
(u1: unit { k' == k })
(u15: unit { t' == maybe_enum_key e } )
(u2: unit { p' == parse_maybe_enum_key p e } )
(f: maybe_enum_key_of_repr'_t e)
: Tot (parser32 p')
= parse32_synth p (maybe_enum_key_of_repr e) f p32 ()
inline_for_extraction
let parse32_maybe_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(p32: parser32 p)
(e: enum key repr)
(f: maybe_enum_key_of_repr'_t e)
: Tot (parser32 (parse_maybe_enum_key p e))
= parse32_maybe_enum_key_gen p32 e _ _ (parse_maybe_enum_key p e) () () () f
module B32 = LowParse.Bytes32
inline_for_extraction
let parse32_enum_key_gen
(#k: parser_kind)
(#key #repr: eqtype)
(p: parser k repr)
(e: enum key repr)
(k' : parser_kind)
(t' : Type)
(p' : parser k' t')
(u1: unit { k' == parse_filter_kind k } )
(u15: unit { t' == enum_key e } )
(u2: unit { p' == parse_enum_key p e } )
(pe: parser32 (parse_maybe_enum_key p e))
: Tot (parser32 p')
= (fun (input: bytes32) -> ((
[@inline_let]
let _ =
parse_enum_key_eq p e (B32.reveal input);
parse_maybe_enum_key_eq p e (B32.reveal input)
in
match pe input with
| Some (k, consumed) ->
begin match k with
| Known k' -> Some (k', consumed)
| _ -> None
end
| _ -> None
) <: (res: option (enum_key e * U32.t) { parser32_correct (parse_enum_key p e) input res } )))
inline_for_extraction
let parse32_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(p32: parser32 p)
(e: enum key repr)
(f: maybe_enum_key_of_repr'_t e)
: Tot (parser32 (parse_enum_key p e))
= parse32_enum_key_gen p e _ _ (parse_enum_key p e) () () () (parse32_maybe_enum_key p32 e f)
inline_for_extraction
let serialize32_enum_key_gen
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: serializer32 s)
(e: enum key repr)
(k' : parser_kind)
(t' : Type)
(p' : parser k' t')
(s' : serializer p')
(u1: unit { k' == parse_filter_kind k } )
(u15: unit { t' == enum_key e } )
(u2: unit { p' == parse_enum_key p e } )
(u3: unit { s' == serialize_enum_key p s e } )
(f: enum_repr_of_key'_t e)
: Tot (serializer32 s')
= fun (input: enum_key e) -> (
[@inline_let]
let _ = serialize_enum_key_eq s e input in
(s32 (f input)) <: (r: bytes32 { serializer32_correct (serialize_enum_key p s e) input r } ))
inline_for_extraction
let serialize32_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: serializer32 s)
(e: enum key repr)
(f: enum_repr_of_key'_t e)
: Tot (serializer32 (serialize_enum_key p s e))
= serialize32_enum_key_gen s32 e _ _ _ (serialize_enum_key p s e) () () () () f
inline_for_extraction
let size32_enum_key_gen
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: size32 s)
(e: enum key repr)
(k' : parser_kind)
(t' : Type)
(p' : parser k' t')
(s' : serializer p')
(u1: unit { k' == parse_filter_kind k } )
(u15: unit { t' == enum_key e } )
(u2: unit { p' == parse_enum_key p e } )
(u3: unit { s' == serialize_enum_key p s e } )
(f: enum_repr_of_key'_t e)
: Tot (size32 s')
= fun (input: enum_key e) -> (
[@inline_let]
let _ = serialize_enum_key_eq s e input in
(s32 (f input)) <: (r: UInt32.t { size32_postcond (serialize_enum_key p s e) input r } )) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.SLow.Combinators.fst.checked",
"LowParse.Bytes32.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.Enum.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Bytes32",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.SLow.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s32: LowParse.SLow.Base.size32 s ->
e: LowParse.Spec.Enum.enum key repr ->
f: LowParse.Spec.Enum.enum_repr_of_key'_t e
-> LowParse.SLow.Base.size32 (LowParse.Spec.Enum.serialize_enum_key p s e) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"Prims.eqtype",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.SLow.Base.size32",
"LowParse.Spec.Enum.enum",
"LowParse.Spec.Enum.enum_repr_of_key'_t",
"LowParse.SLow.Enum.size32_enum_key_gen",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.Enum.enum_key",
"LowParse.Spec.Enum.parse_enum_key",
"LowParse.Spec.Enum.serialize_enum_key"
] | [] | false | false | false | false | false | let size32_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: size32 s)
(e: enum key repr)
(f: enum_repr_of_key'_t e)
: Tot (size32 (serialize_enum_key p s e)) =
| size32_enum_key_gen s32 e _ _ _ (serialize_enum_key p s e) () () () () f | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_to_bytes_le_lemma | val bn_to_bytes_le_lemma:
#t:limb_t
-> len:size_pos{numbytes t * (blocks len (numbytes t)) <= max_size_t}
-> b:lbignum t (blocks len (numbytes t)){bn_v b < pow2 (8 * len)} ->
Lemma (bn_to_bytes_le len b == BSeq.nat_to_intseq_le #U8 len (bn_v b)) | val bn_to_bytes_le_lemma:
#t:limb_t
-> len:size_pos{numbytes t * (blocks len (numbytes t)) <= max_size_t}
-> b:lbignum t (blocks len (numbytes t)){bn_v b < pow2 (8 * len)} ->
Lemma (bn_to_bytes_le len b == BSeq.nat_to_intseq_le #U8 len (bn_v b)) | let bn_to_bytes_le_lemma #t len b =
Hacl.Spec.Bignum.Convert.bn_to_bytes_le_lemma len b | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 53,
"end_line": 278,
"start_col": 0,
"start_line": 277
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind
let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l
let bn_get_bits_lemma #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l
let bn_set_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit input ind
let bn_set_ith_bit_lemma #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma input ind
(* conditional swap *)
let cswap2 #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2 bit b1 b2
let cswap2_lemma #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2_lemma bit b1 b2
(* Bignum comparison and test functions *)
let bn_is_odd #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd b
let bn_is_odd_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd_lemma b
let bn_eq_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask a b
let bn_eq_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask_lemma a b
let bn_is_zero_mask #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask b
let bn_is_zero_mask_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask_lemma b
let bn_lt_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask a b
let bn_lt_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask_lemma a b
let bn_lt_pow2_mask #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask b x
let bn_lt_pow2_mask_lemma #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask_lemma b x
let bn_gt_pow2_mask #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask b x
let bn_gt_pow2_mask_lemma #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask_lemma b x
(* Conversion functions *)
let bn_from_uint #t len x =
Hacl.Spec.Bignum.Convert.bn_from_uint len x
let bn_from_uint_lemma #t len x =
Hacl.Spec.Bignum.Convert.bn_from_uint_lemma len x
let bn_from_bytes_be #t len b =
Hacl.Spec.Bignum.Convert.bn_from_bytes_be len b
let bn_from_bytes_be_lemma #t len b =
Hacl.Spec.Bignum.Convert.bn_from_bytes_be_lemma #t len b
let bn_from_bytes_le #t len b =
Hacl.Spec.Bignum.Convert.bn_from_bytes_le #t len b
let bn_from_bytes_le_lemma #t len b =
Hacl.Spec.Bignum.Convert.bn_from_bytes_le_lemma #t len b
let bn_to_bytes_be #t len b =
Hacl.Spec.Bignum.Convert.bn_to_bytes_be len b
let bn_to_bytes_be_lemma #t len b =
Hacl.Spec.Bignum.Convert.bn_to_bytes_be_lemma len b
let bn_to_bytes_le #t len b =
Hacl.Spec.Bignum.Convert.bn_to_bytes_le len b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
len:
Lib.IntTypes.size_pos
{ Lib.IntTypes.numbytes t *
Hacl.Spec.Bignum.Definitions.blocks len (Lib.IntTypes.numbytes t) <=
Lib.IntTypes.max_size_t } ->
b:
Hacl.Spec.Bignum.Definitions.lbignum t
(Hacl.Spec.Bignum.Definitions.blocks len (Lib.IntTypes.numbytes t))
{Hacl.Spec.Bignum.Definitions.bn_v b < Prims.pow2 (8 * len)}
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Bignum.bn_to_bytes_le len b ==
Lib.ByteSequence.nat_to_intseq_le len (Hacl.Spec.Bignum.Definitions.bn_v b)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.numbytes",
"Hacl.Spec.Bignum.Definitions.blocks",
"Lib.IntTypes.max_size_t",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.op_LessThan",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Prims.pow2",
"Hacl.Spec.Bignum.Convert.bn_to_bytes_le_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let bn_to_bytes_le_lemma #t len b =
| Hacl.Spec.Bignum.Convert.bn_to_bytes_le_lemma len b | false |
Pulse.Lib.PCM.Array.fst | Pulse.Lib.PCM.Array.carrier | val carrier (elt: Type u#a) (len: Ghost.erased nat) : Type u#a | val carrier (elt: Type u#a) (len: Ghost.erased nat) : Type u#a | let carrier (elt: Type u#a) (len: Ghost.erased nat)
: Type u#a
= PM.map (index_t len) (P.fractional elt) | {
"file_name": "share/steel/examples/pulse/lib/Pulse.Lib.PCM.Array.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 41,
"end_line": 14,
"start_col": 0,
"start_line": 12
} | module Pulse.Lib.PCM.Array
module P = Pulse.Lib.PCM.Fraction
module M = FStar.Map
module PM = Pulse.Lib.PCM.Map
module Seq = FStar.Seq
open PulseCore.FractionalPermission
let index_t (len: Ghost.erased nat)
: Type0
= i: nat { i < len } | {
"checked_file": "/",
"dependencies": [
"PulseCore.FractionalPermission.fst.checked",
"Pulse.Lib.PCM.Map.fst.checked",
"Pulse.Lib.PCM.Fraction.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Lib.PCM.Array.fst"
} | [
{
"abbrev": false,
"full_module": "PulseCore.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.PCM.Map",
"short_module": "PM"
},
{
"abbrev": true,
"full_module": "FStar.Map",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.PCM.Fraction",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | elt: Type -> len: FStar.Ghost.erased Prims.nat -> Type | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"Prims.nat",
"Pulse.Lib.PCM.Map.map",
"Pulse.Lib.PCM.Array.index_t",
"Pulse.Lib.PCM.Fraction.fractional"
] | [] | false | false | false | true | true | let carrier (elt: Type u#a) (len: Ghost.erased nat) : Type u#a =
| PM.map (index_t len) (P.fractional elt) | false |
Pulse.Lib.PCM.Array.fst | Pulse.Lib.PCM.Array.pcm | val pcm (elt: Type u#a) (len: Ghost.erased nat) : FStar.PCM.pcm (carrier elt len) | val pcm (elt: Type u#a) (len: Ghost.erased nat) : FStar.PCM.pcm (carrier elt len) | let pcm (elt: Type u#a) (len: Ghost.erased nat)
: FStar.PCM.pcm (carrier elt len)
= PM.pointwise (index_t len) (P.pcm_frac #elt) | {
"file_name": "share/steel/examples/pulse/lib/Pulse.Lib.PCM.Array.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 46,
"end_line": 18,
"start_col": 0,
"start_line": 16
} | module Pulse.Lib.PCM.Array
module P = Pulse.Lib.PCM.Fraction
module M = FStar.Map
module PM = Pulse.Lib.PCM.Map
module Seq = FStar.Seq
open PulseCore.FractionalPermission
let index_t (len: Ghost.erased nat)
: Type0
= i: nat { i < len }
let carrier (elt: Type u#a) (len: Ghost.erased nat)
: Type u#a
= PM.map (index_t len) (P.fractional elt) | {
"checked_file": "/",
"dependencies": [
"PulseCore.FractionalPermission.fst.checked",
"Pulse.Lib.PCM.Map.fst.checked",
"Pulse.Lib.PCM.Fraction.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Lib.PCM.Array.fst"
} | [
{
"abbrev": false,
"full_module": "PulseCore.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.PCM.Map",
"short_module": "PM"
},
{
"abbrev": true,
"full_module": "FStar.Map",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.PCM.Fraction",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | elt: Type -> len: FStar.Ghost.erased Prims.nat
-> FStar.PCM.pcm (Pulse.Lib.PCM.Array.carrier elt len) | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"Prims.nat",
"Pulse.Lib.PCM.Map.pointwise",
"Pulse.Lib.PCM.Fraction.fractional",
"Pulse.Lib.PCM.Array.index_t",
"Pulse.Lib.PCM.Fraction.pcm_frac",
"FStar.PCM.pcm",
"Pulse.Lib.PCM.Array.carrier"
] | [] | false | false | false | false | false | let pcm (elt: Type u#a) (len: Ghost.erased nat) : FStar.PCM.pcm (carrier elt len) =
| PM.pointwise (index_t len) (P.pcm_frac #elt) | false |
LowParse.SLow.Enum.fst | LowParse.SLow.Enum.size32_maybe_enum_key | val size32_maybe_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: size32 s)
(e: enum key repr)
(f: enum_repr_of_key'_t e)
: Tot (size32 (serialize_maybe_enum_key p s e)) | val size32_maybe_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: size32 s)
(e: enum key repr)
(f: enum_repr_of_key'_t e)
: Tot (size32 (serialize_maybe_enum_key p s e)) | let size32_maybe_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: size32 s)
(e: enum key repr)
(f: enum_repr_of_key'_t e)
: Tot (size32 (serialize_maybe_enum_key p s e))
= size32_maybe_enum_key_gen s32 e _ _ _ (serialize_maybe_enum_key p s e) () () () () f | {
"file_name": "src/lowparse/LowParse.SLow.Enum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 87,
"end_line": 256,
"start_col": 0,
"start_line": 247
} | module LowParse.SLow.Enum
include LowParse.Spec.Enum
include LowParse.SLow.Combinators
module L = FStar.List.Tot
module U32 = FStar.UInt32
(* Parser for enums *)
inline_for_extraction
let parse32_maybe_enum_key_gen
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(p32: parser32 p)
(e: enum key repr)
(k' : parser_kind)
(t' : Type)
(p' : parser k' t')
(u1: unit { k' == k })
(u15: unit { t' == maybe_enum_key e } )
(u2: unit { p' == parse_maybe_enum_key p e } )
(f: maybe_enum_key_of_repr'_t e)
: Tot (parser32 p')
= parse32_synth p (maybe_enum_key_of_repr e) f p32 ()
inline_for_extraction
let parse32_maybe_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(p32: parser32 p)
(e: enum key repr)
(f: maybe_enum_key_of_repr'_t e)
: Tot (parser32 (parse_maybe_enum_key p e))
= parse32_maybe_enum_key_gen p32 e _ _ (parse_maybe_enum_key p e) () () () f
module B32 = LowParse.Bytes32
inline_for_extraction
let parse32_enum_key_gen
(#k: parser_kind)
(#key #repr: eqtype)
(p: parser k repr)
(e: enum key repr)
(k' : parser_kind)
(t' : Type)
(p' : parser k' t')
(u1: unit { k' == parse_filter_kind k } )
(u15: unit { t' == enum_key e } )
(u2: unit { p' == parse_enum_key p e } )
(pe: parser32 (parse_maybe_enum_key p e))
: Tot (parser32 p')
= (fun (input: bytes32) -> ((
[@inline_let]
let _ =
parse_enum_key_eq p e (B32.reveal input);
parse_maybe_enum_key_eq p e (B32.reveal input)
in
match pe input with
| Some (k, consumed) ->
begin match k with
| Known k' -> Some (k', consumed)
| _ -> None
end
| _ -> None
) <: (res: option (enum_key e * U32.t) { parser32_correct (parse_enum_key p e) input res } )))
inline_for_extraction
let parse32_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(p32: parser32 p)
(e: enum key repr)
(f: maybe_enum_key_of_repr'_t e)
: Tot (parser32 (parse_enum_key p e))
= parse32_enum_key_gen p e _ _ (parse_enum_key p e) () () () (parse32_maybe_enum_key p32 e f)
inline_for_extraction
let serialize32_enum_key_gen
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: serializer32 s)
(e: enum key repr)
(k' : parser_kind)
(t' : Type)
(p' : parser k' t')
(s' : serializer p')
(u1: unit { k' == parse_filter_kind k } )
(u15: unit { t' == enum_key e } )
(u2: unit { p' == parse_enum_key p e } )
(u3: unit { s' == serialize_enum_key p s e } )
(f: enum_repr_of_key'_t e)
: Tot (serializer32 s')
= fun (input: enum_key e) -> (
[@inline_let]
let _ = serialize_enum_key_eq s e input in
(s32 (f input)) <: (r: bytes32 { serializer32_correct (serialize_enum_key p s e) input r } ))
inline_for_extraction
let serialize32_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: serializer32 s)
(e: enum key repr)
(f: enum_repr_of_key'_t e)
: Tot (serializer32 (serialize_enum_key p s e))
= serialize32_enum_key_gen s32 e _ _ _ (serialize_enum_key p s e) () () () () f
inline_for_extraction
let size32_enum_key_gen
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: size32 s)
(e: enum key repr)
(k' : parser_kind)
(t' : Type)
(p' : parser k' t')
(s' : serializer p')
(u1: unit { k' == parse_filter_kind k } )
(u15: unit { t' == enum_key e } )
(u2: unit { p' == parse_enum_key p e } )
(u3: unit { s' == serialize_enum_key p s e } )
(f: enum_repr_of_key'_t e)
: Tot (size32 s')
= fun (input: enum_key e) -> (
[@inline_let]
let _ = serialize_enum_key_eq s e input in
(s32 (f input)) <: (r: UInt32.t { size32_postcond (serialize_enum_key p s e) input r } ))
inline_for_extraction
let size32_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: size32 s)
(e: enum key repr)
(f: enum_repr_of_key'_t e)
: Tot (size32 (serialize_enum_key p s e))
= size32_enum_key_gen s32 e _ _ _ (serialize_enum_key p s e) () () () () f
inline_for_extraction
let serialize32_maybe_enum_key_gen'
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: serializer32 s)
(e: enum key repr)
(f: serializer32 (serialize_enum_key p s e))
: Tot (serializer32 (serialize_maybe_enum_key p s e))
= fun (input: maybe_enum_key e) -> ((
[@inline_let]
let _ = serialize_maybe_enum_key_eq s e input in
match input with
| Known k ->
[@inline_let]
let _ = serialize_enum_key_eq s e k in
f k
| Unknown r -> s32 r
) <: (r: bytes32 { serializer32_correct (serialize_maybe_enum_key p s e) input r } ))
inline_for_extraction
let serialize32_maybe_enum_key_gen
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: serializer32 s)
(e: enum key repr)
(k' : parser_kind)
(t' : Type)
(p' : parser k' t')
(s' : serializer p')
(u1: unit { k == k' } )
(u15: unit { t' == maybe_enum_key e } )
(u2: unit { p' == parse_maybe_enum_key p e } )
(u3: unit { s' == serialize_maybe_enum_key p s e } )
(f: enum_repr_of_key'_t e)
: Tot (serializer32 s')
= serialize32_maybe_enum_key_gen' s32 e
(serialize32_enum_key_gen s32 e _ _ _ (serialize_enum_key _ s e) () () () () f)
inline_for_extraction
let serialize32_maybe_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: serializer32 s)
(e: enum key repr)
(f: enum_repr_of_key'_t e)
: Tot (serializer32 (serialize_maybe_enum_key p s e))
= serialize32_maybe_enum_key_gen s32 e _ _ _ (serialize_maybe_enum_key p s e) () () () () f
inline_for_extraction
let size32_maybe_enum_key_gen'
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: size32 s)
(e: enum key repr)
(f: size32 (serialize_enum_key p s e))
: Tot (size32 (serialize_maybe_enum_key p s e))
= fun (input: maybe_enum_key e) -> ((
[@inline_let]
let _ = serialize_maybe_enum_key_eq s e input in
match input with
| Known k ->
[@inline_let]
let _ = serialize_enum_key_eq s e k in
f k
| Unknown r -> s32 r
) <: (r: U32.t { size32_postcond (serialize_maybe_enum_key p s e) input r } ))
inline_for_extraction
let size32_maybe_enum_key_gen
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: size32 s)
(e: enum key repr)
(k' : parser_kind)
(t' : Type)
(p' : parser k' t')
(s' : serializer p')
(u1: unit { k == k' } )
(u15: unit { t' == maybe_enum_key e } )
(u2: unit { p' == parse_maybe_enum_key p e } )
(u3: unit { s' == serialize_maybe_enum_key p s e } )
(f: enum_repr_of_key'_t e)
: Tot (size32 s')
= size32_maybe_enum_key_gen' s32 e
(size32_enum_key_gen s32 e _ _ _ (serialize_enum_key _ s e) () () () () f) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.SLow.Combinators.fst.checked",
"LowParse.Bytes32.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.Enum.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Bytes32",
"short_module": "B32"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.SLow.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s32: LowParse.SLow.Base.size32 s ->
e: LowParse.Spec.Enum.enum key repr ->
f: LowParse.Spec.Enum.enum_repr_of_key'_t e
-> LowParse.SLow.Base.size32 (LowParse.Spec.Enum.serialize_maybe_enum_key p s e) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"Prims.eqtype",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.SLow.Base.size32",
"LowParse.Spec.Enum.enum",
"LowParse.Spec.Enum.enum_repr_of_key'_t",
"LowParse.SLow.Enum.size32_maybe_enum_key_gen",
"LowParse.Spec.Enum.maybe_enum_key",
"LowParse.Spec.Enum.parse_maybe_enum_key",
"LowParse.Spec.Enum.serialize_maybe_enum_key"
] | [] | false | false | false | false | false | let size32_maybe_enum_key
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(#s: serializer p)
(s32: size32 s)
(e: enum key repr)
(f: enum_repr_of_key'_t e)
: Tot (size32 (serialize_maybe_enum_key p s e)) =
| size32_maybe_enum_key_gen s32 e _ _ _ (serialize_maybe_enum_key p s e) () () () () f | false |
Hacl.Spec.Bignum.fst | Hacl.Spec.Bignum.bn_to_bytes_be_lemma | val bn_to_bytes_be_lemma:
#t:limb_t
-> len:size_pos{numbytes t * (blocks len (numbytes t)) <= max_size_t}
-> b:lbignum t (blocks len (numbytes t)){bn_v b < pow2 (8 * len)} ->
Lemma (bn_to_bytes_be #t len b == BSeq.nat_to_intseq_be #U8 len (bn_v b)) | val bn_to_bytes_be_lemma:
#t:limb_t
-> len:size_pos{numbytes t * (blocks len (numbytes t)) <= max_size_t}
-> b:lbignum t (blocks len (numbytes t)){bn_v b < pow2 (8 * len)} ->
Lemma (bn_to_bytes_be #t len b == BSeq.nat_to_intseq_be #U8 len (bn_v b)) | let bn_to_bytes_be_lemma #t len b =
Hacl.Spec.Bignum.Convert.bn_to_bytes_be_lemma len b | {
"file_name": "code/bignum/Hacl.Spec.Bignum.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 53,
"end_line": 272,
"start_col": 0,
"start_line": 271
} | module Hacl.Spec.Bignum
module Loops = Lib.LoopCombinators
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_add1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1 a b1
let bn_add1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1
let bn_sub1 #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1 a b1
let bn_sub1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1
let bn_add #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add a b
let bn_add_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_add_lemma a b
let bn_sub #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub a b
let bn_sub_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Addition.bn_sub_lemma a b
let bn_reduce_once #t #len n c0 a =
let c1, res = bn_sub a n in
let c = c0 -. c1 in
map2 (mask_select c) a res
let bn_reduce_once_lemma #t #len n c0 res0 =
let pbits = bits t in
let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in
let c1, res1 = bn_sub res0 n in
bn_sub_lemma res0 n;
assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n);
let c = c0 -. c1 in
assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n);
let res = map2 (mask_select c) res0 res1 in
if tmp < bn_v n then begin
assert (v c0 == 0);
assert (v c1 == 1);
assert (v c == pow2 pbits - 1);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res0);
Math.Lemmas.small_mod tmp (bn_v n);
assert (bn_v res == tmp % bn_v n) end
else begin
assert (tmp - bn_v n < bn_v n);
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c == 0);
lseq_mask_select_lemma res0 res1 c;
assert (bn_v res == bn_v res1);
Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1);
assert (bn_v res % bn_v n == tmp % bn_v n);
Math.Lemmas.small_mod (bn_v res) (bn_v n) end
let bn_add_mod_n #t #len n a b =
let c0, res0 = bn_add a b in
bn_reduce_once n c0 res0
let bn_add_mod_n_lemma #t #len n a b =
let c0, res0 = bn_add a b in
bn_add_lemma a b;
bn_reduce_once_lemma n c0 res0
let bn_sub_mod_n #t #len n a b =
let c0, res0 = bn_sub a b in
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
map2 (mask_select c) res1 res0
let bn_sub_mod_n_lemma #t #len n a b =
let c0, res0 = bn_sub a b in
bn_sub_lemma a b;
assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b);
let c1, res1 = bn_add res0 n in
let c = uint #t 0 -. c0 in
assert (v c == 0 \/ v c == v (ones t SEC));
let res = map2 (mask_select c) res1 res0 in
lseq_mask_select_lemma res1 res0 c;
if v c0 = 0 then begin
assert (bn_v res0 == bn_v a - bn_v b);
Math.Lemmas.small_mod (bn_v res0) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
else begin
bn_add_lemma res0 n;
assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n);
bn_eval_bound res0 len;
bn_eval_bound res1 len;
bn_eval_bound n len;
assert (v c0 - v c1 = 0);
assert (bn_v res1 == bn_v a - bn_v b + bn_v n);
assert (bn_v res1 < bn_v n);
Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1;
Math.Lemmas.small_mod (bn_v res1) (bn_v n);
assert (bn_v res == (bn_v a - bn_v b) % bn_v n);
() end
let bn_mul1 #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1
let bn_mul1_lemma #t #aLen a b1 =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1
let bn_mul #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul a b
let bn_mul_lemma #t #aLen #bLen a b =
Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b
let bn_karatsuba_mul #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b
let bn_karatsuba_mul_lemma #t #aLen a b =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b
let bn_sqr #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr a
let bn_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a
let bn_karatsuba_sqr #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a
let bn_karatsuba_sqr_lemma #t #aLen a =
Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a
let bn_mul1_lshift_add #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc
let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc =
Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc
let bn_rshift #t #len b i =
Hacl.Spec.Bignum.Lib.bn_div_pow2 b i
let bn_rshift_lemma #t #len c i =
Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i
let bn_sub_mask #t #len n a =
let mask = BSeq.seq_eq_mask n a len in
let mod_mask = map (logand mask) n in
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
res
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in
assert (n == a ==> v mask == v (ones t SEC));
assert (n =!= a ==> v mask == v (zeros t SEC));
let mod_mask = map (logand mask) n in
bn_mask_lemma n mask;
assert (n == a ==> bn_v mod_mask == bn_v n);
assert (n =!= a ==> bn_v mod_mask == 0);
let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in
Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask;
assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask);
bn_eval_bound res len;
assert (bn_v res == bn_v a - bn_v mod_mask);
Classical.move_requires_2 (bn_eval_inj len) n a
(* get and set i-th bit of a bignum *)
let bn_get_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit input ind
let bn_get_ith_bit_lemma #t #len b ind =
Hacl.Spec.Bignum.Lib.bn_get_ith_bit_lemma b ind
let bn_get_bits #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits #t #nLen n i l
let bn_get_bits_lemma #t #nLen n i l =
Hacl.Spec.Bignum.Lib.bn_get_bits_lemma #t #nLen n i l
let bn_set_ith_bit #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit input ind
let bn_set_ith_bit_lemma #t #len input ind =
Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma input ind
(* conditional swap *)
let cswap2 #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2 bit b1 b2
let cswap2_lemma #t #len bit b1 b2 =
Hacl.Spec.Bignum.Lib.cswap2_lemma bit b1 b2
(* Bignum comparison and test functions *)
let bn_is_odd #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd b
let bn_is_odd_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_odd_lemma b
let bn_eq_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask a b
let bn_eq_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_eq_mask_lemma a b
let bn_is_zero_mask #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask b
let bn_is_zero_mask_lemma #t #len b =
Hacl.Spec.Bignum.Comparison.bn_is_zero_mask_lemma b
let bn_lt_mask #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask a b
let bn_lt_mask_lemma #t #len a b =
Hacl.Spec.Bignum.Comparison.bn_lt_mask_lemma a b
let bn_lt_pow2_mask #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask b x
let bn_lt_pow2_mask_lemma #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_lt_pow2_mask_lemma b x
let bn_gt_pow2_mask #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask b x
let bn_gt_pow2_mask_lemma #t #len b x =
Hacl.Spec.Bignum.Comparison.bn_gt_pow2_mask_lemma b x
(* Conversion functions *)
let bn_from_uint #t len x =
Hacl.Spec.Bignum.Convert.bn_from_uint len x
let bn_from_uint_lemma #t len x =
Hacl.Spec.Bignum.Convert.bn_from_uint_lemma len x
let bn_from_bytes_be #t len b =
Hacl.Spec.Bignum.Convert.bn_from_bytes_be len b
let bn_from_bytes_be_lemma #t len b =
Hacl.Spec.Bignum.Convert.bn_from_bytes_be_lemma #t len b
let bn_from_bytes_le #t len b =
Hacl.Spec.Bignum.Convert.bn_from_bytes_le #t len b
let bn_from_bytes_le_lemma #t len b =
Hacl.Spec.Bignum.Convert.bn_from_bytes_le_lemma #t len b
let bn_to_bytes_be #t len b =
Hacl.Spec.Bignum.Convert.bn_to_bytes_be len b | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Squaring.fst.checked",
"Hacl.Spec.Bignum.Multiplication.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Spec.Bignum.Comparison.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
len:
Lib.IntTypes.size_pos
{ Lib.IntTypes.numbytes t *
Hacl.Spec.Bignum.Definitions.blocks len (Lib.IntTypes.numbytes t) <=
Lib.IntTypes.max_size_t } ->
b:
Hacl.Spec.Bignum.Definitions.lbignum t
(Hacl.Spec.Bignum.Definitions.blocks len (Lib.IntTypes.numbytes t))
{Hacl.Spec.Bignum.Definitions.bn_v b < Prims.pow2 (8 * len)}
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Bignum.bn_to_bytes_be len b ==
Lib.ByteSequence.nat_to_intseq_be len (Hacl.Spec.Bignum.Definitions.bn_v b)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.numbytes",
"Hacl.Spec.Bignum.Definitions.blocks",
"Lib.IntTypes.max_size_t",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.op_LessThan",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Prims.pow2",
"Hacl.Spec.Bignum.Convert.bn_to_bytes_be_lemma",
"Prims.unit"
] | [] | true | false | true | false | false | let bn_to_bytes_be_lemma #t len b =
| Hacl.Spec.Bignum.Convert.bn_to_bytes_be_lemma len b | false |
SteelFramingTestSuite.fst | SteelFramingTestSuite.test | val test: Prims.unit -> SteelT unit ((p `star` p) `star` p) (fun _ -> (p `star` p) `star` p) | val test: Prims.unit -> SteelT unit ((p `star` p) `star` p) (fun _ -> (p `star` p) `star` p) | let test () : SteelT unit (p `star` p `star` p) (fun _ -> p `star` p `star` p)
= f 0; () | {
"file_name": "share/steel/tests/SteelFramingTestSuite.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 11,
"end_line": 28,
"start_col": 0,
"start_line": 27
} | (*
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 SteelFramingTestSuite
open Steel.Memory
open Steel.Effect
/// A collection of small unit tests for the framing tactic
assume val p : vprop
assume val f (x:int) : SteelT unit p (fun _ -> p) | {
"checked_file": "/",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "SteelFramingTestSuite.fst"
} | [
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 -> Steel.Effect.SteelT Prims.unit | Steel.Effect.SteelT | [] | [] | [
"Prims.unit",
"SteelFramingTestSuite.f",
"Steel.Effect.Common.star",
"SteelFramingTestSuite.p",
"Steel.Effect.Common.vprop"
] | [] | false | true | false | false | false | let test () : SteelT unit ((p `star` p) `star` p) (fun _ -> (p `star` p) `star` p) =
| f 0;
() | false |
Vale.Transformers.PrefetchElim.fst | Vale.Transformers.PrefetchElim.prefetch_elim_correct | val prefetch_elim_correct (is: list ins) (s: machine_state)
: Lemma (peephole_correct prefetch_elim_ph is s)
[SMTPat (peephole_correct prefetch_elim_ph is s)] | val prefetch_elim_correct (is: list ins) (s: machine_state)
: Lemma (peephole_correct prefetch_elim_ph is s)
[SMTPat (peephole_correct prefetch_elim_ph is s)] | let prefetch_elim_correct (is:list ins) (s:machine_state) :
Lemma (peephole_correct prefetch_elim_ph is s)
[SMTPat (peephole_correct prefetch_elim_ph is s)] =
match is with
| [Instr i oprs (AnnotatePrefetchnta ())] -> ()
| _ -> () | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.PrefetchElim.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 28,
"start_col": 0,
"start_line": 23
} | module Vale.Transformers.PrefetchElim
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Transformers.InstructionReorder
open Vale.X64.InsLemmas
open Vale.Transformers.PeepHole
let prefetch_elim_ph = {
ph = (function
| [Instr i oprs (AnnotatePrefetchnta ())] ->
Some []
| _ -> None);
input_hint = 1;
} | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.InsLemmas.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.PeepHole.fsti.checked",
"Vale.Transformers.InstructionReorder.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Transformers.PrefetchElim.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Transformers.PeepHole",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers.InstructionReorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 3,
"max_fuel": 2,
"max_ifuel": 3,
"no_plugins": false,
"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 | is: Prims.list Vale.X64.Machine_Semantics_s.ins -> s: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(ensures
Vale.Transformers.PeepHole.peephole_correct Vale.Transformers.PrefetchElim.prefetch_elim_ph
is
s)
[
SMTPat (Vale.Transformers.PeepHole.peephole_correct Vale.Transformers.PrefetchElim.prefetch_elim_ph
is
s)
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.list",
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Instruction_s.instr_t_record",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Vale.Transformers.PeepHole.peephole_correct",
"Vale.Transformers.PrefetchElim.prefetch_elim_ph",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | false | false | true | false | false | let prefetch_elim_correct (is: list ins) (s: machine_state)
: Lemma (peephole_correct prefetch_elim_ph is s)
[SMTPat (peephole_correct prefetch_elim_ph is s)] =
| match is with
| [Instr i oprs (AnnotatePrefetchnta ())] -> ()
| _ -> () | false |
Pulse.Lib.PCM.Array.fst | Pulse.Lib.PCM.Array.mk_carrier_inj | val mk_carrier_inj (#elt: Type) (len offset: nat) (s1 s2: Seq.seq elt) (p1 p2: perm)
: Lemma
(requires
(mk_carrier len offset s1 p1 == mk_carrier len offset s2 p2 /\ offset + Seq.length s1 <= len /\
offset + Seq.length s2 <= len))
(ensures (s1 `Seq.equal` s2 /\ (Seq.length s1 > 0 ==> p1 == p2))) | val mk_carrier_inj (#elt: Type) (len offset: nat) (s1 s2: Seq.seq elt) (p1 p2: perm)
: Lemma
(requires
(mk_carrier len offset s1 p1 == mk_carrier len offset s2 p2 /\ offset + Seq.length s1 <= len /\
offset + Seq.length s2 <= len))
(ensures (s1 `Seq.equal` s2 /\ (Seq.length s1 > 0 ==> p1 == p2))) | let mk_carrier_inj
(#elt: Type)
(len: nat)
(offset: nat)
(s1 s2: Seq.seq elt)
(p1 p2: perm)
: Lemma
(requires (
mk_carrier len offset s1 p1 == mk_carrier len offset s2 p2 /\
offset + Seq.length s1 <= len /\
offset + Seq.length s2 <= len
))
(ensures (
s1 `Seq.equal` s2 /\
(Seq.length s1 > 0 ==> p1 == p2)
))
= assert (forall (i: nat) . i < Seq.length s1 ==>
(M.sel (mk_carrier len offset s1 p1) (offset + i) == Some (Seq.index s1 i, p1)));
assert (forall (i: nat) . i < Seq.length s2 ==>
M.sel (mk_carrier len offset s2 p2) (offset + i) == Some (Seq.index s2 i, p2)) | {
"file_name": "share/steel/examples/pulse/lib/Pulse.Lib.PCM.Array.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 83,
"end_line": 59,
"start_col": 0,
"start_line": 40
} | module Pulse.Lib.PCM.Array
module P = Pulse.Lib.PCM.Fraction
module M = FStar.Map
module PM = Pulse.Lib.PCM.Map
module Seq = FStar.Seq
open PulseCore.FractionalPermission
let index_t (len: Ghost.erased nat)
: Type0
= i: nat { i < len }
let carrier (elt: Type u#a) (len: Ghost.erased nat)
: Type u#a
= PM.map (index_t len) (P.fractional elt)
let pcm (elt: Type u#a) (len: Ghost.erased nat)
: FStar.PCM.pcm (carrier elt len)
= PM.pointwise (index_t len) (P.pcm_frac #elt)
let one (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).p.one
let composable (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).p.composable
let compose (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).p.op
let mk_carrier
(#elt: Type)
(len: nat)
(offset: nat)
(s: Seq.seq elt)
(p: perm)
: Tot (carrier elt len)
= let f (i: nat) : Tot (P.fractional elt) =
if offset + Seq.length s > len || i < offset || i >= offset + Seq.length s
then None
else Some (Seq.index s (i - offset), p)
in
M.map_literal f | {
"checked_file": "/",
"dependencies": [
"PulseCore.FractionalPermission.fst.checked",
"Pulse.Lib.PCM.Map.fst.checked",
"Pulse.Lib.PCM.Fraction.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Lib.PCM.Array.fst"
} | [
{
"abbrev": false,
"full_module": "PulseCore.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.PCM.Map",
"short_module": "PM"
},
{
"abbrev": true,
"full_module": "FStar.Map",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.PCM.Fraction",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
len: Prims.nat ->
offset: Prims.nat ->
s1: FStar.Seq.Base.seq elt ->
s2: FStar.Seq.Base.seq elt ->
p1: PulseCore.FractionalPermission.perm ->
p2: PulseCore.FractionalPermission.perm
-> FStar.Pervasives.Lemma
(requires
Pulse.Lib.PCM.Array.mk_carrier len offset s1 p1 ==
Pulse.Lib.PCM.Array.mk_carrier len offset s2 p2 /\ offset + FStar.Seq.Base.length s1 <= len /\
offset + FStar.Seq.Base.length s2 <= len)
(ensures FStar.Seq.Base.equal s1 s2 /\ (FStar.Seq.Base.length s1 > 0 ==> p1 == p2)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"FStar.Seq.Base.seq",
"PulseCore.FractionalPermission.perm",
"Prims._assert",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"FStar.Map.sel",
"Pulse.Lib.PCM.Array.index_t",
"FStar.Ghost.hide",
"Pulse.Lib.PCM.Fraction.fractional",
"Pulse.Lib.PCM.Array.mk_carrier",
"Prims.op_Addition",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Seq.Base.index",
"Prims.unit",
"Prims.l_and",
"Pulse.Lib.PCM.Array.carrier",
"Prims.op_LessThanOrEqual",
"Prims.squash",
"FStar.Seq.Base.equal",
"Prims.op_GreaterThan",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let mk_carrier_inj (#elt: Type) (len offset: nat) (s1 s2: Seq.seq elt) (p1 p2: perm)
: Lemma
(requires
(mk_carrier len offset s1 p1 == mk_carrier len offset s2 p2 /\ offset + Seq.length s1 <= len /\
offset + Seq.length s2 <= len))
(ensures (s1 `Seq.equal` s2 /\ (Seq.length s1 > 0 ==> p1 == p2))) =
| assert (forall (i: nat).
i < Seq.length s1 ==>
(M.sel (mk_carrier len offset s1 p1) (offset + i) == Some (Seq.index s1 i, p1)));
assert (forall (i: nat).
i < Seq.length s2 ==>
M.sel (mk_carrier len offset s2 p2) (offset + i) == Some (Seq.index s2 i, p2)) | false |
SteelFramingTestSuite.fst | SteelFramingTestSuite.test_subcomp_dep | val test_subcomp_dep (n: int) : SteelT unit (int_sl n) (fun _ -> int_sl n) | val test_subcomp_dep (n: int) : SteelT unit (int_sl n) (fun _ -> int_sl n) | let test_subcomp_dep (n:int) : SteelT unit (int_sl n) (fun _ -> int_sl n) =
int_f (n - 1 + 1);
int_f n | {
"file_name": "share/steel/tests/SteelFramingTestSuite.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 9,
"end_line": 189,
"start_col": 0,
"start_line": 187
} | (*
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 SteelFramingTestSuite
open Steel.Memory
open Steel.Effect
/// A collection of small unit tests for the framing tactic
assume val p : vprop
assume val f (x:int) : SteelT unit p (fun _ -> p)
let test () : SteelT unit (p `star` p `star` p) (fun _ -> p `star` p `star` p)
= f 0; ()
assume val ref : Type0
assume val ptr (_:ref) : vprop
assume val alloc (x:int) : SteelT ref emp (fun y -> ptr y)
assume val free (r:ref) : SteelT unit (ptr r) (fun _ -> emp)
assume val read (r:ref) : SteelT int (ptr r) (fun _ -> ptr r)
assume val write (r:ref) (v: int) : SteelT unit (ptr r) (fun _ -> ptr r)
let unused x = x // work around another gensym heisenbug
let test0 (b1 b2 b3: ref) : SteelT int
(ptr b1 `star` ptr b2 `star` ptr b3)
(fun _ -> ptr b1 `star` ptr b2 `star` ptr b3)
=
let x = read b1 in
x
let test1 (b1 b2 b3: ref) : SteelT int
(ptr b1 `star` ptr b2 `star` ptr b3)
(fun _ -> ptr b1 `star` ptr b2 `star` ptr b3)
=
let x = (let y = read b1 in y) in
x
let test2 (b1 b2 b3: ref) : SteelT int
(ptr b1 `star` ptr b2 `star` ptr b3)
(fun _ -> ptr b3 `star` ptr b2 `star` ptr b1)
=
let x = read b1 in
x
let test3 (b1 b2 b3: ref) : SteelT int
(ptr b1 `star` ptr b2 `star` ptr b3)
(fun _ -> ptr b2 `star` ptr b1 `star` ptr b3)
=
let x = read b3 in
x
let test4 (b1 b2 b3: ref) : SteelT unit
(ptr b1 `star` ptr b2 `star` ptr b3)
(fun _ -> ptr b2 `star` ptr b1 `star` ptr b3)
=
let x = read b3 in
write b2 x
let test5 (b1 b2 b3: ref) : SteelT unit
(ptr b1 `star` ptr b2 `star` ptr b3)
(fun _ -> ptr b2 `star` ptr b1 `star` ptr b3)
=
let x = read b3 in
write b2 (x + 1)
let test6 (b1 b2 b3: ref) : SteelT unit
(ptr b1 `star` ptr b2 `star` ptr b3)
(fun _ -> ptr b2 `star` ptr b1 `star` ptr b3)
=
let x = read b3 in
let b4 = alloc x in
write b2 (x + 1);
free b4
// With the formalism relying on can_be_split_post, this example fails if we normalize return_pre eqs goals before unification
// When solving this equality, we have the goal
// (*?u19*) _ _ == return_pre ((fun x -> (fun x -> (*?u758*) _ x x) x) r)
// with x and r in the context of ?u19
// Not normalizing allows us to solve it as a function applied to x and r
// Normalizing would lead to solve it to an slprop with x and r in the context,
// but which would later fail when trying to prove the equivalence with (fun r -> ptr r)
// in the postcondition
let test7 (_:unit) : SteelT ref emp ptr
= let r = alloc 0 in
let x = read r in
write r 0;
r
let test8 (b1 b2 b3:ref) : SteelT unit
(ptr b1 `star` ptr b2 `star` ptr b3)
(fun _ -> ptr b2 `star` ptr b1 `star` ptr b3)
= write b2 0
open Steel.Effect.Atomic
let test_if1 (b:bool) : SteelT unit emp (fun _ -> emp)
= if b then noop () else noop ()
let test_if2 (b:bool) (r: ref) : SteelT unit (ptr r) (fun _ -> ptr r)
= if b then write r 0 else write r 1
let test_if3 (b:bool) (r:ref) : SteelT unit (ptr r) (fun _ -> ptr r)
= if b then noop () else noop ()
let test_if4 (b:bool) : SteelT unit emp (fun _ -> emp)
= if b then (let r = alloc 0 in free r) else (noop ())
let test_if5 (b:bool) : SteelT ref emp (fun r -> ptr r)
= if b then alloc 0 else alloc 1
let test_if6 (b:bool) : SteelT ref emp (fun r -> ptr r)
= let r = if b then alloc 0 else alloc 1 in
let x = read r in
write r 0;
r
(* First test with different (but equivalent) slprops in both branches *)
let test_if7 (b:bool) (r1 r2: ref) : SteelT unit
(ptr r1 `star` ptr r2)
(fun _ -> ptr r1 `star` ptr r2)
= if b then (write r1 0; write r2 0) else (write r2 0; write r1 0);
write r2 0
(* Test with different slprops in both branches. The second branch captures the outer frame in its context *)
let test_if8 (b:bool) (r1 r2: ref) : SteelT unit
(ptr r1 `star` ptr r2)
(fun _ -> ptr r1 `star` ptr r2)
= if b then (write r1 0; write r2 0) else (write r2 0);
write r2 0
let test_if9 (b:bool) (r1 r2: ref) : SteelT unit
(ptr r1 `star` ptr r2)
(fun _ -> ptr r1 `star` ptr r2)
= write r1 0;
if b then (write r1 0) else (write r2 0);
write r2 0;
if b then (write r1 0) else (write r2 0);
write r1 0
(* Leave out some extra slprop outside of if_then_else *)
let test_if10 (b:bool) (r1 r2 r3: ref) : SteelT unit
(ptr r1 `star` ptr r2 `star` ptr r3)
(fun _ -> ptr r1 `star` ptr r2 `star` ptr r3)
= if b then (write r1 0; write r2 0) else (write r2 0; write r1 0);
write r2 0
(* Tests if_then_else depending on previously created local var *)
let test_if11 () : SteelT ref emp ptr =
let r = alloc 0 in
if true then return r else return r
// Test for refinement types in return values. cf PR 2227
assume
val f_ref (p:prop) :
SteelT (u:unit{p}) emp (fun _ -> emp)
let g (p:prop)
: Steel unit emp (fun _ -> emp) (requires fun _ -> True) (ensures fun _ _ _ -> p) =
let f2 (p:prop)
: SteelT (u:unit{p}) emp (fun _ -> emp)
= f_ref p
in
let x = f2 p in x
assume
val int_sl ([@@@smt_fallback] n:int) : vprop
assume val int_f (n:int) : SteelT unit (int_sl n) (fun _ -> int_sl n) | {
"checked_file": "/",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "SteelFramingTestSuite.fst"
} | [
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Prims.int -> Steel.Effect.SteelT Prims.unit | Steel.Effect.SteelT | [] | [] | [
"Prims.int",
"SteelFramingTestSuite.int_f",
"Prims.unit",
"Prims.op_Addition",
"Prims.op_Subtraction",
"SteelFramingTestSuite.int_sl",
"Steel.Effect.Common.vprop"
] | [] | false | true | false | false | false | let test_subcomp_dep (n: int) : SteelT unit (int_sl n) (fun _ -> int_sl n) =
| int_f (n - 1 + 1);
int_f n | false |
Steel.ST.HigherArray.fst | Steel.ST.HigherArray.elim_pts_to | val elim_pts_to (#opened: _) (#elt: Type u#1) (a: array elt) (p: P.perm) (s: Seq.seq elt)
: STGhost unit
opened
(pts_to a p s)
(fun _ ->
R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p))
(True)
(fun _ ->
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\
Seq.length s == length a) | val elim_pts_to (#opened: _) (#elt: Type u#1) (a: array elt) (p: P.perm) (s: Seq.seq elt)
: STGhost unit
opened
(pts_to a p s)
(fun _ ->
R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p))
(True)
(fun _ ->
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\
Seq.length s == length a) | let elim_pts_to (#opened: _) (#elt: Type u#1) (a: array elt) (p: P.perm) (s: Seq.seq elt) : STGhost unit opened
(pts_to a p s)
(fun _ -> R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p))
(True)
(fun _ ->
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\
Seq.length s == length a
)
= rewrite
(pts_to a p s)
(pts_to0 a p s);
elim_pure _ | {
"file_name": "lib/steel/Steel.ST.HigherArray.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 13,
"end_line": 178,
"start_col": 0,
"start_line": 167
} | (*
Copyright 2022 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.ST.HigherArray
module P = Steel.PCMFrac
module R = Steel.ST.PCMReference
module M = FStar.Map
module PM = Steel.PCMMap
[@@noextract_to "krml"]
let index_t (len: Ghost.erased nat) : Tot Type0 =
(i: nat { i < len })
[@@noextract_to "krml"]
let carrier (elt: Type u#a) (len: Ghost.erased nat) : Tot Type =
PM.map (index_t len) (P.fractional elt)
[@@noextract_to "krml"]
let pcm (elt: Type u#a) (len: Ghost.erased nat) : Tot (P.pcm (carrier elt len)) =
PM.pointwise (index_t len) (P.pcm_frac #elt)
[@@noextract_to "krml"]
let one (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.one
let composable (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.composable
[@@noextract_to "krml"]
let compose (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.op
[@@noextract_to "krml"]
let mk_carrier
(#elt: Type)
(len: nat)
(offset: nat)
(s: Seq.seq elt)
(p: P.perm)
: Tot (carrier elt len)
= let f (i: nat) : Tot (P.fractional elt) =
if offset + Seq.length s > len || i < offset || i >= offset + Seq.length s
then None
else Some (Seq.index s (i - offset), p)
in
M.map_literal f
let mk_carrier_inj
(#elt: Type)
(len: nat)
(offset: nat)
(s1 s2: Seq.seq elt)
(p1 p2: P.perm)
: Lemma
(requires (
mk_carrier len offset s1 p1 == mk_carrier len offset s2 p2 /\
offset + Seq.length s1 <= len /\
offset + Seq.length s2 <= len
))
(ensures (
s1 `Seq.equal` s2 /\
(Seq.length s1 > 0 ==> p1 == p2)
))
= assert (forall (i: nat) . i < Seq.length s1 ==>
(M.sel (mk_carrier len offset s1 p1) (offset + i) == Some (Seq.index s1 i, p1)));
assert (forall (i: nat) . i < Seq.length s2 ==>
M.sel (mk_carrier len offset s2 p2) (offset + i) == Some (Seq.index s2 i, p2))
[@@erasable]
let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: US.t & ref _ (pcm elt (US.v base_len)))
let base_len (#elt: Type) (b: base_t elt) : GTot nat = US.v (dfst b)
[@@noextract_to "krml"]
noeq
type ptr (elt: Type u#a) : Type0 = {
base_len: Ghost.erased US.t;
// U32.t to prove that A.read, A.write offset computation does not overflow. TODO: replace U32.t with size_t
base: (r: ref _ (pcm elt (US.v base_len)) { core_ref_is_null r ==> US.v base_len == 0 });
offset: (offset: nat { offset <= US.v base_len });
}
let null_ptr a = { base_len = 0sz; base = null #_ #(pcm a 0) ; offset = 0 }
let is_null_ptr p = is_null p.base
let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |)
let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset
let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma
(requires (
base p1 == base p2 /\
offset p1 == offset p2
))
(ensures (
p1 == p2
))
= ()
let base_len_null_ptr _ = ()
let length_fits #elt a = ()
let valid_perm
(len: nat)
(offset: nat)
(slice_len: nat)
(p: P.perm) : Tot prop =
let open FStar.Real in
((offset + slice_len <= len /\ slice_len > 0) ==> (p.P.v <=. one))
[@__reduce__]
let pts_to0 (#elt: Type u#1) (a: array elt) (p: P.perm) (s: Seq.seq elt) : Tot vprop =
R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p) `star`
pure (
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\
Seq.length s == length a
)
let pts_to (#elt: Type u#1) (a: array elt) ([@@@ smt_fallback ] p: P.perm) ([@@@ smt_fallback ] s: Seq.seq elt) : Tot vprop =
pts_to0 a p s
// this lemma is necessary because Steel.PCMReference is marked unfold
let change_r_pts_to
(#opened: _)
(#carrier: Type u#1)
(#pcm: P.pcm carrier)
(p: ref carrier pcm)
(v: carrier)
(#carrier': Type u#1)
(#pcm': P.pcm carrier')
(p': ref carrier' pcm')
(v': carrier')
: STGhost unit opened
(R.pts_to p v)
(fun _ -> R.pts_to p' v')
(// keep on distinct lines for error messages
carrier == carrier' /\
pcm == pcm' /\
p == p' /\
v == v')
(fun _ -> True)
= rewrite
(R.pts_to p v)
(R.pts_to p' v')
let intro_pts_to (#opened: _) (#elt: Type u#1) (a: array elt) (#v: _) (p: P.perm) (s: Seq.seq elt) : STGhost unit opened
(R.pts_to (ptr_of a).base v)
(fun _ -> pts_to a p s)
(
v == mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p /\
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\
Seq.length s == length a
)
(fun _ -> True)
= change_r_pts_to (ptr_of a).base v (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p);
intro_pure _;
rewrite
(pts_to0 a p s)
(pts_to a p s) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.PCMReference.fsti.checked",
"Steel.ST.Loops.fsti.checked",
"Steel.PCMMap.fst.checked",
"Steel.PCMFrac.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.HigherArray.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.PCMMap",
"short_module": "PM"
},
{
"abbrev": true,
"full_module": "FStar.Map",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Steel.ST.PCMReference",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "Steel.PCMFrac",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Steel.ST.HigherArray.array elt -> p: Steel.FractionalPermission.perm -> s: FStar.Seq.Base.seq elt
-> Steel.ST.Effect.Ghost.STGhost Prims.unit | Steel.ST.Effect.Ghost.STGhost | [] | [] | [
"Steel.Memory.inames",
"Steel.ST.HigherArray.array",
"Steel.FractionalPermission.perm",
"FStar.Seq.Base.seq",
"Steel.ST.Util.elim_pure",
"Prims.l_and",
"Steel.ST.HigherArray.valid_perm",
"FStar.SizeT.v",
"FStar.Ghost.reveal",
"FStar.SizeT.t",
"Steel.ST.HigherArray.__proj__Mkptr__item__base_len",
"Steel.ST.HigherArray.ptr_of",
"Steel.ST.HigherArray.__proj__Mkptr__item__offset",
"FStar.Seq.Base.length",
"Prims.eq2",
"Prims.nat",
"Steel.ST.HigherArray.length",
"Prims.unit",
"Steel.ST.Util.rewrite",
"Steel.ST.HigherArray.pts_to",
"Steel.ST.HigherArray.pts_to0",
"Steel.ST.PCMReference.pts_to",
"Steel.ST.HigherArray.carrier",
"FStar.Ghost.hide",
"Steel.ST.HigherArray.pcm",
"Steel.ST.HigherArray.__proj__Mkptr__item__base",
"Steel.ST.HigherArray.mk_carrier",
"Steel.Effect.Common.vprop",
"Prims.l_True"
] | [] | false | true | false | false | false | let elim_pts_to (#opened: _) (#elt: Type u#1) (a: array elt) (p: P.perm) (s: Seq.seq elt)
: STGhost unit
opened
(pts_to a p s)
(fun _ ->
R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p))
(True)
(fun _ ->
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\
Seq.length s == length a) =
| rewrite (pts_to a p s) (pts_to0 a p s);
elim_pure _ | false |
Pulse.Lib.PCM.Array.fst | Pulse.Lib.PCM.Array.mk_carrier | val mk_carrier (#elt: Type) (len offset: nat) (s: Seq.seq elt) (p: perm) : Tot (carrier elt len) | val mk_carrier (#elt: Type) (len offset: nat) (s: Seq.seq elt) (p: perm) : Tot (carrier elt len) | let mk_carrier
(#elt: Type)
(len: nat)
(offset: nat)
(s: Seq.seq elt)
(p: perm)
: Tot (carrier elt len)
= let f (i: nat) : Tot (P.fractional elt) =
if offset + Seq.length s > len || i < offset || i >= offset + Seq.length s
then None
else Some (Seq.index s (i - offset), p)
in
M.map_literal f | {
"file_name": "share/steel/examples/pulse/lib/Pulse.Lib.PCM.Array.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 17,
"end_line": 38,
"start_col": 0,
"start_line": 26
} | module Pulse.Lib.PCM.Array
module P = Pulse.Lib.PCM.Fraction
module M = FStar.Map
module PM = Pulse.Lib.PCM.Map
module Seq = FStar.Seq
open PulseCore.FractionalPermission
let index_t (len: Ghost.erased nat)
: Type0
= i: nat { i < len }
let carrier (elt: Type u#a) (len: Ghost.erased nat)
: Type u#a
= PM.map (index_t len) (P.fractional elt)
let pcm (elt: Type u#a) (len: Ghost.erased nat)
: FStar.PCM.pcm (carrier elt len)
= PM.pointwise (index_t len) (P.pcm_frac #elt)
let one (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).p.one
let composable (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).p.composable
let compose (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).p.op | {
"checked_file": "/",
"dependencies": [
"PulseCore.FractionalPermission.fst.checked",
"Pulse.Lib.PCM.Map.fst.checked",
"Pulse.Lib.PCM.Fraction.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.PCM.fst.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Lib.PCM.Array.fst"
} | [
{
"abbrev": false,
"full_module": "PulseCore.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.PCM.Map",
"short_module": "PM"
},
{
"abbrev": true,
"full_module": "FStar.Map",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.PCM.Fraction",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.PCM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
len: Prims.nat ->
offset: Prims.nat ->
s: FStar.Seq.Base.seq elt ->
p: PulseCore.FractionalPermission.perm
-> Pulse.Lib.PCM.Array.carrier elt (FStar.Ghost.hide len) | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"FStar.Seq.Base.seq",
"PulseCore.FractionalPermission.perm",
"FStar.Map.map_literal",
"Pulse.Lib.PCM.Array.index_t",
"FStar.Ghost.hide",
"Pulse.Lib.PCM.Fraction.fractional",
"Prims.op_BarBar",
"Prims.op_GreaterThan",
"Prims.op_Addition",
"FStar.Seq.Base.length",
"Prims.op_LessThan",
"Prims.op_GreaterThanOrEqual",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.tuple2",
"Prims.bool",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Seq.Base.index",
"Prims.op_Subtraction",
"Pulse.Lib.PCM.Array.carrier"
] | [] | false | false | false | false | false | let mk_carrier (#elt: Type) (len offset: nat) (s: Seq.seq elt) (p: perm) : Tot (carrier elt len) =
| let f (i: nat) : Tot (P.fractional elt) =
if offset + Seq.length s > len || i < offset || i >= offset + Seq.length s
then None
else Some (Seq.index s (i - offset), p)
in
M.map_literal f | false |
Hacl.Bignum.Lib.fst | Hacl.Bignum.Lib.bn_get_top_index_u32 | val bn_get_top_index_u32 (len: _) : bn_get_top_index_st U32 len | val bn_get_top_index_u32 (len: _) : bn_get_top_index_st U32 len | let bn_get_top_index_u32 len: bn_get_top_index_st U32 len = mk_bn_get_top_index #U32 len | {
"file_name": "code/bignum/Hacl.Bignum.Lib.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 88,
"end_line": 136,
"start_col": 0,
"start_line": 136
} | module Hacl.Bignum.Lib
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Base
open Hacl.Bignum.Definitions
module S = Hacl.Spec.Bignum.Lib
module ST = FStar.HyperStack.ST
module Loops = Lib.LoopCombinators
module LSeq = Lib.Sequence
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Get and set i-th bit of a bignum
///
inline_for_extraction noextract
val bn_get_ith_bit:
#t:limb_t
-> len:size_t
-> b:lbignum t len
-> i:size_t{v i / bits t < v len} ->
Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.bn_get_ith_bit (as_seq h0 b) (v i))
let bn_get_ith_bit #t len input ind =
[@inline_let]
let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
let tmp = input.(i) in
(tmp >>. j) &. uint #t 1
inline_for_extraction noextract
val bn_set_ith_bit:
#t:limb_t
-> len:size_t
-> b:lbignum t len
-> i:size_t{v i / bits t < v len} ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i))
let bn_set_ith_bit #t len input ind =
[@inline_let]
let pbits = size (bits t) in
let i = ind /. pbits in
assert (v i == v ind / bits t);
let j = ind %. pbits in
assert (v j == v ind % bits t);
input.(i) <- input.(i) |. (uint #t 1 <<. j)
inline_for_extraction noextract
val cswap2_st:
#t:limb_t
-> len:size_t
-> bit:limb t
-> b1:lbignum t len
-> b2:lbignum t len ->
Stack unit
(requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2)
(ensures fun h0 _ h1 -> modifies (loc b1 |+| loc b2) h0 h1 /\
(as_seq h1 b1, as_seq h1 b2) == S.cswap2 bit (as_seq h0 b1) (as_seq h0 b2))
let cswap2_st #t len bit b1 b2 =
[@inline_let]
let mask = uint #t 0 -. bit in
[@inline_let]
let spec h0 = S.cswap2_f mask in
let h0 = ST.get () in
loop2 h0 len b1 b2 spec
(fun i ->
Loops.unfold_repeati (v len) (spec h0) (as_seq h0 b1, as_seq h0 b2) (v i);
let dummy = mask &. (b1.(i) ^. b2.(i)) in
b1.(i) <- b1.(i) ^. dummy;
b2.(i) <- b2.(i) ^. dummy
)
inline_for_extraction noextract
let bn_get_top_index_st (t:limb_t) (len:size_t{0 < v len}) =
b:lbignum t len ->
Stack (limb t)
(requires fun h -> live h b)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
v r == S.bn_get_top_index (as_seq h0 b))
inline_for_extraction noextract
val mk_bn_get_top_index: #t:limb_t -> len:size_t{0 < v len} -> bn_get_top_index_st t len
let mk_bn_get_top_index #t len b =
push_frame ();
let priv = create 1ul (uint #t 0) in
let h0 = ST.get () in
[@ inline_let]
let refl h i = v (LSeq.index (as_seq h priv) 0) in
[@ inline_let]
let spec h0 = S.bn_get_top_index_f (as_seq h0 b) in
[@ inline_let]
let inv h (i:nat{i <= v len}) =
modifies1 priv h0 h /\
live h priv /\ live h b /\ disjoint priv b /\
refl h i == Loops.repeat_gen i (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) in
Loops.eq_repeat_gen0 (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0);
Lib.Loops.for 0ul len inv
(fun i ->
Loops.unfold_repeat_gen (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) (v i);
let mask = eq_mask b.(i) (zeros t SEC) in
let h1 = ST.get () in
priv.(0ul) <- mask_select mask priv.(0ul) (size_to_limb i);
mask_select_lemma mask (LSeq.index (as_seq h1 priv) 0) (size_to_limb i));
let res = priv.(0ul) in
pop_frame ();
res | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.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.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Lib.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | len: Lib.IntTypes.size_t{0 < Lib.IntTypes.v len}
-> Hacl.Bignum.Lib.bn_get_top_index_st Lib.IntTypes.U32 len | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Bignum.Lib.mk_bn_get_top_index",
"Hacl.Bignum.Lib.bn_get_top_index_st"
] | [] | false | false | false | false | false | let bn_get_top_index_u32 len : bn_get_top_index_st U32 len =
| mk_bn_get_top_index #U32 len | false |
LowParse.SLow.Enum.fst | LowParse.SLow.Enum.parse32_maybe_enum_key_gen | val parse32_maybe_enum_key_gen
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(p32: parser32 p)
(e: enum key repr)
(k': parser_kind)
(t': Type)
(p': parser k' t')
(u1: unit{k' == k})
(u15: unit{t' == maybe_enum_key e})
(u2: unit{p' == parse_maybe_enum_key p e})
(f: maybe_enum_key_of_repr'_t e)
: Tot (parser32 p') | val parse32_maybe_enum_key_gen
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(p32: parser32 p)
(e: enum key repr)
(k': parser_kind)
(t': Type)
(p': parser k' t')
(u1: unit{k' == k})
(u15: unit{t' == maybe_enum_key e})
(u2: unit{p' == parse_maybe_enum_key p e})
(f: maybe_enum_key_of_repr'_t e)
: Tot (parser32 p') | let parse32_maybe_enum_key_gen
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(p32: parser32 p)
(e: enum key repr)
(k' : parser_kind)
(t' : Type)
(p' : parser k' t')
(u1: unit { k' == k })
(u15: unit { t' == maybe_enum_key e } )
(u2: unit { p' == parse_maybe_enum_key p e } )
(f: maybe_enum_key_of_repr'_t e)
: Tot (parser32 p')
= parse32_synth p (maybe_enum_key_of_repr e) f p32 () | {
"file_name": "src/lowparse/LowParse.SLow.Enum.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 53,
"end_line": 25,
"start_col": 0,
"start_line": 11
} | module LowParse.SLow.Enum
include LowParse.Spec.Enum
include LowParse.SLow.Combinators
module L = FStar.List.Tot
module U32 = FStar.UInt32
(* Parser for enums *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Enum.fst.checked",
"LowParse.SLow.Combinators.fst.checked",
"LowParse.Bytes32.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.Enum.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "LowParse.SLow.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p32: LowParse.SLow.Base.parser32 p ->
e: LowParse.Spec.Enum.enum key repr ->
k': LowParse.Spec.Base.parser_kind ->
t': Type0 ->
p': LowParse.Spec.Base.parser k' t' ->
u1: Prims.unit{k' == k} ->
u15: Prims.unit{t' == LowParse.Spec.Enum.maybe_enum_key e} ->
u2: Prims.unit{p' == LowParse.Spec.Enum.parse_maybe_enum_key p e} ->
f: LowParse.Spec.Enum.maybe_enum_key_of_repr'_t e
-> LowParse.SLow.Base.parser32 p' | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"Prims.eqtype",
"LowParse.Spec.Base.parser",
"LowParse.SLow.Base.parser32",
"LowParse.Spec.Enum.enum",
"Prims.unit",
"Prims.eq2",
"LowParse.Spec.Enum.maybe_enum_key",
"LowParse.Spec.Enum.parse_maybe_enum_key",
"LowParse.Spec.Enum.maybe_enum_key_of_repr'_t",
"LowParse.SLow.Combinators.parse32_synth",
"LowParse.Spec.Enum.maybe_enum_key_of_repr"
] | [] | false | false | false | false | false | let parse32_maybe_enum_key_gen
(#k: parser_kind)
(#key #repr: eqtype)
(#p: parser k repr)
(p32: parser32 p)
(e: enum key repr)
(k': parser_kind)
(t': Type)
(p': parser k' t')
(u1: unit{k' == k})
(u15: unit{t' == maybe_enum_key e})
(u2: unit{p' == parse_maybe_enum_key p e})
(f: maybe_enum_key_of_repr'_t e)
: Tot (parser32 p') =
| parse32_synth p (maybe_enum_key_of_repr e) f p32 () | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.