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
CDDL.Spec.fsti
CDDL.Spec.list_ghost_forall2
val list_ghost_forall2 (#t1 #t2: Type) (f: (t1 -> t2 -> GTot prop)) (l1: list t1) (l2: list t2) : GTot bool (decreases l1)
val list_ghost_forall2 (#t1 #t2: Type) (f: (t1 -> t2 -> GTot prop)) (l1: list t1) (l2: list t2) : GTot bool (decreases l1)
let rec list_ghost_forall2 (#t1 #t2: Type) (f: t1 -> t2 -> GTot prop) (l1: list t1) (l2: list t2) : GTot bool (decreases l1) = match l1, l2 with | [], [] -> true | a1 :: q1, a2 :: q2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (f a1 a2) && list_ghost_forall2 f q1 q2 | _ -> false
{ "file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 14, "end_line": 544, "start_col": 0, "start_line": 534 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module CDDL.Spec module Cbor = CBOR.Spec module U8 = FStar.UInt8 module U64 = FStar.UInt64 // Concise Data Definition Language (RFC 8610) noextract let opt_precedes (#t1 #t2: Type) (x1: t1) (x2: option t2) : Tot prop = match x2 with | None -> True | Some x2 -> x1 << x2 [@@noextract_to "krml"] let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization) [@@noextract_to "krml"] let typ = bounded_typ_gen None [@@noextract_to "krml"] let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e) let coerce_to_bounded_typ (b: option Cbor.raw_data_item) (t: typ) : Tot (bounded_typ_gen b) = t noextract let typ_equiv (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : Tot prop = forall x . t1 x == t2 x let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x) let t_choice_equiv #b (t1 t1' t2 t2' : bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2')) (ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2'))) = () // etc. let t_choice_simpl #b (t: bounded_typ_gen b) : Lemma ((t `t_choice` t) `typ_equiv` t) = () let t_always_false : typ = (fun _ -> false) let t_literal (i: Cbor.raw_data_item) : typ = (fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i)) // Appendix D let any : typ = (fun _ -> true) let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64) let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64) let t_int : typ = uint `t_choice` nint let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string) let bytes = bstr let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string) let text = tstr [@@CMacro] let simple_value_false : Cbor.simple_value = 20uy [@@CMacro] let simple_value_true : Cbor.simple_value = 21uy [@@CMacro] let simple_value_nil : Cbor.simple_value = 22uy [@@CMacro] let simple_value_undefined : Cbor.simple_value = 23uy let t_simple_value_literal (s: Cbor.simple_value) : typ = t_literal (Cbor.Simple s) let t_false : typ = t_simple_value_literal simple_value_false let t_true : typ = t_simple_value_literal simple_value_true let t_bool : typ = t_choice t_false t_true let t_nil : typ = t_simple_value_literal simple_value_nil let t_null : typ = t_nil let t_undefined : typ = t_simple_value_literal simple_value_undefined let t_uint_literal (v: U64.t) : typ = t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v) // Section 2.1: Groups // Groups in array context (Section 3.4) // General semantics, which would imply backtracking [@@erasable; noextract_to "krml"] let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool) let array_group1_empty : array_group1 = fun k -> k let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k) let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) = k l || a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more' let array_group1_item (t: typ) : array_group1 = fun k l -> match l with | [] -> false | a :: q -> t a && k q let t_array1 (a: array_group1) : typ = fun x -> Cbor.Array? x && a Nil? (Cbor.Array?.v x) [@@noextract_to "krml"] let nat_up_to (n: nat) : eqtype = (i: nat { i <= n }) [@@noextract_to "krml"] let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l))) [@@noextract_to "krml"] let array_group2_empty : array_group2 = (fun _ i -> [i]) [@@noextract_to "krml"] let array_group2_concat (a1 a2: array_group2) : array_group2 = (fun l i1 -> let res1 = a1 l i1 in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1 ) [@@noextract_to "krml"] let array_group2_choice (a1 a2: array_group2) : array_group2 = fun l i -> a1 l i `List.Tot.append` a2 l i [@@noextract_to "krml"] let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) = i :: begin let r1 = a l i in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> if i2 <= i then [] else array_group2_zero_or_more' a l i2 ) r1 end (* [@@noextract_to "krml"] let array_group2_item (t: typ) : array_group2 = fun l i -> if i = Seq.length l then [] else if t (Seq.index l i) then [i + 1] else [] *) [@@noextract_to "krml"] let t_array2 (a: array_group2) : typ = fun x -> Cbor.Array? x && begin let l = Cbor.Array?.v x in List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0 end // Greedy semantics (Appendix A?) let list_is_suffix_of (#t: Type) (small large: list t) : Tot prop = exists prefix . large == prefix `List.Tot.append` small let list_is_suffix_of_refl (#t: Type) (l: list t) : Lemma (l `list_is_suffix_of` l) [SMTPat (l `list_is_suffix_of` l)] = assert (l == [] `List.Tot.append` l) let rec list_nil_precedes (#t: Type) (l: list t) : Lemma (Nil #t == l \/ Nil #t << l) = match l with | [] -> () | a :: q -> list_nil_precedes q let rec list_is_suffix_of_precedes (#t0 #t: Type) (v0: t0) (small large: list t) : Lemma (requires ( large << v0 /\ small `list_is_suffix_of` large )) (ensures ( small << v0 )) (decreases (List.Tot.length large)) [SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]] = if Nil? small then list_nil_precedes large else begin let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in List.Tot.append_length prefix small; if List.Tot.length small = List.Tot.length large then () else list_is_suffix_of_precedes v0 small (List.Tot.tl large) end [@@erasable; noextract_to "krml"] let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with | None -> True | Some l' -> opt_precedes l' bound )) noextract let array_group3_equiv #b (g1 g2: array_group3 b) : Tot prop = forall l . g1 l == g2 l let array_group3_always_false #b : array_group3 b = fun _ -> None let array_group3_empty #b : array_group3 b = fun x -> Some x let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b = (fun l -> match a1 l with | None -> None | Some l3 -> a3 l3 ) let array_group3_concat_equiv #b (a1 a1' a2 a2' : array_group3 b) : Lemma (requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2'))) (ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2'))) = () let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b = fun l -> match a1 l with | None -> a3 l | Some l3 -> Some l3 let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b)) (decreases (List.Tot.length l)) = match a l with | None -> Some l | Some l' -> if List.Tot.length l' >= List.Tot.length l then Some l else array_group3_zero_or_more' a l' let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more' let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b = a `array_group3_concat` array_group3_zero_or_more a let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) = a `array_group3_choice` array_group3_empty let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l -> match l with | [] -> None | a :: q -> if t a then Some q else None let array_group3_item_equiv #b (t1 t2: bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t2)) (ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2)) = () let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b) (l: list Cbor.raw_data_item {opt_precedes l b}) : GTot bool = match a l with | Some l' -> Nil? l' | _ -> false let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x -> Cbor.Array? x && match_array_group3 a (Cbor.Array?.v x) let t_array3_equiv #b (a1 a2: array_group3 b) : Lemma (requires (array_group3_equiv a1 a2)) (ensures (typ_equiv (t_array3 a1) (t_array3 a2))) = () // Recursive type (needed by COSE Section 5.1 "Recipient") // Inspiring from Barthe et al., Type-Based Termination with Sized // Products (CSL 2008): we allow recursion only at the level of // destructors. In other words, instead of having a generic recursion // combinator, we provide a recursion-enabled version only for each // destructor combinator. We need to annotate it with a bound b (akin // to the "size" annotation in a sized type.) let rec t_array3_rec (phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b))) (x: Cbor.raw_data_item) : GTot bool (decreases x) = Cbor.Array? x && match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x) // Groups in map context (Section 3.5) [@@erasable] noeq type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b module Pull = FStar.Ghost.Pull noextract let opt_map_entry_bounded' (b: option Cbor.raw_data_item) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) : GTot bool = FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b) let opt_map_entry_bounded (b: option Cbor.raw_data_item) : GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool) = Pull.pull (opt_map_entry_bounded' b) let rec opt_precedes_map_for_all_opt_map_entry_bounded (b: option Cbor.raw_data_item) (l: list (Cbor.raw_data_item & Cbor.raw_data_item)) : Lemma (requires (opt_precedes l b)) (ensures (List.Tot.for_all (opt_map_entry_bounded b) l)) [SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)] = match l with | [] -> () | _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q let matches_map_group_entry (#b: option Cbor.raw_data_item) (ge: map_group_entry b) (x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true }) : GTot bool = ge.fst (fst x) && ge.snd (snd x) [@@erasable] noeq type map_group (b: option Cbor.raw_data_item) = { one: list (map_group_entry b); zero_or_one: list (map_group_entry b); zero_or_more: list (map_group_entry b); } let map_group_empty #b : map_group b = { one = []; zero_or_one = []; zero_or_more = []; } let cut_map_group_entry_key #b (key: bounded_typ_gen b) (t: bounded_typ_gen b) (x: Cbor.raw_data_item { opt_precedes x b }) : GTot bool = t x && not (key x) // Section 3.5.4: Cut let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b = cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = { one = List.Tot.map (cut_map_group_entry key) g.one; zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one; zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more; } let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = if cut then cut_map_group (ge.fst) g else g let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with one = ge :: g.one; } let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_one = ge :: g.zero_or_one; } let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_more = ge :: g.zero_or_more; } val matches_map_group (#b: option Cbor.raw_data_item) (m: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x }) : GTot bool val matches_map_group_empty (b: option Cbor.raw_data_item) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (ensures (matches_map_group (map_group_empty #b) x == Nil? x)) [SMTPat (matches_map_group (map_group_empty #b) x)] (* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *) noextract let is_sub_map_group_of #b (small large: map_group b) : Tot prop = forall x . matches_map_group small x ==> matches_map_group large x noextract let map_group_equiv #b (mg1 mg2: map_group b) : Tot prop = forall x . matches_map_group mg1 x == matches_map_group mg2 x noextract let is_sub_typ_of #b (small large: bounded_typ_gen b) : Tot prop = forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x noextract let is_sub_map_group_entry_of #b (small large: map_group_entry b) : Tot prop = small.fst `is_sub_typ_of` large.fst /\ small.snd `is_sub_typ_of` large.snd let map_group_ignore_restricted_entries #b (mg: map_group b) : Tot (map_group b) = {mg with one = []; zero_or_one = []; } let pull_rel (#t1 #t2: Type) (r: t1 -> t2 -> prop) (x1: t1) : GTot ((x2: t2) -> Tot bool) = Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2)) let list_ghost_forall_exists_body (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l2: list t2) : GTot (t1 -> bool) = Pull.pull (fun x1 -> List.Tot.existsb (pull_rel r x1) l2 ) let list_ghost_forall_exists (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l1: list t1) (l2: list t2) : GTot bool = List.Tot.for_all (list_ghost_forall_exists_body r l2) l1 noextract let matches_map_group_entry' (#b: _) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) (y: map_group_entry b) : Tot prop = opt_map_entry_bounded b x ==> matches_map_group_entry y x val matches_map_group_no_restricted (#b: _) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires ( Nil? g.one /\ Nil? g.zero_or_one )) (ensures ( matches_map_group g x <==> list_ghost_forall_exists matches_map_group_entry' x g.zero_or_more )) [SMTPat (matches_map_group g x)]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt.fsti.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.Pull.fsti.checked", "CBOR.Spec.fsti.checked" ], "interface_file": false, "source_file": "CDDL.Spec.fsti" }
[ { "abbrev": true, "full_module": "FStar.Ghost.Pull", "short_module": "Pull" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "CBOR.Spec", "short_module": "Cbor" }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: t1 -> _: t2 -> Prims.GTot Prims.prop) -> l1: Prims.list t1 -> l2: Prims.list t2 -> Prims.GTot Prims.bool
Prims.GTot
[ "sometrivial", "" ]
[]
[ "Prims.prop", "Prims.list", "FStar.Pervasives.Native.Mktuple2", "Prims.op_AmpAmp", "FStar.StrongExcludedMiddle.strong_excluded_middle", "CDDL.Spec.list_ghost_forall2", "FStar.Pervasives.Native.tuple2", "Prims.bool" ]
[ "recursion" ]
false
false
false
false
false
let rec list_ghost_forall2 (#t1 #t2: Type) (f: (t1 -> t2 -> GTot prop)) (l1: list t1) (l2: list t2) : GTot bool (decreases l1) =
match l1, l2 with | [], [] -> true | a1 :: q1, a2 :: q2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (f a1 a2) && list_ghost_forall2 f q1 q2 | _ -> false
false
CDDL.Spec.fsti
CDDL.Spec.list_ghost_forall2_map_r
val list_ghost_forall2_map_r (#t1 #t2: Type) (r: (t1 -> t2 -> prop)) (f: (t1 -> t2)) (l: list t1) : Lemma (requires (forall x. r x (f x))) (ensures (list_ghost_forall2 r l (List.Tot.map f l)))
val list_ghost_forall2_map_r (#t1 #t2: Type) (r: (t1 -> t2 -> prop)) (f: (t1 -> t2)) (l: list t1) : Lemma (requires (forall x. r x (f x))) (ensures (list_ghost_forall2 r l (List.Tot.map f l)))
let rec list_ghost_forall2_map_r (#t1 #t2: Type) (r: t1 -> t2 -> prop) (f: t1 -> t2) (l: list t1) : Lemma (requires (forall x . r x (f x))) (ensures (list_ghost_forall2 r l (List.Tot.map f l))) = match l with | [] -> () | _ :: q -> list_ghost_forall2_map_r r f q
{ "file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 44, "end_line": 632, "start_col": 0, "start_line": 622 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module CDDL.Spec module Cbor = CBOR.Spec module U8 = FStar.UInt8 module U64 = FStar.UInt64 // Concise Data Definition Language (RFC 8610) noextract let opt_precedes (#t1 #t2: Type) (x1: t1) (x2: option t2) : Tot prop = match x2 with | None -> True | Some x2 -> x1 << x2 [@@noextract_to "krml"] let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization) [@@noextract_to "krml"] let typ = bounded_typ_gen None [@@noextract_to "krml"] let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e) let coerce_to_bounded_typ (b: option Cbor.raw_data_item) (t: typ) : Tot (bounded_typ_gen b) = t noextract let typ_equiv (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : Tot prop = forall x . t1 x == t2 x let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x) let t_choice_equiv #b (t1 t1' t2 t2' : bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2')) (ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2'))) = () // etc. let t_choice_simpl #b (t: bounded_typ_gen b) : Lemma ((t `t_choice` t) `typ_equiv` t) = () let t_always_false : typ = (fun _ -> false) let t_literal (i: Cbor.raw_data_item) : typ = (fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i)) // Appendix D let any : typ = (fun _ -> true) let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64) let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64) let t_int : typ = uint `t_choice` nint let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string) let bytes = bstr let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string) let text = tstr [@@CMacro] let simple_value_false : Cbor.simple_value = 20uy [@@CMacro] let simple_value_true : Cbor.simple_value = 21uy [@@CMacro] let simple_value_nil : Cbor.simple_value = 22uy [@@CMacro] let simple_value_undefined : Cbor.simple_value = 23uy let t_simple_value_literal (s: Cbor.simple_value) : typ = t_literal (Cbor.Simple s) let t_false : typ = t_simple_value_literal simple_value_false let t_true : typ = t_simple_value_literal simple_value_true let t_bool : typ = t_choice t_false t_true let t_nil : typ = t_simple_value_literal simple_value_nil let t_null : typ = t_nil let t_undefined : typ = t_simple_value_literal simple_value_undefined let t_uint_literal (v: U64.t) : typ = t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v) // Section 2.1: Groups // Groups in array context (Section 3.4) // General semantics, which would imply backtracking [@@erasable; noextract_to "krml"] let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool) let array_group1_empty : array_group1 = fun k -> k let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k) let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) = k l || a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more' let array_group1_item (t: typ) : array_group1 = fun k l -> match l with | [] -> false | a :: q -> t a && k q let t_array1 (a: array_group1) : typ = fun x -> Cbor.Array? x && a Nil? (Cbor.Array?.v x) [@@noextract_to "krml"] let nat_up_to (n: nat) : eqtype = (i: nat { i <= n }) [@@noextract_to "krml"] let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l))) [@@noextract_to "krml"] let array_group2_empty : array_group2 = (fun _ i -> [i]) [@@noextract_to "krml"] let array_group2_concat (a1 a2: array_group2) : array_group2 = (fun l i1 -> let res1 = a1 l i1 in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1 ) [@@noextract_to "krml"] let array_group2_choice (a1 a2: array_group2) : array_group2 = fun l i -> a1 l i `List.Tot.append` a2 l i [@@noextract_to "krml"] let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) = i :: begin let r1 = a l i in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> if i2 <= i then [] else array_group2_zero_or_more' a l i2 ) r1 end (* [@@noextract_to "krml"] let array_group2_item (t: typ) : array_group2 = fun l i -> if i = Seq.length l then [] else if t (Seq.index l i) then [i + 1] else [] *) [@@noextract_to "krml"] let t_array2 (a: array_group2) : typ = fun x -> Cbor.Array? x && begin let l = Cbor.Array?.v x in List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0 end // Greedy semantics (Appendix A?) let list_is_suffix_of (#t: Type) (small large: list t) : Tot prop = exists prefix . large == prefix `List.Tot.append` small let list_is_suffix_of_refl (#t: Type) (l: list t) : Lemma (l `list_is_suffix_of` l) [SMTPat (l `list_is_suffix_of` l)] = assert (l == [] `List.Tot.append` l) let rec list_nil_precedes (#t: Type) (l: list t) : Lemma (Nil #t == l \/ Nil #t << l) = match l with | [] -> () | a :: q -> list_nil_precedes q let rec list_is_suffix_of_precedes (#t0 #t: Type) (v0: t0) (small large: list t) : Lemma (requires ( large << v0 /\ small `list_is_suffix_of` large )) (ensures ( small << v0 )) (decreases (List.Tot.length large)) [SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]] = if Nil? small then list_nil_precedes large else begin let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in List.Tot.append_length prefix small; if List.Tot.length small = List.Tot.length large then () else list_is_suffix_of_precedes v0 small (List.Tot.tl large) end [@@erasable; noextract_to "krml"] let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with | None -> True | Some l' -> opt_precedes l' bound )) noextract let array_group3_equiv #b (g1 g2: array_group3 b) : Tot prop = forall l . g1 l == g2 l let array_group3_always_false #b : array_group3 b = fun _ -> None let array_group3_empty #b : array_group3 b = fun x -> Some x let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b = (fun l -> match a1 l with | None -> None | Some l3 -> a3 l3 ) let array_group3_concat_equiv #b (a1 a1' a2 a2' : array_group3 b) : Lemma (requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2'))) (ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2'))) = () let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b = fun l -> match a1 l with | None -> a3 l | Some l3 -> Some l3 let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b)) (decreases (List.Tot.length l)) = match a l with | None -> Some l | Some l' -> if List.Tot.length l' >= List.Tot.length l then Some l else array_group3_zero_or_more' a l' let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more' let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b = a `array_group3_concat` array_group3_zero_or_more a let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) = a `array_group3_choice` array_group3_empty let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l -> match l with | [] -> None | a :: q -> if t a then Some q else None let array_group3_item_equiv #b (t1 t2: bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t2)) (ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2)) = () let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b) (l: list Cbor.raw_data_item {opt_precedes l b}) : GTot bool = match a l with | Some l' -> Nil? l' | _ -> false let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x -> Cbor.Array? x && match_array_group3 a (Cbor.Array?.v x) let t_array3_equiv #b (a1 a2: array_group3 b) : Lemma (requires (array_group3_equiv a1 a2)) (ensures (typ_equiv (t_array3 a1) (t_array3 a2))) = () // Recursive type (needed by COSE Section 5.1 "Recipient") // Inspiring from Barthe et al., Type-Based Termination with Sized // Products (CSL 2008): we allow recursion only at the level of // destructors. In other words, instead of having a generic recursion // combinator, we provide a recursion-enabled version only for each // destructor combinator. We need to annotate it with a bound b (akin // to the "size" annotation in a sized type.) let rec t_array3_rec (phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b))) (x: Cbor.raw_data_item) : GTot bool (decreases x) = Cbor.Array? x && match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x) // Groups in map context (Section 3.5) [@@erasable] noeq type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b module Pull = FStar.Ghost.Pull noextract let opt_map_entry_bounded' (b: option Cbor.raw_data_item) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) : GTot bool = FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b) let opt_map_entry_bounded (b: option Cbor.raw_data_item) : GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool) = Pull.pull (opt_map_entry_bounded' b) let rec opt_precedes_map_for_all_opt_map_entry_bounded (b: option Cbor.raw_data_item) (l: list (Cbor.raw_data_item & Cbor.raw_data_item)) : Lemma (requires (opt_precedes l b)) (ensures (List.Tot.for_all (opt_map_entry_bounded b) l)) [SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)] = match l with | [] -> () | _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q let matches_map_group_entry (#b: option Cbor.raw_data_item) (ge: map_group_entry b) (x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true }) : GTot bool = ge.fst (fst x) && ge.snd (snd x) [@@erasable] noeq type map_group (b: option Cbor.raw_data_item) = { one: list (map_group_entry b); zero_or_one: list (map_group_entry b); zero_or_more: list (map_group_entry b); } let map_group_empty #b : map_group b = { one = []; zero_or_one = []; zero_or_more = []; } let cut_map_group_entry_key #b (key: bounded_typ_gen b) (t: bounded_typ_gen b) (x: Cbor.raw_data_item { opt_precedes x b }) : GTot bool = t x && not (key x) // Section 3.5.4: Cut let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b = cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = { one = List.Tot.map (cut_map_group_entry key) g.one; zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one; zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more; } let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = if cut then cut_map_group (ge.fst) g else g let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with one = ge :: g.one; } let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_one = ge :: g.zero_or_one; } let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_more = ge :: g.zero_or_more; } val matches_map_group (#b: option Cbor.raw_data_item) (m: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x }) : GTot bool val matches_map_group_empty (b: option Cbor.raw_data_item) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (ensures (matches_map_group (map_group_empty #b) x == Nil? x)) [SMTPat (matches_map_group (map_group_empty #b) x)] (* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *) noextract let is_sub_map_group_of #b (small large: map_group b) : Tot prop = forall x . matches_map_group small x ==> matches_map_group large x noextract let map_group_equiv #b (mg1 mg2: map_group b) : Tot prop = forall x . matches_map_group mg1 x == matches_map_group mg2 x noextract let is_sub_typ_of #b (small large: bounded_typ_gen b) : Tot prop = forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x noextract let is_sub_map_group_entry_of #b (small large: map_group_entry b) : Tot prop = small.fst `is_sub_typ_of` large.fst /\ small.snd `is_sub_typ_of` large.snd let map_group_ignore_restricted_entries #b (mg: map_group b) : Tot (map_group b) = {mg with one = []; zero_or_one = []; } let pull_rel (#t1 #t2: Type) (r: t1 -> t2 -> prop) (x1: t1) : GTot ((x2: t2) -> Tot bool) = Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2)) let list_ghost_forall_exists_body (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l2: list t2) : GTot (t1 -> bool) = Pull.pull (fun x1 -> List.Tot.existsb (pull_rel r x1) l2 ) let list_ghost_forall_exists (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l1: list t1) (l2: list t2) : GTot bool = List.Tot.for_all (list_ghost_forall_exists_body r l2) l1 noextract let matches_map_group_entry' (#b: _) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) (y: map_group_entry b) : Tot prop = opt_map_entry_bounded b x ==> matches_map_group_entry y x val matches_map_group_no_restricted (#b: _) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires ( Nil? g.one /\ Nil? g.zero_or_one )) (ensures ( matches_map_group g x <==> list_ghost_forall_exists matches_map_group_entry' x g.zero_or_more )) [SMTPat (matches_map_group g x)] let rec list_ghost_forall2 (#t1 #t2: Type) (f: t1 -> t2 -> GTot prop) (l1: list t1) (l2: list t2) : GTot bool (decreases l1) = match l1, l2 with | [], [] -> true | a1 :: q1, a2 :: q2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (f a1 a2) && list_ghost_forall2 f q1 q2 | _ -> false val list_ghost_forall_exists_is_sub_map_group_entry_of_refl (#b: _) (l: list (map_group_entry b)) : Lemma (ensures (list_ghost_forall_exists is_sub_map_group_entry_of l l)) [SMTPat (list_ghost_forall_exists is_sub_map_group_entry_of l l)] let map_group_included_zero_or_more #b (small large: map_group b) : GTot bool = list_ghost_forall_exists is_sub_map_group_entry_of small.one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_more large.zero_or_more && Nil? large.one val map_group_included_zero_or_more_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_zero_or_more small large)) (ensures (is_sub_map_group_of small large)) val map_group_ignore_restricted_entries_sub (#b: _) (mg: map_group b) : Lemma (requires ( list_ghost_forall_exists is_sub_map_group_entry_of mg.one mg.zero_or_more /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( mg `is_sub_map_group_of` map_group_ignore_restricted_entries mg )) let map_group_ignore_restricted_entries_no_one_equiv #b (mg: map_group b) : Lemma (requires ( Nil? mg.one /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( map_group_equiv mg (map_group_ignore_restricted_entries mg) )) = map_group_ignore_restricted_entries_sub mg; map_group_included_zero_or_more_correct (map_group_ignore_restricted_entries mg) mg let map_group_included_pointwise #b (small large: map_group b) : GTot bool = list_ghost_forall2 is_sub_map_group_entry_of small.one large.one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_one large.zero_or_one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_more large.zero_or_more val map_group_included_pointwise_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_pointwise small large)) (ensures (is_sub_map_group_of small large)) let rec list_ghost_forall2_map_l (#t1 #t2: Type) (r: t1 -> t2 -> prop) (f: t2 -> t1) (l: list t2) : Lemma (requires (forall x . r (f x) x)) (ensures (list_ghost_forall2 r (List.Tot.map f l) l)) = match l with | [] -> () | _ :: q -> list_ghost_forall2_map_l r f q
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt.fsti.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.Pull.fsti.checked", "CBOR.Spec.fsti.checked" ], "interface_file": false, "source_file": "CDDL.Spec.fsti" }
[ { "abbrev": true, "full_module": "FStar.Ghost.Pull", "short_module": "Pull" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "CBOR.Spec", "short_module": "Cbor" }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: (_: t1 -> _: t2 -> Prims.prop) -> f: (_: t1 -> t2) -> l: Prims.list t1 -> FStar.Pervasives.Lemma (requires forall (x: t1). r x (f x)) (ensures CDDL.Spec.list_ghost_forall2 r l (FStar.List.Tot.Base.map f l))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.prop", "Prims.list", "CDDL.Spec.list_ghost_forall2_map_r", "Prims.unit", "Prims.l_Forall", "Prims.squash", "Prims.b2t", "CDDL.Spec.list_ghost_forall2", "FStar.List.Tot.Base.map", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec list_ghost_forall2_map_r (#t1 #t2: Type) (r: (t1 -> t2 -> prop)) (f: (t1 -> t2)) (l: list t1) : Lemma (requires (forall x. r x (f x))) (ensures (list_ghost_forall2 r l (List.Tot.map f l))) =
match l with | [] -> () | _ :: q -> list_ghost_forall2_map_r r f q
false
CDDL.Spec.fsti
CDDL.Spec.bstr_cbor
val bstr_cbor (data_item_order: (Cbor.raw_data_item -> Cbor.raw_data_item -> bool)) (ty: typ) : typ
val bstr_cbor (data_item_order: (Cbor.raw_data_item -> Cbor.raw_data_item -> bool)) (ty: typ) : typ
let bstr_cbor (data_item_order: (Cbor.raw_data_item -> Cbor.raw_data_item -> bool)) (ty: typ) // TODO: enable recursion for this construct? If so, we need to replace << with some serialization size : typ = fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string && FStar.StrongExcludedMiddle.strong_excluded_middle ( exists y . Cbor.serialize_cbor y == Cbor.String?.v x /\ Cbor.data_item_wf data_item_order y /\ ty y == true )
{ "file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 3, "end_line": 869, "start_col": 0, "start_line": 859 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module CDDL.Spec module Cbor = CBOR.Spec module U8 = FStar.UInt8 module U64 = FStar.UInt64 // Concise Data Definition Language (RFC 8610) noextract let opt_precedes (#t1 #t2: Type) (x1: t1) (x2: option t2) : Tot prop = match x2 with | None -> True | Some x2 -> x1 << x2 [@@noextract_to "krml"] let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization) [@@noextract_to "krml"] let typ = bounded_typ_gen None [@@noextract_to "krml"] let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e) let coerce_to_bounded_typ (b: option Cbor.raw_data_item) (t: typ) : Tot (bounded_typ_gen b) = t noextract let typ_equiv (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : Tot prop = forall x . t1 x == t2 x let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x) let t_choice_equiv #b (t1 t1' t2 t2' : bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2')) (ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2'))) = () // etc. let t_choice_simpl #b (t: bounded_typ_gen b) : Lemma ((t `t_choice` t) `typ_equiv` t) = () let t_always_false : typ = (fun _ -> false) let t_literal (i: Cbor.raw_data_item) : typ = (fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i)) // Appendix D let any : typ = (fun _ -> true) let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64) let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64) let t_int : typ = uint `t_choice` nint let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string) let bytes = bstr let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string) let text = tstr [@@CMacro] let simple_value_false : Cbor.simple_value = 20uy [@@CMacro] let simple_value_true : Cbor.simple_value = 21uy [@@CMacro] let simple_value_nil : Cbor.simple_value = 22uy [@@CMacro] let simple_value_undefined : Cbor.simple_value = 23uy let t_simple_value_literal (s: Cbor.simple_value) : typ = t_literal (Cbor.Simple s) let t_false : typ = t_simple_value_literal simple_value_false let t_true : typ = t_simple_value_literal simple_value_true let t_bool : typ = t_choice t_false t_true let t_nil : typ = t_simple_value_literal simple_value_nil let t_null : typ = t_nil let t_undefined : typ = t_simple_value_literal simple_value_undefined let t_uint_literal (v: U64.t) : typ = t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v) // Section 2.1: Groups // Groups in array context (Section 3.4) // General semantics, which would imply backtracking [@@erasable; noextract_to "krml"] let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool) let array_group1_empty : array_group1 = fun k -> k let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k) let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) = k l || a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more' let array_group1_item (t: typ) : array_group1 = fun k l -> match l with | [] -> false | a :: q -> t a && k q let t_array1 (a: array_group1) : typ = fun x -> Cbor.Array? x && a Nil? (Cbor.Array?.v x) [@@noextract_to "krml"] let nat_up_to (n: nat) : eqtype = (i: nat { i <= n }) [@@noextract_to "krml"] let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l))) [@@noextract_to "krml"] let array_group2_empty : array_group2 = (fun _ i -> [i]) [@@noextract_to "krml"] let array_group2_concat (a1 a2: array_group2) : array_group2 = (fun l i1 -> let res1 = a1 l i1 in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1 ) [@@noextract_to "krml"] let array_group2_choice (a1 a2: array_group2) : array_group2 = fun l i -> a1 l i `List.Tot.append` a2 l i [@@noextract_to "krml"] let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) = i :: begin let r1 = a l i in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> if i2 <= i then [] else array_group2_zero_or_more' a l i2 ) r1 end (* [@@noextract_to "krml"] let array_group2_item (t: typ) : array_group2 = fun l i -> if i = Seq.length l then [] else if t (Seq.index l i) then [i + 1] else [] *) [@@noextract_to "krml"] let t_array2 (a: array_group2) : typ = fun x -> Cbor.Array? x && begin let l = Cbor.Array?.v x in List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0 end // Greedy semantics (Appendix A?) let list_is_suffix_of (#t: Type) (small large: list t) : Tot prop = exists prefix . large == prefix `List.Tot.append` small let list_is_suffix_of_refl (#t: Type) (l: list t) : Lemma (l `list_is_suffix_of` l) [SMTPat (l `list_is_suffix_of` l)] = assert (l == [] `List.Tot.append` l) let rec list_nil_precedes (#t: Type) (l: list t) : Lemma (Nil #t == l \/ Nil #t << l) = match l with | [] -> () | a :: q -> list_nil_precedes q let rec list_is_suffix_of_precedes (#t0 #t: Type) (v0: t0) (small large: list t) : Lemma (requires ( large << v0 /\ small `list_is_suffix_of` large )) (ensures ( small << v0 )) (decreases (List.Tot.length large)) [SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]] = if Nil? small then list_nil_precedes large else begin let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in List.Tot.append_length prefix small; if List.Tot.length small = List.Tot.length large then () else list_is_suffix_of_precedes v0 small (List.Tot.tl large) end [@@erasable; noextract_to "krml"] let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with | None -> True | Some l' -> opt_precedes l' bound )) noextract let array_group3_equiv #b (g1 g2: array_group3 b) : Tot prop = forall l . g1 l == g2 l let array_group3_always_false #b : array_group3 b = fun _ -> None let array_group3_empty #b : array_group3 b = fun x -> Some x let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b = (fun l -> match a1 l with | None -> None | Some l3 -> a3 l3 ) let array_group3_concat_equiv #b (a1 a1' a2 a2' : array_group3 b) : Lemma (requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2'))) (ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2'))) = () let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b = fun l -> match a1 l with | None -> a3 l | Some l3 -> Some l3 let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b)) (decreases (List.Tot.length l)) = match a l with | None -> Some l | Some l' -> if List.Tot.length l' >= List.Tot.length l then Some l else array_group3_zero_or_more' a l' let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more' let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b = a `array_group3_concat` array_group3_zero_or_more a let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) = a `array_group3_choice` array_group3_empty let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l -> match l with | [] -> None | a :: q -> if t a then Some q else None let array_group3_item_equiv #b (t1 t2: bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t2)) (ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2)) = () let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b) (l: list Cbor.raw_data_item {opt_precedes l b}) : GTot bool = match a l with | Some l' -> Nil? l' | _ -> false let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x -> Cbor.Array? x && match_array_group3 a (Cbor.Array?.v x) let t_array3_equiv #b (a1 a2: array_group3 b) : Lemma (requires (array_group3_equiv a1 a2)) (ensures (typ_equiv (t_array3 a1) (t_array3 a2))) = () // Recursive type (needed by COSE Section 5.1 "Recipient") // Inspiring from Barthe et al., Type-Based Termination with Sized // Products (CSL 2008): we allow recursion only at the level of // destructors. In other words, instead of having a generic recursion // combinator, we provide a recursion-enabled version only for each // destructor combinator. We need to annotate it with a bound b (akin // to the "size" annotation in a sized type.) let rec t_array3_rec (phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b))) (x: Cbor.raw_data_item) : GTot bool (decreases x) = Cbor.Array? x && match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x) // Groups in map context (Section 3.5) [@@erasable] noeq type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b module Pull = FStar.Ghost.Pull noextract let opt_map_entry_bounded' (b: option Cbor.raw_data_item) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) : GTot bool = FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b) let opt_map_entry_bounded (b: option Cbor.raw_data_item) : GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool) = Pull.pull (opt_map_entry_bounded' b) let rec opt_precedes_map_for_all_opt_map_entry_bounded (b: option Cbor.raw_data_item) (l: list (Cbor.raw_data_item & Cbor.raw_data_item)) : Lemma (requires (opt_precedes l b)) (ensures (List.Tot.for_all (opt_map_entry_bounded b) l)) [SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)] = match l with | [] -> () | _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q let matches_map_group_entry (#b: option Cbor.raw_data_item) (ge: map_group_entry b) (x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true }) : GTot bool = ge.fst (fst x) && ge.snd (snd x) [@@erasable] noeq type map_group (b: option Cbor.raw_data_item) = { one: list (map_group_entry b); zero_or_one: list (map_group_entry b); zero_or_more: list (map_group_entry b); } let map_group_empty #b : map_group b = { one = []; zero_or_one = []; zero_or_more = []; } let cut_map_group_entry_key #b (key: bounded_typ_gen b) (t: bounded_typ_gen b) (x: Cbor.raw_data_item { opt_precedes x b }) : GTot bool = t x && not (key x) // Section 3.5.4: Cut let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b = cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = { one = List.Tot.map (cut_map_group_entry key) g.one; zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one; zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more; } let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = if cut then cut_map_group (ge.fst) g else g let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with one = ge :: g.one; } let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_one = ge :: g.zero_or_one; } let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_more = ge :: g.zero_or_more; } val matches_map_group (#b: option Cbor.raw_data_item) (m: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x }) : GTot bool val matches_map_group_empty (b: option Cbor.raw_data_item) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (ensures (matches_map_group (map_group_empty #b) x == Nil? x)) [SMTPat (matches_map_group (map_group_empty #b) x)] (* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *) noextract let is_sub_map_group_of #b (small large: map_group b) : Tot prop = forall x . matches_map_group small x ==> matches_map_group large x noextract let map_group_equiv #b (mg1 mg2: map_group b) : Tot prop = forall x . matches_map_group mg1 x == matches_map_group mg2 x noextract let is_sub_typ_of #b (small large: bounded_typ_gen b) : Tot prop = forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x noextract let is_sub_map_group_entry_of #b (small large: map_group_entry b) : Tot prop = small.fst `is_sub_typ_of` large.fst /\ small.snd `is_sub_typ_of` large.snd let map_group_ignore_restricted_entries #b (mg: map_group b) : Tot (map_group b) = {mg with one = []; zero_or_one = []; } let pull_rel (#t1 #t2: Type) (r: t1 -> t2 -> prop) (x1: t1) : GTot ((x2: t2) -> Tot bool) = Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2)) let list_ghost_forall_exists_body (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l2: list t2) : GTot (t1 -> bool) = Pull.pull (fun x1 -> List.Tot.existsb (pull_rel r x1) l2 ) let list_ghost_forall_exists (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l1: list t1) (l2: list t2) : GTot bool = List.Tot.for_all (list_ghost_forall_exists_body r l2) l1 noextract let matches_map_group_entry' (#b: _) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) (y: map_group_entry b) : Tot prop = opt_map_entry_bounded b x ==> matches_map_group_entry y x val matches_map_group_no_restricted (#b: _) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires ( Nil? g.one /\ Nil? g.zero_or_one )) (ensures ( matches_map_group g x <==> list_ghost_forall_exists matches_map_group_entry' x g.zero_or_more )) [SMTPat (matches_map_group g x)] let rec list_ghost_forall2 (#t1 #t2: Type) (f: t1 -> t2 -> GTot prop) (l1: list t1) (l2: list t2) : GTot bool (decreases l1) = match l1, l2 with | [], [] -> true | a1 :: q1, a2 :: q2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (f a1 a2) && list_ghost_forall2 f q1 q2 | _ -> false val list_ghost_forall_exists_is_sub_map_group_entry_of_refl (#b: _) (l: list (map_group_entry b)) : Lemma (ensures (list_ghost_forall_exists is_sub_map_group_entry_of l l)) [SMTPat (list_ghost_forall_exists is_sub_map_group_entry_of l l)] let map_group_included_zero_or_more #b (small large: map_group b) : GTot bool = list_ghost_forall_exists is_sub_map_group_entry_of small.one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_more large.zero_or_more && Nil? large.one val map_group_included_zero_or_more_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_zero_or_more small large)) (ensures (is_sub_map_group_of small large)) val map_group_ignore_restricted_entries_sub (#b: _) (mg: map_group b) : Lemma (requires ( list_ghost_forall_exists is_sub_map_group_entry_of mg.one mg.zero_or_more /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( mg `is_sub_map_group_of` map_group_ignore_restricted_entries mg )) let map_group_ignore_restricted_entries_no_one_equiv #b (mg: map_group b) : Lemma (requires ( Nil? mg.one /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( map_group_equiv mg (map_group_ignore_restricted_entries mg) )) = map_group_ignore_restricted_entries_sub mg; map_group_included_zero_or_more_correct (map_group_ignore_restricted_entries mg) mg let map_group_included_pointwise #b (small large: map_group b) : GTot bool = list_ghost_forall2 is_sub_map_group_entry_of small.one large.one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_one large.zero_or_one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_more large.zero_or_more val map_group_included_pointwise_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_pointwise small large)) (ensures (is_sub_map_group_of small large)) let rec list_ghost_forall2_map_l (#t1 #t2: Type) (r: t1 -> t2 -> prop) (f: t2 -> t1) (l: list t2) : Lemma (requires (forall x . r (f x) x)) (ensures (list_ghost_forall2 r (List.Tot.map f l) l)) = match l with | [] -> () | _ :: q -> list_ghost_forall2_map_l r f q let rec list_ghost_forall2_map_r (#t1 #t2: Type) (r: t1 -> t2 -> prop) (f: t1 -> t2) (l: list t1) : Lemma (requires (forall x . r x (f x))) (ensures (list_ghost_forall2 r l (List.Tot.map f l))) = match l with | [] -> () | _ :: q -> list_ghost_forall2_map_r r f q let cut_map_group_sub #b (key: bounded_typ_gen b) (mg: map_group b) : Lemma (cut_map_group key mg `is_sub_map_group_of` mg) = list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.one; list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_one; list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_more; map_group_included_pointwise_correct (cut_map_group key mg) mg (* Proving matches_map_group for sorted maps and map groups where key constraints specify whole elements *) let rec list_for_all_filter_invariant (#t: Type) (p: t -> bool) (f: t -> bool) (l: list t) : Lemma (requires (List.Tot.for_all p l == true)) (ensures (List.Tot.for_all p (List.Tot.filter f l) == true)) [SMTPat (List.Tot.for_all p (List.Tot.filter f l))] = match l with | [] -> () | _ :: q -> list_for_all_filter_invariant p f q let map_key_neq' (#t1 t2: Type) (k: t1) (x: (t1 & t2)) : GTot bool = FStar.StrongExcludedMiddle.strong_excluded_middle (~ (fst x == k)) let map_key_neq (#t1 t2: Type) (k: t1) : GTot ((t1 & t2) -> bool) = Pull.pull (map_key_neq' t2 k) let map_group_entry_for #b (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) : Tot (map_group_entry b) = MapGroupEntry (coerce_to_bounded_typ _ (t_literal k)) ty let rec list_ghost_assoc_for_all (#key: Type) (#value: Type) (p: (key & value) -> bool) (k: key) (m: list (key & value)) : Lemma (requires (List.Tot.for_all p m == true)) (ensures (match Cbor.list_ghost_assoc k m with | None -> True | Some y -> p (k, y) )) (decreases m) [SMTPat (List.Tot.for_all p m); SMTPat (Cbor.list_ghost_assoc k m)] = match m with | [] -> () | (k', _) :: m' -> if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k') then () else list_ghost_assoc_for_all p k m' let rec list_assoc_none_for_all_map_key_neq (k: Cbor.raw_data_item) (l: list (Cbor.raw_data_item & Cbor.raw_data_item)) : Lemma (requires (None? (Cbor.list_ghost_assoc k l))) (ensures (List.Tot.for_all (map_key_neq _ k) l == true)) = match l with | [] -> () | _ :: q -> list_assoc_none_for_all_map_key_neq k q val matches_map_group_map_group_cons_zero_or_one_no_repeats (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.no_repeats_p (List.Tot.map fst x))) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b end /\ matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> matches_map_group g x | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) val matches_map_group_map_group_cons_one_no_repeats (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.no_repeats_p (List.Tot.map fst x))) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b end /\ matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> false | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) val matches_map_group_map_group_cons_zero_or_one_deterministically_encoded_cbor_map_key_order (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) x)) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b /\ List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) (List.Tot.filter (map_key_neq _ k) x) end /\ matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> matches_map_group g x | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) [SMTPat (matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x)] val matches_map_group_map_group_cons_one_deterministically_encoded_cbor_map_key_order (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) x)) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b /\ List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) (List.Tot.filter (map_key_neq _ k) x) end /\ matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> false | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) [SMTPat (matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x)] // 2.1 specifies "names that turn into the map key text string" noextract let string64 = (s: Seq.seq U8.t {FStar.UInt.fits (Seq.length s) 64}) let name_as_text_string (s: string64) : typ = t_literal (Cbor.String Cbor.cbor_major_type_text_string s) let t_map (#b: option Cbor.raw_data_item) (m: map_group b) : bounded_typ_gen b = fun x -> Cbor.Map? x && matches_map_group m (Cbor.Map?.v x) let t_map_equiv #b (m1 m2: map_group b) : Lemma (requires (map_group_equiv m1 m2)) (ensures (typ_equiv (t_map m1) (t_map m2))) = () let rec t_map_rec (phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> map_group (Some b))) (x: Cbor.raw_data_item) : GTot bool (decreases x) = Cbor.Map? x && matches_map_group (phi x (t_map_rec phi)) (Cbor.Map?.v x) // Section 3.6: Tags let t_tag (#b: option Cbor.raw_data_item) (tag: U64.t) (t: bounded_typ_gen b) : bounded_typ_gen b = fun x -> Cbor.Tagged? x && Cbor.Tagged?.tag x = tag && t (Cbor.Tagged?.v x) let rec t_tag_rec (tag: U64.t) (phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> bounded_typ b)) (x: Cbor.raw_data_item) : GTot bool (decreases x) = Cbor.Tagged? x && Cbor.Tagged?.tag x = tag && phi x (t_tag_rec tag phi) (Cbor.Tagged?.v x) // Multi-purpose recursive combinator, to allow disjunctions between destructors let rec multi_rec (phi_base: typ) (phi_array: (b: Cbor.raw_data_item) -> bounded_typ b -> array_group3 (Some b)) (phi_map: (b: Cbor.raw_data_item) -> bounded_typ b -> map_group (Some b)) (phi_tag: U64.t -> (b: Cbor.raw_data_item) -> bounded_typ b -> bounded_typ b) (x: Cbor.raw_data_item) : GTot bool (decreases x) = phi_base x || begin match x with | Cbor.Array v -> match_array_group3 (phi_array x (multi_rec phi_base phi_array phi_map phi_tag)) v | Cbor.Map v -> matches_map_group (phi_map x (multi_rec phi_base phi_array phi_map phi_tag)) v | Cbor.Tagged tag v -> phi_tag tag x (multi_rec phi_base phi_array phi_map phi_tag) v | _ -> false end // Section 3.8.1: Control .size let str_size (ty: Cbor.major_type_byte_string_or_text_string) (sz: nat) : typ = fun x -> Cbor.String? x && Cbor.String?.typ x = ty && Seq.length (Cbor.String?.v x) = sz let uint_size (sz: nat) : typ = fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64 && U64.v (Cbor.Int64?.v x) < pow2 sz // Section 3.8.4: Control .cbor // We parameterize over the CBOR order on which the CBOR parser depends
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt.fsti.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.Pull.fsti.checked", "CBOR.Spec.fsti.checked" ], "interface_file": false, "source_file": "CDDL.Spec.fsti" }
[ { "abbrev": true, "full_module": "FStar.Ghost.Pull", "short_module": "Pull" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "CBOR.Spec", "short_module": "Cbor" }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
data_item_order: (_: CBOR.Spec.Type.raw_data_item -> _: CBOR.Spec.Type.raw_data_item -> Prims.bool) -> ty: CDDL.Spec.typ -> CDDL.Spec.typ
Prims.Tot
[ "total" ]
[]
[ "CBOR.Spec.Type.raw_data_item", "Prims.bool", "CDDL.Spec.typ", "CDDL.Spec.opt_precedes", "FStar.Pervasives.Native.None", "Prims.op_AmpAmp", "CBOR.Spec.Type.uu___is_String", "Prims.op_Equality", "CBOR.Spec.Constants.major_type_t", "CBOR.Spec.Type.__proj__String__item__typ", "CBOR.Spec.Constants.cbor_major_type_byte_string", "FStar.StrongExcludedMiddle.strong_excluded_middle", "Prims.l_Exists", "Prims.l_and", "Prims.eq2", "FStar.Seq.Base.seq", "FStar.UInt8.t", "CBOR.Spec.serialize_cbor", "CBOR.Spec.Type.__proj__String__item__v", "Prims.b2t", "CBOR.Spec.Type.data_item_wf" ]
[]
false
false
false
true
false
let bstr_cbor (data_item_order: (Cbor.raw_data_item -> Cbor.raw_data_item -> bool)) (ty: typ) : typ =
fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string && FStar.StrongExcludedMiddle.strong_excluded_middle (exists y. Cbor.serialize_cbor y == Cbor.String?.v x /\ Cbor.data_item_wf data_item_order y /\ ty y == true)
false
Steel.Primitive.ForkJoin.fst
Steel.Primitive.ForkJoin.join
val join (#p:vprop) (t:thread p) : SteelT unit emp (fun _ -> p)
val join (#p:vprop) (t:thread p) : SteelT unit emp (fun _ -> p)
let rec join (#p:vprop) (t:thread p) : SteelT unit emp (fun _ -> p) = let _ = L.acquire t.l in let b = read_refine_pt (maybe_p p) t.r in if b then (rewrite_slprop (lock_inv_pred t.r p b) p (fun _ -> ()); noop ()) else (rewrite_slprop (lock_inv_pred t.r p b) (lock_inv_pred t.r p false) (fun _ -> ()); intro_exists false (lock_inv_pred t.r p); L.release t.l; join t)
{ "file_name": "lib/steel/Steel.Primitive.ForkJoin.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 13, "end_line": 103, "start_col": 0, "start_line": 93 }
(* 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.Primitive.ForkJoin open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect module L = Steel.SpinLock open Steel.FractionalPermission open Steel.Reference //////////////////////////////////////////////////////////////////////////////// let maybe_p (p:vprop) (v:bool) = if v then p else emp [@@__reduce__] let lock_inv_pred (r:ref bool) (p:vprop) (v:bool) : vprop = pts_to r full_perm v `star` maybe_p p v let lock_inv (r:ref bool) (p:vprop) : vprop = h_exists (lock_inv_pred r p) noeq type thread (p:vprop) = { r:ref bool; l:L.lock (lock_inv r p) } let intro_maybe_p_false (p:vprop) : SteelT unit emp (fun _ -> maybe_p p false) = rewrite_slprop emp (maybe_p p false) (fun _ -> ()) let intro_maybe_p_true (p:vprop) : SteelT unit p (fun _ -> maybe_p p true) = rewrite_slprop p (maybe_p p true) (fun _ -> ()) let new_thread (p:vprop) : SteelT (thread p) emp (fun _ -> emp) = let r = alloc_pt false in intro_maybe_p_false p; intro_exists false (lock_inv_pred r p); let l = L.new_lock (lock_inv r p) in let t = {r = r; l = l} in t let finish (#p:vprop) (t:thread p) (v:bool) : SteelT unit (pts_to t.r full_perm v `star` p) (fun _ -> emp) = write_pt t.r true; intro_maybe_p_true p; intro_exists true (lock_inv_pred t.r p); L.release t.l let acquire (#p:vprop) (t:thread p) : SteelT bool emp (fun b -> pts_to t.r full_perm b) = L.acquire t.l; let b = read_refine_pt #_ #full_perm (maybe_p p) t.r in drop (maybe_p p b); return b let spawn (#p #q:vprop) ($f: (unit -> SteelT unit p (fun _ -> q))) (t:thread q) (_:unit) : SteelT unit p (fun _ -> emp) = let b = acquire t in f (); finish t b let fork (#p #q #r #s:vprop) (f: (unit -> SteelT unit p (fun _ -> q))) (g: (thread q -> unit -> SteelT unit r (fun _ -> s))) : SteelT unit (p `star` r) (fun _ -> s) = let t : thread q = new_thread q in let _ = par (spawn f t) (g t) in ()
{ "checked_file": "/", "dependencies": [ "Steel.SpinLock.fsti.checked", "Steel.Reference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Steel.Primitive.ForkJoin.fst" }
[ { "abbrev": false, "full_module": "Steel.Reference", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": true, "full_module": "Steel.SpinLock", "short_module": "L" }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "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": "Steel.Primitive", "short_module": null }, { "abbrev": false, "full_module": "Steel.Primitive", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Steel.Primitive.ForkJoin.thread p -> Steel.Effect.SteelT Prims.unit
Steel.Effect.SteelT
[]
[]
[ "Steel.Effect.Common.vprop", "Steel.Primitive.ForkJoin.thread", "Steel.Effect.Atomic.noop", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Prims.unit", "Steel.Effect.Atomic.rewrite_slprop", "Steel.Primitive.ForkJoin.lock_inv_pred", "Steel.Primitive.ForkJoin.__proj__Mkthread__item__r", "Steel.Memory.mem", "Prims.bool", "Steel.Primitive.ForkJoin.join", "Steel.SpinLock.release", "Steel.Primitive.ForkJoin.lock_inv", "Steel.Primitive.ForkJoin.__proj__Mkthread__item__l", "Steel.Effect.Atomic.intro_exists", "Steel.Reference.read_refine_pt", "Steel.FractionalPermission.full_perm", "Steel.Primitive.ForkJoin.maybe_p", "Steel.SpinLock.acquire", "Steel.Effect.Common.emp" ]
[ "recursion" ]
false
true
false
false
false
let rec join (#p: vprop) (t: thread p) : SteelT unit emp (fun _ -> p) =
let _ = L.acquire t.l in let b = read_refine_pt (maybe_p p) t.r in if b then (rewrite_slprop (lock_inv_pred t.r p b) p (fun _ -> ()); noop ()) else (rewrite_slprop (lock_inv_pred t.r p b) (lock_inv_pred t.r p false) (fun _ -> ()); intro_exists false (lock_inv_pred t.r p); L.release t.l; join t)
false
CDDL.Spec.fsti
CDDL.Spec.list_for_all_filter_invariant
val list_for_all_filter_invariant (#t: Type) (p f: (t -> bool)) (l: list t) : Lemma (requires (List.Tot.for_all p l == true)) (ensures (List.Tot.for_all p (List.Tot.filter f l) == true)) [SMTPat (List.Tot.for_all p (List.Tot.filter f l))]
val list_for_all_filter_invariant (#t: Type) (p f: (t -> bool)) (l: list t) : Lemma (requires (List.Tot.for_all p l == true)) (ensures (List.Tot.for_all p (List.Tot.filter f l) == true)) [SMTPat (List.Tot.for_all p (List.Tot.filter f l))]
let rec list_for_all_filter_invariant (#t: Type) (p: t -> bool) (f: t -> bool) (l: list t) : Lemma (requires (List.Tot.for_all p l == true)) (ensures (List.Tot.for_all p (List.Tot.filter f l) == true)) [SMTPat (List.Tot.for_all p (List.Tot.filter f l))] = match l with | [] -> () | _ :: q -> list_for_all_filter_invariant p f q
{ "file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 49, "end_line": 658, "start_col": 0, "start_line": 647 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module CDDL.Spec module Cbor = CBOR.Spec module U8 = FStar.UInt8 module U64 = FStar.UInt64 // Concise Data Definition Language (RFC 8610) noextract let opt_precedes (#t1 #t2: Type) (x1: t1) (x2: option t2) : Tot prop = match x2 with | None -> True | Some x2 -> x1 << x2 [@@noextract_to "krml"] let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization) [@@noextract_to "krml"] let typ = bounded_typ_gen None [@@noextract_to "krml"] let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e) let coerce_to_bounded_typ (b: option Cbor.raw_data_item) (t: typ) : Tot (bounded_typ_gen b) = t noextract let typ_equiv (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : Tot prop = forall x . t1 x == t2 x let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x) let t_choice_equiv #b (t1 t1' t2 t2' : bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2')) (ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2'))) = () // etc. let t_choice_simpl #b (t: bounded_typ_gen b) : Lemma ((t `t_choice` t) `typ_equiv` t) = () let t_always_false : typ = (fun _ -> false) let t_literal (i: Cbor.raw_data_item) : typ = (fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i)) // Appendix D let any : typ = (fun _ -> true) let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64) let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64) let t_int : typ = uint `t_choice` nint let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string) let bytes = bstr let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string) let text = tstr [@@CMacro] let simple_value_false : Cbor.simple_value = 20uy [@@CMacro] let simple_value_true : Cbor.simple_value = 21uy [@@CMacro] let simple_value_nil : Cbor.simple_value = 22uy [@@CMacro] let simple_value_undefined : Cbor.simple_value = 23uy let t_simple_value_literal (s: Cbor.simple_value) : typ = t_literal (Cbor.Simple s) let t_false : typ = t_simple_value_literal simple_value_false let t_true : typ = t_simple_value_literal simple_value_true let t_bool : typ = t_choice t_false t_true let t_nil : typ = t_simple_value_literal simple_value_nil let t_null : typ = t_nil let t_undefined : typ = t_simple_value_literal simple_value_undefined let t_uint_literal (v: U64.t) : typ = t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v) // Section 2.1: Groups // Groups in array context (Section 3.4) // General semantics, which would imply backtracking [@@erasable; noextract_to "krml"] let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool) let array_group1_empty : array_group1 = fun k -> k let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k) let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) = k l || a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more' let array_group1_item (t: typ) : array_group1 = fun k l -> match l with | [] -> false | a :: q -> t a && k q let t_array1 (a: array_group1) : typ = fun x -> Cbor.Array? x && a Nil? (Cbor.Array?.v x) [@@noextract_to "krml"] let nat_up_to (n: nat) : eqtype = (i: nat { i <= n }) [@@noextract_to "krml"] let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l))) [@@noextract_to "krml"] let array_group2_empty : array_group2 = (fun _ i -> [i]) [@@noextract_to "krml"] let array_group2_concat (a1 a2: array_group2) : array_group2 = (fun l i1 -> let res1 = a1 l i1 in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1 ) [@@noextract_to "krml"] let array_group2_choice (a1 a2: array_group2) : array_group2 = fun l i -> a1 l i `List.Tot.append` a2 l i [@@noextract_to "krml"] let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) = i :: begin let r1 = a l i in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> if i2 <= i then [] else array_group2_zero_or_more' a l i2 ) r1 end (* [@@noextract_to "krml"] let array_group2_item (t: typ) : array_group2 = fun l i -> if i = Seq.length l then [] else if t (Seq.index l i) then [i + 1] else [] *) [@@noextract_to "krml"] let t_array2 (a: array_group2) : typ = fun x -> Cbor.Array? x && begin let l = Cbor.Array?.v x in List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0 end // Greedy semantics (Appendix A?) let list_is_suffix_of (#t: Type) (small large: list t) : Tot prop = exists prefix . large == prefix `List.Tot.append` small let list_is_suffix_of_refl (#t: Type) (l: list t) : Lemma (l `list_is_suffix_of` l) [SMTPat (l `list_is_suffix_of` l)] = assert (l == [] `List.Tot.append` l) let rec list_nil_precedes (#t: Type) (l: list t) : Lemma (Nil #t == l \/ Nil #t << l) = match l with | [] -> () | a :: q -> list_nil_precedes q let rec list_is_suffix_of_precedes (#t0 #t: Type) (v0: t0) (small large: list t) : Lemma (requires ( large << v0 /\ small `list_is_suffix_of` large )) (ensures ( small << v0 )) (decreases (List.Tot.length large)) [SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]] = if Nil? small then list_nil_precedes large else begin let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in List.Tot.append_length prefix small; if List.Tot.length small = List.Tot.length large then () else list_is_suffix_of_precedes v0 small (List.Tot.tl large) end [@@erasable; noextract_to "krml"] let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with | None -> True | Some l' -> opt_precedes l' bound )) noextract let array_group3_equiv #b (g1 g2: array_group3 b) : Tot prop = forall l . g1 l == g2 l let array_group3_always_false #b : array_group3 b = fun _ -> None let array_group3_empty #b : array_group3 b = fun x -> Some x let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b = (fun l -> match a1 l with | None -> None | Some l3 -> a3 l3 ) let array_group3_concat_equiv #b (a1 a1' a2 a2' : array_group3 b) : Lemma (requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2'))) (ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2'))) = () let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b = fun l -> match a1 l with | None -> a3 l | Some l3 -> Some l3 let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b)) (decreases (List.Tot.length l)) = match a l with | None -> Some l | Some l' -> if List.Tot.length l' >= List.Tot.length l then Some l else array_group3_zero_or_more' a l' let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more' let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b = a `array_group3_concat` array_group3_zero_or_more a let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) = a `array_group3_choice` array_group3_empty let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l -> match l with | [] -> None | a :: q -> if t a then Some q else None let array_group3_item_equiv #b (t1 t2: bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t2)) (ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2)) = () let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b) (l: list Cbor.raw_data_item {opt_precedes l b}) : GTot bool = match a l with | Some l' -> Nil? l' | _ -> false let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x -> Cbor.Array? x && match_array_group3 a (Cbor.Array?.v x) let t_array3_equiv #b (a1 a2: array_group3 b) : Lemma (requires (array_group3_equiv a1 a2)) (ensures (typ_equiv (t_array3 a1) (t_array3 a2))) = () // Recursive type (needed by COSE Section 5.1 "Recipient") // Inspiring from Barthe et al., Type-Based Termination with Sized // Products (CSL 2008): we allow recursion only at the level of // destructors. In other words, instead of having a generic recursion // combinator, we provide a recursion-enabled version only for each // destructor combinator. We need to annotate it with a bound b (akin // to the "size" annotation in a sized type.) let rec t_array3_rec (phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b))) (x: Cbor.raw_data_item) : GTot bool (decreases x) = Cbor.Array? x && match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x) // Groups in map context (Section 3.5) [@@erasable] noeq type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b module Pull = FStar.Ghost.Pull noextract let opt_map_entry_bounded' (b: option Cbor.raw_data_item) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) : GTot bool = FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b) let opt_map_entry_bounded (b: option Cbor.raw_data_item) : GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool) = Pull.pull (opt_map_entry_bounded' b) let rec opt_precedes_map_for_all_opt_map_entry_bounded (b: option Cbor.raw_data_item) (l: list (Cbor.raw_data_item & Cbor.raw_data_item)) : Lemma (requires (opt_precedes l b)) (ensures (List.Tot.for_all (opt_map_entry_bounded b) l)) [SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)] = match l with | [] -> () | _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q let matches_map_group_entry (#b: option Cbor.raw_data_item) (ge: map_group_entry b) (x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true }) : GTot bool = ge.fst (fst x) && ge.snd (snd x) [@@erasable] noeq type map_group (b: option Cbor.raw_data_item) = { one: list (map_group_entry b); zero_or_one: list (map_group_entry b); zero_or_more: list (map_group_entry b); } let map_group_empty #b : map_group b = { one = []; zero_or_one = []; zero_or_more = []; } let cut_map_group_entry_key #b (key: bounded_typ_gen b) (t: bounded_typ_gen b) (x: Cbor.raw_data_item { opt_precedes x b }) : GTot bool = t x && not (key x) // Section 3.5.4: Cut let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b = cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = { one = List.Tot.map (cut_map_group_entry key) g.one; zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one; zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more; } let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = if cut then cut_map_group (ge.fst) g else g let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with one = ge :: g.one; } let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_one = ge :: g.zero_or_one; } let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_more = ge :: g.zero_or_more; } val matches_map_group (#b: option Cbor.raw_data_item) (m: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x }) : GTot bool val matches_map_group_empty (b: option Cbor.raw_data_item) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (ensures (matches_map_group (map_group_empty #b) x == Nil? x)) [SMTPat (matches_map_group (map_group_empty #b) x)] (* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *) noextract let is_sub_map_group_of #b (small large: map_group b) : Tot prop = forall x . matches_map_group small x ==> matches_map_group large x noextract let map_group_equiv #b (mg1 mg2: map_group b) : Tot prop = forall x . matches_map_group mg1 x == matches_map_group mg2 x noextract let is_sub_typ_of #b (small large: bounded_typ_gen b) : Tot prop = forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x noextract let is_sub_map_group_entry_of #b (small large: map_group_entry b) : Tot prop = small.fst `is_sub_typ_of` large.fst /\ small.snd `is_sub_typ_of` large.snd let map_group_ignore_restricted_entries #b (mg: map_group b) : Tot (map_group b) = {mg with one = []; zero_or_one = []; } let pull_rel (#t1 #t2: Type) (r: t1 -> t2 -> prop) (x1: t1) : GTot ((x2: t2) -> Tot bool) = Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2)) let list_ghost_forall_exists_body (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l2: list t2) : GTot (t1 -> bool) = Pull.pull (fun x1 -> List.Tot.existsb (pull_rel r x1) l2 ) let list_ghost_forall_exists (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l1: list t1) (l2: list t2) : GTot bool = List.Tot.for_all (list_ghost_forall_exists_body r l2) l1 noextract let matches_map_group_entry' (#b: _) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) (y: map_group_entry b) : Tot prop = opt_map_entry_bounded b x ==> matches_map_group_entry y x val matches_map_group_no_restricted (#b: _) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires ( Nil? g.one /\ Nil? g.zero_or_one )) (ensures ( matches_map_group g x <==> list_ghost_forall_exists matches_map_group_entry' x g.zero_or_more )) [SMTPat (matches_map_group g x)] let rec list_ghost_forall2 (#t1 #t2: Type) (f: t1 -> t2 -> GTot prop) (l1: list t1) (l2: list t2) : GTot bool (decreases l1) = match l1, l2 with | [], [] -> true | a1 :: q1, a2 :: q2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (f a1 a2) && list_ghost_forall2 f q1 q2 | _ -> false val list_ghost_forall_exists_is_sub_map_group_entry_of_refl (#b: _) (l: list (map_group_entry b)) : Lemma (ensures (list_ghost_forall_exists is_sub_map_group_entry_of l l)) [SMTPat (list_ghost_forall_exists is_sub_map_group_entry_of l l)] let map_group_included_zero_or_more #b (small large: map_group b) : GTot bool = list_ghost_forall_exists is_sub_map_group_entry_of small.one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_more large.zero_or_more && Nil? large.one val map_group_included_zero_or_more_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_zero_or_more small large)) (ensures (is_sub_map_group_of small large)) val map_group_ignore_restricted_entries_sub (#b: _) (mg: map_group b) : Lemma (requires ( list_ghost_forall_exists is_sub_map_group_entry_of mg.one mg.zero_or_more /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( mg `is_sub_map_group_of` map_group_ignore_restricted_entries mg )) let map_group_ignore_restricted_entries_no_one_equiv #b (mg: map_group b) : Lemma (requires ( Nil? mg.one /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( map_group_equiv mg (map_group_ignore_restricted_entries mg) )) = map_group_ignore_restricted_entries_sub mg; map_group_included_zero_or_more_correct (map_group_ignore_restricted_entries mg) mg let map_group_included_pointwise #b (small large: map_group b) : GTot bool = list_ghost_forall2 is_sub_map_group_entry_of small.one large.one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_one large.zero_or_one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_more large.zero_or_more val map_group_included_pointwise_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_pointwise small large)) (ensures (is_sub_map_group_of small large)) let rec list_ghost_forall2_map_l (#t1 #t2: Type) (r: t1 -> t2 -> prop) (f: t2 -> t1) (l: list t2) : Lemma (requires (forall x . r (f x) x)) (ensures (list_ghost_forall2 r (List.Tot.map f l) l)) = match l with | [] -> () | _ :: q -> list_ghost_forall2_map_l r f q let rec list_ghost_forall2_map_r (#t1 #t2: Type) (r: t1 -> t2 -> prop) (f: t1 -> t2) (l: list t1) : Lemma (requires (forall x . r x (f x))) (ensures (list_ghost_forall2 r l (List.Tot.map f l))) = match l with | [] -> () | _ :: q -> list_ghost_forall2_map_r r f q let cut_map_group_sub #b (key: bounded_typ_gen b) (mg: map_group b) : Lemma (cut_map_group key mg `is_sub_map_group_of` mg) = list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.one; list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_one; list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_more; map_group_included_pointwise_correct (cut_map_group key mg) mg (* Proving matches_map_group for sorted maps and map groups where key constraints specify whole elements *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt.fsti.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.Pull.fsti.checked", "CBOR.Spec.fsti.checked" ], "interface_file": false, "source_file": "CDDL.Spec.fsti" }
[ { "abbrev": true, "full_module": "FStar.Ghost.Pull", "short_module": "Pull" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "CBOR.Spec", "short_module": "Cbor" }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: (_: t -> Prims.bool) -> f: (_: t -> Prims.bool) -> l: Prims.list t -> FStar.Pervasives.Lemma (requires FStar.List.Tot.Base.for_all p l == true) (ensures FStar.List.Tot.Base.for_all p (FStar.List.Tot.Base.filter f l) == true) [SMTPat (FStar.List.Tot.Base.for_all p (FStar.List.Tot.Base.filter f l))]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.bool", "Prims.list", "CDDL.Spec.list_for_all_filter_invariant", "Prims.unit", "Prims.eq2", "FStar.List.Tot.Base.for_all", "Prims.squash", "FStar.List.Tot.Base.filter", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[ "recursion" ]
false
false
true
false
false
let rec list_for_all_filter_invariant (#t: Type) (p f: (t -> bool)) (l: list t) : Lemma (requires (List.Tot.for_all p l == true)) (ensures (List.Tot.for_all p (List.Tot.filter f l) == true)) [SMTPat (List.Tot.for_all p (List.Tot.filter f l))] =
match l with | [] -> () | _ :: q -> list_for_all_filter_invariant p f q
false
CDDL.Spec.fsti
CDDL.Spec.cut_map_group_sub
val cut_map_group_sub (#b: _) (key: bounded_typ_gen b) (mg: map_group b) : Lemma ((cut_map_group key mg) `is_sub_map_group_of` mg)
val cut_map_group_sub (#b: _) (key: bounded_typ_gen b) (mg: map_group b) : Lemma ((cut_map_group key mg) `is_sub_map_group_of` mg)
let cut_map_group_sub #b (key: bounded_typ_gen b) (mg: map_group b) : Lemma (cut_map_group key mg `is_sub_map_group_of` mg) = list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.one; list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_one; list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_more; map_group_included_pointwise_correct (cut_map_group key mg) mg
{ "file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 64, "end_line": 643, "start_col": 0, "start_line": 634 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module CDDL.Spec module Cbor = CBOR.Spec module U8 = FStar.UInt8 module U64 = FStar.UInt64 // Concise Data Definition Language (RFC 8610) noextract let opt_precedes (#t1 #t2: Type) (x1: t1) (x2: option t2) : Tot prop = match x2 with | None -> True | Some x2 -> x1 << x2 [@@noextract_to "krml"] let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization) [@@noextract_to "krml"] let typ = bounded_typ_gen None [@@noextract_to "krml"] let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e) let coerce_to_bounded_typ (b: option Cbor.raw_data_item) (t: typ) : Tot (bounded_typ_gen b) = t noextract let typ_equiv (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : Tot prop = forall x . t1 x == t2 x let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x) let t_choice_equiv #b (t1 t1' t2 t2' : bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2')) (ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2'))) = () // etc. let t_choice_simpl #b (t: bounded_typ_gen b) : Lemma ((t `t_choice` t) `typ_equiv` t) = () let t_always_false : typ = (fun _ -> false) let t_literal (i: Cbor.raw_data_item) : typ = (fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i)) // Appendix D let any : typ = (fun _ -> true) let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64) let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64) let t_int : typ = uint `t_choice` nint let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string) let bytes = bstr let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string) let text = tstr [@@CMacro] let simple_value_false : Cbor.simple_value = 20uy [@@CMacro] let simple_value_true : Cbor.simple_value = 21uy [@@CMacro] let simple_value_nil : Cbor.simple_value = 22uy [@@CMacro] let simple_value_undefined : Cbor.simple_value = 23uy let t_simple_value_literal (s: Cbor.simple_value) : typ = t_literal (Cbor.Simple s) let t_false : typ = t_simple_value_literal simple_value_false let t_true : typ = t_simple_value_literal simple_value_true let t_bool : typ = t_choice t_false t_true let t_nil : typ = t_simple_value_literal simple_value_nil let t_null : typ = t_nil let t_undefined : typ = t_simple_value_literal simple_value_undefined let t_uint_literal (v: U64.t) : typ = t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v) // Section 2.1: Groups // Groups in array context (Section 3.4) // General semantics, which would imply backtracking [@@erasable; noextract_to "krml"] let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool) let array_group1_empty : array_group1 = fun k -> k let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k) let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) = k l || a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more' let array_group1_item (t: typ) : array_group1 = fun k l -> match l with | [] -> false | a :: q -> t a && k q let t_array1 (a: array_group1) : typ = fun x -> Cbor.Array? x && a Nil? (Cbor.Array?.v x) [@@noextract_to "krml"] let nat_up_to (n: nat) : eqtype = (i: nat { i <= n }) [@@noextract_to "krml"] let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l))) [@@noextract_to "krml"] let array_group2_empty : array_group2 = (fun _ i -> [i]) [@@noextract_to "krml"] let array_group2_concat (a1 a2: array_group2) : array_group2 = (fun l i1 -> let res1 = a1 l i1 in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1 ) [@@noextract_to "krml"] let array_group2_choice (a1 a2: array_group2) : array_group2 = fun l i -> a1 l i `List.Tot.append` a2 l i [@@noextract_to "krml"] let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) = i :: begin let r1 = a l i in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> if i2 <= i then [] else array_group2_zero_or_more' a l i2 ) r1 end (* [@@noextract_to "krml"] let array_group2_item (t: typ) : array_group2 = fun l i -> if i = Seq.length l then [] else if t (Seq.index l i) then [i + 1] else [] *) [@@noextract_to "krml"] let t_array2 (a: array_group2) : typ = fun x -> Cbor.Array? x && begin let l = Cbor.Array?.v x in List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0 end // Greedy semantics (Appendix A?) let list_is_suffix_of (#t: Type) (small large: list t) : Tot prop = exists prefix . large == prefix `List.Tot.append` small let list_is_suffix_of_refl (#t: Type) (l: list t) : Lemma (l `list_is_suffix_of` l) [SMTPat (l `list_is_suffix_of` l)] = assert (l == [] `List.Tot.append` l) let rec list_nil_precedes (#t: Type) (l: list t) : Lemma (Nil #t == l \/ Nil #t << l) = match l with | [] -> () | a :: q -> list_nil_precedes q let rec list_is_suffix_of_precedes (#t0 #t: Type) (v0: t0) (small large: list t) : Lemma (requires ( large << v0 /\ small `list_is_suffix_of` large )) (ensures ( small << v0 )) (decreases (List.Tot.length large)) [SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]] = if Nil? small then list_nil_precedes large else begin let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in List.Tot.append_length prefix small; if List.Tot.length small = List.Tot.length large then () else list_is_suffix_of_precedes v0 small (List.Tot.tl large) end [@@erasable; noextract_to "krml"] let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with | None -> True | Some l' -> opt_precedes l' bound )) noextract let array_group3_equiv #b (g1 g2: array_group3 b) : Tot prop = forall l . g1 l == g2 l let array_group3_always_false #b : array_group3 b = fun _ -> None let array_group3_empty #b : array_group3 b = fun x -> Some x let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b = (fun l -> match a1 l with | None -> None | Some l3 -> a3 l3 ) let array_group3_concat_equiv #b (a1 a1' a2 a2' : array_group3 b) : Lemma (requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2'))) (ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2'))) = () let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b = fun l -> match a1 l with | None -> a3 l | Some l3 -> Some l3 let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b)) (decreases (List.Tot.length l)) = match a l with | None -> Some l | Some l' -> if List.Tot.length l' >= List.Tot.length l then Some l else array_group3_zero_or_more' a l' let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more' let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b = a `array_group3_concat` array_group3_zero_or_more a let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) = a `array_group3_choice` array_group3_empty let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l -> match l with | [] -> None | a :: q -> if t a then Some q else None let array_group3_item_equiv #b (t1 t2: bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t2)) (ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2)) = () let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b) (l: list Cbor.raw_data_item {opt_precedes l b}) : GTot bool = match a l with | Some l' -> Nil? l' | _ -> false let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x -> Cbor.Array? x && match_array_group3 a (Cbor.Array?.v x) let t_array3_equiv #b (a1 a2: array_group3 b) : Lemma (requires (array_group3_equiv a1 a2)) (ensures (typ_equiv (t_array3 a1) (t_array3 a2))) = () // Recursive type (needed by COSE Section 5.1 "Recipient") // Inspiring from Barthe et al., Type-Based Termination with Sized // Products (CSL 2008): we allow recursion only at the level of // destructors. In other words, instead of having a generic recursion // combinator, we provide a recursion-enabled version only for each // destructor combinator. We need to annotate it with a bound b (akin // to the "size" annotation in a sized type.) let rec t_array3_rec (phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b))) (x: Cbor.raw_data_item) : GTot bool (decreases x) = Cbor.Array? x && match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x) // Groups in map context (Section 3.5) [@@erasable] noeq type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b module Pull = FStar.Ghost.Pull noextract let opt_map_entry_bounded' (b: option Cbor.raw_data_item) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) : GTot bool = FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b) let opt_map_entry_bounded (b: option Cbor.raw_data_item) : GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool) = Pull.pull (opt_map_entry_bounded' b) let rec opt_precedes_map_for_all_opt_map_entry_bounded (b: option Cbor.raw_data_item) (l: list (Cbor.raw_data_item & Cbor.raw_data_item)) : Lemma (requires (opt_precedes l b)) (ensures (List.Tot.for_all (opt_map_entry_bounded b) l)) [SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)] = match l with | [] -> () | _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q let matches_map_group_entry (#b: option Cbor.raw_data_item) (ge: map_group_entry b) (x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true }) : GTot bool = ge.fst (fst x) && ge.snd (snd x) [@@erasable] noeq type map_group (b: option Cbor.raw_data_item) = { one: list (map_group_entry b); zero_or_one: list (map_group_entry b); zero_or_more: list (map_group_entry b); } let map_group_empty #b : map_group b = { one = []; zero_or_one = []; zero_or_more = []; } let cut_map_group_entry_key #b (key: bounded_typ_gen b) (t: bounded_typ_gen b) (x: Cbor.raw_data_item { opt_precedes x b }) : GTot bool = t x && not (key x) // Section 3.5.4: Cut let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b = cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = { one = List.Tot.map (cut_map_group_entry key) g.one; zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one; zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more; } let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = if cut then cut_map_group (ge.fst) g else g let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with one = ge :: g.one; } let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_one = ge :: g.zero_or_one; } let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_more = ge :: g.zero_or_more; } val matches_map_group (#b: option Cbor.raw_data_item) (m: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x }) : GTot bool val matches_map_group_empty (b: option Cbor.raw_data_item) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (ensures (matches_map_group (map_group_empty #b) x == Nil? x)) [SMTPat (matches_map_group (map_group_empty #b) x)] (* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *) noextract let is_sub_map_group_of #b (small large: map_group b) : Tot prop = forall x . matches_map_group small x ==> matches_map_group large x noextract let map_group_equiv #b (mg1 mg2: map_group b) : Tot prop = forall x . matches_map_group mg1 x == matches_map_group mg2 x noextract let is_sub_typ_of #b (small large: bounded_typ_gen b) : Tot prop = forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x noextract let is_sub_map_group_entry_of #b (small large: map_group_entry b) : Tot prop = small.fst `is_sub_typ_of` large.fst /\ small.snd `is_sub_typ_of` large.snd let map_group_ignore_restricted_entries #b (mg: map_group b) : Tot (map_group b) = {mg with one = []; zero_or_one = []; } let pull_rel (#t1 #t2: Type) (r: t1 -> t2 -> prop) (x1: t1) : GTot ((x2: t2) -> Tot bool) = Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2)) let list_ghost_forall_exists_body (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l2: list t2) : GTot (t1 -> bool) = Pull.pull (fun x1 -> List.Tot.existsb (pull_rel r x1) l2 ) let list_ghost_forall_exists (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l1: list t1) (l2: list t2) : GTot bool = List.Tot.for_all (list_ghost_forall_exists_body r l2) l1 noextract let matches_map_group_entry' (#b: _) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) (y: map_group_entry b) : Tot prop = opt_map_entry_bounded b x ==> matches_map_group_entry y x val matches_map_group_no_restricted (#b: _) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires ( Nil? g.one /\ Nil? g.zero_or_one )) (ensures ( matches_map_group g x <==> list_ghost_forall_exists matches_map_group_entry' x g.zero_or_more )) [SMTPat (matches_map_group g x)] let rec list_ghost_forall2 (#t1 #t2: Type) (f: t1 -> t2 -> GTot prop) (l1: list t1) (l2: list t2) : GTot bool (decreases l1) = match l1, l2 with | [], [] -> true | a1 :: q1, a2 :: q2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (f a1 a2) && list_ghost_forall2 f q1 q2 | _ -> false val list_ghost_forall_exists_is_sub_map_group_entry_of_refl (#b: _) (l: list (map_group_entry b)) : Lemma (ensures (list_ghost_forall_exists is_sub_map_group_entry_of l l)) [SMTPat (list_ghost_forall_exists is_sub_map_group_entry_of l l)] let map_group_included_zero_or_more #b (small large: map_group b) : GTot bool = list_ghost_forall_exists is_sub_map_group_entry_of small.one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_more large.zero_or_more && Nil? large.one val map_group_included_zero_or_more_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_zero_or_more small large)) (ensures (is_sub_map_group_of small large)) val map_group_ignore_restricted_entries_sub (#b: _) (mg: map_group b) : Lemma (requires ( list_ghost_forall_exists is_sub_map_group_entry_of mg.one mg.zero_or_more /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( mg `is_sub_map_group_of` map_group_ignore_restricted_entries mg )) let map_group_ignore_restricted_entries_no_one_equiv #b (mg: map_group b) : Lemma (requires ( Nil? mg.one /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( map_group_equiv mg (map_group_ignore_restricted_entries mg) )) = map_group_ignore_restricted_entries_sub mg; map_group_included_zero_or_more_correct (map_group_ignore_restricted_entries mg) mg let map_group_included_pointwise #b (small large: map_group b) : GTot bool = list_ghost_forall2 is_sub_map_group_entry_of small.one large.one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_one large.zero_or_one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_more large.zero_or_more val map_group_included_pointwise_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_pointwise small large)) (ensures (is_sub_map_group_of small large)) let rec list_ghost_forall2_map_l (#t1 #t2: Type) (r: t1 -> t2 -> prop) (f: t2 -> t1) (l: list t2) : Lemma (requires (forall x . r (f x) x)) (ensures (list_ghost_forall2 r (List.Tot.map f l) l)) = match l with | [] -> () | _ :: q -> list_ghost_forall2_map_l r f q let rec list_ghost_forall2_map_r (#t1 #t2: Type) (r: t1 -> t2 -> prop) (f: t1 -> t2) (l: list t1) : Lemma (requires (forall x . r x (f x))) (ensures (list_ghost_forall2 r l (List.Tot.map f l))) = match l with | [] -> () | _ :: q -> list_ghost_forall2_map_r r f q
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt.fsti.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.Pull.fsti.checked", "CBOR.Spec.fsti.checked" ], "interface_file": false, "source_file": "CDDL.Spec.fsti" }
[ { "abbrev": true, "full_module": "FStar.Ghost.Pull", "short_module": "Pull" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "CBOR.Spec", "short_module": "Cbor" }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
key: CDDL.Spec.bounded_typ_gen b -> mg: CDDL.Spec.map_group b -> FStar.Pervasives.Lemma (ensures CDDL.Spec.is_sub_map_group_of (CDDL.Spec.cut_map_group key mg) mg)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Pervasives.Native.option", "CBOR.Spec.Type.raw_data_item", "CDDL.Spec.bounded_typ_gen", "CDDL.Spec.map_group", "CDDL.Spec.map_group_included_pointwise_correct", "CDDL.Spec.cut_map_group", "Prims.unit", "CDDL.Spec.list_ghost_forall2_map_l", "CDDL.Spec.map_group_entry", "CDDL.Spec.is_sub_map_group_entry_of", "CDDL.Spec.cut_map_group_entry", "CDDL.Spec.__proj__Mkmap_group__item__zero_or_more", "CDDL.Spec.__proj__Mkmap_group__item__zero_or_one", "CDDL.Spec.__proj__Mkmap_group__item__one", "Prims.l_True", "Prims.squash", "CDDL.Spec.is_sub_map_group_of", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let cut_map_group_sub #b (key: bounded_typ_gen b) (mg: map_group b) : Lemma ((cut_map_group key mg) `is_sub_map_group_of` mg) =
list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.one; list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_one; list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_more; map_group_included_pointwise_correct (cut_map_group key mg) mg
false
CDDL.Spec.fsti
CDDL.Spec.list_ghost_forall2_map_l
val list_ghost_forall2_map_l (#t1 #t2: Type) (r: (t1 -> t2 -> prop)) (f: (t2 -> t1)) (l: list t2) : Lemma (requires (forall x. r (f x) x)) (ensures (list_ghost_forall2 r (List.Tot.map f l) l))
val list_ghost_forall2_map_l (#t1 #t2: Type) (r: (t1 -> t2 -> prop)) (f: (t2 -> t1)) (l: list t2) : Lemma (requires (forall x. r (f x) x)) (ensures (list_ghost_forall2 r (List.Tot.map f l) l))
let rec list_ghost_forall2_map_l (#t1 #t2: Type) (r: t1 -> t2 -> prop) (f: t2 -> t1) (l: list t2) : Lemma (requires (forall x . r (f x) x)) (ensures (list_ghost_forall2 r (List.Tot.map f l) l)) = match l with | [] -> () | _ :: q -> list_ghost_forall2_map_l r f q
{ "file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 44, "end_line": 620, "start_col": 0, "start_line": 610 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module CDDL.Spec module Cbor = CBOR.Spec module U8 = FStar.UInt8 module U64 = FStar.UInt64 // Concise Data Definition Language (RFC 8610) noextract let opt_precedes (#t1 #t2: Type) (x1: t1) (x2: option t2) : Tot prop = match x2 with | None -> True | Some x2 -> x1 << x2 [@@noextract_to "krml"] let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization) [@@noextract_to "krml"] let typ = bounded_typ_gen None [@@noextract_to "krml"] let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e) let coerce_to_bounded_typ (b: option Cbor.raw_data_item) (t: typ) : Tot (bounded_typ_gen b) = t noextract let typ_equiv (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : Tot prop = forall x . t1 x == t2 x let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x) let t_choice_equiv #b (t1 t1' t2 t2' : bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2')) (ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2'))) = () // etc. let t_choice_simpl #b (t: bounded_typ_gen b) : Lemma ((t `t_choice` t) `typ_equiv` t) = () let t_always_false : typ = (fun _ -> false) let t_literal (i: Cbor.raw_data_item) : typ = (fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i)) // Appendix D let any : typ = (fun _ -> true) let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64) let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64) let t_int : typ = uint `t_choice` nint let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string) let bytes = bstr let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string) let text = tstr [@@CMacro] let simple_value_false : Cbor.simple_value = 20uy [@@CMacro] let simple_value_true : Cbor.simple_value = 21uy [@@CMacro] let simple_value_nil : Cbor.simple_value = 22uy [@@CMacro] let simple_value_undefined : Cbor.simple_value = 23uy let t_simple_value_literal (s: Cbor.simple_value) : typ = t_literal (Cbor.Simple s) let t_false : typ = t_simple_value_literal simple_value_false let t_true : typ = t_simple_value_literal simple_value_true let t_bool : typ = t_choice t_false t_true let t_nil : typ = t_simple_value_literal simple_value_nil let t_null : typ = t_nil let t_undefined : typ = t_simple_value_literal simple_value_undefined let t_uint_literal (v: U64.t) : typ = t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v) // Section 2.1: Groups // Groups in array context (Section 3.4) // General semantics, which would imply backtracking [@@erasable; noextract_to "krml"] let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool) let array_group1_empty : array_group1 = fun k -> k let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k) let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) = k l || a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more' let array_group1_item (t: typ) : array_group1 = fun k l -> match l with | [] -> false | a :: q -> t a && k q let t_array1 (a: array_group1) : typ = fun x -> Cbor.Array? x && a Nil? (Cbor.Array?.v x) [@@noextract_to "krml"] let nat_up_to (n: nat) : eqtype = (i: nat { i <= n }) [@@noextract_to "krml"] let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l))) [@@noextract_to "krml"] let array_group2_empty : array_group2 = (fun _ i -> [i]) [@@noextract_to "krml"] let array_group2_concat (a1 a2: array_group2) : array_group2 = (fun l i1 -> let res1 = a1 l i1 in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1 ) [@@noextract_to "krml"] let array_group2_choice (a1 a2: array_group2) : array_group2 = fun l i -> a1 l i `List.Tot.append` a2 l i [@@noextract_to "krml"] let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) = i :: begin let r1 = a l i in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> if i2 <= i then [] else array_group2_zero_or_more' a l i2 ) r1 end (* [@@noextract_to "krml"] let array_group2_item (t: typ) : array_group2 = fun l i -> if i = Seq.length l then [] else if t (Seq.index l i) then [i + 1] else [] *) [@@noextract_to "krml"] let t_array2 (a: array_group2) : typ = fun x -> Cbor.Array? x && begin let l = Cbor.Array?.v x in List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0 end // Greedy semantics (Appendix A?) let list_is_suffix_of (#t: Type) (small large: list t) : Tot prop = exists prefix . large == prefix `List.Tot.append` small let list_is_suffix_of_refl (#t: Type) (l: list t) : Lemma (l `list_is_suffix_of` l) [SMTPat (l `list_is_suffix_of` l)] = assert (l == [] `List.Tot.append` l) let rec list_nil_precedes (#t: Type) (l: list t) : Lemma (Nil #t == l \/ Nil #t << l) = match l with | [] -> () | a :: q -> list_nil_precedes q let rec list_is_suffix_of_precedes (#t0 #t: Type) (v0: t0) (small large: list t) : Lemma (requires ( large << v0 /\ small `list_is_suffix_of` large )) (ensures ( small << v0 )) (decreases (List.Tot.length large)) [SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]] = if Nil? small then list_nil_precedes large else begin let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in List.Tot.append_length prefix small; if List.Tot.length small = List.Tot.length large then () else list_is_suffix_of_precedes v0 small (List.Tot.tl large) end [@@erasable; noextract_to "krml"] let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with | None -> True | Some l' -> opt_precedes l' bound )) noextract let array_group3_equiv #b (g1 g2: array_group3 b) : Tot prop = forall l . g1 l == g2 l let array_group3_always_false #b : array_group3 b = fun _ -> None let array_group3_empty #b : array_group3 b = fun x -> Some x let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b = (fun l -> match a1 l with | None -> None | Some l3 -> a3 l3 ) let array_group3_concat_equiv #b (a1 a1' a2 a2' : array_group3 b) : Lemma (requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2'))) (ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2'))) = () let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b = fun l -> match a1 l with | None -> a3 l | Some l3 -> Some l3 let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b)) (decreases (List.Tot.length l)) = match a l with | None -> Some l | Some l' -> if List.Tot.length l' >= List.Tot.length l then Some l else array_group3_zero_or_more' a l' let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more' let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b = a `array_group3_concat` array_group3_zero_or_more a let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) = a `array_group3_choice` array_group3_empty let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l -> match l with | [] -> None | a :: q -> if t a then Some q else None let array_group3_item_equiv #b (t1 t2: bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t2)) (ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2)) = () let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b) (l: list Cbor.raw_data_item {opt_precedes l b}) : GTot bool = match a l with | Some l' -> Nil? l' | _ -> false let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x -> Cbor.Array? x && match_array_group3 a (Cbor.Array?.v x) let t_array3_equiv #b (a1 a2: array_group3 b) : Lemma (requires (array_group3_equiv a1 a2)) (ensures (typ_equiv (t_array3 a1) (t_array3 a2))) = () // Recursive type (needed by COSE Section 5.1 "Recipient") // Inspiring from Barthe et al., Type-Based Termination with Sized // Products (CSL 2008): we allow recursion only at the level of // destructors. In other words, instead of having a generic recursion // combinator, we provide a recursion-enabled version only for each // destructor combinator. We need to annotate it with a bound b (akin // to the "size" annotation in a sized type.) let rec t_array3_rec (phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b))) (x: Cbor.raw_data_item) : GTot bool (decreases x) = Cbor.Array? x && match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x) // Groups in map context (Section 3.5) [@@erasable] noeq type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b module Pull = FStar.Ghost.Pull noextract let opt_map_entry_bounded' (b: option Cbor.raw_data_item) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) : GTot bool = FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b) let opt_map_entry_bounded (b: option Cbor.raw_data_item) : GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool) = Pull.pull (opt_map_entry_bounded' b) let rec opt_precedes_map_for_all_opt_map_entry_bounded (b: option Cbor.raw_data_item) (l: list (Cbor.raw_data_item & Cbor.raw_data_item)) : Lemma (requires (opt_precedes l b)) (ensures (List.Tot.for_all (opt_map_entry_bounded b) l)) [SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)] = match l with | [] -> () | _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q let matches_map_group_entry (#b: option Cbor.raw_data_item) (ge: map_group_entry b) (x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true }) : GTot bool = ge.fst (fst x) && ge.snd (snd x) [@@erasable] noeq type map_group (b: option Cbor.raw_data_item) = { one: list (map_group_entry b); zero_or_one: list (map_group_entry b); zero_or_more: list (map_group_entry b); } let map_group_empty #b : map_group b = { one = []; zero_or_one = []; zero_or_more = []; } let cut_map_group_entry_key #b (key: bounded_typ_gen b) (t: bounded_typ_gen b) (x: Cbor.raw_data_item { opt_precedes x b }) : GTot bool = t x && not (key x) // Section 3.5.4: Cut let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b = cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = { one = List.Tot.map (cut_map_group_entry key) g.one; zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one; zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more; } let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = if cut then cut_map_group (ge.fst) g else g let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with one = ge :: g.one; } let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_one = ge :: g.zero_or_one; } let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_more = ge :: g.zero_or_more; } val matches_map_group (#b: option Cbor.raw_data_item) (m: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x }) : GTot bool val matches_map_group_empty (b: option Cbor.raw_data_item) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (ensures (matches_map_group (map_group_empty #b) x == Nil? x)) [SMTPat (matches_map_group (map_group_empty #b) x)] (* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *) noextract let is_sub_map_group_of #b (small large: map_group b) : Tot prop = forall x . matches_map_group small x ==> matches_map_group large x noextract let map_group_equiv #b (mg1 mg2: map_group b) : Tot prop = forall x . matches_map_group mg1 x == matches_map_group mg2 x noextract let is_sub_typ_of #b (small large: bounded_typ_gen b) : Tot prop = forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x noextract let is_sub_map_group_entry_of #b (small large: map_group_entry b) : Tot prop = small.fst `is_sub_typ_of` large.fst /\ small.snd `is_sub_typ_of` large.snd let map_group_ignore_restricted_entries #b (mg: map_group b) : Tot (map_group b) = {mg with one = []; zero_or_one = []; } let pull_rel (#t1 #t2: Type) (r: t1 -> t2 -> prop) (x1: t1) : GTot ((x2: t2) -> Tot bool) = Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2)) let list_ghost_forall_exists_body (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l2: list t2) : GTot (t1 -> bool) = Pull.pull (fun x1 -> List.Tot.existsb (pull_rel r x1) l2 ) let list_ghost_forall_exists (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l1: list t1) (l2: list t2) : GTot bool = List.Tot.for_all (list_ghost_forall_exists_body r l2) l1 noextract let matches_map_group_entry' (#b: _) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) (y: map_group_entry b) : Tot prop = opt_map_entry_bounded b x ==> matches_map_group_entry y x val matches_map_group_no_restricted (#b: _) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires ( Nil? g.one /\ Nil? g.zero_or_one )) (ensures ( matches_map_group g x <==> list_ghost_forall_exists matches_map_group_entry' x g.zero_or_more )) [SMTPat (matches_map_group g x)] let rec list_ghost_forall2 (#t1 #t2: Type) (f: t1 -> t2 -> GTot prop) (l1: list t1) (l2: list t2) : GTot bool (decreases l1) = match l1, l2 with | [], [] -> true | a1 :: q1, a2 :: q2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (f a1 a2) && list_ghost_forall2 f q1 q2 | _ -> false val list_ghost_forall_exists_is_sub_map_group_entry_of_refl (#b: _) (l: list (map_group_entry b)) : Lemma (ensures (list_ghost_forall_exists is_sub_map_group_entry_of l l)) [SMTPat (list_ghost_forall_exists is_sub_map_group_entry_of l l)] let map_group_included_zero_or_more #b (small large: map_group b) : GTot bool = list_ghost_forall_exists is_sub_map_group_entry_of small.one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_more large.zero_or_more && Nil? large.one val map_group_included_zero_or_more_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_zero_or_more small large)) (ensures (is_sub_map_group_of small large)) val map_group_ignore_restricted_entries_sub (#b: _) (mg: map_group b) : Lemma (requires ( list_ghost_forall_exists is_sub_map_group_entry_of mg.one mg.zero_or_more /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( mg `is_sub_map_group_of` map_group_ignore_restricted_entries mg )) let map_group_ignore_restricted_entries_no_one_equiv #b (mg: map_group b) : Lemma (requires ( Nil? mg.one /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( map_group_equiv mg (map_group_ignore_restricted_entries mg) )) = map_group_ignore_restricted_entries_sub mg; map_group_included_zero_or_more_correct (map_group_ignore_restricted_entries mg) mg let map_group_included_pointwise #b (small large: map_group b) : GTot bool = list_ghost_forall2 is_sub_map_group_entry_of small.one large.one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_one large.zero_or_one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_more large.zero_or_more val map_group_included_pointwise_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_pointwise small large)) (ensures (is_sub_map_group_of small large))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt.fsti.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.Pull.fsti.checked", "CBOR.Spec.fsti.checked" ], "interface_file": false, "source_file": "CDDL.Spec.fsti" }
[ { "abbrev": true, "full_module": "FStar.Ghost.Pull", "short_module": "Pull" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "CBOR.Spec", "short_module": "Cbor" }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: (_: t1 -> _: t2 -> Prims.prop) -> f: (_: t2 -> t1) -> l: Prims.list t2 -> FStar.Pervasives.Lemma (requires forall (x: t2). r (f x) x) (ensures CDDL.Spec.list_ghost_forall2 r (FStar.List.Tot.Base.map f l) l)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.prop", "Prims.list", "CDDL.Spec.list_ghost_forall2_map_l", "Prims.unit", "Prims.l_Forall", "Prims.squash", "Prims.b2t", "CDDL.Spec.list_ghost_forall2", "FStar.List.Tot.Base.map", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec list_ghost_forall2_map_l (#t1 #t2: Type) (r: (t1 -> t2 -> prop)) (f: (t2 -> t1)) (l: list t2) : Lemma (requires (forall x. r (f x) x)) (ensures (list_ghost_forall2 r (List.Tot.map f l) l)) =
match l with | [] -> () | _ :: q -> list_ghost_forall2_map_l r f q
false
CDDL.Spec.fsti
CDDL.Spec.t_map_rec
val t_map_rec (phi: (b: Cbor.raw_data_item -> (bounded_typ b -> map_group (Some b)))) (x: Cbor.raw_data_item) : GTot bool (decreases x)
val t_map_rec (phi: (b: Cbor.raw_data_item -> (bounded_typ b -> map_group (Some b)))) (x: Cbor.raw_data_item) : GTot bool (decreases x)
let rec t_map_rec (phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> map_group (Some b))) (x: Cbor.raw_data_item) : GTot bool (decreases x) = Cbor.Map? x && matches_map_group (phi x (t_map_rec phi)) (Cbor.Map?.v x)
{ "file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 59, "end_line": 804, "start_col": 0, "start_line": 798 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module CDDL.Spec module Cbor = CBOR.Spec module U8 = FStar.UInt8 module U64 = FStar.UInt64 // Concise Data Definition Language (RFC 8610) noextract let opt_precedes (#t1 #t2: Type) (x1: t1) (x2: option t2) : Tot prop = match x2 with | None -> True | Some x2 -> x1 << x2 [@@noextract_to "krml"] let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization) [@@noextract_to "krml"] let typ = bounded_typ_gen None [@@noextract_to "krml"] let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e) let coerce_to_bounded_typ (b: option Cbor.raw_data_item) (t: typ) : Tot (bounded_typ_gen b) = t noextract let typ_equiv (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : Tot prop = forall x . t1 x == t2 x let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x) let t_choice_equiv #b (t1 t1' t2 t2' : bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2')) (ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2'))) = () // etc. let t_choice_simpl #b (t: bounded_typ_gen b) : Lemma ((t `t_choice` t) `typ_equiv` t) = () let t_always_false : typ = (fun _ -> false) let t_literal (i: Cbor.raw_data_item) : typ = (fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i)) // Appendix D let any : typ = (fun _ -> true) let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64) let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64) let t_int : typ = uint `t_choice` nint let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string) let bytes = bstr let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string) let text = tstr [@@CMacro] let simple_value_false : Cbor.simple_value = 20uy [@@CMacro] let simple_value_true : Cbor.simple_value = 21uy [@@CMacro] let simple_value_nil : Cbor.simple_value = 22uy [@@CMacro] let simple_value_undefined : Cbor.simple_value = 23uy let t_simple_value_literal (s: Cbor.simple_value) : typ = t_literal (Cbor.Simple s) let t_false : typ = t_simple_value_literal simple_value_false let t_true : typ = t_simple_value_literal simple_value_true let t_bool : typ = t_choice t_false t_true let t_nil : typ = t_simple_value_literal simple_value_nil let t_null : typ = t_nil let t_undefined : typ = t_simple_value_literal simple_value_undefined let t_uint_literal (v: U64.t) : typ = t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v) // Section 2.1: Groups // Groups in array context (Section 3.4) // General semantics, which would imply backtracking [@@erasable; noextract_to "krml"] let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool) let array_group1_empty : array_group1 = fun k -> k let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k) let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) = k l || a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more' let array_group1_item (t: typ) : array_group1 = fun k l -> match l with | [] -> false | a :: q -> t a && k q let t_array1 (a: array_group1) : typ = fun x -> Cbor.Array? x && a Nil? (Cbor.Array?.v x) [@@noextract_to "krml"] let nat_up_to (n: nat) : eqtype = (i: nat { i <= n }) [@@noextract_to "krml"] let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l))) [@@noextract_to "krml"] let array_group2_empty : array_group2 = (fun _ i -> [i]) [@@noextract_to "krml"] let array_group2_concat (a1 a2: array_group2) : array_group2 = (fun l i1 -> let res1 = a1 l i1 in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1 ) [@@noextract_to "krml"] let array_group2_choice (a1 a2: array_group2) : array_group2 = fun l i -> a1 l i `List.Tot.append` a2 l i [@@noextract_to "krml"] let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) = i :: begin let r1 = a l i in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> if i2 <= i then [] else array_group2_zero_or_more' a l i2 ) r1 end (* [@@noextract_to "krml"] let array_group2_item (t: typ) : array_group2 = fun l i -> if i = Seq.length l then [] else if t (Seq.index l i) then [i + 1] else [] *) [@@noextract_to "krml"] let t_array2 (a: array_group2) : typ = fun x -> Cbor.Array? x && begin let l = Cbor.Array?.v x in List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0 end // Greedy semantics (Appendix A?) let list_is_suffix_of (#t: Type) (small large: list t) : Tot prop = exists prefix . large == prefix `List.Tot.append` small let list_is_suffix_of_refl (#t: Type) (l: list t) : Lemma (l `list_is_suffix_of` l) [SMTPat (l `list_is_suffix_of` l)] = assert (l == [] `List.Tot.append` l) let rec list_nil_precedes (#t: Type) (l: list t) : Lemma (Nil #t == l \/ Nil #t << l) = match l with | [] -> () | a :: q -> list_nil_precedes q let rec list_is_suffix_of_precedes (#t0 #t: Type) (v0: t0) (small large: list t) : Lemma (requires ( large << v0 /\ small `list_is_suffix_of` large )) (ensures ( small << v0 )) (decreases (List.Tot.length large)) [SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]] = if Nil? small then list_nil_precedes large else begin let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in List.Tot.append_length prefix small; if List.Tot.length small = List.Tot.length large then () else list_is_suffix_of_precedes v0 small (List.Tot.tl large) end [@@erasable; noextract_to "krml"] let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with | None -> True | Some l' -> opt_precedes l' bound )) noextract let array_group3_equiv #b (g1 g2: array_group3 b) : Tot prop = forall l . g1 l == g2 l let array_group3_always_false #b : array_group3 b = fun _ -> None let array_group3_empty #b : array_group3 b = fun x -> Some x let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b = (fun l -> match a1 l with | None -> None | Some l3 -> a3 l3 ) let array_group3_concat_equiv #b (a1 a1' a2 a2' : array_group3 b) : Lemma (requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2'))) (ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2'))) = () let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b = fun l -> match a1 l with | None -> a3 l | Some l3 -> Some l3 let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b)) (decreases (List.Tot.length l)) = match a l with | None -> Some l | Some l' -> if List.Tot.length l' >= List.Tot.length l then Some l else array_group3_zero_or_more' a l' let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more' let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b = a `array_group3_concat` array_group3_zero_or_more a let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) = a `array_group3_choice` array_group3_empty let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l -> match l with | [] -> None | a :: q -> if t a then Some q else None let array_group3_item_equiv #b (t1 t2: bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t2)) (ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2)) = () let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b) (l: list Cbor.raw_data_item {opt_precedes l b}) : GTot bool = match a l with | Some l' -> Nil? l' | _ -> false let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x -> Cbor.Array? x && match_array_group3 a (Cbor.Array?.v x) let t_array3_equiv #b (a1 a2: array_group3 b) : Lemma (requires (array_group3_equiv a1 a2)) (ensures (typ_equiv (t_array3 a1) (t_array3 a2))) = () // Recursive type (needed by COSE Section 5.1 "Recipient") // Inspiring from Barthe et al., Type-Based Termination with Sized // Products (CSL 2008): we allow recursion only at the level of // destructors. In other words, instead of having a generic recursion // combinator, we provide a recursion-enabled version only for each // destructor combinator. We need to annotate it with a bound b (akin // to the "size" annotation in a sized type.) let rec t_array3_rec (phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b))) (x: Cbor.raw_data_item) : GTot bool (decreases x) = Cbor.Array? x && match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x) // Groups in map context (Section 3.5) [@@erasable] noeq type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b module Pull = FStar.Ghost.Pull noextract let opt_map_entry_bounded' (b: option Cbor.raw_data_item) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) : GTot bool = FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b) let opt_map_entry_bounded (b: option Cbor.raw_data_item) : GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool) = Pull.pull (opt_map_entry_bounded' b) let rec opt_precedes_map_for_all_opt_map_entry_bounded (b: option Cbor.raw_data_item) (l: list (Cbor.raw_data_item & Cbor.raw_data_item)) : Lemma (requires (opt_precedes l b)) (ensures (List.Tot.for_all (opt_map_entry_bounded b) l)) [SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)] = match l with | [] -> () | _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q let matches_map_group_entry (#b: option Cbor.raw_data_item) (ge: map_group_entry b) (x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true }) : GTot bool = ge.fst (fst x) && ge.snd (snd x) [@@erasable] noeq type map_group (b: option Cbor.raw_data_item) = { one: list (map_group_entry b); zero_or_one: list (map_group_entry b); zero_or_more: list (map_group_entry b); } let map_group_empty #b : map_group b = { one = []; zero_or_one = []; zero_or_more = []; } let cut_map_group_entry_key #b (key: bounded_typ_gen b) (t: bounded_typ_gen b) (x: Cbor.raw_data_item { opt_precedes x b }) : GTot bool = t x && not (key x) // Section 3.5.4: Cut let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b = cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = { one = List.Tot.map (cut_map_group_entry key) g.one; zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one; zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more; } let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = if cut then cut_map_group (ge.fst) g else g let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with one = ge :: g.one; } let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_one = ge :: g.zero_or_one; } let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_more = ge :: g.zero_or_more; } val matches_map_group (#b: option Cbor.raw_data_item) (m: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x }) : GTot bool val matches_map_group_empty (b: option Cbor.raw_data_item) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (ensures (matches_map_group (map_group_empty #b) x == Nil? x)) [SMTPat (matches_map_group (map_group_empty #b) x)] (* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *) noextract let is_sub_map_group_of #b (small large: map_group b) : Tot prop = forall x . matches_map_group small x ==> matches_map_group large x noextract let map_group_equiv #b (mg1 mg2: map_group b) : Tot prop = forall x . matches_map_group mg1 x == matches_map_group mg2 x noextract let is_sub_typ_of #b (small large: bounded_typ_gen b) : Tot prop = forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x noextract let is_sub_map_group_entry_of #b (small large: map_group_entry b) : Tot prop = small.fst `is_sub_typ_of` large.fst /\ small.snd `is_sub_typ_of` large.snd let map_group_ignore_restricted_entries #b (mg: map_group b) : Tot (map_group b) = {mg with one = []; zero_or_one = []; } let pull_rel (#t1 #t2: Type) (r: t1 -> t2 -> prop) (x1: t1) : GTot ((x2: t2) -> Tot bool) = Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2)) let list_ghost_forall_exists_body (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l2: list t2) : GTot (t1 -> bool) = Pull.pull (fun x1 -> List.Tot.existsb (pull_rel r x1) l2 ) let list_ghost_forall_exists (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l1: list t1) (l2: list t2) : GTot bool = List.Tot.for_all (list_ghost_forall_exists_body r l2) l1 noextract let matches_map_group_entry' (#b: _) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) (y: map_group_entry b) : Tot prop = opt_map_entry_bounded b x ==> matches_map_group_entry y x val matches_map_group_no_restricted (#b: _) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires ( Nil? g.one /\ Nil? g.zero_or_one )) (ensures ( matches_map_group g x <==> list_ghost_forall_exists matches_map_group_entry' x g.zero_or_more )) [SMTPat (matches_map_group g x)] let rec list_ghost_forall2 (#t1 #t2: Type) (f: t1 -> t2 -> GTot prop) (l1: list t1) (l2: list t2) : GTot bool (decreases l1) = match l1, l2 with | [], [] -> true | a1 :: q1, a2 :: q2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (f a1 a2) && list_ghost_forall2 f q1 q2 | _ -> false val list_ghost_forall_exists_is_sub_map_group_entry_of_refl (#b: _) (l: list (map_group_entry b)) : Lemma (ensures (list_ghost_forall_exists is_sub_map_group_entry_of l l)) [SMTPat (list_ghost_forall_exists is_sub_map_group_entry_of l l)] let map_group_included_zero_or_more #b (small large: map_group b) : GTot bool = list_ghost_forall_exists is_sub_map_group_entry_of small.one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_more large.zero_or_more && Nil? large.one val map_group_included_zero_or_more_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_zero_or_more small large)) (ensures (is_sub_map_group_of small large)) val map_group_ignore_restricted_entries_sub (#b: _) (mg: map_group b) : Lemma (requires ( list_ghost_forall_exists is_sub_map_group_entry_of mg.one mg.zero_or_more /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( mg `is_sub_map_group_of` map_group_ignore_restricted_entries mg )) let map_group_ignore_restricted_entries_no_one_equiv #b (mg: map_group b) : Lemma (requires ( Nil? mg.one /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( map_group_equiv mg (map_group_ignore_restricted_entries mg) )) = map_group_ignore_restricted_entries_sub mg; map_group_included_zero_or_more_correct (map_group_ignore_restricted_entries mg) mg let map_group_included_pointwise #b (small large: map_group b) : GTot bool = list_ghost_forall2 is_sub_map_group_entry_of small.one large.one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_one large.zero_or_one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_more large.zero_or_more val map_group_included_pointwise_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_pointwise small large)) (ensures (is_sub_map_group_of small large)) let rec list_ghost_forall2_map_l (#t1 #t2: Type) (r: t1 -> t2 -> prop) (f: t2 -> t1) (l: list t2) : Lemma (requires (forall x . r (f x) x)) (ensures (list_ghost_forall2 r (List.Tot.map f l) l)) = match l with | [] -> () | _ :: q -> list_ghost_forall2_map_l r f q let rec list_ghost_forall2_map_r (#t1 #t2: Type) (r: t1 -> t2 -> prop) (f: t1 -> t2) (l: list t1) : Lemma (requires (forall x . r x (f x))) (ensures (list_ghost_forall2 r l (List.Tot.map f l))) = match l with | [] -> () | _ :: q -> list_ghost_forall2_map_r r f q let cut_map_group_sub #b (key: bounded_typ_gen b) (mg: map_group b) : Lemma (cut_map_group key mg `is_sub_map_group_of` mg) = list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.one; list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_one; list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_more; map_group_included_pointwise_correct (cut_map_group key mg) mg (* Proving matches_map_group for sorted maps and map groups where key constraints specify whole elements *) let rec list_for_all_filter_invariant (#t: Type) (p: t -> bool) (f: t -> bool) (l: list t) : Lemma (requires (List.Tot.for_all p l == true)) (ensures (List.Tot.for_all p (List.Tot.filter f l) == true)) [SMTPat (List.Tot.for_all p (List.Tot.filter f l))] = match l with | [] -> () | _ :: q -> list_for_all_filter_invariant p f q let map_key_neq' (#t1 t2: Type) (k: t1) (x: (t1 & t2)) : GTot bool = FStar.StrongExcludedMiddle.strong_excluded_middle (~ (fst x == k)) let map_key_neq (#t1 t2: Type) (k: t1) : GTot ((t1 & t2) -> bool) = Pull.pull (map_key_neq' t2 k) let map_group_entry_for #b (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) : Tot (map_group_entry b) = MapGroupEntry (coerce_to_bounded_typ _ (t_literal k)) ty let rec list_ghost_assoc_for_all (#key: Type) (#value: Type) (p: (key & value) -> bool) (k: key) (m: list (key & value)) : Lemma (requires (List.Tot.for_all p m == true)) (ensures (match Cbor.list_ghost_assoc k m with | None -> True | Some y -> p (k, y) )) (decreases m) [SMTPat (List.Tot.for_all p m); SMTPat (Cbor.list_ghost_assoc k m)] = match m with | [] -> () | (k', _) :: m' -> if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k') then () else list_ghost_assoc_for_all p k m' let rec list_assoc_none_for_all_map_key_neq (k: Cbor.raw_data_item) (l: list (Cbor.raw_data_item & Cbor.raw_data_item)) : Lemma (requires (None? (Cbor.list_ghost_assoc k l))) (ensures (List.Tot.for_all (map_key_neq _ k) l == true)) = match l with | [] -> () | _ :: q -> list_assoc_none_for_all_map_key_neq k q val matches_map_group_map_group_cons_zero_or_one_no_repeats (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.no_repeats_p (List.Tot.map fst x))) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b end /\ matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> matches_map_group g x | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) val matches_map_group_map_group_cons_one_no_repeats (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.no_repeats_p (List.Tot.map fst x))) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b end /\ matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> false | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) val matches_map_group_map_group_cons_zero_or_one_deterministically_encoded_cbor_map_key_order (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) x)) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b /\ List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) (List.Tot.filter (map_key_neq _ k) x) end /\ matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> matches_map_group g x | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) [SMTPat (matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x)] val matches_map_group_map_group_cons_one_deterministically_encoded_cbor_map_key_order (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) x)) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b /\ List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) (List.Tot.filter (map_key_neq _ k) x) end /\ matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> false | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) [SMTPat (matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x)] // 2.1 specifies "names that turn into the map key text string" noextract let string64 = (s: Seq.seq U8.t {FStar.UInt.fits (Seq.length s) 64}) let name_as_text_string (s: string64) : typ = t_literal (Cbor.String Cbor.cbor_major_type_text_string s) let t_map (#b: option Cbor.raw_data_item) (m: map_group b) : bounded_typ_gen b = fun x -> Cbor.Map? x && matches_map_group m (Cbor.Map?.v x) let t_map_equiv #b (m1 m2: map_group b) : Lemma (requires (map_group_equiv m1 m2)) (ensures (typ_equiv (t_map m1) (t_map m2))) = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt.fsti.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.Pull.fsti.checked", "CBOR.Spec.fsti.checked" ], "interface_file": false, "source_file": "CDDL.Spec.fsti" }
[ { "abbrev": true, "full_module": "FStar.Ghost.Pull", "short_module": "Pull" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "CBOR.Spec", "short_module": "Cbor" }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
phi: (b: CBOR.Spec.Type.raw_data_item -> _: CDDL.Spec.bounded_typ b -> CDDL.Spec.map_group (FStar.Pervasives.Native.Some b)) -> x: CBOR.Spec.Type.raw_data_item -> Prims.GTot Prims.bool
Prims.GTot
[ "sometrivial", "" ]
[]
[ "CBOR.Spec.Type.raw_data_item", "CDDL.Spec.bounded_typ", "CDDL.Spec.map_group", "FStar.Pervasives.Native.Some", "Prims.op_AmpAmp", "CBOR.Spec.Type.uu___is_Map", "CDDL.Spec.matches_map_group", "CDDL.Spec.t_map_rec", "CBOR.Spec.Type.__proj__Map__item__v", "Prims.bool" ]
[ "recursion" ]
false
false
false
false
false
let rec t_map_rec (phi: (b: Cbor.raw_data_item -> (bounded_typ b -> map_group (Some b)))) (x: Cbor.raw_data_item) : GTot bool (decreases x) =
Cbor.Map? x && matches_map_group (phi x (t_map_rec phi)) (Cbor.Map?.v x)
false
CDDL.Spec.fsti
CDDL.Spec.multi_rec
val multi_rec (phi_base: typ) (phi_array: (b: Cbor.raw_data_item -> bounded_typ b -> array_group3 (Some b))) (phi_map: (b: Cbor.raw_data_item -> bounded_typ b -> map_group (Some b))) (phi_tag: (U64.t -> b: Cbor.raw_data_item -> bounded_typ b -> bounded_typ b)) (x: Cbor.raw_data_item) : GTot bool (decreases x)
val multi_rec (phi_base: typ) (phi_array: (b: Cbor.raw_data_item -> bounded_typ b -> array_group3 (Some b))) (phi_map: (b: Cbor.raw_data_item -> bounded_typ b -> map_group (Some b))) (phi_tag: (U64.t -> b: Cbor.raw_data_item -> bounded_typ b -> bounded_typ b)) (x: Cbor.raw_data_item) : GTot bool (decreases x)
let rec multi_rec (phi_base: typ) (phi_array: (b: Cbor.raw_data_item) -> bounded_typ b -> array_group3 (Some b)) (phi_map: (b: Cbor.raw_data_item) -> bounded_typ b -> map_group (Some b)) (phi_tag: U64.t -> (b: Cbor.raw_data_item) -> bounded_typ b -> bounded_typ b) (x: Cbor.raw_data_item) : GTot bool (decreases x) = phi_base x || begin match x with | Cbor.Array v -> match_array_group3 (phi_array x (multi_rec phi_base phi_array phi_map phi_tag)) v | Cbor.Map v -> matches_map_group (phi_map x (multi_rec phi_base phi_array phi_map phi_tag)) v | Cbor.Tagged tag v -> phi_tag tag x (multi_rec phi_base phi_array phi_map phi_tag) v | _ -> false end
{ "file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 5, "end_line": 842, "start_col": 0, "start_line": 825 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module CDDL.Spec module Cbor = CBOR.Spec module U8 = FStar.UInt8 module U64 = FStar.UInt64 // Concise Data Definition Language (RFC 8610) noextract let opt_precedes (#t1 #t2: Type) (x1: t1) (x2: option t2) : Tot prop = match x2 with | None -> True | Some x2 -> x1 << x2 [@@noextract_to "krml"] let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization) [@@noextract_to "krml"] let typ = bounded_typ_gen None [@@noextract_to "krml"] let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e) let coerce_to_bounded_typ (b: option Cbor.raw_data_item) (t: typ) : Tot (bounded_typ_gen b) = t noextract let typ_equiv (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : Tot prop = forall x . t1 x == t2 x let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x) let t_choice_equiv #b (t1 t1' t2 t2' : bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2')) (ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2'))) = () // etc. let t_choice_simpl #b (t: bounded_typ_gen b) : Lemma ((t `t_choice` t) `typ_equiv` t) = () let t_always_false : typ = (fun _ -> false) let t_literal (i: Cbor.raw_data_item) : typ = (fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i)) // Appendix D let any : typ = (fun _ -> true) let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64) let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64) let t_int : typ = uint `t_choice` nint let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string) let bytes = bstr let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string) let text = tstr [@@CMacro] let simple_value_false : Cbor.simple_value = 20uy [@@CMacro] let simple_value_true : Cbor.simple_value = 21uy [@@CMacro] let simple_value_nil : Cbor.simple_value = 22uy [@@CMacro] let simple_value_undefined : Cbor.simple_value = 23uy let t_simple_value_literal (s: Cbor.simple_value) : typ = t_literal (Cbor.Simple s) let t_false : typ = t_simple_value_literal simple_value_false let t_true : typ = t_simple_value_literal simple_value_true let t_bool : typ = t_choice t_false t_true let t_nil : typ = t_simple_value_literal simple_value_nil let t_null : typ = t_nil let t_undefined : typ = t_simple_value_literal simple_value_undefined let t_uint_literal (v: U64.t) : typ = t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v) // Section 2.1: Groups // Groups in array context (Section 3.4) // General semantics, which would imply backtracking [@@erasable; noextract_to "krml"] let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool) let array_group1_empty : array_group1 = fun k -> k let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k) let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) = k l || a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more' let array_group1_item (t: typ) : array_group1 = fun k l -> match l with | [] -> false | a :: q -> t a && k q let t_array1 (a: array_group1) : typ = fun x -> Cbor.Array? x && a Nil? (Cbor.Array?.v x) [@@noextract_to "krml"] let nat_up_to (n: nat) : eqtype = (i: nat { i <= n }) [@@noextract_to "krml"] let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l))) [@@noextract_to "krml"] let array_group2_empty : array_group2 = (fun _ i -> [i]) [@@noextract_to "krml"] let array_group2_concat (a1 a2: array_group2) : array_group2 = (fun l i1 -> let res1 = a1 l i1 in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1 ) [@@noextract_to "krml"] let array_group2_choice (a1 a2: array_group2) : array_group2 = fun l i -> a1 l i `List.Tot.append` a2 l i [@@noextract_to "krml"] let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) = i :: begin let r1 = a l i in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> if i2 <= i then [] else array_group2_zero_or_more' a l i2 ) r1 end (* [@@noextract_to "krml"] let array_group2_item (t: typ) : array_group2 = fun l i -> if i = Seq.length l then [] else if t (Seq.index l i) then [i + 1] else [] *) [@@noextract_to "krml"] let t_array2 (a: array_group2) : typ = fun x -> Cbor.Array? x && begin let l = Cbor.Array?.v x in List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0 end // Greedy semantics (Appendix A?) let list_is_suffix_of (#t: Type) (small large: list t) : Tot prop = exists prefix . large == prefix `List.Tot.append` small let list_is_suffix_of_refl (#t: Type) (l: list t) : Lemma (l `list_is_suffix_of` l) [SMTPat (l `list_is_suffix_of` l)] = assert (l == [] `List.Tot.append` l) let rec list_nil_precedes (#t: Type) (l: list t) : Lemma (Nil #t == l \/ Nil #t << l) = match l with | [] -> () | a :: q -> list_nil_precedes q let rec list_is_suffix_of_precedes (#t0 #t: Type) (v0: t0) (small large: list t) : Lemma (requires ( large << v0 /\ small `list_is_suffix_of` large )) (ensures ( small << v0 )) (decreases (List.Tot.length large)) [SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]] = if Nil? small then list_nil_precedes large else begin let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in List.Tot.append_length prefix small; if List.Tot.length small = List.Tot.length large then () else list_is_suffix_of_precedes v0 small (List.Tot.tl large) end [@@erasable; noextract_to "krml"] let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with | None -> True | Some l' -> opt_precedes l' bound )) noextract let array_group3_equiv #b (g1 g2: array_group3 b) : Tot prop = forall l . g1 l == g2 l let array_group3_always_false #b : array_group3 b = fun _ -> None let array_group3_empty #b : array_group3 b = fun x -> Some x let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b = (fun l -> match a1 l with | None -> None | Some l3 -> a3 l3 ) let array_group3_concat_equiv #b (a1 a1' a2 a2' : array_group3 b) : Lemma (requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2'))) (ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2'))) = () let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b = fun l -> match a1 l with | None -> a3 l | Some l3 -> Some l3 let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b)) (decreases (List.Tot.length l)) = match a l with | None -> Some l | Some l' -> if List.Tot.length l' >= List.Tot.length l then Some l else array_group3_zero_or_more' a l' let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more' let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b = a `array_group3_concat` array_group3_zero_or_more a let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) = a `array_group3_choice` array_group3_empty let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l -> match l with | [] -> None | a :: q -> if t a then Some q else None let array_group3_item_equiv #b (t1 t2: bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t2)) (ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2)) = () let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b) (l: list Cbor.raw_data_item {opt_precedes l b}) : GTot bool = match a l with | Some l' -> Nil? l' | _ -> false let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x -> Cbor.Array? x && match_array_group3 a (Cbor.Array?.v x) let t_array3_equiv #b (a1 a2: array_group3 b) : Lemma (requires (array_group3_equiv a1 a2)) (ensures (typ_equiv (t_array3 a1) (t_array3 a2))) = () // Recursive type (needed by COSE Section 5.1 "Recipient") // Inspiring from Barthe et al., Type-Based Termination with Sized // Products (CSL 2008): we allow recursion only at the level of // destructors. In other words, instead of having a generic recursion // combinator, we provide a recursion-enabled version only for each // destructor combinator. We need to annotate it with a bound b (akin // to the "size" annotation in a sized type.) let rec t_array3_rec (phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b))) (x: Cbor.raw_data_item) : GTot bool (decreases x) = Cbor.Array? x && match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x) // Groups in map context (Section 3.5) [@@erasable] noeq type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b module Pull = FStar.Ghost.Pull noextract let opt_map_entry_bounded' (b: option Cbor.raw_data_item) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) : GTot bool = FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b) let opt_map_entry_bounded (b: option Cbor.raw_data_item) : GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool) = Pull.pull (opt_map_entry_bounded' b) let rec opt_precedes_map_for_all_opt_map_entry_bounded (b: option Cbor.raw_data_item) (l: list (Cbor.raw_data_item & Cbor.raw_data_item)) : Lemma (requires (opt_precedes l b)) (ensures (List.Tot.for_all (opt_map_entry_bounded b) l)) [SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)] = match l with | [] -> () | _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q let matches_map_group_entry (#b: option Cbor.raw_data_item) (ge: map_group_entry b) (x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true }) : GTot bool = ge.fst (fst x) && ge.snd (snd x) [@@erasable] noeq type map_group (b: option Cbor.raw_data_item) = { one: list (map_group_entry b); zero_or_one: list (map_group_entry b); zero_or_more: list (map_group_entry b); } let map_group_empty #b : map_group b = { one = []; zero_or_one = []; zero_or_more = []; } let cut_map_group_entry_key #b (key: bounded_typ_gen b) (t: bounded_typ_gen b) (x: Cbor.raw_data_item { opt_precedes x b }) : GTot bool = t x && not (key x) // Section 3.5.4: Cut let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b = cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = { one = List.Tot.map (cut_map_group_entry key) g.one; zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one; zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more; } let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = if cut then cut_map_group (ge.fst) g else g let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with one = ge :: g.one; } let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_one = ge :: g.zero_or_one; } let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_more = ge :: g.zero_or_more; } val matches_map_group (#b: option Cbor.raw_data_item) (m: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x }) : GTot bool val matches_map_group_empty (b: option Cbor.raw_data_item) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (ensures (matches_map_group (map_group_empty #b) x == Nil? x)) [SMTPat (matches_map_group (map_group_empty #b) x)] (* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *) noextract let is_sub_map_group_of #b (small large: map_group b) : Tot prop = forall x . matches_map_group small x ==> matches_map_group large x noextract let map_group_equiv #b (mg1 mg2: map_group b) : Tot prop = forall x . matches_map_group mg1 x == matches_map_group mg2 x noextract let is_sub_typ_of #b (small large: bounded_typ_gen b) : Tot prop = forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x noextract let is_sub_map_group_entry_of #b (small large: map_group_entry b) : Tot prop = small.fst `is_sub_typ_of` large.fst /\ small.snd `is_sub_typ_of` large.snd let map_group_ignore_restricted_entries #b (mg: map_group b) : Tot (map_group b) = {mg with one = []; zero_or_one = []; } let pull_rel (#t1 #t2: Type) (r: t1 -> t2 -> prop) (x1: t1) : GTot ((x2: t2) -> Tot bool) = Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2)) let list_ghost_forall_exists_body (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l2: list t2) : GTot (t1 -> bool) = Pull.pull (fun x1 -> List.Tot.existsb (pull_rel r x1) l2 ) let list_ghost_forall_exists (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l1: list t1) (l2: list t2) : GTot bool = List.Tot.for_all (list_ghost_forall_exists_body r l2) l1 noextract let matches_map_group_entry' (#b: _) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) (y: map_group_entry b) : Tot prop = opt_map_entry_bounded b x ==> matches_map_group_entry y x val matches_map_group_no_restricted (#b: _) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires ( Nil? g.one /\ Nil? g.zero_or_one )) (ensures ( matches_map_group g x <==> list_ghost_forall_exists matches_map_group_entry' x g.zero_or_more )) [SMTPat (matches_map_group g x)] let rec list_ghost_forall2 (#t1 #t2: Type) (f: t1 -> t2 -> GTot prop) (l1: list t1) (l2: list t2) : GTot bool (decreases l1) = match l1, l2 with | [], [] -> true | a1 :: q1, a2 :: q2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (f a1 a2) && list_ghost_forall2 f q1 q2 | _ -> false val list_ghost_forall_exists_is_sub_map_group_entry_of_refl (#b: _) (l: list (map_group_entry b)) : Lemma (ensures (list_ghost_forall_exists is_sub_map_group_entry_of l l)) [SMTPat (list_ghost_forall_exists is_sub_map_group_entry_of l l)] let map_group_included_zero_or_more #b (small large: map_group b) : GTot bool = list_ghost_forall_exists is_sub_map_group_entry_of small.one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_more large.zero_or_more && Nil? large.one val map_group_included_zero_or_more_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_zero_or_more small large)) (ensures (is_sub_map_group_of small large)) val map_group_ignore_restricted_entries_sub (#b: _) (mg: map_group b) : Lemma (requires ( list_ghost_forall_exists is_sub_map_group_entry_of mg.one mg.zero_or_more /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( mg `is_sub_map_group_of` map_group_ignore_restricted_entries mg )) let map_group_ignore_restricted_entries_no_one_equiv #b (mg: map_group b) : Lemma (requires ( Nil? mg.one /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( map_group_equiv mg (map_group_ignore_restricted_entries mg) )) = map_group_ignore_restricted_entries_sub mg; map_group_included_zero_or_more_correct (map_group_ignore_restricted_entries mg) mg let map_group_included_pointwise #b (small large: map_group b) : GTot bool = list_ghost_forall2 is_sub_map_group_entry_of small.one large.one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_one large.zero_or_one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_more large.zero_or_more val map_group_included_pointwise_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_pointwise small large)) (ensures (is_sub_map_group_of small large)) let rec list_ghost_forall2_map_l (#t1 #t2: Type) (r: t1 -> t2 -> prop) (f: t2 -> t1) (l: list t2) : Lemma (requires (forall x . r (f x) x)) (ensures (list_ghost_forall2 r (List.Tot.map f l) l)) = match l with | [] -> () | _ :: q -> list_ghost_forall2_map_l r f q let rec list_ghost_forall2_map_r (#t1 #t2: Type) (r: t1 -> t2 -> prop) (f: t1 -> t2) (l: list t1) : Lemma (requires (forall x . r x (f x))) (ensures (list_ghost_forall2 r l (List.Tot.map f l))) = match l with | [] -> () | _ :: q -> list_ghost_forall2_map_r r f q let cut_map_group_sub #b (key: bounded_typ_gen b) (mg: map_group b) : Lemma (cut_map_group key mg `is_sub_map_group_of` mg) = list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.one; list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_one; list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_more; map_group_included_pointwise_correct (cut_map_group key mg) mg (* Proving matches_map_group for sorted maps and map groups where key constraints specify whole elements *) let rec list_for_all_filter_invariant (#t: Type) (p: t -> bool) (f: t -> bool) (l: list t) : Lemma (requires (List.Tot.for_all p l == true)) (ensures (List.Tot.for_all p (List.Tot.filter f l) == true)) [SMTPat (List.Tot.for_all p (List.Tot.filter f l))] = match l with | [] -> () | _ :: q -> list_for_all_filter_invariant p f q let map_key_neq' (#t1 t2: Type) (k: t1) (x: (t1 & t2)) : GTot bool = FStar.StrongExcludedMiddle.strong_excluded_middle (~ (fst x == k)) let map_key_neq (#t1 t2: Type) (k: t1) : GTot ((t1 & t2) -> bool) = Pull.pull (map_key_neq' t2 k) let map_group_entry_for #b (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) : Tot (map_group_entry b) = MapGroupEntry (coerce_to_bounded_typ _ (t_literal k)) ty let rec list_ghost_assoc_for_all (#key: Type) (#value: Type) (p: (key & value) -> bool) (k: key) (m: list (key & value)) : Lemma (requires (List.Tot.for_all p m == true)) (ensures (match Cbor.list_ghost_assoc k m with | None -> True | Some y -> p (k, y) )) (decreases m) [SMTPat (List.Tot.for_all p m); SMTPat (Cbor.list_ghost_assoc k m)] = match m with | [] -> () | (k', _) :: m' -> if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k') then () else list_ghost_assoc_for_all p k m' let rec list_assoc_none_for_all_map_key_neq (k: Cbor.raw_data_item) (l: list (Cbor.raw_data_item & Cbor.raw_data_item)) : Lemma (requires (None? (Cbor.list_ghost_assoc k l))) (ensures (List.Tot.for_all (map_key_neq _ k) l == true)) = match l with | [] -> () | _ :: q -> list_assoc_none_for_all_map_key_neq k q val matches_map_group_map_group_cons_zero_or_one_no_repeats (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.no_repeats_p (List.Tot.map fst x))) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b end /\ matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> matches_map_group g x | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) val matches_map_group_map_group_cons_one_no_repeats (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.no_repeats_p (List.Tot.map fst x))) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b end /\ matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> false | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) val matches_map_group_map_group_cons_zero_or_one_deterministically_encoded_cbor_map_key_order (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) x)) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b /\ List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) (List.Tot.filter (map_key_neq _ k) x) end /\ matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> matches_map_group g x | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) [SMTPat (matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x)] val matches_map_group_map_group_cons_one_deterministically_encoded_cbor_map_key_order (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) x)) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b /\ List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) (List.Tot.filter (map_key_neq _ k) x) end /\ matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> false | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) [SMTPat (matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x)] // 2.1 specifies "names that turn into the map key text string" noextract let string64 = (s: Seq.seq U8.t {FStar.UInt.fits (Seq.length s) 64}) let name_as_text_string (s: string64) : typ = t_literal (Cbor.String Cbor.cbor_major_type_text_string s) let t_map (#b: option Cbor.raw_data_item) (m: map_group b) : bounded_typ_gen b = fun x -> Cbor.Map? x && matches_map_group m (Cbor.Map?.v x) let t_map_equiv #b (m1 m2: map_group b) : Lemma (requires (map_group_equiv m1 m2)) (ensures (typ_equiv (t_map m1) (t_map m2))) = () let rec t_map_rec (phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> map_group (Some b))) (x: Cbor.raw_data_item) : GTot bool (decreases x) = Cbor.Map? x && matches_map_group (phi x (t_map_rec phi)) (Cbor.Map?.v x) // Section 3.6: Tags let t_tag (#b: option Cbor.raw_data_item) (tag: U64.t) (t: bounded_typ_gen b) : bounded_typ_gen b = fun x -> Cbor.Tagged? x && Cbor.Tagged?.tag x = tag && t (Cbor.Tagged?.v x) let rec t_tag_rec (tag: U64.t) (phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> bounded_typ b)) (x: Cbor.raw_data_item) : GTot bool (decreases x) = Cbor.Tagged? x && Cbor.Tagged?.tag x = tag && phi x (t_tag_rec tag phi) (Cbor.Tagged?.v x) // Multi-purpose recursive combinator, to allow disjunctions between destructors
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt.fsti.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.Pull.fsti.checked", "CBOR.Spec.fsti.checked" ], "interface_file": false, "source_file": "CDDL.Spec.fsti" }
[ { "abbrev": true, "full_module": "FStar.Ghost.Pull", "short_module": "Pull" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "CBOR.Spec", "short_module": "Cbor" }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
phi_base: CDDL.Spec.typ -> phi_array: (b: CBOR.Spec.Type.raw_data_item -> _: CDDL.Spec.bounded_typ b -> CDDL.Spec.array_group3 (FStar.Pervasives.Native.Some b)) -> phi_map: (b: CBOR.Spec.Type.raw_data_item -> _: CDDL.Spec.bounded_typ b -> CDDL.Spec.map_group (FStar.Pervasives.Native.Some b)) -> phi_tag: (_: FStar.UInt64.t -> b: CBOR.Spec.Type.raw_data_item -> _: CDDL.Spec.bounded_typ b -> CDDL.Spec.bounded_typ b) -> x: CBOR.Spec.Type.raw_data_item -> Prims.GTot Prims.bool
Prims.GTot
[ "sometrivial", "" ]
[]
[ "CDDL.Spec.typ", "CBOR.Spec.Type.raw_data_item", "CDDL.Spec.bounded_typ", "CDDL.Spec.array_group3", "FStar.Pervasives.Native.Some", "CDDL.Spec.map_group", "FStar.UInt64.t", "Prims.op_BarBar", "Prims.list", "Prims.b2t", "FStar.UInt.fits", "FStar.List.Tot.Base.length", "FStar.UInt64.n", "CDDL.Spec.match_array_group3", "CDDL.Spec.multi_rec", "FStar.Pervasives.Native.tuple2", "CDDL.Spec.matches_map_group", "Prims.bool" ]
[ "recursion" ]
false
false
false
false
false
let rec multi_rec (phi_base: typ) (phi_array: (b: Cbor.raw_data_item -> bounded_typ b -> array_group3 (Some b))) (phi_map: (b: Cbor.raw_data_item -> bounded_typ b -> map_group (Some b))) (phi_tag: (U64.t -> b: Cbor.raw_data_item -> bounded_typ b -> bounded_typ b)) (x: Cbor.raw_data_item) : GTot bool (decreases x) =
phi_base x || (match x with | Cbor.Array v -> match_array_group3 (phi_array x (multi_rec phi_base phi_array phi_map phi_tag)) v | Cbor.Map v -> matches_map_group (phi_map x (multi_rec phi_base phi_array phi_map phi_tag)) v | Cbor.Tagged tag v -> phi_tag tag x (multi_rec phi_base phi_array phi_map phi_tag) v | _ -> false)
false
CDDL.Spec.fsti
CDDL.Spec.list_ghost_assoc_for_all
val list_ghost_assoc_for_all (#key #value: Type) (p: ((key & value) -> bool)) (k: key) (m: list (key & value)) : Lemma (requires (List.Tot.for_all p m == true)) (ensures (match Cbor.list_ghost_assoc k m with | None -> True | Some y -> p (k, y))) (decreases m) [SMTPat (List.Tot.for_all p m); SMTPat (Cbor.list_ghost_assoc k m)]
val list_ghost_assoc_for_all (#key #value: Type) (p: ((key & value) -> bool)) (k: key) (m: list (key & value)) : Lemma (requires (List.Tot.for_all p m == true)) (ensures (match Cbor.list_ghost_assoc k m with | None -> True | Some y -> p (k, y))) (decreases m) [SMTPat (List.Tot.for_all p m); SMTPat (Cbor.list_ghost_assoc k m)]
let rec list_ghost_assoc_for_all (#key: Type) (#value: Type) (p: (key & value) -> bool) (k: key) (m: list (key & value)) : Lemma (requires (List.Tot.for_all p m == true)) (ensures (match Cbor.list_ghost_assoc k m with | None -> True | Some y -> p (k, y) )) (decreases m) [SMTPat (List.Tot.for_all p m); SMTPat (Cbor.list_ghost_assoc k m)] = match m with | [] -> () | (k', _) :: m' -> if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k') then () else list_ghost_assoc_for_all p k m'
{ "file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 40, "end_line": 699, "start_col": 0, "start_line": 680 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module CDDL.Spec module Cbor = CBOR.Spec module U8 = FStar.UInt8 module U64 = FStar.UInt64 // Concise Data Definition Language (RFC 8610) noextract let opt_precedes (#t1 #t2: Type) (x1: t1) (x2: option t2) : Tot prop = match x2 with | None -> True | Some x2 -> x1 << x2 [@@noextract_to "krml"] let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization) [@@noextract_to "krml"] let typ = bounded_typ_gen None [@@noextract_to "krml"] let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e) let coerce_to_bounded_typ (b: option Cbor.raw_data_item) (t: typ) : Tot (bounded_typ_gen b) = t noextract let typ_equiv (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : Tot prop = forall x . t1 x == t2 x let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x) let t_choice_equiv #b (t1 t1' t2 t2' : bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2')) (ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2'))) = () // etc. let t_choice_simpl #b (t: bounded_typ_gen b) : Lemma ((t `t_choice` t) `typ_equiv` t) = () let t_always_false : typ = (fun _ -> false) let t_literal (i: Cbor.raw_data_item) : typ = (fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i)) // Appendix D let any : typ = (fun _ -> true) let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64) let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64) let t_int : typ = uint `t_choice` nint let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string) let bytes = bstr let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string) let text = tstr [@@CMacro] let simple_value_false : Cbor.simple_value = 20uy [@@CMacro] let simple_value_true : Cbor.simple_value = 21uy [@@CMacro] let simple_value_nil : Cbor.simple_value = 22uy [@@CMacro] let simple_value_undefined : Cbor.simple_value = 23uy let t_simple_value_literal (s: Cbor.simple_value) : typ = t_literal (Cbor.Simple s) let t_false : typ = t_simple_value_literal simple_value_false let t_true : typ = t_simple_value_literal simple_value_true let t_bool : typ = t_choice t_false t_true let t_nil : typ = t_simple_value_literal simple_value_nil let t_null : typ = t_nil let t_undefined : typ = t_simple_value_literal simple_value_undefined let t_uint_literal (v: U64.t) : typ = t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v) // Section 2.1: Groups // Groups in array context (Section 3.4) // General semantics, which would imply backtracking [@@erasable; noextract_to "krml"] let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool) let array_group1_empty : array_group1 = fun k -> k let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k) let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) = k l || a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more' let array_group1_item (t: typ) : array_group1 = fun k l -> match l with | [] -> false | a :: q -> t a && k q let t_array1 (a: array_group1) : typ = fun x -> Cbor.Array? x && a Nil? (Cbor.Array?.v x) [@@noextract_to "krml"] let nat_up_to (n: nat) : eqtype = (i: nat { i <= n }) [@@noextract_to "krml"] let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l))) [@@noextract_to "krml"] let array_group2_empty : array_group2 = (fun _ i -> [i]) [@@noextract_to "krml"] let array_group2_concat (a1 a2: array_group2) : array_group2 = (fun l i1 -> let res1 = a1 l i1 in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1 ) [@@noextract_to "krml"] let array_group2_choice (a1 a2: array_group2) : array_group2 = fun l i -> a1 l i `List.Tot.append` a2 l i [@@noextract_to "krml"] let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) = i :: begin let r1 = a l i in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> if i2 <= i then [] else array_group2_zero_or_more' a l i2 ) r1 end (* [@@noextract_to "krml"] let array_group2_item (t: typ) : array_group2 = fun l i -> if i = Seq.length l then [] else if t (Seq.index l i) then [i + 1] else [] *) [@@noextract_to "krml"] let t_array2 (a: array_group2) : typ = fun x -> Cbor.Array? x && begin let l = Cbor.Array?.v x in List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0 end // Greedy semantics (Appendix A?) let list_is_suffix_of (#t: Type) (small large: list t) : Tot prop = exists prefix . large == prefix `List.Tot.append` small let list_is_suffix_of_refl (#t: Type) (l: list t) : Lemma (l `list_is_suffix_of` l) [SMTPat (l `list_is_suffix_of` l)] = assert (l == [] `List.Tot.append` l) let rec list_nil_precedes (#t: Type) (l: list t) : Lemma (Nil #t == l \/ Nil #t << l) = match l with | [] -> () | a :: q -> list_nil_precedes q let rec list_is_suffix_of_precedes (#t0 #t: Type) (v0: t0) (small large: list t) : Lemma (requires ( large << v0 /\ small `list_is_suffix_of` large )) (ensures ( small << v0 )) (decreases (List.Tot.length large)) [SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]] = if Nil? small then list_nil_precedes large else begin let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in List.Tot.append_length prefix small; if List.Tot.length small = List.Tot.length large then () else list_is_suffix_of_precedes v0 small (List.Tot.tl large) end [@@erasable; noextract_to "krml"] let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with | None -> True | Some l' -> opt_precedes l' bound )) noextract let array_group3_equiv #b (g1 g2: array_group3 b) : Tot prop = forall l . g1 l == g2 l let array_group3_always_false #b : array_group3 b = fun _ -> None let array_group3_empty #b : array_group3 b = fun x -> Some x let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b = (fun l -> match a1 l with | None -> None | Some l3 -> a3 l3 ) let array_group3_concat_equiv #b (a1 a1' a2 a2' : array_group3 b) : Lemma (requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2'))) (ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2'))) = () let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b = fun l -> match a1 l with | None -> a3 l | Some l3 -> Some l3 let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b)) (decreases (List.Tot.length l)) = match a l with | None -> Some l | Some l' -> if List.Tot.length l' >= List.Tot.length l then Some l else array_group3_zero_or_more' a l' let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more' let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b = a `array_group3_concat` array_group3_zero_or_more a let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) = a `array_group3_choice` array_group3_empty let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l -> match l with | [] -> None | a :: q -> if t a then Some q else None let array_group3_item_equiv #b (t1 t2: bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t2)) (ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2)) = () let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b) (l: list Cbor.raw_data_item {opt_precedes l b}) : GTot bool = match a l with | Some l' -> Nil? l' | _ -> false let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x -> Cbor.Array? x && match_array_group3 a (Cbor.Array?.v x) let t_array3_equiv #b (a1 a2: array_group3 b) : Lemma (requires (array_group3_equiv a1 a2)) (ensures (typ_equiv (t_array3 a1) (t_array3 a2))) = () // Recursive type (needed by COSE Section 5.1 "Recipient") // Inspiring from Barthe et al., Type-Based Termination with Sized // Products (CSL 2008): we allow recursion only at the level of // destructors. In other words, instead of having a generic recursion // combinator, we provide a recursion-enabled version only for each // destructor combinator. We need to annotate it with a bound b (akin // to the "size" annotation in a sized type.) let rec t_array3_rec (phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b))) (x: Cbor.raw_data_item) : GTot bool (decreases x) = Cbor.Array? x && match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x) // Groups in map context (Section 3.5) [@@erasable] noeq type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b module Pull = FStar.Ghost.Pull noextract let opt_map_entry_bounded' (b: option Cbor.raw_data_item) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) : GTot bool = FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b) let opt_map_entry_bounded (b: option Cbor.raw_data_item) : GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool) = Pull.pull (opt_map_entry_bounded' b) let rec opt_precedes_map_for_all_opt_map_entry_bounded (b: option Cbor.raw_data_item) (l: list (Cbor.raw_data_item & Cbor.raw_data_item)) : Lemma (requires (opt_precedes l b)) (ensures (List.Tot.for_all (opt_map_entry_bounded b) l)) [SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)] = match l with | [] -> () | _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q let matches_map_group_entry (#b: option Cbor.raw_data_item) (ge: map_group_entry b) (x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true }) : GTot bool = ge.fst (fst x) && ge.snd (snd x) [@@erasable] noeq type map_group (b: option Cbor.raw_data_item) = { one: list (map_group_entry b); zero_or_one: list (map_group_entry b); zero_or_more: list (map_group_entry b); } let map_group_empty #b : map_group b = { one = []; zero_or_one = []; zero_or_more = []; } let cut_map_group_entry_key #b (key: bounded_typ_gen b) (t: bounded_typ_gen b) (x: Cbor.raw_data_item { opt_precedes x b }) : GTot bool = t x && not (key x) // Section 3.5.4: Cut let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b = cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = { one = List.Tot.map (cut_map_group_entry key) g.one; zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one; zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more; } let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = if cut then cut_map_group (ge.fst) g else g let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with one = ge :: g.one; } let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_one = ge :: g.zero_or_one; } let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_more = ge :: g.zero_or_more; } val matches_map_group (#b: option Cbor.raw_data_item) (m: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x }) : GTot bool val matches_map_group_empty (b: option Cbor.raw_data_item) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (ensures (matches_map_group (map_group_empty #b) x == Nil? x)) [SMTPat (matches_map_group (map_group_empty #b) x)] (* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *) noextract let is_sub_map_group_of #b (small large: map_group b) : Tot prop = forall x . matches_map_group small x ==> matches_map_group large x noextract let map_group_equiv #b (mg1 mg2: map_group b) : Tot prop = forall x . matches_map_group mg1 x == matches_map_group mg2 x noextract let is_sub_typ_of #b (small large: bounded_typ_gen b) : Tot prop = forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x noextract let is_sub_map_group_entry_of #b (small large: map_group_entry b) : Tot prop = small.fst `is_sub_typ_of` large.fst /\ small.snd `is_sub_typ_of` large.snd let map_group_ignore_restricted_entries #b (mg: map_group b) : Tot (map_group b) = {mg with one = []; zero_or_one = []; } let pull_rel (#t1 #t2: Type) (r: t1 -> t2 -> prop) (x1: t1) : GTot ((x2: t2) -> Tot bool) = Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2)) let list_ghost_forall_exists_body (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l2: list t2) : GTot (t1 -> bool) = Pull.pull (fun x1 -> List.Tot.existsb (pull_rel r x1) l2 ) let list_ghost_forall_exists (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l1: list t1) (l2: list t2) : GTot bool = List.Tot.for_all (list_ghost_forall_exists_body r l2) l1 noextract let matches_map_group_entry' (#b: _) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) (y: map_group_entry b) : Tot prop = opt_map_entry_bounded b x ==> matches_map_group_entry y x val matches_map_group_no_restricted (#b: _) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires ( Nil? g.one /\ Nil? g.zero_or_one )) (ensures ( matches_map_group g x <==> list_ghost_forall_exists matches_map_group_entry' x g.zero_or_more )) [SMTPat (matches_map_group g x)] let rec list_ghost_forall2 (#t1 #t2: Type) (f: t1 -> t2 -> GTot prop) (l1: list t1) (l2: list t2) : GTot bool (decreases l1) = match l1, l2 with | [], [] -> true | a1 :: q1, a2 :: q2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (f a1 a2) && list_ghost_forall2 f q1 q2 | _ -> false val list_ghost_forall_exists_is_sub_map_group_entry_of_refl (#b: _) (l: list (map_group_entry b)) : Lemma (ensures (list_ghost_forall_exists is_sub_map_group_entry_of l l)) [SMTPat (list_ghost_forall_exists is_sub_map_group_entry_of l l)] let map_group_included_zero_or_more #b (small large: map_group b) : GTot bool = list_ghost_forall_exists is_sub_map_group_entry_of small.one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_more large.zero_or_more && Nil? large.one val map_group_included_zero_or_more_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_zero_or_more small large)) (ensures (is_sub_map_group_of small large)) val map_group_ignore_restricted_entries_sub (#b: _) (mg: map_group b) : Lemma (requires ( list_ghost_forall_exists is_sub_map_group_entry_of mg.one mg.zero_or_more /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( mg `is_sub_map_group_of` map_group_ignore_restricted_entries mg )) let map_group_ignore_restricted_entries_no_one_equiv #b (mg: map_group b) : Lemma (requires ( Nil? mg.one /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( map_group_equiv mg (map_group_ignore_restricted_entries mg) )) = map_group_ignore_restricted_entries_sub mg; map_group_included_zero_or_more_correct (map_group_ignore_restricted_entries mg) mg let map_group_included_pointwise #b (small large: map_group b) : GTot bool = list_ghost_forall2 is_sub_map_group_entry_of small.one large.one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_one large.zero_or_one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_more large.zero_or_more val map_group_included_pointwise_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_pointwise small large)) (ensures (is_sub_map_group_of small large)) let rec list_ghost_forall2_map_l (#t1 #t2: Type) (r: t1 -> t2 -> prop) (f: t2 -> t1) (l: list t2) : Lemma (requires (forall x . r (f x) x)) (ensures (list_ghost_forall2 r (List.Tot.map f l) l)) = match l with | [] -> () | _ :: q -> list_ghost_forall2_map_l r f q let rec list_ghost_forall2_map_r (#t1 #t2: Type) (r: t1 -> t2 -> prop) (f: t1 -> t2) (l: list t1) : Lemma (requires (forall x . r x (f x))) (ensures (list_ghost_forall2 r l (List.Tot.map f l))) = match l with | [] -> () | _ :: q -> list_ghost_forall2_map_r r f q let cut_map_group_sub #b (key: bounded_typ_gen b) (mg: map_group b) : Lemma (cut_map_group key mg `is_sub_map_group_of` mg) = list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.one; list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_one; list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_more; map_group_included_pointwise_correct (cut_map_group key mg) mg (* Proving matches_map_group for sorted maps and map groups where key constraints specify whole elements *) let rec list_for_all_filter_invariant (#t: Type) (p: t -> bool) (f: t -> bool) (l: list t) : Lemma (requires (List.Tot.for_all p l == true)) (ensures (List.Tot.for_all p (List.Tot.filter f l) == true)) [SMTPat (List.Tot.for_all p (List.Tot.filter f l))] = match l with | [] -> () | _ :: q -> list_for_all_filter_invariant p f q let map_key_neq' (#t1 t2: Type) (k: t1) (x: (t1 & t2)) : GTot bool = FStar.StrongExcludedMiddle.strong_excluded_middle (~ (fst x == k)) let map_key_neq (#t1 t2: Type) (k: t1) : GTot ((t1 & t2) -> bool) = Pull.pull (map_key_neq' t2 k) let map_group_entry_for #b (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) : Tot (map_group_entry b) = MapGroupEntry (coerce_to_bounded_typ _ (t_literal k)) ty
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt.fsti.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.Pull.fsti.checked", "CBOR.Spec.fsti.checked" ], "interface_file": false, "source_file": "CDDL.Spec.fsti" }
[ { "abbrev": true, "full_module": "FStar.Ghost.Pull", "short_module": "Pull" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "CBOR.Spec", "short_module": "Cbor" }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: (_: (key * value) -> Prims.bool) -> k: key -> m: Prims.list (key * value) -> FStar.Pervasives.Lemma (requires FStar.List.Tot.Base.for_all p m == true) (ensures ((match CBOR.Spec.Map.list_ghost_assoc k m with | FStar.Pervasives.Native.None #_ -> Prims.l_True | FStar.Pervasives.Native.Some #_ y -> p (k, y)) <: Type0)) (decreases m) [SMTPat (FStar.List.Tot.Base.for_all p m); SMTPat (CBOR.Spec.Map.list_ghost_assoc k m)]
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "FStar.Pervasives.Native.tuple2", "Prims.bool", "Prims.list", "FStar.StrongExcludedMiddle.strong_excluded_middle", "Prims.eq2", "CDDL.Spec.list_ghost_assoc_for_all", "Prims.unit", "FStar.List.Tot.Base.for_all", "Prims.squash", "CBOR.Spec.Map.list_ghost_assoc", "Prims.l_True", "Prims.b2t", "FStar.Pervasives.Native.Mktuple2", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "FStar.Pervasives.Native.option", "Prims.Nil" ]
[ "recursion" ]
false
false
true
false
false
let rec list_ghost_assoc_for_all (#key #value: Type) (p: ((key & value) -> bool)) (k: key) (m: list (key & value)) : Lemma (requires (List.Tot.for_all p m == true)) (ensures (match Cbor.list_ghost_assoc k m with | None -> True | Some y -> p (k, y))) (decreases m) [SMTPat (List.Tot.for_all p m); SMTPat (Cbor.list_ghost_assoc k m)] =
match m with | [] -> () | (k', _) :: m' -> if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k') then () else list_ghost_assoc_for_all p k m'
false
CDDL.Spec.fsti
CDDL.Spec.t_map
val t_map (#b: option Cbor.raw_data_item) (m: map_group b) : bounded_typ_gen b
val t_map (#b: option Cbor.raw_data_item) (m: map_group b) : bounded_typ_gen b
let t_map (#b: option Cbor.raw_data_item) (m: map_group b) : bounded_typ_gen b = fun x -> Cbor.Map? x && matches_map_group m (Cbor.Map?.v x)
{ "file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 37, "end_line": 791, "start_col": 0, "start_line": 789 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module CDDL.Spec module Cbor = CBOR.Spec module U8 = FStar.UInt8 module U64 = FStar.UInt64 // Concise Data Definition Language (RFC 8610) noextract let opt_precedes (#t1 #t2: Type) (x1: t1) (x2: option t2) : Tot prop = match x2 with | None -> True | Some x2 -> x1 << x2 [@@noextract_to "krml"] let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization) [@@noextract_to "krml"] let typ = bounded_typ_gen None [@@noextract_to "krml"] let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e) let coerce_to_bounded_typ (b: option Cbor.raw_data_item) (t: typ) : Tot (bounded_typ_gen b) = t noextract let typ_equiv (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : Tot prop = forall x . t1 x == t2 x let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x) let t_choice_equiv #b (t1 t1' t2 t2' : bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2')) (ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2'))) = () // etc. let t_choice_simpl #b (t: bounded_typ_gen b) : Lemma ((t `t_choice` t) `typ_equiv` t) = () let t_always_false : typ = (fun _ -> false) let t_literal (i: Cbor.raw_data_item) : typ = (fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i)) // Appendix D let any : typ = (fun _ -> true) let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64) let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64) let t_int : typ = uint `t_choice` nint let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string) let bytes = bstr let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string) let text = tstr [@@CMacro] let simple_value_false : Cbor.simple_value = 20uy [@@CMacro] let simple_value_true : Cbor.simple_value = 21uy [@@CMacro] let simple_value_nil : Cbor.simple_value = 22uy [@@CMacro] let simple_value_undefined : Cbor.simple_value = 23uy let t_simple_value_literal (s: Cbor.simple_value) : typ = t_literal (Cbor.Simple s) let t_false : typ = t_simple_value_literal simple_value_false let t_true : typ = t_simple_value_literal simple_value_true let t_bool : typ = t_choice t_false t_true let t_nil : typ = t_simple_value_literal simple_value_nil let t_null : typ = t_nil let t_undefined : typ = t_simple_value_literal simple_value_undefined let t_uint_literal (v: U64.t) : typ = t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v) // Section 2.1: Groups // Groups in array context (Section 3.4) // General semantics, which would imply backtracking [@@erasable; noextract_to "krml"] let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool) let array_group1_empty : array_group1 = fun k -> k let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k) let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) = k l || a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more' let array_group1_item (t: typ) : array_group1 = fun k l -> match l with | [] -> false | a :: q -> t a && k q let t_array1 (a: array_group1) : typ = fun x -> Cbor.Array? x && a Nil? (Cbor.Array?.v x) [@@noextract_to "krml"] let nat_up_to (n: nat) : eqtype = (i: nat { i <= n }) [@@noextract_to "krml"] let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l))) [@@noextract_to "krml"] let array_group2_empty : array_group2 = (fun _ i -> [i]) [@@noextract_to "krml"] let array_group2_concat (a1 a2: array_group2) : array_group2 = (fun l i1 -> let res1 = a1 l i1 in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1 ) [@@noextract_to "krml"] let array_group2_choice (a1 a2: array_group2) : array_group2 = fun l i -> a1 l i `List.Tot.append` a2 l i [@@noextract_to "krml"] let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) = i :: begin let r1 = a l i in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> if i2 <= i then [] else array_group2_zero_or_more' a l i2 ) r1 end (* [@@noextract_to "krml"] let array_group2_item (t: typ) : array_group2 = fun l i -> if i = Seq.length l then [] else if t (Seq.index l i) then [i + 1] else [] *) [@@noextract_to "krml"] let t_array2 (a: array_group2) : typ = fun x -> Cbor.Array? x && begin let l = Cbor.Array?.v x in List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0 end // Greedy semantics (Appendix A?) let list_is_suffix_of (#t: Type) (small large: list t) : Tot prop = exists prefix . large == prefix `List.Tot.append` small let list_is_suffix_of_refl (#t: Type) (l: list t) : Lemma (l `list_is_suffix_of` l) [SMTPat (l `list_is_suffix_of` l)] = assert (l == [] `List.Tot.append` l) let rec list_nil_precedes (#t: Type) (l: list t) : Lemma (Nil #t == l \/ Nil #t << l) = match l with | [] -> () | a :: q -> list_nil_precedes q let rec list_is_suffix_of_precedes (#t0 #t: Type) (v0: t0) (small large: list t) : Lemma (requires ( large << v0 /\ small `list_is_suffix_of` large )) (ensures ( small << v0 )) (decreases (List.Tot.length large)) [SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]] = if Nil? small then list_nil_precedes large else begin let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in List.Tot.append_length prefix small; if List.Tot.length small = List.Tot.length large then () else list_is_suffix_of_precedes v0 small (List.Tot.tl large) end [@@erasable; noextract_to "krml"] let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with | None -> True | Some l' -> opt_precedes l' bound )) noextract let array_group3_equiv #b (g1 g2: array_group3 b) : Tot prop = forall l . g1 l == g2 l let array_group3_always_false #b : array_group3 b = fun _ -> None let array_group3_empty #b : array_group3 b = fun x -> Some x let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b = (fun l -> match a1 l with | None -> None | Some l3 -> a3 l3 ) let array_group3_concat_equiv #b (a1 a1' a2 a2' : array_group3 b) : Lemma (requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2'))) (ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2'))) = () let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b = fun l -> match a1 l with | None -> a3 l | Some l3 -> Some l3 let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b)) (decreases (List.Tot.length l)) = match a l with | None -> Some l | Some l' -> if List.Tot.length l' >= List.Tot.length l then Some l else array_group3_zero_or_more' a l' let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more' let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b = a `array_group3_concat` array_group3_zero_or_more a let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) = a `array_group3_choice` array_group3_empty let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l -> match l with | [] -> None | a :: q -> if t a then Some q else None let array_group3_item_equiv #b (t1 t2: bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t2)) (ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2)) = () let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b) (l: list Cbor.raw_data_item {opt_precedes l b}) : GTot bool = match a l with | Some l' -> Nil? l' | _ -> false let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x -> Cbor.Array? x && match_array_group3 a (Cbor.Array?.v x) let t_array3_equiv #b (a1 a2: array_group3 b) : Lemma (requires (array_group3_equiv a1 a2)) (ensures (typ_equiv (t_array3 a1) (t_array3 a2))) = () // Recursive type (needed by COSE Section 5.1 "Recipient") // Inspiring from Barthe et al., Type-Based Termination with Sized // Products (CSL 2008): we allow recursion only at the level of // destructors. In other words, instead of having a generic recursion // combinator, we provide a recursion-enabled version only for each // destructor combinator. We need to annotate it with a bound b (akin // to the "size" annotation in a sized type.) let rec t_array3_rec (phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b))) (x: Cbor.raw_data_item) : GTot bool (decreases x) = Cbor.Array? x && match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x) // Groups in map context (Section 3.5) [@@erasable] noeq type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b module Pull = FStar.Ghost.Pull noextract let opt_map_entry_bounded' (b: option Cbor.raw_data_item) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) : GTot bool = FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b) let opt_map_entry_bounded (b: option Cbor.raw_data_item) : GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool) = Pull.pull (opt_map_entry_bounded' b) let rec opt_precedes_map_for_all_opt_map_entry_bounded (b: option Cbor.raw_data_item) (l: list (Cbor.raw_data_item & Cbor.raw_data_item)) : Lemma (requires (opt_precedes l b)) (ensures (List.Tot.for_all (opt_map_entry_bounded b) l)) [SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)] = match l with | [] -> () | _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q let matches_map_group_entry (#b: option Cbor.raw_data_item) (ge: map_group_entry b) (x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true }) : GTot bool = ge.fst (fst x) && ge.snd (snd x) [@@erasable] noeq type map_group (b: option Cbor.raw_data_item) = { one: list (map_group_entry b); zero_or_one: list (map_group_entry b); zero_or_more: list (map_group_entry b); } let map_group_empty #b : map_group b = { one = []; zero_or_one = []; zero_or_more = []; } let cut_map_group_entry_key #b (key: bounded_typ_gen b) (t: bounded_typ_gen b) (x: Cbor.raw_data_item { opt_precedes x b }) : GTot bool = t x && not (key x) // Section 3.5.4: Cut let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b = cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = { one = List.Tot.map (cut_map_group_entry key) g.one; zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one; zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more; } let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = if cut then cut_map_group (ge.fst) g else g let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with one = ge :: g.one; } let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_one = ge :: g.zero_or_one; } let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_more = ge :: g.zero_or_more; } val matches_map_group (#b: option Cbor.raw_data_item) (m: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x }) : GTot bool val matches_map_group_empty (b: option Cbor.raw_data_item) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (ensures (matches_map_group (map_group_empty #b) x == Nil? x)) [SMTPat (matches_map_group (map_group_empty #b) x)] (* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *) noextract let is_sub_map_group_of #b (small large: map_group b) : Tot prop = forall x . matches_map_group small x ==> matches_map_group large x noextract let map_group_equiv #b (mg1 mg2: map_group b) : Tot prop = forall x . matches_map_group mg1 x == matches_map_group mg2 x noextract let is_sub_typ_of #b (small large: bounded_typ_gen b) : Tot prop = forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x noextract let is_sub_map_group_entry_of #b (small large: map_group_entry b) : Tot prop = small.fst `is_sub_typ_of` large.fst /\ small.snd `is_sub_typ_of` large.snd let map_group_ignore_restricted_entries #b (mg: map_group b) : Tot (map_group b) = {mg with one = []; zero_or_one = []; } let pull_rel (#t1 #t2: Type) (r: t1 -> t2 -> prop) (x1: t1) : GTot ((x2: t2) -> Tot bool) = Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2)) let list_ghost_forall_exists_body (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l2: list t2) : GTot (t1 -> bool) = Pull.pull (fun x1 -> List.Tot.existsb (pull_rel r x1) l2 ) let list_ghost_forall_exists (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l1: list t1) (l2: list t2) : GTot bool = List.Tot.for_all (list_ghost_forall_exists_body r l2) l1 noextract let matches_map_group_entry' (#b: _) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) (y: map_group_entry b) : Tot prop = opt_map_entry_bounded b x ==> matches_map_group_entry y x val matches_map_group_no_restricted (#b: _) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires ( Nil? g.one /\ Nil? g.zero_or_one )) (ensures ( matches_map_group g x <==> list_ghost_forall_exists matches_map_group_entry' x g.zero_or_more )) [SMTPat (matches_map_group g x)] let rec list_ghost_forall2 (#t1 #t2: Type) (f: t1 -> t2 -> GTot prop) (l1: list t1) (l2: list t2) : GTot bool (decreases l1) = match l1, l2 with | [], [] -> true | a1 :: q1, a2 :: q2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (f a1 a2) && list_ghost_forall2 f q1 q2 | _ -> false val list_ghost_forall_exists_is_sub_map_group_entry_of_refl (#b: _) (l: list (map_group_entry b)) : Lemma (ensures (list_ghost_forall_exists is_sub_map_group_entry_of l l)) [SMTPat (list_ghost_forall_exists is_sub_map_group_entry_of l l)] let map_group_included_zero_or_more #b (small large: map_group b) : GTot bool = list_ghost_forall_exists is_sub_map_group_entry_of small.one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_more large.zero_or_more && Nil? large.one val map_group_included_zero_or_more_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_zero_or_more small large)) (ensures (is_sub_map_group_of small large)) val map_group_ignore_restricted_entries_sub (#b: _) (mg: map_group b) : Lemma (requires ( list_ghost_forall_exists is_sub_map_group_entry_of mg.one mg.zero_or_more /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( mg `is_sub_map_group_of` map_group_ignore_restricted_entries mg )) let map_group_ignore_restricted_entries_no_one_equiv #b (mg: map_group b) : Lemma (requires ( Nil? mg.one /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( map_group_equiv mg (map_group_ignore_restricted_entries mg) )) = map_group_ignore_restricted_entries_sub mg; map_group_included_zero_or_more_correct (map_group_ignore_restricted_entries mg) mg let map_group_included_pointwise #b (small large: map_group b) : GTot bool = list_ghost_forall2 is_sub_map_group_entry_of small.one large.one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_one large.zero_or_one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_more large.zero_or_more val map_group_included_pointwise_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_pointwise small large)) (ensures (is_sub_map_group_of small large)) let rec list_ghost_forall2_map_l (#t1 #t2: Type) (r: t1 -> t2 -> prop) (f: t2 -> t1) (l: list t2) : Lemma (requires (forall x . r (f x) x)) (ensures (list_ghost_forall2 r (List.Tot.map f l) l)) = match l with | [] -> () | _ :: q -> list_ghost_forall2_map_l r f q let rec list_ghost_forall2_map_r (#t1 #t2: Type) (r: t1 -> t2 -> prop) (f: t1 -> t2) (l: list t1) : Lemma (requires (forall x . r x (f x))) (ensures (list_ghost_forall2 r l (List.Tot.map f l))) = match l with | [] -> () | _ :: q -> list_ghost_forall2_map_r r f q let cut_map_group_sub #b (key: bounded_typ_gen b) (mg: map_group b) : Lemma (cut_map_group key mg `is_sub_map_group_of` mg) = list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.one; list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_one; list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_more; map_group_included_pointwise_correct (cut_map_group key mg) mg (* Proving matches_map_group for sorted maps and map groups where key constraints specify whole elements *) let rec list_for_all_filter_invariant (#t: Type) (p: t -> bool) (f: t -> bool) (l: list t) : Lemma (requires (List.Tot.for_all p l == true)) (ensures (List.Tot.for_all p (List.Tot.filter f l) == true)) [SMTPat (List.Tot.for_all p (List.Tot.filter f l))] = match l with | [] -> () | _ :: q -> list_for_all_filter_invariant p f q let map_key_neq' (#t1 t2: Type) (k: t1) (x: (t1 & t2)) : GTot bool = FStar.StrongExcludedMiddle.strong_excluded_middle (~ (fst x == k)) let map_key_neq (#t1 t2: Type) (k: t1) : GTot ((t1 & t2) -> bool) = Pull.pull (map_key_neq' t2 k) let map_group_entry_for #b (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) : Tot (map_group_entry b) = MapGroupEntry (coerce_to_bounded_typ _ (t_literal k)) ty let rec list_ghost_assoc_for_all (#key: Type) (#value: Type) (p: (key & value) -> bool) (k: key) (m: list (key & value)) : Lemma (requires (List.Tot.for_all p m == true)) (ensures (match Cbor.list_ghost_assoc k m with | None -> True | Some y -> p (k, y) )) (decreases m) [SMTPat (List.Tot.for_all p m); SMTPat (Cbor.list_ghost_assoc k m)] = match m with | [] -> () | (k', _) :: m' -> if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k') then () else list_ghost_assoc_for_all p k m' let rec list_assoc_none_for_all_map_key_neq (k: Cbor.raw_data_item) (l: list (Cbor.raw_data_item & Cbor.raw_data_item)) : Lemma (requires (None? (Cbor.list_ghost_assoc k l))) (ensures (List.Tot.for_all (map_key_neq _ k) l == true)) = match l with | [] -> () | _ :: q -> list_assoc_none_for_all_map_key_neq k q val matches_map_group_map_group_cons_zero_or_one_no_repeats (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.no_repeats_p (List.Tot.map fst x))) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b end /\ matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> matches_map_group g x | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) val matches_map_group_map_group_cons_one_no_repeats (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.no_repeats_p (List.Tot.map fst x))) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b end /\ matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> false | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) val matches_map_group_map_group_cons_zero_or_one_deterministically_encoded_cbor_map_key_order (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) x)) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b /\ List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) (List.Tot.filter (map_key_neq _ k) x) end /\ matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> matches_map_group g x | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) [SMTPat (matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x)] val matches_map_group_map_group_cons_one_deterministically_encoded_cbor_map_key_order (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) x)) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b /\ List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) (List.Tot.filter (map_key_neq _ k) x) end /\ matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> false | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) [SMTPat (matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x)] // 2.1 specifies "names that turn into the map key text string" noextract let string64 = (s: Seq.seq U8.t {FStar.UInt.fits (Seq.length s) 64}) let name_as_text_string (s: string64) : typ = t_literal (Cbor.String Cbor.cbor_major_type_text_string s)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt.fsti.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.Pull.fsti.checked", "CBOR.Spec.fsti.checked" ], "interface_file": false, "source_file": "CDDL.Spec.fsti" }
[ { "abbrev": true, "full_module": "FStar.Ghost.Pull", "short_module": "Pull" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "CBOR.Spec", "short_module": "Cbor" }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
m: CDDL.Spec.map_group b -> CDDL.Spec.bounded_typ_gen b
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.option", "CBOR.Spec.Type.raw_data_item", "CDDL.Spec.map_group", "CDDL.Spec.opt_precedes", "Prims.op_AmpAmp", "CBOR.Spec.Type.uu___is_Map", "CDDL.Spec.matches_map_group", "CBOR.Spec.Type.__proj__Map__item__v", "Prims.bool", "CDDL.Spec.bounded_typ_gen" ]
[]
false
false
false
false
false
let t_map (#b: option Cbor.raw_data_item) (m: map_group b) : bounded_typ_gen b =
fun x -> Cbor.Map? x && matches_map_group m (Cbor.Map?.v x)
false
CDDL.Spec.fsti
CDDL.Spec.uint_size
val uint_size (sz: nat) : typ
val uint_size (sz: nat) : typ
let uint_size (sz: nat) : typ = fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64 && U64.v (Cbor.Int64?.v x) < pow2 sz
{ "file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 35, "end_line": 854, "start_col": 0, "start_line": 851 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module CDDL.Spec module Cbor = CBOR.Spec module U8 = FStar.UInt8 module U64 = FStar.UInt64 // Concise Data Definition Language (RFC 8610) noextract let opt_precedes (#t1 #t2: Type) (x1: t1) (x2: option t2) : Tot prop = match x2 with | None -> True | Some x2 -> x1 << x2 [@@noextract_to "krml"] let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization) [@@noextract_to "krml"] let typ = bounded_typ_gen None [@@noextract_to "krml"] let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e) let coerce_to_bounded_typ (b: option Cbor.raw_data_item) (t: typ) : Tot (bounded_typ_gen b) = t noextract let typ_equiv (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : Tot prop = forall x . t1 x == t2 x let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x) let t_choice_equiv #b (t1 t1' t2 t2' : bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2')) (ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2'))) = () // etc. let t_choice_simpl #b (t: bounded_typ_gen b) : Lemma ((t `t_choice` t) `typ_equiv` t) = () let t_always_false : typ = (fun _ -> false) let t_literal (i: Cbor.raw_data_item) : typ = (fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i)) // Appendix D let any : typ = (fun _ -> true) let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64) let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64) let t_int : typ = uint `t_choice` nint let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string) let bytes = bstr let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string) let text = tstr [@@CMacro] let simple_value_false : Cbor.simple_value = 20uy [@@CMacro] let simple_value_true : Cbor.simple_value = 21uy [@@CMacro] let simple_value_nil : Cbor.simple_value = 22uy [@@CMacro] let simple_value_undefined : Cbor.simple_value = 23uy let t_simple_value_literal (s: Cbor.simple_value) : typ = t_literal (Cbor.Simple s) let t_false : typ = t_simple_value_literal simple_value_false let t_true : typ = t_simple_value_literal simple_value_true let t_bool : typ = t_choice t_false t_true let t_nil : typ = t_simple_value_literal simple_value_nil let t_null : typ = t_nil let t_undefined : typ = t_simple_value_literal simple_value_undefined let t_uint_literal (v: U64.t) : typ = t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v) // Section 2.1: Groups // Groups in array context (Section 3.4) // General semantics, which would imply backtracking [@@erasable; noextract_to "krml"] let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool) let array_group1_empty : array_group1 = fun k -> k let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k) let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) = k l || a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more' let array_group1_item (t: typ) : array_group1 = fun k l -> match l with | [] -> false | a :: q -> t a && k q let t_array1 (a: array_group1) : typ = fun x -> Cbor.Array? x && a Nil? (Cbor.Array?.v x) [@@noextract_to "krml"] let nat_up_to (n: nat) : eqtype = (i: nat { i <= n }) [@@noextract_to "krml"] let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l))) [@@noextract_to "krml"] let array_group2_empty : array_group2 = (fun _ i -> [i]) [@@noextract_to "krml"] let array_group2_concat (a1 a2: array_group2) : array_group2 = (fun l i1 -> let res1 = a1 l i1 in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1 ) [@@noextract_to "krml"] let array_group2_choice (a1 a2: array_group2) : array_group2 = fun l i -> a1 l i `List.Tot.append` a2 l i [@@noextract_to "krml"] let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) = i :: begin let r1 = a l i in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> if i2 <= i then [] else array_group2_zero_or_more' a l i2 ) r1 end (* [@@noextract_to "krml"] let array_group2_item (t: typ) : array_group2 = fun l i -> if i = Seq.length l then [] else if t (Seq.index l i) then [i + 1] else [] *) [@@noextract_to "krml"] let t_array2 (a: array_group2) : typ = fun x -> Cbor.Array? x && begin let l = Cbor.Array?.v x in List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0 end // Greedy semantics (Appendix A?) let list_is_suffix_of (#t: Type) (small large: list t) : Tot prop = exists prefix . large == prefix `List.Tot.append` small let list_is_suffix_of_refl (#t: Type) (l: list t) : Lemma (l `list_is_suffix_of` l) [SMTPat (l `list_is_suffix_of` l)] = assert (l == [] `List.Tot.append` l) let rec list_nil_precedes (#t: Type) (l: list t) : Lemma (Nil #t == l \/ Nil #t << l) = match l with | [] -> () | a :: q -> list_nil_precedes q let rec list_is_suffix_of_precedes (#t0 #t: Type) (v0: t0) (small large: list t) : Lemma (requires ( large << v0 /\ small `list_is_suffix_of` large )) (ensures ( small << v0 )) (decreases (List.Tot.length large)) [SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]] = if Nil? small then list_nil_precedes large else begin let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in List.Tot.append_length prefix small; if List.Tot.length small = List.Tot.length large then () else list_is_suffix_of_precedes v0 small (List.Tot.tl large) end [@@erasable; noextract_to "krml"] let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with | None -> True | Some l' -> opt_precedes l' bound )) noextract let array_group3_equiv #b (g1 g2: array_group3 b) : Tot prop = forall l . g1 l == g2 l let array_group3_always_false #b : array_group3 b = fun _ -> None let array_group3_empty #b : array_group3 b = fun x -> Some x let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b = (fun l -> match a1 l with | None -> None | Some l3 -> a3 l3 ) let array_group3_concat_equiv #b (a1 a1' a2 a2' : array_group3 b) : Lemma (requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2'))) (ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2'))) = () let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b = fun l -> match a1 l with | None -> a3 l | Some l3 -> Some l3 let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b)) (decreases (List.Tot.length l)) = match a l with | None -> Some l | Some l' -> if List.Tot.length l' >= List.Tot.length l then Some l else array_group3_zero_or_more' a l' let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more' let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b = a `array_group3_concat` array_group3_zero_or_more a let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) = a `array_group3_choice` array_group3_empty let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l -> match l with | [] -> None | a :: q -> if t a then Some q else None let array_group3_item_equiv #b (t1 t2: bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t2)) (ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2)) = () let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b) (l: list Cbor.raw_data_item {opt_precedes l b}) : GTot bool = match a l with | Some l' -> Nil? l' | _ -> false let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x -> Cbor.Array? x && match_array_group3 a (Cbor.Array?.v x) let t_array3_equiv #b (a1 a2: array_group3 b) : Lemma (requires (array_group3_equiv a1 a2)) (ensures (typ_equiv (t_array3 a1) (t_array3 a2))) = () // Recursive type (needed by COSE Section 5.1 "Recipient") // Inspiring from Barthe et al., Type-Based Termination with Sized // Products (CSL 2008): we allow recursion only at the level of // destructors. In other words, instead of having a generic recursion // combinator, we provide a recursion-enabled version only for each // destructor combinator. We need to annotate it with a bound b (akin // to the "size" annotation in a sized type.) let rec t_array3_rec (phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b))) (x: Cbor.raw_data_item) : GTot bool (decreases x) = Cbor.Array? x && match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x) // Groups in map context (Section 3.5) [@@erasable] noeq type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b module Pull = FStar.Ghost.Pull noextract let opt_map_entry_bounded' (b: option Cbor.raw_data_item) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) : GTot bool = FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b) let opt_map_entry_bounded (b: option Cbor.raw_data_item) : GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool) = Pull.pull (opt_map_entry_bounded' b) let rec opt_precedes_map_for_all_opt_map_entry_bounded (b: option Cbor.raw_data_item) (l: list (Cbor.raw_data_item & Cbor.raw_data_item)) : Lemma (requires (opt_precedes l b)) (ensures (List.Tot.for_all (opt_map_entry_bounded b) l)) [SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)] = match l with | [] -> () | _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q let matches_map_group_entry (#b: option Cbor.raw_data_item) (ge: map_group_entry b) (x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true }) : GTot bool = ge.fst (fst x) && ge.snd (snd x) [@@erasable] noeq type map_group (b: option Cbor.raw_data_item) = { one: list (map_group_entry b); zero_or_one: list (map_group_entry b); zero_or_more: list (map_group_entry b); } let map_group_empty #b : map_group b = { one = []; zero_or_one = []; zero_or_more = []; } let cut_map_group_entry_key #b (key: bounded_typ_gen b) (t: bounded_typ_gen b) (x: Cbor.raw_data_item { opt_precedes x b }) : GTot bool = t x && not (key x) // Section 3.5.4: Cut let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b = cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = { one = List.Tot.map (cut_map_group_entry key) g.one; zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one; zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more; } let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = if cut then cut_map_group (ge.fst) g else g let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with one = ge :: g.one; } let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_one = ge :: g.zero_or_one; } let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_more = ge :: g.zero_or_more; } val matches_map_group (#b: option Cbor.raw_data_item) (m: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x }) : GTot bool val matches_map_group_empty (b: option Cbor.raw_data_item) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (ensures (matches_map_group (map_group_empty #b) x == Nil? x)) [SMTPat (matches_map_group (map_group_empty #b) x)] (* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *) noextract let is_sub_map_group_of #b (small large: map_group b) : Tot prop = forall x . matches_map_group small x ==> matches_map_group large x noextract let map_group_equiv #b (mg1 mg2: map_group b) : Tot prop = forall x . matches_map_group mg1 x == matches_map_group mg2 x noextract let is_sub_typ_of #b (small large: bounded_typ_gen b) : Tot prop = forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x noextract let is_sub_map_group_entry_of #b (small large: map_group_entry b) : Tot prop = small.fst `is_sub_typ_of` large.fst /\ small.snd `is_sub_typ_of` large.snd let map_group_ignore_restricted_entries #b (mg: map_group b) : Tot (map_group b) = {mg with one = []; zero_or_one = []; } let pull_rel (#t1 #t2: Type) (r: t1 -> t2 -> prop) (x1: t1) : GTot ((x2: t2) -> Tot bool) = Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2)) let list_ghost_forall_exists_body (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l2: list t2) : GTot (t1 -> bool) = Pull.pull (fun x1 -> List.Tot.existsb (pull_rel r x1) l2 ) let list_ghost_forall_exists (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l1: list t1) (l2: list t2) : GTot bool = List.Tot.for_all (list_ghost_forall_exists_body r l2) l1 noextract let matches_map_group_entry' (#b: _) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) (y: map_group_entry b) : Tot prop = opt_map_entry_bounded b x ==> matches_map_group_entry y x val matches_map_group_no_restricted (#b: _) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires ( Nil? g.one /\ Nil? g.zero_or_one )) (ensures ( matches_map_group g x <==> list_ghost_forall_exists matches_map_group_entry' x g.zero_or_more )) [SMTPat (matches_map_group g x)] let rec list_ghost_forall2 (#t1 #t2: Type) (f: t1 -> t2 -> GTot prop) (l1: list t1) (l2: list t2) : GTot bool (decreases l1) = match l1, l2 with | [], [] -> true | a1 :: q1, a2 :: q2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (f a1 a2) && list_ghost_forall2 f q1 q2 | _ -> false val list_ghost_forall_exists_is_sub_map_group_entry_of_refl (#b: _) (l: list (map_group_entry b)) : Lemma (ensures (list_ghost_forall_exists is_sub_map_group_entry_of l l)) [SMTPat (list_ghost_forall_exists is_sub_map_group_entry_of l l)] let map_group_included_zero_or_more #b (small large: map_group b) : GTot bool = list_ghost_forall_exists is_sub_map_group_entry_of small.one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_more large.zero_or_more && Nil? large.one val map_group_included_zero_or_more_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_zero_or_more small large)) (ensures (is_sub_map_group_of small large)) val map_group_ignore_restricted_entries_sub (#b: _) (mg: map_group b) : Lemma (requires ( list_ghost_forall_exists is_sub_map_group_entry_of mg.one mg.zero_or_more /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( mg `is_sub_map_group_of` map_group_ignore_restricted_entries mg )) let map_group_ignore_restricted_entries_no_one_equiv #b (mg: map_group b) : Lemma (requires ( Nil? mg.one /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( map_group_equiv mg (map_group_ignore_restricted_entries mg) )) = map_group_ignore_restricted_entries_sub mg; map_group_included_zero_or_more_correct (map_group_ignore_restricted_entries mg) mg let map_group_included_pointwise #b (small large: map_group b) : GTot bool = list_ghost_forall2 is_sub_map_group_entry_of small.one large.one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_one large.zero_or_one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_more large.zero_or_more val map_group_included_pointwise_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_pointwise small large)) (ensures (is_sub_map_group_of small large)) let rec list_ghost_forall2_map_l (#t1 #t2: Type) (r: t1 -> t2 -> prop) (f: t2 -> t1) (l: list t2) : Lemma (requires (forall x . r (f x) x)) (ensures (list_ghost_forall2 r (List.Tot.map f l) l)) = match l with | [] -> () | _ :: q -> list_ghost_forall2_map_l r f q let rec list_ghost_forall2_map_r (#t1 #t2: Type) (r: t1 -> t2 -> prop) (f: t1 -> t2) (l: list t1) : Lemma (requires (forall x . r x (f x))) (ensures (list_ghost_forall2 r l (List.Tot.map f l))) = match l with | [] -> () | _ :: q -> list_ghost_forall2_map_r r f q let cut_map_group_sub #b (key: bounded_typ_gen b) (mg: map_group b) : Lemma (cut_map_group key mg `is_sub_map_group_of` mg) = list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.one; list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_one; list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_more; map_group_included_pointwise_correct (cut_map_group key mg) mg (* Proving matches_map_group for sorted maps and map groups where key constraints specify whole elements *) let rec list_for_all_filter_invariant (#t: Type) (p: t -> bool) (f: t -> bool) (l: list t) : Lemma (requires (List.Tot.for_all p l == true)) (ensures (List.Tot.for_all p (List.Tot.filter f l) == true)) [SMTPat (List.Tot.for_all p (List.Tot.filter f l))] = match l with | [] -> () | _ :: q -> list_for_all_filter_invariant p f q let map_key_neq' (#t1 t2: Type) (k: t1) (x: (t1 & t2)) : GTot bool = FStar.StrongExcludedMiddle.strong_excluded_middle (~ (fst x == k)) let map_key_neq (#t1 t2: Type) (k: t1) : GTot ((t1 & t2) -> bool) = Pull.pull (map_key_neq' t2 k) let map_group_entry_for #b (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) : Tot (map_group_entry b) = MapGroupEntry (coerce_to_bounded_typ _ (t_literal k)) ty let rec list_ghost_assoc_for_all (#key: Type) (#value: Type) (p: (key & value) -> bool) (k: key) (m: list (key & value)) : Lemma (requires (List.Tot.for_all p m == true)) (ensures (match Cbor.list_ghost_assoc k m with | None -> True | Some y -> p (k, y) )) (decreases m) [SMTPat (List.Tot.for_all p m); SMTPat (Cbor.list_ghost_assoc k m)] = match m with | [] -> () | (k', _) :: m' -> if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k') then () else list_ghost_assoc_for_all p k m' let rec list_assoc_none_for_all_map_key_neq (k: Cbor.raw_data_item) (l: list (Cbor.raw_data_item & Cbor.raw_data_item)) : Lemma (requires (None? (Cbor.list_ghost_assoc k l))) (ensures (List.Tot.for_all (map_key_neq _ k) l == true)) = match l with | [] -> () | _ :: q -> list_assoc_none_for_all_map_key_neq k q val matches_map_group_map_group_cons_zero_or_one_no_repeats (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.no_repeats_p (List.Tot.map fst x))) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b end /\ matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> matches_map_group g x | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) val matches_map_group_map_group_cons_one_no_repeats (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.no_repeats_p (List.Tot.map fst x))) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b end /\ matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> false | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) val matches_map_group_map_group_cons_zero_or_one_deterministically_encoded_cbor_map_key_order (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) x)) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b /\ List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) (List.Tot.filter (map_key_neq _ k) x) end /\ matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> matches_map_group g x | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) [SMTPat (matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x)] val matches_map_group_map_group_cons_one_deterministically_encoded_cbor_map_key_order (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) x)) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b /\ List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) (List.Tot.filter (map_key_neq _ k) x) end /\ matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> false | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) [SMTPat (matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x)] // 2.1 specifies "names that turn into the map key text string" noextract let string64 = (s: Seq.seq U8.t {FStar.UInt.fits (Seq.length s) 64}) let name_as_text_string (s: string64) : typ = t_literal (Cbor.String Cbor.cbor_major_type_text_string s) let t_map (#b: option Cbor.raw_data_item) (m: map_group b) : bounded_typ_gen b = fun x -> Cbor.Map? x && matches_map_group m (Cbor.Map?.v x) let t_map_equiv #b (m1 m2: map_group b) : Lemma (requires (map_group_equiv m1 m2)) (ensures (typ_equiv (t_map m1) (t_map m2))) = () let rec t_map_rec (phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> map_group (Some b))) (x: Cbor.raw_data_item) : GTot bool (decreases x) = Cbor.Map? x && matches_map_group (phi x (t_map_rec phi)) (Cbor.Map?.v x) // Section 3.6: Tags let t_tag (#b: option Cbor.raw_data_item) (tag: U64.t) (t: bounded_typ_gen b) : bounded_typ_gen b = fun x -> Cbor.Tagged? x && Cbor.Tagged?.tag x = tag && t (Cbor.Tagged?.v x) let rec t_tag_rec (tag: U64.t) (phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> bounded_typ b)) (x: Cbor.raw_data_item) : GTot bool (decreases x) = Cbor.Tagged? x && Cbor.Tagged?.tag x = tag && phi x (t_tag_rec tag phi) (Cbor.Tagged?.v x) // Multi-purpose recursive combinator, to allow disjunctions between destructors let rec multi_rec (phi_base: typ) (phi_array: (b: Cbor.raw_data_item) -> bounded_typ b -> array_group3 (Some b)) (phi_map: (b: Cbor.raw_data_item) -> bounded_typ b -> map_group (Some b)) (phi_tag: U64.t -> (b: Cbor.raw_data_item) -> bounded_typ b -> bounded_typ b) (x: Cbor.raw_data_item) : GTot bool (decreases x) = phi_base x || begin match x with | Cbor.Array v -> match_array_group3 (phi_array x (multi_rec phi_base phi_array phi_map phi_tag)) v | Cbor.Map v -> matches_map_group (phi_map x (multi_rec phi_base phi_array phi_map phi_tag)) v | Cbor.Tagged tag v -> phi_tag tag x (multi_rec phi_base phi_array phi_map phi_tag) v | _ -> false end // Section 3.8.1: Control .size let str_size (ty: Cbor.major_type_byte_string_or_text_string) (sz: nat) : typ = fun x -> Cbor.String? x && Cbor.String?.typ x = ty && Seq.length (Cbor.String?.v x) = sz
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt.fsti.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.Pull.fsti.checked", "CBOR.Spec.fsti.checked" ], "interface_file": false, "source_file": "CDDL.Spec.fsti" }
[ { "abbrev": true, "full_module": "FStar.Ghost.Pull", "short_module": "Pull" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "CBOR.Spec", "short_module": "Cbor" }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
sz: Prims.nat -> CDDL.Spec.typ
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "CBOR.Spec.Type.raw_data_item", "CDDL.Spec.opt_precedes", "FStar.Pervasives.Native.None", "Prims.op_AmpAmp", "CBOR.Spec.Type.uu___is_Int64", "Prims.op_Equality", "CBOR.Spec.Constants.major_type_t", "CBOR.Spec.Type.__proj__Int64__item__typ", "CBOR.Spec.Constants.cbor_major_type_uint64", "Prims.op_LessThan", "FStar.UInt64.v", "CBOR.Spec.Type.__proj__Int64__item__v", "Prims.pow2", "Prims.bool", "CDDL.Spec.typ" ]
[]
false
false
false
true
false
let uint_size (sz: nat) : typ =
fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64 && U64.v (Cbor.Int64?.v x) < pow2 sz
false
CDDL.Spec.fsti
CDDL.Spec.t_tag
val t_tag (#b: option Cbor.raw_data_item) (tag: U64.t) (t: bounded_typ_gen b) : bounded_typ_gen b
val t_tag (#b: option Cbor.raw_data_item) (tag: U64.t) (t: bounded_typ_gen b) : bounded_typ_gen b
let t_tag (#b: option Cbor.raw_data_item) (tag: U64.t) (t: bounded_typ_gen b) : bounded_typ_gen b = fun x -> Cbor.Tagged? x && Cbor.Tagged?.tag x = tag && t (Cbor.Tagged?.v x)
{ "file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 22, "end_line": 811, "start_col": 0, "start_line": 808 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module CDDL.Spec module Cbor = CBOR.Spec module U8 = FStar.UInt8 module U64 = FStar.UInt64 // Concise Data Definition Language (RFC 8610) noextract let opt_precedes (#t1 #t2: Type) (x1: t1) (x2: option t2) : Tot prop = match x2 with | None -> True | Some x2 -> x1 << x2 [@@noextract_to "krml"] let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization) [@@noextract_to "krml"] let typ = bounded_typ_gen None [@@noextract_to "krml"] let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e) let coerce_to_bounded_typ (b: option Cbor.raw_data_item) (t: typ) : Tot (bounded_typ_gen b) = t noextract let typ_equiv (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : Tot prop = forall x . t1 x == t2 x let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x) let t_choice_equiv #b (t1 t1' t2 t2' : bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2')) (ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2'))) = () // etc. let t_choice_simpl #b (t: bounded_typ_gen b) : Lemma ((t `t_choice` t) `typ_equiv` t) = () let t_always_false : typ = (fun _ -> false) let t_literal (i: Cbor.raw_data_item) : typ = (fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i)) // Appendix D let any : typ = (fun _ -> true) let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64) let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64) let t_int : typ = uint `t_choice` nint let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string) let bytes = bstr let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string) let text = tstr [@@CMacro] let simple_value_false : Cbor.simple_value = 20uy [@@CMacro] let simple_value_true : Cbor.simple_value = 21uy [@@CMacro] let simple_value_nil : Cbor.simple_value = 22uy [@@CMacro] let simple_value_undefined : Cbor.simple_value = 23uy let t_simple_value_literal (s: Cbor.simple_value) : typ = t_literal (Cbor.Simple s) let t_false : typ = t_simple_value_literal simple_value_false let t_true : typ = t_simple_value_literal simple_value_true let t_bool : typ = t_choice t_false t_true let t_nil : typ = t_simple_value_literal simple_value_nil let t_null : typ = t_nil let t_undefined : typ = t_simple_value_literal simple_value_undefined let t_uint_literal (v: U64.t) : typ = t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v) // Section 2.1: Groups // Groups in array context (Section 3.4) // General semantics, which would imply backtracking [@@erasable; noextract_to "krml"] let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool) let array_group1_empty : array_group1 = fun k -> k let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k) let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) = k l || a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more' let array_group1_item (t: typ) : array_group1 = fun k l -> match l with | [] -> false | a :: q -> t a && k q let t_array1 (a: array_group1) : typ = fun x -> Cbor.Array? x && a Nil? (Cbor.Array?.v x) [@@noextract_to "krml"] let nat_up_to (n: nat) : eqtype = (i: nat { i <= n }) [@@noextract_to "krml"] let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l))) [@@noextract_to "krml"] let array_group2_empty : array_group2 = (fun _ i -> [i]) [@@noextract_to "krml"] let array_group2_concat (a1 a2: array_group2) : array_group2 = (fun l i1 -> let res1 = a1 l i1 in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1 ) [@@noextract_to "krml"] let array_group2_choice (a1 a2: array_group2) : array_group2 = fun l i -> a1 l i `List.Tot.append` a2 l i [@@noextract_to "krml"] let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) = i :: begin let r1 = a l i in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> if i2 <= i then [] else array_group2_zero_or_more' a l i2 ) r1 end (* [@@noextract_to "krml"] let array_group2_item (t: typ) : array_group2 = fun l i -> if i = Seq.length l then [] else if t (Seq.index l i) then [i + 1] else [] *) [@@noextract_to "krml"] let t_array2 (a: array_group2) : typ = fun x -> Cbor.Array? x && begin let l = Cbor.Array?.v x in List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0 end // Greedy semantics (Appendix A?) let list_is_suffix_of (#t: Type) (small large: list t) : Tot prop = exists prefix . large == prefix `List.Tot.append` small let list_is_suffix_of_refl (#t: Type) (l: list t) : Lemma (l `list_is_suffix_of` l) [SMTPat (l `list_is_suffix_of` l)] = assert (l == [] `List.Tot.append` l) let rec list_nil_precedes (#t: Type) (l: list t) : Lemma (Nil #t == l \/ Nil #t << l) = match l with | [] -> () | a :: q -> list_nil_precedes q let rec list_is_suffix_of_precedes (#t0 #t: Type) (v0: t0) (small large: list t) : Lemma (requires ( large << v0 /\ small `list_is_suffix_of` large )) (ensures ( small << v0 )) (decreases (List.Tot.length large)) [SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]] = if Nil? small then list_nil_precedes large else begin let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in List.Tot.append_length prefix small; if List.Tot.length small = List.Tot.length large then () else list_is_suffix_of_precedes v0 small (List.Tot.tl large) end [@@erasable; noextract_to "krml"] let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with | None -> True | Some l' -> opt_precedes l' bound )) noextract let array_group3_equiv #b (g1 g2: array_group3 b) : Tot prop = forall l . g1 l == g2 l let array_group3_always_false #b : array_group3 b = fun _ -> None let array_group3_empty #b : array_group3 b = fun x -> Some x let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b = (fun l -> match a1 l with | None -> None | Some l3 -> a3 l3 ) let array_group3_concat_equiv #b (a1 a1' a2 a2' : array_group3 b) : Lemma (requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2'))) (ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2'))) = () let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b = fun l -> match a1 l with | None -> a3 l | Some l3 -> Some l3 let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b)) (decreases (List.Tot.length l)) = match a l with | None -> Some l | Some l' -> if List.Tot.length l' >= List.Tot.length l then Some l else array_group3_zero_or_more' a l' let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more' let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b = a `array_group3_concat` array_group3_zero_or_more a let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) = a `array_group3_choice` array_group3_empty let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l -> match l with | [] -> None | a :: q -> if t a then Some q else None let array_group3_item_equiv #b (t1 t2: bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t2)) (ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2)) = () let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b) (l: list Cbor.raw_data_item {opt_precedes l b}) : GTot bool = match a l with | Some l' -> Nil? l' | _ -> false let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x -> Cbor.Array? x && match_array_group3 a (Cbor.Array?.v x) let t_array3_equiv #b (a1 a2: array_group3 b) : Lemma (requires (array_group3_equiv a1 a2)) (ensures (typ_equiv (t_array3 a1) (t_array3 a2))) = () // Recursive type (needed by COSE Section 5.1 "Recipient") // Inspiring from Barthe et al., Type-Based Termination with Sized // Products (CSL 2008): we allow recursion only at the level of // destructors. In other words, instead of having a generic recursion // combinator, we provide a recursion-enabled version only for each // destructor combinator. We need to annotate it with a bound b (akin // to the "size" annotation in a sized type.) let rec t_array3_rec (phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b))) (x: Cbor.raw_data_item) : GTot bool (decreases x) = Cbor.Array? x && match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x) // Groups in map context (Section 3.5) [@@erasable] noeq type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b module Pull = FStar.Ghost.Pull noextract let opt_map_entry_bounded' (b: option Cbor.raw_data_item) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) : GTot bool = FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b) let opt_map_entry_bounded (b: option Cbor.raw_data_item) : GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool) = Pull.pull (opt_map_entry_bounded' b) let rec opt_precedes_map_for_all_opt_map_entry_bounded (b: option Cbor.raw_data_item) (l: list (Cbor.raw_data_item & Cbor.raw_data_item)) : Lemma (requires (opt_precedes l b)) (ensures (List.Tot.for_all (opt_map_entry_bounded b) l)) [SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)] = match l with | [] -> () | _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q let matches_map_group_entry (#b: option Cbor.raw_data_item) (ge: map_group_entry b) (x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true }) : GTot bool = ge.fst (fst x) && ge.snd (snd x) [@@erasable] noeq type map_group (b: option Cbor.raw_data_item) = { one: list (map_group_entry b); zero_or_one: list (map_group_entry b); zero_or_more: list (map_group_entry b); } let map_group_empty #b : map_group b = { one = []; zero_or_one = []; zero_or_more = []; } let cut_map_group_entry_key #b (key: bounded_typ_gen b) (t: bounded_typ_gen b) (x: Cbor.raw_data_item { opt_precedes x b }) : GTot bool = t x && not (key x) // Section 3.5.4: Cut let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b = cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = { one = List.Tot.map (cut_map_group_entry key) g.one; zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one; zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more; } let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = if cut then cut_map_group (ge.fst) g else g let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with one = ge :: g.one; } let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_one = ge :: g.zero_or_one; } let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_more = ge :: g.zero_or_more; } val matches_map_group (#b: option Cbor.raw_data_item) (m: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x }) : GTot bool val matches_map_group_empty (b: option Cbor.raw_data_item) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (ensures (matches_map_group (map_group_empty #b) x == Nil? x)) [SMTPat (matches_map_group (map_group_empty #b) x)] (* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *) noextract let is_sub_map_group_of #b (small large: map_group b) : Tot prop = forall x . matches_map_group small x ==> matches_map_group large x noextract let map_group_equiv #b (mg1 mg2: map_group b) : Tot prop = forall x . matches_map_group mg1 x == matches_map_group mg2 x noextract let is_sub_typ_of #b (small large: bounded_typ_gen b) : Tot prop = forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x noextract let is_sub_map_group_entry_of #b (small large: map_group_entry b) : Tot prop = small.fst `is_sub_typ_of` large.fst /\ small.snd `is_sub_typ_of` large.snd let map_group_ignore_restricted_entries #b (mg: map_group b) : Tot (map_group b) = {mg with one = []; zero_or_one = []; } let pull_rel (#t1 #t2: Type) (r: t1 -> t2 -> prop) (x1: t1) : GTot ((x2: t2) -> Tot bool) = Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2)) let list_ghost_forall_exists_body (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l2: list t2) : GTot (t1 -> bool) = Pull.pull (fun x1 -> List.Tot.existsb (pull_rel r x1) l2 ) let list_ghost_forall_exists (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l1: list t1) (l2: list t2) : GTot bool = List.Tot.for_all (list_ghost_forall_exists_body r l2) l1 noextract let matches_map_group_entry' (#b: _) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) (y: map_group_entry b) : Tot prop = opt_map_entry_bounded b x ==> matches_map_group_entry y x val matches_map_group_no_restricted (#b: _) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires ( Nil? g.one /\ Nil? g.zero_or_one )) (ensures ( matches_map_group g x <==> list_ghost_forall_exists matches_map_group_entry' x g.zero_or_more )) [SMTPat (matches_map_group g x)] let rec list_ghost_forall2 (#t1 #t2: Type) (f: t1 -> t2 -> GTot prop) (l1: list t1) (l2: list t2) : GTot bool (decreases l1) = match l1, l2 with | [], [] -> true | a1 :: q1, a2 :: q2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (f a1 a2) && list_ghost_forall2 f q1 q2 | _ -> false val list_ghost_forall_exists_is_sub_map_group_entry_of_refl (#b: _) (l: list (map_group_entry b)) : Lemma (ensures (list_ghost_forall_exists is_sub_map_group_entry_of l l)) [SMTPat (list_ghost_forall_exists is_sub_map_group_entry_of l l)] let map_group_included_zero_or_more #b (small large: map_group b) : GTot bool = list_ghost_forall_exists is_sub_map_group_entry_of small.one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_more large.zero_or_more && Nil? large.one val map_group_included_zero_or_more_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_zero_or_more small large)) (ensures (is_sub_map_group_of small large)) val map_group_ignore_restricted_entries_sub (#b: _) (mg: map_group b) : Lemma (requires ( list_ghost_forall_exists is_sub_map_group_entry_of mg.one mg.zero_or_more /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( mg `is_sub_map_group_of` map_group_ignore_restricted_entries mg )) let map_group_ignore_restricted_entries_no_one_equiv #b (mg: map_group b) : Lemma (requires ( Nil? mg.one /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( map_group_equiv mg (map_group_ignore_restricted_entries mg) )) = map_group_ignore_restricted_entries_sub mg; map_group_included_zero_or_more_correct (map_group_ignore_restricted_entries mg) mg let map_group_included_pointwise #b (small large: map_group b) : GTot bool = list_ghost_forall2 is_sub_map_group_entry_of small.one large.one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_one large.zero_or_one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_more large.zero_or_more val map_group_included_pointwise_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_pointwise small large)) (ensures (is_sub_map_group_of small large)) let rec list_ghost_forall2_map_l (#t1 #t2: Type) (r: t1 -> t2 -> prop) (f: t2 -> t1) (l: list t2) : Lemma (requires (forall x . r (f x) x)) (ensures (list_ghost_forall2 r (List.Tot.map f l) l)) = match l with | [] -> () | _ :: q -> list_ghost_forall2_map_l r f q let rec list_ghost_forall2_map_r (#t1 #t2: Type) (r: t1 -> t2 -> prop) (f: t1 -> t2) (l: list t1) : Lemma (requires (forall x . r x (f x))) (ensures (list_ghost_forall2 r l (List.Tot.map f l))) = match l with | [] -> () | _ :: q -> list_ghost_forall2_map_r r f q let cut_map_group_sub #b (key: bounded_typ_gen b) (mg: map_group b) : Lemma (cut_map_group key mg `is_sub_map_group_of` mg) = list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.one; list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_one; list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_more; map_group_included_pointwise_correct (cut_map_group key mg) mg (* Proving matches_map_group for sorted maps and map groups where key constraints specify whole elements *) let rec list_for_all_filter_invariant (#t: Type) (p: t -> bool) (f: t -> bool) (l: list t) : Lemma (requires (List.Tot.for_all p l == true)) (ensures (List.Tot.for_all p (List.Tot.filter f l) == true)) [SMTPat (List.Tot.for_all p (List.Tot.filter f l))] = match l with | [] -> () | _ :: q -> list_for_all_filter_invariant p f q let map_key_neq' (#t1 t2: Type) (k: t1) (x: (t1 & t2)) : GTot bool = FStar.StrongExcludedMiddle.strong_excluded_middle (~ (fst x == k)) let map_key_neq (#t1 t2: Type) (k: t1) : GTot ((t1 & t2) -> bool) = Pull.pull (map_key_neq' t2 k) let map_group_entry_for #b (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) : Tot (map_group_entry b) = MapGroupEntry (coerce_to_bounded_typ _ (t_literal k)) ty let rec list_ghost_assoc_for_all (#key: Type) (#value: Type) (p: (key & value) -> bool) (k: key) (m: list (key & value)) : Lemma (requires (List.Tot.for_all p m == true)) (ensures (match Cbor.list_ghost_assoc k m with | None -> True | Some y -> p (k, y) )) (decreases m) [SMTPat (List.Tot.for_all p m); SMTPat (Cbor.list_ghost_assoc k m)] = match m with | [] -> () | (k', _) :: m' -> if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k') then () else list_ghost_assoc_for_all p k m' let rec list_assoc_none_for_all_map_key_neq (k: Cbor.raw_data_item) (l: list (Cbor.raw_data_item & Cbor.raw_data_item)) : Lemma (requires (None? (Cbor.list_ghost_assoc k l))) (ensures (List.Tot.for_all (map_key_neq _ k) l == true)) = match l with | [] -> () | _ :: q -> list_assoc_none_for_all_map_key_neq k q val matches_map_group_map_group_cons_zero_or_one_no_repeats (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.no_repeats_p (List.Tot.map fst x))) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b end /\ matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> matches_map_group g x | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) val matches_map_group_map_group_cons_one_no_repeats (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.no_repeats_p (List.Tot.map fst x))) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b end /\ matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> false | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) val matches_map_group_map_group_cons_zero_or_one_deterministically_encoded_cbor_map_key_order (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) x)) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b /\ List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) (List.Tot.filter (map_key_neq _ k) x) end /\ matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> matches_map_group g x | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) [SMTPat (matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x)] val matches_map_group_map_group_cons_one_deterministically_encoded_cbor_map_key_order (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) x)) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b /\ List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) (List.Tot.filter (map_key_neq _ k) x) end /\ matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> false | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) [SMTPat (matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x)] // 2.1 specifies "names that turn into the map key text string" noextract let string64 = (s: Seq.seq U8.t {FStar.UInt.fits (Seq.length s) 64}) let name_as_text_string (s: string64) : typ = t_literal (Cbor.String Cbor.cbor_major_type_text_string s) let t_map (#b: option Cbor.raw_data_item) (m: map_group b) : bounded_typ_gen b = fun x -> Cbor.Map? x && matches_map_group m (Cbor.Map?.v x) let t_map_equiv #b (m1 m2: map_group b) : Lemma (requires (map_group_equiv m1 m2)) (ensures (typ_equiv (t_map m1) (t_map m2))) = () let rec t_map_rec (phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> map_group (Some b))) (x: Cbor.raw_data_item) : GTot bool (decreases x) = Cbor.Map? x && matches_map_group (phi x (t_map_rec phi)) (Cbor.Map?.v x) // Section 3.6: Tags
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt.fsti.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.Pull.fsti.checked", "CBOR.Spec.fsti.checked" ], "interface_file": false, "source_file": "CDDL.Spec.fsti" }
[ { "abbrev": true, "full_module": "FStar.Ghost.Pull", "short_module": "Pull" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "CBOR.Spec", "short_module": "Cbor" }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
tag: FStar.UInt64.t -> t: CDDL.Spec.bounded_typ_gen b -> CDDL.Spec.bounded_typ_gen b
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.option", "CBOR.Spec.Type.raw_data_item", "FStar.UInt64.t", "CDDL.Spec.bounded_typ_gen", "CDDL.Spec.opt_precedes", "Prims.op_AmpAmp", "CBOR.Spec.Type.uu___is_Tagged", "Prims.op_Equality", "CBOR.Spec.Type.__proj__Tagged__item__tag", "CBOR.Spec.Type.__proj__Tagged__item__v", "Prims.bool" ]
[]
false
false
false
false
false
let t_tag (#b: option Cbor.raw_data_item) (tag: U64.t) (t: bounded_typ_gen b) : bounded_typ_gen b =
fun x -> Cbor.Tagged? x && Cbor.Tagged?.tag x = tag && t (Cbor.Tagged?.v x)
false
CDDL.Spec.fsti
CDDL.Spec.list_assoc_none_for_all_map_key_neq
val list_assoc_none_for_all_map_key_neq (k: Cbor.raw_data_item) (l: list (Cbor.raw_data_item & Cbor.raw_data_item)) : Lemma (requires (None? (Cbor.list_ghost_assoc k l))) (ensures (List.Tot.for_all (map_key_neq _ k) l == true))
val list_assoc_none_for_all_map_key_neq (k: Cbor.raw_data_item) (l: list (Cbor.raw_data_item & Cbor.raw_data_item)) : Lemma (requires (None? (Cbor.list_ghost_assoc k l))) (ensures (List.Tot.for_all (map_key_neq _ k) l == true))
let rec list_assoc_none_for_all_map_key_neq (k: Cbor.raw_data_item) (l: list (Cbor.raw_data_item & Cbor.raw_data_item)) : Lemma (requires (None? (Cbor.list_ghost_assoc k l))) (ensures (List.Tot.for_all (map_key_neq _ k) l == true)) = match l with | [] -> () | _ :: q -> list_assoc_none_for_all_map_key_neq k q
{ "file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 53, "end_line": 709, "start_col": 0, "start_line": 701 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module CDDL.Spec module Cbor = CBOR.Spec module U8 = FStar.UInt8 module U64 = FStar.UInt64 // Concise Data Definition Language (RFC 8610) noextract let opt_precedes (#t1 #t2: Type) (x1: t1) (x2: option t2) : Tot prop = match x2 with | None -> True | Some x2 -> x1 << x2 [@@noextract_to "krml"] let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization) [@@noextract_to "krml"] let typ = bounded_typ_gen None [@@noextract_to "krml"] let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e) let coerce_to_bounded_typ (b: option Cbor.raw_data_item) (t: typ) : Tot (bounded_typ_gen b) = t noextract let typ_equiv (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : Tot prop = forall x . t1 x == t2 x let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x) let t_choice_equiv #b (t1 t1' t2 t2' : bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2')) (ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2'))) = () // etc. let t_choice_simpl #b (t: bounded_typ_gen b) : Lemma ((t `t_choice` t) `typ_equiv` t) = () let t_always_false : typ = (fun _ -> false) let t_literal (i: Cbor.raw_data_item) : typ = (fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i)) // Appendix D let any : typ = (fun _ -> true) let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64) let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64) let t_int : typ = uint `t_choice` nint let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string) let bytes = bstr let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string) let text = tstr [@@CMacro] let simple_value_false : Cbor.simple_value = 20uy [@@CMacro] let simple_value_true : Cbor.simple_value = 21uy [@@CMacro] let simple_value_nil : Cbor.simple_value = 22uy [@@CMacro] let simple_value_undefined : Cbor.simple_value = 23uy let t_simple_value_literal (s: Cbor.simple_value) : typ = t_literal (Cbor.Simple s) let t_false : typ = t_simple_value_literal simple_value_false let t_true : typ = t_simple_value_literal simple_value_true let t_bool : typ = t_choice t_false t_true let t_nil : typ = t_simple_value_literal simple_value_nil let t_null : typ = t_nil let t_undefined : typ = t_simple_value_literal simple_value_undefined let t_uint_literal (v: U64.t) : typ = t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v) // Section 2.1: Groups // Groups in array context (Section 3.4) // General semantics, which would imply backtracking [@@erasable; noextract_to "krml"] let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool) let array_group1_empty : array_group1 = fun k -> k let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k) let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) = k l || a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more' let array_group1_item (t: typ) : array_group1 = fun k l -> match l with | [] -> false | a :: q -> t a && k q let t_array1 (a: array_group1) : typ = fun x -> Cbor.Array? x && a Nil? (Cbor.Array?.v x) [@@noextract_to "krml"] let nat_up_to (n: nat) : eqtype = (i: nat { i <= n }) [@@noextract_to "krml"] let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l))) [@@noextract_to "krml"] let array_group2_empty : array_group2 = (fun _ i -> [i]) [@@noextract_to "krml"] let array_group2_concat (a1 a2: array_group2) : array_group2 = (fun l i1 -> let res1 = a1 l i1 in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1 ) [@@noextract_to "krml"] let array_group2_choice (a1 a2: array_group2) : array_group2 = fun l i -> a1 l i `List.Tot.append` a2 l i [@@noextract_to "krml"] let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) = i :: begin let r1 = a l i in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> if i2 <= i then [] else array_group2_zero_or_more' a l i2 ) r1 end (* [@@noextract_to "krml"] let array_group2_item (t: typ) : array_group2 = fun l i -> if i = Seq.length l then [] else if t (Seq.index l i) then [i + 1] else [] *) [@@noextract_to "krml"] let t_array2 (a: array_group2) : typ = fun x -> Cbor.Array? x && begin let l = Cbor.Array?.v x in List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0 end // Greedy semantics (Appendix A?) let list_is_suffix_of (#t: Type) (small large: list t) : Tot prop = exists prefix . large == prefix `List.Tot.append` small let list_is_suffix_of_refl (#t: Type) (l: list t) : Lemma (l `list_is_suffix_of` l) [SMTPat (l `list_is_suffix_of` l)] = assert (l == [] `List.Tot.append` l) let rec list_nil_precedes (#t: Type) (l: list t) : Lemma (Nil #t == l \/ Nil #t << l) = match l with | [] -> () | a :: q -> list_nil_precedes q let rec list_is_suffix_of_precedes (#t0 #t: Type) (v0: t0) (small large: list t) : Lemma (requires ( large << v0 /\ small `list_is_suffix_of` large )) (ensures ( small << v0 )) (decreases (List.Tot.length large)) [SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]] = if Nil? small then list_nil_precedes large else begin let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in List.Tot.append_length prefix small; if List.Tot.length small = List.Tot.length large then () else list_is_suffix_of_precedes v0 small (List.Tot.tl large) end [@@erasable; noextract_to "krml"] let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with | None -> True | Some l' -> opt_precedes l' bound )) noextract let array_group3_equiv #b (g1 g2: array_group3 b) : Tot prop = forall l . g1 l == g2 l let array_group3_always_false #b : array_group3 b = fun _ -> None let array_group3_empty #b : array_group3 b = fun x -> Some x let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b = (fun l -> match a1 l with | None -> None | Some l3 -> a3 l3 ) let array_group3_concat_equiv #b (a1 a1' a2 a2' : array_group3 b) : Lemma (requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2'))) (ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2'))) = () let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b = fun l -> match a1 l with | None -> a3 l | Some l3 -> Some l3 let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b)) (decreases (List.Tot.length l)) = match a l with | None -> Some l | Some l' -> if List.Tot.length l' >= List.Tot.length l then Some l else array_group3_zero_or_more' a l' let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more' let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b = a `array_group3_concat` array_group3_zero_or_more a let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) = a `array_group3_choice` array_group3_empty let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l -> match l with | [] -> None | a :: q -> if t a then Some q else None let array_group3_item_equiv #b (t1 t2: bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t2)) (ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2)) = () let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b) (l: list Cbor.raw_data_item {opt_precedes l b}) : GTot bool = match a l with | Some l' -> Nil? l' | _ -> false let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x -> Cbor.Array? x && match_array_group3 a (Cbor.Array?.v x) let t_array3_equiv #b (a1 a2: array_group3 b) : Lemma (requires (array_group3_equiv a1 a2)) (ensures (typ_equiv (t_array3 a1) (t_array3 a2))) = () // Recursive type (needed by COSE Section 5.1 "Recipient") // Inspiring from Barthe et al., Type-Based Termination with Sized // Products (CSL 2008): we allow recursion only at the level of // destructors. In other words, instead of having a generic recursion // combinator, we provide a recursion-enabled version only for each // destructor combinator. We need to annotate it with a bound b (akin // to the "size" annotation in a sized type.) let rec t_array3_rec (phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b))) (x: Cbor.raw_data_item) : GTot bool (decreases x) = Cbor.Array? x && match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x) // Groups in map context (Section 3.5) [@@erasable] noeq type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b module Pull = FStar.Ghost.Pull noextract let opt_map_entry_bounded' (b: option Cbor.raw_data_item) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) : GTot bool = FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b) let opt_map_entry_bounded (b: option Cbor.raw_data_item) : GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool) = Pull.pull (opt_map_entry_bounded' b) let rec opt_precedes_map_for_all_opt_map_entry_bounded (b: option Cbor.raw_data_item) (l: list (Cbor.raw_data_item & Cbor.raw_data_item)) : Lemma (requires (opt_precedes l b)) (ensures (List.Tot.for_all (opt_map_entry_bounded b) l)) [SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)] = match l with | [] -> () | _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q let matches_map_group_entry (#b: option Cbor.raw_data_item) (ge: map_group_entry b) (x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true }) : GTot bool = ge.fst (fst x) && ge.snd (snd x) [@@erasable] noeq type map_group (b: option Cbor.raw_data_item) = { one: list (map_group_entry b); zero_or_one: list (map_group_entry b); zero_or_more: list (map_group_entry b); } let map_group_empty #b : map_group b = { one = []; zero_or_one = []; zero_or_more = []; } let cut_map_group_entry_key #b (key: bounded_typ_gen b) (t: bounded_typ_gen b) (x: Cbor.raw_data_item { opt_precedes x b }) : GTot bool = t x && not (key x) // Section 3.5.4: Cut let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b = cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = { one = List.Tot.map (cut_map_group_entry key) g.one; zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one; zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more; } let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = if cut then cut_map_group (ge.fst) g else g let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with one = ge :: g.one; } let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_one = ge :: g.zero_or_one; } let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_more = ge :: g.zero_or_more; } val matches_map_group (#b: option Cbor.raw_data_item) (m: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x }) : GTot bool val matches_map_group_empty (b: option Cbor.raw_data_item) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (ensures (matches_map_group (map_group_empty #b) x == Nil? x)) [SMTPat (matches_map_group (map_group_empty #b) x)] (* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *) noextract let is_sub_map_group_of #b (small large: map_group b) : Tot prop = forall x . matches_map_group small x ==> matches_map_group large x noextract let map_group_equiv #b (mg1 mg2: map_group b) : Tot prop = forall x . matches_map_group mg1 x == matches_map_group mg2 x noextract let is_sub_typ_of #b (small large: bounded_typ_gen b) : Tot prop = forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x noextract let is_sub_map_group_entry_of #b (small large: map_group_entry b) : Tot prop = small.fst `is_sub_typ_of` large.fst /\ small.snd `is_sub_typ_of` large.snd let map_group_ignore_restricted_entries #b (mg: map_group b) : Tot (map_group b) = {mg with one = []; zero_or_one = []; } let pull_rel (#t1 #t2: Type) (r: t1 -> t2 -> prop) (x1: t1) : GTot ((x2: t2) -> Tot bool) = Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2)) let list_ghost_forall_exists_body (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l2: list t2) : GTot (t1 -> bool) = Pull.pull (fun x1 -> List.Tot.existsb (pull_rel r x1) l2 ) let list_ghost_forall_exists (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l1: list t1) (l2: list t2) : GTot bool = List.Tot.for_all (list_ghost_forall_exists_body r l2) l1 noextract let matches_map_group_entry' (#b: _) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) (y: map_group_entry b) : Tot prop = opt_map_entry_bounded b x ==> matches_map_group_entry y x val matches_map_group_no_restricted (#b: _) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires ( Nil? g.one /\ Nil? g.zero_or_one )) (ensures ( matches_map_group g x <==> list_ghost_forall_exists matches_map_group_entry' x g.zero_or_more )) [SMTPat (matches_map_group g x)] let rec list_ghost_forall2 (#t1 #t2: Type) (f: t1 -> t2 -> GTot prop) (l1: list t1) (l2: list t2) : GTot bool (decreases l1) = match l1, l2 with | [], [] -> true | a1 :: q1, a2 :: q2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (f a1 a2) && list_ghost_forall2 f q1 q2 | _ -> false val list_ghost_forall_exists_is_sub_map_group_entry_of_refl (#b: _) (l: list (map_group_entry b)) : Lemma (ensures (list_ghost_forall_exists is_sub_map_group_entry_of l l)) [SMTPat (list_ghost_forall_exists is_sub_map_group_entry_of l l)] let map_group_included_zero_or_more #b (small large: map_group b) : GTot bool = list_ghost_forall_exists is_sub_map_group_entry_of small.one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_more large.zero_or_more && Nil? large.one val map_group_included_zero_or_more_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_zero_or_more small large)) (ensures (is_sub_map_group_of small large)) val map_group_ignore_restricted_entries_sub (#b: _) (mg: map_group b) : Lemma (requires ( list_ghost_forall_exists is_sub_map_group_entry_of mg.one mg.zero_or_more /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( mg `is_sub_map_group_of` map_group_ignore_restricted_entries mg )) let map_group_ignore_restricted_entries_no_one_equiv #b (mg: map_group b) : Lemma (requires ( Nil? mg.one /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( map_group_equiv mg (map_group_ignore_restricted_entries mg) )) = map_group_ignore_restricted_entries_sub mg; map_group_included_zero_or_more_correct (map_group_ignore_restricted_entries mg) mg let map_group_included_pointwise #b (small large: map_group b) : GTot bool = list_ghost_forall2 is_sub_map_group_entry_of small.one large.one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_one large.zero_or_one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_more large.zero_or_more val map_group_included_pointwise_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_pointwise small large)) (ensures (is_sub_map_group_of small large)) let rec list_ghost_forall2_map_l (#t1 #t2: Type) (r: t1 -> t2 -> prop) (f: t2 -> t1) (l: list t2) : Lemma (requires (forall x . r (f x) x)) (ensures (list_ghost_forall2 r (List.Tot.map f l) l)) = match l with | [] -> () | _ :: q -> list_ghost_forall2_map_l r f q let rec list_ghost_forall2_map_r (#t1 #t2: Type) (r: t1 -> t2 -> prop) (f: t1 -> t2) (l: list t1) : Lemma (requires (forall x . r x (f x))) (ensures (list_ghost_forall2 r l (List.Tot.map f l))) = match l with | [] -> () | _ :: q -> list_ghost_forall2_map_r r f q let cut_map_group_sub #b (key: bounded_typ_gen b) (mg: map_group b) : Lemma (cut_map_group key mg `is_sub_map_group_of` mg) = list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.one; list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_one; list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_more; map_group_included_pointwise_correct (cut_map_group key mg) mg (* Proving matches_map_group for sorted maps and map groups where key constraints specify whole elements *) let rec list_for_all_filter_invariant (#t: Type) (p: t -> bool) (f: t -> bool) (l: list t) : Lemma (requires (List.Tot.for_all p l == true)) (ensures (List.Tot.for_all p (List.Tot.filter f l) == true)) [SMTPat (List.Tot.for_all p (List.Tot.filter f l))] = match l with | [] -> () | _ :: q -> list_for_all_filter_invariant p f q let map_key_neq' (#t1 t2: Type) (k: t1) (x: (t1 & t2)) : GTot bool = FStar.StrongExcludedMiddle.strong_excluded_middle (~ (fst x == k)) let map_key_neq (#t1 t2: Type) (k: t1) : GTot ((t1 & t2) -> bool) = Pull.pull (map_key_neq' t2 k) let map_group_entry_for #b (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) : Tot (map_group_entry b) = MapGroupEntry (coerce_to_bounded_typ _ (t_literal k)) ty let rec list_ghost_assoc_for_all (#key: Type) (#value: Type) (p: (key & value) -> bool) (k: key) (m: list (key & value)) : Lemma (requires (List.Tot.for_all p m == true)) (ensures (match Cbor.list_ghost_assoc k m with | None -> True | Some y -> p (k, y) )) (decreases m) [SMTPat (List.Tot.for_all p m); SMTPat (Cbor.list_ghost_assoc k m)] = match m with | [] -> () | (k', _) :: m' -> if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k') then () else list_ghost_assoc_for_all p k m'
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt.fsti.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.Pull.fsti.checked", "CBOR.Spec.fsti.checked" ], "interface_file": false, "source_file": "CDDL.Spec.fsti" }
[ { "abbrev": true, "full_module": "FStar.Ghost.Pull", "short_module": "Pull" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "CBOR.Spec", "short_module": "Cbor" }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
k: CBOR.Spec.Type.raw_data_item -> l: Prims.list (CBOR.Spec.Type.raw_data_item * CBOR.Spec.Type.raw_data_item) -> FStar.Pervasives.Lemma (requires None? (CBOR.Spec.Map.list_ghost_assoc k l)) (ensures FStar.List.Tot.Base.for_all (CDDL.Spec.map_key_neq CBOR.Spec.Type.raw_data_item k) l == true )
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "CBOR.Spec.Type.raw_data_item", "Prims.list", "FStar.Pervasives.Native.tuple2", "CDDL.Spec.list_assoc_none_for_all_map_key_neq", "Prims.unit", "Prims.b2t", "FStar.Pervasives.Native.uu___is_None", "CBOR.Spec.Map.list_ghost_assoc", "Prims.squash", "Prims.eq2", "Prims.bool", "FStar.List.Tot.Base.for_all", "CDDL.Spec.map_key_neq", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec list_assoc_none_for_all_map_key_neq (k: Cbor.raw_data_item) (l: list (Cbor.raw_data_item & Cbor.raw_data_item)) : Lemma (requires (None? (Cbor.list_ghost_assoc k l))) (ensures (List.Tot.for_all (map_key_neq _ k) l == true)) =
match l with | [] -> () | _ :: q -> list_assoc_none_for_all_map_key_neq k q
false
FStar.Int.fsti
FStar.Int.min_int
val min_int (n: pos) : Tot int
val min_int (n: pos) : Tot int
let min_int (n:pos) : Tot int = - (pow2 (n-1))
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 46, "end_line": 42, "start_col": 0, "start_line": 42 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos -> Prims.int
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "Prims.op_Minus", "Prims.pow2", "Prims.op_Subtraction", "Prims.int" ]
[]
false
false
false
true
false
let min_int (n: pos) : Tot int =
- (pow2 (n - 1))
false
CDDL.Spec.fsti
CDDL.Spec.str_size
val str_size (ty: Cbor.major_type_byte_string_or_text_string) (sz: nat) : typ
val str_size (ty: Cbor.major_type_byte_string_or_text_string) (sz: nat) : typ
let str_size (ty: Cbor.major_type_byte_string_or_text_string) (sz: nat) : typ = fun x -> Cbor.String? x && Cbor.String?.typ x = ty && Seq.length (Cbor.String?.v x) = sz
{ "file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 36, "end_line": 849, "start_col": 0, "start_line": 846 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module CDDL.Spec module Cbor = CBOR.Spec module U8 = FStar.UInt8 module U64 = FStar.UInt64 // Concise Data Definition Language (RFC 8610) noextract let opt_precedes (#t1 #t2: Type) (x1: t1) (x2: option t2) : Tot prop = match x2 with | None -> True | Some x2 -> x1 << x2 [@@noextract_to "krml"] let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization) [@@noextract_to "krml"] let typ = bounded_typ_gen None [@@noextract_to "krml"] let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e) let coerce_to_bounded_typ (b: option Cbor.raw_data_item) (t: typ) : Tot (bounded_typ_gen b) = t noextract let typ_equiv (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : Tot prop = forall x . t1 x == t2 x let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x) let t_choice_equiv #b (t1 t1' t2 t2' : bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2')) (ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2'))) = () // etc. let t_choice_simpl #b (t: bounded_typ_gen b) : Lemma ((t `t_choice` t) `typ_equiv` t) = () let t_always_false : typ = (fun _ -> false) let t_literal (i: Cbor.raw_data_item) : typ = (fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i)) // Appendix D let any : typ = (fun _ -> true) let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64) let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64) let t_int : typ = uint `t_choice` nint let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string) let bytes = bstr let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string) let text = tstr [@@CMacro] let simple_value_false : Cbor.simple_value = 20uy [@@CMacro] let simple_value_true : Cbor.simple_value = 21uy [@@CMacro] let simple_value_nil : Cbor.simple_value = 22uy [@@CMacro] let simple_value_undefined : Cbor.simple_value = 23uy let t_simple_value_literal (s: Cbor.simple_value) : typ = t_literal (Cbor.Simple s) let t_false : typ = t_simple_value_literal simple_value_false let t_true : typ = t_simple_value_literal simple_value_true let t_bool : typ = t_choice t_false t_true let t_nil : typ = t_simple_value_literal simple_value_nil let t_null : typ = t_nil let t_undefined : typ = t_simple_value_literal simple_value_undefined let t_uint_literal (v: U64.t) : typ = t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v) // Section 2.1: Groups // Groups in array context (Section 3.4) // General semantics, which would imply backtracking [@@erasable; noextract_to "krml"] let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool) let array_group1_empty : array_group1 = fun k -> k let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k) let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) = k l || a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more' let array_group1_item (t: typ) : array_group1 = fun k l -> match l with | [] -> false | a :: q -> t a && k q let t_array1 (a: array_group1) : typ = fun x -> Cbor.Array? x && a Nil? (Cbor.Array?.v x) [@@noextract_to "krml"] let nat_up_to (n: nat) : eqtype = (i: nat { i <= n }) [@@noextract_to "krml"] let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l))) [@@noextract_to "krml"] let array_group2_empty : array_group2 = (fun _ i -> [i]) [@@noextract_to "krml"] let array_group2_concat (a1 a2: array_group2) : array_group2 = (fun l i1 -> let res1 = a1 l i1 in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1 ) [@@noextract_to "krml"] let array_group2_choice (a1 a2: array_group2) : array_group2 = fun l i -> a1 l i `List.Tot.append` a2 l i [@@noextract_to "krml"] let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) = i :: begin let r1 = a l i in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> if i2 <= i then [] else array_group2_zero_or_more' a l i2 ) r1 end (* [@@noextract_to "krml"] let array_group2_item (t: typ) : array_group2 = fun l i -> if i = Seq.length l then [] else if t (Seq.index l i) then [i + 1] else [] *) [@@noextract_to "krml"] let t_array2 (a: array_group2) : typ = fun x -> Cbor.Array? x && begin let l = Cbor.Array?.v x in List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0 end // Greedy semantics (Appendix A?) let list_is_suffix_of (#t: Type) (small large: list t) : Tot prop = exists prefix . large == prefix `List.Tot.append` small let list_is_suffix_of_refl (#t: Type) (l: list t) : Lemma (l `list_is_suffix_of` l) [SMTPat (l `list_is_suffix_of` l)] = assert (l == [] `List.Tot.append` l) let rec list_nil_precedes (#t: Type) (l: list t) : Lemma (Nil #t == l \/ Nil #t << l) = match l with | [] -> () | a :: q -> list_nil_precedes q let rec list_is_suffix_of_precedes (#t0 #t: Type) (v0: t0) (small large: list t) : Lemma (requires ( large << v0 /\ small `list_is_suffix_of` large )) (ensures ( small << v0 )) (decreases (List.Tot.length large)) [SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]] = if Nil? small then list_nil_precedes large else begin let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in List.Tot.append_length prefix small; if List.Tot.length small = List.Tot.length large then () else list_is_suffix_of_precedes v0 small (List.Tot.tl large) end [@@erasable; noextract_to "krml"] let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with | None -> True | Some l' -> opt_precedes l' bound )) noextract let array_group3_equiv #b (g1 g2: array_group3 b) : Tot prop = forall l . g1 l == g2 l let array_group3_always_false #b : array_group3 b = fun _ -> None let array_group3_empty #b : array_group3 b = fun x -> Some x let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b = (fun l -> match a1 l with | None -> None | Some l3 -> a3 l3 ) let array_group3_concat_equiv #b (a1 a1' a2 a2' : array_group3 b) : Lemma (requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2'))) (ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2'))) = () let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b = fun l -> match a1 l with | None -> a3 l | Some l3 -> Some l3 let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b)) (decreases (List.Tot.length l)) = match a l with | None -> Some l | Some l' -> if List.Tot.length l' >= List.Tot.length l then Some l else array_group3_zero_or_more' a l' let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more' let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b = a `array_group3_concat` array_group3_zero_or_more a let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) = a `array_group3_choice` array_group3_empty let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l -> match l with | [] -> None | a :: q -> if t a then Some q else None let array_group3_item_equiv #b (t1 t2: bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t2)) (ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2)) = () let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b) (l: list Cbor.raw_data_item {opt_precedes l b}) : GTot bool = match a l with | Some l' -> Nil? l' | _ -> false let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x -> Cbor.Array? x && match_array_group3 a (Cbor.Array?.v x) let t_array3_equiv #b (a1 a2: array_group3 b) : Lemma (requires (array_group3_equiv a1 a2)) (ensures (typ_equiv (t_array3 a1) (t_array3 a2))) = () // Recursive type (needed by COSE Section 5.1 "Recipient") // Inspiring from Barthe et al., Type-Based Termination with Sized // Products (CSL 2008): we allow recursion only at the level of // destructors. In other words, instead of having a generic recursion // combinator, we provide a recursion-enabled version only for each // destructor combinator. We need to annotate it with a bound b (akin // to the "size" annotation in a sized type.) let rec t_array3_rec (phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b))) (x: Cbor.raw_data_item) : GTot bool (decreases x) = Cbor.Array? x && match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x) // Groups in map context (Section 3.5) [@@erasable] noeq type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b module Pull = FStar.Ghost.Pull noextract let opt_map_entry_bounded' (b: option Cbor.raw_data_item) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) : GTot bool = FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b) let opt_map_entry_bounded (b: option Cbor.raw_data_item) : GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool) = Pull.pull (opt_map_entry_bounded' b) let rec opt_precedes_map_for_all_opt_map_entry_bounded (b: option Cbor.raw_data_item) (l: list (Cbor.raw_data_item & Cbor.raw_data_item)) : Lemma (requires (opt_precedes l b)) (ensures (List.Tot.for_all (opt_map_entry_bounded b) l)) [SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)] = match l with | [] -> () | _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q let matches_map_group_entry (#b: option Cbor.raw_data_item) (ge: map_group_entry b) (x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true }) : GTot bool = ge.fst (fst x) && ge.snd (snd x) [@@erasable] noeq type map_group (b: option Cbor.raw_data_item) = { one: list (map_group_entry b); zero_or_one: list (map_group_entry b); zero_or_more: list (map_group_entry b); } let map_group_empty #b : map_group b = { one = []; zero_or_one = []; zero_or_more = []; } let cut_map_group_entry_key #b (key: bounded_typ_gen b) (t: bounded_typ_gen b) (x: Cbor.raw_data_item { opt_precedes x b }) : GTot bool = t x && not (key x) // Section 3.5.4: Cut let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b = cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = { one = List.Tot.map (cut_map_group_entry key) g.one; zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one; zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more; } let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = if cut then cut_map_group (ge.fst) g else g let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with one = ge :: g.one; } let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_one = ge :: g.zero_or_one; } let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_more = ge :: g.zero_or_more; } val matches_map_group (#b: option Cbor.raw_data_item) (m: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x }) : GTot bool val matches_map_group_empty (b: option Cbor.raw_data_item) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (ensures (matches_map_group (map_group_empty #b) x == Nil? x)) [SMTPat (matches_map_group (map_group_empty #b) x)] (* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *) noextract let is_sub_map_group_of #b (small large: map_group b) : Tot prop = forall x . matches_map_group small x ==> matches_map_group large x noextract let map_group_equiv #b (mg1 mg2: map_group b) : Tot prop = forall x . matches_map_group mg1 x == matches_map_group mg2 x noextract let is_sub_typ_of #b (small large: bounded_typ_gen b) : Tot prop = forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x noextract let is_sub_map_group_entry_of #b (small large: map_group_entry b) : Tot prop = small.fst `is_sub_typ_of` large.fst /\ small.snd `is_sub_typ_of` large.snd let map_group_ignore_restricted_entries #b (mg: map_group b) : Tot (map_group b) = {mg with one = []; zero_or_one = []; } let pull_rel (#t1 #t2: Type) (r: t1 -> t2 -> prop) (x1: t1) : GTot ((x2: t2) -> Tot bool) = Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2)) let list_ghost_forall_exists_body (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l2: list t2) : GTot (t1 -> bool) = Pull.pull (fun x1 -> List.Tot.existsb (pull_rel r x1) l2 ) let list_ghost_forall_exists (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l1: list t1) (l2: list t2) : GTot bool = List.Tot.for_all (list_ghost_forall_exists_body r l2) l1 noextract let matches_map_group_entry' (#b: _) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) (y: map_group_entry b) : Tot prop = opt_map_entry_bounded b x ==> matches_map_group_entry y x val matches_map_group_no_restricted (#b: _) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires ( Nil? g.one /\ Nil? g.zero_or_one )) (ensures ( matches_map_group g x <==> list_ghost_forall_exists matches_map_group_entry' x g.zero_or_more )) [SMTPat (matches_map_group g x)] let rec list_ghost_forall2 (#t1 #t2: Type) (f: t1 -> t2 -> GTot prop) (l1: list t1) (l2: list t2) : GTot bool (decreases l1) = match l1, l2 with | [], [] -> true | a1 :: q1, a2 :: q2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (f a1 a2) && list_ghost_forall2 f q1 q2 | _ -> false val list_ghost_forall_exists_is_sub_map_group_entry_of_refl (#b: _) (l: list (map_group_entry b)) : Lemma (ensures (list_ghost_forall_exists is_sub_map_group_entry_of l l)) [SMTPat (list_ghost_forall_exists is_sub_map_group_entry_of l l)] let map_group_included_zero_or_more #b (small large: map_group b) : GTot bool = list_ghost_forall_exists is_sub_map_group_entry_of small.one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_more large.zero_or_more && Nil? large.one val map_group_included_zero_or_more_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_zero_or_more small large)) (ensures (is_sub_map_group_of small large)) val map_group_ignore_restricted_entries_sub (#b: _) (mg: map_group b) : Lemma (requires ( list_ghost_forall_exists is_sub_map_group_entry_of mg.one mg.zero_or_more /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( mg `is_sub_map_group_of` map_group_ignore_restricted_entries mg )) let map_group_ignore_restricted_entries_no_one_equiv #b (mg: map_group b) : Lemma (requires ( Nil? mg.one /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( map_group_equiv mg (map_group_ignore_restricted_entries mg) )) = map_group_ignore_restricted_entries_sub mg; map_group_included_zero_or_more_correct (map_group_ignore_restricted_entries mg) mg let map_group_included_pointwise #b (small large: map_group b) : GTot bool = list_ghost_forall2 is_sub_map_group_entry_of small.one large.one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_one large.zero_or_one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_more large.zero_or_more val map_group_included_pointwise_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_pointwise small large)) (ensures (is_sub_map_group_of small large)) let rec list_ghost_forall2_map_l (#t1 #t2: Type) (r: t1 -> t2 -> prop) (f: t2 -> t1) (l: list t2) : Lemma (requires (forall x . r (f x) x)) (ensures (list_ghost_forall2 r (List.Tot.map f l) l)) = match l with | [] -> () | _ :: q -> list_ghost_forall2_map_l r f q let rec list_ghost_forall2_map_r (#t1 #t2: Type) (r: t1 -> t2 -> prop) (f: t1 -> t2) (l: list t1) : Lemma (requires (forall x . r x (f x))) (ensures (list_ghost_forall2 r l (List.Tot.map f l))) = match l with | [] -> () | _ :: q -> list_ghost_forall2_map_r r f q let cut_map_group_sub #b (key: bounded_typ_gen b) (mg: map_group b) : Lemma (cut_map_group key mg `is_sub_map_group_of` mg) = list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.one; list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_one; list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_more; map_group_included_pointwise_correct (cut_map_group key mg) mg (* Proving matches_map_group for sorted maps and map groups where key constraints specify whole elements *) let rec list_for_all_filter_invariant (#t: Type) (p: t -> bool) (f: t -> bool) (l: list t) : Lemma (requires (List.Tot.for_all p l == true)) (ensures (List.Tot.for_all p (List.Tot.filter f l) == true)) [SMTPat (List.Tot.for_all p (List.Tot.filter f l))] = match l with | [] -> () | _ :: q -> list_for_all_filter_invariant p f q let map_key_neq' (#t1 t2: Type) (k: t1) (x: (t1 & t2)) : GTot bool = FStar.StrongExcludedMiddle.strong_excluded_middle (~ (fst x == k)) let map_key_neq (#t1 t2: Type) (k: t1) : GTot ((t1 & t2) -> bool) = Pull.pull (map_key_neq' t2 k) let map_group_entry_for #b (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) : Tot (map_group_entry b) = MapGroupEntry (coerce_to_bounded_typ _ (t_literal k)) ty let rec list_ghost_assoc_for_all (#key: Type) (#value: Type) (p: (key & value) -> bool) (k: key) (m: list (key & value)) : Lemma (requires (List.Tot.for_all p m == true)) (ensures (match Cbor.list_ghost_assoc k m with | None -> True | Some y -> p (k, y) )) (decreases m) [SMTPat (List.Tot.for_all p m); SMTPat (Cbor.list_ghost_assoc k m)] = match m with | [] -> () | (k', _) :: m' -> if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k') then () else list_ghost_assoc_for_all p k m' let rec list_assoc_none_for_all_map_key_neq (k: Cbor.raw_data_item) (l: list (Cbor.raw_data_item & Cbor.raw_data_item)) : Lemma (requires (None? (Cbor.list_ghost_assoc k l))) (ensures (List.Tot.for_all (map_key_neq _ k) l == true)) = match l with | [] -> () | _ :: q -> list_assoc_none_for_all_map_key_neq k q val matches_map_group_map_group_cons_zero_or_one_no_repeats (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.no_repeats_p (List.Tot.map fst x))) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b end /\ matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> matches_map_group g x | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) val matches_map_group_map_group_cons_one_no_repeats (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.no_repeats_p (List.Tot.map fst x))) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b end /\ matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> false | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) val matches_map_group_map_group_cons_zero_or_one_deterministically_encoded_cbor_map_key_order (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) x)) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b /\ List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) (List.Tot.filter (map_key_neq _ k) x) end /\ matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> matches_map_group g x | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) [SMTPat (matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x)] val matches_map_group_map_group_cons_one_deterministically_encoded_cbor_map_key_order (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) x)) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b /\ List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) (List.Tot.filter (map_key_neq _ k) x) end /\ matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> false | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) [SMTPat (matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x)] // 2.1 specifies "names that turn into the map key text string" noextract let string64 = (s: Seq.seq U8.t {FStar.UInt.fits (Seq.length s) 64}) let name_as_text_string (s: string64) : typ = t_literal (Cbor.String Cbor.cbor_major_type_text_string s) let t_map (#b: option Cbor.raw_data_item) (m: map_group b) : bounded_typ_gen b = fun x -> Cbor.Map? x && matches_map_group m (Cbor.Map?.v x) let t_map_equiv #b (m1 m2: map_group b) : Lemma (requires (map_group_equiv m1 m2)) (ensures (typ_equiv (t_map m1) (t_map m2))) = () let rec t_map_rec (phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> map_group (Some b))) (x: Cbor.raw_data_item) : GTot bool (decreases x) = Cbor.Map? x && matches_map_group (phi x (t_map_rec phi)) (Cbor.Map?.v x) // Section 3.6: Tags let t_tag (#b: option Cbor.raw_data_item) (tag: U64.t) (t: bounded_typ_gen b) : bounded_typ_gen b = fun x -> Cbor.Tagged? x && Cbor.Tagged?.tag x = tag && t (Cbor.Tagged?.v x) let rec t_tag_rec (tag: U64.t) (phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> bounded_typ b)) (x: Cbor.raw_data_item) : GTot bool (decreases x) = Cbor.Tagged? x && Cbor.Tagged?.tag x = tag && phi x (t_tag_rec tag phi) (Cbor.Tagged?.v x) // Multi-purpose recursive combinator, to allow disjunctions between destructors let rec multi_rec (phi_base: typ) (phi_array: (b: Cbor.raw_data_item) -> bounded_typ b -> array_group3 (Some b)) (phi_map: (b: Cbor.raw_data_item) -> bounded_typ b -> map_group (Some b)) (phi_tag: U64.t -> (b: Cbor.raw_data_item) -> bounded_typ b -> bounded_typ b) (x: Cbor.raw_data_item) : GTot bool (decreases x) = phi_base x || begin match x with | Cbor.Array v -> match_array_group3 (phi_array x (multi_rec phi_base phi_array phi_map phi_tag)) v | Cbor.Map v -> matches_map_group (phi_map x (multi_rec phi_base phi_array phi_map phi_tag)) v | Cbor.Tagged tag v -> phi_tag tag x (multi_rec phi_base phi_array phi_map phi_tag) v | _ -> false end // Section 3.8.1: Control .size
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt.fsti.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.Pull.fsti.checked", "CBOR.Spec.fsti.checked" ], "interface_file": false, "source_file": "CDDL.Spec.fsti" }
[ { "abbrev": true, "full_module": "FStar.Ghost.Pull", "short_module": "Pull" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "CBOR.Spec", "short_module": "Cbor" }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
ty: CBOR.Spec.Constants.major_type_byte_string_or_text_string -> sz: Prims.nat -> CDDL.Spec.typ
Prims.Tot
[ "total" ]
[]
[ "CBOR.Spec.Constants.major_type_byte_string_or_text_string", "Prims.nat", "CBOR.Spec.Type.raw_data_item", "CDDL.Spec.opt_precedes", "FStar.Pervasives.Native.None", "Prims.op_AmpAmp", "CBOR.Spec.Type.uu___is_String", "Prims.op_Equality", "CBOR.Spec.Type.__proj__String__item__typ", "FStar.Seq.Base.length", "FStar.UInt8.t", "CBOR.Spec.Type.__proj__String__item__v", "Prims.bool", "CDDL.Spec.typ" ]
[]
false
false
false
true
false
let str_size (ty: Cbor.major_type_byte_string_or_text_string) (sz: nat) : typ =
fun x -> Cbor.String? x && Cbor.String?.typ x = ty && Seq.length (Cbor.String?.v x) = sz
false
FStar.Int.fsti
FStar.Int.zero
val zero (n: pos) : Tot (int_t n)
val zero (n: pos) : Tot (int_t n)
let zero (n:pos) : Tot (int_t n) = 0
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 36, "end_line": 63, "start_col": 0, "start_line": 63 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos -> FStar.Int.int_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.Int.int_t" ]
[]
false
false
false
false
false
let zero (n: pos) : Tot (int_t n) =
0
false
CDDL.Spec.fsti
CDDL.Spec.t_tag_rec
val t_tag_rec (tag: U64.t) (phi: (b: Cbor.raw_data_item -> (bounded_typ b -> bounded_typ b))) (x: Cbor.raw_data_item) : GTot bool (decreases x)
val t_tag_rec (tag: U64.t) (phi: (b: Cbor.raw_data_item -> (bounded_typ b -> bounded_typ b))) (x: Cbor.raw_data_item) : GTot bool (decreases x)
let rec t_tag_rec (tag: U64.t) (phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> bounded_typ b)) (x: Cbor.raw_data_item) : GTot bool (decreases x) = Cbor.Tagged? x && Cbor.Tagged?.tag x = tag && phi x (t_tag_rec tag phi) (Cbor.Tagged?.v x)
{ "file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 46, "end_line": 821, "start_col": 0, "start_line": 813 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module CDDL.Spec module Cbor = CBOR.Spec module U8 = FStar.UInt8 module U64 = FStar.UInt64 // Concise Data Definition Language (RFC 8610) noextract let opt_precedes (#t1 #t2: Type) (x1: t1) (x2: option t2) : Tot prop = match x2 with | None -> True | Some x2 -> x1 << x2 [@@noextract_to "krml"] let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization) [@@noextract_to "krml"] let typ = bounded_typ_gen None [@@noextract_to "krml"] let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e) let coerce_to_bounded_typ (b: option Cbor.raw_data_item) (t: typ) : Tot (bounded_typ_gen b) = t noextract let typ_equiv (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : Tot prop = forall x . t1 x == t2 x let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x) let t_choice_equiv #b (t1 t1' t2 t2' : bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2')) (ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2'))) = () // etc. let t_choice_simpl #b (t: bounded_typ_gen b) : Lemma ((t `t_choice` t) `typ_equiv` t) = () let t_always_false : typ = (fun _ -> false) let t_literal (i: Cbor.raw_data_item) : typ = (fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i)) // Appendix D let any : typ = (fun _ -> true) let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64) let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64) let t_int : typ = uint `t_choice` nint let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string) let bytes = bstr let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string) let text = tstr [@@CMacro] let simple_value_false : Cbor.simple_value = 20uy [@@CMacro] let simple_value_true : Cbor.simple_value = 21uy [@@CMacro] let simple_value_nil : Cbor.simple_value = 22uy [@@CMacro] let simple_value_undefined : Cbor.simple_value = 23uy let t_simple_value_literal (s: Cbor.simple_value) : typ = t_literal (Cbor.Simple s) let t_false : typ = t_simple_value_literal simple_value_false let t_true : typ = t_simple_value_literal simple_value_true let t_bool : typ = t_choice t_false t_true let t_nil : typ = t_simple_value_literal simple_value_nil let t_null : typ = t_nil let t_undefined : typ = t_simple_value_literal simple_value_undefined let t_uint_literal (v: U64.t) : typ = t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v) // Section 2.1: Groups // Groups in array context (Section 3.4) // General semantics, which would imply backtracking [@@erasable; noextract_to "krml"] let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool) let array_group1_empty : array_group1 = fun k -> k let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k) let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) = k l || a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more' let array_group1_item (t: typ) : array_group1 = fun k l -> match l with | [] -> false | a :: q -> t a && k q let t_array1 (a: array_group1) : typ = fun x -> Cbor.Array? x && a Nil? (Cbor.Array?.v x) [@@noextract_to "krml"] let nat_up_to (n: nat) : eqtype = (i: nat { i <= n }) [@@noextract_to "krml"] let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l))) [@@noextract_to "krml"] let array_group2_empty : array_group2 = (fun _ i -> [i]) [@@noextract_to "krml"] let array_group2_concat (a1 a2: array_group2) : array_group2 = (fun l i1 -> let res1 = a1 l i1 in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1 ) [@@noextract_to "krml"] let array_group2_choice (a1 a2: array_group2) : array_group2 = fun l i -> a1 l i `List.Tot.append` a2 l i [@@noextract_to "krml"] let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) = i :: begin let r1 = a l i in List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> if i2 <= i then [] else array_group2_zero_or_more' a l i2 ) r1 end (* [@@noextract_to "krml"] let array_group2_item (t: typ) : array_group2 = fun l i -> if i = Seq.length l then [] else if t (Seq.index l i) then [i + 1] else [] *) [@@noextract_to "krml"] let t_array2 (a: array_group2) : typ = fun x -> Cbor.Array? x && begin let l = Cbor.Array?.v x in List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0 end // Greedy semantics (Appendix A?) let list_is_suffix_of (#t: Type) (small large: list t) : Tot prop = exists prefix . large == prefix `List.Tot.append` small let list_is_suffix_of_refl (#t: Type) (l: list t) : Lemma (l `list_is_suffix_of` l) [SMTPat (l `list_is_suffix_of` l)] = assert (l == [] `List.Tot.append` l) let rec list_nil_precedes (#t: Type) (l: list t) : Lemma (Nil #t == l \/ Nil #t << l) = match l with | [] -> () | a :: q -> list_nil_precedes q let rec list_is_suffix_of_precedes (#t0 #t: Type) (v0: t0) (small large: list t) : Lemma (requires ( large << v0 /\ small `list_is_suffix_of` large )) (ensures ( small << v0 )) (decreases (List.Tot.length large)) [SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]] = if Nil? small then list_nil_precedes large else begin let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in List.Tot.append_length prefix small; if List.Tot.length small = List.Tot.length large then () else list_is_suffix_of_precedes v0 small (List.Tot.tl large) end [@@erasable; noextract_to "krml"] let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with | None -> True | Some l' -> opt_precedes l' bound )) noextract let array_group3_equiv #b (g1 g2: array_group3 b) : Tot prop = forall l . g1 l == g2 l let array_group3_always_false #b : array_group3 b = fun _ -> None let array_group3_empty #b : array_group3 b = fun x -> Some x let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b = (fun l -> match a1 l with | None -> None | Some l3 -> a3 l3 ) let array_group3_concat_equiv #b (a1 a1' a2 a2' : array_group3 b) : Lemma (requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2'))) (ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2'))) = () let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b = fun l -> match a1 l with | None -> a3 l | Some l3 -> Some l3 let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item)) (requires True) (ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b)) (decreases (List.Tot.length l)) = match a l with | None -> Some l | Some l' -> if List.Tot.length l' >= List.Tot.length l then Some l else array_group3_zero_or_more' a l' let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more' let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b = a `array_group3_concat` array_group3_zero_or_more a let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) = a `array_group3_choice` array_group3_empty let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l -> match l with | [] -> None | a :: q -> if t a then Some q else None let array_group3_item_equiv #b (t1 t2: bounded_typ_gen b) : Lemma (requires (t1 `typ_equiv` t2)) (ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2)) = () let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b) (l: list Cbor.raw_data_item {opt_precedes l b}) : GTot bool = match a l with | Some l' -> Nil? l' | _ -> false let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x -> Cbor.Array? x && match_array_group3 a (Cbor.Array?.v x) let t_array3_equiv #b (a1 a2: array_group3 b) : Lemma (requires (array_group3_equiv a1 a2)) (ensures (typ_equiv (t_array3 a1) (t_array3 a2))) = () // Recursive type (needed by COSE Section 5.1 "Recipient") // Inspiring from Barthe et al., Type-Based Termination with Sized // Products (CSL 2008): we allow recursion only at the level of // destructors. In other words, instead of having a generic recursion // combinator, we provide a recursion-enabled version only for each // destructor combinator. We need to annotate it with a bound b (akin // to the "size" annotation in a sized type.) let rec t_array3_rec (phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b))) (x: Cbor.raw_data_item) : GTot bool (decreases x) = Cbor.Array? x && match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x) // Groups in map context (Section 3.5) [@@erasable] noeq type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b module Pull = FStar.Ghost.Pull noextract let opt_map_entry_bounded' (b: option Cbor.raw_data_item) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) : GTot bool = FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b) let opt_map_entry_bounded (b: option Cbor.raw_data_item) : GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool) = Pull.pull (opt_map_entry_bounded' b) let rec opt_precedes_map_for_all_opt_map_entry_bounded (b: option Cbor.raw_data_item) (l: list (Cbor.raw_data_item & Cbor.raw_data_item)) : Lemma (requires (opt_precedes l b)) (ensures (List.Tot.for_all (opt_map_entry_bounded b) l)) [SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)] = match l with | [] -> () | _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q let matches_map_group_entry (#b: option Cbor.raw_data_item) (ge: map_group_entry b) (x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true }) : GTot bool = ge.fst (fst x) && ge.snd (snd x) [@@erasable] noeq type map_group (b: option Cbor.raw_data_item) = { one: list (map_group_entry b); zero_or_one: list (map_group_entry b); zero_or_more: list (map_group_entry b); } let map_group_empty #b : map_group b = { one = []; zero_or_one = []; zero_or_more = []; } let cut_map_group_entry_key #b (key: bounded_typ_gen b) (t: bounded_typ_gen b) (x: Cbor.raw_data_item { opt_precedes x b }) : GTot bool = t x && not (key x) // Section 3.5.4: Cut let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b = cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = { one = List.Tot.map (cut_map_group_entry key) g.one; zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one; zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more; } let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = if cut then cut_map_group (ge.fst) g else g let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with one = ge :: g.one; } let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_one = ge :: g.zero_or_one; } let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b = let g = maybe_cut_map_group ge cut g in { g with zero_or_more = ge :: g.zero_or_more; } val matches_map_group (#b: option Cbor.raw_data_item) (m: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x }) : GTot bool val matches_map_group_empty (b: option Cbor.raw_data_item) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (ensures (matches_map_group (map_group_empty #b) x == Nil? x)) [SMTPat (matches_map_group (map_group_empty #b) x)] (* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *) noextract let is_sub_map_group_of #b (small large: map_group b) : Tot prop = forall x . matches_map_group small x ==> matches_map_group large x noextract let map_group_equiv #b (mg1 mg2: map_group b) : Tot prop = forall x . matches_map_group mg1 x == matches_map_group mg2 x noextract let is_sub_typ_of #b (small large: bounded_typ_gen b) : Tot prop = forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x noextract let is_sub_map_group_entry_of #b (small large: map_group_entry b) : Tot prop = small.fst `is_sub_typ_of` large.fst /\ small.snd `is_sub_typ_of` large.snd let map_group_ignore_restricted_entries #b (mg: map_group b) : Tot (map_group b) = {mg with one = []; zero_or_one = []; } let pull_rel (#t1 #t2: Type) (r: t1 -> t2 -> prop) (x1: t1) : GTot ((x2: t2) -> Tot bool) = Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2)) let list_ghost_forall_exists_body (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l2: list t2) : GTot (t1 -> bool) = Pull.pull (fun x1 -> List.Tot.existsb (pull_rel r x1) l2 ) let list_ghost_forall_exists (#t1 #t2: Type) (r: t1 -> t2 -> prop) (l1: list t1) (l2: list t2) : GTot bool = List.Tot.for_all (list_ghost_forall_exists_body r l2) l1 noextract let matches_map_group_entry' (#b: _) (x: (Cbor.raw_data_item & Cbor.raw_data_item)) (y: map_group_entry b) : Tot prop = opt_map_entry_bounded b x ==> matches_map_group_entry y x val matches_map_group_no_restricted (#b: _) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires ( Nil? g.one /\ Nil? g.zero_or_one )) (ensures ( matches_map_group g x <==> list_ghost_forall_exists matches_map_group_entry' x g.zero_or_more )) [SMTPat (matches_map_group g x)] let rec list_ghost_forall2 (#t1 #t2: Type) (f: t1 -> t2 -> GTot prop) (l1: list t1) (l2: list t2) : GTot bool (decreases l1) = match l1, l2 with | [], [] -> true | a1 :: q1, a2 :: q2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (f a1 a2) && list_ghost_forall2 f q1 q2 | _ -> false val list_ghost_forall_exists_is_sub_map_group_entry_of_refl (#b: _) (l: list (map_group_entry b)) : Lemma (ensures (list_ghost_forall_exists is_sub_map_group_entry_of l l)) [SMTPat (list_ghost_forall_exists is_sub_map_group_entry_of l l)] let map_group_included_zero_or_more #b (small large: map_group b) : GTot bool = list_ghost_forall_exists is_sub_map_group_entry_of small.one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_one large.zero_or_more && list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_more large.zero_or_more && Nil? large.one val map_group_included_zero_or_more_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_zero_or_more small large)) (ensures (is_sub_map_group_of small large)) val map_group_ignore_restricted_entries_sub (#b: _) (mg: map_group b) : Lemma (requires ( list_ghost_forall_exists is_sub_map_group_entry_of mg.one mg.zero_or_more /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( mg `is_sub_map_group_of` map_group_ignore_restricted_entries mg )) let map_group_ignore_restricted_entries_no_one_equiv #b (mg: map_group b) : Lemma (requires ( Nil? mg.one /\ list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more )) (ensures ( map_group_equiv mg (map_group_ignore_restricted_entries mg) )) = map_group_ignore_restricted_entries_sub mg; map_group_included_zero_or_more_correct (map_group_ignore_restricted_entries mg) mg let map_group_included_pointwise #b (small large: map_group b) : GTot bool = list_ghost_forall2 is_sub_map_group_entry_of small.one large.one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_one large.zero_or_one && list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_more large.zero_or_more val map_group_included_pointwise_correct (#b: _) (small large: map_group b) : Lemma (requires (map_group_included_pointwise small large)) (ensures (is_sub_map_group_of small large)) let rec list_ghost_forall2_map_l (#t1 #t2: Type) (r: t1 -> t2 -> prop) (f: t2 -> t1) (l: list t2) : Lemma (requires (forall x . r (f x) x)) (ensures (list_ghost_forall2 r (List.Tot.map f l) l)) = match l with | [] -> () | _ :: q -> list_ghost_forall2_map_l r f q let rec list_ghost_forall2_map_r (#t1 #t2: Type) (r: t1 -> t2 -> prop) (f: t1 -> t2) (l: list t1) : Lemma (requires (forall x . r x (f x))) (ensures (list_ghost_forall2 r l (List.Tot.map f l))) = match l with | [] -> () | _ :: q -> list_ghost_forall2_map_r r f q let cut_map_group_sub #b (key: bounded_typ_gen b) (mg: map_group b) : Lemma (cut_map_group key mg `is_sub_map_group_of` mg) = list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.one; list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_one; list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_more; map_group_included_pointwise_correct (cut_map_group key mg) mg (* Proving matches_map_group for sorted maps and map groups where key constraints specify whole elements *) let rec list_for_all_filter_invariant (#t: Type) (p: t -> bool) (f: t -> bool) (l: list t) : Lemma (requires (List.Tot.for_all p l == true)) (ensures (List.Tot.for_all p (List.Tot.filter f l) == true)) [SMTPat (List.Tot.for_all p (List.Tot.filter f l))] = match l with | [] -> () | _ :: q -> list_for_all_filter_invariant p f q let map_key_neq' (#t1 t2: Type) (k: t1) (x: (t1 & t2)) : GTot bool = FStar.StrongExcludedMiddle.strong_excluded_middle (~ (fst x == k)) let map_key_neq (#t1 t2: Type) (k: t1) : GTot ((t1 & t2) -> bool) = Pull.pull (map_key_neq' t2 k) let map_group_entry_for #b (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) : Tot (map_group_entry b) = MapGroupEntry (coerce_to_bounded_typ _ (t_literal k)) ty let rec list_ghost_assoc_for_all (#key: Type) (#value: Type) (p: (key & value) -> bool) (k: key) (m: list (key & value)) : Lemma (requires (List.Tot.for_all p m == true)) (ensures (match Cbor.list_ghost_assoc k m with | None -> True | Some y -> p (k, y) )) (decreases m) [SMTPat (List.Tot.for_all p m); SMTPat (Cbor.list_ghost_assoc k m)] = match m with | [] -> () | (k', _) :: m' -> if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k') then () else list_ghost_assoc_for_all p k m' let rec list_assoc_none_for_all_map_key_neq (k: Cbor.raw_data_item) (l: list (Cbor.raw_data_item & Cbor.raw_data_item)) : Lemma (requires (None? (Cbor.list_ghost_assoc k l))) (ensures (List.Tot.for_all (map_key_neq _ k) l == true)) = match l with | [] -> () | _ :: q -> list_assoc_none_for_all_map_key_neq k q val matches_map_group_map_group_cons_zero_or_one_no_repeats (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.no_repeats_p (List.Tot.map fst x))) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b end /\ matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> matches_map_group g x | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) val matches_map_group_map_group_cons_one_no_repeats (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.no_repeats_p (List.Tot.map fst x))) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b end /\ matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> false | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) val matches_map_group_map_group_cons_zero_or_one_deterministically_encoded_cbor_map_key_order (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) x)) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b /\ List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) (List.Tot.filter (map_key_neq _ k) x) end /\ matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> matches_map_group g x | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) [SMTPat (matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x)] val matches_map_group_map_group_cons_one_deterministically_encoded_cbor_map_key_order (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b) (x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x }) : Lemma (requires (List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) x)) (ensures ( begin match Cbor.list_ghost_assoc k x with | None -> True | Some y -> opt_precedes y b /\ List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) (List.Tot.filter (map_key_neq _ k) x) end /\ matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x == begin match Cbor.list_ghost_assoc k x with | None -> false | Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x) end )) [SMTPat (matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x)] // 2.1 specifies "names that turn into the map key text string" noextract let string64 = (s: Seq.seq U8.t {FStar.UInt.fits (Seq.length s) 64}) let name_as_text_string (s: string64) : typ = t_literal (Cbor.String Cbor.cbor_major_type_text_string s) let t_map (#b: option Cbor.raw_data_item) (m: map_group b) : bounded_typ_gen b = fun x -> Cbor.Map? x && matches_map_group m (Cbor.Map?.v x) let t_map_equiv #b (m1 m2: map_group b) : Lemma (requires (map_group_equiv m1 m2)) (ensures (typ_equiv (t_map m1) (t_map m2))) = () let rec t_map_rec (phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> map_group (Some b))) (x: Cbor.raw_data_item) : GTot bool (decreases x) = Cbor.Map? x && matches_map_group (phi x (t_map_rec phi)) (Cbor.Map?.v x) // Section 3.6: Tags let t_tag (#b: option Cbor.raw_data_item) (tag: U64.t) (t: bounded_typ_gen b) : bounded_typ_gen b = fun x -> Cbor.Tagged? x && Cbor.Tagged?.tag x = tag && t (Cbor.Tagged?.v x)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt.fsti.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.IndefiniteDescription.fsti.checked", "FStar.Ghost.Pull.fsti.checked", "CBOR.Spec.fsti.checked" ], "interface_file": false, "source_file": "CDDL.Spec.fsti" }
[ { "abbrev": true, "full_module": "FStar.Ghost.Pull", "short_module": "Pull" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "CBOR.Spec", "short_module": "Cbor" }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "CDDL", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
tag: FStar.UInt64.t -> phi: (b: CBOR.Spec.Type.raw_data_item -> _: CDDL.Spec.bounded_typ b -> CDDL.Spec.bounded_typ b) -> x: CBOR.Spec.Type.raw_data_item -> Prims.GTot Prims.bool
Prims.GTot
[ "sometrivial", "" ]
[]
[ "FStar.UInt64.t", "CBOR.Spec.Type.raw_data_item", "CDDL.Spec.bounded_typ", "Prims.op_AmpAmp", "CBOR.Spec.Type.uu___is_Tagged", "Prims.op_Equality", "CBOR.Spec.Type.__proj__Tagged__item__tag", "CDDL.Spec.t_tag_rec", "CBOR.Spec.Type.__proj__Tagged__item__v", "Prims.bool" ]
[ "recursion" ]
false
false
false
false
false
let rec t_tag_rec (tag: U64.t) (phi: (b: Cbor.raw_data_item -> (bounded_typ b -> bounded_typ b))) (x: Cbor.raw_data_item) : GTot bool (decreases x) =
Cbor.Tagged? x && Cbor.Tagged?.tag x = tag && phi x (t_tag_rec tag phi) (Cbor.Tagged?.v x)
false
FStar.Int.fsti
FStar.Int.op_At_Percent
val ( @% ) (v: int) (p: int{p > 0 /\ p % 2 = 0}) : Tot int
val ( @% ) (v: int) (p: int{p > 0 /\ p % 2 = 0}) : Tot int
let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 48, "end_line": 59, "start_col": 0, "start_line": 58 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: Prims.int -> p: Prims.int{p > 0 /\ p % 2 = 0} -> Prims.int
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_Equality", "Prims.op_Modulus", "Prims.op_GreaterThanOrEqual", "FStar.Int.op_Slash", "Prims.op_Subtraction", "Prims.bool" ]
[]
false
false
false
false
false
let ( @% ) (v: int) (p: int{p > 0 /\ p % 2 = 0}) : Tot int =
let m = v % p in if m >= p / 2 then m - p else m
false
FStar.Int.fsti
FStar.Int.pow2_minus_one
val pow2_minus_one (#n: pos{1 < n}) (m: nat{m < n}) : Tot (int_t n)
val pow2_minus_one (#n: pos{1 < n}) (m: nat{m < n}) : Tot (int_t n)
let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 12, "end_line": 72, "start_col": 0, "start_line": 70 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: Prims.nat{m < n} -> FStar.Int.int_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "Prims.b2t", "Prims.op_LessThan", "Prims.nat", "Prims.op_Subtraction", "Prims.pow2", "Prims.unit", "FStar.Math.Lemmas.pow2_le_compat", "FStar.Int.int_t" ]
[]
false
false
false
false
false
let pow2_minus_one (#n: pos{1 < n}) (m: nat{m < n}) : Tot (int_t n) =
pow2_le_compat (n - 1) m; pow2 m - 1
false
FStar.Int.fsti
FStar.Int.max_int
val max_int (n: pos) : Tot int
val max_int (n: pos) : Tot int
let max_int (n:pos) : Tot int = pow2 (n-1) - 1
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 46, "end_line": 41, "start_col": 0, "start_line": 41 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos -> Prims.int
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "Prims.op_Subtraction", "Prims.pow2", "Prims.int" ]
[]
false
false
false
true
false
let max_int (n: pos) : Tot int =
pow2 (n - 1) - 1
false
FStar.Int.fsti
FStar.Int.pow2_n
val pow2_n (#n: pos) (p: nat{p < n - 1}) : Tot (int_t n)
val pow2_n (#n: pos) (p: nat{p < n - 1}) : Tot (int_t n)
let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 68, "start_col": 0, "start_line": 67 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Prims.nat{p < n - 1} -> FStar.Int.int_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Subtraction", "Prims.pow2", "Prims.unit", "FStar.Math.Lemmas.pow2_le_compat", "FStar.Int.int_t" ]
[]
false
false
false
false
false
let pow2_n (#n: pos) (p: nat{p < n - 1}) : Tot (int_t n) =
pow2_le_compat (n - 2) p; pow2 p
false
FStar.Int.fsti
FStar.Int.gte
val gte (#n: _) (a b: int_t n) : Tot bool
val gte (#n: _) (a b: int_t n) : Tot bool
let gte #n (a:int_t n) (b:int_t n) : Tot bool = a >= b
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 54, "end_line": 182, "start_col": 0, "start_line": 182 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1)) (* Addition primitives *) let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) #push-options "--initial_fuel 1 --max_fuel 1" let add_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a + b) @% (pow2 n) (* Subtraction primitives *) let sub (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a - b) @% (pow2 n) (* Multiplication primitives *) let mul (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a * b) @% (pow2 n) #pop-options (* Division primitives *) let div (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Pure (int_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:pos -> a:int_t n -> b:int_t n{b <> 0} -> Pure (int_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:int_t n{min_int n < a} -> b:int_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:int_t n{min_int n < a}) (b:int_t n{b <> 0}) : Tot (c:int_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b (* Modulo primitives *) let mod (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Tot (int_t n) = a - ((a/b) * b) (* Comparison operators *) let eq #n (a:int_t n) (b:int_t n) : Tot bool = a = b
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.Int.int_t n -> b: FStar.Int.int_t n -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.Int.int_t", "Prims.op_GreaterThanOrEqual", "Prims.bool" ]
[]
false
false
false
false
false
let gte #n (a: int_t n) (b: int_t n) : Tot bool =
a >= b
false
FStar.Int.fsti
FStar.Int.op_Slash
val ( / ) (a: int) (b: int{b <> 0}) : Tot int
val ( / ) (a: int) (b: int{b <> 0}) : Tot int
let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 20, "end_line": 55, "start_col": 0, "start_line": 53 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Prims.int -> b: Prims.int{b <> 0} -> Prims.int
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "Prims.b2t", "Prims.op_disEquality", "Prims.op_BarBar", "Prims.op_AmpAmp", "Prims.op_GreaterThanOrEqual", "Prims.op_LessThan", "Prims.op_Minus", "Prims.op_Division", "Prims.abs", "Prims.bool" ]
[]
false
false
false
false
false
let ( / ) (a: int) (b: int{b <> 0}) : Tot int =
if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b
false
FStar.Int.fsti
FStar.Int.ones
val ones (n: pos) : Tot (int_t n)
val ones (n: pos) : Tot (int_t n)
let ones (n:pos) : Tot (int_t n) = -1
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 37, "end_line": 78, "start_col": 0, "start_line": 78 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos -> FStar.Int.int_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "Prims.op_Minus", "FStar.Int.int_t" ]
[]
false
false
false
false
false
let ones (n: pos) : Tot (int_t n) =
- 1
false
FStar.Int.fsti
FStar.Int.one
val one (n: pos{1 < n}) : Tot (int_t n)
val one (n: pos{1 < n}) : Tot (int_t n)
let one (n:pos{1 < n}) : Tot (int_t n) = 1
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 42, "end_line": 74, "start_col": 0, "start_line": 74 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos{1 < n} -> FStar.Int.int_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "Prims.b2t", "Prims.op_LessThan", "FStar.Int.int_t" ]
[]
false
false
false
false
false
let one (n: pos{1 < n}) : Tot (int_t n) =
1
false
FStar.Int.fsti
FStar.Int.lt
val lt (#n: _) (a b: int_t n) : Tot bool
val lt (#n: _) (a b: int_t n) : Tot bool
let lt #n (a:int_t n) (b:int_t n) : Tot bool = a < b
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 52, "end_line": 183, "start_col": 0, "start_line": 183 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1)) (* Addition primitives *) let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) #push-options "--initial_fuel 1 --max_fuel 1" let add_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a + b) @% (pow2 n) (* Subtraction primitives *) let sub (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a - b) @% (pow2 n) (* Multiplication primitives *) let mul (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a * b) @% (pow2 n) #pop-options (* Division primitives *) let div (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Pure (int_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:pos -> a:int_t n -> b:int_t n{b <> 0} -> Pure (int_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:int_t n{min_int n < a} -> b:int_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:int_t n{min_int n < a}) (b:int_t n{b <> 0}) : Tot (c:int_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b (* Modulo primitives *) let mod (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Tot (int_t n) = a - ((a/b) * b) (* Comparison operators *) let eq #n (a:int_t n) (b:int_t n) : Tot bool = a = b let gt #n (a:int_t n) (b:int_t n) : Tot bool = a > b
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.Int.int_t n -> b: FStar.Int.int_t n -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.Int.int_t", "Prims.op_LessThan", "Prims.bool" ]
[]
false
false
false
false
false
let lt #n (a: int_t n) (b: int_t n) : Tot bool =
a < b
false
FStar.Int.fsti
FStar.Int.decr_mod
val decr_mod (#n: pos) (a: int_t n) : Tot (int_t n)
val decr_mod (#n: pos) (a: int_t n) : Tot (int_t n)
let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1))
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 24, "end_line": 103, "start_col": 0, "start_line": 102 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.Int.int_t n -> FStar.Int.int_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.Int.int_t", "Prims.op_Modulus", "Prims.op_Subtraction", "Prims.pow2" ]
[]
false
false
false
false
false
let decr_mod (#n: pos) (a: int_t n) : Tot (int_t n) =
(a - 1) % (pow2 (n - 1))
false
FStar.Int.fsti
FStar.Int.incr
val incr (#n: pos) (a: int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True))
val incr (#n: pos) (a: int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True))
let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 9, "end_line": 84, "start_col": 0, "start_line": 81 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.Int.int_t n -> Prims.Pure (FStar.Int.int_t n)
Prims.Pure
[]
[]
[ "Prims.pos", "FStar.Int.int_t", "Prims.op_Addition", "Prims.b2t", "Prims.op_LessThan", "FStar.Int.max_int", "Prims.l_True" ]
[]
false
false
false
false
false
let incr (#n: pos) (a: int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) =
a + 1
false
FStar.Int.fsti
FStar.Int.gt
val gt (#n: _) (a b: int_t n) : Tot bool
val gt (#n: _) (a b: int_t n) : Tot bool
let gt #n (a:int_t n) (b:int_t n) : Tot bool = a > b
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 52, "end_line": 181, "start_col": 0, "start_line": 181 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1)) (* Addition primitives *) let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) #push-options "--initial_fuel 1 --max_fuel 1" let add_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a + b) @% (pow2 n) (* Subtraction primitives *) let sub (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a - b) @% (pow2 n) (* Multiplication primitives *) let mul (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a * b) @% (pow2 n) #pop-options (* Division primitives *) let div (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Pure (int_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:pos -> a:int_t n -> b:int_t n{b <> 0} -> Pure (int_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:int_t n{min_int n < a} -> b:int_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:int_t n{min_int n < a}) (b:int_t n{b <> 0}) : Tot (c:int_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b (* Modulo primitives *) let mod (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Tot (int_t n) = a - ((a/b) * b) (* Comparison operators *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.Int.int_t n -> b: FStar.Int.int_t n -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.Int.int_t", "Prims.op_GreaterThan", "Prims.bool" ]
[]
false
false
false
false
false
let gt #n (a: int_t n) (b: int_t n) : Tot bool =
a > b
false
FStar.Int.fsti
FStar.Int.lte
val lte (#n: _) (a b: int_t n) : Tot bool
val lte (#n: _) (a b: int_t n) : Tot bool
let lte #n (a:int_t n) (b:int_t n) : Tot bool = a <= b
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 54, "end_line": 184, "start_col": 0, "start_line": 184 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1)) (* Addition primitives *) let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) #push-options "--initial_fuel 1 --max_fuel 1" let add_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a + b) @% (pow2 n) (* Subtraction primitives *) let sub (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a - b) @% (pow2 n) (* Multiplication primitives *) let mul (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a * b) @% (pow2 n) #pop-options (* Division primitives *) let div (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Pure (int_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:pos -> a:int_t n -> b:int_t n{b <> 0} -> Pure (int_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:int_t n{min_int n < a} -> b:int_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:int_t n{min_int n < a}) (b:int_t n{b <> 0}) : Tot (c:int_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b (* Modulo primitives *) let mod (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Tot (int_t n) = a - ((a/b) * b) (* Comparison operators *) let eq #n (a:int_t n) (b:int_t n) : Tot bool = a = b let gt #n (a:int_t n) (b:int_t n) : Tot bool = a > b let gte #n (a:int_t n) (b:int_t n) : Tot bool = a >= b
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.Int.int_t n -> b: FStar.Int.int_t n -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.Int.int_t", "Prims.op_LessThanOrEqual", "Prims.bool" ]
[]
false
false
false
false
false
let lte #n (a: int_t n) (b: int_t n) : Tot bool =
a <= b
false
FStar.Int.fsti
FStar.Int.incr_mod
val incr_mod (#n: pos) (a: int_t n) : Tot (int_t n)
val incr_mod (#n: pos) (a: int_t n) : Tot (int_t n)
let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1))
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 24, "end_line": 100, "start_col": 0, "start_line": 99 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.Int.int_t n -> FStar.Int.int_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.Int.int_t", "Prims.op_Modulus", "Prims.op_Addition", "Prims.pow2", "Prims.op_Subtraction" ]
[]
false
false
false
false
false
let incr_mod (#n: pos) (a: int_t n) : Tot (int_t n) =
(a + 1) % (pow2 (n - 1))
false
FStar.Int.fsti
FStar.Int.decr
val decr (#n: pos) (a: int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True))
val decr (#n: pos) (a: int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True))
let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 9, "end_line": 89, "start_col": 0, "start_line": 86 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.Int.int_t n -> Prims.Pure (FStar.Int.int_t n)
Prims.Pure
[]
[]
[ "Prims.pos", "FStar.Int.int_t", "Prims.op_Subtraction", "Prims.b2t", "Prims.op_GreaterThan", "FStar.Int.min_int", "Prims.l_True" ]
[]
false
false
false
false
false
let decr (#n: pos) (a: int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) =
a - 1
false
FStar.Int.fsti
FStar.Int.logand
val logand (#n: pos) (a b: int_t n) : Tot (int_t n)
val logand (#n: pos) (a b: int_t n) : Tot (int_t n)
let logand (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = from_vec #n (logand_vec #n (to_vec #n a) (to_vec #n b))
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 57, "end_line": 293, "start_col": 0, "start_line": 292 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1)) (* Addition primitives *) let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) #push-options "--initial_fuel 1 --max_fuel 1" let add_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a + b) @% (pow2 n) (* Subtraction primitives *) let sub (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a - b) @% (pow2 n) (* Multiplication primitives *) let mul (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a * b) @% (pow2 n) #pop-options (* Division primitives *) let div (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Pure (int_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:pos -> a:int_t n -> b:int_t n{b <> 0} -> Pure (int_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:int_t n{min_int n < a} -> b:int_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:int_t n{min_int n < a}) (b:int_t n{b <> 0}) : Tot (c:int_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b (* Modulo primitives *) let mod (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Tot (int_t n) = a - ((a/b) * b) (* Comparison operators *) let eq #n (a:int_t n) (b:int_t n) : Tot bool = a = b let gt #n (a:int_t n) (b:int_t n) : Tot bool = a > b let gte #n (a:int_t n) (b:int_t n) : Tot bool = a >= b let lt #n (a:int_t n) (b:int_t n) : Tot bool = a < b let lte #n (a:int_t n) (b:int_t n) : Tot bool = a <= b #push-options "--initial_fuel 1 --max_fuel 1" /// Casts let to_uint (#n:pos) (x:int_t n) : Tot (UInt.uint_t n) = if 0 <= x then x else x + pow2 n let from_uint (#n:pos) (x:UInt.uint_t n) : Tot (int_t n) = if x <= max_int n then x else x - pow2 n val to_uint_injective: #n:pos -> x:int_t n -> Lemma (ensures from_uint (to_uint x) == x) [SMTPat (to_uint x)] let to_int_t (m:pos) (a:int) : Tot (int_t m) = a @% pow2 m open FStar.Seq (* WARNING: Mind the big endian vs little endian definition *) let to_vec (#n:pos) (num:int_t n) : Tot (bv_t n) = UInt.to_vec (to_uint num) let from_vec (#n:pos) (vec:bv_t n) : Tot (int_t n) = let x = UInt.from_vec vec in if max_int n < x then x - pow2 n else x val to_vec_lemma_1: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires a = b) (ensures equal (to_vec a) (to_vec b)) val to_vec_lemma_2: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires equal (to_vec a) (to_vec b)) (ensures a = b) val inverse_aux: #n:nat -> vec:bv_t n -> i:nat{i < n} -> Lemma (requires True) (ensures index vec i = index (to_vec (from_vec vec)) i) [SMTPat (index (to_vec (from_vec vec)) i)] val inverse_vec_lemma: #n:pos -> vec:bv_t n -> Lemma (requires True) (ensures equal vec (to_vec (from_vec vec))) [SMTPat (to_vec (from_vec vec))] val inverse_num_lemma: #n:pos -> num:int_t n -> Lemma (requires True) (ensures num = from_vec (to_vec num)) [SMTPat (from_vec (to_vec num))] val from_vec_lemma_1: #n:pos -> a:bv_t n -> b:bv_t n -> Lemma (requires equal a b) (ensures from_vec a = from_vec b) val from_vec_lemma_2: #n:pos -> a:bv_t n -> b:bv_t n -> Lemma (requires from_vec a = from_vec b) (ensures equal a b) (* Relations between constants in BitVector and in UInt. *) val zero_to_vec_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (zero n)) i = index (zero_vec #n) i) [SMTPat (index (to_vec (zero n)) i)] val zero_from_vec_lemma: #n:pos -> Lemma (requires True) (ensures from_vec (zero_vec #n) = zero n) [SMTPat (from_vec (zero_vec #n))] val one_to_vec_lemma: #n:pos{1 < n} -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (one n)) i = index (elem_vec #n (n - 1)) i) [SMTPat (index (to_vec (one n)) i)] val pow2_to_vec_lemma: #n:pos -> p:nat{p < n-1} -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (pow2_n #n p)) i = index (elem_vec #n (n - p - 1)) i) [SMTPat (index (to_vec (pow2_n #n p)) i)] val pow2_from_vec_lemma: #n:pos -> p:pos{p < n-1} -> Lemma (requires True) (ensures from_vec (elem_vec #n p) = pow2_n #n (n - p - 1)) [SMTPat (from_vec (elem_vec #n p))] val ones_to_vec_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (ones n)) i = index (ones_vec #n) i) [SMTPat (index (to_vec (ones n)) i)] val ones_from_vec_lemma: #n:pos -> Lemma (requires True) (ensures from_vec (ones_vec #n) = ones n) [SMTPat (from_vec (ones_vec #n))] (* (nth a i) returns a boolean indicating the i-th bit of a. *) let nth (#n:pos) (a:int_t n) (i:nat{i < n}) : Tot bool = index (to_vec #n a) i val nth_lemma: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires forall (i:nat{i < n}). nth a i = nth b i) (ensures a = b) (* Lemmas for constants *) val zero_nth_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures nth (zero n) i = false) [SMTPat (nth (zero n) i)] val one_nth_lemma: #n:pos{1 < n} -> i:nat{i < n} -> Lemma (requires True) (ensures (i = n - 1 ==> nth (one n) i = true) /\ (i < n - 1 ==> nth (one n) i = false)) [SMTPat (nth (one n) i)] val ones_nth_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (ones n) i) = true) [SMTPat (nth (ones n) i)]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.Int.int_t n -> b: FStar.Int.int_t n -> FStar.Int.int_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.Int.int_t", "FStar.Int.from_vec", "FStar.BitVector.logand_vec", "FStar.Int.to_vec" ]
[]
false
false
false
false
false
let logand (#n: pos) (a b: int_t n) : Tot (int_t n) =
from_vec #n (logand_vec #n (to_vec #n a) (to_vec #n b))
false
FStar.Int.fsti
FStar.Int.logxor
val logxor (#n: pos) (a b: int_t n) : Tot (int_t n)
val logxor (#n: pos) (a b: int_t n) : Tot (int_t n)
let logxor (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = from_vec #n (logxor_vec #n (to_vec #n a) (to_vec #n b))
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 57, "end_line": 296, "start_col": 0, "start_line": 295 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1)) (* Addition primitives *) let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) #push-options "--initial_fuel 1 --max_fuel 1" let add_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a + b) @% (pow2 n) (* Subtraction primitives *) let sub (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a - b) @% (pow2 n) (* Multiplication primitives *) let mul (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a * b) @% (pow2 n) #pop-options (* Division primitives *) let div (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Pure (int_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:pos -> a:int_t n -> b:int_t n{b <> 0} -> Pure (int_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:int_t n{min_int n < a} -> b:int_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:int_t n{min_int n < a}) (b:int_t n{b <> 0}) : Tot (c:int_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b (* Modulo primitives *) let mod (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Tot (int_t n) = a - ((a/b) * b) (* Comparison operators *) let eq #n (a:int_t n) (b:int_t n) : Tot bool = a = b let gt #n (a:int_t n) (b:int_t n) : Tot bool = a > b let gte #n (a:int_t n) (b:int_t n) : Tot bool = a >= b let lt #n (a:int_t n) (b:int_t n) : Tot bool = a < b let lte #n (a:int_t n) (b:int_t n) : Tot bool = a <= b #push-options "--initial_fuel 1 --max_fuel 1" /// Casts let to_uint (#n:pos) (x:int_t n) : Tot (UInt.uint_t n) = if 0 <= x then x else x + pow2 n let from_uint (#n:pos) (x:UInt.uint_t n) : Tot (int_t n) = if x <= max_int n then x else x - pow2 n val to_uint_injective: #n:pos -> x:int_t n -> Lemma (ensures from_uint (to_uint x) == x) [SMTPat (to_uint x)] let to_int_t (m:pos) (a:int) : Tot (int_t m) = a @% pow2 m open FStar.Seq (* WARNING: Mind the big endian vs little endian definition *) let to_vec (#n:pos) (num:int_t n) : Tot (bv_t n) = UInt.to_vec (to_uint num) let from_vec (#n:pos) (vec:bv_t n) : Tot (int_t n) = let x = UInt.from_vec vec in if max_int n < x then x - pow2 n else x val to_vec_lemma_1: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires a = b) (ensures equal (to_vec a) (to_vec b)) val to_vec_lemma_2: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires equal (to_vec a) (to_vec b)) (ensures a = b) val inverse_aux: #n:nat -> vec:bv_t n -> i:nat{i < n} -> Lemma (requires True) (ensures index vec i = index (to_vec (from_vec vec)) i) [SMTPat (index (to_vec (from_vec vec)) i)] val inverse_vec_lemma: #n:pos -> vec:bv_t n -> Lemma (requires True) (ensures equal vec (to_vec (from_vec vec))) [SMTPat (to_vec (from_vec vec))] val inverse_num_lemma: #n:pos -> num:int_t n -> Lemma (requires True) (ensures num = from_vec (to_vec num)) [SMTPat (from_vec (to_vec num))] val from_vec_lemma_1: #n:pos -> a:bv_t n -> b:bv_t n -> Lemma (requires equal a b) (ensures from_vec a = from_vec b) val from_vec_lemma_2: #n:pos -> a:bv_t n -> b:bv_t n -> Lemma (requires from_vec a = from_vec b) (ensures equal a b) (* Relations between constants in BitVector and in UInt. *) val zero_to_vec_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (zero n)) i = index (zero_vec #n) i) [SMTPat (index (to_vec (zero n)) i)] val zero_from_vec_lemma: #n:pos -> Lemma (requires True) (ensures from_vec (zero_vec #n) = zero n) [SMTPat (from_vec (zero_vec #n))] val one_to_vec_lemma: #n:pos{1 < n} -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (one n)) i = index (elem_vec #n (n - 1)) i) [SMTPat (index (to_vec (one n)) i)] val pow2_to_vec_lemma: #n:pos -> p:nat{p < n-1} -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (pow2_n #n p)) i = index (elem_vec #n (n - p - 1)) i) [SMTPat (index (to_vec (pow2_n #n p)) i)] val pow2_from_vec_lemma: #n:pos -> p:pos{p < n-1} -> Lemma (requires True) (ensures from_vec (elem_vec #n p) = pow2_n #n (n - p - 1)) [SMTPat (from_vec (elem_vec #n p))] val ones_to_vec_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (ones n)) i = index (ones_vec #n) i) [SMTPat (index (to_vec (ones n)) i)] val ones_from_vec_lemma: #n:pos -> Lemma (requires True) (ensures from_vec (ones_vec #n) = ones n) [SMTPat (from_vec (ones_vec #n))] (* (nth a i) returns a boolean indicating the i-th bit of a. *) let nth (#n:pos) (a:int_t n) (i:nat{i < n}) : Tot bool = index (to_vec #n a) i val nth_lemma: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires forall (i:nat{i < n}). nth a i = nth b i) (ensures a = b) (* Lemmas for constants *) val zero_nth_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures nth (zero n) i = false) [SMTPat (nth (zero n) i)] val one_nth_lemma: #n:pos{1 < n} -> i:nat{i < n} -> Lemma (requires True) (ensures (i = n - 1 ==> nth (one n) i = true) /\ (i < n - 1 ==> nth (one n) i = false)) [SMTPat (nth (one n) i)] val ones_nth_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (ones n) i) = true) [SMTPat (nth (ones n) i)] (* Bitwise operators *) let logand (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = from_vec #n (logand_vec #n (to_vec #n a) (to_vec #n b))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.Int.int_t n -> b: FStar.Int.int_t n -> FStar.Int.int_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.Int.int_t", "FStar.Int.from_vec", "FStar.BitVector.logxor_vec", "FStar.Int.to_vec" ]
[]
false
false
false
false
false
let logxor (#n: pos) (a b: int_t n) : Tot (int_t n) =
from_vec #n (logxor_vec #n (to_vec #n a) (to_vec #n b))
false
FStar.Int.fsti
FStar.Int.mul
val mul (#n: pos) (a b: int_t n) : Pure (int_t n) (requires (size (a * b) n)) (ensures (fun _ -> True))
val mul (#n: pos) (a b: int_t n) : Pure (int_t n) (requires (size (a * b) n)) (ensures (fun _ -> True))
let mul (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 9, "end_line": 142, "start_col": 0, "start_line": 138 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1)) (* Addition primitives *) let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) #push-options "--initial_fuel 1 --max_fuel 1" let add_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a + b) @% (pow2 n) (* Subtraction primitives *) let sub (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a - b) @% (pow2 n)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.Int.int_t n -> b: FStar.Int.int_t n -> Prims.Pure (FStar.Int.int_t n)
Prims.Pure
[]
[]
[ "Prims.pos", "FStar.Int.int_t", "FStar.Mul.op_Star", "FStar.Int.size", "Prims.l_True" ]
[]
false
false
false
false
false
let mul (#n: pos) (a b: int_t n) : Pure (int_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) =
a * b
false
FStar.Int.fsti
FStar.Int.add
val add (#n: pos) (a b: int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True))
val add (#n: pos) (a b: int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True))
let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 9, "end_line": 110, "start_col": 0, "start_line": 106 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.Int.int_t n -> b: FStar.Int.int_t n -> Prims.Pure (FStar.Int.int_t n)
Prims.Pure
[]
[]
[ "Prims.pos", "FStar.Int.int_t", "Prims.op_Addition", "FStar.Int.size", "Prims.l_True" ]
[]
false
false
false
false
false
let add (#n: pos) (a b: int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) =
a + b
false
FStar.Int.fsti
FStar.Int.add_mod
val add_mod (#n: pos) (a b: int_t n) : Tot (int_t n)
val add_mod (#n: pos) (a b: int_t n) : Tot (int_t n)
let add_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a + b) @% (pow2 n)
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 21, "end_line": 120, "start_col": 0, "start_line": 119 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1)) (* Addition primitives *) let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) #push-options "--initial_fuel 1 --max_fuel 1"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.Int.int_t n -> b: FStar.Int.int_t n -> FStar.Int.int_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.Int.int_t", "FStar.Int.op_At_Percent", "Prims.op_Addition", "Prims.pow2" ]
[]
false
false
false
false
false
let add_mod (#n: pos) (a b: int_t n) : Tot (int_t n) =
(a + b) @% (pow2 n)
false
FStar.Int.fsti
FStar.Int.sub_mod
val sub_mod (#n: pos) (a b: int_t n) : Tot (int_t n)
val sub_mod (#n: pos) (a b: int_t n) : Tot (int_t n)
let sub_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a - b) @% (pow2 n)
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 21, "end_line": 135, "start_col": 0, "start_line": 134 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1)) (* Addition primitives *) let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) #push-options "--initial_fuel 1 --max_fuel 1" let add_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a + b) @% (pow2 n) (* Subtraction primitives *) let sub (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.Int.int_t n -> b: FStar.Int.int_t n -> FStar.Int.int_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.Int.int_t", "FStar.Int.op_At_Percent", "Prims.op_Subtraction", "Prims.pow2" ]
[]
false
false
false
false
false
let sub_mod (#n: pos) (a b: int_t n) : Tot (int_t n) =
(a - b) @% (pow2 n)
false
FStar.Int.fsti
FStar.Int.udiv
val udiv (#n: pos) (a: int_t n {min_int n < a}) (b: int_t n {b <> 0}) : Tot (c: int_t n {b <> 0 ==> a / b = c})
val udiv (#n: pos) (a: int_t n {min_int n < a}) (b: int_t n {b <> 0}) : Tot (c: int_t n {b <> 0 ==> a / b = c})
let udiv (#n:pos) (a:int_t n{min_int n < a}) (b:int_t n{b <> 0}) : Tot (c:int_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 9, "end_line": 172, "start_col": 0, "start_line": 169 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1)) (* Addition primitives *) let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) #push-options "--initial_fuel 1 --max_fuel 1" let add_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a + b) @% (pow2 n) (* Subtraction primitives *) let sub (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a - b) @% (pow2 n) (* Multiplication primitives *) let mul (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a * b) @% (pow2 n) #pop-options (* Division primitives *) let div (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Pure (int_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:pos -> a:int_t n -> b:int_t n{b <> 0} -> Pure (int_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:int_t n{min_int n < a} -> b:int_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.Int.int_t n {FStar.Int.min_int n < a} -> b: FStar.Int.int_t n {b <> 0} -> c: FStar.Int.int_t n {b <> 0 ==> a / b = c}
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.Int.int_t", "Prims.b2t", "Prims.op_LessThan", "FStar.Int.min_int", "Prims.op_disEquality", "Prims.int", "FStar.Int.op_Slash", "Prims.unit", "FStar.Int.div_size", "Prims.l_imp", "Prims.op_Equality" ]
[]
false
false
false
false
false
let udiv (#n: pos) (a: int_t n {min_int n < a}) (b: int_t n {b <> 0}) : Tot (c: int_t n {b <> 0 ==> a / b = c}) =
div_size #n a b; a / b
false
FStar.Int.fsti
FStar.Int.lognot
val lognot (#n: pos) (a: int_t n) : Tot (int_t n)
val lognot (#n: pos) (a: int_t n) : Tot (int_t n)
let lognot (#n:pos) (a:int_t n) : Tot (int_t n)= from_vec #n (lognot_vec #n (to_vec #n a))
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 43, "end_line": 302, "start_col": 0, "start_line": 301 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1)) (* Addition primitives *) let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) #push-options "--initial_fuel 1 --max_fuel 1" let add_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a + b) @% (pow2 n) (* Subtraction primitives *) let sub (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a - b) @% (pow2 n) (* Multiplication primitives *) let mul (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a * b) @% (pow2 n) #pop-options (* Division primitives *) let div (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Pure (int_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:pos -> a:int_t n -> b:int_t n{b <> 0} -> Pure (int_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:int_t n{min_int n < a} -> b:int_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:int_t n{min_int n < a}) (b:int_t n{b <> 0}) : Tot (c:int_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b (* Modulo primitives *) let mod (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Tot (int_t n) = a - ((a/b) * b) (* Comparison operators *) let eq #n (a:int_t n) (b:int_t n) : Tot bool = a = b let gt #n (a:int_t n) (b:int_t n) : Tot bool = a > b let gte #n (a:int_t n) (b:int_t n) : Tot bool = a >= b let lt #n (a:int_t n) (b:int_t n) : Tot bool = a < b let lte #n (a:int_t n) (b:int_t n) : Tot bool = a <= b #push-options "--initial_fuel 1 --max_fuel 1" /// Casts let to_uint (#n:pos) (x:int_t n) : Tot (UInt.uint_t n) = if 0 <= x then x else x + pow2 n let from_uint (#n:pos) (x:UInt.uint_t n) : Tot (int_t n) = if x <= max_int n then x else x - pow2 n val to_uint_injective: #n:pos -> x:int_t n -> Lemma (ensures from_uint (to_uint x) == x) [SMTPat (to_uint x)] let to_int_t (m:pos) (a:int) : Tot (int_t m) = a @% pow2 m open FStar.Seq (* WARNING: Mind the big endian vs little endian definition *) let to_vec (#n:pos) (num:int_t n) : Tot (bv_t n) = UInt.to_vec (to_uint num) let from_vec (#n:pos) (vec:bv_t n) : Tot (int_t n) = let x = UInt.from_vec vec in if max_int n < x then x - pow2 n else x val to_vec_lemma_1: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires a = b) (ensures equal (to_vec a) (to_vec b)) val to_vec_lemma_2: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires equal (to_vec a) (to_vec b)) (ensures a = b) val inverse_aux: #n:nat -> vec:bv_t n -> i:nat{i < n} -> Lemma (requires True) (ensures index vec i = index (to_vec (from_vec vec)) i) [SMTPat (index (to_vec (from_vec vec)) i)] val inverse_vec_lemma: #n:pos -> vec:bv_t n -> Lemma (requires True) (ensures equal vec (to_vec (from_vec vec))) [SMTPat (to_vec (from_vec vec))] val inverse_num_lemma: #n:pos -> num:int_t n -> Lemma (requires True) (ensures num = from_vec (to_vec num)) [SMTPat (from_vec (to_vec num))] val from_vec_lemma_1: #n:pos -> a:bv_t n -> b:bv_t n -> Lemma (requires equal a b) (ensures from_vec a = from_vec b) val from_vec_lemma_2: #n:pos -> a:bv_t n -> b:bv_t n -> Lemma (requires from_vec a = from_vec b) (ensures equal a b) (* Relations between constants in BitVector and in UInt. *) val zero_to_vec_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (zero n)) i = index (zero_vec #n) i) [SMTPat (index (to_vec (zero n)) i)] val zero_from_vec_lemma: #n:pos -> Lemma (requires True) (ensures from_vec (zero_vec #n) = zero n) [SMTPat (from_vec (zero_vec #n))] val one_to_vec_lemma: #n:pos{1 < n} -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (one n)) i = index (elem_vec #n (n - 1)) i) [SMTPat (index (to_vec (one n)) i)] val pow2_to_vec_lemma: #n:pos -> p:nat{p < n-1} -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (pow2_n #n p)) i = index (elem_vec #n (n - p - 1)) i) [SMTPat (index (to_vec (pow2_n #n p)) i)] val pow2_from_vec_lemma: #n:pos -> p:pos{p < n-1} -> Lemma (requires True) (ensures from_vec (elem_vec #n p) = pow2_n #n (n - p - 1)) [SMTPat (from_vec (elem_vec #n p))] val ones_to_vec_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (ones n)) i = index (ones_vec #n) i) [SMTPat (index (to_vec (ones n)) i)] val ones_from_vec_lemma: #n:pos -> Lemma (requires True) (ensures from_vec (ones_vec #n) = ones n) [SMTPat (from_vec (ones_vec #n))] (* (nth a i) returns a boolean indicating the i-th bit of a. *) let nth (#n:pos) (a:int_t n) (i:nat{i < n}) : Tot bool = index (to_vec #n a) i val nth_lemma: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires forall (i:nat{i < n}). nth a i = nth b i) (ensures a = b) (* Lemmas for constants *) val zero_nth_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures nth (zero n) i = false) [SMTPat (nth (zero n) i)] val one_nth_lemma: #n:pos{1 < n} -> i:nat{i < n} -> Lemma (requires True) (ensures (i = n - 1 ==> nth (one n) i = true) /\ (i < n - 1 ==> nth (one n) i = false)) [SMTPat (nth (one n) i)] val ones_nth_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (ones n) i) = true) [SMTPat (nth (ones n) i)] (* Bitwise operators *) let logand (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = from_vec #n (logand_vec #n (to_vec #n a) (to_vec #n b)) let logxor (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = from_vec #n (logxor_vec #n (to_vec #n a) (to_vec #n b)) let logor (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = from_vec #n (logor_vec #n (to_vec #n a) (to_vec #n b))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.Int.int_t n -> FStar.Int.int_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.Int.int_t", "FStar.Int.from_vec", "FStar.BitVector.lognot_vec", "FStar.Int.to_vec" ]
[]
false
false
false
false
false
let lognot (#n: pos) (a: int_t n) : Tot (int_t n) =
from_vec #n (lognot_vec #n (to_vec #n a))
false
FStar.Int.fsti
FStar.Int.sub
val sub (#n: pos) (a b: int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True))
val sub (#n: pos) (a b: int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True))
let sub (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 9, "end_line": 127, "start_col": 0, "start_line": 123 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1)) (* Addition primitives *) let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) #push-options "--initial_fuel 1 --max_fuel 1" let add_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a + b) @% (pow2 n)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.Int.int_t n -> b: FStar.Int.int_t n -> Prims.Pure (FStar.Int.int_t n)
Prims.Pure
[]
[]
[ "Prims.pos", "FStar.Int.int_t", "Prims.op_Subtraction", "FStar.Int.size", "Prims.l_True" ]
[]
false
false
false
false
false
let sub (#n: pos) (a b: int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) =
a - b
false
FStar.Int.fsti
FStar.Int.mod
val mod (#n: pos) (a: int_t n) (b: int_t n {b <> 0}) : Tot (int_t n)
val mod (#n: pos) (a: int_t n) (b: int_t n {b <> 0}) : Tot (int_t n)
let mod (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Tot (int_t n) = a - ((a/b) * b)
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 177, "start_col": 0, "start_line": 176 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1)) (* Addition primitives *) let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) #push-options "--initial_fuel 1 --max_fuel 1" let add_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a + b) @% (pow2 n) (* Subtraction primitives *) let sub (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a - b) @% (pow2 n) (* Multiplication primitives *) let mul (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a * b) @% (pow2 n) #pop-options (* Division primitives *) let div (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Pure (int_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:pos -> a:int_t n -> b:int_t n{b <> 0} -> Pure (int_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:int_t n{min_int n < a} -> b:int_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:int_t n{min_int n < a}) (b:int_t n{b <> 0}) : Tot (c:int_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.Int.int_t n -> b: FStar.Int.int_t n {b <> 0} -> FStar.Int.int_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.Int.int_t", "Prims.b2t", "Prims.op_disEquality", "Prims.int", "Prims.op_Subtraction", "FStar.Mul.op_Star", "FStar.Int.op_Slash" ]
[]
false
false
false
false
false
let mod (#n: pos) (a: int_t n) (b: int_t n {b <> 0}) : Tot (int_t n) =
a - ((a / b) * b)
false
FStar.Int.fsti
FStar.Int.shift_left
val shift_left (#n: pos) (a: int_t n {0 <= a}) (s: nat) : Tot (int_t n)
val shift_left (#n: pos) (a: int_t n {0 <= a}) (s: nat) : Tot (int_t n)
let shift_left (#n:pos) (a:int_t n{0 <= a}) (s:nat) : Tot (int_t n) = from_vec (shift_left_vec #n (to_vec #n a) s)
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 46, "end_line": 394, "start_col": 0, "start_line": 393 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1)) (* Addition primitives *) let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) #push-options "--initial_fuel 1 --max_fuel 1" let add_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a + b) @% (pow2 n) (* Subtraction primitives *) let sub (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a - b) @% (pow2 n) (* Multiplication primitives *) let mul (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a * b) @% (pow2 n) #pop-options (* Division primitives *) let div (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Pure (int_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:pos -> a:int_t n -> b:int_t n{b <> 0} -> Pure (int_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:int_t n{min_int n < a} -> b:int_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:int_t n{min_int n < a}) (b:int_t n{b <> 0}) : Tot (c:int_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b (* Modulo primitives *) let mod (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Tot (int_t n) = a - ((a/b) * b) (* Comparison operators *) let eq #n (a:int_t n) (b:int_t n) : Tot bool = a = b let gt #n (a:int_t n) (b:int_t n) : Tot bool = a > b let gte #n (a:int_t n) (b:int_t n) : Tot bool = a >= b let lt #n (a:int_t n) (b:int_t n) : Tot bool = a < b let lte #n (a:int_t n) (b:int_t n) : Tot bool = a <= b #push-options "--initial_fuel 1 --max_fuel 1" /// Casts let to_uint (#n:pos) (x:int_t n) : Tot (UInt.uint_t n) = if 0 <= x then x else x + pow2 n let from_uint (#n:pos) (x:UInt.uint_t n) : Tot (int_t n) = if x <= max_int n then x else x - pow2 n val to_uint_injective: #n:pos -> x:int_t n -> Lemma (ensures from_uint (to_uint x) == x) [SMTPat (to_uint x)] let to_int_t (m:pos) (a:int) : Tot (int_t m) = a @% pow2 m open FStar.Seq (* WARNING: Mind the big endian vs little endian definition *) let to_vec (#n:pos) (num:int_t n) : Tot (bv_t n) = UInt.to_vec (to_uint num) let from_vec (#n:pos) (vec:bv_t n) : Tot (int_t n) = let x = UInt.from_vec vec in if max_int n < x then x - pow2 n else x val to_vec_lemma_1: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires a = b) (ensures equal (to_vec a) (to_vec b)) val to_vec_lemma_2: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires equal (to_vec a) (to_vec b)) (ensures a = b) val inverse_aux: #n:nat -> vec:bv_t n -> i:nat{i < n} -> Lemma (requires True) (ensures index vec i = index (to_vec (from_vec vec)) i) [SMTPat (index (to_vec (from_vec vec)) i)] val inverse_vec_lemma: #n:pos -> vec:bv_t n -> Lemma (requires True) (ensures equal vec (to_vec (from_vec vec))) [SMTPat (to_vec (from_vec vec))] val inverse_num_lemma: #n:pos -> num:int_t n -> Lemma (requires True) (ensures num = from_vec (to_vec num)) [SMTPat (from_vec (to_vec num))] val from_vec_lemma_1: #n:pos -> a:bv_t n -> b:bv_t n -> Lemma (requires equal a b) (ensures from_vec a = from_vec b) val from_vec_lemma_2: #n:pos -> a:bv_t n -> b:bv_t n -> Lemma (requires from_vec a = from_vec b) (ensures equal a b) (* Relations between constants in BitVector and in UInt. *) val zero_to_vec_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (zero n)) i = index (zero_vec #n) i) [SMTPat (index (to_vec (zero n)) i)] val zero_from_vec_lemma: #n:pos -> Lemma (requires True) (ensures from_vec (zero_vec #n) = zero n) [SMTPat (from_vec (zero_vec #n))] val one_to_vec_lemma: #n:pos{1 < n} -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (one n)) i = index (elem_vec #n (n - 1)) i) [SMTPat (index (to_vec (one n)) i)] val pow2_to_vec_lemma: #n:pos -> p:nat{p < n-1} -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (pow2_n #n p)) i = index (elem_vec #n (n - p - 1)) i) [SMTPat (index (to_vec (pow2_n #n p)) i)] val pow2_from_vec_lemma: #n:pos -> p:pos{p < n-1} -> Lemma (requires True) (ensures from_vec (elem_vec #n p) = pow2_n #n (n - p - 1)) [SMTPat (from_vec (elem_vec #n p))] val ones_to_vec_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (ones n)) i = index (ones_vec #n) i) [SMTPat (index (to_vec (ones n)) i)] val ones_from_vec_lemma: #n:pos -> Lemma (requires True) (ensures from_vec (ones_vec #n) = ones n) [SMTPat (from_vec (ones_vec #n))] (* (nth a i) returns a boolean indicating the i-th bit of a. *) let nth (#n:pos) (a:int_t n) (i:nat{i < n}) : Tot bool = index (to_vec #n a) i val nth_lemma: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires forall (i:nat{i < n}). nth a i = nth b i) (ensures a = b) (* Lemmas for constants *) val zero_nth_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures nth (zero n) i = false) [SMTPat (nth (zero n) i)] val one_nth_lemma: #n:pos{1 < n} -> i:nat{i < n} -> Lemma (requires True) (ensures (i = n - 1 ==> nth (one n) i = true) /\ (i < n - 1 ==> nth (one n) i = false)) [SMTPat (nth (one n) i)] val ones_nth_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (ones n) i) = true) [SMTPat (nth (ones n) i)] (* Bitwise operators *) let logand (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = from_vec #n (logand_vec #n (to_vec #n a) (to_vec #n b)) let logxor (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = from_vec #n (logxor_vec #n (to_vec #n a) (to_vec #n b)) let logor (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = from_vec #n (logor_vec #n (to_vec #n a) (to_vec #n b)) let lognot (#n:pos) (a:int_t n) : Tot (int_t n)= from_vec #n (lognot_vec #n (to_vec #n a)) (* Bitwise operators definitions *) val logand_definition: #n:pos -> a:int_t n -> b:int_t n -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (logand a b) i = (nth a i && nth b i))) [SMTPat (nth (logand a b) i)] val logxor_definition: #n:pos -> a:int_t n -> b:int_t n -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (logxor a b) i = (nth a i <> nth b i))) [SMTPat (nth (logxor a b) i)] val logor_definition: #n:pos -> a:int_t n -> b:int_t n -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (logor a b) i = (nth a i || nth b i))) [SMTPat (nth (logor a b) i)] val lognot_definition: #n:pos -> a:int_t n -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (lognot a) i = not(nth a i))) [SMTPat (nth (lognot a) i)] (* Two's complement unary minus *) inline_for_extraction let minus (#n:pos{1 < n}) (a:int_t n) : Tot (int_t n) = add_mod (lognot a) 1 (* Bitwise operators lemmas *) (* TODO: lemmas about the relations between different operators *) (* Bitwise AND operator *) val logand_commutative: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires True) (ensures (logand #n a b = logand #n b a)) val logand_associative: #n:pos -> a:int_t n -> b:int_t n -> c:int_t n -> Lemma (logand #n (logand #n a b) c = logand #n a (logand #n b c)) val logand_self: #n:pos -> a:int_t n -> Lemma (logand #n a a = a) val logand_lemma_1: #n:pos -> a:int_t n -> Lemma (requires True) (ensures (logand #n a (zero n) = zero n)) val logand_lemma_2: #n:pos -> a:int_t n -> Lemma (logand #n a (ones n) = a) val sign_bit_negative: #n:pos{1 < n} -> a:int_t n -> Lemma (nth a 0 = true <==> a < 0) val sign_bit_positive: #n:pos{1 < n} -> a:int_t n -> Lemma (nth a 0 = false <==> 0 <= a) val logand_pos_le: #n:pos{1 < n} -> a:int_t n{0 <= a} -> b:int_t n{0 <= b} -> Lemma (0 <= logand a b /\ logand a b <= a /\ logand a b <= b) val logand_pow2_minus_one: #n:pos{1 < n} -> a:int_t n -> m:pos{m < n} -> Lemma (0 <= logand a (pow2_minus_one m) /\ logand a (pow2_minus_one m) <= pow2_minus_one #n m) val logand_max: #n:pos{1 < n} -> a:int_t n{0 <= a} -> Lemma (0 <= logand a (max_int n) /\ a = logand a (max_int n)) (* Bitwise XOR operator *) val logxor_commutative: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires True) (ensures (logxor #n a b = logxor #n b a)) val logxor_associative: #n:pos -> a:int_t n -> b:int_t n -> c:int_t n -> Lemma (requires True) (ensures (logxor #n (logxor #n a b) c = logxor #n a (logxor #n b c))) val logxor_self: #n:pos -> a:int_t n -> Lemma (requires True) (ensures (logxor #n a a = zero n)) val logxor_lemma_1: #n:pos -> a:int_t n -> Lemma (requires True) (ensures (logxor #n a (zero n) = a)) val logxor_lemma_2: #n:pos -> a:int_t n -> Lemma (requires True) (ensures (logxor #n a (ones n) = lognot #n a)) val logxor_inv: #n:pos -> a:int_t n -> b:int_t n -> Lemma (a = logxor #n (logxor #n a b) b) val logxor_neq_nonzero: #n:pos -> a:int_t n -> b:int_t n -> Lemma (a <> b ==> logxor a b <> 0) val lognot_negative: #n:pos -> a:int_t n -> Lemma (requires a < 0) (ensures lognot a == UInt.lognot #n (a + pow2 n)) (* Shift operators *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.Int.int_t n {0 <= a} -> s: Prims.nat -> FStar.Int.int_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.Int.int_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.nat", "FStar.Int.from_vec", "FStar.BitVector.shift_left_vec", "FStar.Int.to_vec" ]
[]
false
false
false
false
false
let shift_left (#n: pos) (a: int_t n {0 <= a}) (s: nat) : Tot (int_t n) =
from_vec (shift_left_vec #n (to_vec #n a) s)
false
FStar.Int.fsti
FStar.Int.mul_mod
val mul_mod (#n: pos) (a b: int_t n) : Tot (int_t n)
val mul_mod (#n: pos) (a b: int_t n) : Tot (int_t n)
let mul_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a * b) @% (pow2 n)
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 21, "end_line": 150, "start_col": 0, "start_line": 149 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1)) (* Addition primitives *) let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) #push-options "--initial_fuel 1 --max_fuel 1" let add_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a + b) @% (pow2 n) (* Subtraction primitives *) let sub (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a - b) @% (pow2 n) (* Multiplication primitives *) let mul (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.Int.int_t n -> b: FStar.Int.int_t n -> FStar.Int.int_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.Int.int_t", "FStar.Int.op_At_Percent", "FStar.Mul.op_Star", "Prims.pow2" ]
[]
false
false
false
false
false
let mul_mod (#n: pos) (a b: int_t n) : Tot (int_t n) =
(a * b) @% (pow2 n)
false
FStar.Int.fsti
FStar.Int.logor
val logor (#n: pos) (a b: int_t n) : Tot (int_t n)
val logor (#n: pos) (a b: int_t n) : Tot (int_t n)
let logor (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = from_vec #n (logor_vec #n (to_vec #n a) (to_vec #n b))
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 56, "end_line": 299, "start_col": 0, "start_line": 298 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1)) (* Addition primitives *) let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) #push-options "--initial_fuel 1 --max_fuel 1" let add_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a + b) @% (pow2 n) (* Subtraction primitives *) let sub (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a - b) @% (pow2 n) (* Multiplication primitives *) let mul (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a * b) @% (pow2 n) #pop-options (* Division primitives *) let div (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Pure (int_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:pos -> a:int_t n -> b:int_t n{b <> 0} -> Pure (int_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:int_t n{min_int n < a} -> b:int_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:int_t n{min_int n < a}) (b:int_t n{b <> 0}) : Tot (c:int_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b (* Modulo primitives *) let mod (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Tot (int_t n) = a - ((a/b) * b) (* Comparison operators *) let eq #n (a:int_t n) (b:int_t n) : Tot bool = a = b let gt #n (a:int_t n) (b:int_t n) : Tot bool = a > b let gte #n (a:int_t n) (b:int_t n) : Tot bool = a >= b let lt #n (a:int_t n) (b:int_t n) : Tot bool = a < b let lte #n (a:int_t n) (b:int_t n) : Tot bool = a <= b #push-options "--initial_fuel 1 --max_fuel 1" /// Casts let to_uint (#n:pos) (x:int_t n) : Tot (UInt.uint_t n) = if 0 <= x then x else x + pow2 n let from_uint (#n:pos) (x:UInt.uint_t n) : Tot (int_t n) = if x <= max_int n then x else x - pow2 n val to_uint_injective: #n:pos -> x:int_t n -> Lemma (ensures from_uint (to_uint x) == x) [SMTPat (to_uint x)] let to_int_t (m:pos) (a:int) : Tot (int_t m) = a @% pow2 m open FStar.Seq (* WARNING: Mind the big endian vs little endian definition *) let to_vec (#n:pos) (num:int_t n) : Tot (bv_t n) = UInt.to_vec (to_uint num) let from_vec (#n:pos) (vec:bv_t n) : Tot (int_t n) = let x = UInt.from_vec vec in if max_int n < x then x - pow2 n else x val to_vec_lemma_1: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires a = b) (ensures equal (to_vec a) (to_vec b)) val to_vec_lemma_2: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires equal (to_vec a) (to_vec b)) (ensures a = b) val inverse_aux: #n:nat -> vec:bv_t n -> i:nat{i < n} -> Lemma (requires True) (ensures index vec i = index (to_vec (from_vec vec)) i) [SMTPat (index (to_vec (from_vec vec)) i)] val inverse_vec_lemma: #n:pos -> vec:bv_t n -> Lemma (requires True) (ensures equal vec (to_vec (from_vec vec))) [SMTPat (to_vec (from_vec vec))] val inverse_num_lemma: #n:pos -> num:int_t n -> Lemma (requires True) (ensures num = from_vec (to_vec num)) [SMTPat (from_vec (to_vec num))] val from_vec_lemma_1: #n:pos -> a:bv_t n -> b:bv_t n -> Lemma (requires equal a b) (ensures from_vec a = from_vec b) val from_vec_lemma_2: #n:pos -> a:bv_t n -> b:bv_t n -> Lemma (requires from_vec a = from_vec b) (ensures equal a b) (* Relations between constants in BitVector and in UInt. *) val zero_to_vec_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (zero n)) i = index (zero_vec #n) i) [SMTPat (index (to_vec (zero n)) i)] val zero_from_vec_lemma: #n:pos -> Lemma (requires True) (ensures from_vec (zero_vec #n) = zero n) [SMTPat (from_vec (zero_vec #n))] val one_to_vec_lemma: #n:pos{1 < n} -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (one n)) i = index (elem_vec #n (n - 1)) i) [SMTPat (index (to_vec (one n)) i)] val pow2_to_vec_lemma: #n:pos -> p:nat{p < n-1} -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (pow2_n #n p)) i = index (elem_vec #n (n - p - 1)) i) [SMTPat (index (to_vec (pow2_n #n p)) i)] val pow2_from_vec_lemma: #n:pos -> p:pos{p < n-1} -> Lemma (requires True) (ensures from_vec (elem_vec #n p) = pow2_n #n (n - p - 1)) [SMTPat (from_vec (elem_vec #n p))] val ones_to_vec_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (ones n)) i = index (ones_vec #n) i) [SMTPat (index (to_vec (ones n)) i)] val ones_from_vec_lemma: #n:pos -> Lemma (requires True) (ensures from_vec (ones_vec #n) = ones n) [SMTPat (from_vec (ones_vec #n))] (* (nth a i) returns a boolean indicating the i-th bit of a. *) let nth (#n:pos) (a:int_t n) (i:nat{i < n}) : Tot bool = index (to_vec #n a) i val nth_lemma: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires forall (i:nat{i < n}). nth a i = nth b i) (ensures a = b) (* Lemmas for constants *) val zero_nth_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures nth (zero n) i = false) [SMTPat (nth (zero n) i)] val one_nth_lemma: #n:pos{1 < n} -> i:nat{i < n} -> Lemma (requires True) (ensures (i = n - 1 ==> nth (one n) i = true) /\ (i < n - 1 ==> nth (one n) i = false)) [SMTPat (nth (one n) i)] val ones_nth_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (ones n) i) = true) [SMTPat (nth (ones n) i)] (* Bitwise operators *) let logand (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = from_vec #n (logand_vec #n (to_vec #n a) (to_vec #n b)) let logxor (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = from_vec #n (logxor_vec #n (to_vec #n a) (to_vec #n b))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.Int.int_t n -> b: FStar.Int.int_t n -> FStar.Int.int_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.Int.int_t", "FStar.Int.from_vec", "FStar.BitVector.logor_vec", "FStar.Int.to_vec" ]
[]
false
false
false
false
false
let logor (#n: pos) (a b: int_t n) : Tot (int_t n) =
from_vec #n (logor_vec #n (to_vec #n a) (to_vec #n b))
false
FStar.Int.fsti
FStar.Int.shift_arithmetic_right
val shift_arithmetic_right (#n: pos) (a: int_t n) (s: nat) : Tot (int_t n)
val shift_arithmetic_right (#n: pos) (a: int_t n) (s: nat) : Tot (int_t n)
let shift_arithmetic_right (#n:pos) (a:int_t n) (s:nat) : Tot (int_t n) = from_vec (shift_arithmetic_right_vec #n (to_vec #n a) s)
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 58, "end_line": 401, "start_col": 0, "start_line": 400 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1)) (* Addition primitives *) let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) #push-options "--initial_fuel 1 --max_fuel 1" let add_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a + b) @% (pow2 n) (* Subtraction primitives *) let sub (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a - b) @% (pow2 n) (* Multiplication primitives *) let mul (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a * b) @% (pow2 n) #pop-options (* Division primitives *) let div (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Pure (int_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:pos -> a:int_t n -> b:int_t n{b <> 0} -> Pure (int_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:int_t n{min_int n < a} -> b:int_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:int_t n{min_int n < a}) (b:int_t n{b <> 0}) : Tot (c:int_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b (* Modulo primitives *) let mod (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Tot (int_t n) = a - ((a/b) * b) (* Comparison operators *) let eq #n (a:int_t n) (b:int_t n) : Tot bool = a = b let gt #n (a:int_t n) (b:int_t n) : Tot bool = a > b let gte #n (a:int_t n) (b:int_t n) : Tot bool = a >= b let lt #n (a:int_t n) (b:int_t n) : Tot bool = a < b let lte #n (a:int_t n) (b:int_t n) : Tot bool = a <= b #push-options "--initial_fuel 1 --max_fuel 1" /// Casts let to_uint (#n:pos) (x:int_t n) : Tot (UInt.uint_t n) = if 0 <= x then x else x + pow2 n let from_uint (#n:pos) (x:UInt.uint_t n) : Tot (int_t n) = if x <= max_int n then x else x - pow2 n val to_uint_injective: #n:pos -> x:int_t n -> Lemma (ensures from_uint (to_uint x) == x) [SMTPat (to_uint x)] let to_int_t (m:pos) (a:int) : Tot (int_t m) = a @% pow2 m open FStar.Seq (* WARNING: Mind the big endian vs little endian definition *) let to_vec (#n:pos) (num:int_t n) : Tot (bv_t n) = UInt.to_vec (to_uint num) let from_vec (#n:pos) (vec:bv_t n) : Tot (int_t n) = let x = UInt.from_vec vec in if max_int n < x then x - pow2 n else x val to_vec_lemma_1: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires a = b) (ensures equal (to_vec a) (to_vec b)) val to_vec_lemma_2: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires equal (to_vec a) (to_vec b)) (ensures a = b) val inverse_aux: #n:nat -> vec:bv_t n -> i:nat{i < n} -> Lemma (requires True) (ensures index vec i = index (to_vec (from_vec vec)) i) [SMTPat (index (to_vec (from_vec vec)) i)] val inverse_vec_lemma: #n:pos -> vec:bv_t n -> Lemma (requires True) (ensures equal vec (to_vec (from_vec vec))) [SMTPat (to_vec (from_vec vec))] val inverse_num_lemma: #n:pos -> num:int_t n -> Lemma (requires True) (ensures num = from_vec (to_vec num)) [SMTPat (from_vec (to_vec num))] val from_vec_lemma_1: #n:pos -> a:bv_t n -> b:bv_t n -> Lemma (requires equal a b) (ensures from_vec a = from_vec b) val from_vec_lemma_2: #n:pos -> a:bv_t n -> b:bv_t n -> Lemma (requires from_vec a = from_vec b) (ensures equal a b) (* Relations between constants in BitVector and in UInt. *) val zero_to_vec_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (zero n)) i = index (zero_vec #n) i) [SMTPat (index (to_vec (zero n)) i)] val zero_from_vec_lemma: #n:pos -> Lemma (requires True) (ensures from_vec (zero_vec #n) = zero n) [SMTPat (from_vec (zero_vec #n))] val one_to_vec_lemma: #n:pos{1 < n} -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (one n)) i = index (elem_vec #n (n - 1)) i) [SMTPat (index (to_vec (one n)) i)] val pow2_to_vec_lemma: #n:pos -> p:nat{p < n-1} -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (pow2_n #n p)) i = index (elem_vec #n (n - p - 1)) i) [SMTPat (index (to_vec (pow2_n #n p)) i)] val pow2_from_vec_lemma: #n:pos -> p:pos{p < n-1} -> Lemma (requires True) (ensures from_vec (elem_vec #n p) = pow2_n #n (n - p - 1)) [SMTPat (from_vec (elem_vec #n p))] val ones_to_vec_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (ones n)) i = index (ones_vec #n) i) [SMTPat (index (to_vec (ones n)) i)] val ones_from_vec_lemma: #n:pos -> Lemma (requires True) (ensures from_vec (ones_vec #n) = ones n) [SMTPat (from_vec (ones_vec #n))] (* (nth a i) returns a boolean indicating the i-th bit of a. *) let nth (#n:pos) (a:int_t n) (i:nat{i < n}) : Tot bool = index (to_vec #n a) i val nth_lemma: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires forall (i:nat{i < n}). nth a i = nth b i) (ensures a = b) (* Lemmas for constants *) val zero_nth_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures nth (zero n) i = false) [SMTPat (nth (zero n) i)] val one_nth_lemma: #n:pos{1 < n} -> i:nat{i < n} -> Lemma (requires True) (ensures (i = n - 1 ==> nth (one n) i = true) /\ (i < n - 1 ==> nth (one n) i = false)) [SMTPat (nth (one n) i)] val ones_nth_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (ones n) i) = true) [SMTPat (nth (ones n) i)] (* Bitwise operators *) let logand (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = from_vec #n (logand_vec #n (to_vec #n a) (to_vec #n b)) let logxor (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = from_vec #n (logxor_vec #n (to_vec #n a) (to_vec #n b)) let logor (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = from_vec #n (logor_vec #n (to_vec #n a) (to_vec #n b)) let lognot (#n:pos) (a:int_t n) : Tot (int_t n)= from_vec #n (lognot_vec #n (to_vec #n a)) (* Bitwise operators definitions *) val logand_definition: #n:pos -> a:int_t n -> b:int_t n -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (logand a b) i = (nth a i && nth b i))) [SMTPat (nth (logand a b) i)] val logxor_definition: #n:pos -> a:int_t n -> b:int_t n -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (logxor a b) i = (nth a i <> nth b i))) [SMTPat (nth (logxor a b) i)] val logor_definition: #n:pos -> a:int_t n -> b:int_t n -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (logor a b) i = (nth a i || nth b i))) [SMTPat (nth (logor a b) i)] val lognot_definition: #n:pos -> a:int_t n -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (lognot a) i = not(nth a i))) [SMTPat (nth (lognot a) i)] (* Two's complement unary minus *) inline_for_extraction let minus (#n:pos{1 < n}) (a:int_t n) : Tot (int_t n) = add_mod (lognot a) 1 (* Bitwise operators lemmas *) (* TODO: lemmas about the relations between different operators *) (* Bitwise AND operator *) val logand_commutative: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires True) (ensures (logand #n a b = logand #n b a)) val logand_associative: #n:pos -> a:int_t n -> b:int_t n -> c:int_t n -> Lemma (logand #n (logand #n a b) c = logand #n a (logand #n b c)) val logand_self: #n:pos -> a:int_t n -> Lemma (logand #n a a = a) val logand_lemma_1: #n:pos -> a:int_t n -> Lemma (requires True) (ensures (logand #n a (zero n) = zero n)) val logand_lemma_2: #n:pos -> a:int_t n -> Lemma (logand #n a (ones n) = a) val sign_bit_negative: #n:pos{1 < n} -> a:int_t n -> Lemma (nth a 0 = true <==> a < 0) val sign_bit_positive: #n:pos{1 < n} -> a:int_t n -> Lemma (nth a 0 = false <==> 0 <= a) val logand_pos_le: #n:pos{1 < n} -> a:int_t n{0 <= a} -> b:int_t n{0 <= b} -> Lemma (0 <= logand a b /\ logand a b <= a /\ logand a b <= b) val logand_pow2_minus_one: #n:pos{1 < n} -> a:int_t n -> m:pos{m < n} -> Lemma (0 <= logand a (pow2_minus_one m) /\ logand a (pow2_minus_one m) <= pow2_minus_one #n m) val logand_max: #n:pos{1 < n} -> a:int_t n{0 <= a} -> Lemma (0 <= logand a (max_int n) /\ a = logand a (max_int n)) (* Bitwise XOR operator *) val logxor_commutative: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires True) (ensures (logxor #n a b = logxor #n b a)) val logxor_associative: #n:pos -> a:int_t n -> b:int_t n -> c:int_t n -> Lemma (requires True) (ensures (logxor #n (logxor #n a b) c = logxor #n a (logxor #n b c))) val logxor_self: #n:pos -> a:int_t n -> Lemma (requires True) (ensures (logxor #n a a = zero n)) val logxor_lemma_1: #n:pos -> a:int_t n -> Lemma (requires True) (ensures (logxor #n a (zero n) = a)) val logxor_lemma_2: #n:pos -> a:int_t n -> Lemma (requires True) (ensures (logxor #n a (ones n) = lognot #n a)) val logxor_inv: #n:pos -> a:int_t n -> b:int_t n -> Lemma (a = logxor #n (logxor #n a b) b) val logxor_neq_nonzero: #n:pos -> a:int_t n -> b:int_t n -> Lemma (a <> b ==> logxor a b <> 0) val lognot_negative: #n:pos -> a:int_t n -> Lemma (requires a < 0) (ensures lognot a == UInt.lognot #n (a + pow2 n)) (* Shift operators *) (** If a is negative the result is undefined behaviour *) let shift_left (#n:pos) (a:int_t n{0 <= a}) (s:nat) : Tot (int_t n) = from_vec (shift_left_vec #n (to_vec #n a) s) (** If a is negative the result is implementation defined *) let shift_right (#n:pos) (a:int_t n{0 <= a}) (s:nat) : Tot (int_t n) = from_vec (shift_right_vec #n (to_vec #n a) s)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.Int.int_t n -> s: Prims.nat -> FStar.Int.int_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.Int.int_t", "Prims.nat", "FStar.Int.from_vec", "FStar.BitVector.shift_arithmetic_right_vec", "FStar.Int.to_vec" ]
[]
false
false
false
false
false
let shift_arithmetic_right (#n: pos) (a: int_t n) (s: nat) : Tot (int_t n) =
from_vec (shift_arithmetic_right_vec #n (to_vec #n a) s)
false
FStar.Int.fsti
FStar.Int.div
val div (#n: pos) (a: int_t n) (b: int_t n {b <> 0}) : Pure (int_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c))
val div (#n: pos) (a: int_t n) (b: int_t n {b <> 0}) : Pure (int_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c))
let div (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Pure (int_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 7, "end_line": 159, "start_col": 0, "start_line": 155 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1)) (* Addition primitives *) let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) #push-options "--initial_fuel 1 --max_fuel 1" let add_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a + b) @% (pow2 n) (* Subtraction primitives *) let sub (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a - b) @% (pow2 n) (* Multiplication primitives *) let mul (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a * b) @% (pow2 n) #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.Int.int_t n -> b: FStar.Int.int_t n {b <> 0} -> Prims.Pure (FStar.Int.int_t n)
Prims.Pure
[]
[]
[ "Prims.pos", "FStar.Int.int_t", "Prims.b2t", "Prims.op_disEquality", "Prims.int", "FStar.Int.op_Slash", "FStar.Int.size", "Prims.l_imp", "Prims.op_Equality" ]
[]
false
false
false
false
false
let div (#n: pos) (a: int_t n) (b: int_t n {b <> 0}) : Pure (int_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) =
a / b
false
FStar.Int.fsti
FStar.Int.to_vec
val to_vec (#n: pos) (num: int_t n) : Tot (bv_t n)
val to_vec (#n: pos) (num: int_t n) : Tot (bv_t n)
let to_vec (#n:pos) (num:int_t n) : Tot (bv_t n) = UInt.to_vec (to_uint num)
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 27, "end_line": 206, "start_col": 0, "start_line": 205 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1)) (* Addition primitives *) let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) #push-options "--initial_fuel 1 --max_fuel 1" let add_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a + b) @% (pow2 n) (* Subtraction primitives *) let sub (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a - b) @% (pow2 n) (* Multiplication primitives *) let mul (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a * b) @% (pow2 n) #pop-options (* Division primitives *) let div (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Pure (int_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:pos -> a:int_t n -> b:int_t n{b <> 0} -> Pure (int_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:int_t n{min_int n < a} -> b:int_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:int_t n{min_int n < a}) (b:int_t n{b <> 0}) : Tot (c:int_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b (* Modulo primitives *) let mod (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Tot (int_t n) = a - ((a/b) * b) (* Comparison operators *) let eq #n (a:int_t n) (b:int_t n) : Tot bool = a = b let gt #n (a:int_t n) (b:int_t n) : Tot bool = a > b let gte #n (a:int_t n) (b:int_t n) : Tot bool = a >= b let lt #n (a:int_t n) (b:int_t n) : Tot bool = a < b let lte #n (a:int_t n) (b:int_t n) : Tot bool = a <= b #push-options "--initial_fuel 1 --max_fuel 1" /// Casts let to_uint (#n:pos) (x:int_t n) : Tot (UInt.uint_t n) = if 0 <= x then x else x + pow2 n let from_uint (#n:pos) (x:UInt.uint_t n) : Tot (int_t n) = if x <= max_int n then x else x - pow2 n val to_uint_injective: #n:pos -> x:int_t n -> Lemma (ensures from_uint (to_uint x) == x) [SMTPat (to_uint x)] let to_int_t (m:pos) (a:int) : Tot (int_t m) = a @% pow2 m open FStar.Seq (* WARNING: Mind the big endian vs little endian definition *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
num: FStar.Int.int_t n -> FStar.BitVector.bv_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.Int.int_t", "FStar.UInt.to_vec", "FStar.Int.to_uint", "FStar.BitVector.bv_t" ]
[]
false
false
false
false
false
let to_vec (#n: pos) (num: int_t n) : Tot (bv_t n) =
UInt.to_vec (to_uint num)
false
FStar.Int.fsti
FStar.Int.shift_right
val shift_right (#n: pos) (a: int_t n {0 <= a}) (s: nat) : Tot (int_t n)
val shift_right (#n: pos) (a: int_t n {0 <= a}) (s: nat) : Tot (int_t n)
let shift_right (#n:pos) (a:int_t n{0 <= a}) (s:nat) : Tot (int_t n) = from_vec (shift_right_vec #n (to_vec #n a) s)
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 47, "end_line": 398, "start_col": 0, "start_line": 397 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1)) (* Addition primitives *) let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) #push-options "--initial_fuel 1 --max_fuel 1" let add_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a + b) @% (pow2 n) (* Subtraction primitives *) let sub (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a - b) @% (pow2 n) (* Multiplication primitives *) let mul (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a * b) @% (pow2 n) #pop-options (* Division primitives *) let div (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Pure (int_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:pos -> a:int_t n -> b:int_t n{b <> 0} -> Pure (int_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:int_t n{min_int n < a} -> b:int_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:int_t n{min_int n < a}) (b:int_t n{b <> 0}) : Tot (c:int_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b (* Modulo primitives *) let mod (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Tot (int_t n) = a - ((a/b) * b) (* Comparison operators *) let eq #n (a:int_t n) (b:int_t n) : Tot bool = a = b let gt #n (a:int_t n) (b:int_t n) : Tot bool = a > b let gte #n (a:int_t n) (b:int_t n) : Tot bool = a >= b let lt #n (a:int_t n) (b:int_t n) : Tot bool = a < b let lte #n (a:int_t n) (b:int_t n) : Tot bool = a <= b #push-options "--initial_fuel 1 --max_fuel 1" /// Casts let to_uint (#n:pos) (x:int_t n) : Tot (UInt.uint_t n) = if 0 <= x then x else x + pow2 n let from_uint (#n:pos) (x:UInt.uint_t n) : Tot (int_t n) = if x <= max_int n then x else x - pow2 n val to_uint_injective: #n:pos -> x:int_t n -> Lemma (ensures from_uint (to_uint x) == x) [SMTPat (to_uint x)] let to_int_t (m:pos) (a:int) : Tot (int_t m) = a @% pow2 m open FStar.Seq (* WARNING: Mind the big endian vs little endian definition *) let to_vec (#n:pos) (num:int_t n) : Tot (bv_t n) = UInt.to_vec (to_uint num) let from_vec (#n:pos) (vec:bv_t n) : Tot (int_t n) = let x = UInt.from_vec vec in if max_int n < x then x - pow2 n else x val to_vec_lemma_1: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires a = b) (ensures equal (to_vec a) (to_vec b)) val to_vec_lemma_2: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires equal (to_vec a) (to_vec b)) (ensures a = b) val inverse_aux: #n:nat -> vec:bv_t n -> i:nat{i < n} -> Lemma (requires True) (ensures index vec i = index (to_vec (from_vec vec)) i) [SMTPat (index (to_vec (from_vec vec)) i)] val inverse_vec_lemma: #n:pos -> vec:bv_t n -> Lemma (requires True) (ensures equal vec (to_vec (from_vec vec))) [SMTPat (to_vec (from_vec vec))] val inverse_num_lemma: #n:pos -> num:int_t n -> Lemma (requires True) (ensures num = from_vec (to_vec num)) [SMTPat (from_vec (to_vec num))] val from_vec_lemma_1: #n:pos -> a:bv_t n -> b:bv_t n -> Lemma (requires equal a b) (ensures from_vec a = from_vec b) val from_vec_lemma_2: #n:pos -> a:bv_t n -> b:bv_t n -> Lemma (requires from_vec a = from_vec b) (ensures equal a b) (* Relations between constants in BitVector and in UInt. *) val zero_to_vec_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (zero n)) i = index (zero_vec #n) i) [SMTPat (index (to_vec (zero n)) i)] val zero_from_vec_lemma: #n:pos -> Lemma (requires True) (ensures from_vec (zero_vec #n) = zero n) [SMTPat (from_vec (zero_vec #n))] val one_to_vec_lemma: #n:pos{1 < n} -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (one n)) i = index (elem_vec #n (n - 1)) i) [SMTPat (index (to_vec (one n)) i)] val pow2_to_vec_lemma: #n:pos -> p:nat{p < n-1} -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (pow2_n #n p)) i = index (elem_vec #n (n - p - 1)) i) [SMTPat (index (to_vec (pow2_n #n p)) i)] val pow2_from_vec_lemma: #n:pos -> p:pos{p < n-1} -> Lemma (requires True) (ensures from_vec (elem_vec #n p) = pow2_n #n (n - p - 1)) [SMTPat (from_vec (elem_vec #n p))] val ones_to_vec_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (ones n)) i = index (ones_vec #n) i) [SMTPat (index (to_vec (ones n)) i)] val ones_from_vec_lemma: #n:pos -> Lemma (requires True) (ensures from_vec (ones_vec #n) = ones n) [SMTPat (from_vec (ones_vec #n))] (* (nth a i) returns a boolean indicating the i-th bit of a. *) let nth (#n:pos) (a:int_t n) (i:nat{i < n}) : Tot bool = index (to_vec #n a) i val nth_lemma: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires forall (i:nat{i < n}). nth a i = nth b i) (ensures a = b) (* Lemmas for constants *) val zero_nth_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures nth (zero n) i = false) [SMTPat (nth (zero n) i)] val one_nth_lemma: #n:pos{1 < n} -> i:nat{i < n} -> Lemma (requires True) (ensures (i = n - 1 ==> nth (one n) i = true) /\ (i < n - 1 ==> nth (one n) i = false)) [SMTPat (nth (one n) i)] val ones_nth_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (ones n) i) = true) [SMTPat (nth (ones n) i)] (* Bitwise operators *) let logand (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = from_vec #n (logand_vec #n (to_vec #n a) (to_vec #n b)) let logxor (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = from_vec #n (logxor_vec #n (to_vec #n a) (to_vec #n b)) let logor (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = from_vec #n (logor_vec #n (to_vec #n a) (to_vec #n b)) let lognot (#n:pos) (a:int_t n) : Tot (int_t n)= from_vec #n (lognot_vec #n (to_vec #n a)) (* Bitwise operators definitions *) val logand_definition: #n:pos -> a:int_t n -> b:int_t n -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (logand a b) i = (nth a i && nth b i))) [SMTPat (nth (logand a b) i)] val logxor_definition: #n:pos -> a:int_t n -> b:int_t n -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (logxor a b) i = (nth a i <> nth b i))) [SMTPat (nth (logxor a b) i)] val logor_definition: #n:pos -> a:int_t n -> b:int_t n -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (logor a b) i = (nth a i || nth b i))) [SMTPat (nth (logor a b) i)] val lognot_definition: #n:pos -> a:int_t n -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (lognot a) i = not(nth a i))) [SMTPat (nth (lognot a) i)] (* Two's complement unary minus *) inline_for_extraction let minus (#n:pos{1 < n}) (a:int_t n) : Tot (int_t n) = add_mod (lognot a) 1 (* Bitwise operators lemmas *) (* TODO: lemmas about the relations between different operators *) (* Bitwise AND operator *) val logand_commutative: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires True) (ensures (logand #n a b = logand #n b a)) val logand_associative: #n:pos -> a:int_t n -> b:int_t n -> c:int_t n -> Lemma (logand #n (logand #n a b) c = logand #n a (logand #n b c)) val logand_self: #n:pos -> a:int_t n -> Lemma (logand #n a a = a) val logand_lemma_1: #n:pos -> a:int_t n -> Lemma (requires True) (ensures (logand #n a (zero n) = zero n)) val logand_lemma_2: #n:pos -> a:int_t n -> Lemma (logand #n a (ones n) = a) val sign_bit_negative: #n:pos{1 < n} -> a:int_t n -> Lemma (nth a 0 = true <==> a < 0) val sign_bit_positive: #n:pos{1 < n} -> a:int_t n -> Lemma (nth a 0 = false <==> 0 <= a) val logand_pos_le: #n:pos{1 < n} -> a:int_t n{0 <= a} -> b:int_t n{0 <= b} -> Lemma (0 <= logand a b /\ logand a b <= a /\ logand a b <= b) val logand_pow2_minus_one: #n:pos{1 < n} -> a:int_t n -> m:pos{m < n} -> Lemma (0 <= logand a (pow2_minus_one m) /\ logand a (pow2_minus_one m) <= pow2_minus_one #n m) val logand_max: #n:pos{1 < n} -> a:int_t n{0 <= a} -> Lemma (0 <= logand a (max_int n) /\ a = logand a (max_int n)) (* Bitwise XOR operator *) val logxor_commutative: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires True) (ensures (logxor #n a b = logxor #n b a)) val logxor_associative: #n:pos -> a:int_t n -> b:int_t n -> c:int_t n -> Lemma (requires True) (ensures (logxor #n (logxor #n a b) c = logxor #n a (logxor #n b c))) val logxor_self: #n:pos -> a:int_t n -> Lemma (requires True) (ensures (logxor #n a a = zero n)) val logxor_lemma_1: #n:pos -> a:int_t n -> Lemma (requires True) (ensures (logxor #n a (zero n) = a)) val logxor_lemma_2: #n:pos -> a:int_t n -> Lemma (requires True) (ensures (logxor #n a (ones n) = lognot #n a)) val logxor_inv: #n:pos -> a:int_t n -> b:int_t n -> Lemma (a = logxor #n (logxor #n a b) b) val logxor_neq_nonzero: #n:pos -> a:int_t n -> b:int_t n -> Lemma (a <> b ==> logxor a b <> 0) val lognot_negative: #n:pos -> a:int_t n -> Lemma (requires a < 0) (ensures lognot a == UInt.lognot #n (a + pow2 n)) (* Shift operators *) (** If a is negative the result is undefined behaviour *) let shift_left (#n:pos) (a:int_t n{0 <= a}) (s:nat) : Tot (int_t n) = from_vec (shift_left_vec #n (to_vec #n a) s)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.Int.int_t n {0 <= a} -> s: Prims.nat -> FStar.Int.int_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.Int.int_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.nat", "FStar.Int.from_vec", "FStar.BitVector.shift_right_vec", "FStar.Int.to_vec" ]
[]
false
false
false
false
false
let shift_right (#n: pos) (a: int_t n {0 <= a}) (s: nat) : Tot (int_t n) =
from_vec (shift_right_vec #n (to_vec #n a) s)
false
FStar.Int.fsti
FStar.Int.from_vec
val from_vec (#n: pos) (vec: bv_t n) : Tot (int_t n)
val from_vec (#n: pos) (vec: bv_t n) : Tot (int_t n)
let from_vec (#n:pos) (vec:bv_t n) : Tot (int_t n) = let x = UInt.from_vec vec in if max_int n < x then x - pow2 n else x
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 41, "end_line": 210, "start_col": 0, "start_line": 208 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1)) (* Addition primitives *) let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) #push-options "--initial_fuel 1 --max_fuel 1" let add_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a + b) @% (pow2 n) (* Subtraction primitives *) let sub (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a - b) @% (pow2 n) (* Multiplication primitives *) let mul (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a * b) @% (pow2 n) #pop-options (* Division primitives *) let div (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Pure (int_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:pos -> a:int_t n -> b:int_t n{b <> 0} -> Pure (int_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:int_t n{min_int n < a} -> b:int_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:int_t n{min_int n < a}) (b:int_t n{b <> 0}) : Tot (c:int_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b (* Modulo primitives *) let mod (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Tot (int_t n) = a - ((a/b) * b) (* Comparison operators *) let eq #n (a:int_t n) (b:int_t n) : Tot bool = a = b let gt #n (a:int_t n) (b:int_t n) : Tot bool = a > b let gte #n (a:int_t n) (b:int_t n) : Tot bool = a >= b let lt #n (a:int_t n) (b:int_t n) : Tot bool = a < b let lte #n (a:int_t n) (b:int_t n) : Tot bool = a <= b #push-options "--initial_fuel 1 --max_fuel 1" /// Casts let to_uint (#n:pos) (x:int_t n) : Tot (UInt.uint_t n) = if 0 <= x then x else x + pow2 n let from_uint (#n:pos) (x:UInt.uint_t n) : Tot (int_t n) = if x <= max_int n then x else x - pow2 n val to_uint_injective: #n:pos -> x:int_t n -> Lemma (ensures from_uint (to_uint x) == x) [SMTPat (to_uint x)] let to_int_t (m:pos) (a:int) : Tot (int_t m) = a @% pow2 m open FStar.Seq (* WARNING: Mind the big endian vs little endian definition *) let to_vec (#n:pos) (num:int_t n) : Tot (bv_t n) = UInt.to_vec (to_uint num)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
vec: FStar.BitVector.bv_t n -> FStar.Int.int_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.BitVector.bv_t", "Prims.op_LessThan", "FStar.Int.max_int", "Prims.op_Subtraction", "Prims.pow2", "Prims.bool", "FStar.Int.int_t", "FStar.UInt.uint_t", "FStar.UInt.from_vec" ]
[]
false
false
false
false
false
let from_vec (#n: pos) (vec: bv_t n) : Tot (int_t n) =
let x = UInt.from_vec vec in if max_int n < x then x - pow2 n else x
false
FStar.Int.fsti
FStar.Int.from_uint
val from_uint (#n: pos) (x: UInt.uint_t n) : Tot (int_t n)
val from_uint (#n: pos) (x: UInt.uint_t n) : Tot (int_t n)
let from_uint (#n:pos) (x:UInt.uint_t n) : Tot (int_t n) = if x <= max_int n then x else x - pow2 n
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 42, "end_line": 194, "start_col": 0, "start_line": 193 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1)) (* Addition primitives *) let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) #push-options "--initial_fuel 1 --max_fuel 1" let add_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a + b) @% (pow2 n) (* Subtraction primitives *) let sub (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a - b) @% (pow2 n) (* Multiplication primitives *) let mul (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a * b) @% (pow2 n) #pop-options (* Division primitives *) let div (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Pure (int_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:pos -> a:int_t n -> b:int_t n{b <> 0} -> Pure (int_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:int_t n{min_int n < a} -> b:int_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:int_t n{min_int n < a}) (b:int_t n{b <> 0}) : Tot (c:int_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b (* Modulo primitives *) let mod (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Tot (int_t n) = a - ((a/b) * b) (* Comparison operators *) let eq #n (a:int_t n) (b:int_t n) : Tot bool = a = b let gt #n (a:int_t n) (b:int_t n) : Tot bool = a > b let gte #n (a:int_t n) (b:int_t n) : Tot bool = a >= b let lt #n (a:int_t n) (b:int_t n) : Tot bool = a < b let lte #n (a:int_t n) (b:int_t n) : Tot bool = a <= b #push-options "--initial_fuel 1 --max_fuel 1" /// Casts let to_uint (#n:pos) (x:int_t n) : Tot (UInt.uint_t n) = if 0 <= x then x else x + pow2 n
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.UInt.uint_t n -> FStar.Int.int_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.UInt.uint_t", "Prims.op_LessThanOrEqual", "FStar.Int.max_int", "Prims.bool", "Prims.op_Subtraction", "Prims.pow2", "FStar.Int.int_t" ]
[]
false
false
false
false
false
let from_uint (#n: pos) (x: UInt.uint_t n) : Tot (int_t n) =
if x <= max_int n then x else x - pow2 n
false
FStar.Int.fsti
FStar.Int.eq
val eq (#n: _) (a b: int_t n) : Tot bool
val eq (#n: _) (a b: int_t n) : Tot bool
let eq #n (a:int_t n) (b:int_t n) : Tot bool = a = b
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 52, "end_line": 180, "start_col": 0, "start_line": 180 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1)) (* Addition primitives *) let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) #push-options "--initial_fuel 1 --max_fuel 1" let add_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a + b) @% (pow2 n) (* Subtraction primitives *) let sub (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a - b) @% (pow2 n) (* Multiplication primitives *) let mul (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a * b) @% (pow2 n) #pop-options (* Division primitives *) let div (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Pure (int_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:pos -> a:int_t n -> b:int_t n{b <> 0} -> Pure (int_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:int_t n{min_int n < a} -> b:int_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:int_t n{min_int n < a}) (b:int_t n{b <> 0}) : Tot (c:int_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b (* Modulo primitives *) let mod (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Tot (int_t n) = a - ((a/b) * b)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.Int.int_t n -> b: FStar.Int.int_t n -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.Int.int_t", "Prims.op_Equality", "Prims.bool" ]
[]
false
false
false
false
false
let eq #n (a: int_t n) (b: int_t n) : Tot bool =
a = b
false
FStar.Int.fsti
FStar.Int.to_uint
val to_uint (#n: pos) (x: int_t n) : Tot (UInt.uint_t n)
val to_uint (#n: pos) (x: int_t n) : Tot (UInt.uint_t n)
let to_uint (#n:pos) (x:int_t n) : Tot (UInt.uint_t n) = if 0 <= x then x else x + pow2 n
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 191, "start_col": 0, "start_line": 190 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1)) (* Addition primitives *) let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) #push-options "--initial_fuel 1 --max_fuel 1" let add_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a + b) @% (pow2 n) (* Subtraction primitives *) let sub (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a - b) @% (pow2 n) (* Multiplication primitives *) let mul (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a * b) @% (pow2 n) #pop-options (* Division primitives *) let div (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Pure (int_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:pos -> a:int_t n -> b:int_t n{b <> 0} -> Pure (int_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:int_t n{min_int n < a} -> b:int_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:int_t n{min_int n < a}) (b:int_t n{b <> 0}) : Tot (c:int_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b (* Modulo primitives *) let mod (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Tot (int_t n) = a - ((a/b) * b) (* Comparison operators *) let eq #n (a:int_t n) (b:int_t n) : Tot bool = a = b let gt #n (a:int_t n) (b:int_t n) : Tot bool = a > b let gte #n (a:int_t n) (b:int_t n) : Tot bool = a >= b let lt #n (a:int_t n) (b:int_t n) : Tot bool = a < b let lte #n (a:int_t n) (b:int_t n) : Tot bool = a <= b #push-options "--initial_fuel 1 --max_fuel 1" /// Casts
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.Int.int_t n -> FStar.UInt.uint_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.Int.int_t", "Prims.op_LessThanOrEqual", "Prims.bool", "Prims.op_Addition", "Prims.pow2", "FStar.UInt.uint_t" ]
[]
false
false
false
false
false
let to_uint (#n: pos) (x: int_t n) : Tot (UInt.uint_t n) =
if 0 <= x then x else x + pow2 n
false
FStar.Int.fsti
FStar.Int.nth
val nth (#n: pos) (a: int_t n) (i: nat{i < n}) : Tot bool
val nth (#n: pos) (a: int_t n) (i: nat{i < n}) : Tot bool
let nth (#n:pos) (a:int_t n) (i:nat{i < n}) : Tot bool = index (to_vec #n a) i
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 78, "end_line": 270, "start_col": 0, "start_line": 270 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1)) (* Addition primitives *) let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) #push-options "--initial_fuel 1 --max_fuel 1" let add_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a + b) @% (pow2 n) (* Subtraction primitives *) let sub (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a - b) @% (pow2 n) (* Multiplication primitives *) let mul (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a * b) @% (pow2 n) #pop-options (* Division primitives *) let div (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Pure (int_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:pos -> a:int_t n -> b:int_t n{b <> 0} -> Pure (int_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:int_t n{min_int n < a} -> b:int_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:int_t n{min_int n < a}) (b:int_t n{b <> 0}) : Tot (c:int_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b (* Modulo primitives *) let mod (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Tot (int_t n) = a - ((a/b) * b) (* Comparison operators *) let eq #n (a:int_t n) (b:int_t n) : Tot bool = a = b let gt #n (a:int_t n) (b:int_t n) : Tot bool = a > b let gte #n (a:int_t n) (b:int_t n) : Tot bool = a >= b let lt #n (a:int_t n) (b:int_t n) : Tot bool = a < b let lte #n (a:int_t n) (b:int_t n) : Tot bool = a <= b #push-options "--initial_fuel 1 --max_fuel 1" /// Casts let to_uint (#n:pos) (x:int_t n) : Tot (UInt.uint_t n) = if 0 <= x then x else x + pow2 n let from_uint (#n:pos) (x:UInt.uint_t n) : Tot (int_t n) = if x <= max_int n then x else x - pow2 n val to_uint_injective: #n:pos -> x:int_t n -> Lemma (ensures from_uint (to_uint x) == x) [SMTPat (to_uint x)] let to_int_t (m:pos) (a:int) : Tot (int_t m) = a @% pow2 m open FStar.Seq (* WARNING: Mind the big endian vs little endian definition *) let to_vec (#n:pos) (num:int_t n) : Tot (bv_t n) = UInt.to_vec (to_uint num) let from_vec (#n:pos) (vec:bv_t n) : Tot (int_t n) = let x = UInt.from_vec vec in if max_int n < x then x - pow2 n else x val to_vec_lemma_1: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires a = b) (ensures equal (to_vec a) (to_vec b)) val to_vec_lemma_2: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires equal (to_vec a) (to_vec b)) (ensures a = b) val inverse_aux: #n:nat -> vec:bv_t n -> i:nat{i < n} -> Lemma (requires True) (ensures index vec i = index (to_vec (from_vec vec)) i) [SMTPat (index (to_vec (from_vec vec)) i)] val inverse_vec_lemma: #n:pos -> vec:bv_t n -> Lemma (requires True) (ensures equal vec (to_vec (from_vec vec))) [SMTPat (to_vec (from_vec vec))] val inverse_num_lemma: #n:pos -> num:int_t n -> Lemma (requires True) (ensures num = from_vec (to_vec num)) [SMTPat (from_vec (to_vec num))] val from_vec_lemma_1: #n:pos -> a:bv_t n -> b:bv_t n -> Lemma (requires equal a b) (ensures from_vec a = from_vec b) val from_vec_lemma_2: #n:pos -> a:bv_t n -> b:bv_t n -> Lemma (requires from_vec a = from_vec b) (ensures equal a b) (* Relations between constants in BitVector and in UInt. *) val zero_to_vec_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (zero n)) i = index (zero_vec #n) i) [SMTPat (index (to_vec (zero n)) i)] val zero_from_vec_lemma: #n:pos -> Lemma (requires True) (ensures from_vec (zero_vec #n) = zero n) [SMTPat (from_vec (zero_vec #n))] val one_to_vec_lemma: #n:pos{1 < n} -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (one n)) i = index (elem_vec #n (n - 1)) i) [SMTPat (index (to_vec (one n)) i)] val pow2_to_vec_lemma: #n:pos -> p:nat{p < n-1} -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (pow2_n #n p)) i = index (elem_vec #n (n - p - 1)) i) [SMTPat (index (to_vec (pow2_n #n p)) i)] val pow2_from_vec_lemma: #n:pos -> p:pos{p < n-1} -> Lemma (requires True) (ensures from_vec (elem_vec #n p) = pow2_n #n (n - p - 1)) [SMTPat (from_vec (elem_vec #n p))] val ones_to_vec_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (ones n)) i = index (ones_vec #n) i) [SMTPat (index (to_vec (ones n)) i)] val ones_from_vec_lemma: #n:pos -> Lemma (requires True) (ensures from_vec (ones_vec #n) = ones n) [SMTPat (from_vec (ones_vec #n))]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.Int.int_t n -> i: Prims.nat{i < n} -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.Int.int_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.Seq.Base.index", "Prims.bool", "FStar.Int.to_vec" ]
[]
false
false
false
false
false
let nth (#n: pos) (a: int_t n) (i: nat{i < n}) : Tot bool =
index (to_vec #n a) i
false
FStar.Int.fsti
FStar.Int.to_int_t
val to_int_t (m: pos) (a: int) : Tot (int_t m)
val to_int_t (m: pos) (a: int) : Tot (int_t m)
let to_int_t (m:pos) (a:int) : Tot (int_t m) = a @% pow2 m
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 58, "end_line": 199, "start_col": 0, "start_line": 199 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1)) (* Addition primitives *) let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) #push-options "--initial_fuel 1 --max_fuel 1" let add_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a + b) @% (pow2 n) (* Subtraction primitives *) let sub (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a - b) @% (pow2 n) (* Multiplication primitives *) let mul (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a * b) @% (pow2 n) #pop-options (* Division primitives *) let div (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Pure (int_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:pos -> a:int_t n -> b:int_t n{b <> 0} -> Pure (int_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:int_t n{min_int n < a} -> b:int_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:int_t n{min_int n < a}) (b:int_t n{b <> 0}) : Tot (c:int_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b (* Modulo primitives *) let mod (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Tot (int_t n) = a - ((a/b) * b) (* Comparison operators *) let eq #n (a:int_t n) (b:int_t n) : Tot bool = a = b let gt #n (a:int_t n) (b:int_t n) : Tot bool = a > b let gte #n (a:int_t n) (b:int_t n) : Tot bool = a >= b let lt #n (a:int_t n) (b:int_t n) : Tot bool = a < b let lte #n (a:int_t n) (b:int_t n) : Tot bool = a <= b #push-options "--initial_fuel 1 --max_fuel 1" /// Casts let to_uint (#n:pos) (x:int_t n) : Tot (UInt.uint_t n) = if 0 <= x then x else x + pow2 n let from_uint (#n:pos) (x:UInt.uint_t n) : Tot (int_t n) = if x <= max_int n then x else x - pow2 n val to_uint_injective: #n:pos -> x:int_t n -> Lemma (ensures from_uint (to_uint x) == x) [SMTPat (to_uint x)]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: Prims.pos -> a: Prims.int -> FStar.Int.int_t m
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "Prims.int", "FStar.Int.op_At_Percent", "Prims.pow2", "FStar.Int.int_t" ]
[]
false
false
false
false
false
let to_int_t (m: pos) (a: int) : Tot (int_t m) =
a @% pow2 m
false
FStar.Int.fsti
FStar.Int.minus
val minus (#n: pos{1 < n}) (a: int_t n) : Tot (int_t n)
val minus (#n: pos{1 < n}) (a: int_t n) : Tot (int_t n)
let minus (#n:pos{1 < n}) (a:int_t n) : Tot (int_t n) = add_mod (lognot a) 1
{ "file_name": "ulib/FStar.Int.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 22, "end_line": 328, "start_col": 0, "start_line": 327 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Int (* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | _ -> True) [SMTPat (pow2 x)] /// Specs let max_int (n:pos) : Tot int = pow2 (n-1) - 1 let min_int (n:pos) : Tot int = - (pow2 (n-1)) let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type int_t (n:pos) = x:int{size x n} /// Multiplicative operator semantics, see C11 6.5.5 (* Truncation towards zero division *) let op_Slash (a:int) (b:int{b <> 0}) : Tot int = if (a >= 0 && b < 0) || (a < 0 && b >= 0) then - (abs a / abs b) else abs a / abs b (* Wrap-around modulo: wraps into [-p/2; p/2[ *) let op_At_Percent (v:int) (p:int{p>0/\ p%2=0}) : Tot int = let m = v % p in if m >= p/2 then m - p else m /// Constants let zero (n:pos) : Tot (int_t n) = 0 #push-options "--initial_fuel 1 --max_fuel 1" let pow2_n (#n:pos) (p:nat{p < n-1}) : Tot (int_t n) = pow2_le_compat (n - 2) p; pow2 p let pow2_minus_one (#n:pos{1 < n}) (m:nat{m < n}) : Tot (int_t n) = pow2_le_compat (n - 1) m; pow2 m - 1 let one (n:pos{1 < n}) : Tot (int_t n) = 1 #pop-options let ones (n:pos) : Tot (int_t n) = -1 (* Increment and decrement *) let incr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:pos) (a:int_t n) : Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a + 1) % (pow2 (n-1)) let decr_mod (#n:pos) (a:int_t n) : Tot (int_t n) = (a - 1) % (pow2 (n-1)) (* Addition primitives *) let add (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) #push-options "--initial_fuel 1 --max_fuel 1" let add_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a + b) @% (pow2 n) (* Subtraction primitives *) let sub (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a - b) @% (pow2 n) (* Multiplication primitives *) let mul (#n:pos) (a:int_t n) (b:int_t n) : Pure (int_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = (a * b) @% (pow2 n) #pop-options (* Division primitives *) let div (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Pure (int_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:pos -> a:int_t n -> b:int_t n{b <> 0} -> Pure (int_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:int_t n{min_int n < a} -> b:int_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:int_t n{min_int n < a}) (b:int_t n{b <> 0}) : Tot (c:int_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b (* Modulo primitives *) let mod (#n:pos) (a:int_t n) (b:int_t n{b <> 0}) : Tot (int_t n) = a - ((a/b) * b) (* Comparison operators *) let eq #n (a:int_t n) (b:int_t n) : Tot bool = a = b let gt #n (a:int_t n) (b:int_t n) : Tot bool = a > b let gte #n (a:int_t n) (b:int_t n) : Tot bool = a >= b let lt #n (a:int_t n) (b:int_t n) : Tot bool = a < b let lte #n (a:int_t n) (b:int_t n) : Tot bool = a <= b #push-options "--initial_fuel 1 --max_fuel 1" /// Casts let to_uint (#n:pos) (x:int_t n) : Tot (UInt.uint_t n) = if 0 <= x then x else x + pow2 n let from_uint (#n:pos) (x:UInt.uint_t n) : Tot (int_t n) = if x <= max_int n then x else x - pow2 n val to_uint_injective: #n:pos -> x:int_t n -> Lemma (ensures from_uint (to_uint x) == x) [SMTPat (to_uint x)] let to_int_t (m:pos) (a:int) : Tot (int_t m) = a @% pow2 m open FStar.Seq (* WARNING: Mind the big endian vs little endian definition *) let to_vec (#n:pos) (num:int_t n) : Tot (bv_t n) = UInt.to_vec (to_uint num) let from_vec (#n:pos) (vec:bv_t n) : Tot (int_t n) = let x = UInt.from_vec vec in if max_int n < x then x - pow2 n else x val to_vec_lemma_1: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires a = b) (ensures equal (to_vec a) (to_vec b)) val to_vec_lemma_2: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires equal (to_vec a) (to_vec b)) (ensures a = b) val inverse_aux: #n:nat -> vec:bv_t n -> i:nat{i < n} -> Lemma (requires True) (ensures index vec i = index (to_vec (from_vec vec)) i) [SMTPat (index (to_vec (from_vec vec)) i)] val inverse_vec_lemma: #n:pos -> vec:bv_t n -> Lemma (requires True) (ensures equal vec (to_vec (from_vec vec))) [SMTPat (to_vec (from_vec vec))] val inverse_num_lemma: #n:pos -> num:int_t n -> Lemma (requires True) (ensures num = from_vec (to_vec num)) [SMTPat (from_vec (to_vec num))] val from_vec_lemma_1: #n:pos -> a:bv_t n -> b:bv_t n -> Lemma (requires equal a b) (ensures from_vec a = from_vec b) val from_vec_lemma_2: #n:pos -> a:bv_t n -> b:bv_t n -> Lemma (requires from_vec a = from_vec b) (ensures equal a b) (* Relations between constants in BitVector and in UInt. *) val zero_to_vec_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (zero n)) i = index (zero_vec #n) i) [SMTPat (index (to_vec (zero n)) i)] val zero_from_vec_lemma: #n:pos -> Lemma (requires True) (ensures from_vec (zero_vec #n) = zero n) [SMTPat (from_vec (zero_vec #n))] val one_to_vec_lemma: #n:pos{1 < n} -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (one n)) i = index (elem_vec #n (n - 1)) i) [SMTPat (index (to_vec (one n)) i)] val pow2_to_vec_lemma: #n:pos -> p:nat{p < n-1} -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (pow2_n #n p)) i = index (elem_vec #n (n - p - 1)) i) [SMTPat (index (to_vec (pow2_n #n p)) i)] val pow2_from_vec_lemma: #n:pos -> p:pos{p < n-1} -> Lemma (requires True) (ensures from_vec (elem_vec #n p) = pow2_n #n (n - p - 1)) [SMTPat (from_vec (elem_vec #n p))] val ones_to_vec_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (ones n)) i = index (ones_vec #n) i) [SMTPat (index (to_vec (ones n)) i)] val ones_from_vec_lemma: #n:pos -> Lemma (requires True) (ensures from_vec (ones_vec #n) = ones n) [SMTPat (from_vec (ones_vec #n))] (* (nth a i) returns a boolean indicating the i-th bit of a. *) let nth (#n:pos) (a:int_t n) (i:nat{i < n}) : Tot bool = index (to_vec #n a) i val nth_lemma: #n:pos -> a:int_t n -> b:int_t n -> Lemma (requires forall (i:nat{i < n}). nth a i = nth b i) (ensures a = b) (* Lemmas for constants *) val zero_nth_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures nth (zero n) i = false) [SMTPat (nth (zero n) i)] val one_nth_lemma: #n:pos{1 < n} -> i:nat{i < n} -> Lemma (requires True) (ensures (i = n - 1 ==> nth (one n) i = true) /\ (i < n - 1 ==> nth (one n) i = false)) [SMTPat (nth (one n) i)] val ones_nth_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (ones n) i) = true) [SMTPat (nth (ones n) i)] (* Bitwise operators *) let logand (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = from_vec #n (logand_vec #n (to_vec #n a) (to_vec #n b)) let logxor (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = from_vec #n (logxor_vec #n (to_vec #n a) (to_vec #n b)) let logor (#n:pos) (a:int_t n) (b:int_t n) : Tot (int_t n) = from_vec #n (logor_vec #n (to_vec #n a) (to_vec #n b)) let lognot (#n:pos) (a:int_t n) : Tot (int_t n)= from_vec #n (lognot_vec #n (to_vec #n a)) (* Bitwise operators definitions *) val logand_definition: #n:pos -> a:int_t n -> b:int_t n -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (logand a b) i = (nth a i && nth b i))) [SMTPat (nth (logand a b) i)] val logxor_definition: #n:pos -> a:int_t n -> b:int_t n -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (logxor a b) i = (nth a i <> nth b i))) [SMTPat (nth (logxor a b) i)] val logor_definition: #n:pos -> a:int_t n -> b:int_t n -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (logor a b) i = (nth a i || nth b i))) [SMTPat (nth (logor a b) i)] val lognot_definition: #n:pos -> a:int_t n -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (lognot a) i = not(nth a i))) [SMTPat (nth (lognot a) i)] (* Two's complement unary minus *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.Int.fsti" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.Int.int_t n -> FStar.Int.int_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "Prims.b2t", "Prims.op_LessThan", "FStar.Int.int_t", "FStar.Int.add_mod", "FStar.Int.lognot" ]
[]
false
false
false
false
false
let minus (#n: pos{1 < n}) (a: int_t n) : Tot (int_t n) =
add_mod (lognot a) 1
false
Spec.Blake2.fst
Spec.Blake2.blake2_init_hash
val blake2_init_hash: a:alg -> p:blake2_params a -> kk:size_nat{kk <= max_key a} -> nn:size_nat{1 <= nn /\ nn <= max_output a} -> Tot (state a)
val blake2_init_hash: a:alg -> p:blake2_params a -> kk:size_nat{kk <= max_key a} -> nn:size_nat{1 <= nn /\ nn <= max_output a} -> Tot (state a)
let blake2_init_hash a p kk nn = let iv0 = secret (ivTable a).[0] in let iv1 = secret (ivTable a).[1] in let iv2 = secret (ivTable a).[2] in let iv3 = secret (ivTable a).[3] in let iv4 = secret (ivTable a).[4] in let iv5 = secret (ivTable a).[5] in let iv6 = secret (ivTable a).[6] in let iv7 = secret (ivTable a).[7] in let r0 = create_row #a iv0 iv1 iv2 iv3 in let r1 = create_row #a iv4 iv5 iv6 iv7 in let p: blake2_params a = set_key_length (set_digest_length p nn) kk in let s = serialize_blake2_params p in let iv0' = iv0 ^. s.[0] in let iv1' = iv1 ^. s.[1] in let iv2' = iv2 ^. s.[2] in let iv3' = iv3 ^. s.[3] in let iv4' = iv4 ^. s.[4] in let iv5' = iv5 ^. s.[5] in let iv6' = iv6 ^. s.[6] in let iv7' = iv7 ^. s.[7] in let r0' = create_row #a iv0' iv1' iv2' iv3' in let r1' = create_row #a iv4' iv5' iv6' iv7' in let s_iv = createL [r0';r1';r0;r1] in s_iv
{ "file_name": "specs/Spec.Blake2.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 6, "end_line": 401, "start_col": 0, "start_line": 375 }
module Spec.Blake2 open FStar.Mul open Lib.IntTypes open Lib.RawIntTypes open Lib.Sequence open Lib.ByteSequence open Lib.LoopCombinators module UpdateMulti = Lib.UpdateMulti include Spec.Blake2.Definitions #set-options "--z3rlimit 50" /// Serialize blake2s parameters to be xor'ed with the state during initialization /// As the state is represented using uint32, we need to serialize to uint32 instead /// of the more standard bytes representation let serialize_blake2s_params (p: blake2s_params) : lseq uint32 8 = let s0 = (u32 (v p.digest_length)) ^. (u32 (v p.key_length) <<. (size 8)) ^. (u32 (v p.fanout) <<. (size 16)) ^. (u32 (v p.depth) <<. (size 24)) in let s1 = p.leaf_length in let s2 = p.node_offset in let s3 = (u32 (v p.xof_length)) ^. (u32 (v p.node_depth) <<. (size 16)) ^. (u32 (v p.inner_length) <<. (size 24)) in let salt_u32: lseq uint32 2 = uints_from_bytes_le p.salt in let s4 = salt_u32.[0] in let s5 = salt_u32.[1] in let personal_u32: lseq uint32 2 = uints_from_bytes_le p.personal in let s6 = personal_u32.[0] in let s7 = personal_u32.[1] in [@inline_let] let l = [s0; s1; s2; s3; s4; s5; s6; s7] in assert_norm (List.Tot.length l == 8); createL l /// Serialize blake2b parameters to be xor'ed with the state during initialization /// As the state is represented using uint64, we need to serialize to uint64 instead /// of the more standard bytes representation let serialize_blake2b_params (p: blake2b_params) : lseq uint64 8 = let s0 = (u64 (v p.digest_length)) ^. (u64 (v p.key_length) <<. (size 8)) ^. (u64 (v p.fanout) <<. (size 16)) ^. (u64 (v p.depth) <<. (size 24)) ^. (u64 (v p.leaf_length) <<. (size 32)) in let s1 = (u64 (v p.node_offset)) ^. (u64 (v p.xof_length) <<. (size 32)) in // The serialization corresponding to s2 contains node_depth and inner_length, // followed by the 14 reserved bytes which always seem to be zeros, and can hence // be ignored when building the corresponding uint64 using xor's let s2 = (u64 (v p.node_depth)) ^. (u64 (v p.inner_length) <<. (size 8)) in // s3 corresponds to the remaining of the reserved bytes let s3 = u64 0 in let salt_u64: lseq uint64 2 = uints_from_bytes_le p.salt in let s4 = salt_u64.[0] in let s5 = salt_u64.[1] in let personal_u64: lseq uint64 2 = uints_from_bytes_le p.personal in let s6 = personal_u64.[0] in let s7 = personal_u64.[1] in [@inline_let] let l = [s0; s1; s2; s3; s4; s5; s6; s7] in assert_norm (List.Tot.length l == 8); createL l inline_for_extraction let serialize_blake2_params (#a: alg) (p: blake2_params a): lseq (word_t a) 8 = match a with | Blake2S -> serialize_blake2s_params p | Blake2B -> serialize_blake2b_params p [@"opaque_to_smt"] inline_for_extraction let rTable_list_S : List.Tot.llist (rotval U32) 4 = [ size 16; size 12; size 8; size 7 ] [@"opaque_to_smt"] inline_for_extraction let rTable_list_B: List.Tot.llist (rotval U64) 4 = [ size 32; size 24; size 16; size 63 ] inline_for_extraction let rTable (a:alg) : rtable_t a = match a with | Blake2S -> (of_list rTable_list_S) | Blake2B -> (of_list rTable_list_B) [@"opaque_to_smt"] inline_for_extraction let list_iv_S: List.Tot.llist (uint_t U32 PUB) 8 = [@inline_let] let l = [ 0x6A09E667ul; 0xBB67AE85ul; 0x3C6EF372ul; 0xA54FF53Aul; 0x510E527Ful; 0x9B05688Cul; 0x1F83D9ABul; 0x5BE0CD19ul] in assert_norm(List.Tot.length l == 8); l [@"opaque_to_smt"] inline_for_extraction let list_iv_B: List.Tot.llist (uint_t U64 PUB) 8 = [@inline_let] let l = [ 0x6A09E667F3BCC908uL; 0xBB67AE8584CAA73BuL; 0x3C6EF372FE94F82BuL; 0xA54FF53A5F1D36F1uL; 0x510E527FADE682D1uL; 0x9B05688C2B3E6C1FuL; 0x1F83D9ABFB41BD6BuL; 0x5BE0CD19137E2179uL] in assert_norm(List.Tot.length l == 8); l [@"opaque_to_smt"] inline_for_extraction let list_iv (a:alg): List.Tot.llist (pub_word_t a) 8 = match a with | Blake2S -> list_iv_S | Blake2B -> list_iv_B inline_for_extraction let ivTable (a:alg) : lseq (pub_word_t a) 8 = match a with | Blake2S -> of_list list_iv_S | Blake2B -> of_list list_iv_B [@"opaque_to_smt"] let list_sigma: list_sigma_t = [@inline_let] let l : list sigma_elt_t = [ size 0; size 1; size 2; size 3; size 4; size 5; size 6; size 7; size 8; size 9; size 10; size 11; size 12; size 13; size 14; size 15; size 14; size 10; size 4; size 8; size 9; size 15; size 13; size 6; size 1; size 12; size 0; size 2; size 11; size 7; size 5; size 3; size 11; size 8; size 12; size 0; size 5; size 2; size 15; size 13; size 10; size 14; size 3; size 6; size 7; size 1; size 9; size 4; size 7; size 9; size 3; size 1; size 13; size 12; size 11; size 14; size 2; size 6; size 5; size 10; size 4; size 0; size 15; size 8; size 9; size 0; size 5; size 7; size 2; size 4; size 10; size 15; size 14; size 1; size 11; size 12; size 6; size 8; size 3; size 13; size 2; size 12; size 6; size 10; size 0; size 11; size 8; size 3; size 4; size 13; size 7; size 5; size 15; size 14; size 1; size 9; size 12; size 5; size 1; size 15; size 14; size 13; size 4; size 10; size 0; size 7; size 6; size 3; size 9; size 2; size 8; size 11; size 13; size 11; size 7; size 14; size 12; size 1; size 3; size 9; size 5; size 0; size 15; size 4; size 8; size 6; size 2; size 10; size 6; size 15; size 14; size 9; size 11; size 3; size 0; size 8; size 12; size 2; size 13; size 7; size 1; size 4; size 10; size 5; size 10; size 2; size 8; size 4; size 7; size 6; size 1; size 5; size 15; size 11; size 9; size 14; size 3; size 12; size 13; size 0 ] in assert_norm(List.Tot.length l == 160); l inline_for_extraction let sigmaTable:lseq sigma_elt_t size_sigmaTable = assert_norm (List.Tot.length list_sigma == size_sigmaTable); of_list list_sigma (* Functions *) let g1 (a:alg) (wv:state a) (i:row_idx) (j:row_idx) (r:rotval (wt a)) : Tot (state a) = wv.[i] <- (wv.[i] ^| wv.[j]) >>>| r let g2 (a:alg) (wv:state a) (i:row_idx) (j:row_idx) (x:row a) : Tot (state a) = wv.[i] <- (wv.[i] +| wv.[j] +| x) let g2z (a:alg) (wv:state a) (i:row_idx) (j:row_idx) : Tot (state a) = wv.[i] <- (wv.[i] +| wv.[j]) val blake2_mixing: a:alg -> ws:state a -> row a -> row a -> Tot (state a) let blake2_mixing al wv x y = let a = 0 in let b = 1 in let c = 2 in let d = 3 in let rt = rTable al in let wv = g2 al wv a b x in let wv = g1 al wv d a rt.[0] in let wv = g2z al wv c d in let wv = g1 al wv b c rt.[1] in let wv = g2 al wv a b y in let wv = g1 al wv d a rt.[2] in let wv = g2z al wv c d in let wv = g1 al wv b c rt.[3] in wv let diag (#a:alg) (wv:state a) : state a = let wv = wv.[1] <- rotr wv.[1] 1 in let wv = wv.[2] <- rotr wv.[2] 2 in let wv = wv.[3] <- rotr wv.[3] 3 in wv let undiag (#a:alg) (wv:state a) : state a = let wv = wv.[1] <- rotr wv.[1] 3 in let wv = wv.[2] <- rotr wv.[2] 2 in let wv = wv.[3] <- rotr wv.[3] 1 in wv inline_for_extraction let gather_row (#a:alg) (m:block_w a) (i0 i1 i2 i3:sigma_elt_t) : row a = create_row m.[v i0] m.[v i1] m.[v i2] m.[v i3] val gather_state: a:alg -> m:block_w a -> start:nat{start <= 144} -> state a let gather_state a m start = let x = gather_row m sigmaTable.[start] sigmaTable.[start+2] sigmaTable.[start+4] sigmaTable.[start+6] in let y = gather_row m sigmaTable.[start+1] sigmaTable.[start+3] sigmaTable.[start+5] sigmaTable.[start+7] in let z = gather_row m sigmaTable.[start+8] sigmaTable.[start+10] sigmaTable.[start+12] sigmaTable.[start+14] in let w = gather_row m sigmaTable.[start+9] sigmaTable.[start+11] sigmaTable.[start+13] sigmaTable.[start+15] in let l = [x;y;z;w] in assert_norm (List.Tot.length l == 4); createL l val blake2_round: a:alg -> m:block_w a -> i:size_nat -> wv:state a -> state a let blake2_round a m i wv = let start = (i%10) * 16 in let m_s = gather_state a m start in let wv = blake2_mixing a wv m_s.[0] m_s.[1] in let wv = diag wv in let wv = blake2_mixing a wv m_s.[2] m_s.[3] in undiag wv val blake2_compress0: a:alg -> m:block_s a -> block_w a let blake2_compress0 a m = uints_from_bytes_le m val blake2_compress1: a:alg -> s_iv:state a -> offset:limb_t a -> flag:bool -> Tot (state a) let blake2_compress1 a s_iv offset flag = let wv : state a = s_iv in let low_offset = limb_to_word a offset in let high_offset = limb_to_word a (shift_right #(limb_inttype a) offset (size (bits (wt a)))) in let m_12 = low_offset in let m_13 = high_offset in let m_14 = if flag then (ones (wt a) SEC) else zero a in let m_15 = zero a in let mask = create_row m_12 m_13 m_14 m_15 in let wv = wv.[3] <- wv.[3] ^| mask in wv val blake2_compress2: a:alg -> wv:state a -> m:block_w a -> Tot (state a) let blake2_compress2 a wv m = repeati (rounds a) (blake2_round a m) wv val blake2_compress3: a:alg -> wv:state a -> s_iv:state a -> Tot (state a) let blake2_compress3 a wv s = let s = s.[0] <- (s.[0] ^| wv.[0]) ^| wv.[2] in let s = s.[1] <- (s.[1] ^| wv.[1]) ^| wv.[3] in s val blake2_compress: a:alg -> s_iv:state a -> m:block_s a -> offset:limb_t a -> flag:bool -> Tot (state a) let blake2_compress a s_iv m offset flag = let m_w = blake2_compress0 a m in let wv = blake2_compress1 a s_iv offset flag in let wv = blake2_compress2 a wv m_w in let s_iv = blake2_compress3 a wv s_iv in s_iv val blake2_update_block: a:alg -> flag:bool -> totlen:nat{totlen <= max_limb a} -> d:block_s a -> s_iv:state a -> Tot (state a) let blake2_update_block a flag totlen d s = let offset = nat_to_limb a totlen in blake2_compress a s d offset flag val blake2_update1: a:alg -> prev:nat -> m:bytes -> i:nat{i < length m / size_block a /\ prev + length m <= max_limb a} -> s:state a -> Tot (state a) let get_blocki (a:alg) (m:bytes) (i:nat{i < length m / size_block a}) : block_s a = Seq.slice m (i * size_block a) ((i+1) * size_block a) let blake2_update1 a prev m i s = let totlen = prev + (i+1) * size_block a in let d = get_blocki a m i in blake2_update_block a false totlen d s val blake2_update_last: a:alg -> prev:nat -> rem:nat -> m:bytes{prev + length m <= max_limb a /\ rem <= length m /\ rem <= size_block a} -> s:state a -> Tot (state a) let get_last_padded_block (a:alg) (m:bytes) (rem:nat{rem <= length m /\ rem <= size_block a}) : block_s a = let last = Seq.slice m (length m - rem) (length m) in let last_block = create (size_block a) (u8 0) in let last_block = update_sub last_block 0 rem last in last_block let blake2_update_last a prev rem m s = let inlen = length m in let totlen = prev + inlen in let last_block = get_last_padded_block a m rem in blake2_update_block a true totlen last_block s val blake2_update_blocks: a:alg -> prev:nat -> m:bytes{prev + length m <= max_limb a} -> s:state a -> Tot (state a) let split (a:alg) (len:nat) : nb_rem:(nat & nat){let (nb,rem) = nb_rem in nb * size_block a + rem == len} = UpdateMulti.split_at_last_lazy_nb_rem (size_block a) len let blake2_update_blocks a prev m s = let (nb,rem) = split a (length m) in let s = repeati nb (blake2_update1 a prev m) s in blake2_update_last a prev rem m s val blake2_init_hash: a:alg -> p:blake2_params a -> kk:size_nat{kk <= max_key a} -> nn:size_nat{1 <= nn /\ nn <= max_output a} -> Tot (state a)
{ "checked_file": "/", "dependencies": [ "Spec.Blake2.Definitions.fst.checked", "prims.fst.checked", "Lib.UpdateMulti.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Spec.Blake2.fst" }
[ { "abbrev": false, "full_module": "Spec.Blake2.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Lib.UpdateMulti", "short_module": "UpdateMulti" }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.RawIntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec", "short_module": null }, { "abbrev": false, "full_module": "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": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Blake2.Definitions.alg -> p: Spec.Blake2.Definitions.blake2_params a -> kk: Lib.IntTypes.size_nat{kk <= Spec.Blake2.Definitions.max_key a} -> nn: Lib.IntTypes.size_nat{1 <= nn /\ nn <= Spec.Blake2.Definitions.max_output a} -> Spec.Blake2.Definitions.state a
Prims.Tot
[ "total" ]
[]
[ "Spec.Blake2.Definitions.alg", "Spec.Blake2.Definitions.blake2_params", "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Spec.Blake2.Definitions.max_key", "Prims.l_and", "Spec.Blake2.Definitions.max_output", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Spec.Blake2.Definitions.wt", "Lib.IntTypes.SEC", "FStar.List.Tot.Base.length", "Prims.Cons", "Prims.Nil", "Prims.eq2", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.seq_of_list", "Lib.Sequence.createL", "Spec.Blake2.Definitions.row", "Spec.Blake2.Definitions.create_row", "Lib.IntTypes.op_Hat_Dot", "Lib.Sequence.op_String_Access", "Spec.Blake2.Definitions.word_t", "Spec.Blake2.serialize_blake2_params", "Spec.Blake2.Definitions.set_key_length", "Spec.Blake2.Definitions.set_digest_length", "Prims.int", "Lib.IntTypes.range", "Lib.IntTypes.v", "Lib.IntTypes.PUB", "Lib.Sequence.index", "Spec.Blake2.Definitions.pub_word_t", "Spec.Blake2.ivTable", "Lib.IntTypes.secret", "Spec.Blake2.Definitions.state" ]
[]
false
false
false
false
false
let blake2_init_hash a p kk nn =
let iv0 = secret (ivTable a).[ 0 ] in let iv1 = secret (ivTable a).[ 1 ] in let iv2 = secret (ivTable a).[ 2 ] in let iv3 = secret (ivTable a).[ 3 ] in let iv4 = secret (ivTable a).[ 4 ] in let iv5 = secret (ivTable a).[ 5 ] in let iv6 = secret (ivTable a).[ 6 ] in let iv7 = secret (ivTable a).[ 7 ] in let r0 = create_row #a iv0 iv1 iv2 iv3 in let r1 = create_row #a iv4 iv5 iv6 iv7 in let p:blake2_params a = set_key_length (set_digest_length p nn) kk in let s = serialize_blake2_params p in let iv0' = iv0 ^. s.[ 0 ] in let iv1' = iv1 ^. s.[ 1 ] in let iv2' = iv2 ^. s.[ 2 ] in let iv3' = iv3 ^. s.[ 3 ] in let iv4' = iv4 ^. s.[ 4 ] in let iv5' = iv5 ^. s.[ 5 ] in let iv6' = iv6 ^. s.[ 6 ] in let iv7' = iv7 ^. s.[ 7 ] in let r0' = create_row #a iv0' iv1' iv2' iv3' in let r1' = create_row #a iv4' iv5' iv6' iv7' in let s_iv = createL [r0'; r1'; r0; r1] in s_iv
false
EverCrypt.Hash.fsti
EverCrypt.Hash.alg
val alg : Type0
let alg = fixed_len_alg
{ "file_name": "providers/evercrypt/EverCrypt.Hash.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 23, "end_line": 24, "start_col": 0, "start_line": 24 }
module EverCrypt.Hash open EverCrypt.Helpers open FStar.HyperStack.ST open FStar.Integers open Spec.Hash.Definitions open Hacl.Hash.Definitions #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" /// Algorithmic agility for hash specifications. We reuse the agile /// specifications from HACL*'s specs/ directory. /// SUPPORTED ALGORITHMS see e.g. https://en.wikipedia.org/wiki/SHA-1 /// for a global comparison and lengths /// /// * We support all variants of SHA2. /// * MD5 and SHA1 are still required by TLS 1.2, included for legacy /// purpose only /// * SHA3 will be provided by HACL* /// /// ``hash_alg``, from Spec.Hash.Definitions, lists all supported algorithms
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Incremental.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.Helpers.fsti.checked", "C.String.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.Hash.fsti" }
[ { "abbrev": false, "full_module": "Hacl.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Spec.Hash.Definitions.fixed_len_alg" ]
[]
false
false
false
true
true
let alg =
fixed_len_alg
false
EverCrypt.Hash.fsti
EverCrypt.Hash.freeable
val freeable : h: FStar.Monotonic.HyperStack.mem -> p: EverCrypt.Hash.state a -> Prims.logical
let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p)
{ "file_name": "providers/evercrypt/EverCrypt.Hash.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 42, "end_line": 84, "start_col": 0, "start_line": 83 }
module EverCrypt.Hash open EverCrypt.Helpers open FStar.HyperStack.ST open FStar.Integers open Spec.Hash.Definitions open Hacl.Hash.Definitions #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" /// Algorithmic agility for hash specifications. We reuse the agile /// specifications from HACL*'s specs/ directory. /// SUPPORTED ALGORITHMS see e.g. https://en.wikipedia.org/wiki/SHA-1 /// for a global comparison and lengths /// /// * We support all variants of SHA2. /// * MD5 and SHA1 are still required by TLS 1.2, included for legacy /// purpose only /// * SHA3 will be provided by HACL* /// /// ``hash_alg``, from Spec.Hash.Definitions, lists all supported algorithms unfold let alg = fixed_len_alg /// TODO: move this one to Hacl.Hash.Definitions val string_of_alg: alg -> C.String.t /// kept only for functional backward compatibility, never assumed to be secure type broken_alg = a:alg {a = MD5 \/ a = SHA1} /// HMAC/HKDF ALGORITHMS; we make security assumptions only for constructions /// based on those. type alg13 = a:alg { a=SHA2_256 \/ a=SHA2_384 \/ a=SHA2_512 } /// No pattern (would fire too often)! let uint32_fits_maxLength (a: alg) (x: UInt32.t): Lemma (requires True) (ensures UInt32.v x `less_than_max_input_length` a) = assert_norm (pow2 32 < pow2 61); assert_norm (pow2 61 < pow2 125) /// To specify their low-level incremental computations, we assume /// Merkle-Damgard/sponge-like algorithms: /// /// The hash state is kept in an accumulator, with /// - an initial value /// - an update function, adding a block of bytes; /// - an extract (also: "finish") function, returning a hash tag. /// /// Before hashing, some algorithm-specific padding and length encoding is /// appended to the input bytestring. /// /// This is not a general-purpose incremental specification, which would support /// adding text fragments of arbitrary lengths (for that, see /// EverCrypt.Hash.Incremental). /// Stateful interface implementing the agile specifications. module HS = FStar.HyperStack module B = LowStar.Buffer module M = LowStar.Modifies module G = FStar.Ghost open LowStar.BufferOps /// do not use as argument of ghost functions type e_alg = G.erased alg [@CAbstractStruct] val state_s: alg -> Type0 // pointer to abstract implementation state let state alg = B.pointer (state_s alg) // abstract freeable (deep) predicate; only needed for create/free pairs inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Incremental.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.Helpers.fsti.checked", "C.String.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.Hash.fsti" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": false, "full_module": "C.Failure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "EverCrypt.AutoConfig2", "short_module": "AC" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> p: EverCrypt.Hash.state a -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "EverCrypt.Hash.alg", "FStar.Monotonic.HyperStack.mem", "EverCrypt.Hash.state", "Prims.l_and", "LowStar.Monotonic.Buffer.freeable", "EverCrypt.Hash.state_s", "LowStar.Buffer.trivial_preorder", "EverCrypt.Hash.freeable_s", "LowStar.Monotonic.Buffer.deref", "Prims.logical" ]
[]
false
false
false
false
true
let freeable (#a: alg) (h: HS.mem) (p: state a) =
B.freeable p /\ freeable_s (B.deref h p)
false
EverCrypt.Hash.fsti
EverCrypt.Hash.preserves_freeable
val preserves_freeable (#a: _) (s: state a) (h0 h1: HS.mem) : Type0
val preserves_freeable (#a: _) (s: state a) (h0 h1: HS.mem) : Type0
let preserves_freeable #a (s: state a) (h0 h1: HS.mem): Type0 = freeable h0 s ==> freeable h1 s
{ "file_name": "providers/evercrypt/EverCrypt.Hash.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 33, "end_line": 180, "start_col": 0, "start_line": 179 }
module EverCrypt.Hash open EverCrypt.Helpers open FStar.HyperStack.ST open FStar.Integers open Spec.Hash.Definitions open Hacl.Hash.Definitions #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" /// Algorithmic agility for hash specifications. We reuse the agile /// specifications from HACL*'s specs/ directory. /// SUPPORTED ALGORITHMS see e.g. https://en.wikipedia.org/wiki/SHA-1 /// for a global comparison and lengths /// /// * We support all variants of SHA2. /// * MD5 and SHA1 are still required by TLS 1.2, included for legacy /// purpose only /// * SHA3 will be provided by HACL* /// /// ``hash_alg``, from Spec.Hash.Definitions, lists all supported algorithms unfold let alg = fixed_len_alg /// TODO: move this one to Hacl.Hash.Definitions val string_of_alg: alg -> C.String.t /// kept only for functional backward compatibility, never assumed to be secure type broken_alg = a:alg {a = MD5 \/ a = SHA1} /// HMAC/HKDF ALGORITHMS; we make security assumptions only for constructions /// based on those. type alg13 = a:alg { a=SHA2_256 \/ a=SHA2_384 \/ a=SHA2_512 } /// No pattern (would fire too often)! let uint32_fits_maxLength (a: alg) (x: UInt32.t): Lemma (requires True) (ensures UInt32.v x `less_than_max_input_length` a) = assert_norm (pow2 32 < pow2 61); assert_norm (pow2 61 < pow2 125) /// To specify their low-level incremental computations, we assume /// Merkle-Damgard/sponge-like algorithms: /// /// The hash state is kept in an accumulator, with /// - an initial value /// - an update function, adding a block of bytes; /// - an extract (also: "finish") function, returning a hash tag. /// /// Before hashing, some algorithm-specific padding and length encoding is /// appended to the input bytestring. /// /// This is not a general-purpose incremental specification, which would support /// adding text fragments of arbitrary lengths (for that, see /// EverCrypt.Hash.Incremental). /// Stateful interface implementing the agile specifications. module HS = FStar.HyperStack module B = LowStar.Buffer module M = LowStar.Modifies module G = FStar.Ghost open LowStar.BufferOps /// do not use as argument of ghost functions type e_alg = G.erased alg [@CAbstractStruct] val state_s: alg -> Type0 // pointer to abstract implementation state let state alg = B.pointer (state_s alg) // abstract freeable (deep) predicate; only needed for create/free pairs inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0 inline_for_extraction noextract let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p) // NS: note that the state is the first argument to the invariant so that we can // do partial applications in pre- and post-conditions val footprint_s: #a:alg -> state_s a -> GTot M.loc let footprint (#a:alg) (s: state a) (m: HS.mem) = M.(loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s))) // TR: the following pattern is necessary because, if we generically // add such a pattern directly on `loc_includes_union_l`, then // verification will blowup whenever both sides of `loc_includes` are // `loc_union`s. We would like to break all unions on the // right-hand-side of `loc_includes` first, using // `loc_includes_union_r`. Here the pattern is on `footprint_s`, // because we already expose the fact that `footprint` is a // `loc_union`. (In other words, the pattern should be on every // smallest location that is not exposed to be a `loc_union`.) let loc_includes_union_l_footprint_s (l1 l2: M.loc) (#a: alg) (s: state_s a) : Lemma (requires ( M.loc_includes l1 (footprint_s s) \/ M.loc_includes l2 (footprint_s s) )) (ensures (M.loc_includes (M.loc_union l1 l2) (footprint_s s))) [SMTPat (M.loc_includes (M.loc_union l1 l2) (footprint_s s))] = M.loc_includes_union_l l1 l2 (footprint_s s) inline_for_extraction noextract val invariant_s: (#a:alg) -> state_s a -> HS.mem -> Type0 inline_for_extraction noextract let invariant (#a:alg) (s: state a) (m: HS.mem) = B.live m s /\ M.(loc_disjoint (loc_addr_of_buffer s) (footprint_s (B.deref m s))) /\ invariant_s (B.get m s 0) m //18-07-06 as_acc a better name? not really a representation val repr: #a:alg -> s:state a -> h:HS.mem -> GTot (words_state a) val alg_of_state: a:e_alg -> ( let a = G.reveal a in s: state a -> Stack alg (fun h0 -> invariant s h0) (fun h0 a' h1 -> h0 == h1 /\ a' == a)) val fresh_is_disjoint: l1:M.loc -> l2:M.loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (B.fresh_loc l1 h0 h1 /\ l2 `B.loc_in` h0)) (ensures (M.loc_disjoint l1 l2)) // TR: this lemma is necessary to prove that the footprint is disjoint // from any fresh memory location. val invariant_loc_in_footprint (#a: alg) (s: state a) (m: HS.mem) : Lemma (requires (invariant s m)) (ensures (B.loc_in (footprint s m) m)) [SMTPat (invariant s m)] // TR: frame_invariant, just like all lemmas eliminating `modifies` // clauses, should have `modifies_inert` as a precondition instead of // `modifies`, in order to use it in all cases where a modifies clause // is produced but should not be composed with `modifies_trans` for // pattern reasons (e.g. push_frame, pop_frame) // 18-07-12 why not bundling the next two lemmas? val frame_invariant: #a:alg -> l:M.loc -> s:state a -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( invariant s h0 /\ M.loc_disjoint l (footprint s h0) /\ M.modifies l h0 h1)) (ensures ( invariant s h1 /\ repr s h0 == repr s h1)) let frame_invariant_implies_footprint_preservation (#a: alg) (l: M.loc) (s: state a) (h0 h1: HS.mem): Lemma (requires ( invariant s h0 /\ M.loc_disjoint l (footprint s h0) /\ M.modifies l h0 h1)) (ensures ( footprint s h1 == footprint s h0)) = ()
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Incremental.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.Helpers.fsti.checked", "C.String.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.Hash.fsti" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": false, "full_module": "C.Failure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "EverCrypt.AutoConfig2", "short_module": "AC" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: EverCrypt.Hash.state a -> h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> Type0
Prims.Tot
[ "total" ]
[]
[ "EverCrypt.Hash.alg", "EverCrypt.Hash.state", "FStar.Monotonic.HyperStack.mem", "Prims.l_imp", "EverCrypt.Hash.freeable" ]
[]
false
false
false
false
true
let preserves_freeable #a (s: state a) (h0: HS.mem) (h1: HS.mem) : Type0 =
freeable h0 s ==> freeable h1 s
false
EverCrypt.Hash.fsti
EverCrypt.Hash.state
val state : alg: EverCrypt.Hash.alg -> Type0
let state alg = B.pointer (state_s alg)
{ "file_name": "providers/evercrypt/EverCrypt.Hash.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 39, "end_line": 76, "start_col": 0, "start_line": 76 }
module EverCrypt.Hash open EverCrypt.Helpers open FStar.HyperStack.ST open FStar.Integers open Spec.Hash.Definitions open Hacl.Hash.Definitions #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" /// Algorithmic agility for hash specifications. We reuse the agile /// specifications from HACL*'s specs/ directory. /// SUPPORTED ALGORITHMS see e.g. https://en.wikipedia.org/wiki/SHA-1 /// for a global comparison and lengths /// /// * We support all variants of SHA2. /// * MD5 and SHA1 are still required by TLS 1.2, included for legacy /// purpose only /// * SHA3 will be provided by HACL* /// /// ``hash_alg``, from Spec.Hash.Definitions, lists all supported algorithms unfold let alg = fixed_len_alg /// TODO: move this one to Hacl.Hash.Definitions val string_of_alg: alg -> C.String.t /// kept only for functional backward compatibility, never assumed to be secure type broken_alg = a:alg {a = MD5 \/ a = SHA1} /// HMAC/HKDF ALGORITHMS; we make security assumptions only for constructions /// based on those. type alg13 = a:alg { a=SHA2_256 \/ a=SHA2_384 \/ a=SHA2_512 } /// No pattern (would fire too often)! let uint32_fits_maxLength (a: alg) (x: UInt32.t): Lemma (requires True) (ensures UInt32.v x `less_than_max_input_length` a) = assert_norm (pow2 32 < pow2 61); assert_norm (pow2 61 < pow2 125) /// To specify their low-level incremental computations, we assume /// Merkle-Damgard/sponge-like algorithms: /// /// The hash state is kept in an accumulator, with /// - an initial value /// - an update function, adding a block of bytes; /// - an extract (also: "finish") function, returning a hash tag. /// /// Before hashing, some algorithm-specific padding and length encoding is /// appended to the input bytestring. /// /// This is not a general-purpose incremental specification, which would support /// adding text fragments of arbitrary lengths (for that, see /// EverCrypt.Hash.Incremental). /// Stateful interface implementing the agile specifications. module HS = FStar.HyperStack module B = LowStar.Buffer module M = LowStar.Modifies module G = FStar.Ghost open LowStar.BufferOps /// do not use as argument of ghost functions type e_alg = G.erased alg [@CAbstractStruct] val state_s: alg -> Type0
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Incremental.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.Helpers.fsti.checked", "C.String.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.Hash.fsti" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": false, "full_module": "C.Failure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "EverCrypt.AutoConfig2", "short_module": "AC" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
alg: EverCrypt.Hash.alg -> Type0
Prims.Tot
[ "total" ]
[]
[ "EverCrypt.Hash.alg", "LowStar.Buffer.pointer", "EverCrypt.Hash.state_s" ]
[]
false
false
false
true
true
let state alg =
B.pointer (state_s alg)
false
EverCrypt.Hash.fsti
EverCrypt.Hash.footprint
val footprint : s: EverCrypt.Hash.state a -> m: FStar.Monotonic.HyperStack.mem -> Prims.GTot LowStar.Monotonic.Buffer.loc
let footprint (#a:alg) (s: state a) (m: HS.mem) = M.(loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s)))
{ "file_name": "providers/evercrypt/EverCrypt.Hash.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 66, "end_line": 90, "start_col": 0, "start_line": 89 }
module EverCrypt.Hash open EverCrypt.Helpers open FStar.HyperStack.ST open FStar.Integers open Spec.Hash.Definitions open Hacl.Hash.Definitions #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" /// Algorithmic agility for hash specifications. We reuse the agile /// specifications from HACL*'s specs/ directory. /// SUPPORTED ALGORITHMS see e.g. https://en.wikipedia.org/wiki/SHA-1 /// for a global comparison and lengths /// /// * We support all variants of SHA2. /// * MD5 and SHA1 are still required by TLS 1.2, included for legacy /// purpose only /// * SHA3 will be provided by HACL* /// /// ``hash_alg``, from Spec.Hash.Definitions, lists all supported algorithms unfold let alg = fixed_len_alg /// TODO: move this one to Hacl.Hash.Definitions val string_of_alg: alg -> C.String.t /// kept only for functional backward compatibility, never assumed to be secure type broken_alg = a:alg {a = MD5 \/ a = SHA1} /// HMAC/HKDF ALGORITHMS; we make security assumptions only for constructions /// based on those. type alg13 = a:alg { a=SHA2_256 \/ a=SHA2_384 \/ a=SHA2_512 } /// No pattern (would fire too often)! let uint32_fits_maxLength (a: alg) (x: UInt32.t): Lemma (requires True) (ensures UInt32.v x `less_than_max_input_length` a) = assert_norm (pow2 32 < pow2 61); assert_norm (pow2 61 < pow2 125) /// To specify their low-level incremental computations, we assume /// Merkle-Damgard/sponge-like algorithms: /// /// The hash state is kept in an accumulator, with /// - an initial value /// - an update function, adding a block of bytes; /// - an extract (also: "finish") function, returning a hash tag. /// /// Before hashing, some algorithm-specific padding and length encoding is /// appended to the input bytestring. /// /// This is not a general-purpose incremental specification, which would support /// adding text fragments of arbitrary lengths (for that, see /// EverCrypt.Hash.Incremental). /// Stateful interface implementing the agile specifications. module HS = FStar.HyperStack module B = LowStar.Buffer module M = LowStar.Modifies module G = FStar.Ghost open LowStar.BufferOps /// do not use as argument of ghost functions type e_alg = G.erased alg [@CAbstractStruct] val state_s: alg -> Type0 // pointer to abstract implementation state let state alg = B.pointer (state_s alg) // abstract freeable (deep) predicate; only needed for create/free pairs inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0 inline_for_extraction noextract let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p) // NS: note that the state is the first argument to the invariant so that we can // do partial applications in pre- and post-conditions
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Incremental.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.Helpers.fsti.checked", "C.String.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.Hash.fsti" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": false, "full_module": "C.Failure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "EverCrypt.AutoConfig2", "short_module": "AC" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: EverCrypt.Hash.state a -> m: FStar.Monotonic.HyperStack.mem -> Prims.GTot LowStar.Monotonic.Buffer.loc
Prims.GTot
[ "sometrivial" ]
[]
[ "EverCrypt.Hash.alg", "EverCrypt.Hash.state", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc_addr_of_buffer", "EverCrypt.Hash.state_s", "LowStar.Buffer.trivial_preorder", "EverCrypt.Hash.footprint_s", "LowStar.Monotonic.Buffer.deref", "LowStar.Monotonic.Buffer.loc" ]
[]
false
false
false
false
false
let footprint (#a: alg) (s: state a) (m: HS.mem) =
let open M in loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s))
false
EverCrypt.Hash.fsti
EverCrypt.Hash.free
val free (#a: e_alg) : (let a = Ghost.reveal a in s: state a -> ST unit (requires fun h0 -> freeable h0 s /\ invariant s h0) (ensures fun h0 _ h1 -> let open M in modifies (footprint s h0) h0 h1))
val free (#a: e_alg) : (let a = Ghost.reveal a in s: state a -> ST unit (requires fun h0 -> freeable h0 s /\ invariant s h0) (ensures fun h0 _ h1 -> let open M in modifies (footprint s h0) h0 h1))
let free: #a:e_alg -> ( let a = Ghost.reveal a in s:state a -> ST unit (requires fun h0 -> freeable h0 s /\ invariant s h0) (ensures fun h0 _ h1 -> M.(modifies (footprint s h0) h0 h1))) = free_
{ "file_name": "providers/evercrypt/EverCrypt.Hash.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 8, "end_line": 347, "start_col": 0, "start_line": 339 }
module EverCrypt.Hash open EverCrypt.Helpers open FStar.HyperStack.ST open FStar.Integers open Spec.Hash.Definitions open Hacl.Hash.Definitions #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" /// Algorithmic agility for hash specifications. We reuse the agile /// specifications from HACL*'s specs/ directory. /// SUPPORTED ALGORITHMS see e.g. https://en.wikipedia.org/wiki/SHA-1 /// for a global comparison and lengths /// /// * We support all variants of SHA2. /// * MD5 and SHA1 are still required by TLS 1.2, included for legacy /// purpose only /// * SHA3 will be provided by HACL* /// /// ``hash_alg``, from Spec.Hash.Definitions, lists all supported algorithms unfold let alg = fixed_len_alg /// TODO: move this one to Hacl.Hash.Definitions val string_of_alg: alg -> C.String.t /// kept only for functional backward compatibility, never assumed to be secure type broken_alg = a:alg {a = MD5 \/ a = SHA1} /// HMAC/HKDF ALGORITHMS; we make security assumptions only for constructions /// based on those. type alg13 = a:alg { a=SHA2_256 \/ a=SHA2_384 \/ a=SHA2_512 } /// No pattern (would fire too often)! let uint32_fits_maxLength (a: alg) (x: UInt32.t): Lemma (requires True) (ensures UInt32.v x `less_than_max_input_length` a) = assert_norm (pow2 32 < pow2 61); assert_norm (pow2 61 < pow2 125) /// To specify their low-level incremental computations, we assume /// Merkle-Damgard/sponge-like algorithms: /// /// The hash state is kept in an accumulator, with /// - an initial value /// - an update function, adding a block of bytes; /// - an extract (also: "finish") function, returning a hash tag. /// /// Before hashing, some algorithm-specific padding and length encoding is /// appended to the input bytestring. /// /// This is not a general-purpose incremental specification, which would support /// adding text fragments of arbitrary lengths (for that, see /// EverCrypt.Hash.Incremental). /// Stateful interface implementing the agile specifications. module HS = FStar.HyperStack module B = LowStar.Buffer module M = LowStar.Modifies module G = FStar.Ghost open LowStar.BufferOps /// do not use as argument of ghost functions type e_alg = G.erased alg [@CAbstractStruct] val state_s: alg -> Type0 // pointer to abstract implementation state let state alg = B.pointer (state_s alg) // abstract freeable (deep) predicate; only needed for create/free pairs inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0 inline_for_extraction noextract let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p) // NS: note that the state is the first argument to the invariant so that we can // do partial applications in pre- and post-conditions val footprint_s: #a:alg -> state_s a -> GTot M.loc let footprint (#a:alg) (s: state a) (m: HS.mem) = M.(loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s))) // TR: the following pattern is necessary because, if we generically // add such a pattern directly on `loc_includes_union_l`, then // verification will blowup whenever both sides of `loc_includes` are // `loc_union`s. We would like to break all unions on the // right-hand-side of `loc_includes` first, using // `loc_includes_union_r`. Here the pattern is on `footprint_s`, // because we already expose the fact that `footprint` is a // `loc_union`. (In other words, the pattern should be on every // smallest location that is not exposed to be a `loc_union`.) let loc_includes_union_l_footprint_s (l1 l2: M.loc) (#a: alg) (s: state_s a) : Lemma (requires ( M.loc_includes l1 (footprint_s s) \/ M.loc_includes l2 (footprint_s s) )) (ensures (M.loc_includes (M.loc_union l1 l2) (footprint_s s))) [SMTPat (M.loc_includes (M.loc_union l1 l2) (footprint_s s))] = M.loc_includes_union_l l1 l2 (footprint_s s) inline_for_extraction noextract val invariant_s: (#a:alg) -> state_s a -> HS.mem -> Type0 inline_for_extraction noextract let invariant (#a:alg) (s: state a) (m: HS.mem) = B.live m s /\ M.(loc_disjoint (loc_addr_of_buffer s) (footprint_s (B.deref m s))) /\ invariant_s (B.get m s 0) m //18-07-06 as_acc a better name? not really a representation val repr: #a:alg -> s:state a -> h:HS.mem -> GTot (words_state a) val alg_of_state: a:e_alg -> ( let a = G.reveal a in s: state a -> Stack alg (fun h0 -> invariant s h0) (fun h0 a' h1 -> h0 == h1 /\ a' == a)) val fresh_is_disjoint: l1:M.loc -> l2:M.loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (B.fresh_loc l1 h0 h1 /\ l2 `B.loc_in` h0)) (ensures (M.loc_disjoint l1 l2)) // TR: this lemma is necessary to prove that the footprint is disjoint // from any fresh memory location. val invariant_loc_in_footprint (#a: alg) (s: state a) (m: HS.mem) : Lemma (requires (invariant s m)) (ensures (B.loc_in (footprint s m) m)) [SMTPat (invariant s m)] // TR: frame_invariant, just like all lemmas eliminating `modifies` // clauses, should have `modifies_inert` as a precondition instead of // `modifies`, in order to use it in all cases where a modifies clause // is produced but should not be composed with `modifies_trans` for // pattern reasons (e.g. push_frame, pop_frame) // 18-07-12 why not bundling the next two lemmas? val frame_invariant: #a:alg -> l:M.loc -> s:state a -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( invariant s h0 /\ M.loc_disjoint l (footprint s h0) /\ M.modifies l h0 h1)) (ensures ( invariant s h1 /\ repr s h0 == repr s h1)) let frame_invariant_implies_footprint_preservation (#a: alg) (l: M.loc) (s: state a) (h0 h1: HS.mem): Lemma (requires ( invariant s h0 /\ M.loc_disjoint l (footprint s h0) /\ M.modifies l h0 h1)) (ensures ( footprint s h1 == footprint s h0)) = () inline_for_extraction noextract let preserves_freeable #a (s: state a) (h0 h1: HS.mem): Type0 = freeable h0 s ==> freeable h1 s /// This function will generally not extract properly, so it should be used with /// great care. Callers must: /// - run with evercrypt/fst in scope to benefit from the definition of this function /// - know, at call-site, the concrete value of a via suitable usage of inline_for_extraction inline_for_extraction noextract val alloca: a:alg -> StackInline (state a) (requires (fun _ -> True)) (ensures (fun h0 s h1 -> invariant s h1 /\ M.(modifies loc_none h0 h1) /\ B.fresh_loc (footprint s h1) h0 h1 /\ M.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint s h1)))) (** @type: true *) val create_in: a:alg -> r:HS.rid -> ST (state a) (requires (fun _ -> HyperStack.ST.is_eternal_region r)) (ensures (fun h0 s h1 -> invariant s h1 /\ M.(modifies loc_none h0 h1) /\ B.fresh_loc (footprint s h1) h0 h1 /\ M.(loc_includes (loc_region_only true r) (footprint s h1)) /\ freeable h1 s)) (** @type: true *) val create: a:alg -> ST (state a) (requires fun h0 -> True) (ensures fun h0 s h1 -> invariant s h1 /\ M.(modifies loc_none h0 h1) /\ B.fresh_loc (footprint s h1) h0 h1 /\ freeable h1 s) (** @type: true *) val init: #a:e_alg -> ( let a = Ghost.reveal a in s: state a -> Stack unit (requires invariant s) (ensures fun h0 _ h1 -> invariant s h1 /\ repr s h1 == Spec.Agile.Hash.init a /\ M.(modifies (footprint s h0) h0 h1) /\ footprint s h0 == footprint s h1 /\ preserves_freeable s h0 h1)) val update_multi_256: Hacl.Hash.Definitions.update_multi_st (|SHA2_256, ()|) inline_for_extraction noextract val update_multi_224: Hacl.Hash.Definitions.update_multi_st (|SHA2_224, ()|) inline_for_extraction noextract let ev_of_uint64 a (prevlen: UInt64.t { UInt64.v prevlen % block_length a = 0 }): Spec.Hash.Definitions.extra_state a = (if is_blake a then UInt64.v prevlen else ()) /// The ``update_multi`` method // Note that we pass the data length in bytes (rather than blocks). (** @type: true *) val update_multi: #a:e_alg -> ( let a = Ghost.reveal a in s:state a -> prevlen : uint64_t { UInt64.v prevlen % block_length a = 0 } -> blocks:B.buffer Lib.IntTypes.uint8 { B.length blocks % block_length a = 0 } -> len: UInt32.t { v len = B.length blocks } -> Stack unit (requires fun h0 -> invariant s h0 /\ B.live h0 blocks /\ Spec.Agile.Hash.update_multi_pre a (ev_of_uint64 a prevlen) (B.as_seq h0 blocks) /\ M.(loc_disjoint (footprint s h0) (loc_buffer blocks))) (ensures fun h0 _ h1 -> M.(modifies (footprint s h0) h0 h1) /\ footprint s h0 == footprint s h1 /\ invariant s h1 /\ repr s h1 == Spec.Agile.Hash.update_multi a (repr s h0) (ev_of_uint64 a prevlen) (B.as_seq h0 blocks) /\ preserves_freeable s h0 h1)) inline_for_extraction noextract let prev_len_of_uint64 a (prevlen: UInt64.t { UInt64.v prevlen % block_length a = 0 }): Spec.Hash.Incremental.prev_length_t a = (if is_keccak a then () else UInt64.v prevlen) /// The ``update_last`` method with support for blake2 // 18-03-05 note the *new* length-passing convention! // 18-03-03 it is best to let the caller keep track of lengths. // 18-03-03 the last block is *never* complete so there is room for the 1st byte of padding. // 18-10-10 using uint64 for the length as the is the only thing that TLS needs // and also saves the need for a (painful) indexed type // 18-10-15 a crucial bit is that this function reveals that last @| padding is a multiple of the // block size; indeed, any caller will want to know this in order to reason // about that sequence concatenation (** @type: true *) val update_last: #a:e_alg -> ( let a = Ghost.reveal a in s:state a -> prev_len:uint64_t -> last:B.buffer Lib.IntTypes.uint8 { B.length last <= block_length a } -> last_len:uint32_t { v last_len = B.length last /\ (v prev_len + v last_len) `less_than_max_input_length` a /\ v prev_len % block_length a = 0 } -> Stack unit (requires fun h0 -> invariant s h0 /\ B.live h0 last /\ Spec.Agile.Hash.update_multi_pre a (ev_of_uint64 a prev_len) (B.as_seq h0 last) /\ M.(loc_disjoint (footprint s h0) (loc_buffer last))) (ensures fun h0 _ h1 -> invariant s h1 /\ repr s h1 == Spec.Hash.Incremental.update_last a (repr s h0) (prev_len_of_uint64 a prev_len) (B.as_seq h0 last) /\ M.(modifies (footprint s h0) h0 h1) /\ footprint s h0 == footprint s h1 /\ preserves_freeable s h0 h1)) (** @type: true *) val finish: #a:e_alg -> ( let a = Ghost.reveal a in s:state a -> dst:B.buffer Lib.IntTypes.uint8 { B.length dst = hash_length a } -> Stack unit (requires fun h0 -> invariant s h0 /\ B.live h0 dst /\ M.(loc_disjoint (footprint s h0) (loc_buffer dst))) (ensures fun h0 _ h1 -> invariant s h1 /\ M.(modifies (loc_buffer dst `loc_union` footprint s h0) h0 h1) /\ footprint s h0 == footprint s h1 /\ (* The 0UL value is dummy: it is actually useless *) B.as_seq h1 dst == Spec.Agile.Hash.finish a (repr s h0) () /\ preserves_freeable s h0 h1)) (** @type: true *) val free_: #a:e_alg -> ( let a = Ghost.reveal a in s:state a -> ST unit (requires fun h0 -> freeable h0 s /\ invariant s h0) (ensures fun h0 _ h1 -> M.(modifies (footprint s h0) h0 h1))) // Avoids C-level collisions with the stdlib free. // Not clear why we need to repeat the type annotation.
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Incremental.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.Helpers.fsti.checked", "C.String.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.Hash.fsti" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": false, "full_module": "C.Failure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "EverCrypt.AutoConfig2", "short_module": "AC" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: EverCrypt.Hash.state (FStar.Ghost.reveal a) -> FStar.HyperStack.ST.ST Prims.unit
FStar.HyperStack.ST.ST
[]
[]
[ "EverCrypt.Hash.free_" ]
[]
false
true
false
false
false
let free: #a: e_alg -> (let a = Ghost.reveal a in s: state a -> ST unit (requires fun h0 -> freeable h0 s /\ invariant s h0) (ensures fun h0 _ h1 -> let open M in modifies (footprint s h0) h0 h1)) =
free_
false
Hacl.Bignum256.fst
Hacl.Bignum256.sub
val sub: BN.bn_sub_eq_len_st t_limbs n_limbs
val sub: BN.bn_sub_eq_len_st t_limbs n_limbs
let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 26, "end_line": 18, "start_col": 0, "start_line": 17 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.bn_sub_eq_len_st Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.bn_sub_eq_len", "Hacl.Bignum256.t_limbs", "Hacl.Bignum256.n_limbs", "Hacl.Bignum.bn_sub_eq_len_st" ]
[]
false
false
false
true
false
let sub:BN.bn_sub_eq_len_st t_limbs n_limbs =
BN.bn_sub_eq_len n_limbs
false
Hacl.Bignum256.fst
Hacl.Bignum256.add
val add: BN.bn_add_eq_len_st t_limbs n_limbs
val add: BN.bn_add_eq_len_st t_limbs n_limbs
let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 26, "end_line": 15, "start_col": 0, "start_line": 14 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.bn_add_eq_len_st Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.bn_add_eq_len", "Hacl.Bignum256.t_limbs", "Hacl.Bignum256.n_limbs", "Hacl.Bignum.bn_add_eq_len_st" ]
[]
false
false
false
true
false
let add:BN.bn_add_eq_len_st t_limbs n_limbs =
BN.bn_add_eq_len n_limbs
false
Hacl.Bignum256.fst
Hacl.Bignum256.bn_inst
[@@ FStar.Tactics.Typeclasses.tcinstance] val bn_inst:BN.bn t_limbs
[@@ FStar.Tactics.Typeclasses.tcinstance] val bn_inst:BN.bn t_limbs
instance bn_inst: BN.bn t_limbs = { BN.len = n_limbs; BN.add; BN.sub; BN.add_mod_n = add_mod; BN.sub_mod_n = sub_mod; BN.mul; BN.sqr }
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 1, "end_line": 42, "start_col": 0, "start_line": 34 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs let mul (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a = BN.bn_mul n_limbs n_limbs a let sqr (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_sqr_st t_limbs n_limbs a = BN.bn_sqr n_limbs a //BN.bn_mul n_limbs n_limbs a a
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.bn Hacl.Bignum256.t_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Mkbn", "Hacl.Bignum256.t_limbs", "Hacl.Bignum256.n_limbs", "Hacl.Bignum256.add", "Hacl.Bignum256.sub", "Hacl.Bignum256.add_mod", "Hacl.Bignum256.sub_mod", "Hacl.Bignum256.mul", "Hacl.Bignum256.sqr" ]
[]
false
false
false
true
false
[@@ FStar.Tactics.Typeclasses.tcinstance] let bn_inst:BN.bn t_limbs =
{ BN.len = n_limbs; BN.add = add; BN.sub = sub; BN.add_mod_n = add_mod; BN.sub_mod_n = sub_mod; BN.mul = mul; BN.sqr = sqr }
false
Hacl.Bignum256.fst
Hacl.Bignum256.mont_check
val mont_check:BM.bn_check_modulus_st t_limbs n_limbs
val mont_check:BM.bn_check_modulus_st t_limbs n_limbs
let mont_check: BM.bn_check_modulus_st t_limbs n_limbs = BM.bn_check_modulus
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 21, "end_line": 46, "start_col": 0, "start_line": 45 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs let mul (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a = BN.bn_mul n_limbs n_limbs a let sqr (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_sqr_st t_limbs n_limbs a = BN.bn_sqr n_limbs a //BN.bn_mul n_limbs n_limbs a a inline_for_extraction noextract instance bn_inst: BN.bn t_limbs = { BN.len = n_limbs; BN.add; BN.sub; BN.add_mod_n = add_mod; BN.sub_mod_n = sub_mod; BN.mul; BN.sqr }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.Montgomery.bn_check_modulus_st Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Montgomery.bn_check_modulus", "Hacl.Bignum256.t_limbs", "Hacl.Bignum256.n_limbs" ]
[]
false
false
false
true
false
let mont_check:BM.bn_check_modulus_st t_limbs n_limbs =
BM.bn_check_modulus
false
Hacl.Bignum256.fst
Hacl.Bignum256.to
val to:BM.bn_to_mont_st t_limbs n_limbs
val to:BM.bn_to_mont_st t_limbs n_limbs
let to: BM.bn_to_mont_st t_limbs n_limbs = BM.bn_to_mont bn_inst reduction
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 33, "end_line": 58, "start_col": 0, "start_line": 57 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs let mul (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a = BN.bn_mul n_limbs n_limbs a let sqr (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_sqr_st t_limbs n_limbs a = BN.bn_sqr n_limbs a //BN.bn_mul n_limbs n_limbs a a inline_for_extraction noextract instance bn_inst: BN.bn t_limbs = { BN.len = n_limbs; BN.add; BN.sub; BN.add_mod_n = add_mod; BN.sub_mod_n = sub_mod; BN.mul; BN.sqr } [@CInline] let mont_check: BM.bn_check_modulus_st t_limbs n_limbs = BM.bn_check_modulus [@CInline] let precompr2: BM.bn_precomp_r2_mod_n_st t_limbs n_limbs = BM.bn_precomp_r2_mod_n bn_inst [@CInline] let reduction: BM.bn_mont_reduction_st t_limbs n_limbs = BM.bn_mont_reduction bn_inst
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.Montgomery.bn_to_mont_st Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Montgomery.bn_to_mont", "Hacl.Bignum256.t_limbs", "Hacl.Bignum256.bn_inst", "Hacl.Bignum256.reduction" ]
[]
false
false
false
true
false
let to:BM.bn_to_mont_st t_limbs n_limbs =
BM.bn_to_mont bn_inst reduction
false
EverCrypt.Hash.fsti
EverCrypt.Hash.loc_includes_union_l_footprint_s
val loc_includes_union_l_footprint_s (l1 l2: M.loc) (#a: alg) (s: state_s a) : Lemma (requires (M.loc_includes l1 (footprint_s s) \/ M.loc_includes l2 (footprint_s s))) (ensures (M.loc_includes (M.loc_union l1 l2) (footprint_s s))) [SMTPat (M.loc_includes (M.loc_union l1 l2) (footprint_s s))]
val loc_includes_union_l_footprint_s (l1 l2: M.loc) (#a: alg) (s: state_s a) : Lemma (requires (M.loc_includes l1 (footprint_s s) \/ M.loc_includes l2 (footprint_s s))) (ensures (M.loc_includes (M.loc_union l1 l2) (footprint_s s))) [SMTPat (M.loc_includes (M.loc_union l1 l2) (footprint_s s))]
let loc_includes_union_l_footprint_s (l1 l2: M.loc) (#a: alg) (s: state_s a) : Lemma (requires ( M.loc_includes l1 (footprint_s s) \/ M.loc_includes l2 (footprint_s s) )) (ensures (M.loc_includes (M.loc_union l1 l2) (footprint_s s))) [SMTPat (M.loc_includes (M.loc_union l1 l2) (footprint_s s))] = M.loc_includes_union_l l1 l2 (footprint_s s)
{ "file_name": "providers/evercrypt/EverCrypt.Hash.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 46, "end_line": 111, "start_col": 0, "start_line": 103 }
module EverCrypt.Hash open EverCrypt.Helpers open FStar.HyperStack.ST open FStar.Integers open Spec.Hash.Definitions open Hacl.Hash.Definitions #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" /// Algorithmic agility for hash specifications. We reuse the agile /// specifications from HACL*'s specs/ directory. /// SUPPORTED ALGORITHMS see e.g. https://en.wikipedia.org/wiki/SHA-1 /// for a global comparison and lengths /// /// * We support all variants of SHA2. /// * MD5 and SHA1 are still required by TLS 1.2, included for legacy /// purpose only /// * SHA3 will be provided by HACL* /// /// ``hash_alg``, from Spec.Hash.Definitions, lists all supported algorithms unfold let alg = fixed_len_alg /// TODO: move this one to Hacl.Hash.Definitions val string_of_alg: alg -> C.String.t /// kept only for functional backward compatibility, never assumed to be secure type broken_alg = a:alg {a = MD5 \/ a = SHA1} /// HMAC/HKDF ALGORITHMS; we make security assumptions only for constructions /// based on those. type alg13 = a:alg { a=SHA2_256 \/ a=SHA2_384 \/ a=SHA2_512 } /// No pattern (would fire too often)! let uint32_fits_maxLength (a: alg) (x: UInt32.t): Lemma (requires True) (ensures UInt32.v x `less_than_max_input_length` a) = assert_norm (pow2 32 < pow2 61); assert_norm (pow2 61 < pow2 125) /// To specify their low-level incremental computations, we assume /// Merkle-Damgard/sponge-like algorithms: /// /// The hash state is kept in an accumulator, with /// - an initial value /// - an update function, adding a block of bytes; /// - an extract (also: "finish") function, returning a hash tag. /// /// Before hashing, some algorithm-specific padding and length encoding is /// appended to the input bytestring. /// /// This is not a general-purpose incremental specification, which would support /// adding text fragments of arbitrary lengths (for that, see /// EverCrypt.Hash.Incremental). /// Stateful interface implementing the agile specifications. module HS = FStar.HyperStack module B = LowStar.Buffer module M = LowStar.Modifies module G = FStar.Ghost open LowStar.BufferOps /// do not use as argument of ghost functions type e_alg = G.erased alg [@CAbstractStruct] val state_s: alg -> Type0 // pointer to abstract implementation state let state alg = B.pointer (state_s alg) // abstract freeable (deep) predicate; only needed for create/free pairs inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0 inline_for_extraction noextract let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p) // NS: note that the state is the first argument to the invariant so that we can // do partial applications in pre- and post-conditions val footprint_s: #a:alg -> state_s a -> GTot M.loc let footprint (#a:alg) (s: state a) (m: HS.mem) = M.(loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s))) // TR: the following pattern is necessary because, if we generically // add such a pattern directly on `loc_includes_union_l`, then // verification will blowup whenever both sides of `loc_includes` are // `loc_union`s. We would like to break all unions on the // right-hand-side of `loc_includes` first, using // `loc_includes_union_r`. Here the pattern is on `footprint_s`, // because we already expose the fact that `footprint` is a // `loc_union`. (In other words, the pattern should be on every // smallest location that is not exposed to be a `loc_union`.)
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Incremental.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.Helpers.fsti.checked", "C.String.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.Hash.fsti" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": false, "full_module": "C.Failure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "EverCrypt.AutoConfig2", "short_module": "AC" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l1: LowStar.Monotonic.Buffer.loc -> l2: LowStar.Monotonic.Buffer.loc -> s: EverCrypt.Hash.state_s a -> FStar.Pervasives.Lemma (requires LowStar.Monotonic.Buffer.loc_includes l1 (EverCrypt.Hash.footprint_s s) \/ LowStar.Monotonic.Buffer.loc_includes l2 (EverCrypt.Hash.footprint_s s)) (ensures LowStar.Monotonic.Buffer.loc_includes (LowStar.Monotonic.Buffer.loc_union l1 l2) (EverCrypt.Hash.footprint_s s)) [ SMTPat (LowStar.Monotonic.Buffer.loc_includes (LowStar.Monotonic.Buffer.loc_union l1 l2) (EverCrypt.Hash.footprint_s s)) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "LowStar.Monotonic.Buffer.loc", "EverCrypt.Hash.alg", "EverCrypt.Hash.state_s", "LowStar.Monotonic.Buffer.loc_includes_union_l", "EverCrypt.Hash.footprint_s", "Prims.unit", "Prims.l_or", "LowStar.Monotonic.Buffer.loc_includes", "Prims.squash", "LowStar.Monotonic.Buffer.loc_union", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
true
false
true
false
false
let loc_includes_union_l_footprint_s (l1 l2: M.loc) (#a: alg) (s: state_s a) : Lemma (requires (M.loc_includes l1 (footprint_s s) \/ M.loc_includes l2 (footprint_s s))) (ensures (M.loc_includes (M.loc_union l1 l2) (footprint_s s))) [SMTPat (M.loc_includes (M.loc_union l1 l2) (footprint_s s))] =
M.loc_includes_union_l l1 l2 (footprint_s s)
false
Hacl.Bignum256.fst
Hacl.Bignum256.precompr2
val precompr2:BM.bn_precomp_r2_mod_n_st t_limbs n_limbs
val precompr2:BM.bn_precomp_r2_mod_n_st t_limbs n_limbs
let precompr2: BM.bn_precomp_r2_mod_n_st t_limbs n_limbs = BM.bn_precomp_r2_mod_n bn_inst
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 50, "start_col": 0, "start_line": 49 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs let mul (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a = BN.bn_mul n_limbs n_limbs a let sqr (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_sqr_st t_limbs n_limbs a = BN.bn_sqr n_limbs a //BN.bn_mul n_limbs n_limbs a a inline_for_extraction noextract instance bn_inst: BN.bn t_limbs = { BN.len = n_limbs; BN.add; BN.sub; BN.add_mod_n = add_mod; BN.sub_mod_n = sub_mod; BN.mul; BN.sqr } [@CInline] let mont_check: BM.bn_check_modulus_st t_limbs n_limbs = BM.bn_check_modulus
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.Montgomery.bn_precomp_r2_mod_n_st Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Montgomery.bn_precomp_r2_mod_n", "Hacl.Bignum256.t_limbs", "Hacl.Bignum256.bn_inst" ]
[]
false
false
false
true
false
let precompr2:BM.bn_precomp_r2_mod_n_st t_limbs n_limbs =
BM.bn_precomp_r2_mod_n bn_inst
false
Hacl.Bignum256.fst
Hacl.Bignum256.almost_mont_inst
[@@ FStar.Tactics.Typeclasses.tcinstance] val almost_mont_inst:AM.almost_mont t_limbs
[@@ FStar.Tactics.Typeclasses.tcinstance] val almost_mont_inst:AM.almost_mont t_limbs
instance almost_mont_inst: AM.almost_mont t_limbs = { AM.bn = bn_inst; AM.mont_check; AM.precomp = precompr2; AM.reduction = areduction; AM.to; AM.from; AM.mul = amont_mul; AM.sqr = amont_sqr; }
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 1, "end_line": 106, "start_col": 0, "start_line": 97 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs let mul (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a = BN.bn_mul n_limbs n_limbs a let sqr (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_sqr_st t_limbs n_limbs a = BN.bn_sqr n_limbs a //BN.bn_mul n_limbs n_limbs a a inline_for_extraction noextract instance bn_inst: BN.bn t_limbs = { BN.len = n_limbs; BN.add; BN.sub; BN.add_mod_n = add_mod; BN.sub_mod_n = sub_mod; BN.mul; BN.sqr } [@CInline] let mont_check: BM.bn_check_modulus_st t_limbs n_limbs = BM.bn_check_modulus [@CInline] let precompr2: BM.bn_precomp_r2_mod_n_st t_limbs n_limbs = BM.bn_precomp_r2_mod_n bn_inst [@CInline] let reduction: BM.bn_mont_reduction_st t_limbs n_limbs = BM.bn_mont_reduction bn_inst [@CInline] let to: BM.bn_to_mont_st t_limbs n_limbs = BM.bn_to_mont bn_inst reduction [@CInline] let from: BM.bn_from_mont_st t_limbs n_limbs = BM.bn_from_mont bn_inst reduction // [@CInline] // let mont_mul: BM.bn_mont_mul_st t_limbs n_limbs = // BM.bn_mont_mul bn_inst reduction // [@CInline] // let mont_sqr: BM.bn_mont_sqr_st t_limbs n_limbs = // BM.bn_mont_sqr bn_inst reduction // inline_for_extraction noextract // instance mont_inst: BM.mont t_limbs = { // BM.bn = bn_inst; // BM.mont_check; // BM.precomp = precompr2; // BM.reduction; // BM.to; // BM.from; // BM.mul = mont_mul; // BM.sqr = mont_sqr; // } [@CInline] let areduction: AM.bn_almost_mont_reduction_st t_limbs n_limbs = AM.bn_almost_mont_reduction bn_inst [@CInline] let amont_mul: AM.bn_almost_mont_mul_st t_limbs n_limbs = AM.bn_almost_mont_mul bn_inst areduction [@CInline] let amont_sqr: AM.bn_almost_mont_sqr_st t_limbs n_limbs = AM.bn_almost_mont_sqr bn_inst areduction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.AlmostMontgomery.almost_mont Hacl.Bignum256.t_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.AlmostMontgomery.Mkalmost_mont", "Hacl.Bignum256.t_limbs", "Hacl.Bignum256.bn_inst", "Hacl.Bignum256.mont_check", "Hacl.Bignum256.precompr2", "Hacl.Bignum256.areduction", "Hacl.Bignum256.to", "Hacl.Bignum256.from", "Hacl.Bignum256.amont_mul", "Hacl.Bignum256.amont_sqr" ]
[]
false
false
false
true
false
[@@ FStar.Tactics.Typeclasses.tcinstance] let almost_mont_inst:AM.almost_mont t_limbs =
{ AM.bn = bn_inst; AM.mont_check = mont_check; AM.precomp = precompr2; AM.reduction = areduction; AM.to = to; AM.from = from; AM.mul = amont_mul; AM.sqr = amont_sqr }
false
Hacl.Bignum256.fst
Hacl.Bignum256.from
val from:BM.bn_from_mont_st t_limbs n_limbs
val from:BM.bn_from_mont_st t_limbs n_limbs
let from: BM.bn_from_mont_st t_limbs n_limbs = BM.bn_from_mont bn_inst reduction
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 35, "end_line": 62, "start_col": 0, "start_line": 61 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs let mul (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a = BN.bn_mul n_limbs n_limbs a let sqr (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_sqr_st t_limbs n_limbs a = BN.bn_sqr n_limbs a //BN.bn_mul n_limbs n_limbs a a inline_for_extraction noextract instance bn_inst: BN.bn t_limbs = { BN.len = n_limbs; BN.add; BN.sub; BN.add_mod_n = add_mod; BN.sub_mod_n = sub_mod; BN.mul; BN.sqr } [@CInline] let mont_check: BM.bn_check_modulus_st t_limbs n_limbs = BM.bn_check_modulus [@CInline] let precompr2: BM.bn_precomp_r2_mod_n_st t_limbs n_limbs = BM.bn_precomp_r2_mod_n bn_inst [@CInline] let reduction: BM.bn_mont_reduction_st t_limbs n_limbs = BM.bn_mont_reduction bn_inst [@CInline] let to: BM.bn_to_mont_st t_limbs n_limbs = BM.bn_to_mont bn_inst reduction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.Montgomery.bn_from_mont_st Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Montgomery.bn_from_mont", "Hacl.Bignum256.t_limbs", "Hacl.Bignum256.bn_inst", "Hacl.Bignum256.reduction" ]
[]
false
false
false
true
false
let from:BM.bn_from_mont_st t_limbs n_limbs =
BM.bn_from_mont bn_inst reduction
false
Hacl.Bignum256.fst
Hacl.Bignum256.amont_sqr
val amont_sqr:AM.bn_almost_mont_sqr_st t_limbs n_limbs
val amont_sqr:AM.bn_almost_mont_sqr_st t_limbs n_limbs
let amont_sqr: AM.bn_almost_mont_sqr_st t_limbs n_limbs = AM.bn_almost_mont_sqr bn_inst areduction
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 42, "end_line": 94, "start_col": 0, "start_line": 93 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs let mul (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a = BN.bn_mul n_limbs n_limbs a let sqr (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_sqr_st t_limbs n_limbs a = BN.bn_sqr n_limbs a //BN.bn_mul n_limbs n_limbs a a inline_for_extraction noextract instance bn_inst: BN.bn t_limbs = { BN.len = n_limbs; BN.add; BN.sub; BN.add_mod_n = add_mod; BN.sub_mod_n = sub_mod; BN.mul; BN.sqr } [@CInline] let mont_check: BM.bn_check_modulus_st t_limbs n_limbs = BM.bn_check_modulus [@CInline] let precompr2: BM.bn_precomp_r2_mod_n_st t_limbs n_limbs = BM.bn_precomp_r2_mod_n bn_inst [@CInline] let reduction: BM.bn_mont_reduction_st t_limbs n_limbs = BM.bn_mont_reduction bn_inst [@CInline] let to: BM.bn_to_mont_st t_limbs n_limbs = BM.bn_to_mont bn_inst reduction [@CInline] let from: BM.bn_from_mont_st t_limbs n_limbs = BM.bn_from_mont bn_inst reduction // [@CInline] // let mont_mul: BM.bn_mont_mul_st t_limbs n_limbs = // BM.bn_mont_mul bn_inst reduction // [@CInline] // let mont_sqr: BM.bn_mont_sqr_st t_limbs n_limbs = // BM.bn_mont_sqr bn_inst reduction // inline_for_extraction noextract // instance mont_inst: BM.mont t_limbs = { // BM.bn = bn_inst; // BM.mont_check; // BM.precomp = precompr2; // BM.reduction; // BM.to; // BM.from; // BM.mul = mont_mul; // BM.sqr = mont_sqr; // } [@CInline] let areduction: AM.bn_almost_mont_reduction_st t_limbs n_limbs = AM.bn_almost_mont_reduction bn_inst [@CInline] let amont_mul: AM.bn_almost_mont_mul_st t_limbs n_limbs = AM.bn_almost_mont_mul bn_inst areduction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.AlmostMontgomery.bn_almost_mont_sqr_st Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.AlmostMontgomery.bn_almost_mont_sqr", "Hacl.Bignum256.t_limbs", "Hacl.Bignum256.bn_inst", "Hacl.Bignum256.areduction" ]
[]
false
false
false
true
false
let amont_sqr:AM.bn_almost_mont_sqr_st t_limbs n_limbs =
AM.bn_almost_mont_sqr bn_inst areduction
false
EverCrypt.Hash.fsti
EverCrypt.Hash.invariant
val invariant : s: EverCrypt.Hash.state a -> m: FStar.Monotonic.HyperStack.mem -> Prims.logical
let invariant (#a:alg) (s: state a) (m: HS.mem) = B.live m s /\ M.(loc_disjoint (loc_addr_of_buffer s) (footprint_s (B.deref m s))) /\ invariant_s (B.get m s 0) m
{ "file_name": "providers/evercrypt/EverCrypt.Hash.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 120, "start_col": 0, "start_line": 117 }
module EverCrypt.Hash open EverCrypt.Helpers open FStar.HyperStack.ST open FStar.Integers open Spec.Hash.Definitions open Hacl.Hash.Definitions #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" /// Algorithmic agility for hash specifications. We reuse the agile /// specifications from HACL*'s specs/ directory. /// SUPPORTED ALGORITHMS see e.g. https://en.wikipedia.org/wiki/SHA-1 /// for a global comparison and lengths /// /// * We support all variants of SHA2. /// * MD5 and SHA1 are still required by TLS 1.2, included for legacy /// purpose only /// * SHA3 will be provided by HACL* /// /// ``hash_alg``, from Spec.Hash.Definitions, lists all supported algorithms unfold let alg = fixed_len_alg /// TODO: move this one to Hacl.Hash.Definitions val string_of_alg: alg -> C.String.t /// kept only for functional backward compatibility, never assumed to be secure type broken_alg = a:alg {a = MD5 \/ a = SHA1} /// HMAC/HKDF ALGORITHMS; we make security assumptions only for constructions /// based on those. type alg13 = a:alg { a=SHA2_256 \/ a=SHA2_384 \/ a=SHA2_512 } /// No pattern (would fire too often)! let uint32_fits_maxLength (a: alg) (x: UInt32.t): Lemma (requires True) (ensures UInt32.v x `less_than_max_input_length` a) = assert_norm (pow2 32 < pow2 61); assert_norm (pow2 61 < pow2 125) /// To specify their low-level incremental computations, we assume /// Merkle-Damgard/sponge-like algorithms: /// /// The hash state is kept in an accumulator, with /// - an initial value /// - an update function, adding a block of bytes; /// - an extract (also: "finish") function, returning a hash tag. /// /// Before hashing, some algorithm-specific padding and length encoding is /// appended to the input bytestring. /// /// This is not a general-purpose incremental specification, which would support /// adding text fragments of arbitrary lengths (for that, see /// EverCrypt.Hash.Incremental). /// Stateful interface implementing the agile specifications. module HS = FStar.HyperStack module B = LowStar.Buffer module M = LowStar.Modifies module G = FStar.Ghost open LowStar.BufferOps /// do not use as argument of ghost functions type e_alg = G.erased alg [@CAbstractStruct] val state_s: alg -> Type0 // pointer to abstract implementation state let state alg = B.pointer (state_s alg) // abstract freeable (deep) predicate; only needed for create/free pairs inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0 inline_for_extraction noextract let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p) // NS: note that the state is the first argument to the invariant so that we can // do partial applications in pre- and post-conditions val footprint_s: #a:alg -> state_s a -> GTot M.loc let footprint (#a:alg) (s: state a) (m: HS.mem) = M.(loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s))) // TR: the following pattern is necessary because, if we generically // add such a pattern directly on `loc_includes_union_l`, then // verification will blowup whenever both sides of `loc_includes` are // `loc_union`s. We would like to break all unions on the // right-hand-side of `loc_includes` first, using // `loc_includes_union_r`. Here the pattern is on `footprint_s`, // because we already expose the fact that `footprint` is a // `loc_union`. (In other words, the pattern should be on every // smallest location that is not exposed to be a `loc_union`.) let loc_includes_union_l_footprint_s (l1 l2: M.loc) (#a: alg) (s: state_s a) : Lemma (requires ( M.loc_includes l1 (footprint_s s) \/ M.loc_includes l2 (footprint_s s) )) (ensures (M.loc_includes (M.loc_union l1 l2) (footprint_s s))) [SMTPat (M.loc_includes (M.loc_union l1 l2) (footprint_s s))] = M.loc_includes_union_l l1 l2 (footprint_s s) inline_for_extraction noextract val invariant_s: (#a:alg) -> state_s a -> HS.mem -> Type0
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Incremental.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.Helpers.fsti.checked", "C.String.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.Hash.fsti" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": false, "full_module": "C.Failure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "EverCrypt.AutoConfig2", "short_module": "AC" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: EverCrypt.Hash.state a -> m: FStar.Monotonic.HyperStack.mem -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "EverCrypt.Hash.alg", "EverCrypt.Hash.state", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "LowStar.Monotonic.Buffer.live", "EverCrypt.Hash.state_s", "LowStar.Buffer.trivial_preorder", "LowStar.Monotonic.Buffer.loc_disjoint", "LowStar.Monotonic.Buffer.loc_addr_of_buffer", "EverCrypt.Hash.footprint_s", "LowStar.Monotonic.Buffer.deref", "EverCrypt.Hash.invariant_s", "LowStar.Monotonic.Buffer.get", "Prims.logical" ]
[]
false
false
false
false
true
let invariant (#a: alg) (s: state a) (m: HS.mem) =
B.live m s /\ M.(loc_disjoint (loc_addr_of_buffer s) (footprint_s (B.deref m s))) /\ invariant_s (B.get m s 0) m
false
Hacl.Bignum256.fst
Hacl.Bignum256.amont_mul
val amont_mul:AM.bn_almost_mont_mul_st t_limbs n_limbs
val amont_mul:AM.bn_almost_mont_mul_st t_limbs n_limbs
let amont_mul: AM.bn_almost_mont_mul_st t_limbs n_limbs = AM.bn_almost_mont_mul bn_inst areduction
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 42, "end_line": 90, "start_col": 0, "start_line": 89 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs let mul (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a = BN.bn_mul n_limbs n_limbs a let sqr (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_sqr_st t_limbs n_limbs a = BN.bn_sqr n_limbs a //BN.bn_mul n_limbs n_limbs a a inline_for_extraction noextract instance bn_inst: BN.bn t_limbs = { BN.len = n_limbs; BN.add; BN.sub; BN.add_mod_n = add_mod; BN.sub_mod_n = sub_mod; BN.mul; BN.sqr } [@CInline] let mont_check: BM.bn_check_modulus_st t_limbs n_limbs = BM.bn_check_modulus [@CInline] let precompr2: BM.bn_precomp_r2_mod_n_st t_limbs n_limbs = BM.bn_precomp_r2_mod_n bn_inst [@CInline] let reduction: BM.bn_mont_reduction_st t_limbs n_limbs = BM.bn_mont_reduction bn_inst [@CInline] let to: BM.bn_to_mont_st t_limbs n_limbs = BM.bn_to_mont bn_inst reduction [@CInline] let from: BM.bn_from_mont_st t_limbs n_limbs = BM.bn_from_mont bn_inst reduction // [@CInline] // let mont_mul: BM.bn_mont_mul_st t_limbs n_limbs = // BM.bn_mont_mul bn_inst reduction // [@CInline] // let mont_sqr: BM.bn_mont_sqr_st t_limbs n_limbs = // BM.bn_mont_sqr bn_inst reduction // inline_for_extraction noextract // instance mont_inst: BM.mont t_limbs = { // BM.bn = bn_inst; // BM.mont_check; // BM.precomp = precompr2; // BM.reduction; // BM.to; // BM.from; // BM.mul = mont_mul; // BM.sqr = mont_sqr; // } [@CInline] let areduction: AM.bn_almost_mont_reduction_st t_limbs n_limbs = AM.bn_almost_mont_reduction bn_inst
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.AlmostMontgomery.bn_almost_mont_mul_st Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.AlmostMontgomery.bn_almost_mont_mul", "Hacl.Bignum256.t_limbs", "Hacl.Bignum256.bn_inst", "Hacl.Bignum256.areduction" ]
[]
false
false
false
true
false
let amont_mul:AM.bn_almost_mont_mul_st t_limbs n_limbs =
AM.bn_almost_mont_mul bn_inst areduction
false
EverCrypt.Hash.fsti
EverCrypt.Hash.uint32_fits_maxLength
val uint32_fits_maxLength (a: alg) (x: UInt32.t) : Lemma (requires True) (ensures (UInt32.v x) `less_than_max_input_length` a)
val uint32_fits_maxLength (a: alg) (x: UInt32.t) : Lemma (requires True) (ensures (UInt32.v x) `less_than_max_input_length` a)
let uint32_fits_maxLength (a: alg) (x: UInt32.t): Lemma (requires True) (ensures UInt32.v x `less_than_max_input_length` a) = assert_norm (pow2 32 < pow2 61); assert_norm (pow2 61 < pow2 125)
{ "file_name": "providers/evercrypt/EverCrypt.Hash.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 34, "end_line": 42, "start_col": 0, "start_line": 37 }
module EverCrypt.Hash open EverCrypt.Helpers open FStar.HyperStack.ST open FStar.Integers open Spec.Hash.Definitions open Hacl.Hash.Definitions #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" /// Algorithmic agility for hash specifications. We reuse the agile /// specifications from HACL*'s specs/ directory. /// SUPPORTED ALGORITHMS see e.g. https://en.wikipedia.org/wiki/SHA-1 /// for a global comparison and lengths /// /// * We support all variants of SHA2. /// * MD5 and SHA1 are still required by TLS 1.2, included for legacy /// purpose only /// * SHA3 will be provided by HACL* /// /// ``hash_alg``, from Spec.Hash.Definitions, lists all supported algorithms unfold let alg = fixed_len_alg /// TODO: move this one to Hacl.Hash.Definitions val string_of_alg: alg -> C.String.t /// kept only for functional backward compatibility, never assumed to be secure type broken_alg = a:alg {a = MD5 \/ a = SHA1} /// HMAC/HKDF ALGORITHMS; we make security assumptions only for constructions /// based on those. type alg13 = a:alg { a=SHA2_256 \/ a=SHA2_384 \/ a=SHA2_512 }
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Incremental.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.Helpers.fsti.checked", "C.String.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.Hash.fsti" }
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": false, "full_module": "C.Failure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "EverCrypt.AutoConfig2", "short_module": "AC" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: EverCrypt.Hash.alg -> x: FStar.UInt32.t -> FStar.Pervasives.Lemma (ensures Spec.Hash.Definitions.less_than_max_input_length (FStar.UInt32.v x) a)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "EverCrypt.Hash.alg", "FStar.UInt32.t", "FStar.Pervasives.assert_norm", "Prims.b2t", "FStar.Integers.op_Less", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "Prims.pow2", "Prims.unit", "Prims.l_True", "Prims.squash", "Spec.Hash.Definitions.less_than_max_input_length", "FStar.UInt32.v", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let uint32_fits_maxLength (a: alg) (x: UInt32.t) : Lemma (requires True) (ensures (UInt32.v x) `less_than_max_input_length` a) =
assert_norm (pow2 32 < pow2 61); assert_norm (pow2 61 < pow2 125)
false
Hacl.Bignum256.fst
Hacl.Bignum256.bn_slow_precomp
val bn_slow_precomp:BR.bn_mod_slow_precomp_st t_limbs n_limbs
val bn_slow_precomp:BR.bn_mod_slow_precomp_st t_limbs n_limbs
let bn_slow_precomp : BR.bn_mod_slow_precomp_st t_limbs n_limbs = BR.bn_mod_slow_precomp almost_mont_inst
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 41, "end_line": 110, "start_col": 0, "start_line": 109 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs let mul (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a = BN.bn_mul n_limbs n_limbs a let sqr (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_sqr_st t_limbs n_limbs a = BN.bn_sqr n_limbs a //BN.bn_mul n_limbs n_limbs a a inline_for_extraction noextract instance bn_inst: BN.bn t_limbs = { BN.len = n_limbs; BN.add; BN.sub; BN.add_mod_n = add_mod; BN.sub_mod_n = sub_mod; BN.mul; BN.sqr } [@CInline] let mont_check: BM.bn_check_modulus_st t_limbs n_limbs = BM.bn_check_modulus [@CInline] let precompr2: BM.bn_precomp_r2_mod_n_st t_limbs n_limbs = BM.bn_precomp_r2_mod_n bn_inst [@CInline] let reduction: BM.bn_mont_reduction_st t_limbs n_limbs = BM.bn_mont_reduction bn_inst [@CInline] let to: BM.bn_to_mont_st t_limbs n_limbs = BM.bn_to_mont bn_inst reduction [@CInline] let from: BM.bn_from_mont_st t_limbs n_limbs = BM.bn_from_mont bn_inst reduction // [@CInline] // let mont_mul: BM.bn_mont_mul_st t_limbs n_limbs = // BM.bn_mont_mul bn_inst reduction // [@CInline] // let mont_sqr: BM.bn_mont_sqr_st t_limbs n_limbs = // BM.bn_mont_sqr bn_inst reduction // inline_for_extraction noextract // instance mont_inst: BM.mont t_limbs = { // BM.bn = bn_inst; // BM.mont_check; // BM.precomp = precompr2; // BM.reduction; // BM.to; // BM.from; // BM.mul = mont_mul; // BM.sqr = mont_sqr; // } [@CInline] let areduction: AM.bn_almost_mont_reduction_st t_limbs n_limbs = AM.bn_almost_mont_reduction bn_inst [@CInline] let amont_mul: AM.bn_almost_mont_mul_st t_limbs n_limbs = AM.bn_almost_mont_mul bn_inst areduction [@CInline] let amont_sqr: AM.bn_almost_mont_sqr_st t_limbs n_limbs = AM.bn_almost_mont_sqr bn_inst areduction inline_for_extraction noextract instance almost_mont_inst: AM.almost_mont t_limbs = { AM.bn = bn_inst; AM.mont_check; AM.precomp = precompr2; AM.reduction = areduction; AM.to; AM.from; AM.mul = amont_mul; AM.sqr = amont_sqr; }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.ModReduction.bn_mod_slow_precomp_st Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.ModReduction.bn_mod_slow_precomp", "Hacl.Bignum256.t_limbs", "Hacl.Bignum256.almost_mont_inst" ]
[]
false
false
false
true
false
let bn_slow_precomp:BR.bn_mod_slow_precomp_st t_limbs n_limbs =
BR.bn_mod_slow_precomp almost_mont_inst
false
Hacl.Bignum256.fst
Hacl.Bignum256.exp_check
val exp_check:BE.bn_check_mod_exp_st t_limbs n_limbs
val exp_check:BE.bn_check_mod_exp_st t_limbs n_limbs
let exp_check: BE.bn_check_mod_exp_st t_limbs n_limbs = BE.bn_check_mod_exp n_limbs
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 116, "start_col": 0, "start_line": 115 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs let mul (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a = BN.bn_mul n_limbs n_limbs a let sqr (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_sqr_st t_limbs n_limbs a = BN.bn_sqr n_limbs a //BN.bn_mul n_limbs n_limbs a a inline_for_extraction noextract instance bn_inst: BN.bn t_limbs = { BN.len = n_limbs; BN.add; BN.sub; BN.add_mod_n = add_mod; BN.sub_mod_n = sub_mod; BN.mul; BN.sqr } [@CInline] let mont_check: BM.bn_check_modulus_st t_limbs n_limbs = BM.bn_check_modulus [@CInline] let precompr2: BM.bn_precomp_r2_mod_n_st t_limbs n_limbs = BM.bn_precomp_r2_mod_n bn_inst [@CInline] let reduction: BM.bn_mont_reduction_st t_limbs n_limbs = BM.bn_mont_reduction bn_inst [@CInline] let to: BM.bn_to_mont_st t_limbs n_limbs = BM.bn_to_mont bn_inst reduction [@CInline] let from: BM.bn_from_mont_st t_limbs n_limbs = BM.bn_from_mont bn_inst reduction // [@CInline] // let mont_mul: BM.bn_mont_mul_st t_limbs n_limbs = // BM.bn_mont_mul bn_inst reduction // [@CInline] // let mont_sqr: BM.bn_mont_sqr_st t_limbs n_limbs = // BM.bn_mont_sqr bn_inst reduction // inline_for_extraction noextract // instance mont_inst: BM.mont t_limbs = { // BM.bn = bn_inst; // BM.mont_check; // BM.precomp = precompr2; // BM.reduction; // BM.to; // BM.from; // BM.mul = mont_mul; // BM.sqr = mont_sqr; // } [@CInline] let areduction: AM.bn_almost_mont_reduction_st t_limbs n_limbs = AM.bn_almost_mont_reduction bn_inst [@CInline] let amont_mul: AM.bn_almost_mont_mul_st t_limbs n_limbs = AM.bn_almost_mont_mul bn_inst areduction [@CInline] let amont_sqr: AM.bn_almost_mont_sqr_st t_limbs n_limbs = AM.bn_almost_mont_sqr bn_inst areduction inline_for_extraction noextract instance almost_mont_inst: AM.almost_mont t_limbs = { AM.bn = bn_inst; AM.mont_check; AM.precomp = precompr2; AM.reduction = areduction; AM.to; AM.from; AM.mul = amont_mul; AM.sqr = amont_sqr; } [@CInline] let bn_slow_precomp : BR.bn_mod_slow_precomp_st t_limbs n_limbs = BR.bn_mod_slow_precomp almost_mont_inst let mod n a res = BS.mk_bn_mod_slow_safe n_limbs (BR.mk_bn_mod_slow n_limbs precompr2 bn_slow_precomp) n a res
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.Exponentiation.bn_check_mod_exp_st Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Exponentiation.bn_check_mod_exp", "Hacl.Bignum256.t_limbs", "Hacl.Bignum256.n_limbs" ]
[]
false
false
false
true
false
let exp_check:BE.bn_check_mod_exp_st t_limbs n_limbs =
BE.bn_check_mod_exp n_limbs
false
EverCrypt.Hash.fsti
EverCrypt.Hash.prev_len_of_uint64
val prev_len_of_uint64 (a: _) (prevlen: UInt64.t{UInt64.v prevlen % block_length a = 0}) : Spec.Hash.Incremental.prev_length_t a
val prev_len_of_uint64 (a: _) (prevlen: UInt64.t{UInt64.v prevlen % block_length a = 0}) : Spec.Hash.Incremental.prev_length_t a
let prev_len_of_uint64 a (prevlen: UInt64.t { UInt64.v prevlen % block_length a = 0 }): Spec.Hash.Incremental.prev_length_t a = (if is_keccak a then () else UInt64.v prevlen)
{ "file_name": "providers/evercrypt/EverCrypt.Hash.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 48, "end_line": 266, "start_col": 0, "start_line": 265 }
module EverCrypt.Hash open EverCrypt.Helpers open FStar.HyperStack.ST open FStar.Integers open Spec.Hash.Definitions open Hacl.Hash.Definitions #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" /// Algorithmic agility for hash specifications. We reuse the agile /// specifications from HACL*'s specs/ directory. /// SUPPORTED ALGORITHMS see e.g. https://en.wikipedia.org/wiki/SHA-1 /// for a global comparison and lengths /// /// * We support all variants of SHA2. /// * MD5 and SHA1 are still required by TLS 1.2, included for legacy /// purpose only /// * SHA3 will be provided by HACL* /// /// ``hash_alg``, from Spec.Hash.Definitions, lists all supported algorithms unfold let alg = fixed_len_alg /// TODO: move this one to Hacl.Hash.Definitions val string_of_alg: alg -> C.String.t /// kept only for functional backward compatibility, never assumed to be secure type broken_alg = a:alg {a = MD5 \/ a = SHA1} /// HMAC/HKDF ALGORITHMS; we make security assumptions only for constructions /// based on those. type alg13 = a:alg { a=SHA2_256 \/ a=SHA2_384 \/ a=SHA2_512 } /// No pattern (would fire too often)! let uint32_fits_maxLength (a: alg) (x: UInt32.t): Lemma (requires True) (ensures UInt32.v x `less_than_max_input_length` a) = assert_norm (pow2 32 < pow2 61); assert_norm (pow2 61 < pow2 125) /// To specify their low-level incremental computations, we assume /// Merkle-Damgard/sponge-like algorithms: /// /// The hash state is kept in an accumulator, with /// - an initial value /// - an update function, adding a block of bytes; /// - an extract (also: "finish") function, returning a hash tag. /// /// Before hashing, some algorithm-specific padding and length encoding is /// appended to the input bytestring. /// /// This is not a general-purpose incremental specification, which would support /// adding text fragments of arbitrary lengths (for that, see /// EverCrypt.Hash.Incremental). /// Stateful interface implementing the agile specifications. module HS = FStar.HyperStack module B = LowStar.Buffer module M = LowStar.Modifies module G = FStar.Ghost open LowStar.BufferOps /// do not use as argument of ghost functions type e_alg = G.erased alg [@CAbstractStruct] val state_s: alg -> Type0 // pointer to abstract implementation state let state alg = B.pointer (state_s alg) // abstract freeable (deep) predicate; only needed for create/free pairs inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0 inline_for_extraction noextract let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p) // NS: note that the state is the first argument to the invariant so that we can // do partial applications in pre- and post-conditions val footprint_s: #a:alg -> state_s a -> GTot M.loc let footprint (#a:alg) (s: state a) (m: HS.mem) = M.(loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s))) // TR: the following pattern is necessary because, if we generically // add such a pattern directly on `loc_includes_union_l`, then // verification will blowup whenever both sides of `loc_includes` are // `loc_union`s. We would like to break all unions on the // right-hand-side of `loc_includes` first, using // `loc_includes_union_r`. Here the pattern is on `footprint_s`, // because we already expose the fact that `footprint` is a // `loc_union`. (In other words, the pattern should be on every // smallest location that is not exposed to be a `loc_union`.) let loc_includes_union_l_footprint_s (l1 l2: M.loc) (#a: alg) (s: state_s a) : Lemma (requires ( M.loc_includes l1 (footprint_s s) \/ M.loc_includes l2 (footprint_s s) )) (ensures (M.loc_includes (M.loc_union l1 l2) (footprint_s s))) [SMTPat (M.loc_includes (M.loc_union l1 l2) (footprint_s s))] = M.loc_includes_union_l l1 l2 (footprint_s s) inline_for_extraction noextract val invariant_s: (#a:alg) -> state_s a -> HS.mem -> Type0 inline_for_extraction noextract let invariant (#a:alg) (s: state a) (m: HS.mem) = B.live m s /\ M.(loc_disjoint (loc_addr_of_buffer s) (footprint_s (B.deref m s))) /\ invariant_s (B.get m s 0) m //18-07-06 as_acc a better name? not really a representation val repr: #a:alg -> s:state a -> h:HS.mem -> GTot (words_state a) val alg_of_state: a:e_alg -> ( let a = G.reveal a in s: state a -> Stack alg (fun h0 -> invariant s h0) (fun h0 a' h1 -> h0 == h1 /\ a' == a)) val fresh_is_disjoint: l1:M.loc -> l2:M.loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (B.fresh_loc l1 h0 h1 /\ l2 `B.loc_in` h0)) (ensures (M.loc_disjoint l1 l2)) // TR: this lemma is necessary to prove that the footprint is disjoint // from any fresh memory location. val invariant_loc_in_footprint (#a: alg) (s: state a) (m: HS.mem) : Lemma (requires (invariant s m)) (ensures (B.loc_in (footprint s m) m)) [SMTPat (invariant s m)] // TR: frame_invariant, just like all lemmas eliminating `modifies` // clauses, should have `modifies_inert` as a precondition instead of // `modifies`, in order to use it in all cases where a modifies clause // is produced but should not be composed with `modifies_trans` for // pattern reasons (e.g. push_frame, pop_frame) // 18-07-12 why not bundling the next two lemmas? val frame_invariant: #a:alg -> l:M.loc -> s:state a -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( invariant s h0 /\ M.loc_disjoint l (footprint s h0) /\ M.modifies l h0 h1)) (ensures ( invariant s h1 /\ repr s h0 == repr s h1)) let frame_invariant_implies_footprint_preservation (#a: alg) (l: M.loc) (s: state a) (h0 h1: HS.mem): Lemma (requires ( invariant s h0 /\ M.loc_disjoint l (footprint s h0) /\ M.modifies l h0 h1)) (ensures ( footprint s h1 == footprint s h0)) = () inline_for_extraction noextract let preserves_freeable #a (s: state a) (h0 h1: HS.mem): Type0 = freeable h0 s ==> freeable h1 s /// This function will generally not extract properly, so it should be used with /// great care. Callers must: /// - run with evercrypt/fst in scope to benefit from the definition of this function /// - know, at call-site, the concrete value of a via suitable usage of inline_for_extraction inline_for_extraction noextract val alloca: a:alg -> StackInline (state a) (requires (fun _ -> True)) (ensures (fun h0 s h1 -> invariant s h1 /\ M.(modifies loc_none h0 h1) /\ B.fresh_loc (footprint s h1) h0 h1 /\ M.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint s h1)))) (** @type: true *) val create_in: a:alg -> r:HS.rid -> ST (state a) (requires (fun _ -> HyperStack.ST.is_eternal_region r)) (ensures (fun h0 s h1 -> invariant s h1 /\ M.(modifies loc_none h0 h1) /\ B.fresh_loc (footprint s h1) h0 h1 /\ M.(loc_includes (loc_region_only true r) (footprint s h1)) /\ freeable h1 s)) (** @type: true *) val create: a:alg -> ST (state a) (requires fun h0 -> True) (ensures fun h0 s h1 -> invariant s h1 /\ M.(modifies loc_none h0 h1) /\ B.fresh_loc (footprint s h1) h0 h1 /\ freeable h1 s) (** @type: true *) val init: #a:e_alg -> ( let a = Ghost.reveal a in s: state a -> Stack unit (requires invariant s) (ensures fun h0 _ h1 -> invariant s h1 /\ repr s h1 == Spec.Agile.Hash.init a /\ M.(modifies (footprint s h0) h0 h1) /\ footprint s h0 == footprint s h1 /\ preserves_freeable s h0 h1)) val update_multi_256: Hacl.Hash.Definitions.update_multi_st (|SHA2_256, ()|) inline_for_extraction noextract val update_multi_224: Hacl.Hash.Definitions.update_multi_st (|SHA2_224, ()|) inline_for_extraction noextract let ev_of_uint64 a (prevlen: UInt64.t { UInt64.v prevlen % block_length a = 0 }): Spec.Hash.Definitions.extra_state a = (if is_blake a then UInt64.v prevlen else ()) /// The ``update_multi`` method // Note that we pass the data length in bytes (rather than blocks). (** @type: true *) val update_multi: #a:e_alg -> ( let a = Ghost.reveal a in s:state a -> prevlen : uint64_t { UInt64.v prevlen % block_length a = 0 } -> blocks:B.buffer Lib.IntTypes.uint8 { B.length blocks % block_length a = 0 } -> len: UInt32.t { v len = B.length blocks } -> Stack unit (requires fun h0 -> invariant s h0 /\ B.live h0 blocks /\ Spec.Agile.Hash.update_multi_pre a (ev_of_uint64 a prevlen) (B.as_seq h0 blocks) /\ M.(loc_disjoint (footprint s h0) (loc_buffer blocks))) (ensures fun h0 _ h1 -> M.(modifies (footprint s h0) h0 h1) /\ footprint s h0 == footprint s h1 /\ invariant s h1 /\ repr s h1 == Spec.Agile.Hash.update_multi a (repr s h0) (ev_of_uint64 a prevlen) (B.as_seq h0 blocks) /\ preserves_freeable s h0 h1))
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Incremental.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.Helpers.fsti.checked", "C.String.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.Hash.fsti" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": false, "full_module": "C.Failure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "EverCrypt.AutoConfig2", "short_module": "AC" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Hash.Definitions.hash_alg -> prevlen: FStar.UInt64.t{FStar.UInt64.v prevlen % Spec.Hash.Definitions.block_length a = 0} -> Spec.Hash.Incremental.Definitions.prev_length_t a
Prims.Tot
[ "total" ]
[]
[ "Spec.Hash.Definitions.hash_alg", "FStar.UInt64.t", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.Integers.op_Percent", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "FStar.UInt64.v", "Spec.Hash.Definitions.block_length", "Spec.Hash.Definitions.is_keccak", "Prims.bool", "Spec.Hash.Incremental.Definitions.prev_length_t" ]
[]
false
false
false
false
false
let prev_len_of_uint64 a (prevlen: UInt64.t{UInt64.v prevlen % block_length a = 0}) : Spec.Hash.Incremental.prev_length_t a =
(if is_keccak a then () else UInt64.v prevlen)
false
EverCrypt.Hash.fsti
EverCrypt.Hash.ev_of_uint64
val ev_of_uint64 (a: _) (prevlen: UInt64.t{UInt64.v prevlen % block_length a = 0}) : Spec.Hash.Definitions.extra_state a
val ev_of_uint64 (a: _) (prevlen: UInt64.t{UInt64.v prevlen % block_length a = 0}) : Spec.Hash.Definitions.extra_state a
let ev_of_uint64 a (prevlen: UInt64.t { UInt64.v prevlen % block_length a = 0 }): Spec.Hash.Definitions.extra_state a = (if is_blake a then UInt64.v prevlen else ())
{ "file_name": "providers/evercrypt/EverCrypt.Hash.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 47, "end_line": 237, "start_col": 0, "start_line": 236 }
module EverCrypt.Hash open EverCrypt.Helpers open FStar.HyperStack.ST open FStar.Integers open Spec.Hash.Definitions open Hacl.Hash.Definitions #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" /// Algorithmic agility for hash specifications. We reuse the agile /// specifications from HACL*'s specs/ directory. /// SUPPORTED ALGORITHMS see e.g. https://en.wikipedia.org/wiki/SHA-1 /// for a global comparison and lengths /// /// * We support all variants of SHA2. /// * MD5 and SHA1 are still required by TLS 1.2, included for legacy /// purpose only /// * SHA3 will be provided by HACL* /// /// ``hash_alg``, from Spec.Hash.Definitions, lists all supported algorithms unfold let alg = fixed_len_alg /// TODO: move this one to Hacl.Hash.Definitions val string_of_alg: alg -> C.String.t /// kept only for functional backward compatibility, never assumed to be secure type broken_alg = a:alg {a = MD5 \/ a = SHA1} /// HMAC/HKDF ALGORITHMS; we make security assumptions only for constructions /// based on those. type alg13 = a:alg { a=SHA2_256 \/ a=SHA2_384 \/ a=SHA2_512 } /// No pattern (would fire too often)! let uint32_fits_maxLength (a: alg) (x: UInt32.t): Lemma (requires True) (ensures UInt32.v x `less_than_max_input_length` a) = assert_norm (pow2 32 < pow2 61); assert_norm (pow2 61 < pow2 125) /// To specify their low-level incremental computations, we assume /// Merkle-Damgard/sponge-like algorithms: /// /// The hash state is kept in an accumulator, with /// - an initial value /// - an update function, adding a block of bytes; /// - an extract (also: "finish") function, returning a hash tag. /// /// Before hashing, some algorithm-specific padding and length encoding is /// appended to the input bytestring. /// /// This is not a general-purpose incremental specification, which would support /// adding text fragments of arbitrary lengths (for that, see /// EverCrypt.Hash.Incremental). /// Stateful interface implementing the agile specifications. module HS = FStar.HyperStack module B = LowStar.Buffer module M = LowStar.Modifies module G = FStar.Ghost open LowStar.BufferOps /// do not use as argument of ghost functions type e_alg = G.erased alg [@CAbstractStruct] val state_s: alg -> Type0 // pointer to abstract implementation state let state alg = B.pointer (state_s alg) // abstract freeable (deep) predicate; only needed for create/free pairs inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0 inline_for_extraction noextract let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p) // NS: note that the state is the first argument to the invariant so that we can // do partial applications in pre- and post-conditions val footprint_s: #a:alg -> state_s a -> GTot M.loc let footprint (#a:alg) (s: state a) (m: HS.mem) = M.(loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s))) // TR: the following pattern is necessary because, if we generically // add such a pattern directly on `loc_includes_union_l`, then // verification will blowup whenever both sides of `loc_includes` are // `loc_union`s. We would like to break all unions on the // right-hand-side of `loc_includes` first, using // `loc_includes_union_r`. Here the pattern is on `footprint_s`, // because we already expose the fact that `footprint` is a // `loc_union`. (In other words, the pattern should be on every // smallest location that is not exposed to be a `loc_union`.) let loc_includes_union_l_footprint_s (l1 l2: M.loc) (#a: alg) (s: state_s a) : Lemma (requires ( M.loc_includes l1 (footprint_s s) \/ M.loc_includes l2 (footprint_s s) )) (ensures (M.loc_includes (M.loc_union l1 l2) (footprint_s s))) [SMTPat (M.loc_includes (M.loc_union l1 l2) (footprint_s s))] = M.loc_includes_union_l l1 l2 (footprint_s s) inline_for_extraction noextract val invariant_s: (#a:alg) -> state_s a -> HS.mem -> Type0 inline_for_extraction noextract let invariant (#a:alg) (s: state a) (m: HS.mem) = B.live m s /\ M.(loc_disjoint (loc_addr_of_buffer s) (footprint_s (B.deref m s))) /\ invariant_s (B.get m s 0) m //18-07-06 as_acc a better name? not really a representation val repr: #a:alg -> s:state a -> h:HS.mem -> GTot (words_state a) val alg_of_state: a:e_alg -> ( let a = G.reveal a in s: state a -> Stack alg (fun h0 -> invariant s h0) (fun h0 a' h1 -> h0 == h1 /\ a' == a)) val fresh_is_disjoint: l1:M.loc -> l2:M.loc -> h0:HS.mem -> h1:HS.mem -> Lemma (requires (B.fresh_loc l1 h0 h1 /\ l2 `B.loc_in` h0)) (ensures (M.loc_disjoint l1 l2)) // TR: this lemma is necessary to prove that the footprint is disjoint // from any fresh memory location. val invariant_loc_in_footprint (#a: alg) (s: state a) (m: HS.mem) : Lemma (requires (invariant s m)) (ensures (B.loc_in (footprint s m) m)) [SMTPat (invariant s m)] // TR: frame_invariant, just like all lemmas eliminating `modifies` // clauses, should have `modifies_inert` as a precondition instead of // `modifies`, in order to use it in all cases where a modifies clause // is produced but should not be composed with `modifies_trans` for // pattern reasons (e.g. push_frame, pop_frame) // 18-07-12 why not bundling the next two lemmas? val frame_invariant: #a:alg -> l:M.loc -> s:state a -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( invariant s h0 /\ M.loc_disjoint l (footprint s h0) /\ M.modifies l h0 h1)) (ensures ( invariant s h1 /\ repr s h0 == repr s h1)) let frame_invariant_implies_footprint_preservation (#a: alg) (l: M.loc) (s: state a) (h0 h1: HS.mem): Lemma (requires ( invariant s h0 /\ M.loc_disjoint l (footprint s h0) /\ M.modifies l h0 h1)) (ensures ( footprint s h1 == footprint s h0)) = () inline_for_extraction noextract let preserves_freeable #a (s: state a) (h0 h1: HS.mem): Type0 = freeable h0 s ==> freeable h1 s /// This function will generally not extract properly, so it should be used with /// great care. Callers must: /// - run with evercrypt/fst in scope to benefit from the definition of this function /// - know, at call-site, the concrete value of a via suitable usage of inline_for_extraction inline_for_extraction noextract val alloca: a:alg -> StackInline (state a) (requires (fun _ -> True)) (ensures (fun h0 s h1 -> invariant s h1 /\ M.(modifies loc_none h0 h1) /\ B.fresh_loc (footprint s h1) h0 h1 /\ M.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint s h1)))) (** @type: true *) val create_in: a:alg -> r:HS.rid -> ST (state a) (requires (fun _ -> HyperStack.ST.is_eternal_region r)) (ensures (fun h0 s h1 -> invariant s h1 /\ M.(modifies loc_none h0 h1) /\ B.fresh_loc (footprint s h1) h0 h1 /\ M.(loc_includes (loc_region_only true r) (footprint s h1)) /\ freeable h1 s)) (** @type: true *) val create: a:alg -> ST (state a) (requires fun h0 -> True) (ensures fun h0 s h1 -> invariant s h1 /\ M.(modifies loc_none h0 h1) /\ B.fresh_loc (footprint s h1) h0 h1 /\ freeable h1 s) (** @type: true *) val init: #a:e_alg -> ( let a = Ghost.reveal a in s: state a -> Stack unit (requires invariant s) (ensures fun h0 _ h1 -> invariant s h1 /\ repr s h1 == Spec.Agile.Hash.init a /\ M.(modifies (footprint s h0) h0 h1) /\ footprint s h0 == footprint s h1 /\ preserves_freeable s h0 h1)) val update_multi_256: Hacl.Hash.Definitions.update_multi_st (|SHA2_256, ()|) inline_for_extraction noextract val update_multi_224: Hacl.Hash.Definitions.update_multi_st (|SHA2_224, ()|)
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Incremental.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Hash.Definitions.fst.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.Helpers.fsti.checked", "C.String.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.Hash.fsti" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "LowStar.Modifies", "short_module": "M" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": false, "full_module": "C.Failure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "EverCrypt.AutoConfig2", "short_module": "AC" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.ImmutableBuffer", "short_module": "IB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt.Helpers", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Hash.Definitions.hash_alg -> prevlen: FStar.UInt64.t{FStar.UInt64.v prevlen % Spec.Hash.Definitions.block_length a = 0} -> Spec.Hash.Definitions.extra_state a
Prims.Tot
[ "total" ]
[]
[ "Spec.Hash.Definitions.hash_alg", "FStar.UInt64.t", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.Integers.op_Percent", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "FStar.UInt64.v", "Spec.Hash.Definitions.block_length", "Spec.Hash.Definitions.is_blake", "Prims.bool", "Spec.Hash.Definitions.extra_state" ]
[]
false
false
false
false
false
let ev_of_uint64 a (prevlen: UInt64.t{UInt64.v prevlen % block_length a = 0}) : Spec.Hash.Definitions.extra_state a =
(if is_blake a then UInt64.v prevlen)
false
Hacl.Bignum256.fst
Hacl.Bignum256.mod_exp_vartime
val mod_exp_vartime: BS.bn_mod_exp_safe_st t_limbs n_limbs
val mod_exp_vartime: BS.bn_mod_exp_safe_st t_limbs n_limbs
let mod_exp_vartime = BS.mk_bn_mod_exp_safe n_limbs exp_check exp_vartime
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 73, "end_line": 138, "start_col": 0, "start_line": 138 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs let mul (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a = BN.bn_mul n_limbs n_limbs a let sqr (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_sqr_st t_limbs n_limbs a = BN.bn_sqr n_limbs a //BN.bn_mul n_limbs n_limbs a a inline_for_extraction noextract instance bn_inst: BN.bn t_limbs = { BN.len = n_limbs; BN.add; BN.sub; BN.add_mod_n = add_mod; BN.sub_mod_n = sub_mod; BN.mul; BN.sqr } [@CInline] let mont_check: BM.bn_check_modulus_st t_limbs n_limbs = BM.bn_check_modulus [@CInline] let precompr2: BM.bn_precomp_r2_mod_n_st t_limbs n_limbs = BM.bn_precomp_r2_mod_n bn_inst [@CInline] let reduction: BM.bn_mont_reduction_st t_limbs n_limbs = BM.bn_mont_reduction bn_inst [@CInline] let to: BM.bn_to_mont_st t_limbs n_limbs = BM.bn_to_mont bn_inst reduction [@CInline] let from: BM.bn_from_mont_st t_limbs n_limbs = BM.bn_from_mont bn_inst reduction // [@CInline] // let mont_mul: BM.bn_mont_mul_st t_limbs n_limbs = // BM.bn_mont_mul bn_inst reduction // [@CInline] // let mont_sqr: BM.bn_mont_sqr_st t_limbs n_limbs = // BM.bn_mont_sqr bn_inst reduction // inline_for_extraction noextract // instance mont_inst: BM.mont t_limbs = { // BM.bn = bn_inst; // BM.mont_check; // BM.precomp = precompr2; // BM.reduction; // BM.to; // BM.from; // BM.mul = mont_mul; // BM.sqr = mont_sqr; // } [@CInline] let areduction: AM.bn_almost_mont_reduction_st t_limbs n_limbs = AM.bn_almost_mont_reduction bn_inst [@CInline] let amont_mul: AM.bn_almost_mont_mul_st t_limbs n_limbs = AM.bn_almost_mont_mul bn_inst areduction [@CInline] let amont_sqr: AM.bn_almost_mont_sqr_st t_limbs n_limbs = AM.bn_almost_mont_sqr bn_inst areduction inline_for_extraction noextract instance almost_mont_inst: AM.almost_mont t_limbs = { AM.bn = bn_inst; AM.mont_check; AM.precomp = precompr2; AM.reduction = areduction; AM.to; AM.from; AM.mul = amont_mul; AM.sqr = amont_sqr; } [@CInline] let bn_slow_precomp : BR.bn_mod_slow_precomp_st t_limbs n_limbs = BR.bn_mod_slow_precomp almost_mont_inst let mod n a res = BS.mk_bn_mod_slow_safe n_limbs (BR.mk_bn_mod_slow n_limbs precompr2 bn_slow_precomp) n a res let exp_check: BE.bn_check_mod_exp_st t_limbs n_limbs = BE.bn_check_mod_exp n_limbs [@CInline] let exp_vartime_precomp: BE.bn_mod_exp_precomp_st t_limbs n_limbs = BE.bn_mod_exp_vartime_precomp n_limbs (BE.bn_mod_exp_amm_bm_vartime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_vartime_precomp almost_mont_inst 4ul) [@CInline] let exp_consttime_precomp: BE.bn_mod_exp_precomp_st t_limbs n_limbs = BE.bn_mod_exp_consttime_precomp n_limbs (BE.bn_mod_exp_amm_bm_consttime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_consttime_precomp almost_mont_inst 4ul) [@CInline] let exp_vartime: BE.bn_mod_exp_st t_limbs n_limbs = BE.mk_bn_mod_exp n_limbs precompr2 exp_vartime_precomp [@CInline] let exp_consttime: BE.bn_mod_exp_st t_limbs n_limbs = BE.mk_bn_mod_exp n_limbs precompr2 exp_consttime_precomp
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.SafeAPI.bn_mod_exp_safe_st Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.SafeAPI.mk_bn_mod_exp_safe", "Hacl.Bignum256.t_limbs", "Hacl.Bignum256.n_limbs", "Hacl.Bignum256.exp_check", "Hacl.Bignum256.exp_vartime" ]
[]
false
false
false
true
false
let mod_exp_vartime =
BS.mk_bn_mod_exp_safe n_limbs exp_check exp_vartime
false
Hacl.Bignum256.fst
Hacl.Bignum256.add_mod
val add_mod: BN.bn_add_mod_n_st t_limbs n_limbs
val add_mod: BN.bn_add_mod_n_st t_limbs n_limbs
let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 25, "end_line": 21, "start_col": 0, "start_line": 20 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.bn_add_mod_n_st Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.bn_add_mod_n", "Hacl.Bignum256.t_limbs", "Hacl.Bignum256.n_limbs", "Hacl.Bignum.bn_add_mod_n_st" ]
[]
false
false
false
true
false
let add_mod:BN.bn_add_mod_n_st t_limbs n_limbs =
BN.bn_add_mod_n n_limbs
false
Hacl.Bignum256.fst
Hacl.Bignum256.sub_mod
val sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs
val sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs
let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 25, "end_line": 24, "start_col": 0, "start_line": 23 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.bn_sub_mod_n_st Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.bn_sub_mod_n", "Hacl.Bignum256.t_limbs", "Hacl.Bignum256.n_limbs", "Hacl.Bignum.bn_sub_mod_n_st" ]
[]
false
false
false
true
false
let sub_mod:BN.bn_sub_mod_n_st t_limbs n_limbs =
BN.bn_sub_mod_n n_limbs
false
Hacl.Bignum256.fst
Hacl.Bignum256.exp_vartime
val exp_vartime:BE.bn_mod_exp_st t_limbs n_limbs
val exp_vartime:BE.bn_mod_exp_st t_limbs n_limbs
let exp_vartime: BE.bn_mod_exp_st t_limbs n_limbs = BE.mk_bn_mod_exp n_limbs precompr2 exp_vartime_precomp
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 56, "end_line": 132, "start_col": 0, "start_line": 131 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs let mul (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a = BN.bn_mul n_limbs n_limbs a let sqr (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_sqr_st t_limbs n_limbs a = BN.bn_sqr n_limbs a //BN.bn_mul n_limbs n_limbs a a inline_for_extraction noextract instance bn_inst: BN.bn t_limbs = { BN.len = n_limbs; BN.add; BN.sub; BN.add_mod_n = add_mod; BN.sub_mod_n = sub_mod; BN.mul; BN.sqr } [@CInline] let mont_check: BM.bn_check_modulus_st t_limbs n_limbs = BM.bn_check_modulus [@CInline] let precompr2: BM.bn_precomp_r2_mod_n_st t_limbs n_limbs = BM.bn_precomp_r2_mod_n bn_inst [@CInline] let reduction: BM.bn_mont_reduction_st t_limbs n_limbs = BM.bn_mont_reduction bn_inst [@CInline] let to: BM.bn_to_mont_st t_limbs n_limbs = BM.bn_to_mont bn_inst reduction [@CInline] let from: BM.bn_from_mont_st t_limbs n_limbs = BM.bn_from_mont bn_inst reduction // [@CInline] // let mont_mul: BM.bn_mont_mul_st t_limbs n_limbs = // BM.bn_mont_mul bn_inst reduction // [@CInline] // let mont_sqr: BM.bn_mont_sqr_st t_limbs n_limbs = // BM.bn_mont_sqr bn_inst reduction // inline_for_extraction noextract // instance mont_inst: BM.mont t_limbs = { // BM.bn = bn_inst; // BM.mont_check; // BM.precomp = precompr2; // BM.reduction; // BM.to; // BM.from; // BM.mul = mont_mul; // BM.sqr = mont_sqr; // } [@CInline] let areduction: AM.bn_almost_mont_reduction_st t_limbs n_limbs = AM.bn_almost_mont_reduction bn_inst [@CInline] let amont_mul: AM.bn_almost_mont_mul_st t_limbs n_limbs = AM.bn_almost_mont_mul bn_inst areduction [@CInline] let amont_sqr: AM.bn_almost_mont_sqr_st t_limbs n_limbs = AM.bn_almost_mont_sqr bn_inst areduction inline_for_extraction noextract instance almost_mont_inst: AM.almost_mont t_limbs = { AM.bn = bn_inst; AM.mont_check; AM.precomp = precompr2; AM.reduction = areduction; AM.to; AM.from; AM.mul = amont_mul; AM.sqr = amont_sqr; } [@CInline] let bn_slow_precomp : BR.bn_mod_slow_precomp_st t_limbs n_limbs = BR.bn_mod_slow_precomp almost_mont_inst let mod n a res = BS.mk_bn_mod_slow_safe n_limbs (BR.mk_bn_mod_slow n_limbs precompr2 bn_slow_precomp) n a res let exp_check: BE.bn_check_mod_exp_st t_limbs n_limbs = BE.bn_check_mod_exp n_limbs [@CInline] let exp_vartime_precomp: BE.bn_mod_exp_precomp_st t_limbs n_limbs = BE.bn_mod_exp_vartime_precomp n_limbs (BE.bn_mod_exp_amm_bm_vartime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_vartime_precomp almost_mont_inst 4ul) [@CInline] let exp_consttime_precomp: BE.bn_mod_exp_precomp_st t_limbs n_limbs = BE.bn_mod_exp_consttime_precomp n_limbs (BE.bn_mod_exp_amm_bm_consttime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_consttime_precomp almost_mont_inst 4ul)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.Exponentiation.bn_mod_exp_st Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Exponentiation.mk_bn_mod_exp", "Hacl.Bignum256.t_limbs", "Hacl.Bignum256.n_limbs", "Hacl.Bignum256.precompr2", "Hacl.Bignum256.exp_vartime_precomp" ]
[]
false
false
false
true
false
let exp_vartime:BE.bn_mod_exp_st t_limbs n_limbs =
BE.mk_bn_mod_exp n_limbs precompr2 exp_vartime_precomp
false
Hacl.Bignum256.fst
Hacl.Bignum256.mod_exp_consttime
val mod_exp_consttime: BS.bn_mod_exp_safe_st t_limbs n_limbs
val mod_exp_consttime: BS.bn_mod_exp_safe_st t_limbs n_limbs
let mod_exp_consttime = BS.mk_bn_mod_exp_safe n_limbs exp_check exp_consttime
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 77, "end_line": 140, "start_col": 0, "start_line": 140 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs let mul (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a = BN.bn_mul n_limbs n_limbs a let sqr (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_sqr_st t_limbs n_limbs a = BN.bn_sqr n_limbs a //BN.bn_mul n_limbs n_limbs a a inline_for_extraction noextract instance bn_inst: BN.bn t_limbs = { BN.len = n_limbs; BN.add; BN.sub; BN.add_mod_n = add_mod; BN.sub_mod_n = sub_mod; BN.mul; BN.sqr } [@CInline] let mont_check: BM.bn_check_modulus_st t_limbs n_limbs = BM.bn_check_modulus [@CInline] let precompr2: BM.bn_precomp_r2_mod_n_st t_limbs n_limbs = BM.bn_precomp_r2_mod_n bn_inst [@CInline] let reduction: BM.bn_mont_reduction_st t_limbs n_limbs = BM.bn_mont_reduction bn_inst [@CInline] let to: BM.bn_to_mont_st t_limbs n_limbs = BM.bn_to_mont bn_inst reduction [@CInline] let from: BM.bn_from_mont_st t_limbs n_limbs = BM.bn_from_mont bn_inst reduction // [@CInline] // let mont_mul: BM.bn_mont_mul_st t_limbs n_limbs = // BM.bn_mont_mul bn_inst reduction // [@CInline] // let mont_sqr: BM.bn_mont_sqr_st t_limbs n_limbs = // BM.bn_mont_sqr bn_inst reduction // inline_for_extraction noextract // instance mont_inst: BM.mont t_limbs = { // BM.bn = bn_inst; // BM.mont_check; // BM.precomp = precompr2; // BM.reduction; // BM.to; // BM.from; // BM.mul = mont_mul; // BM.sqr = mont_sqr; // } [@CInline] let areduction: AM.bn_almost_mont_reduction_st t_limbs n_limbs = AM.bn_almost_mont_reduction bn_inst [@CInline] let amont_mul: AM.bn_almost_mont_mul_st t_limbs n_limbs = AM.bn_almost_mont_mul bn_inst areduction [@CInline] let amont_sqr: AM.bn_almost_mont_sqr_st t_limbs n_limbs = AM.bn_almost_mont_sqr bn_inst areduction inline_for_extraction noextract instance almost_mont_inst: AM.almost_mont t_limbs = { AM.bn = bn_inst; AM.mont_check; AM.precomp = precompr2; AM.reduction = areduction; AM.to; AM.from; AM.mul = amont_mul; AM.sqr = amont_sqr; } [@CInline] let bn_slow_precomp : BR.bn_mod_slow_precomp_st t_limbs n_limbs = BR.bn_mod_slow_precomp almost_mont_inst let mod n a res = BS.mk_bn_mod_slow_safe n_limbs (BR.mk_bn_mod_slow n_limbs precompr2 bn_slow_precomp) n a res let exp_check: BE.bn_check_mod_exp_st t_limbs n_limbs = BE.bn_check_mod_exp n_limbs [@CInline] let exp_vartime_precomp: BE.bn_mod_exp_precomp_st t_limbs n_limbs = BE.bn_mod_exp_vartime_precomp n_limbs (BE.bn_mod_exp_amm_bm_vartime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_vartime_precomp almost_mont_inst 4ul) [@CInline] let exp_consttime_precomp: BE.bn_mod_exp_precomp_st t_limbs n_limbs = BE.bn_mod_exp_consttime_precomp n_limbs (BE.bn_mod_exp_amm_bm_consttime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_consttime_precomp almost_mont_inst 4ul) [@CInline] let exp_vartime: BE.bn_mod_exp_st t_limbs n_limbs = BE.mk_bn_mod_exp n_limbs precompr2 exp_vartime_precomp [@CInline] let exp_consttime: BE.bn_mod_exp_st t_limbs n_limbs = BE.mk_bn_mod_exp n_limbs precompr2 exp_consttime_precomp let mod_exp_vartime = BS.mk_bn_mod_exp_safe n_limbs exp_check exp_vartime
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.SafeAPI.bn_mod_exp_safe_st Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.SafeAPI.mk_bn_mod_exp_safe", "Hacl.Bignum256.t_limbs", "Hacl.Bignum256.n_limbs", "Hacl.Bignum256.exp_check", "Hacl.Bignum256.exp_consttime" ]
[]
false
false
false
true
false
let mod_exp_consttime =
BS.mk_bn_mod_exp_safe n_limbs exp_check exp_consttime
false
Hacl.Bignum256.fst
Hacl.Bignum256.mont_ctx_free
val mont_ctx_free: MA.bn_field_free_st t_limbs
val mont_ctx_free: MA.bn_field_free_st t_limbs
let mont_ctx_free k = MA.bn_field_free k
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 20, "end_line": 148, "start_col": 0, "start_line": 147 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs let mul (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a = BN.bn_mul n_limbs n_limbs a let sqr (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_sqr_st t_limbs n_limbs a = BN.bn_sqr n_limbs a //BN.bn_mul n_limbs n_limbs a a inline_for_extraction noextract instance bn_inst: BN.bn t_limbs = { BN.len = n_limbs; BN.add; BN.sub; BN.add_mod_n = add_mod; BN.sub_mod_n = sub_mod; BN.mul; BN.sqr } [@CInline] let mont_check: BM.bn_check_modulus_st t_limbs n_limbs = BM.bn_check_modulus [@CInline] let precompr2: BM.bn_precomp_r2_mod_n_st t_limbs n_limbs = BM.bn_precomp_r2_mod_n bn_inst [@CInline] let reduction: BM.bn_mont_reduction_st t_limbs n_limbs = BM.bn_mont_reduction bn_inst [@CInline] let to: BM.bn_to_mont_st t_limbs n_limbs = BM.bn_to_mont bn_inst reduction [@CInline] let from: BM.bn_from_mont_st t_limbs n_limbs = BM.bn_from_mont bn_inst reduction // [@CInline] // let mont_mul: BM.bn_mont_mul_st t_limbs n_limbs = // BM.bn_mont_mul bn_inst reduction // [@CInline] // let mont_sqr: BM.bn_mont_sqr_st t_limbs n_limbs = // BM.bn_mont_sqr bn_inst reduction // inline_for_extraction noextract // instance mont_inst: BM.mont t_limbs = { // BM.bn = bn_inst; // BM.mont_check; // BM.precomp = precompr2; // BM.reduction; // BM.to; // BM.from; // BM.mul = mont_mul; // BM.sqr = mont_sqr; // } [@CInline] let areduction: AM.bn_almost_mont_reduction_st t_limbs n_limbs = AM.bn_almost_mont_reduction bn_inst [@CInline] let amont_mul: AM.bn_almost_mont_mul_st t_limbs n_limbs = AM.bn_almost_mont_mul bn_inst areduction [@CInline] let amont_sqr: AM.bn_almost_mont_sqr_st t_limbs n_limbs = AM.bn_almost_mont_sqr bn_inst areduction inline_for_extraction noextract instance almost_mont_inst: AM.almost_mont t_limbs = { AM.bn = bn_inst; AM.mont_check; AM.precomp = precompr2; AM.reduction = areduction; AM.to; AM.from; AM.mul = amont_mul; AM.sqr = amont_sqr; } [@CInline] let bn_slow_precomp : BR.bn_mod_slow_precomp_st t_limbs n_limbs = BR.bn_mod_slow_precomp almost_mont_inst let mod n a res = BS.mk_bn_mod_slow_safe n_limbs (BR.mk_bn_mod_slow n_limbs precompr2 bn_slow_precomp) n a res let exp_check: BE.bn_check_mod_exp_st t_limbs n_limbs = BE.bn_check_mod_exp n_limbs [@CInline] let exp_vartime_precomp: BE.bn_mod_exp_precomp_st t_limbs n_limbs = BE.bn_mod_exp_vartime_precomp n_limbs (BE.bn_mod_exp_amm_bm_vartime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_vartime_precomp almost_mont_inst 4ul) [@CInline] let exp_consttime_precomp: BE.bn_mod_exp_precomp_st t_limbs n_limbs = BE.bn_mod_exp_consttime_precomp n_limbs (BE.bn_mod_exp_amm_bm_consttime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_consttime_precomp almost_mont_inst 4ul) [@CInline] let exp_vartime: BE.bn_mod_exp_st t_limbs n_limbs = BE.mk_bn_mod_exp n_limbs precompr2 exp_vartime_precomp [@CInline] let exp_consttime: BE.bn_mod_exp_st t_limbs n_limbs = BE.mk_bn_mod_exp n_limbs precompr2 exp_consttime_precomp let mod_exp_vartime = BS.mk_bn_mod_exp_safe n_limbs exp_check exp_vartime let mod_exp_consttime = BS.mk_bn_mod_exp_safe n_limbs exp_check exp_consttime let mod_inv_prime_vartime = BS.mk_bn_mod_inv_prime_safe n_limbs exp_vartime let mont_ctx_init r n = MA.bn_field_init n_limbs precompr2 r n
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.MontArithmetic.bn_field_free_st Hacl.Bignum256.t_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.MontArithmetic.pbn_mont_ctx", "Hacl.Bignum256.t_limbs", "Hacl.Bignum.MontArithmetic.bn_field_free", "Prims.unit" ]
[]
false
false
false
true
false
let mont_ctx_free k =
MA.bn_field_free k
false
Hacl.Bignum256.fst
Hacl.Bignum256.mont_ctx_init
val mont_ctx_init: MA.bn_field_init_st t_limbs n_limbs
val mont_ctx_init: MA.bn_field_init_st t_limbs n_limbs
let mont_ctx_init r n = MA.bn_field_init n_limbs precompr2 r n
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 40, "end_line": 145, "start_col": 0, "start_line": 144 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs let mul (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a = BN.bn_mul n_limbs n_limbs a let sqr (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_sqr_st t_limbs n_limbs a = BN.bn_sqr n_limbs a //BN.bn_mul n_limbs n_limbs a a inline_for_extraction noextract instance bn_inst: BN.bn t_limbs = { BN.len = n_limbs; BN.add; BN.sub; BN.add_mod_n = add_mod; BN.sub_mod_n = sub_mod; BN.mul; BN.sqr } [@CInline] let mont_check: BM.bn_check_modulus_st t_limbs n_limbs = BM.bn_check_modulus [@CInline] let precompr2: BM.bn_precomp_r2_mod_n_st t_limbs n_limbs = BM.bn_precomp_r2_mod_n bn_inst [@CInline] let reduction: BM.bn_mont_reduction_st t_limbs n_limbs = BM.bn_mont_reduction bn_inst [@CInline] let to: BM.bn_to_mont_st t_limbs n_limbs = BM.bn_to_mont bn_inst reduction [@CInline] let from: BM.bn_from_mont_st t_limbs n_limbs = BM.bn_from_mont bn_inst reduction // [@CInline] // let mont_mul: BM.bn_mont_mul_st t_limbs n_limbs = // BM.bn_mont_mul bn_inst reduction // [@CInline] // let mont_sqr: BM.bn_mont_sqr_st t_limbs n_limbs = // BM.bn_mont_sqr bn_inst reduction // inline_for_extraction noextract // instance mont_inst: BM.mont t_limbs = { // BM.bn = bn_inst; // BM.mont_check; // BM.precomp = precompr2; // BM.reduction; // BM.to; // BM.from; // BM.mul = mont_mul; // BM.sqr = mont_sqr; // } [@CInline] let areduction: AM.bn_almost_mont_reduction_st t_limbs n_limbs = AM.bn_almost_mont_reduction bn_inst [@CInline] let amont_mul: AM.bn_almost_mont_mul_st t_limbs n_limbs = AM.bn_almost_mont_mul bn_inst areduction [@CInline] let amont_sqr: AM.bn_almost_mont_sqr_st t_limbs n_limbs = AM.bn_almost_mont_sqr bn_inst areduction inline_for_extraction noextract instance almost_mont_inst: AM.almost_mont t_limbs = { AM.bn = bn_inst; AM.mont_check; AM.precomp = precompr2; AM.reduction = areduction; AM.to; AM.from; AM.mul = amont_mul; AM.sqr = amont_sqr; } [@CInline] let bn_slow_precomp : BR.bn_mod_slow_precomp_st t_limbs n_limbs = BR.bn_mod_slow_precomp almost_mont_inst let mod n a res = BS.mk_bn_mod_slow_safe n_limbs (BR.mk_bn_mod_slow n_limbs precompr2 bn_slow_precomp) n a res let exp_check: BE.bn_check_mod_exp_st t_limbs n_limbs = BE.bn_check_mod_exp n_limbs [@CInline] let exp_vartime_precomp: BE.bn_mod_exp_precomp_st t_limbs n_limbs = BE.bn_mod_exp_vartime_precomp n_limbs (BE.bn_mod_exp_amm_bm_vartime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_vartime_precomp almost_mont_inst 4ul) [@CInline] let exp_consttime_precomp: BE.bn_mod_exp_precomp_st t_limbs n_limbs = BE.bn_mod_exp_consttime_precomp n_limbs (BE.bn_mod_exp_amm_bm_consttime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_consttime_precomp almost_mont_inst 4ul) [@CInline] let exp_vartime: BE.bn_mod_exp_st t_limbs n_limbs = BE.mk_bn_mod_exp n_limbs precompr2 exp_vartime_precomp [@CInline] let exp_consttime: BE.bn_mod_exp_st t_limbs n_limbs = BE.mk_bn_mod_exp n_limbs precompr2 exp_consttime_precomp let mod_exp_vartime = BS.mk_bn_mod_exp_safe n_limbs exp_check exp_vartime let mod_exp_consttime = BS.mk_bn_mod_exp_safe n_limbs exp_check exp_consttime let mod_inv_prime_vartime = BS.mk_bn_mod_inv_prime_safe n_limbs exp_vartime
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.MontArithmetic.bn_field_init_st Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs
Prims.Tot
[ "total" ]
[]
[ "FStar.Monotonic.HyperHeap.rid", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum256.t_limbs", "Hacl.Bignum256.n_limbs", "Hacl.Bignum.MontArithmetic.bn_field_init", "Hacl.Bignum256.precompr2", "Hacl.Bignum.MontArithmetic.pbn_mont_ctx" ]
[]
false
false
false
true
false
let mont_ctx_init r n =
MA.bn_field_init n_limbs precompr2 r n
false
Hacl.Bignum256.fst
Hacl.Bignum256.exp_consttime
val exp_consttime:BE.bn_mod_exp_st t_limbs n_limbs
val exp_consttime:BE.bn_mod_exp_st t_limbs n_limbs
let exp_consttime: BE.bn_mod_exp_st t_limbs n_limbs = BE.mk_bn_mod_exp n_limbs precompr2 exp_consttime_precomp
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 58, "end_line": 136, "start_col": 0, "start_line": 135 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs let mul (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a = BN.bn_mul n_limbs n_limbs a let sqr (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_sqr_st t_limbs n_limbs a = BN.bn_sqr n_limbs a //BN.bn_mul n_limbs n_limbs a a inline_for_extraction noextract instance bn_inst: BN.bn t_limbs = { BN.len = n_limbs; BN.add; BN.sub; BN.add_mod_n = add_mod; BN.sub_mod_n = sub_mod; BN.mul; BN.sqr } [@CInline] let mont_check: BM.bn_check_modulus_st t_limbs n_limbs = BM.bn_check_modulus [@CInline] let precompr2: BM.bn_precomp_r2_mod_n_st t_limbs n_limbs = BM.bn_precomp_r2_mod_n bn_inst [@CInline] let reduction: BM.bn_mont_reduction_st t_limbs n_limbs = BM.bn_mont_reduction bn_inst [@CInline] let to: BM.bn_to_mont_st t_limbs n_limbs = BM.bn_to_mont bn_inst reduction [@CInline] let from: BM.bn_from_mont_st t_limbs n_limbs = BM.bn_from_mont bn_inst reduction // [@CInline] // let mont_mul: BM.bn_mont_mul_st t_limbs n_limbs = // BM.bn_mont_mul bn_inst reduction // [@CInline] // let mont_sqr: BM.bn_mont_sqr_st t_limbs n_limbs = // BM.bn_mont_sqr bn_inst reduction // inline_for_extraction noextract // instance mont_inst: BM.mont t_limbs = { // BM.bn = bn_inst; // BM.mont_check; // BM.precomp = precompr2; // BM.reduction; // BM.to; // BM.from; // BM.mul = mont_mul; // BM.sqr = mont_sqr; // } [@CInline] let areduction: AM.bn_almost_mont_reduction_st t_limbs n_limbs = AM.bn_almost_mont_reduction bn_inst [@CInline] let amont_mul: AM.bn_almost_mont_mul_st t_limbs n_limbs = AM.bn_almost_mont_mul bn_inst areduction [@CInline] let amont_sqr: AM.bn_almost_mont_sqr_st t_limbs n_limbs = AM.bn_almost_mont_sqr bn_inst areduction inline_for_extraction noextract instance almost_mont_inst: AM.almost_mont t_limbs = { AM.bn = bn_inst; AM.mont_check; AM.precomp = precompr2; AM.reduction = areduction; AM.to; AM.from; AM.mul = amont_mul; AM.sqr = amont_sqr; } [@CInline] let bn_slow_precomp : BR.bn_mod_slow_precomp_st t_limbs n_limbs = BR.bn_mod_slow_precomp almost_mont_inst let mod n a res = BS.mk_bn_mod_slow_safe n_limbs (BR.mk_bn_mod_slow n_limbs precompr2 bn_slow_precomp) n a res let exp_check: BE.bn_check_mod_exp_st t_limbs n_limbs = BE.bn_check_mod_exp n_limbs [@CInline] let exp_vartime_precomp: BE.bn_mod_exp_precomp_st t_limbs n_limbs = BE.bn_mod_exp_vartime_precomp n_limbs (BE.bn_mod_exp_amm_bm_vartime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_vartime_precomp almost_mont_inst 4ul) [@CInline] let exp_consttime_precomp: BE.bn_mod_exp_precomp_st t_limbs n_limbs = BE.bn_mod_exp_consttime_precomp n_limbs (BE.bn_mod_exp_amm_bm_consttime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_consttime_precomp almost_mont_inst 4ul) [@CInline] let exp_vartime: BE.bn_mod_exp_st t_limbs n_limbs = BE.mk_bn_mod_exp n_limbs precompr2 exp_vartime_precomp
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.Exponentiation.bn_mod_exp_st Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Exponentiation.mk_bn_mod_exp", "Hacl.Bignum256.t_limbs", "Hacl.Bignum256.n_limbs", "Hacl.Bignum256.precompr2", "Hacl.Bignum256.exp_consttime_precomp" ]
[]
false
false
false
true
false
let exp_consttime:BE.bn_mod_exp_st t_limbs n_limbs =
BE.mk_bn_mod_exp n_limbs precompr2 exp_consttime_precomp
false
Hacl.Bignum256.fst
Hacl.Bignum256.mod_inv_prime_vartime
val mod_inv_prime_vartime: BS.bn_mod_inv_prime_safe_st t_limbs n_limbs
val mod_inv_prime_vartime: BS.bn_mod_inv_prime_safe_st t_limbs n_limbs
let mod_inv_prime_vartime = BS.mk_bn_mod_inv_prime_safe n_limbs exp_vartime
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 75, "end_line": 142, "start_col": 0, "start_line": 142 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs let mul (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a = BN.bn_mul n_limbs n_limbs a let sqr (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_sqr_st t_limbs n_limbs a = BN.bn_sqr n_limbs a //BN.bn_mul n_limbs n_limbs a a inline_for_extraction noextract instance bn_inst: BN.bn t_limbs = { BN.len = n_limbs; BN.add; BN.sub; BN.add_mod_n = add_mod; BN.sub_mod_n = sub_mod; BN.mul; BN.sqr } [@CInline] let mont_check: BM.bn_check_modulus_st t_limbs n_limbs = BM.bn_check_modulus [@CInline] let precompr2: BM.bn_precomp_r2_mod_n_st t_limbs n_limbs = BM.bn_precomp_r2_mod_n bn_inst [@CInline] let reduction: BM.bn_mont_reduction_st t_limbs n_limbs = BM.bn_mont_reduction bn_inst [@CInline] let to: BM.bn_to_mont_st t_limbs n_limbs = BM.bn_to_mont bn_inst reduction [@CInline] let from: BM.bn_from_mont_st t_limbs n_limbs = BM.bn_from_mont bn_inst reduction // [@CInline] // let mont_mul: BM.bn_mont_mul_st t_limbs n_limbs = // BM.bn_mont_mul bn_inst reduction // [@CInline] // let mont_sqr: BM.bn_mont_sqr_st t_limbs n_limbs = // BM.bn_mont_sqr bn_inst reduction // inline_for_extraction noextract // instance mont_inst: BM.mont t_limbs = { // BM.bn = bn_inst; // BM.mont_check; // BM.precomp = precompr2; // BM.reduction; // BM.to; // BM.from; // BM.mul = mont_mul; // BM.sqr = mont_sqr; // } [@CInline] let areduction: AM.bn_almost_mont_reduction_st t_limbs n_limbs = AM.bn_almost_mont_reduction bn_inst [@CInline] let amont_mul: AM.bn_almost_mont_mul_st t_limbs n_limbs = AM.bn_almost_mont_mul bn_inst areduction [@CInline] let amont_sqr: AM.bn_almost_mont_sqr_st t_limbs n_limbs = AM.bn_almost_mont_sqr bn_inst areduction inline_for_extraction noextract instance almost_mont_inst: AM.almost_mont t_limbs = { AM.bn = bn_inst; AM.mont_check; AM.precomp = precompr2; AM.reduction = areduction; AM.to; AM.from; AM.mul = amont_mul; AM.sqr = amont_sqr; } [@CInline] let bn_slow_precomp : BR.bn_mod_slow_precomp_st t_limbs n_limbs = BR.bn_mod_slow_precomp almost_mont_inst let mod n a res = BS.mk_bn_mod_slow_safe n_limbs (BR.mk_bn_mod_slow n_limbs precompr2 bn_slow_precomp) n a res let exp_check: BE.bn_check_mod_exp_st t_limbs n_limbs = BE.bn_check_mod_exp n_limbs [@CInline] let exp_vartime_precomp: BE.bn_mod_exp_precomp_st t_limbs n_limbs = BE.bn_mod_exp_vartime_precomp n_limbs (BE.bn_mod_exp_amm_bm_vartime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_vartime_precomp almost_mont_inst 4ul) [@CInline] let exp_consttime_precomp: BE.bn_mod_exp_precomp_st t_limbs n_limbs = BE.bn_mod_exp_consttime_precomp n_limbs (BE.bn_mod_exp_amm_bm_consttime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_consttime_precomp almost_mont_inst 4ul) [@CInline] let exp_vartime: BE.bn_mod_exp_st t_limbs n_limbs = BE.mk_bn_mod_exp n_limbs precompr2 exp_vartime_precomp [@CInline] let exp_consttime: BE.bn_mod_exp_st t_limbs n_limbs = BE.mk_bn_mod_exp n_limbs precompr2 exp_consttime_precomp let mod_exp_vartime = BS.mk_bn_mod_exp_safe n_limbs exp_check exp_vartime let mod_exp_consttime = BS.mk_bn_mod_exp_safe n_limbs exp_check exp_consttime
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.SafeAPI.bn_mod_inv_prime_safe_st Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.SafeAPI.mk_bn_mod_inv_prime_safe", "Hacl.Bignum256.t_limbs", "Hacl.Bignum256.n_limbs", "Hacl.Bignum256.exp_vartime" ]
[]
false
false
false
true
false
let mod_inv_prime_vartime =
BS.mk_bn_mod_inv_prime_safe n_limbs exp_vartime
false
Hacl.Bignum256.fst
Hacl.Bignum256.lt_mask
val lt_mask: BN.bn_lt_mask_st t_limbs n_limbs
val lt_mask: BN.bn_lt_mask_st t_limbs n_limbs
let lt_mask = BN.bn_lt_mask n_limbs
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 35, "end_line": 171, "start_col": 0, "start_line": 171 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs let mul (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a = BN.bn_mul n_limbs n_limbs a let sqr (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_sqr_st t_limbs n_limbs a = BN.bn_sqr n_limbs a //BN.bn_mul n_limbs n_limbs a a inline_for_extraction noextract instance bn_inst: BN.bn t_limbs = { BN.len = n_limbs; BN.add; BN.sub; BN.add_mod_n = add_mod; BN.sub_mod_n = sub_mod; BN.mul; BN.sqr } [@CInline] let mont_check: BM.bn_check_modulus_st t_limbs n_limbs = BM.bn_check_modulus [@CInline] let precompr2: BM.bn_precomp_r2_mod_n_st t_limbs n_limbs = BM.bn_precomp_r2_mod_n bn_inst [@CInline] let reduction: BM.bn_mont_reduction_st t_limbs n_limbs = BM.bn_mont_reduction bn_inst [@CInline] let to: BM.bn_to_mont_st t_limbs n_limbs = BM.bn_to_mont bn_inst reduction [@CInline] let from: BM.bn_from_mont_st t_limbs n_limbs = BM.bn_from_mont bn_inst reduction // [@CInline] // let mont_mul: BM.bn_mont_mul_st t_limbs n_limbs = // BM.bn_mont_mul bn_inst reduction // [@CInline] // let mont_sqr: BM.bn_mont_sqr_st t_limbs n_limbs = // BM.bn_mont_sqr bn_inst reduction // inline_for_extraction noextract // instance mont_inst: BM.mont t_limbs = { // BM.bn = bn_inst; // BM.mont_check; // BM.precomp = precompr2; // BM.reduction; // BM.to; // BM.from; // BM.mul = mont_mul; // BM.sqr = mont_sqr; // } [@CInline] let areduction: AM.bn_almost_mont_reduction_st t_limbs n_limbs = AM.bn_almost_mont_reduction bn_inst [@CInline] let amont_mul: AM.bn_almost_mont_mul_st t_limbs n_limbs = AM.bn_almost_mont_mul bn_inst areduction [@CInline] let amont_sqr: AM.bn_almost_mont_sqr_st t_limbs n_limbs = AM.bn_almost_mont_sqr bn_inst areduction inline_for_extraction noextract instance almost_mont_inst: AM.almost_mont t_limbs = { AM.bn = bn_inst; AM.mont_check; AM.precomp = precompr2; AM.reduction = areduction; AM.to; AM.from; AM.mul = amont_mul; AM.sqr = amont_sqr; } [@CInline] let bn_slow_precomp : BR.bn_mod_slow_precomp_st t_limbs n_limbs = BR.bn_mod_slow_precomp almost_mont_inst let mod n a res = BS.mk_bn_mod_slow_safe n_limbs (BR.mk_bn_mod_slow n_limbs precompr2 bn_slow_precomp) n a res let exp_check: BE.bn_check_mod_exp_st t_limbs n_limbs = BE.bn_check_mod_exp n_limbs [@CInline] let exp_vartime_precomp: BE.bn_mod_exp_precomp_st t_limbs n_limbs = BE.bn_mod_exp_vartime_precomp n_limbs (BE.bn_mod_exp_amm_bm_vartime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_vartime_precomp almost_mont_inst 4ul) [@CInline] let exp_consttime_precomp: BE.bn_mod_exp_precomp_st t_limbs n_limbs = BE.bn_mod_exp_consttime_precomp n_limbs (BE.bn_mod_exp_amm_bm_consttime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_consttime_precomp almost_mont_inst 4ul) [@CInline] let exp_vartime: BE.bn_mod_exp_st t_limbs n_limbs = BE.mk_bn_mod_exp n_limbs precompr2 exp_vartime_precomp [@CInline] let exp_consttime: BE.bn_mod_exp_st t_limbs n_limbs = BE.mk_bn_mod_exp n_limbs precompr2 exp_consttime_precomp let mod_exp_vartime = BS.mk_bn_mod_exp_safe n_limbs exp_check exp_vartime let mod_exp_consttime = BS.mk_bn_mod_exp_safe n_limbs exp_check exp_consttime let mod_inv_prime_vartime = BS.mk_bn_mod_inv_prime_safe n_limbs exp_vartime let mont_ctx_init r n = MA.bn_field_init n_limbs precompr2 r n let mont_ctx_free k = MA.bn_field_free k let mod_precomp k a res = BS.bn_mod_ctx n_limbs bn_slow_precomp k a res let mod_exp_vartime_precomp k a bBits b res = BS.mk_bn_mod_exp_ctx n_limbs exp_vartime_precomp k a bBits b res let mod_exp_consttime_precomp k a bBits b res = BS.mk_bn_mod_exp_ctx n_limbs exp_consttime_precomp k a bBits b res let mod_inv_prime_vartime_precomp k a res = BS.mk_bn_mod_inv_prime_ctx n_limbs (BI.mk_bn_mod_inv_prime_precomp n_limbs exp_vartime_precomp) k a res let new_bn_from_bytes_be = BS.new_bn_from_bytes_be let new_bn_from_bytes_le = BS.new_bn_from_bytes_le let bn_to_bytes_be = Hacl.Bignum.Convert.mk_bn_to_bytes_be true n_bytes let bn_to_bytes_le = Hacl.Bignum.Convert.mk_bn_to_bytes_le true n_bytes
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.bn_lt_mask_st Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.bn_lt_mask", "Hacl.Bignum256.t_limbs", "Hacl.Bignum256.n_limbs" ]
[]
false
false
false
true
false
let lt_mask =
BN.bn_lt_mask n_limbs
false
Hacl.Bignum256.fst
Hacl.Bignum256.mod_inv_prime_vartime_precomp
val mod_inv_prime_vartime_precomp: BS.bn_mod_inv_prime_ctx_st t_limbs n_limbs
val mod_inv_prime_vartime_precomp: BS.bn_mod_inv_prime_ctx_st t_limbs n_limbs
let mod_inv_prime_vartime_precomp k a res = BS.mk_bn_mod_inv_prime_ctx n_limbs (BI.mk_bn_mod_inv_prime_precomp n_limbs exp_vartime_precomp) k a res
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 72, "end_line": 161, "start_col": 0, "start_line": 159 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs let mul (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a = BN.bn_mul n_limbs n_limbs a let sqr (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_sqr_st t_limbs n_limbs a = BN.bn_sqr n_limbs a //BN.bn_mul n_limbs n_limbs a a inline_for_extraction noextract instance bn_inst: BN.bn t_limbs = { BN.len = n_limbs; BN.add; BN.sub; BN.add_mod_n = add_mod; BN.sub_mod_n = sub_mod; BN.mul; BN.sqr } [@CInline] let mont_check: BM.bn_check_modulus_st t_limbs n_limbs = BM.bn_check_modulus [@CInline] let precompr2: BM.bn_precomp_r2_mod_n_st t_limbs n_limbs = BM.bn_precomp_r2_mod_n bn_inst [@CInline] let reduction: BM.bn_mont_reduction_st t_limbs n_limbs = BM.bn_mont_reduction bn_inst [@CInline] let to: BM.bn_to_mont_st t_limbs n_limbs = BM.bn_to_mont bn_inst reduction [@CInline] let from: BM.bn_from_mont_st t_limbs n_limbs = BM.bn_from_mont bn_inst reduction // [@CInline] // let mont_mul: BM.bn_mont_mul_st t_limbs n_limbs = // BM.bn_mont_mul bn_inst reduction // [@CInline] // let mont_sqr: BM.bn_mont_sqr_st t_limbs n_limbs = // BM.bn_mont_sqr bn_inst reduction // inline_for_extraction noextract // instance mont_inst: BM.mont t_limbs = { // BM.bn = bn_inst; // BM.mont_check; // BM.precomp = precompr2; // BM.reduction; // BM.to; // BM.from; // BM.mul = mont_mul; // BM.sqr = mont_sqr; // } [@CInline] let areduction: AM.bn_almost_mont_reduction_st t_limbs n_limbs = AM.bn_almost_mont_reduction bn_inst [@CInline] let amont_mul: AM.bn_almost_mont_mul_st t_limbs n_limbs = AM.bn_almost_mont_mul bn_inst areduction [@CInline] let amont_sqr: AM.bn_almost_mont_sqr_st t_limbs n_limbs = AM.bn_almost_mont_sqr bn_inst areduction inline_for_extraction noextract instance almost_mont_inst: AM.almost_mont t_limbs = { AM.bn = bn_inst; AM.mont_check; AM.precomp = precompr2; AM.reduction = areduction; AM.to; AM.from; AM.mul = amont_mul; AM.sqr = amont_sqr; } [@CInline] let bn_slow_precomp : BR.bn_mod_slow_precomp_st t_limbs n_limbs = BR.bn_mod_slow_precomp almost_mont_inst let mod n a res = BS.mk_bn_mod_slow_safe n_limbs (BR.mk_bn_mod_slow n_limbs precompr2 bn_slow_precomp) n a res let exp_check: BE.bn_check_mod_exp_st t_limbs n_limbs = BE.bn_check_mod_exp n_limbs [@CInline] let exp_vartime_precomp: BE.bn_mod_exp_precomp_st t_limbs n_limbs = BE.bn_mod_exp_vartime_precomp n_limbs (BE.bn_mod_exp_amm_bm_vartime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_vartime_precomp almost_mont_inst 4ul) [@CInline] let exp_consttime_precomp: BE.bn_mod_exp_precomp_st t_limbs n_limbs = BE.bn_mod_exp_consttime_precomp n_limbs (BE.bn_mod_exp_amm_bm_consttime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_consttime_precomp almost_mont_inst 4ul) [@CInline] let exp_vartime: BE.bn_mod_exp_st t_limbs n_limbs = BE.mk_bn_mod_exp n_limbs precompr2 exp_vartime_precomp [@CInline] let exp_consttime: BE.bn_mod_exp_st t_limbs n_limbs = BE.mk_bn_mod_exp n_limbs precompr2 exp_consttime_precomp let mod_exp_vartime = BS.mk_bn_mod_exp_safe n_limbs exp_check exp_vartime let mod_exp_consttime = BS.mk_bn_mod_exp_safe n_limbs exp_check exp_consttime let mod_inv_prime_vartime = BS.mk_bn_mod_inv_prime_safe n_limbs exp_vartime let mont_ctx_init r n = MA.bn_field_init n_limbs precompr2 r n let mont_ctx_free k = MA.bn_field_free k let mod_precomp k a res = BS.bn_mod_ctx n_limbs bn_slow_precomp k a res let mod_exp_vartime_precomp k a bBits b res = BS.mk_bn_mod_exp_ctx n_limbs exp_vartime_precomp k a bBits b res let mod_exp_consttime_precomp k a bBits b res = BS.mk_bn_mod_exp_ctx n_limbs exp_consttime_precomp k a bBits b res
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.SafeAPI.bn_mod_inv_prime_ctx_st Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.MontArithmetic.pbn_mont_ctx", "Hacl.Bignum256.t_limbs", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum256.n_limbs", "Hacl.Bignum.SafeAPI.mk_bn_mod_inv_prime_ctx", "FStar.Ghost.hide", "Hacl.Bignum.meta_len", "Hacl.Bignum.ModInv.mk_bn_mod_inv_prime_precomp", "Hacl.Bignum256.exp_vartime_precomp", "Prims.unit" ]
[]
false
false
false
true
false
let mod_inv_prime_vartime_precomp k a res =
BS.mk_bn_mod_inv_prime_ctx n_limbs (BI.mk_bn_mod_inv_prime_precomp n_limbs exp_vartime_precomp) k a res
false
Hacl.Bignum256.fst
Hacl.Bignum256.mul
val mul: a:lbignum t_limbs n_limbs -> BN.bn_karatsuba_mul_st t_limbs n_limbs a
val mul: a:lbignum t_limbs n_limbs -> BN.bn_karatsuba_mul_st t_limbs n_limbs a
let mul (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a = BN.bn_mul n_limbs n_limbs a
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 27, "start_col": 0, "start_line": 26 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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.Bignum256.lbignum Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs -> Hacl.Bignum.bn_karatsuba_mul_st Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs a
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum256.lbignum", "Hacl.Bignum256.t_limbs", "Hacl.Bignum256.n_limbs", "Hacl.Bignum.bn_mul", "Hacl.Bignum.bn_karatsuba_mul_st" ]
[]
false
false
false
false
false
let mul (a: lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a =
BN.bn_mul n_limbs n_limbs a
false
Hacl.Bignum256.fst
Hacl.Bignum256.eq_mask
val eq_mask: BN.bn_eq_mask_st t_limbs n_limbs
val eq_mask: BN.bn_eq_mask_st t_limbs n_limbs
let eq_mask = BN.bn_eq_mask n_limbs
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 35, "end_line": 173, "start_col": 0, "start_line": 173 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs let mul (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a = BN.bn_mul n_limbs n_limbs a let sqr (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_sqr_st t_limbs n_limbs a = BN.bn_sqr n_limbs a //BN.bn_mul n_limbs n_limbs a a inline_for_extraction noextract instance bn_inst: BN.bn t_limbs = { BN.len = n_limbs; BN.add; BN.sub; BN.add_mod_n = add_mod; BN.sub_mod_n = sub_mod; BN.mul; BN.sqr } [@CInline] let mont_check: BM.bn_check_modulus_st t_limbs n_limbs = BM.bn_check_modulus [@CInline] let precompr2: BM.bn_precomp_r2_mod_n_st t_limbs n_limbs = BM.bn_precomp_r2_mod_n bn_inst [@CInline] let reduction: BM.bn_mont_reduction_st t_limbs n_limbs = BM.bn_mont_reduction bn_inst [@CInline] let to: BM.bn_to_mont_st t_limbs n_limbs = BM.bn_to_mont bn_inst reduction [@CInline] let from: BM.bn_from_mont_st t_limbs n_limbs = BM.bn_from_mont bn_inst reduction // [@CInline] // let mont_mul: BM.bn_mont_mul_st t_limbs n_limbs = // BM.bn_mont_mul bn_inst reduction // [@CInline] // let mont_sqr: BM.bn_mont_sqr_st t_limbs n_limbs = // BM.bn_mont_sqr bn_inst reduction // inline_for_extraction noextract // instance mont_inst: BM.mont t_limbs = { // BM.bn = bn_inst; // BM.mont_check; // BM.precomp = precompr2; // BM.reduction; // BM.to; // BM.from; // BM.mul = mont_mul; // BM.sqr = mont_sqr; // } [@CInline] let areduction: AM.bn_almost_mont_reduction_st t_limbs n_limbs = AM.bn_almost_mont_reduction bn_inst [@CInline] let amont_mul: AM.bn_almost_mont_mul_st t_limbs n_limbs = AM.bn_almost_mont_mul bn_inst areduction [@CInline] let amont_sqr: AM.bn_almost_mont_sqr_st t_limbs n_limbs = AM.bn_almost_mont_sqr bn_inst areduction inline_for_extraction noextract instance almost_mont_inst: AM.almost_mont t_limbs = { AM.bn = bn_inst; AM.mont_check; AM.precomp = precompr2; AM.reduction = areduction; AM.to; AM.from; AM.mul = amont_mul; AM.sqr = amont_sqr; } [@CInline] let bn_slow_precomp : BR.bn_mod_slow_precomp_st t_limbs n_limbs = BR.bn_mod_slow_precomp almost_mont_inst let mod n a res = BS.mk_bn_mod_slow_safe n_limbs (BR.mk_bn_mod_slow n_limbs precompr2 bn_slow_precomp) n a res let exp_check: BE.bn_check_mod_exp_st t_limbs n_limbs = BE.bn_check_mod_exp n_limbs [@CInline] let exp_vartime_precomp: BE.bn_mod_exp_precomp_st t_limbs n_limbs = BE.bn_mod_exp_vartime_precomp n_limbs (BE.bn_mod_exp_amm_bm_vartime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_vartime_precomp almost_mont_inst 4ul) [@CInline] let exp_consttime_precomp: BE.bn_mod_exp_precomp_st t_limbs n_limbs = BE.bn_mod_exp_consttime_precomp n_limbs (BE.bn_mod_exp_amm_bm_consttime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_consttime_precomp almost_mont_inst 4ul) [@CInline] let exp_vartime: BE.bn_mod_exp_st t_limbs n_limbs = BE.mk_bn_mod_exp n_limbs precompr2 exp_vartime_precomp [@CInline] let exp_consttime: BE.bn_mod_exp_st t_limbs n_limbs = BE.mk_bn_mod_exp n_limbs precompr2 exp_consttime_precomp let mod_exp_vartime = BS.mk_bn_mod_exp_safe n_limbs exp_check exp_vartime let mod_exp_consttime = BS.mk_bn_mod_exp_safe n_limbs exp_check exp_consttime let mod_inv_prime_vartime = BS.mk_bn_mod_inv_prime_safe n_limbs exp_vartime let mont_ctx_init r n = MA.bn_field_init n_limbs precompr2 r n let mont_ctx_free k = MA.bn_field_free k let mod_precomp k a res = BS.bn_mod_ctx n_limbs bn_slow_precomp k a res let mod_exp_vartime_precomp k a bBits b res = BS.mk_bn_mod_exp_ctx n_limbs exp_vartime_precomp k a bBits b res let mod_exp_consttime_precomp k a bBits b res = BS.mk_bn_mod_exp_ctx n_limbs exp_consttime_precomp k a bBits b res let mod_inv_prime_vartime_precomp k a res = BS.mk_bn_mod_inv_prime_ctx n_limbs (BI.mk_bn_mod_inv_prime_precomp n_limbs exp_vartime_precomp) k a res let new_bn_from_bytes_be = BS.new_bn_from_bytes_be let new_bn_from_bytes_le = BS.new_bn_from_bytes_le let bn_to_bytes_be = Hacl.Bignum.Convert.mk_bn_to_bytes_be true n_bytes let bn_to_bytes_le = Hacl.Bignum.Convert.mk_bn_to_bytes_le true n_bytes let lt_mask = BN.bn_lt_mask n_limbs
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.bn_eq_mask_st Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.bn_eq_mask", "Hacl.Bignum256.t_limbs", "Hacl.Bignum256.n_limbs" ]
[]
false
false
false
true
false
let eq_mask =
BN.bn_eq_mask n_limbs
false
Hacl.Bignum256.fst
Hacl.Bignum256.new_bn_from_bytes_le
val new_bn_from_bytes_le: BS.new_bn_from_bytes_le_st t_limbs
val new_bn_from_bytes_le: BS.new_bn_from_bytes_le_st t_limbs
let new_bn_from_bytes_le = BS.new_bn_from_bytes_le
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 50, "end_line": 165, "start_col": 0, "start_line": 165 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs let mul (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a = BN.bn_mul n_limbs n_limbs a let sqr (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_sqr_st t_limbs n_limbs a = BN.bn_sqr n_limbs a //BN.bn_mul n_limbs n_limbs a a inline_for_extraction noextract instance bn_inst: BN.bn t_limbs = { BN.len = n_limbs; BN.add; BN.sub; BN.add_mod_n = add_mod; BN.sub_mod_n = sub_mod; BN.mul; BN.sqr } [@CInline] let mont_check: BM.bn_check_modulus_st t_limbs n_limbs = BM.bn_check_modulus [@CInline] let precompr2: BM.bn_precomp_r2_mod_n_st t_limbs n_limbs = BM.bn_precomp_r2_mod_n bn_inst [@CInline] let reduction: BM.bn_mont_reduction_st t_limbs n_limbs = BM.bn_mont_reduction bn_inst [@CInline] let to: BM.bn_to_mont_st t_limbs n_limbs = BM.bn_to_mont bn_inst reduction [@CInline] let from: BM.bn_from_mont_st t_limbs n_limbs = BM.bn_from_mont bn_inst reduction // [@CInline] // let mont_mul: BM.bn_mont_mul_st t_limbs n_limbs = // BM.bn_mont_mul bn_inst reduction // [@CInline] // let mont_sqr: BM.bn_mont_sqr_st t_limbs n_limbs = // BM.bn_mont_sqr bn_inst reduction // inline_for_extraction noextract // instance mont_inst: BM.mont t_limbs = { // BM.bn = bn_inst; // BM.mont_check; // BM.precomp = precompr2; // BM.reduction; // BM.to; // BM.from; // BM.mul = mont_mul; // BM.sqr = mont_sqr; // } [@CInline] let areduction: AM.bn_almost_mont_reduction_st t_limbs n_limbs = AM.bn_almost_mont_reduction bn_inst [@CInline] let amont_mul: AM.bn_almost_mont_mul_st t_limbs n_limbs = AM.bn_almost_mont_mul bn_inst areduction [@CInline] let amont_sqr: AM.bn_almost_mont_sqr_st t_limbs n_limbs = AM.bn_almost_mont_sqr bn_inst areduction inline_for_extraction noextract instance almost_mont_inst: AM.almost_mont t_limbs = { AM.bn = bn_inst; AM.mont_check; AM.precomp = precompr2; AM.reduction = areduction; AM.to; AM.from; AM.mul = amont_mul; AM.sqr = amont_sqr; } [@CInline] let bn_slow_precomp : BR.bn_mod_slow_precomp_st t_limbs n_limbs = BR.bn_mod_slow_precomp almost_mont_inst let mod n a res = BS.mk_bn_mod_slow_safe n_limbs (BR.mk_bn_mod_slow n_limbs precompr2 bn_slow_precomp) n a res let exp_check: BE.bn_check_mod_exp_st t_limbs n_limbs = BE.bn_check_mod_exp n_limbs [@CInline] let exp_vartime_precomp: BE.bn_mod_exp_precomp_st t_limbs n_limbs = BE.bn_mod_exp_vartime_precomp n_limbs (BE.bn_mod_exp_amm_bm_vartime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_vartime_precomp almost_mont_inst 4ul) [@CInline] let exp_consttime_precomp: BE.bn_mod_exp_precomp_st t_limbs n_limbs = BE.bn_mod_exp_consttime_precomp n_limbs (BE.bn_mod_exp_amm_bm_consttime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_consttime_precomp almost_mont_inst 4ul) [@CInline] let exp_vartime: BE.bn_mod_exp_st t_limbs n_limbs = BE.mk_bn_mod_exp n_limbs precompr2 exp_vartime_precomp [@CInline] let exp_consttime: BE.bn_mod_exp_st t_limbs n_limbs = BE.mk_bn_mod_exp n_limbs precompr2 exp_consttime_precomp let mod_exp_vartime = BS.mk_bn_mod_exp_safe n_limbs exp_check exp_vartime let mod_exp_consttime = BS.mk_bn_mod_exp_safe n_limbs exp_check exp_consttime let mod_inv_prime_vartime = BS.mk_bn_mod_inv_prime_safe n_limbs exp_vartime let mont_ctx_init r n = MA.bn_field_init n_limbs precompr2 r n let mont_ctx_free k = MA.bn_field_free k let mod_precomp k a res = BS.bn_mod_ctx n_limbs bn_slow_precomp k a res let mod_exp_vartime_precomp k a bBits b res = BS.mk_bn_mod_exp_ctx n_limbs exp_vartime_precomp k a bBits b res let mod_exp_consttime_precomp k a bBits b res = BS.mk_bn_mod_exp_ctx n_limbs exp_consttime_precomp k a bBits b res let mod_inv_prime_vartime_precomp k a res = BS.mk_bn_mod_inv_prime_ctx n_limbs (BI.mk_bn_mod_inv_prime_precomp n_limbs exp_vartime_precomp) k a res let new_bn_from_bytes_be = BS.new_bn_from_bytes_be
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.SafeAPI.new_bn_from_bytes_le_st Hacl.Bignum256.t_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.SafeAPI.new_bn_from_bytes_le", "Hacl.Bignum256.t_limbs" ]
[]
false
false
false
true
false
let new_bn_from_bytes_le =
BS.new_bn_from_bytes_le
false
Hacl.Bignum256.fst
Hacl.Bignum256.mod
val mod: BS.bn_mod_slow_safe_st t_limbs n_limbs
val mod: BS.bn_mod_slow_safe_st t_limbs n_limbs
let mod n a res = BS.mk_bn_mod_slow_safe n_limbs (BR.mk_bn_mod_slow n_limbs precompr2 bn_slow_precomp) n a res
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 94, "end_line": 113, "start_col": 0, "start_line": 112 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs let mul (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a = BN.bn_mul n_limbs n_limbs a let sqr (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_sqr_st t_limbs n_limbs a = BN.bn_sqr n_limbs a //BN.bn_mul n_limbs n_limbs a a inline_for_extraction noextract instance bn_inst: BN.bn t_limbs = { BN.len = n_limbs; BN.add; BN.sub; BN.add_mod_n = add_mod; BN.sub_mod_n = sub_mod; BN.mul; BN.sqr } [@CInline] let mont_check: BM.bn_check_modulus_st t_limbs n_limbs = BM.bn_check_modulus [@CInline] let precompr2: BM.bn_precomp_r2_mod_n_st t_limbs n_limbs = BM.bn_precomp_r2_mod_n bn_inst [@CInline] let reduction: BM.bn_mont_reduction_st t_limbs n_limbs = BM.bn_mont_reduction bn_inst [@CInline] let to: BM.bn_to_mont_st t_limbs n_limbs = BM.bn_to_mont bn_inst reduction [@CInline] let from: BM.bn_from_mont_st t_limbs n_limbs = BM.bn_from_mont bn_inst reduction // [@CInline] // let mont_mul: BM.bn_mont_mul_st t_limbs n_limbs = // BM.bn_mont_mul bn_inst reduction // [@CInline] // let mont_sqr: BM.bn_mont_sqr_st t_limbs n_limbs = // BM.bn_mont_sqr bn_inst reduction // inline_for_extraction noextract // instance mont_inst: BM.mont t_limbs = { // BM.bn = bn_inst; // BM.mont_check; // BM.precomp = precompr2; // BM.reduction; // BM.to; // BM.from; // BM.mul = mont_mul; // BM.sqr = mont_sqr; // } [@CInline] let areduction: AM.bn_almost_mont_reduction_st t_limbs n_limbs = AM.bn_almost_mont_reduction bn_inst [@CInline] let amont_mul: AM.bn_almost_mont_mul_st t_limbs n_limbs = AM.bn_almost_mont_mul bn_inst areduction [@CInline] let amont_sqr: AM.bn_almost_mont_sqr_st t_limbs n_limbs = AM.bn_almost_mont_sqr bn_inst areduction inline_for_extraction noextract instance almost_mont_inst: AM.almost_mont t_limbs = { AM.bn = bn_inst; AM.mont_check; AM.precomp = precompr2; AM.reduction = areduction; AM.to; AM.from; AM.mul = amont_mul; AM.sqr = amont_sqr; } [@CInline] let bn_slow_precomp : BR.bn_mod_slow_precomp_st t_limbs n_limbs = BR.bn_mod_slow_precomp almost_mont_inst
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.SafeAPI.bn_mod_slow_safe_st Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum256.t_limbs", "Hacl.Bignum256.n_limbs", "Lib.IntTypes.op_Plus_Bang", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.SafeAPI.mk_bn_mod_slow_safe", "Hacl.Bignum.ModReduction.mk_bn_mod_slow", "Hacl.Bignum256.precompr2", "Hacl.Bignum256.bn_slow_precomp", "Prims.bool" ]
[]
false
false
false
true
false
let mod n a res =
BS.mk_bn_mod_slow_safe n_limbs (BR.mk_bn_mod_slow n_limbs precompr2 bn_slow_precomp) n a res
false
Hacl.Bignum256.fst
Hacl.Bignum256.new_bn_from_bytes_be
val new_bn_from_bytes_be: BS.new_bn_from_bytes_be_st t_limbs
val new_bn_from_bytes_be: BS.new_bn_from_bytes_be_st t_limbs
let new_bn_from_bytes_be = BS.new_bn_from_bytes_be
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 50, "end_line": 163, "start_col": 0, "start_line": 163 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs let mul (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a = BN.bn_mul n_limbs n_limbs a let sqr (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_sqr_st t_limbs n_limbs a = BN.bn_sqr n_limbs a //BN.bn_mul n_limbs n_limbs a a inline_for_extraction noextract instance bn_inst: BN.bn t_limbs = { BN.len = n_limbs; BN.add; BN.sub; BN.add_mod_n = add_mod; BN.sub_mod_n = sub_mod; BN.mul; BN.sqr } [@CInline] let mont_check: BM.bn_check_modulus_st t_limbs n_limbs = BM.bn_check_modulus [@CInline] let precompr2: BM.bn_precomp_r2_mod_n_st t_limbs n_limbs = BM.bn_precomp_r2_mod_n bn_inst [@CInline] let reduction: BM.bn_mont_reduction_st t_limbs n_limbs = BM.bn_mont_reduction bn_inst [@CInline] let to: BM.bn_to_mont_st t_limbs n_limbs = BM.bn_to_mont bn_inst reduction [@CInline] let from: BM.bn_from_mont_st t_limbs n_limbs = BM.bn_from_mont bn_inst reduction // [@CInline] // let mont_mul: BM.bn_mont_mul_st t_limbs n_limbs = // BM.bn_mont_mul bn_inst reduction // [@CInline] // let mont_sqr: BM.bn_mont_sqr_st t_limbs n_limbs = // BM.bn_mont_sqr bn_inst reduction // inline_for_extraction noextract // instance mont_inst: BM.mont t_limbs = { // BM.bn = bn_inst; // BM.mont_check; // BM.precomp = precompr2; // BM.reduction; // BM.to; // BM.from; // BM.mul = mont_mul; // BM.sqr = mont_sqr; // } [@CInline] let areduction: AM.bn_almost_mont_reduction_st t_limbs n_limbs = AM.bn_almost_mont_reduction bn_inst [@CInline] let amont_mul: AM.bn_almost_mont_mul_st t_limbs n_limbs = AM.bn_almost_mont_mul bn_inst areduction [@CInline] let amont_sqr: AM.bn_almost_mont_sqr_st t_limbs n_limbs = AM.bn_almost_mont_sqr bn_inst areduction inline_for_extraction noextract instance almost_mont_inst: AM.almost_mont t_limbs = { AM.bn = bn_inst; AM.mont_check; AM.precomp = precompr2; AM.reduction = areduction; AM.to; AM.from; AM.mul = amont_mul; AM.sqr = amont_sqr; } [@CInline] let bn_slow_precomp : BR.bn_mod_slow_precomp_st t_limbs n_limbs = BR.bn_mod_slow_precomp almost_mont_inst let mod n a res = BS.mk_bn_mod_slow_safe n_limbs (BR.mk_bn_mod_slow n_limbs precompr2 bn_slow_precomp) n a res let exp_check: BE.bn_check_mod_exp_st t_limbs n_limbs = BE.bn_check_mod_exp n_limbs [@CInline] let exp_vartime_precomp: BE.bn_mod_exp_precomp_st t_limbs n_limbs = BE.bn_mod_exp_vartime_precomp n_limbs (BE.bn_mod_exp_amm_bm_vartime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_vartime_precomp almost_mont_inst 4ul) [@CInline] let exp_consttime_precomp: BE.bn_mod_exp_precomp_st t_limbs n_limbs = BE.bn_mod_exp_consttime_precomp n_limbs (BE.bn_mod_exp_amm_bm_consttime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_consttime_precomp almost_mont_inst 4ul) [@CInline] let exp_vartime: BE.bn_mod_exp_st t_limbs n_limbs = BE.mk_bn_mod_exp n_limbs precompr2 exp_vartime_precomp [@CInline] let exp_consttime: BE.bn_mod_exp_st t_limbs n_limbs = BE.mk_bn_mod_exp n_limbs precompr2 exp_consttime_precomp let mod_exp_vartime = BS.mk_bn_mod_exp_safe n_limbs exp_check exp_vartime let mod_exp_consttime = BS.mk_bn_mod_exp_safe n_limbs exp_check exp_consttime let mod_inv_prime_vartime = BS.mk_bn_mod_inv_prime_safe n_limbs exp_vartime let mont_ctx_init r n = MA.bn_field_init n_limbs precompr2 r n let mont_ctx_free k = MA.bn_field_free k let mod_precomp k a res = BS.bn_mod_ctx n_limbs bn_slow_precomp k a res let mod_exp_vartime_precomp k a bBits b res = BS.mk_bn_mod_exp_ctx n_limbs exp_vartime_precomp k a bBits b res let mod_exp_consttime_precomp k a bBits b res = BS.mk_bn_mod_exp_ctx n_limbs exp_consttime_precomp k a bBits b res let mod_inv_prime_vartime_precomp k a res = BS.mk_bn_mod_inv_prime_ctx n_limbs (BI.mk_bn_mod_inv_prime_precomp n_limbs exp_vartime_precomp) k a res
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.SafeAPI.new_bn_from_bytes_be_st Hacl.Bignum256.t_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.SafeAPI.new_bn_from_bytes_be", "Hacl.Bignum256.t_limbs" ]
[]
false
false
false
true
false
let new_bn_from_bytes_be =
BS.new_bn_from_bytes_be
false
Hacl.Bignum256.fst
Hacl.Bignum256.sqr
val sqr: a:lbignum t_limbs n_limbs -> BN.bn_karatsuba_sqr_st t_limbs n_limbs a
val sqr: a:lbignum t_limbs n_limbs -> BN.bn_karatsuba_sqr_st t_limbs n_limbs a
let sqr (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_sqr_st t_limbs n_limbs a = BN.bn_sqr n_limbs a
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 21, "end_line": 30, "start_col": 0, "start_line": 29 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs let mul (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a = BN.bn_mul n_limbs n_limbs a
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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.Bignum256.lbignum Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs -> Hacl.Bignum.bn_karatsuba_sqr_st Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs a
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum256.lbignum", "Hacl.Bignum256.t_limbs", "Hacl.Bignum256.n_limbs", "Hacl.Bignum.bn_sqr", "Hacl.Bignum.bn_karatsuba_sqr_st" ]
[]
false
false
false
false
false
let sqr (a: lbignum t_limbs n_limbs) : BN.bn_karatsuba_sqr_st t_limbs n_limbs a =
BN.bn_sqr n_limbs a
false
Hacl.Bignum256.fst
Hacl.Bignum256.exp_vartime_precomp
val exp_vartime_precomp:BE.bn_mod_exp_precomp_st t_limbs n_limbs
val exp_vartime_precomp:BE.bn_mod_exp_precomp_st t_limbs n_limbs
let exp_vartime_precomp: BE.bn_mod_exp_precomp_st t_limbs n_limbs = BE.bn_mod_exp_vartime_precomp n_limbs (BE.bn_mod_exp_amm_bm_vartime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_vartime_precomp almost_mont_inst 4ul)
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 63, "end_line": 122, "start_col": 0, "start_line": 119 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs let mul (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a = BN.bn_mul n_limbs n_limbs a let sqr (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_sqr_st t_limbs n_limbs a = BN.bn_sqr n_limbs a //BN.bn_mul n_limbs n_limbs a a inline_for_extraction noextract instance bn_inst: BN.bn t_limbs = { BN.len = n_limbs; BN.add; BN.sub; BN.add_mod_n = add_mod; BN.sub_mod_n = sub_mod; BN.mul; BN.sqr } [@CInline] let mont_check: BM.bn_check_modulus_st t_limbs n_limbs = BM.bn_check_modulus [@CInline] let precompr2: BM.bn_precomp_r2_mod_n_st t_limbs n_limbs = BM.bn_precomp_r2_mod_n bn_inst [@CInline] let reduction: BM.bn_mont_reduction_st t_limbs n_limbs = BM.bn_mont_reduction bn_inst [@CInline] let to: BM.bn_to_mont_st t_limbs n_limbs = BM.bn_to_mont bn_inst reduction [@CInline] let from: BM.bn_from_mont_st t_limbs n_limbs = BM.bn_from_mont bn_inst reduction // [@CInline] // let mont_mul: BM.bn_mont_mul_st t_limbs n_limbs = // BM.bn_mont_mul bn_inst reduction // [@CInline] // let mont_sqr: BM.bn_mont_sqr_st t_limbs n_limbs = // BM.bn_mont_sqr bn_inst reduction // inline_for_extraction noextract // instance mont_inst: BM.mont t_limbs = { // BM.bn = bn_inst; // BM.mont_check; // BM.precomp = precompr2; // BM.reduction; // BM.to; // BM.from; // BM.mul = mont_mul; // BM.sqr = mont_sqr; // } [@CInline] let areduction: AM.bn_almost_mont_reduction_st t_limbs n_limbs = AM.bn_almost_mont_reduction bn_inst [@CInline] let amont_mul: AM.bn_almost_mont_mul_st t_limbs n_limbs = AM.bn_almost_mont_mul bn_inst areduction [@CInline] let amont_sqr: AM.bn_almost_mont_sqr_st t_limbs n_limbs = AM.bn_almost_mont_sqr bn_inst areduction inline_for_extraction noextract instance almost_mont_inst: AM.almost_mont t_limbs = { AM.bn = bn_inst; AM.mont_check; AM.precomp = precompr2; AM.reduction = areduction; AM.to; AM.from; AM.mul = amont_mul; AM.sqr = amont_sqr; } [@CInline] let bn_slow_precomp : BR.bn_mod_slow_precomp_st t_limbs n_limbs = BR.bn_mod_slow_precomp almost_mont_inst let mod n a res = BS.mk_bn_mod_slow_safe n_limbs (BR.mk_bn_mod_slow n_limbs precompr2 bn_slow_precomp) n a res let exp_check: BE.bn_check_mod_exp_st t_limbs n_limbs = BE.bn_check_mod_exp n_limbs
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.Exponentiation.bn_mod_exp_precomp_st Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Exponentiation.bn_mod_exp_vartime_precomp", "Hacl.Bignum256.t_limbs", "Hacl.Bignum256.n_limbs", "Hacl.Bignum.Exponentiation.bn_mod_exp_amm_bm_vartime_precomp", "Hacl.Bignum256.almost_mont_inst", "Hacl.Bignum.Exponentiation.bn_mod_exp_amm_fw_vartime_precomp", "FStar.UInt32.__uint_to_t" ]
[]
false
false
false
true
false
let exp_vartime_precomp:BE.bn_mod_exp_precomp_st t_limbs n_limbs =
BE.bn_mod_exp_vartime_precomp n_limbs (BE.bn_mod_exp_amm_bm_vartime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_vartime_precomp almost_mont_inst 4ul)
false
Hacl.Bignum256.fst
Hacl.Bignum256.exp_consttime_precomp
val exp_consttime_precomp:BE.bn_mod_exp_precomp_st t_limbs n_limbs
val exp_consttime_precomp:BE.bn_mod_exp_precomp_st t_limbs n_limbs
let exp_consttime_precomp: BE.bn_mod_exp_precomp_st t_limbs n_limbs = BE.bn_mod_exp_consttime_precomp n_limbs (BE.bn_mod_exp_amm_bm_consttime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_consttime_precomp almost_mont_inst 4ul)
{ "file_name": "code/bignum/Hacl.Bignum256.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 65, "end_line": 128, "start_col": 0, "start_line": 125 }
module Hacl.Bignum256 open FStar.Mul module BN = Hacl.Bignum module BM = Hacl.Bignum.Montgomery module AM = Hacl.Bignum.AlmostMontgomery module BE = Hacl.Bignum.Exponentiation module BR = Hacl.Bignum.ModReduction module BI = Hacl.Bignum.ModInv #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let add: BN.bn_add_eq_len_st t_limbs n_limbs = BN.bn_add_eq_len n_limbs let sub: BN.bn_sub_eq_len_st t_limbs n_limbs = BN.bn_sub_eq_len n_limbs let add_mod: BN.bn_add_mod_n_st t_limbs n_limbs = BN.bn_add_mod_n n_limbs let sub_mod: BN.bn_sub_mod_n_st t_limbs n_limbs = BN.bn_sub_mod_n n_limbs let mul (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_mul_st t_limbs n_limbs a = BN.bn_mul n_limbs n_limbs a let sqr (a:lbignum t_limbs n_limbs) : BN.bn_karatsuba_sqr_st t_limbs n_limbs a = BN.bn_sqr n_limbs a //BN.bn_mul n_limbs n_limbs a a inline_for_extraction noextract instance bn_inst: BN.bn t_limbs = { BN.len = n_limbs; BN.add; BN.sub; BN.add_mod_n = add_mod; BN.sub_mod_n = sub_mod; BN.mul; BN.sqr } [@CInline] let mont_check: BM.bn_check_modulus_st t_limbs n_limbs = BM.bn_check_modulus [@CInline] let precompr2: BM.bn_precomp_r2_mod_n_st t_limbs n_limbs = BM.bn_precomp_r2_mod_n bn_inst [@CInline] let reduction: BM.bn_mont_reduction_st t_limbs n_limbs = BM.bn_mont_reduction bn_inst [@CInline] let to: BM.bn_to_mont_st t_limbs n_limbs = BM.bn_to_mont bn_inst reduction [@CInline] let from: BM.bn_from_mont_st t_limbs n_limbs = BM.bn_from_mont bn_inst reduction // [@CInline] // let mont_mul: BM.bn_mont_mul_st t_limbs n_limbs = // BM.bn_mont_mul bn_inst reduction // [@CInline] // let mont_sqr: BM.bn_mont_sqr_st t_limbs n_limbs = // BM.bn_mont_sqr bn_inst reduction // inline_for_extraction noextract // instance mont_inst: BM.mont t_limbs = { // BM.bn = bn_inst; // BM.mont_check; // BM.precomp = precompr2; // BM.reduction; // BM.to; // BM.from; // BM.mul = mont_mul; // BM.sqr = mont_sqr; // } [@CInline] let areduction: AM.bn_almost_mont_reduction_st t_limbs n_limbs = AM.bn_almost_mont_reduction bn_inst [@CInline] let amont_mul: AM.bn_almost_mont_mul_st t_limbs n_limbs = AM.bn_almost_mont_mul bn_inst areduction [@CInline] let amont_sqr: AM.bn_almost_mont_sqr_st t_limbs n_limbs = AM.bn_almost_mont_sqr bn_inst areduction inline_for_extraction noextract instance almost_mont_inst: AM.almost_mont t_limbs = { AM.bn = bn_inst; AM.mont_check; AM.precomp = precompr2; AM.reduction = areduction; AM.to; AM.from; AM.mul = amont_mul; AM.sqr = amont_sqr; } [@CInline] let bn_slow_precomp : BR.bn_mod_slow_precomp_st t_limbs n_limbs = BR.bn_mod_slow_precomp almost_mont_inst let mod n a res = BS.mk_bn_mod_slow_safe n_limbs (BR.mk_bn_mod_slow n_limbs precompr2 bn_slow_precomp) n a res let exp_check: BE.bn_check_mod_exp_st t_limbs n_limbs = BE.bn_check_mod_exp n_limbs [@CInline] let exp_vartime_precomp: BE.bn_mod_exp_precomp_st t_limbs n_limbs = BE.bn_mod_exp_vartime_precomp n_limbs (BE.bn_mod_exp_amm_bm_vartime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_vartime_precomp almost_mont_inst 4ul)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Bignum.Montgomery.fsti.checked", "Hacl.Bignum.ModReduction.fst.checked", "Hacl.Bignum.ModInv.fst.checked", "Hacl.Bignum.Exponentiation.fsti.checked", "Hacl.Bignum.Convert.fst.checked", "Hacl.Bignum.AlmostMontgomery.fsti.checked", "Hacl.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Hacl.Bignum256.fst" }
[ { "abbrev": true, "full_module": "Hacl.Bignum.ModInv", "short_module": "BI" }, { "abbrev": true, "full_module": "Hacl.Bignum.ModReduction", "short_module": "BR" }, { "abbrev": true, "full_module": "Hacl.Bignum.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Hacl.Bignum.AlmostMontgomery", "short_module": "AM" }, { "abbrev": true, "full_module": "Hacl.Bignum.Montgomery", "short_module": "BM" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Bignum.MontArithmetic", "short_module": "MA" }, { "abbrev": true, "full_module": "Hacl.Bignum.SafeAPI", "short_module": "BS" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Bignum.Exponentiation.bn_mod_exp_precomp_st Hacl.Bignum256.t_limbs Hacl.Bignum256.n_limbs
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Exponentiation.bn_mod_exp_consttime_precomp", "Hacl.Bignum256.t_limbs", "Hacl.Bignum256.n_limbs", "Hacl.Bignum.Exponentiation.bn_mod_exp_amm_bm_consttime_precomp", "Hacl.Bignum256.almost_mont_inst", "Hacl.Bignum.Exponentiation.bn_mod_exp_amm_fw_consttime_precomp", "FStar.UInt32.__uint_to_t" ]
[]
false
false
false
true
false
let exp_consttime_precomp:BE.bn_mod_exp_precomp_st t_limbs n_limbs =
BE.bn_mod_exp_consttime_precomp n_limbs (BE.bn_mod_exp_amm_bm_consttime_precomp almost_mont_inst) (BE.bn_mod_exp_amm_fw_consttime_precomp almost_mont_inst 4ul)
false