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
LowParse.SLow.BoundedInt.fsti
LowParse.SLow.BoundedInt.parse32_bounded_int32
val parse32_bounded_int32 (min32: U32.t) (max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296}) : Tot (parser32 (parse_bounded_int32 (U32.v min32) (U32.v max32)))
val parse32_bounded_int32 (min32: U32.t) (max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296}) : Tot (parser32 (parse_bounded_int32 (U32.v min32) (U32.v max32)))
let parse32_bounded_int32 (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) : Tot (parser32 (parse_bounded_int32 (U32.v min32) (U32.v max32))) = fun input -> ( if max32 `U32.lt` 256ul then parse32_bounded_int32_1 min32 max32 input else if max32 `U32.lt` 65536ul then parse32_bounded_int32_2 min32 max32 input else if max32 `U32.lt` 16777216ul then parse32_bounded_int32_3 min32 max32 input else parse32_bounded_int32_4 min32 max32 input )
{ "file_name": "src/lowparse/LowParse.SLow.BoundedInt.fsti", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 166, "start_col": 0, "start_line": 154 }
module LowParse.SLow.BoundedInt include LowParse.Spec.BoundedInt include LowParse.SLow.Base (* bounded integers *) inline_for_extraction val parse32_bounded_integer_1 : (parser32 (parse_bounded_integer 1)) inline_for_extraction val parse32_bounded_integer_2 : (parser32 (parse_bounded_integer 2)) inline_for_extraction val parse32_bounded_integer_3 : (parser32 (parse_bounded_integer 3)) inline_for_extraction val parse32_bounded_integer_4 : (parser32 (parse_bounded_integer 4)) inline_for_extraction noextract let parse32_bounded_integer (sz: integer_size) : Tot (parser32 (parse_bounded_integer sz)) = match sz with | 1 -> parse32_bounded_integer_1 | 2 -> parse32_bounded_integer_2 | 3 -> parse32_bounded_integer_3 | 4 -> parse32_bounded_integer_4 inline_for_extraction val serialize32_bounded_integer_1 : (serializer32 (serialize_bounded_integer 1)) inline_for_extraction val serialize32_bounded_integer_2 : (serializer32 (serialize_bounded_integer 2)) inline_for_extraction val serialize32_bounded_integer_3 : (serializer32 (serialize_bounded_integer 3)) inline_for_extraction val serialize32_bounded_integer_4 : (serializer32 (serialize_bounded_integer 4)) inline_for_extraction noextract let serialize32_bounded_integer (sz: integer_size) : Tot (serializer32 (serialize_bounded_integer sz)) = match sz with | 1 -> serialize32_bounded_integer_1 | 2 -> serialize32_bounded_integer_2 | 3 -> serialize32_bounded_integer_3 | 4 -> serialize32_bounded_integer_4 #push-options "--max_fuel 0" inline_for_extraction val parse32_bounded_integer_le_1 : parser32 (parse_bounded_integer_le 1) inline_for_extraction val parse32_bounded_integer_le_2 : parser32 (parse_bounded_integer_le 2) inline_for_extraction val parse32_bounded_integer_le_3 : parser32 (parse_bounded_integer_le 3) inline_for_extraction val parse32_bounded_integer_le_4 : parser32 (parse_bounded_integer_le 4) inline_for_extraction noextract let parse32_bounded_integer_le (sz: integer_size) : Tot (parser32 (parse_bounded_integer_le sz)) = match sz with | 1 -> parse32_bounded_integer_le_1 | 2 -> parse32_bounded_integer_le_2 | 3 -> parse32_bounded_integer_le_3 | 4 -> parse32_bounded_integer_le_4 inline_for_extraction val parse32_u16_le : parser32 parse_u16_le inline_for_extraction val parse32_u32_le : parser32 parse_u32_le #pop-options inline_for_extraction val serialize32_bounded_integer_le_1 : serializer32 (serialize_bounded_integer_le 1) inline_for_extraction val serialize32_bounded_integer_le_2 : serializer32 (serialize_bounded_integer_le 2) inline_for_extraction val serialize32_bounded_integer_le_3 : serializer32 (serialize_bounded_integer_le 3) inline_for_extraction val serialize32_bounded_integer_le_4 : serializer32 (serialize_bounded_integer_le 4) inline_for_extraction noextract let serialize32_bounded_integer_le (sz: integer_size) : Tot (serializer32 (serialize_bounded_integer_le sz)) = match sz with | 1 -> serialize32_bounded_integer_le_1 | 2 -> serialize32_bounded_integer_le_2 | 3 -> serialize32_bounded_integer_le_3 | 4 -> serialize32_bounded_integer_le_4 inline_for_extraction val serialize32_u16_le : serializer32 serialize_u16_le inline_for_extraction val serialize32_u32_le : serializer32 serialize_u32_le inline_for_extraction let size32_u16_le: size32 serialize_u16_le = assert_norm (size32_constant_precond serialize_u16_le 2ul); size32_constant serialize_u16_le 2ul () inline_for_extraction let size32_u32_le: size32 serialize_u32_le = assert_norm (size32_constant_precond serialize_u32_le 4ul); size32_constant serialize_u32_le 4ul () module U32 = FStar.UInt32 val parse32_bounded_int32_1 (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 256 }) : Tot (parser32 (parse_bounded_int32 (U32.v min32) (U32.v max32))) val parse32_bounded_int32_2 (min32: U32.t) (max32: U32.t { 256 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 65536 }) : Tot (parser32 (parse_bounded_int32 (U32.v min32) (U32.v max32))) val parse32_bounded_int32_3 (min32: U32.t) (max32: U32.t { 65536 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 16777216 }) : Tot (parser32 (parse_bounded_int32 (U32.v min32) (U32.v max32))) val parse32_bounded_int32_4 (min32: U32.t) (max32: U32.t { 16777216 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) : Tot (parser32 (parse_bounded_int32 (U32.v min32) (U32.v max32)))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.BoundedInt.fsti.checked", "LowParse.SLow.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.BoundedInt.fsti" }
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.SLow.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 0 < FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 4294967296 } -> LowParse.SLow.Base.parser32 (LowParse.Spec.BoundedInt.parse_bounded_int32 (FStar.UInt32.v min32 ) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.op_LessThanOrEqual", "LowParse.SLow.Base.bytes32", "FStar.UInt32.lt", "FStar.UInt32.__uint_to_t", "LowParse.SLow.BoundedInt.parse32_bounded_int32_1", "Prims.bool", "LowParse.SLow.BoundedInt.parse32_bounded_int32_2", "LowParse.SLow.BoundedInt.parse32_bounded_int32_3", "LowParse.SLow.BoundedInt.parse32_bounded_int32_4", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.SLow.Base.parser32_correct", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.parse_bounded_int32", "LowParse.SLow.Base.parser32" ]
[]
false
false
false
false
false
let parse32_bounded_int32 (min32: U32.t) (max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296}) : Tot (parser32 (parse_bounded_int32 (U32.v min32) (U32.v max32))) =
fun input -> (if max32 `U32.lt` 256ul then parse32_bounded_int32_1 min32 max32 input else if max32 `U32.lt` 65536ul then parse32_bounded_int32_2 min32 max32 input else if max32 `U32.lt` 16777216ul then parse32_bounded_int32_3 min32 max32 input else parse32_bounded_int32_4 min32 max32 input)
false
Steel.ST.Printf.fst
Steel.ST.Printf.test3_printf
val test3_printf (m: UInt64.t) (l: UInt32.t) (x: A.array bool {A.length x == U32.v l}) (v: Ghost.erased (Seq.seq bool)) : STT unit (A.pts_to x full_perm v) (fun _ -> A.pts_to x full_perm v)
val test3_printf (m: UInt64.t) (l: UInt32.t) (x: A.array bool {A.length x == U32.v l}) (v: Ghost.erased (Seq.seq bool)) : STT unit (A.pts_to x full_perm v) (fun _ -> A.pts_to x full_perm v)
let test3_printf (m:UInt64.t) (l:UInt32.t) (x:A.array bool {A.length x == U32.v l}) (v: Ghost.erased (Seq.seq bool)) : STT unit (A.pts_to x full_perm v) (fun _ -> A.pts_to x full_perm v) = skip "Hello %b Steel.ST %uL Printf %xb %s" true //%b boolean m //%uL u64 l x //%xb (buffer bool) "bye" done
{ "file_name": "lib/steel/Steel.ST.Printf.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 18, "end_line": 579, "start_col": 0, "start_line": 572 }
(* Copyright 2008-2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Printf /// This module provides Steel.ST imperative printing functions for several /// primitive Low* types, including /// -- booleans (%b) /// -- characters (%c) /// -- strings (%s) /// -- machine integers /// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL; /// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L) /// -- and arrays of these base types formatted /// as %xN, where N is the format specifier for the array element type /// e.g., %xuy for buffers of UInt8.t /// The main function of this module is `printf` /// There are a few main differences relative to C printf /// -- The format specifiers are different (see above) /// /// -- For technical reasons explained below, an extra dummy /// argument `done` has to be provided at the end for the /// computation to have any effect. /// /// E.g., one must write /// `printf "%b %c" true 'c' done` /// rather than just /// `printf "%b %c" true 'c'` /// /// -- When printing arrays, two arguments must be passed; the /// length of the array fragment to be formatted and the array /// itself /// /// -- When extracted, rather than producing a C `printf` (which /// does not, e.g., support printing of dynamically sized /// arrays), our `printf` is specialized to a sequence of calls /// to primitive printers for each supported type /// /// Before diving into the technical details of how this module works, /// you might want to see a sample usage at the very end of this file. open FStar.Char open FStar.String open Steel.ST.Util module L = FStar.List.Tot module A = Steel.ST.Array module U32 = FStar.UInt32 #set-options "--ide_id_info_off" /// `lmbuffer a l` is /// - an array of `a` /// - governed by preorders `r` and `s` /// - with length `l` inline_for_extraction let lmbuffer a l = b: A.array a { A.length b == U32.v l } /// `StTrivial`: A effect abbreviation for a stateful computation /// with no precondition, and which does not read or change the state effect StTrivial (a:Type) = STT a emp (fun _ -> emp) /// `StBuf a b`: A effect abbreviation for a stateful computation /// that may read `b` but does not change the state /// /// NOTE: I need to provide those primitives operating on /// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise /// Karamel will complain about arity mismatch inline_for_extraction let stBuf (t:Type) : Type = (l: U32.t) -> (p: Ghost.erased (lmbuffer t l & perm)) -> (x: Ghost.erased (Seq.seq t)) -> (b: A.ptr t) -> ST unit (A.pts_to (fst p) (snd p) x) (fun _ -> A.pts_to (fst p) (snd p) x) (A.ptr_of (fst p) == b) (fun _ -> True) /// Primitive printers for all the types supported by this module assume val print_string: string -> StTrivial unit assume val print_char : char -> StTrivial unit assume val print_u8 : UInt8.t -> StTrivial unit assume val print_u16 : UInt16.t -> StTrivial unit assume val print_u32 : UInt32.t -> StTrivial unit assume val print_u64 : UInt64.t -> StTrivial unit assume val print_i8 : Int8.t -> StTrivial unit assume val print_i16 : Int16.t -> StTrivial unit assume val print_i32 : Int32.t -> StTrivial unit assume val print_i64 : Int64.t -> StTrivial unit assume val print_bool : bool -> StTrivial unit assume val print_lmbuffer_bool : stBuf bool assume val print_lmbuffer_char : stBuf char assume val print_lmbuffer_string : stBuf string assume val print_lmbuffer_u8 : stBuf UInt8.t assume val print_lmbuffer_u16 : stBuf UInt16.t assume val print_lmbuffer_u32 : stBuf UInt32.t assume val print_lmbuffer_u64 : stBuf UInt64.t assume val print_lmbuffer_i8 : stBuf Int8.t assume val print_lmbuffer_i16 : stBuf Int16.t assume val print_lmbuffer_i32 : stBuf Int32.t assume val print_lmbuffer_i64 : stBuf Int64.t /// An attribute to control reduction noextract irreducible let __printf_reduce__ = unit /// Base types supported so far noextract type base_typ = | Bool | Char | String | U8 | U16 | U32 | U64 | I8 | I16 | I32 | I64 /// Argument types are base types and arrays thereof /// Or polymorphic arguments specified by "%a" noextract type arg = | Base of base_typ | Array of base_typ | Any /// Interpreting a `base_typ` as a type [@@__printf_reduce__] noextract let base_typ_as_type (b:base_typ) : Type0 = match b with | Bool -> bool | Char -> char | String -> string | U8 -> FStar.UInt8.t | U16 -> FStar.UInt16.t | U32 -> FStar.UInt32.t | U64 -> FStar.UInt64.t | I8 -> FStar.Int8.t | I16 -> FStar.Int16.t | I32 -> FStar.Int32.t | I64 -> FStar.Int64.t /// `fragment`: A format string is parsed into a list of fragments of /// string literals and other arguments that need to be spliced in /// (interpolated) noextract type fragment = | Frag of string | Interpolate of arg noextract let fragments = list fragment /// `parse_format s`: /// Parses a list of characters in a format string into a list of fragments /// Or None, in case the format string is invalid [@@__printf_reduce__] noextract inline_for_extraction let rec parse_format (s:list char) : Tot (option fragments) (decreases (L.length s)) = let add_dir (d:arg) (ods : option fragments) = match ods with | None -> None | Some ds -> Some (Interpolate d::ds) in let head_buffer (ods:option fragments) = match ods with | Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest) | _ -> None in let cons_frag (c:char) (ods:option fragments) = match ods with | Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest) | Some rest -> Some (Frag (string_of_list [c]) :: rest) | _ -> None in match s with | [] -> Some [] | ['%'] -> None // %a... polymorphic arguments and preceded by their printers | '%' :: 'a' :: s' -> add_dir Any (parse_format s') // %x... arrays of base types | '%' :: 'x' :: s' -> head_buffer (parse_format ('%' :: s')) // %u ... Unsigned integers | '%' :: 'u' :: s' -> begin match s' with | 'y' :: s'' -> add_dir (Base U8) (parse_format s'') | 's' :: s'' -> add_dir (Base U16) (parse_format s'') | 'l' :: s'' -> add_dir (Base U32) (parse_format s'') | 'L' :: s'' -> add_dir (Base U64) (parse_format s'') | _ -> None end | '%' :: c :: s' -> begin match c with | '%' -> cons_frag '%' (parse_format s') | 'b' -> add_dir (Base Bool) (parse_format s') | 'c' -> add_dir (Base Char) (parse_format s') | 's' -> add_dir (Base String) (parse_format s') | 'y' -> add_dir (Base I8) (parse_format s') | 'i' -> add_dir (Base I16) (parse_format s') | 'l' -> add_dir (Base I32) (parse_format s') | 'L' -> add_dir (Base I64) (parse_format s') | _ -> None end | c :: s' -> cons_frag c (parse_format s') /// `parse_format_string`: a wrapper around `parse_format` [@@__printf_reduce__] noextract inline_for_extraction let parse_format_string (s:string) : option fragments = parse_format (list_of_string s) /// `lift a` lifts the type `a` to a higher universe noextract type lift (a:Type u#a) : Type u#(max a b) = | Lift : a -> lift a /// `done` is a `unit` in universe 1 noextract let done : lift unit = Lift u#0 u#1 () /// `arg_t`: interpreting an argument as a type /// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers. /// GM: Somehow, this needs to be a `let rec` (even if it not really recursive) /// or print_frags fails to verify. I don't know why; the generated /// VC and its encoding seem identical (modulo hash consing in the /// latter). [@@__printf_reduce__] noextract let rec arg_t (a:arg) : Type u#1 = match a with | Base t -> lift (base_typ_as_type t) | Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t))) | Any -> (a:Type0 & (a -> StTrivial unit) & a) /// `frag_t`: a fragment is either a string literal or a argument to be interpolated noextract let frag_t = either string (a:arg & arg_t a) /// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l` [@@__printf_reduce__; Steel.Effect.Common.__reduce__] noextract let live_frag0 (f: frag_t) : vprop = match f with | Inl _ -> emp | Inr a -> (match a with | (| Base _, _ |) -> emp | (| Any, _ |) -> emp | (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v) [@@__printf_reduce__] noextract let live_frag (f: frag_t) : vprop = live_frag0 f [@@__printf_reduce__] noextract let rec live_frags (l:list frag_t) : vprop = match l with | [] -> emp | a :: q -> live_frag a `star` live_frags q /// `interpret_frags` interprets a list of fragments as a Steel.ST function type /// Note `l` is the fragments in L-to-R order (i.e., parsing order) /// `acc` accumulates the fragment values in reverse order [@@__printf_reduce__] noextract let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 = match l with | [] -> // Always a dummy argument at the end // Ensures that all cases of this match // have the same universe, i.e., u#1 lift u#0 u#1 unit -> STT unit (live_frags acc) (fun _ -> live_frags acc) | Interpolate (Base t) :: args -> // Base types are simple: we just take one more argument x:base_typ_as_type t -> interpret_frags args (Inr (| Base t, Lift x |) :: acc) | Interpolate (Array t) :: args -> // Arrays are implicitly polymorphic in their preorders `r` and `s` // which is what forces us to be in universe 1 // Note, the length `l` is explicit l:UInt32.t -> #p:perm -> #v:Ghost.erased (Seq.seq (base_typ_as_type t)) -> b:lmbuffer (base_typ_as_type t) l -> interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) | Interpolate Any :: args -> #a:Type0 -> p:(a -> StTrivial unit) -> x:a -> interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc) | Frag s :: args -> // Literal fragments do not incur an additional argument // We just accumulate them and recur interpret_frags args (Inl s :: acc) /// `normal` A normalization marker with very specific steps enabled noextract unfold let normal (#a:Type) (x:a) : a = FStar.Pervasives.norm [iota; zeta; delta_attr [`%__printf_reduce__; `%BigOps.__reduce__]; delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string]; primops; simplify] x /// `coerce`: A utility to trigger extensional equality of types noextract let coerce (x:'a{'a == 'b}) : 'b = x /// `fragment_printer`: The type of a printer of fragments noextract let fragment_printer = (acc:list frag_t) -> STT unit (live_frags acc) (fun _ -> live_frags acc) /// `print_frags`: Having accumulated all the pieces of a format /// string and the arguments to the printed (i.e., the `list frag_t`), /// this function does the actual work of printing them all using the /// primitive printers noextract inline_for_extraction let print_lmbuffer_gen (#t: Type) (#fr: frag_t) (f: stBuf t) (l: U32.t) (#tb: Type) (b: tb) (p: perm) (#tv: Type) (v: tv) : ST unit (live_frag fr) (fun _ -> live_frag fr) (tb == lmbuffer t l /\ tv == Ghost.erased (Seq.seq t) /\ live_frag fr == A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v)) (fun _ -> True) = [@inline_let] let b' : lmbuffer t l = coerce b in let v' : Ghost.erased (Seq.seq t) = coerce v in let p' : Ghost.erased (lmbuffer t l & perm) = Ghost.hide (b', p) in rewrite (live_frag fr) (A.pts_to #t (fst p') (snd p') v'); f l _ _ (A.ptr_of b'); rewrite (A.pts_to _ _ _) (live_frag fr) noextract inline_for_extraction let print_frag (hd: frag_t) : STT unit (live_frag hd) (fun _ -> live_frag hd) = (match hd with | Inl s -> print_string s | Inr (| Base t, Lift value |) -> (match t with | Bool -> print_bool value | Char -> print_char value | String -> print_string value | U8 -> print_u8 value | U16 -> print_u16 value | U32 -> print_u32 value | U64 -> print_u64 value | I8 -> print_i8 value | I16 -> print_i16 value | I32 -> print_i32 value | I64 -> print_i64 value) | Inr (| Array t, Lift ((| l, value |), p, v ) |) -> (match t with | Bool -> print_lmbuffer_gen print_lmbuffer_bool l value p v | Char -> print_lmbuffer_gen print_lmbuffer_char l value p v | String -> print_lmbuffer_gen print_lmbuffer_string l value p v | U8 -> print_lmbuffer_gen print_lmbuffer_u8 l value p v | U16 -> print_lmbuffer_gen print_lmbuffer_u16 l value p v | U32 -> print_lmbuffer_gen print_lmbuffer_u32 l value p v | U64 -> print_lmbuffer_gen print_lmbuffer_u64 l value p v | I8 -> print_lmbuffer_gen print_lmbuffer_i8 l value p v | I16 -> print_lmbuffer_gen print_lmbuffer_i16 l value p v | I32 -> print_lmbuffer_gen print_lmbuffer_i32 l value p v | I64 -> print_lmbuffer_gen print_lmbuffer_i64 l value p v ) | Inr (| Any, (| _, printer, value |) |) -> printer value) noextract inline_for_extraction let rec print_frags (acc:list frag_t) : STT unit (live_frags acc) (fun _ -> live_frags acc) = match acc with | [] -> noop () | hd::tl -> rewrite (live_frags acc) (live_frag hd `star` live_frags tl); print_frags tl; print_frag hd; rewrite (live_frag hd `star` live_frags tl) (live_frags acc) [@@__printf_reduce__] let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f [@@__printf_reduce__] let elim_unit_arrow #t (f:unit -> t) : t = f () /// `aux frags acc`: This is the main workhorse which interprets a /// parsed format string (`frags`) as a variadic, stateful function [@@__printf_reduce__] noextract inline_for_extraction let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc = match frags with | [] -> let f (l:lift u#0 u#1 unit) : STT unit (live_frags acc) (fun _ -> live_frags acc) = fp acc in (f <: interpret_frags [] acc) | Frag s :: rest -> coerce (aux rest (Inl s :: acc) fp) | Interpolate (Base t) :: args -> let f (x:base_typ_as_type t) : interpret_frags args (Inr (| Base t, Lift x |) :: acc) = aux args (Inr (| Base t, Lift x |) :: acc) fp in f | Interpolate (Array t) :: rest -> let f : l:UInt32.t -> #p:perm -> #v:Ghost.erased (Seq.seq (base_typ_as_type t)) -> b:lmbuffer (base_typ_as_type t) l -> interpret_frags rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) = fun l #p #v b -> aux rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) fp in f <: interpret_frags (Interpolate (Array t) :: rest) acc | Interpolate Any :: rest -> let f : unit -> #a:Type -> p:(a -> StTrivial unit) -> x:a -> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc) = fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp in elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc)) /// `format_string` : A valid format string is one that can be successfully parsed [@@__printf_reduce__] noextract let format_string = s:string{normal #bool (Some? (parse_format_string s))} /// `interpret_format_string` parses a string into fragments and then /// interprets it as a type [@@__printf_reduce__] noextract let interpret_format_string (s:format_string) : Type = interpret_frags (Some?.v (parse_format_string s)) [] /// `printf'`: Almost there ... this has a variadic type /// and calls the actual printers for all its arguments. /// /// Note, the `normalize_term` in its body is crucial. It's what /// allows the term to be specialized at extraction time. noextract inline_for_extraction let printf' (s:format_string) : interpret_format_string s = normalize_term (match parse_format_string s with | Some frags -> aux frags [] print_frags) /// `intro_normal_f`: a technical gadget to introduce /// implicit normalization in the domain and co-domain of a function type noextract inline_for_extraction let intro_normal_f (#a:Type) (b: (a -> Type)) (f:(x:a -> b x)) : (x:(normal a) -> normal (b x)) = f /// `printf`: The main function has type /// `s:normal format_string -> normal (interpret_format_string s)` /// Note: /// This is the type F* infers for it and it is best to leave it that way /// rather then writing it down and asking F* to re-check what it inferred. /// /// Annotating it results in a needless additional proof obligation to /// equate types after they are partially reduced, which is pointless. noextract inline_for_extraction val printf : s:normal format_string -> normal (interpret_format_string s) let printf = intro_normal_f #format_string interpret_format_string printf' /// `skip`: We also provide `skip`, a function that has the same type as printf /// but normalizes to `()`, i.e., it prints nothing. This is useful for conditional /// printing in debug code, for instance. noextract inline_for_extraction let skip' (s:format_string) : interpret_format_string s = normalize_term (match parse_format_string s with | Some frags -> aux frags [] (fun _ -> noop ())) noextract inline_for_extraction val skip : s:normal format_string -> normal (interpret_format_string s) let skip = intro_normal_f #format_string interpret_format_string skip' /// `test`: A small test function /// Running `fstar --codegen OCaml Steel.ST.Printf.fst --extract Steel.ST.Printf` /// produces the following for the body of this function /// ``` /// print_string "Hello "; /// print_bool true; /// print_string " Steel.ST "; /// print_u64 m; /// print_string " Printf "; /// print_lmbuffer_bool l x () (); /// print_string " "; /// print_string "bye" /// ``` let test_printf (m:UInt64.t) (l:UInt32.t) (x:A.array bool {A.length x == U32.v l}) (v: Ghost.erased (Seq.seq bool)) : STT unit (A.pts_to x full_perm v) (fun _ -> A.pts_to x full_perm v) = printf "Hello %b Steel.ST %uL Printf %xb %s" true //%b boolean m //%uL u64 l x //%xb (buffer bool) "bye" done //dummy universe coercion let test2_printf (x:(int * int)) (print_pair:(int * int) -> StTrivial unit) : STT unit emp (fun _ -> emp) = printf "Hello pair %a" print_pair x done
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.Array.fsti.checked", "Steel.Effect.Common.fsti.checked", "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.String.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Char.fsti.checked", "FStar.BigOps.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.Printf.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Steel.ST.Array", "short_module": "A" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.String", "short_module": null }, { "abbrev": false, "full_module": "FStar.Char", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: FStar.UInt64.t -> l: FStar.UInt32.t -> x: Steel.ST.Array.array Prims.bool {Steel.ST.Array.length x == FStar.UInt32.v l} -> v: FStar.Ghost.erased (FStar.Seq.Base.seq Prims.bool) -> Steel.ST.Effect.STT Prims.unit
Steel.ST.Effect.STT
[]
[]
[ "FStar.UInt64.t", "FStar.UInt32.t", "Steel.ST.Array.array", "Prims.bool", "Prims.eq2", "Prims.int", "Prims.l_or", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "Steel.ST.Array.length", "FStar.UInt32.v", "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Steel.ST.Printf.skip", "Steel.FractionalPermission.full_perm", "Steel.ST.Printf.done", "Prims.unit", "Steel.ST.Array.pts_to", "FStar.Ghost.reveal", "Steel.Effect.Common.vprop" ]
[]
false
true
false
false
false
let test3_printf (m: UInt64.t) (l: UInt32.t) (x: A.array bool {A.length x == U32.v l}) (v: Ghost.erased (Seq.seq bool)) : STT unit (A.pts_to x full_perm v) (fun _ -> A.pts_to x full_perm v) =
skip "Hello %b Steel.ST %uL Printf %xb %s" true m l x "bye" done
false
LowParse.SLow.BoundedInt.fsti
LowParse.SLow.BoundedInt.serialize32_bounded_int32_le
val serialize32_bounded_int32_le (min32: U32.t) (max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296}) : Tot (serializer32 (serialize_bounded_int32_le (U32.v min32) (U32.v max32)))
val serialize32_bounded_int32_le (min32: U32.t) (max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296}) : Tot (serializer32 (serialize_bounded_int32_le (U32.v min32) (U32.v max32)))
let serialize32_bounded_int32_le (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) : Tot (serializer32 (serialize_bounded_int32_le (U32.v min32) (U32.v max32))) = fun input -> ( if max32 `U32.lt` 256ul then serialize32_bounded_int32_le_1 min32 max32 input else if max32 `U32.lt` 65536ul then serialize32_bounded_int32_le_2 min32 max32 input else if max32 `U32.lt` 16777216ul then serialize32_bounded_int32_le_3 min32 max32 input else serialize32_bounded_int32_le_4 min32 max32 input )
{ "file_name": "src/lowparse/LowParse.SLow.BoundedInt.fsti", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 272, "start_col": 0, "start_line": 260 }
module LowParse.SLow.BoundedInt include LowParse.Spec.BoundedInt include LowParse.SLow.Base (* bounded integers *) inline_for_extraction val parse32_bounded_integer_1 : (parser32 (parse_bounded_integer 1)) inline_for_extraction val parse32_bounded_integer_2 : (parser32 (parse_bounded_integer 2)) inline_for_extraction val parse32_bounded_integer_3 : (parser32 (parse_bounded_integer 3)) inline_for_extraction val parse32_bounded_integer_4 : (parser32 (parse_bounded_integer 4)) inline_for_extraction noextract let parse32_bounded_integer (sz: integer_size) : Tot (parser32 (parse_bounded_integer sz)) = match sz with | 1 -> parse32_bounded_integer_1 | 2 -> parse32_bounded_integer_2 | 3 -> parse32_bounded_integer_3 | 4 -> parse32_bounded_integer_4 inline_for_extraction val serialize32_bounded_integer_1 : (serializer32 (serialize_bounded_integer 1)) inline_for_extraction val serialize32_bounded_integer_2 : (serializer32 (serialize_bounded_integer 2)) inline_for_extraction val serialize32_bounded_integer_3 : (serializer32 (serialize_bounded_integer 3)) inline_for_extraction val serialize32_bounded_integer_4 : (serializer32 (serialize_bounded_integer 4)) inline_for_extraction noextract let serialize32_bounded_integer (sz: integer_size) : Tot (serializer32 (serialize_bounded_integer sz)) = match sz with | 1 -> serialize32_bounded_integer_1 | 2 -> serialize32_bounded_integer_2 | 3 -> serialize32_bounded_integer_3 | 4 -> serialize32_bounded_integer_4 #push-options "--max_fuel 0" inline_for_extraction val parse32_bounded_integer_le_1 : parser32 (parse_bounded_integer_le 1) inline_for_extraction val parse32_bounded_integer_le_2 : parser32 (parse_bounded_integer_le 2) inline_for_extraction val parse32_bounded_integer_le_3 : parser32 (parse_bounded_integer_le 3) inline_for_extraction val parse32_bounded_integer_le_4 : parser32 (parse_bounded_integer_le 4) inline_for_extraction noextract let parse32_bounded_integer_le (sz: integer_size) : Tot (parser32 (parse_bounded_integer_le sz)) = match sz with | 1 -> parse32_bounded_integer_le_1 | 2 -> parse32_bounded_integer_le_2 | 3 -> parse32_bounded_integer_le_3 | 4 -> parse32_bounded_integer_le_4 inline_for_extraction val parse32_u16_le : parser32 parse_u16_le inline_for_extraction val parse32_u32_le : parser32 parse_u32_le #pop-options inline_for_extraction val serialize32_bounded_integer_le_1 : serializer32 (serialize_bounded_integer_le 1) inline_for_extraction val serialize32_bounded_integer_le_2 : serializer32 (serialize_bounded_integer_le 2) inline_for_extraction val serialize32_bounded_integer_le_3 : serializer32 (serialize_bounded_integer_le 3) inline_for_extraction val serialize32_bounded_integer_le_4 : serializer32 (serialize_bounded_integer_le 4) inline_for_extraction noextract let serialize32_bounded_integer_le (sz: integer_size) : Tot (serializer32 (serialize_bounded_integer_le sz)) = match sz with | 1 -> serialize32_bounded_integer_le_1 | 2 -> serialize32_bounded_integer_le_2 | 3 -> serialize32_bounded_integer_le_3 | 4 -> serialize32_bounded_integer_le_4 inline_for_extraction val serialize32_u16_le : serializer32 serialize_u16_le inline_for_extraction val serialize32_u32_le : serializer32 serialize_u32_le inline_for_extraction let size32_u16_le: size32 serialize_u16_le = assert_norm (size32_constant_precond serialize_u16_le 2ul); size32_constant serialize_u16_le 2ul () inline_for_extraction let size32_u32_le: size32 serialize_u32_le = assert_norm (size32_constant_precond serialize_u32_le 4ul); size32_constant serialize_u32_le 4ul () module U32 = FStar.UInt32 val parse32_bounded_int32_1 (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 256 }) : Tot (parser32 (parse_bounded_int32 (U32.v min32) (U32.v max32))) val parse32_bounded_int32_2 (min32: U32.t) (max32: U32.t { 256 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 65536 }) : Tot (parser32 (parse_bounded_int32 (U32.v min32) (U32.v max32))) val parse32_bounded_int32_3 (min32: U32.t) (max32: U32.t { 65536 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 16777216 }) : Tot (parser32 (parse_bounded_int32 (U32.v min32) (U32.v max32))) val parse32_bounded_int32_4 (min32: U32.t) (max32: U32.t { 16777216 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) : Tot (parser32 (parse_bounded_int32 (U32.v min32) (U32.v max32))) inline_for_extraction let parse32_bounded_int32 (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) : Tot (parser32 (parse_bounded_int32 (U32.v min32) (U32.v max32))) = fun input -> ( if max32 `U32.lt` 256ul then parse32_bounded_int32_1 min32 max32 input else if max32 `U32.lt` 65536ul then parse32_bounded_int32_2 min32 max32 input else if max32 `U32.lt` 16777216ul then parse32_bounded_int32_3 min32 max32 input else parse32_bounded_int32_4 min32 max32 input ) val serialize32_bounded_int32_1 (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 256 }) : Tot (serializer32 (serialize_bounded_int32 (U32.v min32) (U32.v max32))) val serialize32_bounded_int32_2 (min32: U32.t) (max32: U32.t { 256 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 65536 }) : Tot (serializer32 (serialize_bounded_int32 (U32.v min32) (U32.v max32))) val serialize32_bounded_int32_3 (min32: U32.t) (max32: U32.t { 65536 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 16777216 }) : Tot (serializer32 (serialize_bounded_int32 (U32.v min32) (U32.v max32))) val serialize32_bounded_int32_4 (min32: U32.t) (max32: U32.t { 16777216 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) : Tot (serializer32 (serialize_bounded_int32 (U32.v min32) (U32.v max32))) inline_for_extraction let serialize32_bounded_int32 (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) : Tot (serializer32 (serialize_bounded_int32 (U32.v min32) (U32.v max32))) = fun input -> ( if max32 `U32.lt` 256ul then serialize32_bounded_int32_1 min32 max32 input else if max32 `U32.lt` 65536ul then serialize32_bounded_int32_2 min32 max32 input else if max32 `U32.lt` 16777216ul then serialize32_bounded_int32_3 min32 max32 input else serialize32_bounded_int32_4 min32 max32 input ) val parse32_bounded_int32_le_1 (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 256 }) : Tot (parser32 (parse_bounded_int32_le (U32.v min32) (U32.v max32))) val parse32_bounded_int32_le_2 (min32: U32.t) (max32: U32.t { 256 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 65536 }) : Tot (parser32 (parse_bounded_int32_le (U32.v min32) (U32.v max32))) val parse32_bounded_int32_le_3 (min32: U32.t) (max32: U32.t { 65536 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 16777216 }) : Tot (parser32 (parse_bounded_int32_le (U32.v min32) (U32.v max32))) val parse32_bounded_int32_le_4 (min32: U32.t) (max32: U32.t { 16777216 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) : Tot (parser32 (parse_bounded_int32_le (U32.v min32) (U32.v max32))) inline_for_extraction let parse32_bounded_int32_le (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) : Tot (parser32 (parse_bounded_int32_le (U32.v min32) (U32.v max32))) = fun input -> ( if max32 `U32.lt` 256ul then parse32_bounded_int32_le_1 min32 max32 input else if max32 `U32.lt` 65536ul then parse32_bounded_int32_le_2 min32 max32 input else if max32 `U32.lt` 16777216ul then parse32_bounded_int32_le_3 min32 max32 input else parse32_bounded_int32_le_4 min32 max32 input ) val serialize32_bounded_int32_le_1 (min32: U32.t) (max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 256 }) : Tot (serializer32 (serialize_bounded_int32_le (U32.v min32) (U32.v max32))) val serialize32_bounded_int32_le_2 (min32: U32.t) (max32: U32.t { 256 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 65536 }) : Tot (serializer32 (serialize_bounded_int32_le (U32.v min32) (U32.v max32))) val serialize32_bounded_int32_le_3 (min32: U32.t) (max32: U32.t { 65536 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 16777216 }) : Tot (serializer32 (serialize_bounded_int32_le (U32.v min32) (U32.v max32))) val serialize32_bounded_int32_le_4 (min32: U32.t) (max32: U32.t { 16777216 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 }) : Tot (serializer32 (serialize_bounded_int32_le (U32.v min32) (U32.v max32)))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.BoundedInt.fsti.checked", "LowParse.SLow.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.BoundedInt.fsti" }
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.SLow.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min32: FStar.UInt32.t -> max32: FStar.UInt32.t { 0 < FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\ FStar.UInt32.v max32 < 4294967296 } -> LowParse.SLow.Base.serializer32 (LowParse.Spec.BoundedInt.serialize_bounded_int32_le (FStar.UInt32.v min32) (FStar.UInt32.v max32))
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "Prims.op_LessThanOrEqual", "LowParse.Spec.BoundedInt.bounded_int32", "FStar.UInt32.lt", "FStar.UInt32.__uint_to_t", "LowParse.SLow.BoundedInt.serialize32_bounded_int32_le_1", "Prims.bool", "LowParse.SLow.BoundedInt.serialize32_bounded_int32_le_2", "LowParse.SLow.BoundedInt.serialize32_bounded_int32_le_3", "LowParse.SLow.BoundedInt.serialize32_bounded_int32_le_4", "LowParse.SLow.Base.bytes32", "LowParse.SLow.Base.serializer32_correct", "LowParse.Spec.BoundedInt.parse_bounded_int32_kind", "LowParse.Spec.BoundedInt.parse_bounded_int32_le", "LowParse.Spec.BoundedInt.serialize_bounded_int32_le", "LowParse.SLow.Base.serializer32" ]
[]
false
false
false
false
false
let serialize32_bounded_int32_le (min32: U32.t) (max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296}) : Tot (serializer32 (serialize_bounded_int32_le (U32.v min32) (U32.v max32))) =
fun input -> (if max32 `U32.lt` 256ul then serialize32_bounded_int32_le_1 min32 max32 input else if max32 `U32.lt` 65536ul then serialize32_bounded_int32_le_2 min32 max32 input else if max32 `U32.lt` 16777216ul then serialize32_bounded_int32_le_3 min32 max32 input else serialize32_bounded_int32_le_4 min32 max32 input)
false
HaclExample2.fst
HaclExample2.test_alloc_free
val test_alloc_free: Prims.unit -> STT unit emp (fun _ -> emp)
val test_alloc_free: Prims.unit -> STT unit emp (fun _ -> emp)
let test_alloc_free () : STT unit emp (fun _ -> emp) = let a = array_alloc (scalar bool) 42sz in let _ = gen_elim () in if array_is_null a then begin rewrite (array_pts_to_or_null _ _) emp; rewrite (freeable_or_null_array _) emp; noop () end else begin let s = vpattern_replace (array_pts_to_or_null _) in rewrite (array_pts_to_or_null _ _) (array_pts_to a s); rewrite (freeable_or_null_array _) (freeable_array a); array_free a end
{ "file_name": "share/steel/examples/steelc/HaclExample2.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 5, "end_line": 100, "start_col": 0, "start_line": 82 }
module HaclExample2 open Steel.ST.GenElim open Steel.ST.C.Types open Steel.C.Typenat open Steel.C.Typestring module SZ = FStar.SizeT module U64 = FStar.UInt64 (** In this file we demonstrate how Steel could be used to manipulate the following data type used in Hacl*: https://github.com/project-everest/hacl-star/blob/master/code/poly1305/Hacl.Impl.Poly1305.fsti#L18 This Low* definition amounts to the struct definition struct poly1305_ctx { uint64_t limbs[5]; uint64_t precomp[20]; }; and, with our new model of structs and arrays and pointer-to-field, can be expresesd directly in Steel. See PointStruct.fst for more detailed explanations of the various definitions needed below. *) noextract inline_for_extraction let five = normalize (nat_t_of_nat 5) noextract inline_for_extraction let twenty = normalize (nat_t_of_nat 20) noextract inline_for_extraction let comp_name = normalize (mk_string_t "HaclExample2.comp") noextract inline_for_extraction [@@norm_field_attr] let comp_fields = field_description_cons "limbs" (base_array0 five (scalar U64.t) 5sz) ( field_description_cons "precomp" (base_array0 twenty (scalar U64.t) 20sz) ( field_description_nil )) noextract inline_for_extraction let comp = struct0 comp_name "HaclExample2.comp" comp_fields let _ = define_struct0 comp_name "HaclExample2.comp" comp_fields (** To demonstrate how our model could be used, we write a simple function that takes pointers to the limbs and precomp fields and passes them to helper functions (which in this case simply set on element of the corresponding array to zero) *) let do_something_with_limbs (#v: Ghost.erased (Seq.seq (scalar_t U64.t))) (a: array (scalar U64.t)) : ST (Ghost.erased (Seq.seq (scalar_t U64.t))) (array_pts_to a v) (fun v' -> array_pts_to a v') (requires array_length a == 5 /\ full_seq (scalar U64.t) v ) (ensures (fun v' -> full_seq (scalar U64.t) v' )) = let p = array_cell a 2sz in write p 0uL; unarray_cell _ _ _; drop (has_array_cell _ _ _); return _ let do_something_with_precomp (#v: Ghost.erased (Seq.seq (scalar_t U64.t))) (a: array (scalar U64.t)) : ST (ptr (scalar U64.t)) (array_pts_to a v) (fun _ -> exists_ (fun (v': Seq.seq (scalar_t U64.t)) -> array_pts_to a v' `star` pure (full_seq (scalar U64.t) v') )) (requires array_length a == 20 /\ full_seq (scalar U64.t) v ) (ensures fun _ -> True) = let p = array_cell a 19sz in write p 0uL; unarray_cell _ _ _; drop (has_array_cell _ _ _); noop (); return (null _)
{ "checked_file": "/", "dependencies": [ "Steel.ST.GenElim.fsti.checked", "Steel.ST.C.Types.fst.checked", "Steel.C.Typestring.fsti.checked", "Steel.C.Typenat.fsti.checked", "prims.fst.checked", "FStar.UInt64.fsti.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "HaclExample2.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "SZ" }, { "abbrev": false, "full_module": "Steel.C.Typestring", "short_module": null }, { "abbrev": false, "full_module": "Steel.C.Typenat", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.C.Types", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenElim", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> Steel.ST.Effect.STT Prims.unit
Steel.ST.Effect.STT
[]
[]
[ "Prims.unit", "Steel.ST.Util.noop", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.ST.Util.rewrite", "Steel.ST.C.Types.Array.freeable_or_null_array", "Steel.ST.C.Types.Scalar.scalar_t", "Prims.bool", "Steel.ST.C.Types.Scalar.scalar", "Steel.Effect.Common.emp", "Steel.ST.C.Types.Array.array_pts_to_or_null", "FStar.Ghost.reveal", "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Steel.ST.C.Types.Array.array_free", "Steel.ST.C.Types.Array.freeable_array", "Steel.ST.C.Types.Array.array_pts_to", "Steel.ST.Util.vpattern_replace", "Steel.ST.C.Types.Array.array_is_null", "Steel.ST.GenElim.gen_elim", "Steel.Effect.Common.VStar", "Steel.ST.Util.exists_", "Steel.ST.Util.pure", "Prims.l_and", "Prims.l_imp", "Prims.eq2", "Steel.ST.C.Types.Array.g_array_is_null", "Prims.nat", "Steel.ST.C.Types.Array.array_length", "FStar.Seq.Base.create", "Steel.ST.C.Types.Base.uninitialized", "Steel.Effect.Common.vprop", "Steel.Effect.Common.star", "Prims.l_True", "Prims.prop", "Steel.ST.C.Types.Array.array_or_null", "Steel.ST.C.Types.Array.array_alloc", "FStar.SizeT.__uint_to_t" ]
[]
false
true
false
false
false
let test_alloc_free () : STT unit emp (fun _ -> emp) =
let a = array_alloc (scalar bool) 42sz in let _ = gen_elim () in if array_is_null a then (rewrite (array_pts_to_or_null _ _) emp; rewrite (freeable_or_null_array _) emp; noop ()) else let s = vpattern_replace (array_pts_to_or_null _) in rewrite (array_pts_to_or_null _ _) (array_pts_to a s); rewrite (freeable_or_null_array _) (freeable_array a); array_free a
false
OPLSS2021.Vale.fst
OPLSS2021.Vale.pow2_64
val pow2_64 : Prims.int
let pow2_64 = 0x10000000000000000
{ "file_name": "examples/oplss2021/OPLSS2021.Vale.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 33, "end_line": 33, "start_col": 0, "start_line": 33 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul //suppress a benign warning in this program #push-options "--warn_error -290" (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.Vale.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.int
Prims.Tot
[ "total" ]
[]
[]
[]
false
false
false
true
false
let pow2_64 =
0x10000000000000000
false
OPLSS2021.Vale.fst
OPLSS2021.Vale.update_state
val update_state (r: reg) (s' s: state) : state
val update_state (r: reg) (s' s: state) : state
let update_state (r:reg) (s' s:state) : state = update_reg s r (s' r)
{ "file_name": "examples/oplss2021/OPLSS2021.Vale.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 23, "end_line": 86, "start_col": 0, "start_line": 85 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul //suppress a benign warning in this program #push-options "--warn_error -290" (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// 2^64 let pow2_64 = 0x10000000000000000 /// Natural numbers representable in 64 bits type nat64 = i:int{0 <= i /\ i < pow2_64} /// We have 4 registers type reg = | Rax | Rbx | Rcx | Rdx /// An operand is either a register or a constant type operand = | OReg: r:reg -> operand | OConst: n:nat64 -> operand /// Only 2 instructions here: /// A move or an add type ins = | Mov64: dst:operand -> src:operand -> ins | Add64: dst:operand -> src:operand -> ins /// A program is /// - a single instruction /// - a block of instructions /// - or a while loop type code = | Ins: ins:ins -> code | Block: block:list code -> code | WhileLessThan: src1:operand -> src2:operand -> whileBody:code -> code /// The state of a program is the register file /// holiding a 64-bit value for each register type state = reg -> nat64 /// fuel: To prove the termination of while loops, we're going to /// instrument while loops with fuel type fuel = nat /// Evaluating an operand: /// -- marked for reduction /// -- Registers evaluated by state lookup let eval_operand (o:operand) (s:state) : nat64 = match o with | OReg r -> s r | OConst n -> n /// updating a register state `s` at `r` with `v` let update_reg (s:state) (r:reg) (v:nat64) : state = fun r' -> if r = r' then v else s r' /// updating a register state `s` at `r` with `s' r`
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.Vale.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: OPLSS2021.Vale.reg -> s': OPLSS2021.Vale.state -> s: OPLSS2021.Vale.state -> OPLSS2021.Vale.state
Prims.Tot
[ "total" ]
[]
[ "OPLSS2021.Vale.reg", "OPLSS2021.Vale.state", "OPLSS2021.Vale.update_reg" ]
[]
false
false
false
true
false
let update_state (r: reg) (s' s: state) : state =
update_reg s r (s' r)
false
OPLSS2021.Vale.fst
OPLSS2021.Vale.eval_ins
val eval_ins (ins: ins) (s: state) : state
val eval_ins (ins: ins) (s: state) : state
let eval_ins (ins:ins) (s:state) : state = match ins with | Mov64 (OConst _) _ -> unknown_state s | Mov64 (OReg dst) src -> update_reg s dst (eval_operand src s) | Add64 (OConst _) _ -> unknown_state s | Add64 (OReg dst) src -> update_reg s dst ((s dst + eval_operand src s) % 0x10000000000000000)
{ "file_name": "examples/oplss2021/OPLSS2021.Vale.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 73, "end_line": 110, "start_col": 0, "start_line": 98 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul //suppress a benign warning in this program #push-options "--warn_error -290" (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// 2^64 let pow2_64 = 0x10000000000000000 /// Natural numbers representable in 64 bits type nat64 = i:int{0 <= i /\ i < pow2_64} /// We have 4 registers type reg = | Rax | Rbx | Rcx | Rdx /// An operand is either a register or a constant type operand = | OReg: r:reg -> operand | OConst: n:nat64 -> operand /// Only 2 instructions here: /// A move or an add type ins = | Mov64: dst:operand -> src:operand -> ins | Add64: dst:operand -> src:operand -> ins /// A program is /// - a single instruction /// - a block of instructions /// - or a while loop type code = | Ins: ins:ins -> code | Block: block:list code -> code | WhileLessThan: src1:operand -> src2:operand -> whileBody:code -> code /// The state of a program is the register file /// holiding a 64-bit value for each register type state = reg -> nat64 /// fuel: To prove the termination of while loops, we're going to /// instrument while loops with fuel type fuel = nat /// Evaluating an operand: /// -- marked for reduction /// -- Registers evaluated by state lookup let eval_operand (o:operand) (s:state) : nat64 = match o with | OReg r -> s r | OConst n -> n /// updating a register state `s` at `r` with `v` let update_reg (s:state) (r:reg) (v:nat64) : state = fun r' -> if r = r' then v else s r' /// updating a register state `s` at `r` with `s' r` let update_state (r:reg) (s' s:state) : state = update_reg s r (s' r) /// We don't have an "ok" flag, so errors just result an arbitrary state: assume val unknown_state (s:state) : state (*** A basic semantics using a big-step interpreter ***) /// Instruction evaluation:
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.Vale.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ins: OPLSS2021.Vale.ins -> s: OPLSS2021.Vale.state -> OPLSS2021.Vale.state
Prims.Tot
[ "total" ]
[]
[ "OPLSS2021.Vale.ins", "OPLSS2021.Vale.state", "OPLSS2021.Vale.nat64", "OPLSS2021.Vale.operand", "OPLSS2021.Vale.unknown_state", "OPLSS2021.Vale.reg", "OPLSS2021.Vale.update_reg", "OPLSS2021.Vale.eval_operand", "Prims.op_Modulus", "Prims.op_Addition" ]
[]
false
false
false
true
false
let eval_ins (ins: ins) (s: state) : state =
match ins with | Mov64 (OConst _) _ -> unknown_state s | Mov64 (OReg dst) src -> update_reg s dst (eval_operand src s) | Add64 (OConst _) _ -> unknown_state s | Add64 (OReg dst) src -> update_reg s dst ((s dst + eval_operand src s) % 0x10000000000000000)
false
OPLSS2021.Vale.fst
OPLSS2021.Vale.eval_code
val eval_code (c: code) (f: fuel) (s: state) : option state
val eval_code (c: code) (f: fuel) (s: state) : option state
let rec eval_code (c:code) (f:fuel) (s:state) : option state = match c with | Ins ins -> Some (eval_ins ins s) | Block cs -> eval_codes cs f s | WhileLessThan src1 src2 body -> if f = 0 then None else if eval_operand src1 s < eval_operand src2 s then match eval_code body f s with | None -> None | Some s -> eval_code c (f - 1) s else Some s and eval_codes (cs:list code) (f:fuel) (s:state) : option state = match cs with | [] -> Some s | c::cs -> match eval_code c f s with | None -> None | Some s -> eval_codes cs f s
{ "file_name": "examples/oplss2021/OPLSS2021.Vale.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 35, "end_line": 139, "start_col": 0, "start_line": 115 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul //suppress a benign warning in this program #push-options "--warn_error -290" (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// 2^64 let pow2_64 = 0x10000000000000000 /// Natural numbers representable in 64 bits type nat64 = i:int{0 <= i /\ i < pow2_64} /// We have 4 registers type reg = | Rax | Rbx | Rcx | Rdx /// An operand is either a register or a constant type operand = | OReg: r:reg -> operand | OConst: n:nat64 -> operand /// Only 2 instructions here: /// A move or an add type ins = | Mov64: dst:operand -> src:operand -> ins | Add64: dst:operand -> src:operand -> ins /// A program is /// - a single instruction /// - a block of instructions /// - or a while loop type code = | Ins: ins:ins -> code | Block: block:list code -> code | WhileLessThan: src1:operand -> src2:operand -> whileBody:code -> code /// The state of a program is the register file /// holiding a 64-bit value for each register type state = reg -> nat64 /// fuel: To prove the termination of while loops, we're going to /// instrument while loops with fuel type fuel = nat /// Evaluating an operand: /// -- marked for reduction /// -- Registers evaluated by state lookup let eval_operand (o:operand) (s:state) : nat64 = match o with | OReg r -> s r | OConst n -> n /// updating a register state `s` at `r` with `v` let update_reg (s:state) (r:reg) (v:nat64) : state = fun r' -> if r = r' then v else s r' /// updating a register state `s` at `r` with `s' r` let update_state (r:reg) (s' s:state) : state = update_reg s r (s' r) /// We don't have an "ok" flag, so errors just result an arbitrary state: assume val unknown_state (s:state) : state (*** A basic semantics using a big-step interpreter ***) /// Instruction evaluation: /// only some operands are valid let eval_ins (ins:ins) (s:state) : state = match ins with | Mov64 (OConst _) _ -> unknown_state s | Mov64 (OReg dst) src -> update_reg s dst (eval_operand src s) | Add64 (OConst _) _ -> unknown_state s | Add64 (OReg dst) src -> update_reg s dst ((s dst + eval_operand src s) % 0x10000000000000000) /// eval_code: /// A fueled big-step interpreter
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.Vale.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: OPLSS2021.Vale.code -> f: OPLSS2021.Vale.fuel -> s: OPLSS2021.Vale.state -> FStar.Pervasives.Native.option OPLSS2021.Vale.state
Prims.Tot
[ "total" ]
[ "eval_code", "eval_codes" ]
[ "OPLSS2021.Vale.code", "OPLSS2021.Vale.fuel", "OPLSS2021.Vale.state", "OPLSS2021.Vale.ins", "FStar.Pervasives.Native.Some", "OPLSS2021.Vale.eval_ins", "Prims.list", "OPLSS2021.Vale.eval_codes", "OPLSS2021.Vale.operand", "Prims.op_Equality", "Prims.int", "FStar.Pervasives.Native.None", "Prims.bool", "Prims.op_LessThan", "OPLSS2021.Vale.eval_operand", "OPLSS2021.Vale.eval_code", "Prims.op_Subtraction", "FStar.Pervasives.Native.option" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec eval_code (c: code) (f: fuel) (s: state) : option state =
match c with | Ins ins -> Some (eval_ins ins s) | Block cs -> eval_codes cs f s | WhileLessThan src1 src2 body -> if f = 0 then None else if eval_operand src1 s < eval_operand src2 s then match eval_code body f s with | None -> None | Some s -> eval_code c (f - 1) s else Some s
false
OPLSS2021.Vale.fst
OPLSS2021.Vale.eval_codes
val eval_codes (cs: list code) (f: fuel) (s: state) : option state
val eval_codes (cs: list code) (f: fuel) (s: state) : option state
let rec eval_code (c:code) (f:fuel) (s:state) : option state = match c with | Ins ins -> Some (eval_ins ins s) | Block cs -> eval_codes cs f s | WhileLessThan src1 src2 body -> if f = 0 then None else if eval_operand src1 s < eval_operand src2 s then match eval_code body f s with | None -> None | Some s -> eval_code c (f - 1) s else Some s and eval_codes (cs:list code) (f:fuel) (s:state) : option state = match cs with | [] -> Some s | c::cs -> match eval_code c f s with | None -> None | Some s -> eval_codes cs f s
{ "file_name": "examples/oplss2021/OPLSS2021.Vale.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 35, "end_line": 139, "start_col": 0, "start_line": 115 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul //suppress a benign warning in this program #push-options "--warn_error -290" (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// 2^64 let pow2_64 = 0x10000000000000000 /// Natural numbers representable in 64 bits type nat64 = i:int{0 <= i /\ i < pow2_64} /// We have 4 registers type reg = | Rax | Rbx | Rcx | Rdx /// An operand is either a register or a constant type operand = | OReg: r:reg -> operand | OConst: n:nat64 -> operand /// Only 2 instructions here: /// A move or an add type ins = | Mov64: dst:operand -> src:operand -> ins | Add64: dst:operand -> src:operand -> ins /// A program is /// - a single instruction /// - a block of instructions /// - or a while loop type code = | Ins: ins:ins -> code | Block: block:list code -> code | WhileLessThan: src1:operand -> src2:operand -> whileBody:code -> code /// The state of a program is the register file /// holiding a 64-bit value for each register type state = reg -> nat64 /// fuel: To prove the termination of while loops, we're going to /// instrument while loops with fuel type fuel = nat /// Evaluating an operand: /// -- marked for reduction /// -- Registers evaluated by state lookup let eval_operand (o:operand) (s:state) : nat64 = match o with | OReg r -> s r | OConst n -> n /// updating a register state `s` at `r` with `v` let update_reg (s:state) (r:reg) (v:nat64) : state = fun r' -> if r = r' then v else s r' /// updating a register state `s` at `r` with `s' r` let update_state (r:reg) (s' s:state) : state = update_reg s r (s' r) /// We don't have an "ok" flag, so errors just result an arbitrary state: assume val unknown_state (s:state) : state (*** A basic semantics using a big-step interpreter ***) /// Instruction evaluation: /// only some operands are valid let eval_ins (ins:ins) (s:state) : state = match ins with | Mov64 (OConst _) _ -> unknown_state s | Mov64 (OReg dst) src -> update_reg s dst (eval_operand src s) | Add64 (OConst _) _ -> unknown_state s | Add64 (OReg dst) src -> update_reg s dst ((s dst + eval_operand src s) % 0x10000000000000000) /// eval_code: /// A fueled big-step interpreter
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.Vale.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cs: Prims.list OPLSS2021.Vale.code -> f: OPLSS2021.Vale.fuel -> s: OPLSS2021.Vale.state -> FStar.Pervasives.Native.option OPLSS2021.Vale.state
Prims.Tot
[ "total" ]
[ "eval_code", "eval_codes" ]
[ "Prims.list", "OPLSS2021.Vale.code", "OPLSS2021.Vale.fuel", "OPLSS2021.Vale.state", "FStar.Pervasives.Native.Some", "OPLSS2021.Vale.eval_code", "FStar.Pervasives.Native.None", "OPLSS2021.Vale.eval_codes", "FStar.Pervasives.Native.option" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec eval_codes (cs: list code) (f: fuel) (s: state) : option state =
match cs with | [] -> Some s | c :: cs -> match eval_code c f s with | None -> None | Some s -> eval_codes cs f s
false
OPLSS2021.Vale.fst
OPLSS2021.Vale.eval_operand
val eval_operand (o: operand) (s: state) : nat64
val eval_operand (o: operand) (s: state) : nat64
let eval_operand (o:operand) (s:state) : nat64 = match o with | OReg r -> s r | OConst n -> n
{ "file_name": "examples/oplss2021/OPLSS2021.Vale.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 76, "start_col": 0, "start_line": 73 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul //suppress a benign warning in this program #push-options "--warn_error -290" (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// 2^64 let pow2_64 = 0x10000000000000000 /// Natural numbers representable in 64 bits type nat64 = i:int{0 <= i /\ i < pow2_64} /// We have 4 registers type reg = | Rax | Rbx | Rcx | Rdx /// An operand is either a register or a constant type operand = | OReg: r:reg -> operand | OConst: n:nat64 -> operand /// Only 2 instructions here: /// A move or an add type ins = | Mov64: dst:operand -> src:operand -> ins | Add64: dst:operand -> src:operand -> ins /// A program is /// - a single instruction /// - a block of instructions /// - or a while loop type code = | Ins: ins:ins -> code | Block: block:list code -> code | WhileLessThan: src1:operand -> src2:operand -> whileBody:code -> code /// The state of a program is the register file /// holiding a 64-bit value for each register type state = reg -> nat64 /// fuel: To prove the termination of while loops, we're going to /// instrument while loops with fuel type fuel = nat /// Evaluating an operand: /// -- marked for reduction /// -- Registers evaluated by state lookup
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.Vale.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
o: OPLSS2021.Vale.operand -> s: OPLSS2021.Vale.state -> OPLSS2021.Vale.nat64
Prims.Tot
[ "total" ]
[]
[ "OPLSS2021.Vale.operand", "OPLSS2021.Vale.state", "OPLSS2021.Vale.reg", "OPLSS2021.Vale.nat64" ]
[]
false
false
false
true
false
let eval_operand (o: operand) (s: state) : nat64 =
match o with | OReg r -> s r | OConst n -> n
false
OPLSS2021.Vale.fst
OPLSS2021.Vale.codes_Triple
val codes_Triple:list code
val codes_Triple:list code
let codes_Triple : list code = [ Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax; Ins (Add64 (OReg Rax) (OReg Rbx)); //add rax rbx; Ins (Add64 (OReg Rbx) (OReg Rax)) //add rbx rax; ]
{ "file_name": "examples/oplss2021/OPLSS2021.Vale.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 235, "start_col": 0, "start_line": 230 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul //suppress a benign warning in this program #push-options "--warn_error -290" (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// 2^64 let pow2_64 = 0x10000000000000000 /// Natural numbers representable in 64 bits type nat64 = i:int{0 <= i /\ i < pow2_64} /// We have 4 registers type reg = | Rax | Rbx | Rcx | Rdx /// An operand is either a register or a constant type operand = | OReg: r:reg -> operand | OConst: n:nat64 -> operand /// Only 2 instructions here: /// A move or an add type ins = | Mov64: dst:operand -> src:operand -> ins | Add64: dst:operand -> src:operand -> ins /// A program is /// - a single instruction /// - a block of instructions /// - or a while loop type code = | Ins: ins:ins -> code | Block: block:list code -> code | WhileLessThan: src1:operand -> src2:operand -> whileBody:code -> code /// The state of a program is the register file /// holiding a 64-bit value for each register type state = reg -> nat64 /// fuel: To prove the termination of while loops, we're going to /// instrument while loops with fuel type fuel = nat /// Evaluating an operand: /// -- marked for reduction /// -- Registers evaluated by state lookup let eval_operand (o:operand) (s:state) : nat64 = match o with | OReg r -> s r | OConst n -> n /// updating a register state `s` at `r` with `v` let update_reg (s:state) (r:reg) (v:nat64) : state = fun r' -> if r = r' then v else s r' /// updating a register state `s` at `r` with `s' r` let update_state (r:reg) (s' s:state) : state = update_reg s r (s' r) /// We don't have an "ok" flag, so errors just result an arbitrary state: assume val unknown_state (s:state) : state (*** A basic semantics using a big-step interpreter ***) /// Instruction evaluation: /// only some operands are valid let eval_ins (ins:ins) (s:state) : state = match ins with | Mov64 (OConst _) _ -> unknown_state s | Mov64 (OReg dst) src -> update_reg s dst (eval_operand src s) | Add64 (OConst _) _ -> unknown_state s | Add64 (OReg dst) src -> update_reg s dst ((s dst + eval_operand src s) % 0x10000000000000000) /// eval_code: /// A fueled big-step interpreter /// While lops return None when we're out of fuel let rec eval_code (c:code) (f:fuel) (s:state) : option state = match c with | Ins ins -> Some (eval_ins ins s) | Block cs -> eval_codes cs f s | WhileLessThan src1 src2 body -> if f = 0 then None else if eval_operand src1 s < eval_operand src2 s then match eval_code body f s with | None -> None | Some s -> eval_code c (f - 1) s else Some s and eval_codes (cs:list code) (f:fuel) (s:state) : option state = match cs with | [] -> Some s | c::cs -> match eval_code c f s with | None -> None | Some s -> eval_codes cs f s (*** END OF TRUSTED SEMANTICS ***) //////////////////////////////////////////////////////////////////////////////// /// 1. We prove that incrasing the fuel is irrelevant to terminating executions let rec increase_fuel (c:code) (s0:state) (f0:fuel) (sN:state) (fN:fuel) : Lemma (requires eval_code c f0 s0 == Some sN /\ f0 <= fN) (ensures eval_code c fN s0 == Some sN) (decreases %[f0; c]) = match c with | Ins ins -> () | Block l -> increase_fuels l s0 f0 sN fN | WhileLessThan src1 src2 body -> if eval_operand src1 s0 < eval_operand src2 s0 then match eval_code body f0 s0 with | None -> () | Some s1 -> increase_fuel body s0 f0 s1 fN; increase_fuel c s1 (f0 - 1) sN (fN - 1) else () and increase_fuels (c:list code) (s0:state) (f0:fuel) (sN:state) (fN:fuel) : Lemma (requires eval_code (Block c) f0 s0 == Some sN /\ f0 <= fN) (ensures eval_code (Block c) fN s0 == Some sN) (decreases %[f0; c]) = match c with | [] -> () | h::t -> let Some s1 = eval_code h f0 s0 in increase_fuel h s0 f0 s1 fN; increase_fuels t s1 f0 sN fN (* t -> Pure t' pre post is (roughly) sugar for x:t{pre} -> y:t'{post y} *) /// 2. We can compute the fuel needed to run a sequential composition /// as the max of the fuel to compute each piece of code in it let lemma_merge (c:code) (cs:list code) (s0:state) (f0:fuel) (sM:state) (fM:fuel) (sN:state) : Pure fuel (requires eval_code c f0 s0 == Some sM /\ eval_code (Block cs) fM sM == Some sN) (ensures fun fN -> eval_code (Block (c::cs)) fN s0 == Some sN) = let f = if f0 > fM then f0 else fM in increase_fuel c s0 f0 sM f; increase_fuel (Block cs) sM fM sN f; f //////////////////////////////////////////////////////////////////////////////// let lemma_Move (s0:state) (dst:operand) (src:operand) : Pure (state & fuel) (requires OReg? dst) (ensures fun (sM, fM) -> eval_code (Ins (Mov64 dst src)) fM s0 == Some sM /\ eval_operand dst sM == eval_operand src s0 /\ sM == update_state (OReg?.r dst) sM s0 ) = let Some sM = eval_code (Ins (Mov64 dst src)) 0 s0 in (sM, 0) let lemma_Add (s0:state) (dst:operand) (src:operand) : Pure (state & fuel) (requires OReg? dst /\ eval_operand dst s0 + eval_operand src s0 < pow2_64) (ensures fun (sM, fM) -> eval_code (Ins (Add64 dst src)) fM s0 == Some sM /\ eval_operand dst sM == eval_operand dst s0 + eval_operand src s0 /\ sM == update_state (OReg?.r dst) sM s0 ) = let Some sM = eval_code (Ins (Add64 dst src)) 0 s0 in (sM, 0)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.Vale.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.list OPLSS2021.Vale.code
Prims.Tot
[ "total" ]
[]
[ "Prims.Cons", "OPLSS2021.Vale.code", "OPLSS2021.Vale.Ins", "OPLSS2021.Vale.Mov64", "OPLSS2021.Vale.OReg", "OPLSS2021.Vale.Rbx", "OPLSS2021.Vale.Rax", "OPLSS2021.Vale.Add64", "Prims.Nil" ]
[]
false
false
false
true
false
let codes_Triple:list code =
[ Ins (Mov64 (OReg Rbx) (OReg Rax)); Ins (Add64 (OReg Rax) (OReg Rbx)); Ins (Add64 (OReg Rbx) (OReg Rax)) ]
false
OPLSS2021.Vale.fst
OPLSS2021.Vale.update_reg
val update_reg (s: state) (r: reg) (v: nat64) : state
val update_reg (s: state) (r: reg) (v: nat64) : state
let update_reg (s:state) (r:reg) (v:nat64) : state = fun r' -> if r = r' then v else s r'
{ "file_name": "examples/oplss2021/OPLSS2021.Vale.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 38, "end_line": 81, "start_col": 0, "start_line": 80 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul //suppress a benign warning in this program #push-options "--warn_error -290" (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// 2^64 let pow2_64 = 0x10000000000000000 /// Natural numbers representable in 64 bits type nat64 = i:int{0 <= i /\ i < pow2_64} /// We have 4 registers type reg = | Rax | Rbx | Rcx | Rdx /// An operand is either a register or a constant type operand = | OReg: r:reg -> operand | OConst: n:nat64 -> operand /// Only 2 instructions here: /// A move or an add type ins = | Mov64: dst:operand -> src:operand -> ins | Add64: dst:operand -> src:operand -> ins /// A program is /// - a single instruction /// - a block of instructions /// - or a while loop type code = | Ins: ins:ins -> code | Block: block:list code -> code | WhileLessThan: src1:operand -> src2:operand -> whileBody:code -> code /// The state of a program is the register file /// holiding a 64-bit value for each register type state = reg -> nat64 /// fuel: To prove the termination of while loops, we're going to /// instrument while loops with fuel type fuel = nat /// Evaluating an operand: /// -- marked for reduction /// -- Registers evaluated by state lookup let eval_operand (o:operand) (s:state) : nat64 = match o with | OReg r -> s r | OConst n -> n /// updating a register state `s` at `r` with `v`
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.Vale.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: OPLSS2021.Vale.state -> r: OPLSS2021.Vale.reg -> v: OPLSS2021.Vale.nat64 -> OPLSS2021.Vale.state
Prims.Tot
[ "total" ]
[]
[ "OPLSS2021.Vale.state", "OPLSS2021.Vale.reg", "OPLSS2021.Vale.nat64", "Prims.op_Equality", "Prims.bool" ]
[]
false
false
false
true
false
let update_reg (s: state) (r: reg) (v: nat64) : state =
fun r' -> if r = r' then v else s r'
false
OPLSS2021.Vale.fst
OPLSS2021.Vale.increase_fuels
val increase_fuels (c: list code) (s0: state) (f0: fuel) (sN: state) (fN: fuel) : Lemma (requires eval_code (Block c) f0 s0 == Some sN /\ f0 <= fN) (ensures eval_code (Block c) fN s0 == Some sN) (decreases %[f0;c])
val increase_fuels (c: list code) (s0: state) (f0: fuel) (sN: state) (fN: fuel) : Lemma (requires eval_code (Block c) f0 s0 == Some sN /\ f0 <= fN) (ensures eval_code (Block c) fN s0 == Some sN) (decreases %[f0;c])
let rec increase_fuel (c:code) (s0:state) (f0:fuel) (sN:state) (fN:fuel) : Lemma (requires eval_code c f0 s0 == Some sN /\ f0 <= fN) (ensures eval_code c fN s0 == Some sN) (decreases %[f0; c]) = match c with | Ins ins -> () | Block l -> increase_fuels l s0 f0 sN fN | WhileLessThan src1 src2 body -> if eval_operand src1 s0 < eval_operand src2 s0 then match eval_code body f0 s0 with | None -> () | Some s1 -> increase_fuel body s0 f0 s1 fN; increase_fuel c s1 (f0 - 1) sN (fN - 1) else () and increase_fuels (c:list code) (s0:state) (f0:fuel) (sN:state) (fN:fuel) : Lemma (requires eval_code (Block c) f0 s0 == Some sN /\ f0 <= fN) (ensures eval_code (Block c) fN s0 == Some sN) (decreases %[f0; c]) = match c with | [] -> () | h::t -> let Some s1 = eval_code h f0 s0 in increase_fuel h s0 f0 s1 fN; increase_fuels t s1 f0 sN fN
{ "file_name": "examples/oplss2021/OPLSS2021.Vale.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 180, "start_col": 0, "start_line": 146 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul //suppress a benign warning in this program #push-options "--warn_error -290" (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// 2^64 let pow2_64 = 0x10000000000000000 /// Natural numbers representable in 64 bits type nat64 = i:int{0 <= i /\ i < pow2_64} /// We have 4 registers type reg = | Rax | Rbx | Rcx | Rdx /// An operand is either a register or a constant type operand = | OReg: r:reg -> operand | OConst: n:nat64 -> operand /// Only 2 instructions here: /// A move or an add type ins = | Mov64: dst:operand -> src:operand -> ins | Add64: dst:operand -> src:operand -> ins /// A program is /// - a single instruction /// - a block of instructions /// - or a while loop type code = | Ins: ins:ins -> code | Block: block:list code -> code | WhileLessThan: src1:operand -> src2:operand -> whileBody:code -> code /// The state of a program is the register file /// holiding a 64-bit value for each register type state = reg -> nat64 /// fuel: To prove the termination of while loops, we're going to /// instrument while loops with fuel type fuel = nat /// Evaluating an operand: /// -- marked for reduction /// -- Registers evaluated by state lookup let eval_operand (o:operand) (s:state) : nat64 = match o with | OReg r -> s r | OConst n -> n /// updating a register state `s` at `r` with `v` let update_reg (s:state) (r:reg) (v:nat64) : state = fun r' -> if r = r' then v else s r' /// updating a register state `s` at `r` with `s' r` let update_state (r:reg) (s' s:state) : state = update_reg s r (s' r) /// We don't have an "ok" flag, so errors just result an arbitrary state: assume val unknown_state (s:state) : state (*** A basic semantics using a big-step interpreter ***) /// Instruction evaluation: /// only some operands are valid let eval_ins (ins:ins) (s:state) : state = match ins with | Mov64 (OConst _) _ -> unknown_state s | Mov64 (OReg dst) src -> update_reg s dst (eval_operand src s) | Add64 (OConst _) _ -> unknown_state s | Add64 (OReg dst) src -> update_reg s dst ((s dst + eval_operand src s) % 0x10000000000000000) /// eval_code: /// A fueled big-step interpreter /// While lops return None when we're out of fuel let rec eval_code (c:code) (f:fuel) (s:state) : option state = match c with | Ins ins -> Some (eval_ins ins s) | Block cs -> eval_codes cs f s | WhileLessThan src1 src2 body -> if f = 0 then None else if eval_operand src1 s < eval_operand src2 s then match eval_code body f s with | None -> None | Some s -> eval_code c (f - 1) s else Some s and eval_codes (cs:list code) (f:fuel) (s:state) : option state = match cs with | [] -> Some s | c::cs -> match eval_code c f s with | None -> None | Some s -> eval_codes cs f s (*** END OF TRUSTED SEMANTICS ***) ////////////////////////////////////////////////////////////////////////////////
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.Vale.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Prims.list OPLSS2021.Vale.code -> s0: OPLSS2021.Vale.state -> f0: OPLSS2021.Vale.fuel -> sN: OPLSS2021.Vale.state -> fN: OPLSS2021.Vale.fuel -> FStar.Pervasives.Lemma (requires OPLSS2021.Vale.eval_code (OPLSS2021.Vale.Block c) f0 s0 == FStar.Pervasives.Native.Some sN /\ f0 <= fN) (ensures OPLSS2021.Vale.eval_code (OPLSS2021.Vale.Block c) fN s0 == FStar.Pervasives.Native.Some sN) (decreases %[f0;c])
FStar.Pervasives.Lemma
[ "lemma", "" ]
[ "increase_fuel", "increase_fuels" ]
[ "Prims.list", "OPLSS2021.Vale.code", "OPLSS2021.Vale.state", "OPLSS2021.Vale.fuel", "OPLSS2021.Vale.increase_fuels", "Prims.unit", "OPLSS2021.Vale.increase_fuel", "FStar.Pervasives.Native.option", "OPLSS2021.Vale.eval_code", "Prims.l_and", "Prims.eq2", "OPLSS2021.Vale.Block", "FStar.Pervasives.Native.Some", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "mutual recursion" ]
false
false
true
false
false
let rec increase_fuels (c: list code) (s0: state) (f0: fuel) (sN: state) (fN: fuel) : Lemma (requires eval_code (Block c) f0 s0 == Some sN /\ f0 <= fN) (ensures eval_code (Block c) fN s0 == Some sN) (decreases %[f0;c]) =
match c with | [] -> () | h :: t -> let Some s1 = eval_code h f0 s0 in increase_fuel h s0 f0 s1 fN; increase_fuels t s1 f0 sN fN
false
OPLSS2021.Vale.fst
OPLSS2021.Vale.increase_fuel
val increase_fuel (c: code) (s0: state) (f0: fuel) (sN: state) (fN: fuel) : Lemma (requires eval_code c f0 s0 == Some sN /\ f0 <= fN) (ensures eval_code c fN s0 == Some sN) (decreases %[f0;c])
val increase_fuel (c: code) (s0: state) (f0: fuel) (sN: state) (fN: fuel) : Lemma (requires eval_code c f0 s0 == Some sN /\ f0 <= fN) (ensures eval_code c fN s0 == Some sN) (decreases %[f0;c])
let rec increase_fuel (c:code) (s0:state) (f0:fuel) (sN:state) (fN:fuel) : Lemma (requires eval_code c f0 s0 == Some sN /\ f0 <= fN) (ensures eval_code c fN s0 == Some sN) (decreases %[f0; c]) = match c with | Ins ins -> () | Block l -> increase_fuels l s0 f0 sN fN | WhileLessThan src1 src2 body -> if eval_operand src1 s0 < eval_operand src2 s0 then match eval_code body f0 s0 with | None -> () | Some s1 -> increase_fuel body s0 f0 s1 fN; increase_fuel c s1 (f0 - 1) sN (fN - 1) else () and increase_fuels (c:list code) (s0:state) (f0:fuel) (sN:state) (fN:fuel) : Lemma (requires eval_code (Block c) f0 s0 == Some sN /\ f0 <= fN) (ensures eval_code (Block c) fN s0 == Some sN) (decreases %[f0; c]) = match c with | [] -> () | h::t -> let Some s1 = eval_code h f0 s0 in increase_fuel h s0 f0 s1 fN; increase_fuels t s1 f0 sN fN
{ "file_name": "examples/oplss2021/OPLSS2021.Vale.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 180, "start_col": 0, "start_line": 146 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul //suppress a benign warning in this program #push-options "--warn_error -290" (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// 2^64 let pow2_64 = 0x10000000000000000 /// Natural numbers representable in 64 bits type nat64 = i:int{0 <= i /\ i < pow2_64} /// We have 4 registers type reg = | Rax | Rbx | Rcx | Rdx /// An operand is either a register or a constant type operand = | OReg: r:reg -> operand | OConst: n:nat64 -> operand /// Only 2 instructions here: /// A move or an add type ins = | Mov64: dst:operand -> src:operand -> ins | Add64: dst:operand -> src:operand -> ins /// A program is /// - a single instruction /// - a block of instructions /// - or a while loop type code = | Ins: ins:ins -> code | Block: block:list code -> code | WhileLessThan: src1:operand -> src2:operand -> whileBody:code -> code /// The state of a program is the register file /// holiding a 64-bit value for each register type state = reg -> nat64 /// fuel: To prove the termination of while loops, we're going to /// instrument while loops with fuel type fuel = nat /// Evaluating an operand: /// -- marked for reduction /// -- Registers evaluated by state lookup let eval_operand (o:operand) (s:state) : nat64 = match o with | OReg r -> s r | OConst n -> n /// updating a register state `s` at `r` with `v` let update_reg (s:state) (r:reg) (v:nat64) : state = fun r' -> if r = r' then v else s r' /// updating a register state `s` at `r` with `s' r` let update_state (r:reg) (s' s:state) : state = update_reg s r (s' r) /// We don't have an "ok" flag, so errors just result an arbitrary state: assume val unknown_state (s:state) : state (*** A basic semantics using a big-step interpreter ***) /// Instruction evaluation: /// only some operands are valid let eval_ins (ins:ins) (s:state) : state = match ins with | Mov64 (OConst _) _ -> unknown_state s | Mov64 (OReg dst) src -> update_reg s dst (eval_operand src s) | Add64 (OConst _) _ -> unknown_state s | Add64 (OReg dst) src -> update_reg s dst ((s dst + eval_operand src s) % 0x10000000000000000) /// eval_code: /// A fueled big-step interpreter /// While lops return None when we're out of fuel let rec eval_code (c:code) (f:fuel) (s:state) : option state = match c with | Ins ins -> Some (eval_ins ins s) | Block cs -> eval_codes cs f s | WhileLessThan src1 src2 body -> if f = 0 then None else if eval_operand src1 s < eval_operand src2 s then match eval_code body f s with | None -> None | Some s -> eval_code c (f - 1) s else Some s and eval_codes (cs:list code) (f:fuel) (s:state) : option state = match cs with | [] -> Some s | c::cs -> match eval_code c f s with | None -> None | Some s -> eval_codes cs f s (*** END OF TRUSTED SEMANTICS ***) ////////////////////////////////////////////////////////////////////////////////
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.Vale.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: OPLSS2021.Vale.code -> s0: OPLSS2021.Vale.state -> f0: OPLSS2021.Vale.fuel -> sN: OPLSS2021.Vale.state -> fN: OPLSS2021.Vale.fuel -> FStar.Pervasives.Lemma (requires OPLSS2021.Vale.eval_code c f0 s0 == FStar.Pervasives.Native.Some sN /\ f0 <= fN) (ensures OPLSS2021.Vale.eval_code c fN s0 == FStar.Pervasives.Native.Some sN) (decreases %[f0;c])
FStar.Pervasives.Lemma
[ "lemma", "" ]
[ "increase_fuel", "increase_fuels" ]
[ "OPLSS2021.Vale.code", "OPLSS2021.Vale.state", "OPLSS2021.Vale.fuel", "OPLSS2021.Vale.ins", "Prims.list", "OPLSS2021.Vale.increase_fuels", "OPLSS2021.Vale.operand", "Prims.op_LessThan", "OPLSS2021.Vale.eval_operand", "OPLSS2021.Vale.eval_code", "OPLSS2021.Vale.increase_fuel", "Prims.op_Subtraction", "Prims.unit", "Prims.bool", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.Some", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "mutual recursion" ]
false
false
true
false
false
let rec increase_fuel (c: code) (s0: state) (f0: fuel) (sN: state) (fN: fuel) : Lemma (requires eval_code c f0 s0 == Some sN /\ f0 <= fN) (ensures eval_code c fN s0 == Some sN) (decreases %[f0;c]) =
match c with | Ins ins -> () | Block l -> increase_fuels l s0 f0 sN fN | WhileLessThan src1 src2 body -> if eval_operand src1 s0 < eval_operand src2 s0 then match eval_code body f0 s0 with | None -> () | Some s1 -> increase_fuel body s0 f0 s1 fN; increase_fuel c s1 (f0 - 1) sN (fN - 1)
false
OPLSS2021.Vale.fst
OPLSS2021.Vale.lemma_merge
val lemma_merge (c: code) (cs: list code) (s0: state) (f0: fuel) (sM: state) (fM: fuel) (sN: state) : Pure fuel (requires eval_code c f0 s0 == Some sM /\ eval_code (Block cs) fM sM == Some sN) (ensures fun fN -> eval_code (Block (c :: cs)) fN s0 == Some sN)
val lemma_merge (c: code) (cs: list code) (s0: state) (f0: fuel) (sM: state) (fM: fuel) (sN: state) : Pure fuel (requires eval_code c f0 s0 == Some sM /\ eval_code (Block cs) fM sM == Some sN) (ensures fun fN -> eval_code (Block (c :: cs)) fN s0 == Some sN)
let lemma_merge (c:code) (cs:list code) (s0:state) (f0:fuel) (sM:state) (fM:fuel) (sN:state) : Pure fuel (requires eval_code c f0 s0 == Some sM /\ eval_code (Block cs) fM sM == Some sN) (ensures fun fN -> eval_code (Block (c::cs)) fN s0 == Some sN) = let f = if f0 > fM then f0 else fM in increase_fuel c s0 f0 sM f; increase_fuel (Block cs) sM fM sN f; f
{ "file_name": "examples/oplss2021/OPLSS2021.Vale.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 202, "start_col": 0, "start_line": 192 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul //suppress a benign warning in this program #push-options "--warn_error -290" (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// 2^64 let pow2_64 = 0x10000000000000000 /// Natural numbers representable in 64 bits type nat64 = i:int{0 <= i /\ i < pow2_64} /// We have 4 registers type reg = | Rax | Rbx | Rcx | Rdx /// An operand is either a register or a constant type operand = | OReg: r:reg -> operand | OConst: n:nat64 -> operand /// Only 2 instructions here: /// A move or an add type ins = | Mov64: dst:operand -> src:operand -> ins | Add64: dst:operand -> src:operand -> ins /// A program is /// - a single instruction /// - a block of instructions /// - or a while loop type code = | Ins: ins:ins -> code | Block: block:list code -> code | WhileLessThan: src1:operand -> src2:operand -> whileBody:code -> code /// The state of a program is the register file /// holiding a 64-bit value for each register type state = reg -> nat64 /// fuel: To prove the termination of while loops, we're going to /// instrument while loops with fuel type fuel = nat /// Evaluating an operand: /// -- marked for reduction /// -- Registers evaluated by state lookup let eval_operand (o:operand) (s:state) : nat64 = match o with | OReg r -> s r | OConst n -> n /// updating a register state `s` at `r` with `v` let update_reg (s:state) (r:reg) (v:nat64) : state = fun r' -> if r = r' then v else s r' /// updating a register state `s` at `r` with `s' r` let update_state (r:reg) (s' s:state) : state = update_reg s r (s' r) /// We don't have an "ok" flag, so errors just result an arbitrary state: assume val unknown_state (s:state) : state (*** A basic semantics using a big-step interpreter ***) /// Instruction evaluation: /// only some operands are valid let eval_ins (ins:ins) (s:state) : state = match ins with | Mov64 (OConst _) _ -> unknown_state s | Mov64 (OReg dst) src -> update_reg s dst (eval_operand src s) | Add64 (OConst _) _ -> unknown_state s | Add64 (OReg dst) src -> update_reg s dst ((s dst + eval_operand src s) % 0x10000000000000000) /// eval_code: /// A fueled big-step interpreter /// While lops return None when we're out of fuel let rec eval_code (c:code) (f:fuel) (s:state) : option state = match c with | Ins ins -> Some (eval_ins ins s) | Block cs -> eval_codes cs f s | WhileLessThan src1 src2 body -> if f = 0 then None else if eval_operand src1 s < eval_operand src2 s then match eval_code body f s with | None -> None | Some s -> eval_code c (f - 1) s else Some s and eval_codes (cs:list code) (f:fuel) (s:state) : option state = match cs with | [] -> Some s | c::cs -> match eval_code c f s with | None -> None | Some s -> eval_codes cs f s (*** END OF TRUSTED SEMANTICS ***) //////////////////////////////////////////////////////////////////////////////// /// 1. We prove that incrasing the fuel is irrelevant to terminating executions let rec increase_fuel (c:code) (s0:state) (f0:fuel) (sN:state) (fN:fuel) : Lemma (requires eval_code c f0 s0 == Some sN /\ f0 <= fN) (ensures eval_code c fN s0 == Some sN) (decreases %[f0; c]) = match c with | Ins ins -> () | Block l -> increase_fuels l s0 f0 sN fN | WhileLessThan src1 src2 body -> if eval_operand src1 s0 < eval_operand src2 s0 then match eval_code body f0 s0 with | None -> () | Some s1 -> increase_fuel body s0 f0 s1 fN; increase_fuel c s1 (f0 - 1) sN (fN - 1) else () and increase_fuels (c:list code) (s0:state) (f0:fuel) (sN:state) (fN:fuel) : Lemma (requires eval_code (Block c) f0 s0 == Some sN /\ f0 <= fN) (ensures eval_code (Block c) fN s0 == Some sN) (decreases %[f0; c]) = match c with | [] -> () | h::t -> let Some s1 = eval_code h f0 s0 in increase_fuel h s0 f0 s1 fN; increase_fuels t s1 f0 sN fN (* t -> Pure t' pre post is (roughly) sugar for x:t{pre} -> y:t'{post y} *) /// 2. We can compute the fuel needed to run a sequential composition
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.Vale.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: OPLSS2021.Vale.code -> cs: Prims.list OPLSS2021.Vale.code -> s0: OPLSS2021.Vale.state -> f0: OPLSS2021.Vale.fuel -> sM: OPLSS2021.Vale.state -> fM: OPLSS2021.Vale.fuel -> sN: OPLSS2021.Vale.state -> Prims.Pure OPLSS2021.Vale.fuel
Prims.Pure
[]
[]
[ "OPLSS2021.Vale.code", "Prims.list", "OPLSS2021.Vale.state", "OPLSS2021.Vale.fuel", "Prims.unit", "OPLSS2021.Vale.increase_fuel", "OPLSS2021.Vale.Block", "Prims.op_GreaterThan", "Prims.bool", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.option", "OPLSS2021.Vale.eval_code", "FStar.Pervasives.Native.Some", "Prims.Cons" ]
[]
false
false
false
false
false
let lemma_merge (c: code) (cs: list code) (s0: state) (f0: fuel) (sM: state) (fM: fuel) (sN: state) : Pure fuel (requires eval_code c f0 s0 == Some sM /\ eval_code (Block cs) fM sM == Some sN) (ensures fun fN -> eval_code (Block (c :: cs)) fN s0 == Some sN) =
let f = if f0 > fM then f0 else fM in increase_fuel c s0 f0 sM f; increase_fuel (Block cs) sM fM sN f; f
false
OPLSS2021.Vale.fst
OPLSS2021.Vale.lemma_Move
val lemma_Move (s0: state) (dst src: operand) : Pure (state & fuel) (requires OReg? dst) (ensures fun (sM, fM) -> eval_code (Ins (Mov64 dst src)) fM s0 == Some sM /\ eval_operand dst sM == eval_operand src s0 /\ sM == update_state (OReg?.r dst) sM s0)
val lemma_Move (s0: state) (dst src: operand) : Pure (state & fuel) (requires OReg? dst) (ensures fun (sM, fM) -> eval_code (Ins (Mov64 dst src)) fM s0 == Some sM /\ eval_operand dst sM == eval_operand src s0 /\ sM == update_state (OReg?.r dst) sM s0)
let lemma_Move (s0:state) (dst:operand) (src:operand) : Pure (state & fuel) (requires OReg? dst) (ensures fun (sM, fM) -> eval_code (Ins (Mov64 dst src)) fM s0 == Some sM /\ eval_operand dst sM == eval_operand src s0 /\ sM == update_state (OReg?.r dst) sM s0 ) = let Some sM = eval_code (Ins (Mov64 dst src)) 0 s0 in (sM, 0)
{ "file_name": "examples/oplss2021/OPLSS2021.Vale.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 9, "end_line": 216, "start_col": 0, "start_line": 206 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul //suppress a benign warning in this program #push-options "--warn_error -290" (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// 2^64 let pow2_64 = 0x10000000000000000 /// Natural numbers representable in 64 bits type nat64 = i:int{0 <= i /\ i < pow2_64} /// We have 4 registers type reg = | Rax | Rbx | Rcx | Rdx /// An operand is either a register or a constant type operand = | OReg: r:reg -> operand | OConst: n:nat64 -> operand /// Only 2 instructions here: /// A move or an add type ins = | Mov64: dst:operand -> src:operand -> ins | Add64: dst:operand -> src:operand -> ins /// A program is /// - a single instruction /// - a block of instructions /// - or a while loop type code = | Ins: ins:ins -> code | Block: block:list code -> code | WhileLessThan: src1:operand -> src2:operand -> whileBody:code -> code /// The state of a program is the register file /// holiding a 64-bit value for each register type state = reg -> nat64 /// fuel: To prove the termination of while loops, we're going to /// instrument while loops with fuel type fuel = nat /// Evaluating an operand: /// -- marked for reduction /// -- Registers evaluated by state lookup let eval_operand (o:operand) (s:state) : nat64 = match o with | OReg r -> s r | OConst n -> n /// updating a register state `s` at `r` with `v` let update_reg (s:state) (r:reg) (v:nat64) : state = fun r' -> if r = r' then v else s r' /// updating a register state `s` at `r` with `s' r` let update_state (r:reg) (s' s:state) : state = update_reg s r (s' r) /// We don't have an "ok" flag, so errors just result an arbitrary state: assume val unknown_state (s:state) : state (*** A basic semantics using a big-step interpreter ***) /// Instruction evaluation: /// only some operands are valid let eval_ins (ins:ins) (s:state) : state = match ins with | Mov64 (OConst _) _ -> unknown_state s | Mov64 (OReg dst) src -> update_reg s dst (eval_operand src s) | Add64 (OConst _) _ -> unknown_state s | Add64 (OReg dst) src -> update_reg s dst ((s dst + eval_operand src s) % 0x10000000000000000) /// eval_code: /// A fueled big-step interpreter /// While lops return None when we're out of fuel let rec eval_code (c:code) (f:fuel) (s:state) : option state = match c with | Ins ins -> Some (eval_ins ins s) | Block cs -> eval_codes cs f s | WhileLessThan src1 src2 body -> if f = 0 then None else if eval_operand src1 s < eval_operand src2 s then match eval_code body f s with | None -> None | Some s -> eval_code c (f - 1) s else Some s and eval_codes (cs:list code) (f:fuel) (s:state) : option state = match cs with | [] -> Some s | c::cs -> match eval_code c f s with | None -> None | Some s -> eval_codes cs f s (*** END OF TRUSTED SEMANTICS ***) //////////////////////////////////////////////////////////////////////////////// /// 1. We prove that incrasing the fuel is irrelevant to terminating executions let rec increase_fuel (c:code) (s0:state) (f0:fuel) (sN:state) (fN:fuel) : Lemma (requires eval_code c f0 s0 == Some sN /\ f0 <= fN) (ensures eval_code c fN s0 == Some sN) (decreases %[f0; c]) = match c with | Ins ins -> () | Block l -> increase_fuels l s0 f0 sN fN | WhileLessThan src1 src2 body -> if eval_operand src1 s0 < eval_operand src2 s0 then match eval_code body f0 s0 with | None -> () | Some s1 -> increase_fuel body s0 f0 s1 fN; increase_fuel c s1 (f0 - 1) sN (fN - 1) else () and increase_fuels (c:list code) (s0:state) (f0:fuel) (sN:state) (fN:fuel) : Lemma (requires eval_code (Block c) f0 s0 == Some sN /\ f0 <= fN) (ensures eval_code (Block c) fN s0 == Some sN) (decreases %[f0; c]) = match c with | [] -> () | h::t -> let Some s1 = eval_code h f0 s0 in increase_fuel h s0 f0 s1 fN; increase_fuels t s1 f0 sN fN (* t -> Pure t' pre post is (roughly) sugar for x:t{pre} -> y:t'{post y} *) /// 2. We can compute the fuel needed to run a sequential composition /// as the max of the fuel to compute each piece of code in it let lemma_merge (c:code) (cs:list code) (s0:state) (f0:fuel) (sM:state) (fM:fuel) (sN:state) : Pure fuel (requires eval_code c f0 s0 == Some sM /\ eval_code (Block cs) fM sM == Some sN) (ensures fun fN -> eval_code (Block (c::cs)) fN s0 == Some sN) = let f = if f0 > fM then f0 else fM in increase_fuel c s0 f0 sM f; increase_fuel (Block cs) sM fM sN f; f ////////////////////////////////////////////////////////////////////////////////
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.Vale.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s0: OPLSS2021.Vale.state -> dst: OPLSS2021.Vale.operand -> src: OPLSS2021.Vale.operand -> Prims.Pure (OPLSS2021.Vale.state * OPLSS2021.Vale.fuel)
Prims.Pure
[]
[]
[ "OPLSS2021.Vale.state", "OPLSS2021.Vale.operand", "FStar.Pervasives.Native.Mktuple2", "OPLSS2021.Vale.fuel", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.option", "OPLSS2021.Vale.eval_code", "OPLSS2021.Vale.Ins", "OPLSS2021.Vale.Mov64", "Prims.b2t", "OPLSS2021.Vale.uu___is_OReg", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.Some", "OPLSS2021.Vale.nat64", "OPLSS2021.Vale.eval_operand", "OPLSS2021.Vale.update_state", "OPLSS2021.Vale.__proj__OReg__item__r" ]
[]
false
false
false
false
false
let lemma_Move (s0: state) (dst src: operand) : Pure (state & fuel) (requires OReg? dst) (ensures fun (sM, fM) -> eval_code (Ins (Mov64 dst src)) fM s0 == Some sM /\ eval_operand dst sM == eval_operand src s0 /\ sM == update_state (OReg?.r dst) sM s0) =
let Some sM = eval_code (Ins (Mov64 dst src)) 0 s0 in (sM, 0)
false
OPLSS2021.Vale.fst
OPLSS2021.Vale.lemma_Add
val lemma_Add (s0: state) (dst src: operand) : Pure (state & fuel) (requires OReg? dst /\ eval_operand dst s0 + eval_operand src s0 < pow2_64) (ensures fun (sM, fM) -> eval_code (Ins (Add64 dst src)) fM s0 == Some sM /\ eval_operand dst sM == eval_operand dst s0 + eval_operand src s0 /\ sM == update_state (OReg?.r dst) sM s0)
val lemma_Add (s0: state) (dst src: operand) : Pure (state & fuel) (requires OReg? dst /\ eval_operand dst s0 + eval_operand src s0 < pow2_64) (ensures fun (sM, fM) -> eval_code (Ins (Add64 dst src)) fM s0 == Some sM /\ eval_operand dst sM == eval_operand dst s0 + eval_operand src s0 /\ sM == update_state (OReg?.r dst) sM s0)
let lemma_Add (s0:state) (dst:operand) (src:operand) : Pure (state & fuel) (requires OReg? dst /\ eval_operand dst s0 + eval_operand src s0 < pow2_64) (ensures fun (sM, fM) -> eval_code (Ins (Add64 dst src)) fM s0 == Some sM /\ eval_operand dst sM == eval_operand dst s0 + eval_operand src s0 /\ sM == update_state (OReg?.r dst) sM s0 ) = let Some sM = eval_code (Ins (Add64 dst src)) 0 s0 in (sM, 0)
{ "file_name": "examples/oplss2021/OPLSS2021.Vale.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 9, "end_line": 228, "start_col": 0, "start_line": 218 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul //suppress a benign warning in this program #push-options "--warn_error -290" (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// 2^64 let pow2_64 = 0x10000000000000000 /// Natural numbers representable in 64 bits type nat64 = i:int{0 <= i /\ i < pow2_64} /// We have 4 registers type reg = | Rax | Rbx | Rcx | Rdx /// An operand is either a register or a constant type operand = | OReg: r:reg -> operand | OConst: n:nat64 -> operand /// Only 2 instructions here: /// A move or an add type ins = | Mov64: dst:operand -> src:operand -> ins | Add64: dst:operand -> src:operand -> ins /// A program is /// - a single instruction /// - a block of instructions /// - or a while loop type code = | Ins: ins:ins -> code | Block: block:list code -> code | WhileLessThan: src1:operand -> src2:operand -> whileBody:code -> code /// The state of a program is the register file /// holiding a 64-bit value for each register type state = reg -> nat64 /// fuel: To prove the termination of while loops, we're going to /// instrument while loops with fuel type fuel = nat /// Evaluating an operand: /// -- marked for reduction /// -- Registers evaluated by state lookup let eval_operand (o:operand) (s:state) : nat64 = match o with | OReg r -> s r | OConst n -> n /// updating a register state `s` at `r` with `v` let update_reg (s:state) (r:reg) (v:nat64) : state = fun r' -> if r = r' then v else s r' /// updating a register state `s` at `r` with `s' r` let update_state (r:reg) (s' s:state) : state = update_reg s r (s' r) /// We don't have an "ok" flag, so errors just result an arbitrary state: assume val unknown_state (s:state) : state (*** A basic semantics using a big-step interpreter ***) /// Instruction evaluation: /// only some operands are valid let eval_ins (ins:ins) (s:state) : state = match ins with | Mov64 (OConst _) _ -> unknown_state s | Mov64 (OReg dst) src -> update_reg s dst (eval_operand src s) | Add64 (OConst _) _ -> unknown_state s | Add64 (OReg dst) src -> update_reg s dst ((s dst + eval_operand src s) % 0x10000000000000000) /// eval_code: /// A fueled big-step interpreter /// While lops return None when we're out of fuel let rec eval_code (c:code) (f:fuel) (s:state) : option state = match c with | Ins ins -> Some (eval_ins ins s) | Block cs -> eval_codes cs f s | WhileLessThan src1 src2 body -> if f = 0 then None else if eval_operand src1 s < eval_operand src2 s then match eval_code body f s with | None -> None | Some s -> eval_code c (f - 1) s else Some s and eval_codes (cs:list code) (f:fuel) (s:state) : option state = match cs with | [] -> Some s | c::cs -> match eval_code c f s with | None -> None | Some s -> eval_codes cs f s (*** END OF TRUSTED SEMANTICS ***) //////////////////////////////////////////////////////////////////////////////// /// 1. We prove that incrasing the fuel is irrelevant to terminating executions let rec increase_fuel (c:code) (s0:state) (f0:fuel) (sN:state) (fN:fuel) : Lemma (requires eval_code c f0 s0 == Some sN /\ f0 <= fN) (ensures eval_code c fN s0 == Some sN) (decreases %[f0; c]) = match c with | Ins ins -> () | Block l -> increase_fuels l s0 f0 sN fN | WhileLessThan src1 src2 body -> if eval_operand src1 s0 < eval_operand src2 s0 then match eval_code body f0 s0 with | None -> () | Some s1 -> increase_fuel body s0 f0 s1 fN; increase_fuel c s1 (f0 - 1) sN (fN - 1) else () and increase_fuels (c:list code) (s0:state) (f0:fuel) (sN:state) (fN:fuel) : Lemma (requires eval_code (Block c) f0 s0 == Some sN /\ f0 <= fN) (ensures eval_code (Block c) fN s0 == Some sN) (decreases %[f0; c]) = match c with | [] -> () | h::t -> let Some s1 = eval_code h f0 s0 in increase_fuel h s0 f0 s1 fN; increase_fuels t s1 f0 sN fN (* t -> Pure t' pre post is (roughly) sugar for x:t{pre} -> y:t'{post y} *) /// 2. We can compute the fuel needed to run a sequential composition /// as the max of the fuel to compute each piece of code in it let lemma_merge (c:code) (cs:list code) (s0:state) (f0:fuel) (sM:state) (fM:fuel) (sN:state) : Pure fuel (requires eval_code c f0 s0 == Some sM /\ eval_code (Block cs) fM sM == Some sN) (ensures fun fN -> eval_code (Block (c::cs)) fN s0 == Some sN) = let f = if f0 > fM then f0 else fM in increase_fuel c s0 f0 sM f; increase_fuel (Block cs) sM fM sN f; f //////////////////////////////////////////////////////////////////////////////// let lemma_Move (s0:state) (dst:operand) (src:operand) : Pure (state & fuel) (requires OReg? dst) (ensures fun (sM, fM) -> eval_code (Ins (Mov64 dst src)) fM s0 == Some sM /\ eval_operand dst sM == eval_operand src s0 /\ sM == update_state (OReg?.r dst) sM s0 ) = let Some sM = eval_code (Ins (Mov64 dst src)) 0 s0 in (sM, 0)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.Vale.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s0: OPLSS2021.Vale.state -> dst: OPLSS2021.Vale.operand -> src: OPLSS2021.Vale.operand -> Prims.Pure (OPLSS2021.Vale.state * OPLSS2021.Vale.fuel)
Prims.Pure
[]
[]
[ "OPLSS2021.Vale.state", "OPLSS2021.Vale.operand", "FStar.Pervasives.Native.Mktuple2", "OPLSS2021.Vale.fuel", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.option", "OPLSS2021.Vale.eval_code", "OPLSS2021.Vale.Ins", "OPLSS2021.Vale.Add64", "Prims.l_and", "Prims.b2t", "OPLSS2021.Vale.uu___is_OReg", "Prims.op_LessThan", "Prims.op_Addition", "OPLSS2021.Vale.eval_operand", "OPLSS2021.Vale.pow2_64", "Prims.eq2", "FStar.Pervasives.Native.Some", "Prims.int", "OPLSS2021.Vale.update_state", "OPLSS2021.Vale.__proj__OReg__item__r" ]
[]
false
false
false
false
false
let lemma_Add (s0: state) (dst src: operand) : Pure (state & fuel) (requires OReg? dst /\ eval_operand dst s0 + eval_operand src s0 < pow2_64) (ensures fun (sM, fM) -> eval_code (Ins (Add64 dst src)) fM s0 == Some sM /\ eval_operand dst sM == eval_operand dst s0 + eval_operand src s0 /\ sM == update_state (OReg?.r dst) sM s0) =
let Some sM = eval_code (Ins (Add64 dst src)) 0 s0 in (sM, 0)
false
OPLSS2021.Vale.fst
OPLSS2021.Vale.lemma_Triple
val lemma_Triple (s0: state) : Pure (state & fuel) (requires s0 Rax < 100) (ensures fun (sM, f0) -> eval_code (Block codes_Triple) f0 s0 == Some sM /\ sM Rbx == 3 * s0 Rax /\ sM `feq` (update_state Rax sM (update_state Rbx sM s0)))
val lemma_Triple (s0: state) : Pure (state & fuel) (requires s0 Rax < 100) (ensures fun (sM, f0) -> eval_code (Block codes_Triple) f0 s0 == Some sM /\ sM Rbx == 3 * s0 Rax /\ sM `feq` (update_state Rax sM (update_state Rbx sM s0)))
let lemma_Triple (s0:state) : Pure (state & fuel) (requires s0 Rax < 100) (ensures fun (sM, f0) -> eval_code (Block codes_Triple) f0 s0 == Some sM /\ sM Rbx == 3 * s0 Rax /\ sM `feq` update_state Rax sM (update_state Rbx sM s0)) = // Naive proof: let b1 = codes_Triple in let (s2, fc2) = lemma_Move s0 (OReg Rbx) (OReg Rax) in let b2 = Cons?.tl b1 in let (s3, fc3) = lemma_Add s2 (OReg Rax) (OReg Rbx) in let b3 = Cons?.tl b2 in let (s4, fc4) = lemma_Add s3 (OReg Rbx) (OReg Rax) in let b4 = Cons?.tl b3 in let (sM, f4) = (s4, 0) in let f3 = lemma_merge (Cons?.hd b3) b4 s3 fc4 s4 f4 sM in let f2 = lemma_merge (Cons?.hd b2) b3 s2 fc3 s3 f3 sM in let fM = lemma_merge (Cons?.hd b1) b2 s0 fc2 s2 f2 sM in (sM, fM)
{ "file_name": "examples/oplss2021/OPLSS2021.Vale.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 10, "end_line": 254, "start_col": 0, "start_line": 237 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul //suppress a benign warning in this program #push-options "--warn_error -290" (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// 2^64 let pow2_64 = 0x10000000000000000 /// Natural numbers representable in 64 bits type nat64 = i:int{0 <= i /\ i < pow2_64} /// We have 4 registers type reg = | Rax | Rbx | Rcx | Rdx /// An operand is either a register or a constant type operand = | OReg: r:reg -> operand | OConst: n:nat64 -> operand /// Only 2 instructions here: /// A move or an add type ins = | Mov64: dst:operand -> src:operand -> ins | Add64: dst:operand -> src:operand -> ins /// A program is /// - a single instruction /// - a block of instructions /// - or a while loop type code = | Ins: ins:ins -> code | Block: block:list code -> code | WhileLessThan: src1:operand -> src2:operand -> whileBody:code -> code /// The state of a program is the register file /// holiding a 64-bit value for each register type state = reg -> nat64 /// fuel: To prove the termination of while loops, we're going to /// instrument while loops with fuel type fuel = nat /// Evaluating an operand: /// -- marked for reduction /// -- Registers evaluated by state lookup let eval_operand (o:operand) (s:state) : nat64 = match o with | OReg r -> s r | OConst n -> n /// updating a register state `s` at `r` with `v` let update_reg (s:state) (r:reg) (v:nat64) : state = fun r' -> if r = r' then v else s r' /// updating a register state `s` at `r` with `s' r` let update_state (r:reg) (s' s:state) : state = update_reg s r (s' r) /// We don't have an "ok" flag, so errors just result an arbitrary state: assume val unknown_state (s:state) : state (*** A basic semantics using a big-step interpreter ***) /// Instruction evaluation: /// only some operands are valid let eval_ins (ins:ins) (s:state) : state = match ins with | Mov64 (OConst _) _ -> unknown_state s | Mov64 (OReg dst) src -> update_reg s dst (eval_operand src s) | Add64 (OConst _) _ -> unknown_state s | Add64 (OReg dst) src -> update_reg s dst ((s dst + eval_operand src s) % 0x10000000000000000) /// eval_code: /// A fueled big-step interpreter /// While lops return None when we're out of fuel let rec eval_code (c:code) (f:fuel) (s:state) : option state = match c with | Ins ins -> Some (eval_ins ins s) | Block cs -> eval_codes cs f s | WhileLessThan src1 src2 body -> if f = 0 then None else if eval_operand src1 s < eval_operand src2 s then match eval_code body f s with | None -> None | Some s -> eval_code c (f - 1) s else Some s and eval_codes (cs:list code) (f:fuel) (s:state) : option state = match cs with | [] -> Some s | c::cs -> match eval_code c f s with | None -> None | Some s -> eval_codes cs f s (*** END OF TRUSTED SEMANTICS ***) //////////////////////////////////////////////////////////////////////////////// /// 1. We prove that incrasing the fuel is irrelevant to terminating executions let rec increase_fuel (c:code) (s0:state) (f0:fuel) (sN:state) (fN:fuel) : Lemma (requires eval_code c f0 s0 == Some sN /\ f0 <= fN) (ensures eval_code c fN s0 == Some sN) (decreases %[f0; c]) = match c with | Ins ins -> () | Block l -> increase_fuels l s0 f0 sN fN | WhileLessThan src1 src2 body -> if eval_operand src1 s0 < eval_operand src2 s0 then match eval_code body f0 s0 with | None -> () | Some s1 -> increase_fuel body s0 f0 s1 fN; increase_fuel c s1 (f0 - 1) sN (fN - 1) else () and increase_fuels (c:list code) (s0:state) (f0:fuel) (sN:state) (fN:fuel) : Lemma (requires eval_code (Block c) f0 s0 == Some sN /\ f0 <= fN) (ensures eval_code (Block c) fN s0 == Some sN) (decreases %[f0; c]) = match c with | [] -> () | h::t -> let Some s1 = eval_code h f0 s0 in increase_fuel h s0 f0 s1 fN; increase_fuels t s1 f0 sN fN (* t -> Pure t' pre post is (roughly) sugar for x:t{pre} -> y:t'{post y} *) /// 2. We can compute the fuel needed to run a sequential composition /// as the max of the fuel to compute each piece of code in it let lemma_merge (c:code) (cs:list code) (s0:state) (f0:fuel) (sM:state) (fM:fuel) (sN:state) : Pure fuel (requires eval_code c f0 s0 == Some sM /\ eval_code (Block cs) fM sM == Some sN) (ensures fun fN -> eval_code (Block (c::cs)) fN s0 == Some sN) = let f = if f0 > fM then f0 else fM in increase_fuel c s0 f0 sM f; increase_fuel (Block cs) sM fM sN f; f //////////////////////////////////////////////////////////////////////////////// let lemma_Move (s0:state) (dst:operand) (src:operand) : Pure (state & fuel) (requires OReg? dst) (ensures fun (sM, fM) -> eval_code (Ins (Mov64 dst src)) fM s0 == Some sM /\ eval_operand dst sM == eval_operand src s0 /\ sM == update_state (OReg?.r dst) sM s0 ) = let Some sM = eval_code (Ins (Mov64 dst src)) 0 s0 in (sM, 0) let lemma_Add (s0:state) (dst:operand) (src:operand) : Pure (state & fuel) (requires OReg? dst /\ eval_operand dst s0 + eval_operand src s0 < pow2_64) (ensures fun (sM, fM) -> eval_code (Ins (Add64 dst src)) fM s0 == Some sM /\ eval_operand dst sM == eval_operand dst s0 + eval_operand src s0 /\ sM == update_state (OReg?.r dst) sM s0 ) = let Some sM = eval_code (Ins (Add64 dst src)) 0 s0 in (sM, 0) let codes_Triple : list code = [ Ins (Mov64 (OReg Rbx) (OReg Rax)); //mov rbx rax; Ins (Add64 (OReg Rax) (OReg Rbx)); //add rax rbx; Ins (Add64 (OReg Rbx) (OReg Rax)) //add rbx rax; ]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.Vale.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s0: OPLSS2021.Vale.state -> Prims.Pure (OPLSS2021.Vale.state * OPLSS2021.Vale.fuel)
Prims.Pure
[]
[]
[ "OPLSS2021.Vale.state", "OPLSS2021.Vale.fuel", "FStar.Pervasives.Native.Mktuple2", "OPLSS2021.Vale.lemma_merge", "Prims.__proj__Cons__item__hd", "OPLSS2021.Vale.code", "FStar.Pervasives.Native.tuple2", "Prims.list", "Prims.__proj__Cons__item__tl", "OPLSS2021.Vale.lemma_Add", "OPLSS2021.Vale.OReg", "OPLSS2021.Vale.Rbx", "OPLSS2021.Vale.Rax", "OPLSS2021.Vale.lemma_Move", "OPLSS2021.Vale.codes_Triple", "Prims.b2t", "Prims.op_LessThan", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.option", "OPLSS2021.Vale.eval_code", "OPLSS2021.Vale.Block", "FStar.Pervasives.Native.Some", "Prims.int", "FStar.Mul.op_Star", "FStar.FunctionalExtensionality.feq", "OPLSS2021.Vale.reg", "OPLSS2021.Vale.nat64", "OPLSS2021.Vale.update_state" ]
[]
false
false
false
false
false
let lemma_Triple (s0: state) : Pure (state & fuel) (requires s0 Rax < 100) (ensures fun (sM, f0) -> eval_code (Block codes_Triple) f0 s0 == Some sM /\ sM Rbx == 3 * s0 Rax /\ sM `feq` (update_state Rax sM (update_state Rbx sM s0))) =
let b1 = codes_Triple in let s2, fc2 = lemma_Move s0 (OReg Rbx) (OReg Rax) in let b2 = Cons?.tl b1 in let s3, fc3 = lemma_Add s2 (OReg Rax) (OReg Rbx) in let b3 = Cons?.tl b2 in let s4, fc4 = lemma_Add s3 (OReg Rbx) (OReg Rax) in let b4 = Cons?.tl b3 in let sM, f4 = (s4, 0) in let f3 = lemma_merge (Cons?.hd b3) b4 s3 fc4 s4 f4 sM in let f2 = lemma_merge (Cons?.hd b2) b3 s2 fc3 s3 f3 sM in let fM = lemma_merge (Cons?.hd b1) b2 s0 fc2 s2 f2 sM in (sM, fM)
false
Hacl.Bignum.Comparison.fst
Hacl.Bignum.Comparison.bn_is_odd
val bn_is_odd: #t:limb_t -> len:size_t{v len > 0} -> a:lbignum t len -> Stack (limb t) (requires fun h -> live h a) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_is_odd (as_seq h0 a))
val bn_is_odd: #t:limb_t -> len:size_t{v len > 0} -> a:lbignum t len -> Stack (limb t) (requires fun h -> live h a) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_is_odd (as_seq h0 a))
let bn_is_odd #t len a = a.(0ul) &. uint #t 1
{ "file_name": "code/bignum/Hacl.Bignum.Comparison.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 45, "end_line": 35, "start_col": 0, "start_line": 35 }
module Hacl.Bignum.Comparison open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Base open Hacl.Bignum.Definitions open Hacl.Bignum.Lib module S = Hacl.Spec.Bignum.Comparison module ST = FStar.HyperStack.ST module Loops = Lib.LoopCombinators #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Bignum comparison and test functions /// inline_for_extraction noextract val bn_is_odd: #t:limb_t -> len:size_t{v len > 0} -> a:lbignum t len -> Stack (limb t) (requires fun h -> live h a) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_is_odd (as_seq h0 a))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Comparison.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Comparison.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Comparison", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> a: Hacl.Bignum.Definitions.lbignum t len -> FStar.HyperStack.ST.Stack (Hacl.Bignum.Definitions.limb t)
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.Definitions.lbignum", "Lib.IntTypes.op_Amp_Dot", "Lib.IntTypes.SEC", "Lib.IntTypes.uint", "Hacl.Bignum.Definitions.limb", "Lib.IntTypes.int_t", "Lib.Buffer.op_Array_Access", "Lib.Buffer.MUT", "FStar.UInt32.__uint_to_t" ]
[]
false
true
false
false
false
let bn_is_odd #t len a =
a.(0ul) &. uint #t 1
false
Hacl.Bignum.Comparison.fst
Hacl.Bignum.Comparison.bn_gt_pow2_mask
val bn_gt_pow2_mask: #t:limb_t -> len:size_t{0 < v len /\ bits t * v len <= max_size_t} -> b:lbignum t len -> x:size_t{v x < bits t * v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_gt_pow2_mask (as_seq h0 b) (v x))
val bn_gt_pow2_mask: #t:limb_t -> len:size_t{0 < v len /\ bits t * v len <= max_size_t} -> b:lbignum t len -> x:size_t{v x < bits t * v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_gt_pow2_mask (as_seq h0 b) (v x))
let bn_gt_pow2_mask #t len b x = push_frame (); let b2 = create len (uint #t 0) in bn_set_ith_bit len b2 x; let res = bn_lt_mask len b2 b in pop_frame (); res
{ "file_name": "code/bignum/Hacl.Bignum.Comparison.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 147, "start_col": 0, "start_line": 141 }
module Hacl.Bignum.Comparison open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Base open Hacl.Bignum.Definitions open Hacl.Bignum.Lib module S = Hacl.Spec.Bignum.Comparison module ST = FStar.HyperStack.ST module Loops = Lib.LoopCombinators #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Bignum comparison and test functions /// inline_for_extraction noextract val bn_is_odd: #t:limb_t -> len:size_t{v len > 0} -> a:lbignum t len -> Stack (limb t) (requires fun h -> live h a) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_is_odd (as_seq h0 a)) let bn_is_odd #t len a = a.(0ul) &. uint #t 1 inline_for_extraction noextract val bn_eq_mask: #t:limb_t -> len:size_t -> a:lbignum t len -> b:lbignum t len -> Stack (limb t) (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_eq_mask (as_seq h0 a) (as_seq h0 b)) let bn_eq_mask #t len a b = push_frame (); let mask = create 1ul (ones t SEC) in let mask = Lib.ByteBuffer.buf_eq_mask a b len mask in pop_frame (); mask inline_for_extraction noextract val bn_is_zero_mask: #t:limb_t -> len:size_t{v len > 0} -> a:lbignum t len -> Stack (limb t) (requires fun h -> live h a) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_is_zero_mask (as_seq h0 a)) let bn_is_zero_mask #t len b = push_frame (); let bn_zero = create len (uint #t 0) in let res = bn_eq_mask len b bn_zero in pop_frame (); res inline_for_extraction noextract val bn_lt_mask: #t:limb_t -> len:size_t -> a:lbignum t len -> b:lbignum t len -> Stack (limb t) (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_lt_mask (as_seq h0 a) (as_seq h0 b)) let bn_lt_mask #t len a b = push_frame (); let acc = create 1ul (uint #t 0) in [@inline_let] let refl h i : GTot (limb t) = Lib.Sequence.index (as_seq h acc) 0 in [@inline_let] let footprint i = loc acc in [@inline_let] let spec h = S.bn_lt_mask_f (as_seq h a) (as_seq h b) in let h0 = ST.get () in loop h0 len (S.bn_lt_mask_t t (v len)) refl footprint spec (fun i -> Loops.unfold_repeat_gen (v len) (S.bn_lt_mask_t t (v len)) (spec h0) (refl h0 0) (v i); let beq = eq_mask a.(i) b.(i) in let blt = lt_mask a.(i) b.(i) in acc.(0ul) <- mask_select beq acc.(0ul) (mask_select blt (ones t SEC) (zeros t SEC)) ); let mask = acc.(0ul) in pop_frame (); mask inline_for_extraction noextract val bn_lt_pow2_mask: #t:limb_t -> len:size_t{0 < v len /\ bits t * v len <= max_size_t} -> b:lbignum t len -> x:size_t{v x < bits t * v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_lt_pow2_mask (as_seq h0 b) (v x)) let bn_lt_pow2_mask #t len b x = push_frame (); let b2 = create len (uint #t 0) in bn_set_ith_bit len b2 x; let res = bn_lt_mask len b b2 in pop_frame (); res inline_for_extraction noextract val bn_gt_pow2_mask: #t:limb_t -> len:size_t{0 < v len /\ bits t * v len <= max_size_t} -> b:lbignum t len -> x:size_t{v x < bits t * v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_gt_pow2_mask (as_seq h0 b) (v x))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Comparison.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Comparison.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Comparison", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t { 0 < Lib.IntTypes.v len /\ Lib.IntTypes.bits t * Lib.IntTypes.v len <= Lib.IntTypes.max_size_t } -> b: Hacl.Bignum.Definitions.lbignum t len -> x: Lib.IntTypes.size_t{Lib.IntTypes.v x < Lib.IntTypes.bits t * Lib.IntTypes.v len} -> FStar.HyperStack.ST.Stack (Hacl.Bignum.Definitions.limb t)
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.bits", "Lib.IntTypes.max_size_t", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Definitions.limb", "Prims.unit", "FStar.HyperStack.ST.pop_frame", "Hacl.Bignum.Comparison.bn_lt_mask", "Hacl.Bignum.Lib.bn_set_ith_bit", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.Buffer.create", "Lib.IntTypes.uint", "Lib.IntTypes.SEC", "Lib.Buffer.lbuffer", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let bn_gt_pow2_mask #t len b x =
push_frame (); let b2 = create len (uint #t 0) in bn_set_ith_bit len b2 x; let res = bn_lt_mask len b2 b in pop_frame (); res
false
Hacl.Bignum.Comparison.fst
Hacl.Bignum.Comparison.bn_lt_mask
val bn_lt_mask: #t:limb_t -> len:size_t -> a:lbignum t len -> b:lbignum t len -> Stack (limb t) (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_lt_mask (as_seq h0 a) (as_seq h0 b))
val bn_lt_mask: #t:limb_t -> len:size_t -> a:lbignum t len -> b:lbignum t len -> Stack (limb t) (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_lt_mask (as_seq h0 a) (as_seq h0 b))
let bn_lt_mask #t len a b = push_frame (); let acc = create 1ul (uint #t 0) in [@inline_let] let refl h i : GTot (limb t) = Lib.Sequence.index (as_seq h acc) 0 in [@inline_let] let footprint i = loc acc in [@inline_let] let spec h = S.bn_lt_mask_f (as_seq h a) (as_seq h b) in let h0 = ST.get () in loop h0 len (S.bn_lt_mask_t t (v len)) refl footprint spec (fun i -> Loops.unfold_repeat_gen (v len) (S.bn_lt_mask_t t (v len)) (spec h0) (refl h0 0) (v i); let beq = eq_mask a.(i) b.(i) in let blt = lt_mask a.(i) b.(i) in acc.(0ul) <- mask_select beq acc.(0ul) (mask_select blt (ones t SEC) (zeros t SEC)) ); let mask = acc.(0ul) in pop_frame (); mask
{ "file_name": "code/bignum/Hacl.Bignum.Comparison.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 6, "end_line": 107, "start_col": 0, "start_line": 86 }
module Hacl.Bignum.Comparison open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Base open Hacl.Bignum.Definitions open Hacl.Bignum.Lib module S = Hacl.Spec.Bignum.Comparison module ST = FStar.HyperStack.ST module Loops = Lib.LoopCombinators #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Bignum comparison and test functions /// inline_for_extraction noextract val bn_is_odd: #t:limb_t -> len:size_t{v len > 0} -> a:lbignum t len -> Stack (limb t) (requires fun h -> live h a) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_is_odd (as_seq h0 a)) let bn_is_odd #t len a = a.(0ul) &. uint #t 1 inline_for_extraction noextract val bn_eq_mask: #t:limb_t -> len:size_t -> a:lbignum t len -> b:lbignum t len -> Stack (limb t) (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_eq_mask (as_seq h0 a) (as_seq h0 b)) let bn_eq_mask #t len a b = push_frame (); let mask = create 1ul (ones t SEC) in let mask = Lib.ByteBuffer.buf_eq_mask a b len mask in pop_frame (); mask inline_for_extraction noextract val bn_is_zero_mask: #t:limb_t -> len:size_t{v len > 0} -> a:lbignum t len -> Stack (limb t) (requires fun h -> live h a) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_is_zero_mask (as_seq h0 a)) let bn_is_zero_mask #t len b = push_frame (); let bn_zero = create len (uint #t 0) in let res = bn_eq_mask len b bn_zero in pop_frame (); res inline_for_extraction noextract val bn_lt_mask: #t:limb_t -> len:size_t -> a:lbignum t len -> b:lbignum t len -> Stack (limb t) (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_lt_mask (as_seq h0 a) (as_seq h0 b))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Comparison.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Comparison.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Comparison", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t -> a: Hacl.Bignum.Definitions.lbignum t len -> b: Hacl.Bignum.Definitions.lbignum t len -> FStar.HyperStack.ST.Stack (Hacl.Bignum.Definitions.limb t)
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Definitions.limb", "Prims.unit", "FStar.HyperStack.ST.pop_frame", "Lib.Buffer.op_Array_Access", "Lib.Buffer.MUT", "FStar.UInt32.__uint_to_t", "Lib.Buffer.loop", "Hacl.Spec.Bignum.Comparison.bn_lt_mask_t", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.b2t", "Prims.op_LessThan", "Lib.Buffer.op_Array_Assignment", "Hacl.Spec.Bignum.Base.mask_select", "Lib.IntTypes.ones", "Lib.IntTypes.SEC", "Lib.IntTypes.zeros", "Hacl.Spec.Bignum.Definitions.limb", "Lib.IntTypes.int_t", "Lib.IntTypes.lt_mask", "Lib.IntTypes.eq_mask", "Lib.LoopCombinators.unfold_repeat_gen", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Prims.nat", "Hacl.Spec.Bignum.Comparison.bn_lt_mask_f", "Lib.Buffer.as_seq", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "Prims.pow2", "LowStar.Monotonic.Buffer.loc", "Lib.IntTypes.size_nat", "Lib.Buffer.loc", "Prims.int", "Lib.Sequence.index", "Lib.Buffer.lbuffer_t", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "Lib.IntTypes.uint", "Lib.Buffer.lbuffer", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let bn_lt_mask #t len a b =
push_frame (); let acc = create 1ul (uint #t 0) in [@@ inline_let ]let refl h i : GTot (limb t) = Lib.Sequence.index (as_seq h acc) 0 in [@@ inline_let ]let footprint i = loc acc in [@@ inline_let ]let spec h = S.bn_lt_mask_f (as_seq h a) (as_seq h b) in let h0 = ST.get () in loop h0 len (S.bn_lt_mask_t t (v len)) refl footprint spec (fun i -> Loops.unfold_repeat_gen (v len) (S.bn_lt_mask_t t (v len)) (spec h0) (refl h0 0) (v i); let beq = eq_mask a.(i) b.(i) in let blt = lt_mask a.(i) b.(i) in acc.(0ul) <- mask_select beq acc.(0ul) (mask_select blt (ones t SEC) (zeros t SEC))); let mask = acc.(0ul) in pop_frame (); mask
false
Hacl.Bignum.Comparison.fst
Hacl.Bignum.Comparison.bn_lt_pow2_mask
val bn_lt_pow2_mask: #t:limb_t -> len:size_t{0 < v len /\ bits t * v len <= max_size_t} -> b:lbignum t len -> x:size_t{v x < bits t * v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_lt_pow2_mask (as_seq h0 b) (v x))
val bn_lt_pow2_mask: #t:limb_t -> len:size_t{0 < v len /\ bits t * v len <= max_size_t} -> b:lbignum t len -> x:size_t{v x < bits t * v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_lt_pow2_mask (as_seq h0 b) (v x))
let bn_lt_pow2_mask #t len b x = push_frame (); let b2 = create len (uint #t 0) in bn_set_ith_bit len b2 x; let res = bn_lt_mask len b b2 in pop_frame (); res
{ "file_name": "code/bignum/Hacl.Bignum.Comparison.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 127, "start_col": 0, "start_line": 121 }
module Hacl.Bignum.Comparison open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Base open Hacl.Bignum.Definitions open Hacl.Bignum.Lib module S = Hacl.Spec.Bignum.Comparison module ST = FStar.HyperStack.ST module Loops = Lib.LoopCombinators #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Bignum comparison and test functions /// inline_for_extraction noextract val bn_is_odd: #t:limb_t -> len:size_t{v len > 0} -> a:lbignum t len -> Stack (limb t) (requires fun h -> live h a) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_is_odd (as_seq h0 a)) let bn_is_odd #t len a = a.(0ul) &. uint #t 1 inline_for_extraction noextract val bn_eq_mask: #t:limb_t -> len:size_t -> a:lbignum t len -> b:lbignum t len -> Stack (limb t) (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_eq_mask (as_seq h0 a) (as_seq h0 b)) let bn_eq_mask #t len a b = push_frame (); let mask = create 1ul (ones t SEC) in let mask = Lib.ByteBuffer.buf_eq_mask a b len mask in pop_frame (); mask inline_for_extraction noextract val bn_is_zero_mask: #t:limb_t -> len:size_t{v len > 0} -> a:lbignum t len -> Stack (limb t) (requires fun h -> live h a) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_is_zero_mask (as_seq h0 a)) let bn_is_zero_mask #t len b = push_frame (); let bn_zero = create len (uint #t 0) in let res = bn_eq_mask len b bn_zero in pop_frame (); res inline_for_extraction noextract val bn_lt_mask: #t:limb_t -> len:size_t -> a:lbignum t len -> b:lbignum t len -> Stack (limb t) (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_lt_mask (as_seq h0 a) (as_seq h0 b)) let bn_lt_mask #t len a b = push_frame (); let acc = create 1ul (uint #t 0) in [@inline_let] let refl h i : GTot (limb t) = Lib.Sequence.index (as_seq h acc) 0 in [@inline_let] let footprint i = loc acc in [@inline_let] let spec h = S.bn_lt_mask_f (as_seq h a) (as_seq h b) in let h0 = ST.get () in loop h0 len (S.bn_lt_mask_t t (v len)) refl footprint spec (fun i -> Loops.unfold_repeat_gen (v len) (S.bn_lt_mask_t t (v len)) (spec h0) (refl h0 0) (v i); let beq = eq_mask a.(i) b.(i) in let blt = lt_mask a.(i) b.(i) in acc.(0ul) <- mask_select beq acc.(0ul) (mask_select blt (ones t SEC) (zeros t SEC)) ); let mask = acc.(0ul) in pop_frame (); mask inline_for_extraction noextract val bn_lt_pow2_mask: #t:limb_t -> len:size_t{0 < v len /\ bits t * v len <= max_size_t} -> b:lbignum t len -> x:size_t{v x < bits t * v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_lt_pow2_mask (as_seq h0 b) (v x))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Comparison.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Comparison.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Comparison", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t { 0 < Lib.IntTypes.v len /\ Lib.IntTypes.bits t * Lib.IntTypes.v len <= Lib.IntTypes.max_size_t } -> b: Hacl.Bignum.Definitions.lbignum t len -> x: Lib.IntTypes.size_t{Lib.IntTypes.v x < Lib.IntTypes.bits t * Lib.IntTypes.v len} -> FStar.HyperStack.ST.Stack (Hacl.Bignum.Definitions.limb t)
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.bits", "Lib.IntTypes.max_size_t", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Definitions.limb", "Prims.unit", "FStar.HyperStack.ST.pop_frame", "Hacl.Bignum.Comparison.bn_lt_mask", "Hacl.Bignum.Lib.bn_set_ith_bit", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.Buffer.create", "Lib.IntTypes.uint", "Lib.IntTypes.SEC", "Lib.Buffer.lbuffer", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let bn_lt_pow2_mask #t len b x =
push_frame (); let b2 = create len (uint #t 0) in bn_set_ith_bit len b2 x; let res = bn_lt_mask len b b2 in pop_frame (); res
false
Hacl.Bignum.Comparison.fst
Hacl.Bignum.Comparison.bn_is_zero_mask
val bn_is_zero_mask: #t:limb_t -> len:size_t{v len > 0} -> a:lbignum t len -> Stack (limb t) (requires fun h -> live h a) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_is_zero_mask (as_seq h0 a))
val bn_is_zero_mask: #t:limb_t -> len:size_t{v len > 0} -> a:lbignum t len -> Stack (limb t) (requires fun h -> live h a) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_is_zero_mask (as_seq h0 a))
let bn_is_zero_mask #t len b = push_frame (); let bn_zero = create len (uint #t 0) in let res = bn_eq_mask len b bn_zero in pop_frame (); res
{ "file_name": "code/bignum/Hacl.Bignum.Comparison.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 72, "start_col": 0, "start_line": 67 }
module Hacl.Bignum.Comparison open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Base open Hacl.Bignum.Definitions open Hacl.Bignum.Lib module S = Hacl.Spec.Bignum.Comparison module ST = FStar.HyperStack.ST module Loops = Lib.LoopCombinators #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Bignum comparison and test functions /// inline_for_extraction noextract val bn_is_odd: #t:limb_t -> len:size_t{v len > 0} -> a:lbignum t len -> Stack (limb t) (requires fun h -> live h a) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_is_odd (as_seq h0 a)) let bn_is_odd #t len a = a.(0ul) &. uint #t 1 inline_for_extraction noextract val bn_eq_mask: #t:limb_t -> len:size_t -> a:lbignum t len -> b:lbignum t len -> Stack (limb t) (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_eq_mask (as_seq h0 a) (as_seq h0 b)) let bn_eq_mask #t len a b = push_frame (); let mask = create 1ul (ones t SEC) in let mask = Lib.ByteBuffer.buf_eq_mask a b len mask in pop_frame (); mask inline_for_extraction noextract val bn_is_zero_mask: #t:limb_t -> len:size_t{v len > 0} -> a:lbignum t len -> Stack (limb t) (requires fun h -> live h a) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_is_zero_mask (as_seq h0 a))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Comparison.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Comparison.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Comparison", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> a: Hacl.Bignum.Definitions.lbignum t len -> FStar.HyperStack.ST.Stack (Hacl.Bignum.Definitions.limb t)
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Definitions.limb", "Prims.unit", "FStar.HyperStack.ST.pop_frame", "Hacl.Bignum.Comparison.bn_eq_mask", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.Buffer.create", "Lib.IntTypes.uint", "Lib.IntTypes.SEC", "Lib.Buffer.lbuffer", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let bn_is_zero_mask #t len b =
push_frame (); let bn_zero = create len (uint #t 0) in let res = bn_eq_mask len b bn_zero in pop_frame (); res
false
Hacl.Bignum.Comparison.fst
Hacl.Bignum.Comparison.bn_eq_mask
val bn_eq_mask: #t:limb_t -> len:size_t -> a:lbignum t len -> b:lbignum t len -> Stack (limb t) (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_eq_mask (as_seq h0 a) (as_seq h0 b))
val bn_eq_mask: #t:limb_t -> len:size_t -> a:lbignum t len -> b:lbignum t len -> Stack (limb t) (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_eq_mask (as_seq h0 a) (as_seq h0 b))
let bn_eq_mask #t len a b = push_frame (); let mask = create 1ul (ones t SEC) in let mask = Lib.ByteBuffer.buf_eq_mask a b len mask in pop_frame (); mask
{ "file_name": "code/bignum/Hacl.Bignum.Comparison.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 6, "end_line": 54, "start_col": 0, "start_line": 49 }
module Hacl.Bignum.Comparison open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Base open Hacl.Bignum.Definitions open Hacl.Bignum.Lib module S = Hacl.Spec.Bignum.Comparison module ST = FStar.HyperStack.ST module Loops = Lib.LoopCombinators #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Bignum comparison and test functions /// inline_for_extraction noextract val bn_is_odd: #t:limb_t -> len:size_t{v len > 0} -> a:lbignum t len -> Stack (limb t) (requires fun h -> live h a) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_is_odd (as_seq h0 a)) let bn_is_odd #t len a = a.(0ul) &. uint #t 1 inline_for_extraction noextract val bn_eq_mask: #t:limb_t -> len:size_t -> a:lbignum t len -> b:lbignum t len -> Stack (limb t) (requires fun h -> live h a /\ live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ r == S.bn_eq_mask (as_seq h0 a) (as_seq h0 b))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Comparison.fst.checked", "Hacl.Bignum.Lib.fst.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Comparison.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Comparison", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t -> a: Hacl.Bignum.Definitions.lbignum t len -> b: Hacl.Bignum.Definitions.lbignum t len -> FStar.HyperStack.ST.Stack (Hacl.Bignum.Definitions.limb t)
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Definitions.limb", "Prims.unit", "FStar.HyperStack.ST.pop_frame", "Lib.IntTypes.int_t", "Lib.IntTypes.SEC", "Lib.ByteBuffer.buf_eq_mask", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.ones", "Lib.Buffer.lbuffer", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let bn_eq_mask #t len a b =
push_frame (); let mask = create 1ul (ones t SEC) in let mask = Lib.ByteBuffer.buf_eq_mask a b len mask in pop_frame (); mask
false
Hacl.Impl.Curve25519.Finv.fst
Hacl.Impl.Curve25519.Finv.finv3
val finv3: #s:field_spec -> t1:lbuffer (limb s) (4ul *! nlimb s) -> tmp:felem_wide2 s -> Stack unit (requires fun h0 -> live h0 t1 /\ live h0 tmp /\ disjoint t1 tmp /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in let cs : felem s = gsub t1 (2ul *! nlimb s) (nlimb s) in fsquare_times_inv h0 as0 /\ fsquare_times_inv h0 bs /\ fsquare_times_inv h0 cs)) (ensures fun h0 _ h1 -> modifies (loc t1 |+| loc tmp) h0 h1 /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in let cs : felem s = gsub t1 (2ul *! nlimb s) (nlimb s) in let ts0 : felem s = gsub t1 (3ul *! nlimb s) (nlimb s) in let t0 = S.fsquare_times (feval h0 cs) 100 in let t0 = P.fmul t0 (feval h0 cs) in let t0 = S.fsquare_times t0 50 in let t0 = P.fmul t0 (feval h0 bs) in let t0 = S.fsquare_times t0 5 in feval h1 as0 == feval h0 as0 /\ fsquare_times_inv h1 as0 /\ feval h1 ts0 == t0 /\ fsquare_times_inv h1 ts0))
val finv3: #s:field_spec -> t1:lbuffer (limb s) (4ul *! nlimb s) -> tmp:felem_wide2 s -> Stack unit (requires fun h0 -> live h0 t1 /\ live h0 tmp /\ disjoint t1 tmp /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in let cs : felem s = gsub t1 (2ul *! nlimb s) (nlimb s) in fsquare_times_inv h0 as0 /\ fsquare_times_inv h0 bs /\ fsquare_times_inv h0 cs)) (ensures fun h0 _ h1 -> modifies (loc t1 |+| loc tmp) h0 h1 /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in let cs : felem s = gsub t1 (2ul *! nlimb s) (nlimb s) in let ts0 : felem s = gsub t1 (3ul *! nlimb s) (nlimb s) in let t0 = S.fsquare_times (feval h0 cs) 100 in let t0 = P.fmul t0 (feval h0 cs) in let t0 = S.fsquare_times t0 50 in let t0 = P.fmul t0 (feval h0 bs) in let t0 = S.fsquare_times t0 5 in feval h1 as0 == feval h0 as0 /\ fsquare_times_inv h1 as0 /\ feval h1 ts0 == t0 /\ fsquare_times_inv h1 ts0))
let finv3 #s t1 tmp = let h0 = ST.get () in let a : felem s = sub t1 0ul (nlimb s) in let b : felem s = sub t1 (nlimb s) (nlimb s) in let c : felem s = sub t1 (2ul *! nlimb s) (nlimb s) in let t0 : felem s = sub t1 (3ul *! nlimb s) (nlimb s) in let tmp1 : felem_wide s = sub tmp 0ul (nwide s) in (* 2^200 - 2^100 *) fsquare_times #s t0 c tmp1 100ul; (* 2^200 - 2^0 *) fmul_s #s t0 t0 c tmp; (* 2^250 - 2^50 *) fsquare_times #s t0 t0 tmp1 50ul; (* 2^250 - 2^0 *) fmul_s #s t0 t0 b tmp; (* 2^255 - 2^5 *) fsquare_times #s t0 t0 tmp1 5ul
{ "file_name": "code/curve25519/Hacl.Impl.Curve25519.Finv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 51, "end_line": 249, "start_col": 0, "start_line": 238 }
module Hacl.Impl.Curve25519.Finv open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Curve25519.Fields module ST = FStar.HyperStack.ST module C = Hacl.Impl.Curve25519.Fields.Core module S = Hacl.Spec.Curve25519.Finv module P = Spec.Curve25519 let _: squash (inversion field_spec) = allow_inversion field_spec #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --record_options" noextract val fsquare_times_inv: #s:field_spec -> h:mem -> f:felem s -> Type0 let fsquare_times_inv #s h f = match s with | M51 -> C.f51_felem_fits h f (1, 2, 1, 1, 1) | M64 -> True val fsqr_s: #s:field_spec -> out:felem s -> f1:felem s -> tmp:felem_wide s -> Stack unit (requires fun h -> live h out /\ live h f1 /\ live h tmp /\ (disjoint out f1 \/ out == f1) /\ (disjoint out tmp) /\ disjoint tmp f1 /\ fsquare_times_inv h f1) (ensures fun h0 _ h1 -> modifies (loc out |+| loc tmp) h0 h1 /\ fsquare_times_inv h1 out /\ feval h1 out == P.fmul (feval h0 f1) (feval h0 f1)) [@ Meta.Attribute.inline_ ] let fsqr_s #s out f1 tmp = C.fsqr #s out f1 tmp noextract val fmuls_pre: #s:field_spec -> h:mem -> f1:felem s -> f2:felem s -> Type0 let fmuls_pre #s h f1 f2 = match s with | M51 -> f51_felem_fits h f1 (1, 2, 1, 1, 1) /\ f51_felem_fits h f2 (1, 2, 1, 1, 1) | M64 -> True val fmul_s: #s:field_spec -> out:felem s -> f1:felem s -> f2:felem s -> tmp:felem_wide2 s -> Stack unit (requires fun h -> live h out /\ live h f1 /\ live h f2 /\ live h tmp /\ (disjoint out f1 \/ out == f1) /\ (disjoint out f2 \/ out == f2) /\ (disjoint out tmp) /\ (disjoint f1 f2 \/ f1 == f2) /\ disjoint f1 tmp /\ disjoint f2 tmp /\ fmuls_pre h f1 f2) (ensures fun h0 _ h1 -> modifies (loc out |+| loc tmp) h0 h1 /\ fsquare_times_inv h1 out /\ feval h1 out == P.fmul (feval h0 f1) (feval h0 f2)) [@ Meta.Attribute.inline_ ] let fmul_s #s out f1 f2 tmp = C.fmul #s out f1 f2 tmp val fsquare_times: #s:field_spec -> o:felem s -> i:felem s -> tmp:felem_wide s -> n:size_t{v n > 0} -> Stack unit (requires fun h0 -> live h0 o /\ live h0 i /\ live h0 tmp /\ (disjoint o i \/ o == i) /\ disjoint o tmp /\ disjoint tmp i /\ fsquare_times_inv h0 i) (ensures fun h0 _ h1 -> modifies (loc o |+| loc tmp) h0 h1 /\ fsquare_times_inv h1 o /\ feval h1 o == S.pow (feval #s h0 i) (pow2 (v n))) [@ Meta.Attribute.specialize ] let fsquare_times #s o inp tmp n = let h0 = ST.get() in fsqr_s #s o inp tmp; S.lemma_pow_one (feval h0 inp); S.lemma_pow_add (feval h0 inp) 1 1; assert_norm (pow2 1 = 2); let inv (h:mem) (i:nat{i < v n}) = modifies (loc o |+| loc tmp) h0 h /\ fsquare_times_inv #s h o /\ feval h o == S.pow (feval #s h0 inp) (pow2 (i + 1)) in let h1 = ST.get () in assert (inv h1 0); Lib.Loops.for 0ul (n -! 1ul) inv (fun i -> let h2 = ST.get () in fsqr_s #s o o tmp; S.lemma_pow_add (feval #s h0 inp) (pow2 (v i + 1)) (pow2 (v i + 1)); Math.Lemmas.pow2_double_sum (v i + 1)) val finv1: #s:field_spec -> i:felem s -> t1:lbuffer (limb s) (4ul *! nlimb s) -> tmp:felem_wide2 s -> Stack unit (requires fun h0 -> live h0 i /\ live h0 t1 /\ live h0 tmp /\ disjoint i t1 /\ disjoint i tmp /\ disjoint t1 tmp /\ fsquare_times_inv h0 i) (ensures fun h0 _ h1 -> modifies (loc t1 |+| loc tmp) h0 h1 /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in let a = S.fsquare_times (feval h0 i) 1 in let t0 = S.fsquare_times a 2 in let b = P.fmul t0 (feval h0 i) in let a = P.fmul b a in let t0 = S.fsquare_times a 1 in let b = P.fmul t0 b in let t0 = S.fsquare_times b 5 in let b = P.fmul t0 b in feval h1 as0 == a /\ fsquare_times_inv h1 as0 /\ feval h1 bs == b /\ fsquare_times_inv h1 bs)) [@ Meta.Attribute.inline_ ] let finv1 #s i t1 tmp = let h0 = ST.get () in let a : felem s = sub t1 0ul (nlimb s) in let b : felem s = sub t1 (nlimb s) (nlimb s) in let c : felem s = sub t1 (2ul *! nlimb s) (nlimb s) in let t0 : felem s = sub t1 (3ul *! nlimb s) (nlimb s) in let tmp1 : felem_wide s = sub tmp 0ul (nwide s) in (* 2 *) fsquare_times #s a i tmp1 1ul; (* 8 *) fsquare_times #s t0 a tmp1 2ul; (* 9 *) fmul_s #s b t0 i tmp; (* 11 *) fmul_s #s a b a tmp; (* 22 *) fsquare_times #s t0 a tmp1 1ul; (* 2^5 - 2^0 = 31 *) fmul_s #s b t0 b tmp; (* 2^10 - 2^5 *) fsquare_times #s t0 b tmp1 5ul; (* 2^10 - 2^0 *) fmul_s #s b t0 b tmp val finv2: #s:field_spec -> t1:lbuffer (limb s) (4ul *! nlimb s) -> tmp:felem_wide2 s -> Stack unit (requires fun h0 -> live h0 t1 /\ live h0 tmp /\ disjoint t1 tmp /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in fsquare_times_inv h0 as0 /\ fsquare_times_inv h0 bs)) (ensures fun h0 _ h1 -> modifies (loc t1 |+| loc tmp) h0 h1 /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in let cs : felem s = gsub t1 (2ul *! nlimb s) (nlimb s) in let t0 = S.fsquare_times (feval h0 bs) 10 in let c = P.fmul t0 (feval h0 bs) in let t0 = S.fsquare_times c 20 in let t0 = P.fmul t0 c in let t0 = S.fsquare_times t0 10 in let b = P.fmul t0 (feval h0 bs) in let t0 = S.fsquare_times b 50 in let c = P.fmul t0 b in feval h1 as0 == feval h0 as0 /\ fsquare_times_inv h1 as0 /\ feval h1 bs == b /\ fsquare_times_inv h1 bs /\ feval h1 cs == c /\ fsquare_times_inv h1 cs)) [@ Meta.Attribute.inline_ ] let finv2 #s t1 tmp = let h0 = ST.get () in let a : felem s = sub t1 0ul (nlimb s) in let b : felem s = sub t1 (nlimb s) (nlimb s) in let c : felem s = sub t1 (2ul *! nlimb s) (nlimb s) in let t0 : felem s = sub t1 (3ul *! nlimb s) (nlimb s) in let tmp1 : felem_wide s = sub tmp 0ul (nwide s) in (* 2^20 - 2^10 *) fsquare_times #s t0 b tmp1 10ul; (* 2^20 - 2^0 *) fmul_s #s c t0 b tmp; (* 2^40 - 2^20 *) fsquare_times #s t0 c tmp1 20ul; (* 2^40 - 2^0 *) fmul_s #s t0 t0 c tmp; (* 2^50 - 2^10 *) fsquare_times #s t0 t0 tmp1 10ul; (* 2^50 - 2^0 *) fmul_s #s b t0 b tmp; (* 2^100 - 2^50 *) fsquare_times #s t0 b tmp1 50ul; (* 2^100 - 2^0 *) fmul_s #s c t0 b tmp val finv3: #s:field_spec -> t1:lbuffer (limb s) (4ul *! nlimb s) -> tmp:felem_wide2 s -> Stack unit (requires fun h0 -> live h0 t1 /\ live h0 tmp /\ disjoint t1 tmp /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in let cs : felem s = gsub t1 (2ul *! nlimb s) (nlimb s) in fsquare_times_inv h0 as0 /\ fsquare_times_inv h0 bs /\ fsquare_times_inv h0 cs)) (ensures fun h0 _ h1 -> modifies (loc t1 |+| loc tmp) h0 h1 /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in let cs : felem s = gsub t1 (2ul *! nlimb s) (nlimb s) in let ts0 : felem s = gsub t1 (3ul *! nlimb s) (nlimb s) in let t0 = S.fsquare_times (feval h0 cs) 100 in let t0 = P.fmul t0 (feval h0 cs) in let t0 = S.fsquare_times t0 50 in let t0 = P.fmul t0 (feval h0 bs) in let t0 = S.fsquare_times t0 5 in feval h1 as0 == feval h0 as0 /\ fsquare_times_inv h1 as0 /\ feval h1 ts0 == t0 /\ fsquare_times_inv h1 ts0))
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Loops.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Finv.fst.checked", "Hacl.Impl.Curve25519.Fields.Core.fsti.checked", "Hacl.Impl.Curve25519.Fields.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Curve25519.Finv.fst" }
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "P" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Finv", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Fields.Core", "short_module": "C" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 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
t1: Lib.Buffer.lbuffer (Hacl.Impl.Curve25519.Fields.Core.limb s) (4ul *! Hacl.Impl.Curve25519.Fields.Core.nlimb s) -> tmp: Hacl.Impl.Curve25519.Fields.Core.felem_wide2 s -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Curve25519.Fields.Core.field_spec", "Lib.Buffer.lbuffer", "Hacl.Impl.Curve25519.Fields.Core.limb", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "FStar.UInt32.__uint_to_t", "Hacl.Impl.Curve25519.Fields.Core.nlimb", "Hacl.Impl.Curve25519.Fields.Core.felem_wide2", "Hacl.Impl.Curve25519.Finv.fsquare_times", "Prims.unit", "Hacl.Impl.Curve25519.Finv.fmul_s", "Hacl.Impl.Curve25519.Fields.Core.felem_wide", "Lib.Buffer.sub", "Lib.Buffer.MUT", "Hacl.Impl.Curve25519.Fields.Core.wide", "Lib.IntTypes.op_Plus_Dot", "Hacl.Impl.Curve25519.Fields.Core.nwide", "Lib.Buffer.lbuffer_t", "Hacl.Impl.Curve25519.Fields.Core.felem", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
false
true
false
false
false
let finv3 #s t1 tmp =
let h0 = ST.get () in let a:felem s = sub t1 0ul (nlimb s) in let b:felem s = sub t1 (nlimb s) (nlimb s) in let c:felem s = sub t1 (2ul *! nlimb s) (nlimb s) in let t0:felem s = sub t1 (3ul *! nlimb s) (nlimb s) in let tmp1:felem_wide s = sub tmp 0ul (nwide s) in fsquare_times #s t0 c tmp1 100ul; fmul_s #s t0 t0 c tmp; fsquare_times #s t0 t0 tmp1 50ul; fmul_s #s t0 t0 b tmp; fsquare_times #s t0 t0 tmp1 5ul
false
Hacl.Impl.Curve25519.Finv.fst
Hacl.Impl.Curve25519.Finv.finv1
val finv1: #s:field_spec -> i:felem s -> t1:lbuffer (limb s) (4ul *! nlimb s) -> tmp:felem_wide2 s -> Stack unit (requires fun h0 -> live h0 i /\ live h0 t1 /\ live h0 tmp /\ disjoint i t1 /\ disjoint i tmp /\ disjoint t1 tmp /\ fsquare_times_inv h0 i) (ensures fun h0 _ h1 -> modifies (loc t1 |+| loc tmp) h0 h1 /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in let a = S.fsquare_times (feval h0 i) 1 in let t0 = S.fsquare_times a 2 in let b = P.fmul t0 (feval h0 i) in let a = P.fmul b a in let t0 = S.fsquare_times a 1 in let b = P.fmul t0 b in let t0 = S.fsquare_times b 5 in let b = P.fmul t0 b in feval h1 as0 == a /\ fsquare_times_inv h1 as0 /\ feval h1 bs == b /\ fsquare_times_inv h1 bs))
val finv1: #s:field_spec -> i:felem s -> t1:lbuffer (limb s) (4ul *! nlimb s) -> tmp:felem_wide2 s -> Stack unit (requires fun h0 -> live h0 i /\ live h0 t1 /\ live h0 tmp /\ disjoint i t1 /\ disjoint i tmp /\ disjoint t1 tmp /\ fsquare_times_inv h0 i) (ensures fun h0 _ h1 -> modifies (loc t1 |+| loc tmp) h0 h1 /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in let a = S.fsquare_times (feval h0 i) 1 in let t0 = S.fsquare_times a 2 in let b = P.fmul t0 (feval h0 i) in let a = P.fmul b a in let t0 = S.fsquare_times a 1 in let b = P.fmul t0 b in let t0 = S.fsquare_times b 5 in let b = P.fmul t0 b in feval h1 as0 == a /\ fsquare_times_inv h1 as0 /\ feval h1 bs == b /\ fsquare_times_inv h1 bs))
let finv1 #s i t1 tmp = let h0 = ST.get () in let a : felem s = sub t1 0ul (nlimb s) in let b : felem s = sub t1 (nlimb s) (nlimb s) in let c : felem s = sub t1 (2ul *! nlimb s) (nlimb s) in let t0 : felem s = sub t1 (3ul *! nlimb s) (nlimb s) in let tmp1 : felem_wide s = sub tmp 0ul (nwide s) in (* 2 *) fsquare_times #s a i tmp1 1ul; (* 8 *) fsquare_times #s t0 a tmp1 2ul; (* 9 *) fmul_s #s b t0 i tmp; (* 11 *) fmul_s #s a b a tmp; (* 22 *) fsquare_times #s t0 a tmp1 1ul; (* 2^5 - 2^0 = 31 *) fmul_s #s b t0 b tmp; (* 2^10 - 2^5 *) fsquare_times #s t0 b tmp1 5ul; (* 2^10 - 2^0 *) fmul_s #s b t0 b tmp
{ "file_name": "code/curve25519/Hacl.Impl.Curve25519.Finv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 39, "end_line": 163, "start_col": 0, "start_line": 149 }
module Hacl.Impl.Curve25519.Finv open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Curve25519.Fields module ST = FStar.HyperStack.ST module C = Hacl.Impl.Curve25519.Fields.Core module S = Hacl.Spec.Curve25519.Finv module P = Spec.Curve25519 let _: squash (inversion field_spec) = allow_inversion field_spec #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --record_options" noextract val fsquare_times_inv: #s:field_spec -> h:mem -> f:felem s -> Type0 let fsquare_times_inv #s h f = match s with | M51 -> C.f51_felem_fits h f (1, 2, 1, 1, 1) | M64 -> True val fsqr_s: #s:field_spec -> out:felem s -> f1:felem s -> tmp:felem_wide s -> Stack unit (requires fun h -> live h out /\ live h f1 /\ live h tmp /\ (disjoint out f1 \/ out == f1) /\ (disjoint out tmp) /\ disjoint tmp f1 /\ fsquare_times_inv h f1) (ensures fun h0 _ h1 -> modifies (loc out |+| loc tmp) h0 h1 /\ fsquare_times_inv h1 out /\ feval h1 out == P.fmul (feval h0 f1) (feval h0 f1)) [@ Meta.Attribute.inline_ ] let fsqr_s #s out f1 tmp = C.fsqr #s out f1 tmp noextract val fmuls_pre: #s:field_spec -> h:mem -> f1:felem s -> f2:felem s -> Type0 let fmuls_pre #s h f1 f2 = match s with | M51 -> f51_felem_fits h f1 (1, 2, 1, 1, 1) /\ f51_felem_fits h f2 (1, 2, 1, 1, 1) | M64 -> True val fmul_s: #s:field_spec -> out:felem s -> f1:felem s -> f2:felem s -> tmp:felem_wide2 s -> Stack unit (requires fun h -> live h out /\ live h f1 /\ live h f2 /\ live h tmp /\ (disjoint out f1 \/ out == f1) /\ (disjoint out f2 \/ out == f2) /\ (disjoint out tmp) /\ (disjoint f1 f2 \/ f1 == f2) /\ disjoint f1 tmp /\ disjoint f2 tmp /\ fmuls_pre h f1 f2) (ensures fun h0 _ h1 -> modifies (loc out |+| loc tmp) h0 h1 /\ fsquare_times_inv h1 out /\ feval h1 out == P.fmul (feval h0 f1) (feval h0 f2)) [@ Meta.Attribute.inline_ ] let fmul_s #s out f1 f2 tmp = C.fmul #s out f1 f2 tmp val fsquare_times: #s:field_spec -> o:felem s -> i:felem s -> tmp:felem_wide s -> n:size_t{v n > 0} -> Stack unit (requires fun h0 -> live h0 o /\ live h0 i /\ live h0 tmp /\ (disjoint o i \/ o == i) /\ disjoint o tmp /\ disjoint tmp i /\ fsquare_times_inv h0 i) (ensures fun h0 _ h1 -> modifies (loc o |+| loc tmp) h0 h1 /\ fsquare_times_inv h1 o /\ feval h1 o == S.pow (feval #s h0 i) (pow2 (v n))) [@ Meta.Attribute.specialize ] let fsquare_times #s o inp tmp n = let h0 = ST.get() in fsqr_s #s o inp tmp; S.lemma_pow_one (feval h0 inp); S.lemma_pow_add (feval h0 inp) 1 1; assert_norm (pow2 1 = 2); let inv (h:mem) (i:nat{i < v n}) = modifies (loc o |+| loc tmp) h0 h /\ fsquare_times_inv #s h o /\ feval h o == S.pow (feval #s h0 inp) (pow2 (i + 1)) in let h1 = ST.get () in assert (inv h1 0); Lib.Loops.for 0ul (n -! 1ul) inv (fun i -> let h2 = ST.get () in fsqr_s #s o o tmp; S.lemma_pow_add (feval #s h0 inp) (pow2 (v i + 1)) (pow2 (v i + 1)); Math.Lemmas.pow2_double_sum (v i + 1)) val finv1: #s:field_spec -> i:felem s -> t1:lbuffer (limb s) (4ul *! nlimb s) -> tmp:felem_wide2 s -> Stack unit (requires fun h0 -> live h0 i /\ live h0 t1 /\ live h0 tmp /\ disjoint i t1 /\ disjoint i tmp /\ disjoint t1 tmp /\ fsquare_times_inv h0 i) (ensures fun h0 _ h1 -> modifies (loc t1 |+| loc tmp) h0 h1 /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in let a = S.fsquare_times (feval h0 i) 1 in let t0 = S.fsquare_times a 2 in let b = P.fmul t0 (feval h0 i) in let a = P.fmul b a in let t0 = S.fsquare_times a 1 in let b = P.fmul t0 b in let t0 = S.fsquare_times b 5 in let b = P.fmul t0 b in feval h1 as0 == a /\ fsquare_times_inv h1 as0 /\ feval h1 bs == b /\ fsquare_times_inv h1 bs))
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Loops.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Finv.fst.checked", "Hacl.Impl.Curve25519.Fields.Core.fsti.checked", "Hacl.Impl.Curve25519.Fields.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Curve25519.Finv.fst" }
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "P" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Finv", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Fields.Core", "short_module": "C" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 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
i: Hacl.Impl.Curve25519.Fields.Core.felem s -> t1: Lib.Buffer.lbuffer (Hacl.Impl.Curve25519.Fields.Core.limb s) (4ul *! Hacl.Impl.Curve25519.Fields.Core.nlimb s) -> tmp: Hacl.Impl.Curve25519.Fields.Core.felem_wide2 s -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Curve25519.Fields.Core.field_spec", "Hacl.Impl.Curve25519.Fields.Core.felem", "Lib.Buffer.lbuffer", "Hacl.Impl.Curve25519.Fields.Core.limb", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "FStar.UInt32.__uint_to_t", "Hacl.Impl.Curve25519.Fields.Core.nlimb", "Hacl.Impl.Curve25519.Fields.Core.felem_wide2", "Hacl.Impl.Curve25519.Finv.fmul_s", "Prims.unit", "Hacl.Impl.Curve25519.Finv.fsquare_times", "Hacl.Impl.Curve25519.Fields.Core.felem_wide", "Lib.Buffer.sub", "Lib.Buffer.MUT", "Hacl.Impl.Curve25519.Fields.Core.wide", "Lib.IntTypes.op_Plus_Dot", "Hacl.Impl.Curve25519.Fields.Core.nwide", "Lib.Buffer.lbuffer_t", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
false
true
false
false
false
let finv1 #s i t1 tmp =
let h0 = ST.get () in let a:felem s = sub t1 0ul (nlimb s) in let b:felem s = sub t1 (nlimb s) (nlimb s) in let c:felem s = sub t1 (2ul *! nlimb s) (nlimb s) in let t0:felem s = sub t1 (3ul *! nlimb s) (nlimb s) in let tmp1:felem_wide s = sub tmp 0ul (nwide s) in fsquare_times #s a i tmp1 1ul; fsquare_times #s t0 a tmp1 2ul; fmul_s #s b t0 i tmp; fmul_s #s a b a tmp; fsquare_times #s t0 a tmp1 1ul; fmul_s #s b t0 b tmp; fsquare_times #s t0 b tmp1 5ul; fmul_s #s b t0 b tmp
false
Hacl.Spec.BignumQ.Mul.fst
Hacl.Spec.BignumQ.Mul.mask40
val mask40:x: uint64{v x == pow2 40 - 1}
val mask40:x: uint64{v x == pow2 40 - 1}
let mask40 : x:uint64{v x == pow2 40 - 1} = assert_norm (pow2 40 - 1 == 0xffffffffff); u64 0xffffffffff
{ "file_name": "code/ed25519/Hacl.Spec.BignumQ.Mul.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 18, "end_line": 23, "start_col": 0, "start_line": 21 }
module Hacl.Spec.BignumQ.Mul open FStar.Mul open Lib.IntTypes module S = Spec.Ed25519 module Lemmas = Hacl.Spec.BignumQ.Lemmas include Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask56 : x:uint64{v x == pow2 56 - 1} = assert_norm (pow2 56 - 1 == 0xffffffffffffff); u64 0xffffffffffffff
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.BignumQ.Mul.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Lib.IntTypes.int_t Lib.IntTypes.U64 Lib.IntTypes.SEC {Lib.IntTypes.v x == Prims.pow2 40 - 1}
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.u64", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "Prims.op_Subtraction", "Prims.pow2" ]
[]
false
false
false
false
false
let mask40:x: uint64{v x == pow2 40 - 1} =
assert_norm (pow2 40 - 1 == 0xffffffffff); u64 0xffffffffff
false
Hacl.Impl.Curve25519.Finv.fst
Hacl.Impl.Curve25519.Finv.finv0
val finv0: #s:field_spec -> i:felem s -> t1:lbuffer (limb s) (4ul *! nlimb s) -> tmp:felem_wide2 s -> Stack unit (requires fun h0 -> live h0 i /\ live h0 t1 /\ live h0 tmp /\ disjoint i t1 /\ disjoint i tmp /\ disjoint t1 tmp /\ fsquare_times_inv h0 i) (ensures fun h0 _ h1 -> modifies (loc t1 |+| loc tmp) h0 h1 /\ (let a_s, t0_s = S.finv0 (feval h0 i) in let a = gsub t1 0ul (nlimb s) in let t0 = gsub t1 (3ul *! nlimb s) (nlimb s) in fsquare_times_inv h1 a /\ fsquare_times_inv h1 t0 /\ (feval h1 a, feval h1 t0) == (a_s, t0_s)))
val finv0: #s:field_spec -> i:felem s -> t1:lbuffer (limb s) (4ul *! nlimb s) -> tmp:felem_wide2 s -> Stack unit (requires fun h0 -> live h0 i /\ live h0 t1 /\ live h0 tmp /\ disjoint i t1 /\ disjoint i tmp /\ disjoint t1 tmp /\ fsquare_times_inv h0 i) (ensures fun h0 _ h1 -> modifies (loc t1 |+| loc tmp) h0 h1 /\ (let a_s, t0_s = S.finv0 (feval h0 i) in let a = gsub t1 0ul (nlimb s) in let t0 = gsub t1 (3ul *! nlimb s) (nlimb s) in fsquare_times_inv h1 a /\ fsquare_times_inv h1 t0 /\ (feval h1 a, feval h1 t0) == (a_s, t0_s)))
let finv0 #s i t1 tmp = let h0 = ST.get () in let a : felem s = sub t1 0ul (nlimb s) in let b : felem s = sub t1 (nlimb s) (nlimb s) in let c : felem s = sub t1 (2ul *! nlimb s) (nlimb s) in let t0 : felem s = sub t1 (3ul *! nlimb s) (nlimb s) in finv1 #s i t1 tmp; finv2 #s t1 tmp; finv3 #s t1 tmp; let h1 = ST.get () in assert (fsquare_times_inv h1 t0); assert (fsquare_times_inv h1 a); assert (modifies (loc t1 |+| loc tmp) h0 h1); assert ( (feval h1 a, feval h1 t0) == S.finv0 (feval h0 i))
{ "file_name": "code/curve25519/Hacl.Impl.Curve25519.Finv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 61, "end_line": 285, "start_col": 0, "start_line": 272 }
module Hacl.Impl.Curve25519.Finv open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Curve25519.Fields module ST = FStar.HyperStack.ST module C = Hacl.Impl.Curve25519.Fields.Core module S = Hacl.Spec.Curve25519.Finv module P = Spec.Curve25519 let _: squash (inversion field_spec) = allow_inversion field_spec #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --record_options" noextract val fsquare_times_inv: #s:field_spec -> h:mem -> f:felem s -> Type0 let fsquare_times_inv #s h f = match s with | M51 -> C.f51_felem_fits h f (1, 2, 1, 1, 1) | M64 -> True val fsqr_s: #s:field_spec -> out:felem s -> f1:felem s -> tmp:felem_wide s -> Stack unit (requires fun h -> live h out /\ live h f1 /\ live h tmp /\ (disjoint out f1 \/ out == f1) /\ (disjoint out tmp) /\ disjoint tmp f1 /\ fsquare_times_inv h f1) (ensures fun h0 _ h1 -> modifies (loc out |+| loc tmp) h0 h1 /\ fsquare_times_inv h1 out /\ feval h1 out == P.fmul (feval h0 f1) (feval h0 f1)) [@ Meta.Attribute.inline_ ] let fsqr_s #s out f1 tmp = C.fsqr #s out f1 tmp noextract val fmuls_pre: #s:field_spec -> h:mem -> f1:felem s -> f2:felem s -> Type0 let fmuls_pre #s h f1 f2 = match s with | M51 -> f51_felem_fits h f1 (1, 2, 1, 1, 1) /\ f51_felem_fits h f2 (1, 2, 1, 1, 1) | M64 -> True val fmul_s: #s:field_spec -> out:felem s -> f1:felem s -> f2:felem s -> tmp:felem_wide2 s -> Stack unit (requires fun h -> live h out /\ live h f1 /\ live h f2 /\ live h tmp /\ (disjoint out f1 \/ out == f1) /\ (disjoint out f2 \/ out == f2) /\ (disjoint out tmp) /\ (disjoint f1 f2 \/ f1 == f2) /\ disjoint f1 tmp /\ disjoint f2 tmp /\ fmuls_pre h f1 f2) (ensures fun h0 _ h1 -> modifies (loc out |+| loc tmp) h0 h1 /\ fsquare_times_inv h1 out /\ feval h1 out == P.fmul (feval h0 f1) (feval h0 f2)) [@ Meta.Attribute.inline_ ] let fmul_s #s out f1 f2 tmp = C.fmul #s out f1 f2 tmp val fsquare_times: #s:field_spec -> o:felem s -> i:felem s -> tmp:felem_wide s -> n:size_t{v n > 0} -> Stack unit (requires fun h0 -> live h0 o /\ live h0 i /\ live h0 tmp /\ (disjoint o i \/ o == i) /\ disjoint o tmp /\ disjoint tmp i /\ fsquare_times_inv h0 i) (ensures fun h0 _ h1 -> modifies (loc o |+| loc tmp) h0 h1 /\ fsquare_times_inv h1 o /\ feval h1 o == S.pow (feval #s h0 i) (pow2 (v n))) [@ Meta.Attribute.specialize ] let fsquare_times #s o inp tmp n = let h0 = ST.get() in fsqr_s #s o inp tmp; S.lemma_pow_one (feval h0 inp); S.lemma_pow_add (feval h0 inp) 1 1; assert_norm (pow2 1 = 2); let inv (h:mem) (i:nat{i < v n}) = modifies (loc o |+| loc tmp) h0 h /\ fsquare_times_inv #s h o /\ feval h o == S.pow (feval #s h0 inp) (pow2 (i + 1)) in let h1 = ST.get () in assert (inv h1 0); Lib.Loops.for 0ul (n -! 1ul) inv (fun i -> let h2 = ST.get () in fsqr_s #s o o tmp; S.lemma_pow_add (feval #s h0 inp) (pow2 (v i + 1)) (pow2 (v i + 1)); Math.Lemmas.pow2_double_sum (v i + 1)) val finv1: #s:field_spec -> i:felem s -> t1:lbuffer (limb s) (4ul *! nlimb s) -> tmp:felem_wide2 s -> Stack unit (requires fun h0 -> live h0 i /\ live h0 t1 /\ live h0 tmp /\ disjoint i t1 /\ disjoint i tmp /\ disjoint t1 tmp /\ fsquare_times_inv h0 i) (ensures fun h0 _ h1 -> modifies (loc t1 |+| loc tmp) h0 h1 /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in let a = S.fsquare_times (feval h0 i) 1 in let t0 = S.fsquare_times a 2 in let b = P.fmul t0 (feval h0 i) in let a = P.fmul b a in let t0 = S.fsquare_times a 1 in let b = P.fmul t0 b in let t0 = S.fsquare_times b 5 in let b = P.fmul t0 b in feval h1 as0 == a /\ fsquare_times_inv h1 as0 /\ feval h1 bs == b /\ fsquare_times_inv h1 bs)) [@ Meta.Attribute.inline_ ] let finv1 #s i t1 tmp = let h0 = ST.get () in let a : felem s = sub t1 0ul (nlimb s) in let b : felem s = sub t1 (nlimb s) (nlimb s) in let c : felem s = sub t1 (2ul *! nlimb s) (nlimb s) in let t0 : felem s = sub t1 (3ul *! nlimb s) (nlimb s) in let tmp1 : felem_wide s = sub tmp 0ul (nwide s) in (* 2 *) fsquare_times #s a i tmp1 1ul; (* 8 *) fsquare_times #s t0 a tmp1 2ul; (* 9 *) fmul_s #s b t0 i tmp; (* 11 *) fmul_s #s a b a tmp; (* 22 *) fsquare_times #s t0 a tmp1 1ul; (* 2^5 - 2^0 = 31 *) fmul_s #s b t0 b tmp; (* 2^10 - 2^5 *) fsquare_times #s t0 b tmp1 5ul; (* 2^10 - 2^0 *) fmul_s #s b t0 b tmp val finv2: #s:field_spec -> t1:lbuffer (limb s) (4ul *! nlimb s) -> tmp:felem_wide2 s -> Stack unit (requires fun h0 -> live h0 t1 /\ live h0 tmp /\ disjoint t1 tmp /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in fsquare_times_inv h0 as0 /\ fsquare_times_inv h0 bs)) (ensures fun h0 _ h1 -> modifies (loc t1 |+| loc tmp) h0 h1 /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in let cs : felem s = gsub t1 (2ul *! nlimb s) (nlimb s) in let t0 = S.fsquare_times (feval h0 bs) 10 in let c = P.fmul t0 (feval h0 bs) in let t0 = S.fsquare_times c 20 in let t0 = P.fmul t0 c in let t0 = S.fsquare_times t0 10 in let b = P.fmul t0 (feval h0 bs) in let t0 = S.fsquare_times b 50 in let c = P.fmul t0 b in feval h1 as0 == feval h0 as0 /\ fsquare_times_inv h1 as0 /\ feval h1 bs == b /\ fsquare_times_inv h1 bs /\ feval h1 cs == c /\ fsquare_times_inv h1 cs)) [@ Meta.Attribute.inline_ ] let finv2 #s t1 tmp = let h0 = ST.get () in let a : felem s = sub t1 0ul (nlimb s) in let b : felem s = sub t1 (nlimb s) (nlimb s) in let c : felem s = sub t1 (2ul *! nlimb s) (nlimb s) in let t0 : felem s = sub t1 (3ul *! nlimb s) (nlimb s) in let tmp1 : felem_wide s = sub tmp 0ul (nwide s) in (* 2^20 - 2^10 *) fsquare_times #s t0 b tmp1 10ul; (* 2^20 - 2^0 *) fmul_s #s c t0 b tmp; (* 2^40 - 2^20 *) fsquare_times #s t0 c tmp1 20ul; (* 2^40 - 2^0 *) fmul_s #s t0 t0 c tmp; (* 2^50 - 2^10 *) fsquare_times #s t0 t0 tmp1 10ul; (* 2^50 - 2^0 *) fmul_s #s b t0 b tmp; (* 2^100 - 2^50 *) fsquare_times #s t0 b tmp1 50ul; (* 2^100 - 2^0 *) fmul_s #s c t0 b tmp val finv3: #s:field_spec -> t1:lbuffer (limb s) (4ul *! nlimb s) -> tmp:felem_wide2 s -> Stack unit (requires fun h0 -> live h0 t1 /\ live h0 tmp /\ disjoint t1 tmp /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in let cs : felem s = gsub t1 (2ul *! nlimb s) (nlimb s) in fsquare_times_inv h0 as0 /\ fsquare_times_inv h0 bs /\ fsquare_times_inv h0 cs)) (ensures fun h0 _ h1 -> modifies (loc t1 |+| loc tmp) h0 h1 /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in let cs : felem s = gsub t1 (2ul *! nlimb s) (nlimb s) in let ts0 : felem s = gsub t1 (3ul *! nlimb s) (nlimb s) in let t0 = S.fsquare_times (feval h0 cs) 100 in let t0 = P.fmul t0 (feval h0 cs) in let t0 = S.fsquare_times t0 50 in let t0 = P.fmul t0 (feval h0 bs) in let t0 = S.fsquare_times t0 5 in feval h1 as0 == feval h0 as0 /\ fsquare_times_inv h1 as0 /\ feval h1 ts0 == t0 /\ fsquare_times_inv h1 ts0)) [@ Meta.Attribute.inline_ ] let finv3 #s t1 tmp = let h0 = ST.get () in let a : felem s = sub t1 0ul (nlimb s) in let b : felem s = sub t1 (nlimb s) (nlimb s) in let c : felem s = sub t1 (2ul *! nlimb s) (nlimb s) in let t0 : felem s = sub t1 (3ul *! nlimb s) (nlimb s) in let tmp1 : felem_wide s = sub tmp 0ul (nwide s) in (* 2^200 - 2^100 *) fsquare_times #s t0 c tmp1 100ul; (* 2^200 - 2^0 *) fmul_s #s t0 t0 c tmp; (* 2^250 - 2^50 *) fsquare_times #s t0 t0 tmp1 50ul; (* 2^250 - 2^0 *) fmul_s #s t0 t0 b tmp; (* 2^255 - 2^5 *) fsquare_times #s t0 t0 tmp1 5ul val finv0: #s:field_spec -> i:felem s -> t1:lbuffer (limb s) (4ul *! nlimb s) -> tmp:felem_wide2 s -> Stack unit (requires fun h0 -> live h0 i /\ live h0 t1 /\ live h0 tmp /\ disjoint i t1 /\ disjoint i tmp /\ disjoint t1 tmp /\ fsquare_times_inv h0 i) (ensures fun h0 _ h1 -> modifies (loc t1 |+| loc tmp) h0 h1 /\ (let a_s, t0_s = S.finv0 (feval h0 i) in let a = gsub t1 0ul (nlimb s) in let t0 = gsub t1 (3ul *! nlimb s) (nlimb s) in fsquare_times_inv h1 a /\ fsquare_times_inv h1 t0 /\ (feval h1 a, feval h1 t0) == (a_s, t0_s)))
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Loops.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Finv.fst.checked", "Hacl.Impl.Curve25519.Fields.Core.fsti.checked", "Hacl.Impl.Curve25519.Fields.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Curve25519.Finv.fst" }
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "P" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Finv", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Fields.Core", "short_module": "C" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 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
i: Hacl.Impl.Curve25519.Fields.Core.felem s -> t1: Lib.Buffer.lbuffer (Hacl.Impl.Curve25519.Fields.Core.limb s) (4ul *! Hacl.Impl.Curve25519.Fields.Core.nlimb s) -> tmp: Hacl.Impl.Curve25519.Fields.Core.felem_wide2 s -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Curve25519.Fields.Core.field_spec", "Hacl.Impl.Curve25519.Fields.Core.felem", "Lib.Buffer.lbuffer", "Hacl.Impl.Curve25519.Fields.Core.limb", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "FStar.UInt32.__uint_to_t", "Hacl.Impl.Curve25519.Fields.Core.nlimb", "Hacl.Impl.Curve25519.Fields.Core.felem_wide2", "Prims._assert", "Prims.eq2", "FStar.Pervasives.Native.tuple2", "Spec.Curve25519.elem", "FStar.Pervasives.Native.Mktuple2", "Hacl.Impl.Curve25519.Fields.Core.feval", "Hacl.Spec.Curve25519.Finv.finv0", "Prims.unit", "Lib.Buffer.modifies", "Lib.Buffer.op_Bar_Plus_Bar", "Lib.Buffer.loc", "Lib.Buffer.MUT", "Hacl.Impl.Curve25519.Fields.Core.wide", "Hacl.Impl.Curve25519.Finv.fsquare_times_inv", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.Impl.Curve25519.Finv.finv3", "Hacl.Impl.Curve25519.Finv.finv2", "Hacl.Impl.Curve25519.Finv.finv1", "Lib.Buffer.sub", "Lib.Buffer.lbuffer_t" ]
[]
false
true
false
false
false
let finv0 #s i t1 tmp =
let h0 = ST.get () in let a:felem s = sub t1 0ul (nlimb s) in let b:felem s = sub t1 (nlimb s) (nlimb s) in let c:felem s = sub t1 (2ul *! nlimb s) (nlimb s) in let t0:felem s = sub t1 (3ul *! nlimb s) (nlimb s) in finv1 #s i t1 tmp; finv2 #s t1 tmp; finv3 #s t1 tmp; let h1 = ST.get () in assert (fsquare_times_inv h1 t0); assert (fsquare_times_inv h1 a); assert (modifies (loc t1 |+| loc tmp) h0 h1); assert ((feval h1 a, feval h1 t0) == S.finv0 (feval h0 i))
false
Hacl.Spec.BignumQ.Mul.fst
Hacl.Spec.BignumQ.Mul.mask56
val mask56:x: uint64{v x == pow2 56 - 1}
val mask56:x: uint64{v x == pow2 56 - 1}
let mask56 : x:uint64{v x == pow2 56 - 1} = assert_norm (pow2 56 - 1 == 0xffffffffffffff); u64 0xffffffffffffff
{ "file_name": "code/ed25519/Hacl.Spec.BignumQ.Mul.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 22, "end_line": 17, "start_col": 0, "start_line": 15 }
module Hacl.Spec.BignumQ.Mul open FStar.Mul open Lib.IntTypes module S = Spec.Ed25519 module Lemmas = Hacl.Spec.BignumQ.Lemmas include Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0"
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.BignumQ.Mul.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Lib.IntTypes.int_t Lib.IntTypes.U64 Lib.IntTypes.SEC {Lib.IntTypes.v x == Prims.pow2 56 - 1}
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.u64", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "Prims.op_Subtraction", "Prims.pow2" ]
[]
false
false
false
false
false
let mask56:x: uint64{v x == pow2 56 - 1} =
assert_norm (pow2 56 - 1 == 0xffffffffffffff); u64 0xffffffffffffff
false
Hacl.Spec.BignumQ.Mul.fst
Hacl.Spec.BignumQ.Mul.make_m
val make_m: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == S.q}
val make_m: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == S.q}
let make_m () = let m0 = u64 0x12631a5cf5d3ed in let m1 = u64 0xf9dea2f79cd658 in let m2 = u64 0x000000000014de in let m3 = u64 0x00000000000000 in let m4 = u64 0x00000010000000 in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == S.q); (m0, m1, m2, m3, m4)
{ "file_name": "code/ed25519/Hacl.Spec.BignumQ.Mul.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 22, "end_line": 35, "start_col": 0, "start_line": 28 }
module Hacl.Spec.BignumQ.Mul open FStar.Mul open Lib.IntTypes module S = Spec.Ed25519 module Lemmas = Hacl.Spec.BignumQ.Lemmas include Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask56 : x:uint64{v x == pow2 56 - 1} = assert_norm (pow2 56 - 1 == 0xffffffffffffff); u64 0xffffffffffffff inline_for_extraction noextract let mask40 : x:uint64{v x == pow2 40 - 1} = assert_norm (pow2 40 - 1 == 0xffffffffff); u64 0xffffffffff inline_for_extraction noextract
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.BignumQ.Mul.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> m: Hacl.Spec.BignumQ.Definitions.qelem5 { Hacl.Spec.BignumQ.Definitions.qelem_fits5 m (1, 1, 1, 1, 1) /\ Hacl.Spec.BignumQ.Definitions.as_nat5 m == Spec.Ed25519.q }
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "FStar.Pervasives.Native.Mktuple5", "Lib.IntTypes.uint64", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.nat", "Hacl.Spec.BignumQ.Definitions.as_nat5", "Spec.Ed25519.q", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Prims.int", "Lib.IntTypes.range", "Lib.IntTypes.v", "Lib.IntTypes.u64", "Hacl.Spec.BignumQ.Definitions.qelem5", "Prims.l_and", "Hacl.Spec.BignumQ.Definitions.qelem_fits5" ]
[]
false
false
false
false
false
let make_m () =
let m0 = u64 0x12631a5cf5d3ed in let m1 = u64 0xf9dea2f79cd658 in let m2 = u64 0x000000000014de in let m3 = u64 0x00000000000000 in let m4 = u64 0x00000010000000 in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == S.q); (m0, m1, m2, m3, m4)
false
Hacl.Spec.BignumQ.Mul.fst
Hacl.Spec.BignumQ.Mul.subm_step
val subm_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow56 /\ v y <= pow56) (ensures fun (b, t) -> v b <= 1 /\ qelem_fits1 t 1 /\ v x - v y == v t - v b * pow56)
val subm_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow56 /\ v y <= pow56) (ensures fun (b, t) -> v b <= 1 /\ qelem_fits1 t 1 /\ v x - v y == v t - v b * pow56)
let subm_step x y = let b = (x -. y) >>. 63ul in //assert (if v x >= v y then v b == 0 else v b == 1); let lshift56 = (b <<. 56ul) in //assert (if v x >= v y then v lshift56 == 0 else v lshift56 == pow56); //assert (v lshift56 == v b * pow56); //assert (v ((b <<. 56ul) +! x) == v b * pow56 + v x); let t = ((b <<. 56ul) +! x) -! y in b, t
{ "file_name": "code/ed25519/Hacl.Spec.BignumQ.Mul.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 6, "end_line": 90, "start_col": 0, "start_line": 82 }
module Hacl.Spec.BignumQ.Mul open FStar.Mul open Lib.IntTypes module S = Spec.Ed25519 module Lemmas = Hacl.Spec.BignumQ.Lemmas include Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask56 : x:uint64{v x == pow2 56 - 1} = assert_norm (pow2 56 - 1 == 0xffffffffffffff); u64 0xffffffffffffff inline_for_extraction noextract let mask40 : x:uint64{v x == pow2 40 - 1} = assert_norm (pow2 40 - 1 == 0xffffffffff); u64 0xffffffffff inline_for_extraction noextract val make_m: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == S.q} let make_m () = let m0 = u64 0x12631a5cf5d3ed in let m1 = u64 0xf9dea2f79cd658 in let m2 = u64 0x000000000014de in let m3 = u64 0x00000000000000 in let m4 = u64 0x00000010000000 in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val make_mu: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == pow2 512 / S.q} let make_mu m = let m0 = u64 0x9ce5a30a2c131b in let m1 = u64 0x215d086329a7ed in let m2 = u64 0xffffffffeb2106 in let m3 = u64 0xffffffffffffff in let m4 = u64 0x00000fffffffff in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == pow2 512 / S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val choose: b:uint64 -> x:qelem5 -> y:qelem5 -> Pure qelem5 (requires v b == 0 \/ v b == 1) (ensures fun z -> if v b = 1 then z == x else z == y) let choose b (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let mask = b -. u64 1 in let z0 = x0 ^. (mask &. (x0 ^. y0)) in Lemmas.lemma_choose_step b x0 y0; let z1 = x1 ^. (mask &. (x1 ^. y1)) in Lemmas.lemma_choose_step b x1 y1; let z2 = x2 ^. (mask &. (x2 ^. y2)) in Lemmas.lemma_choose_step b x2 y2; let z3 = x3 ^. (mask &. (x3 ^. y3)) in Lemmas.lemma_choose_step b x3 y3; let z4 = x4 ^. (mask &. (x4 ^. y4)) in Lemmas.lemma_choose_step b x4 y4; (z0, z1, z2, z3, z4) inline_for_extraction noextract val subm_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow56 /\ v y <= pow56) (ensures fun (b, t) -> v b <= 1 /\ qelem_fits1 t 1 /\ v x - v y == v t - v b * pow56)
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.BignumQ.Mul.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Lib.IntTypes.uint64 -> y: Lib.IntTypes.uint64 -> Prims.Pure (Lib.IntTypes.uint64 * Lib.IntTypes.uint64)
Prims.Pure
[]
[]
[ "Lib.IntTypes.uint64", "FStar.Pervasives.Native.Mktuple2", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Subtraction_Bang", "Lib.IntTypes.op_Plus_Bang", "Lib.IntTypes.op_Less_Less_Dot", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.op_Greater_Greater_Dot", "Lib.IntTypes.op_Subtraction_Dot", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
false
false
let subm_step x y =
let b = (x -. y) >>. 63ul in let lshift56 = (b <<. 56ul) in let t = ((b <<. 56ul) +! x) -! y in b, t
false
Hacl.Spec.BignumQ.Mul.fst
Hacl.Spec.BignumQ.Mul.choose
val choose: b:uint64 -> x:qelem5 -> y:qelem5 -> Pure qelem5 (requires v b == 0 \/ v b == 1) (ensures fun z -> if v b = 1 then z == x else z == y)
val choose: b:uint64 -> x:qelem5 -> y:qelem5 -> Pure qelem5 (requires v b == 0 \/ v b == 1) (ensures fun z -> if v b = 1 then z == x else z == y)
let choose b (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let mask = b -. u64 1 in let z0 = x0 ^. (mask &. (x0 ^. y0)) in Lemmas.lemma_choose_step b x0 y0; let z1 = x1 ^. (mask &. (x1 ^. y1)) in Lemmas.lemma_choose_step b x1 y1; let z2 = x2 ^. (mask &. (x2 ^. y2)) in Lemmas.lemma_choose_step b x2 y2; let z3 = x3 ^. (mask &. (x3 ^. y3)) in Lemmas.lemma_choose_step b x3 y3; let z4 = x4 ^. (mask &. (x4 ^. y4)) in Lemmas.lemma_choose_step b x4 y4; (z0, z1, z2, z3, z4)
{ "file_name": "code/ed25519/Hacl.Spec.BignumQ.Mul.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 22, "end_line": 71, "start_col": 0, "start_line": 59 }
module Hacl.Spec.BignumQ.Mul open FStar.Mul open Lib.IntTypes module S = Spec.Ed25519 module Lemmas = Hacl.Spec.BignumQ.Lemmas include Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask56 : x:uint64{v x == pow2 56 - 1} = assert_norm (pow2 56 - 1 == 0xffffffffffffff); u64 0xffffffffffffff inline_for_extraction noextract let mask40 : x:uint64{v x == pow2 40 - 1} = assert_norm (pow2 40 - 1 == 0xffffffffff); u64 0xffffffffff inline_for_extraction noextract val make_m: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == S.q} let make_m () = let m0 = u64 0x12631a5cf5d3ed in let m1 = u64 0xf9dea2f79cd658 in let m2 = u64 0x000000000014de in let m3 = u64 0x00000000000000 in let m4 = u64 0x00000010000000 in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val make_mu: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == pow2 512 / S.q} let make_mu m = let m0 = u64 0x9ce5a30a2c131b in let m1 = u64 0x215d086329a7ed in let m2 = u64 0xffffffffeb2106 in let m3 = u64 0xffffffffffffff in let m4 = u64 0x00000fffffffff in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == pow2 512 / S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val choose: b:uint64 -> x:qelem5 -> y:qelem5 -> Pure qelem5 (requires v b == 0 \/ v b == 1) (ensures fun z -> if v b = 1 then z == x else z == y)
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.BignumQ.Mul.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Lib.IntTypes.uint64 -> x: Hacl.Spec.BignumQ.Definitions.qelem5 -> y: Hacl.Spec.BignumQ.Definitions.qelem5 -> Prims.Pure Hacl.Spec.BignumQ.Definitions.qelem5
Prims.Pure
[]
[]
[ "Lib.IntTypes.uint64", "Hacl.Spec.BignumQ.Definitions.qelem5", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple5", "FStar.Pervasives.Native.Mktuple5", "Prims.unit", "Hacl.Spec.BignumQ.Lemmas.lemma_choose_step", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Hat_Dot", "Lib.IntTypes.op_Amp_Dot", "Lib.IntTypes.op_Subtraction_Dot", "Lib.IntTypes.u64" ]
[]
false
false
false
false
false
let choose b (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) =
let mask = b -. u64 1 in let z0 = x0 ^. (mask &. (x0 ^. y0)) in Lemmas.lemma_choose_step b x0 y0; let z1 = x1 ^. (mask &. (x1 ^. y1)) in Lemmas.lemma_choose_step b x1 y1; let z2 = x2 ^. (mask &. (x2 ^. y2)) in Lemmas.lemma_choose_step b x2 y2; let z3 = x3 ^. (mask &. (x3 ^. y3)) in Lemmas.lemma_choose_step b x3 y3; let z4 = x4 ^. (mask &. (x4 ^. y4)) in Lemmas.lemma_choose_step b x4 y4; (z0, z1, z2, z3, z4)
false
Hacl.Spec.BignumQ.Mul.fst
Hacl.Spec.BignumQ.Mul.carry56
val carry56: x:uint64 -> Pure (uint64 & uint64) (requires v x <= pow2 57) (ensures fun (t, c) -> v t < pow56 /\ v c <= 2 /\ v x == v c * pow56 + v t)
val carry56: x:uint64 -> Pure (uint64 & uint64) (requires v x <= pow2 57) (ensures fun (t, c) -> v t < pow56 /\ v c <= 2 /\ v x == v c * pow56 + v t)
let carry56 x = let carry = x >>. 56ul in FStar.Math.Lemmas.pow2_minus 57 56; let t = x &. mask56 in assert_norm (pow2 56 < pow2 64); mod_mask_lemma x 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); t, carry
{ "file_name": "code/ed25519/Hacl.Spec.BignumQ.Mul.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 10, "end_line": 161, "start_col": 0, "start_line": 152 }
module Hacl.Spec.BignumQ.Mul open FStar.Mul open Lib.IntTypes module S = Spec.Ed25519 module Lemmas = Hacl.Spec.BignumQ.Lemmas include Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask56 : x:uint64{v x == pow2 56 - 1} = assert_norm (pow2 56 - 1 == 0xffffffffffffff); u64 0xffffffffffffff inline_for_extraction noextract let mask40 : x:uint64{v x == pow2 40 - 1} = assert_norm (pow2 40 - 1 == 0xffffffffff); u64 0xffffffffff inline_for_extraction noextract val make_m: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == S.q} let make_m () = let m0 = u64 0x12631a5cf5d3ed in let m1 = u64 0xf9dea2f79cd658 in let m2 = u64 0x000000000014de in let m3 = u64 0x00000000000000 in let m4 = u64 0x00000010000000 in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val make_mu: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == pow2 512 / S.q} let make_mu m = let m0 = u64 0x9ce5a30a2c131b in let m1 = u64 0x215d086329a7ed in let m2 = u64 0xffffffffeb2106 in let m3 = u64 0xffffffffffffff in let m4 = u64 0x00000fffffffff in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == pow2 512 / S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val choose: b:uint64 -> x:qelem5 -> y:qelem5 -> Pure qelem5 (requires v b == 0 \/ v b == 1) (ensures fun z -> if v b = 1 then z == x else z == y) let choose b (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let mask = b -. u64 1 in let z0 = x0 ^. (mask &. (x0 ^. y0)) in Lemmas.lemma_choose_step b x0 y0; let z1 = x1 ^. (mask &. (x1 ^. y1)) in Lemmas.lemma_choose_step b x1 y1; let z2 = x2 ^. (mask &. (x2 ^. y2)) in Lemmas.lemma_choose_step b x2 y2; let z3 = x3 ^. (mask &. (x3 ^. y3)) in Lemmas.lemma_choose_step b x3 y3; let z4 = x4 ^. (mask &. (x4 ^. y4)) in Lemmas.lemma_choose_step b x4 y4; (z0, z1, z2, z3, z4) inline_for_extraction noextract val subm_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow56 /\ v y <= pow56) (ensures fun (b, t) -> v b <= 1 /\ qelem_fits1 t 1 /\ v x - v y == v t - v b * pow56) let subm_step x y = let b = (x -. y) >>. 63ul in //assert (if v x >= v y then v b == 0 else v b == 1); let lshift56 = (b <<. 56ul) in //assert (if v x >= v y then v lshift56 == 0 else v lshift56 == pow56); //assert (v lshift56 == v b * pow56); //assert (v ((b <<. 56ul) +! x) == v b * pow56 + v x); let t = ((b <<. 56ul) +! x) -! y in b, t inline_for_extraction noextract val subm_conditional: x:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ (if as_nat5 x >= S.q then as_nat5 r == as_nat5 x - S.q else as_nat5 r == as_nat5 x)) let subm_conditional (x0, x1, x2, x3, x4) = let (y0, y1, y2, y3, y4) = make_m () in let (b0, t0) = subm_step x0 y0 in assert (v x0 - v y0 == v t0 - v b0 * pow56); let (b1, t1) = subm_step x1 (y1 +! b0) in assert (v x1 - v y1 - v b0 == v t1 - v b1 * pow56); let (b2, t2) = subm_step x2 (y2 +! b1) in assert (v x2 - v y2 - v b1 == v t2 - v b2 * pow56); let (b3, t3) = subm_step x3 (y3 +! b2) in assert (v x3 - v y3 - v b2 == v t3 - v b3 * pow56); let (b4, t4) = subm_step x4 (y4 +! b3) in assert (v x4 - v y4 - v b3 == v t4 - v b4 * pow56); Lemmas.lemma_subm_conditional (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) (v b0) (v b1) (v b2) (v b3) (v b4); assert ( as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow56 * pow224 == as_nat5 (x0, x1, x2, x3, x4) - as_nat5 (y0, y1, y2, y3, y4)); //assert_norm (pow56 * pow224 = pow2 280); //assert (as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow2 280 == as_nat5 (x0, x1, x2, x3, x4) - S.q); Lemmas.lemma_as_nat5 (x0, x1, x2, x3, x4); Lemmas.lemma_as_nat5 (t0, t1, t2, t3, t4); //assert (if v b4 = 0 then as_nat5 (x0, x1, x2, x3, x4) >= S.q else as_nat5 (x0, x1, x2, x3, x4) < S.q); assert (if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 else v b4 == 1); let (z0, z1, z2, z3, z4) = choose b4 (x0, x1, x2, x3, x4) (t0, t1, t2, t3, t4) in assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else v b4 == 1 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); (z0, z1, z2, z3, z4) inline_for_extraction noextract val carry56: x:uint64 -> Pure (uint64 & uint64) (requires v x <= pow2 57) (ensures fun (t, c) -> v t < pow56 /\ v c <= 2 /\ v x == v c * pow56 + v t)
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.BignumQ.Mul.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Lib.IntTypes.uint64 -> Prims.Pure (Lib.IntTypes.uint64 * Lib.IntTypes.uint64)
Prims.Pure
[]
[]
[ "Lib.IntTypes.uint64", "FStar.Pervasives.Native.Mktuple2", "Prims.unit", "Prims._assert", "Prims.eq2", "Prims.int", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Prims.op_Addition", "FStar.Mul.op_Star", "Prims.pow2", "Prims.op_Modulus", "Lib.IntTypes.range_t", "Lib.IntTypes.mod_mask", "FStar.UInt32.__uint_to_t", "Hacl.Spec.BignumQ.Mul.mask56", "Lib.IntTypes.mod_mask_lemma", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Amp_Dot", "FStar.Math.Lemmas.pow2_minus", "Lib.IntTypes.op_Greater_Greater_Dot", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
false
false
let carry56 x =
let carry = x >>. 56ul in FStar.Math.Lemmas.pow2_minus 57 56; let t = x &. mask56 in assert_norm (pow2 56 < pow2 64); mod_mask_lemma x 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); t, carry
false
Hacl.Spec.BignumQ.Mul.fst
Hacl.Spec.BignumQ.Mul.add2
val add2: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112) (ensures fun z -> v z == v a + v b /\ v z <= pow2 116)
val add2: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112) (ensures fun z -> v z == v a + v b /\ v z <= pow2 116)
let add2 a b = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b
{ "file_name": "code/ed25519/Hacl.Spec.BignumQ.Mul.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 8, "end_line": 266, "start_col": 0, "start_line": 262 }
module Hacl.Spec.BignumQ.Mul open FStar.Mul open Lib.IntTypes module S = Spec.Ed25519 module Lemmas = Hacl.Spec.BignumQ.Lemmas include Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask56 : x:uint64{v x == pow2 56 - 1} = assert_norm (pow2 56 - 1 == 0xffffffffffffff); u64 0xffffffffffffff inline_for_extraction noextract let mask40 : x:uint64{v x == pow2 40 - 1} = assert_norm (pow2 40 - 1 == 0xffffffffff); u64 0xffffffffff inline_for_extraction noextract val make_m: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == S.q} let make_m () = let m0 = u64 0x12631a5cf5d3ed in let m1 = u64 0xf9dea2f79cd658 in let m2 = u64 0x000000000014de in let m3 = u64 0x00000000000000 in let m4 = u64 0x00000010000000 in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val make_mu: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == pow2 512 / S.q} let make_mu m = let m0 = u64 0x9ce5a30a2c131b in let m1 = u64 0x215d086329a7ed in let m2 = u64 0xffffffffeb2106 in let m3 = u64 0xffffffffffffff in let m4 = u64 0x00000fffffffff in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == pow2 512 / S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val choose: b:uint64 -> x:qelem5 -> y:qelem5 -> Pure qelem5 (requires v b == 0 \/ v b == 1) (ensures fun z -> if v b = 1 then z == x else z == y) let choose b (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let mask = b -. u64 1 in let z0 = x0 ^. (mask &. (x0 ^. y0)) in Lemmas.lemma_choose_step b x0 y0; let z1 = x1 ^. (mask &. (x1 ^. y1)) in Lemmas.lemma_choose_step b x1 y1; let z2 = x2 ^. (mask &. (x2 ^. y2)) in Lemmas.lemma_choose_step b x2 y2; let z3 = x3 ^. (mask &. (x3 ^. y3)) in Lemmas.lemma_choose_step b x3 y3; let z4 = x4 ^. (mask &. (x4 ^. y4)) in Lemmas.lemma_choose_step b x4 y4; (z0, z1, z2, z3, z4) inline_for_extraction noextract val subm_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow56 /\ v y <= pow56) (ensures fun (b, t) -> v b <= 1 /\ qelem_fits1 t 1 /\ v x - v y == v t - v b * pow56) let subm_step x y = let b = (x -. y) >>. 63ul in //assert (if v x >= v y then v b == 0 else v b == 1); let lshift56 = (b <<. 56ul) in //assert (if v x >= v y then v lshift56 == 0 else v lshift56 == pow56); //assert (v lshift56 == v b * pow56); //assert (v ((b <<. 56ul) +! x) == v b * pow56 + v x); let t = ((b <<. 56ul) +! x) -! y in b, t inline_for_extraction noextract val subm_conditional: x:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ (if as_nat5 x >= S.q then as_nat5 r == as_nat5 x - S.q else as_nat5 r == as_nat5 x)) let subm_conditional (x0, x1, x2, x3, x4) = let (y0, y1, y2, y3, y4) = make_m () in let (b0, t0) = subm_step x0 y0 in assert (v x0 - v y0 == v t0 - v b0 * pow56); let (b1, t1) = subm_step x1 (y1 +! b0) in assert (v x1 - v y1 - v b0 == v t1 - v b1 * pow56); let (b2, t2) = subm_step x2 (y2 +! b1) in assert (v x2 - v y2 - v b1 == v t2 - v b2 * pow56); let (b3, t3) = subm_step x3 (y3 +! b2) in assert (v x3 - v y3 - v b2 == v t3 - v b3 * pow56); let (b4, t4) = subm_step x4 (y4 +! b3) in assert (v x4 - v y4 - v b3 == v t4 - v b4 * pow56); Lemmas.lemma_subm_conditional (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) (v b0) (v b1) (v b2) (v b3) (v b4); assert ( as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow56 * pow224 == as_nat5 (x0, x1, x2, x3, x4) - as_nat5 (y0, y1, y2, y3, y4)); //assert_norm (pow56 * pow224 = pow2 280); //assert (as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow2 280 == as_nat5 (x0, x1, x2, x3, x4) - S.q); Lemmas.lemma_as_nat5 (x0, x1, x2, x3, x4); Lemmas.lemma_as_nat5 (t0, t1, t2, t3, t4); //assert (if v b4 = 0 then as_nat5 (x0, x1, x2, x3, x4) >= S.q else as_nat5 (x0, x1, x2, x3, x4) < S.q); assert (if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 else v b4 == 1); let (z0, z1, z2, z3, z4) = choose b4 (x0, x1, x2, x3, x4) (t0, t1, t2, t3, t4) in assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else v b4 == 1 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); (z0, z1, z2, z3, z4) inline_for_extraction noextract val carry56: x:uint64 -> Pure (uint64 & uint64) (requires v x <= pow2 57) (ensures fun (t, c) -> v t < pow56 /\ v c <= 2 /\ v x == v c * pow56 + v t) let carry56 x = let carry = x >>. 56ul in FStar.Math.Lemmas.pow2_minus 57 56; let t = x &. mask56 in assert_norm (pow2 56 < pow2 64); mod_mask_lemma x 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); t, carry inline_for_extraction noextract val add_modq5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < S.q /\ as_nat5 y < S.q) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (as_nat5 x + as_nat5 y) % S.q) let add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = assert_norm (pow56 - 1 + pow56 - 1 == pow2 57 - 2); let (t0, c0) = carry56 (x0 +! y0) in let (t1, c1) = carry56 (x1 +! y1 +! c0) in let (t2, c2) = carry56 (x2 +! y2 +! c1) in let (t3, c3) = carry56 (x3 +! y3 +! c2) in let t4 = x4 +! y4 +! c3 in assert (as_nat5 (t0, t1, t2, t3, t4) == as_nat5 (x0, x1, x2, x3, x4) + as_nat5 (y0, y1, y2, y3, y4)); let (o0, o1, o2, o3, o4) = subm_conditional (t0, t1, t2, t3, t4) in Lemmas.lemma_add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) (t0, t1, t2, t3, t4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry56_wide: x:uint128 -> Pure (uint128 & uint64) (requires v x < pow2 117) (ensures fun (c, t) -> v t < pow56 /\ v c < pow2 61 /\ v x - v c * pow56 == v t /\ v c == v x / pow56) let carry56_wide x = let carry = x >>. 56ul in let t = to_u64 x &. mask56 in assert_norm (pow2 56 < pow2 64); Math.Lemmas.lemma_div_lt_nat (v x) 117 56; mod_mask_lemma (to_u64 x) 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == (v x % pow2 64) % pow2 56); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v x) 56 64; assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); carry, t inline_for_extraction noextract val mul64_wide_5: (a:uint64) -> (b:uint64) -> Pure uint128 (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures fun z -> v z == v a * v b /\ v z <= pow2 112 - pow2 57 + 1 /\ v z < pow2 112) let mul64_wide_5 a b = let lemma_smaller (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) < pow2 112) = if v a = 0 || v b = 0 then () else calc (<) { v a * v b <: int; (<) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56) } v a * pow2 56; (<) { Math.Lemmas.lemma_mult_le_right (pow2 56) (v a) (pow2 56) } pow2 56 * pow2 56; (==) { assert_norm (pow2 56 * pow2 56 == pow2 112) } pow2 112; } in let lemma_le (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) <= pow2 112 - pow2 57 + 1) = if v a = 0 || v b = 0 then () else assert_norm (pow2 112 - pow2 57 + 1 >= 0); calc (<=) { v a * v b <: int; (<=) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56 - 1) } v a * (pow2 56 - 1); (<=) { Math.Lemmas.lemma_mult_le_right (pow2 56 - 1) (v a) (pow2 56 - 1) } (pow2 56 - 1) * (pow2 56 - 1); (==) { assert_norm ((pow2 56 - 1) * (pow2 56 - 1) == pow2 112 - pow2 57 + 1) } pow2 112 - pow2 57 + 1; } in lemma_le a b; lemma_smaller a b; mul64_wide a b inline_for_extraction noextract val add2: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112) (ensures fun z -> v z == v a + v b /\
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.BignumQ.Mul.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.IntTypes.uint128 -> b: Lib.IntTypes.uint128 -> Prims.Pure Lib.IntTypes.uint128
Prims.Pure
[]
[]
[ "Lib.IntTypes.uint128", "Lib.IntTypes.op_Plus_Dot", "Lib.IntTypes.U128", "Lib.IntTypes.SEC", "Prims.unit", "FStar.Math.Lemmas.small_mod", "Prims.op_Addition", "Lib.IntTypes.v", "Prims.pow2", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan" ]
[]
false
false
false
false
false
let add2 a b =
assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b
false
Hacl.Spec.BignumQ.Mul.fst
Hacl.Spec.BignumQ.Mul.add3
val add3: (a:uint128) -> (b:uint128) -> (c:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 ) (ensures fun z -> v z == v a + v b + v c /\ v z <= pow2 116)
val add3: (a:uint128) -> (b:uint128) -> (c:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 ) (ensures fun z -> v z == v a + v b + v c /\ v z <= pow2 116)
let add3 a b c = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); a +. b +. c
{ "file_name": "code/ed25519/Hacl.Spec.BignumQ.Mul.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 282, "start_col": 0, "start_line": 276 }
module Hacl.Spec.BignumQ.Mul open FStar.Mul open Lib.IntTypes module S = Spec.Ed25519 module Lemmas = Hacl.Spec.BignumQ.Lemmas include Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask56 : x:uint64{v x == pow2 56 - 1} = assert_norm (pow2 56 - 1 == 0xffffffffffffff); u64 0xffffffffffffff inline_for_extraction noextract let mask40 : x:uint64{v x == pow2 40 - 1} = assert_norm (pow2 40 - 1 == 0xffffffffff); u64 0xffffffffff inline_for_extraction noextract val make_m: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == S.q} let make_m () = let m0 = u64 0x12631a5cf5d3ed in let m1 = u64 0xf9dea2f79cd658 in let m2 = u64 0x000000000014de in let m3 = u64 0x00000000000000 in let m4 = u64 0x00000010000000 in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val make_mu: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == pow2 512 / S.q} let make_mu m = let m0 = u64 0x9ce5a30a2c131b in let m1 = u64 0x215d086329a7ed in let m2 = u64 0xffffffffeb2106 in let m3 = u64 0xffffffffffffff in let m4 = u64 0x00000fffffffff in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == pow2 512 / S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val choose: b:uint64 -> x:qelem5 -> y:qelem5 -> Pure qelem5 (requires v b == 0 \/ v b == 1) (ensures fun z -> if v b = 1 then z == x else z == y) let choose b (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let mask = b -. u64 1 in let z0 = x0 ^. (mask &. (x0 ^. y0)) in Lemmas.lemma_choose_step b x0 y0; let z1 = x1 ^. (mask &. (x1 ^. y1)) in Lemmas.lemma_choose_step b x1 y1; let z2 = x2 ^. (mask &. (x2 ^. y2)) in Lemmas.lemma_choose_step b x2 y2; let z3 = x3 ^. (mask &. (x3 ^. y3)) in Lemmas.lemma_choose_step b x3 y3; let z4 = x4 ^. (mask &. (x4 ^. y4)) in Lemmas.lemma_choose_step b x4 y4; (z0, z1, z2, z3, z4) inline_for_extraction noextract val subm_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow56 /\ v y <= pow56) (ensures fun (b, t) -> v b <= 1 /\ qelem_fits1 t 1 /\ v x - v y == v t - v b * pow56) let subm_step x y = let b = (x -. y) >>. 63ul in //assert (if v x >= v y then v b == 0 else v b == 1); let lshift56 = (b <<. 56ul) in //assert (if v x >= v y then v lshift56 == 0 else v lshift56 == pow56); //assert (v lshift56 == v b * pow56); //assert (v ((b <<. 56ul) +! x) == v b * pow56 + v x); let t = ((b <<. 56ul) +! x) -! y in b, t inline_for_extraction noextract val subm_conditional: x:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ (if as_nat5 x >= S.q then as_nat5 r == as_nat5 x - S.q else as_nat5 r == as_nat5 x)) let subm_conditional (x0, x1, x2, x3, x4) = let (y0, y1, y2, y3, y4) = make_m () in let (b0, t0) = subm_step x0 y0 in assert (v x0 - v y0 == v t0 - v b0 * pow56); let (b1, t1) = subm_step x1 (y1 +! b0) in assert (v x1 - v y1 - v b0 == v t1 - v b1 * pow56); let (b2, t2) = subm_step x2 (y2 +! b1) in assert (v x2 - v y2 - v b1 == v t2 - v b2 * pow56); let (b3, t3) = subm_step x3 (y3 +! b2) in assert (v x3 - v y3 - v b2 == v t3 - v b3 * pow56); let (b4, t4) = subm_step x4 (y4 +! b3) in assert (v x4 - v y4 - v b3 == v t4 - v b4 * pow56); Lemmas.lemma_subm_conditional (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) (v b0) (v b1) (v b2) (v b3) (v b4); assert ( as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow56 * pow224 == as_nat5 (x0, x1, x2, x3, x4) - as_nat5 (y0, y1, y2, y3, y4)); //assert_norm (pow56 * pow224 = pow2 280); //assert (as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow2 280 == as_nat5 (x0, x1, x2, x3, x4) - S.q); Lemmas.lemma_as_nat5 (x0, x1, x2, x3, x4); Lemmas.lemma_as_nat5 (t0, t1, t2, t3, t4); //assert (if v b4 = 0 then as_nat5 (x0, x1, x2, x3, x4) >= S.q else as_nat5 (x0, x1, x2, x3, x4) < S.q); assert (if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 else v b4 == 1); let (z0, z1, z2, z3, z4) = choose b4 (x0, x1, x2, x3, x4) (t0, t1, t2, t3, t4) in assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else v b4 == 1 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); (z0, z1, z2, z3, z4) inline_for_extraction noextract val carry56: x:uint64 -> Pure (uint64 & uint64) (requires v x <= pow2 57) (ensures fun (t, c) -> v t < pow56 /\ v c <= 2 /\ v x == v c * pow56 + v t) let carry56 x = let carry = x >>. 56ul in FStar.Math.Lemmas.pow2_minus 57 56; let t = x &. mask56 in assert_norm (pow2 56 < pow2 64); mod_mask_lemma x 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); t, carry inline_for_extraction noextract val add_modq5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < S.q /\ as_nat5 y < S.q) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (as_nat5 x + as_nat5 y) % S.q) let add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = assert_norm (pow56 - 1 + pow56 - 1 == pow2 57 - 2); let (t0, c0) = carry56 (x0 +! y0) in let (t1, c1) = carry56 (x1 +! y1 +! c0) in let (t2, c2) = carry56 (x2 +! y2 +! c1) in let (t3, c3) = carry56 (x3 +! y3 +! c2) in let t4 = x4 +! y4 +! c3 in assert (as_nat5 (t0, t1, t2, t3, t4) == as_nat5 (x0, x1, x2, x3, x4) + as_nat5 (y0, y1, y2, y3, y4)); let (o0, o1, o2, o3, o4) = subm_conditional (t0, t1, t2, t3, t4) in Lemmas.lemma_add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) (t0, t1, t2, t3, t4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry56_wide: x:uint128 -> Pure (uint128 & uint64) (requires v x < pow2 117) (ensures fun (c, t) -> v t < pow56 /\ v c < pow2 61 /\ v x - v c * pow56 == v t /\ v c == v x / pow56) let carry56_wide x = let carry = x >>. 56ul in let t = to_u64 x &. mask56 in assert_norm (pow2 56 < pow2 64); Math.Lemmas.lemma_div_lt_nat (v x) 117 56; mod_mask_lemma (to_u64 x) 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == (v x % pow2 64) % pow2 56); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v x) 56 64; assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); carry, t inline_for_extraction noextract val mul64_wide_5: (a:uint64) -> (b:uint64) -> Pure uint128 (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures fun z -> v z == v a * v b /\ v z <= pow2 112 - pow2 57 + 1 /\ v z < pow2 112) let mul64_wide_5 a b = let lemma_smaller (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) < pow2 112) = if v a = 0 || v b = 0 then () else calc (<) { v a * v b <: int; (<) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56) } v a * pow2 56; (<) { Math.Lemmas.lemma_mult_le_right (pow2 56) (v a) (pow2 56) } pow2 56 * pow2 56; (==) { assert_norm (pow2 56 * pow2 56 == pow2 112) } pow2 112; } in let lemma_le (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) <= pow2 112 - pow2 57 + 1) = if v a = 0 || v b = 0 then () else assert_norm (pow2 112 - pow2 57 + 1 >= 0); calc (<=) { v a * v b <: int; (<=) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56 - 1) } v a * (pow2 56 - 1); (<=) { Math.Lemmas.lemma_mult_le_right (pow2 56 - 1) (v a) (pow2 56 - 1) } (pow2 56 - 1) * (pow2 56 - 1); (==) { assert_norm ((pow2 56 - 1) * (pow2 56 - 1) == pow2 112 - pow2 57 + 1) } pow2 112 - pow2 57 + 1; } in lemma_le a b; lemma_smaller a b; mul64_wide a b inline_for_extraction noextract val add2: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112) (ensures fun z -> v z == v a + v b /\ v z <= pow2 116) let add2 a b = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b inline_for_extraction noextract val add3: (a:uint128) -> (b:uint128) -> (c:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 ) (ensures fun z -> v z == v a + v b + v c /\
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.BignumQ.Mul.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.IntTypes.uint128 -> b: Lib.IntTypes.uint128 -> c: Lib.IntTypes.uint128 -> Prims.Pure Lib.IntTypes.uint128
Prims.Pure
[]
[]
[ "Lib.IntTypes.uint128", "Lib.IntTypes.op_Plus_Dot", "Lib.IntTypes.U128", "Lib.IntTypes.SEC", "Prims.unit", "FStar.Math.Lemmas.small_mod", "Prims.op_Addition", "Lib.IntTypes.v", "Prims.pow2", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan" ]
[]
false
false
false
false
false
let add3 a b c =
assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); a +. b +. c
false
Hacl.Spec.BignumQ.Mul.fst
Hacl.Spec.BignumQ.Mul.add_inner_carry
val add_inner_carry: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a <= pow2 116 /\ v b < pow2 61) (ensures fun z -> v z == v a + v b /\ v z < pow2 117)
val add_inner_carry: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a <= pow2 116 /\ v b < pow2 61) (ensures fun z -> v z == v a + v b /\ v z < pow2 117)
let add_inner_carry a b = assert_norm (pow2 116 + pow2 61 < pow2 128); assert_norm (pow2 116 + pow2 61 < pow2 117); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b
{ "file_name": "code/ed25519/Hacl.Spec.BignumQ.Mul.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 8, "end_line": 334, "start_col": 0, "start_line": 330 }
module Hacl.Spec.BignumQ.Mul open FStar.Mul open Lib.IntTypes module S = Spec.Ed25519 module Lemmas = Hacl.Spec.BignumQ.Lemmas include Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask56 : x:uint64{v x == pow2 56 - 1} = assert_norm (pow2 56 - 1 == 0xffffffffffffff); u64 0xffffffffffffff inline_for_extraction noextract let mask40 : x:uint64{v x == pow2 40 - 1} = assert_norm (pow2 40 - 1 == 0xffffffffff); u64 0xffffffffff inline_for_extraction noextract val make_m: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == S.q} let make_m () = let m0 = u64 0x12631a5cf5d3ed in let m1 = u64 0xf9dea2f79cd658 in let m2 = u64 0x000000000014de in let m3 = u64 0x00000000000000 in let m4 = u64 0x00000010000000 in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val make_mu: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == pow2 512 / S.q} let make_mu m = let m0 = u64 0x9ce5a30a2c131b in let m1 = u64 0x215d086329a7ed in let m2 = u64 0xffffffffeb2106 in let m3 = u64 0xffffffffffffff in let m4 = u64 0x00000fffffffff in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == pow2 512 / S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val choose: b:uint64 -> x:qelem5 -> y:qelem5 -> Pure qelem5 (requires v b == 0 \/ v b == 1) (ensures fun z -> if v b = 1 then z == x else z == y) let choose b (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let mask = b -. u64 1 in let z0 = x0 ^. (mask &. (x0 ^. y0)) in Lemmas.lemma_choose_step b x0 y0; let z1 = x1 ^. (mask &. (x1 ^. y1)) in Lemmas.lemma_choose_step b x1 y1; let z2 = x2 ^. (mask &. (x2 ^. y2)) in Lemmas.lemma_choose_step b x2 y2; let z3 = x3 ^. (mask &. (x3 ^. y3)) in Lemmas.lemma_choose_step b x3 y3; let z4 = x4 ^. (mask &. (x4 ^. y4)) in Lemmas.lemma_choose_step b x4 y4; (z0, z1, z2, z3, z4) inline_for_extraction noextract val subm_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow56 /\ v y <= pow56) (ensures fun (b, t) -> v b <= 1 /\ qelem_fits1 t 1 /\ v x - v y == v t - v b * pow56) let subm_step x y = let b = (x -. y) >>. 63ul in //assert (if v x >= v y then v b == 0 else v b == 1); let lshift56 = (b <<. 56ul) in //assert (if v x >= v y then v lshift56 == 0 else v lshift56 == pow56); //assert (v lshift56 == v b * pow56); //assert (v ((b <<. 56ul) +! x) == v b * pow56 + v x); let t = ((b <<. 56ul) +! x) -! y in b, t inline_for_extraction noextract val subm_conditional: x:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ (if as_nat5 x >= S.q then as_nat5 r == as_nat5 x - S.q else as_nat5 r == as_nat5 x)) let subm_conditional (x0, x1, x2, x3, x4) = let (y0, y1, y2, y3, y4) = make_m () in let (b0, t0) = subm_step x0 y0 in assert (v x0 - v y0 == v t0 - v b0 * pow56); let (b1, t1) = subm_step x1 (y1 +! b0) in assert (v x1 - v y1 - v b0 == v t1 - v b1 * pow56); let (b2, t2) = subm_step x2 (y2 +! b1) in assert (v x2 - v y2 - v b1 == v t2 - v b2 * pow56); let (b3, t3) = subm_step x3 (y3 +! b2) in assert (v x3 - v y3 - v b2 == v t3 - v b3 * pow56); let (b4, t4) = subm_step x4 (y4 +! b3) in assert (v x4 - v y4 - v b3 == v t4 - v b4 * pow56); Lemmas.lemma_subm_conditional (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) (v b0) (v b1) (v b2) (v b3) (v b4); assert ( as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow56 * pow224 == as_nat5 (x0, x1, x2, x3, x4) - as_nat5 (y0, y1, y2, y3, y4)); //assert_norm (pow56 * pow224 = pow2 280); //assert (as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow2 280 == as_nat5 (x0, x1, x2, x3, x4) - S.q); Lemmas.lemma_as_nat5 (x0, x1, x2, x3, x4); Lemmas.lemma_as_nat5 (t0, t1, t2, t3, t4); //assert (if v b4 = 0 then as_nat5 (x0, x1, x2, x3, x4) >= S.q else as_nat5 (x0, x1, x2, x3, x4) < S.q); assert (if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 else v b4 == 1); let (z0, z1, z2, z3, z4) = choose b4 (x0, x1, x2, x3, x4) (t0, t1, t2, t3, t4) in assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else v b4 == 1 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); (z0, z1, z2, z3, z4) inline_for_extraction noextract val carry56: x:uint64 -> Pure (uint64 & uint64) (requires v x <= pow2 57) (ensures fun (t, c) -> v t < pow56 /\ v c <= 2 /\ v x == v c * pow56 + v t) let carry56 x = let carry = x >>. 56ul in FStar.Math.Lemmas.pow2_minus 57 56; let t = x &. mask56 in assert_norm (pow2 56 < pow2 64); mod_mask_lemma x 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); t, carry inline_for_extraction noextract val add_modq5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < S.q /\ as_nat5 y < S.q) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (as_nat5 x + as_nat5 y) % S.q) let add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = assert_norm (pow56 - 1 + pow56 - 1 == pow2 57 - 2); let (t0, c0) = carry56 (x0 +! y0) in let (t1, c1) = carry56 (x1 +! y1 +! c0) in let (t2, c2) = carry56 (x2 +! y2 +! c1) in let (t3, c3) = carry56 (x3 +! y3 +! c2) in let t4 = x4 +! y4 +! c3 in assert (as_nat5 (t0, t1, t2, t3, t4) == as_nat5 (x0, x1, x2, x3, x4) + as_nat5 (y0, y1, y2, y3, y4)); let (o0, o1, o2, o3, o4) = subm_conditional (t0, t1, t2, t3, t4) in Lemmas.lemma_add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) (t0, t1, t2, t3, t4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry56_wide: x:uint128 -> Pure (uint128 & uint64) (requires v x < pow2 117) (ensures fun (c, t) -> v t < pow56 /\ v c < pow2 61 /\ v x - v c * pow56 == v t /\ v c == v x / pow56) let carry56_wide x = let carry = x >>. 56ul in let t = to_u64 x &. mask56 in assert_norm (pow2 56 < pow2 64); Math.Lemmas.lemma_div_lt_nat (v x) 117 56; mod_mask_lemma (to_u64 x) 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == (v x % pow2 64) % pow2 56); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v x) 56 64; assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); carry, t inline_for_extraction noextract val mul64_wide_5: (a:uint64) -> (b:uint64) -> Pure uint128 (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures fun z -> v z == v a * v b /\ v z <= pow2 112 - pow2 57 + 1 /\ v z < pow2 112) let mul64_wide_5 a b = let lemma_smaller (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) < pow2 112) = if v a = 0 || v b = 0 then () else calc (<) { v a * v b <: int; (<) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56) } v a * pow2 56; (<) { Math.Lemmas.lemma_mult_le_right (pow2 56) (v a) (pow2 56) } pow2 56 * pow2 56; (==) { assert_norm (pow2 56 * pow2 56 == pow2 112) } pow2 112; } in let lemma_le (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) <= pow2 112 - pow2 57 + 1) = if v a = 0 || v b = 0 then () else assert_norm (pow2 112 - pow2 57 + 1 >= 0); calc (<=) { v a * v b <: int; (<=) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56 - 1) } v a * (pow2 56 - 1); (<=) { Math.Lemmas.lemma_mult_le_right (pow2 56 - 1) (v a) (pow2 56 - 1) } (pow2 56 - 1) * (pow2 56 - 1); (==) { assert_norm ((pow2 56 - 1) * (pow2 56 - 1) == pow2 112 - pow2 57 + 1) } pow2 112 - pow2 57 + 1; } in lemma_le a b; lemma_smaller a b; mul64_wide a b inline_for_extraction noextract val add2: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112) (ensures fun z -> v z == v a + v b /\ v z <= pow2 116) let add2 a b = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b inline_for_extraction noextract val add3: (a:uint128) -> (b:uint128) -> (c:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 ) (ensures fun z -> v z == v a + v b + v c /\ v z <= pow2 116) let add3 a b c = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); a +. b +. c inline_for_extraction noextract val add4: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d /\ v z <= pow2 116) let add4 a b c d = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d) (pow2 128); a +. b +. c +. d inline_for_extraction noextract val add5: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> (e:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112 /\ v e < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d + v e/\ v z <= pow2 116) let add5 a b c d e = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d + v e) (pow2 128); a +. b +. c +. d +. e inline_for_extraction noextract val add_inner_carry: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a <= pow2 116 /\ v b < pow2 61) (ensures fun z -> v z == v a + v b /\
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.BignumQ.Mul.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.IntTypes.uint128 -> b: Lib.IntTypes.uint128 -> Prims.Pure Lib.IntTypes.uint128
Prims.Pure
[]
[]
[ "Lib.IntTypes.uint128", "Lib.IntTypes.op_Plus_Dot", "Lib.IntTypes.U128", "Lib.IntTypes.SEC", "Prims.unit", "FStar.Math.Lemmas.small_mod", "Prims.op_Addition", "Lib.IntTypes.v", "Prims.pow2", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_LessThan" ]
[]
false
false
false
false
false
let add_inner_carry a b =
assert_norm (pow2 116 + pow2 61 < pow2 128); assert_norm (pow2 116 + pow2 61 < pow2 117); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b
false
Hacl.Spec.BignumQ.Mul.fst
Hacl.Spec.BignumQ.Mul.carry56_wide
val carry56_wide: x:uint128 -> Pure (uint128 & uint64) (requires v x < pow2 117) (ensures fun (c, t) -> v t < pow56 /\ v c < pow2 61 /\ v x - v c * pow56 == v t /\ v c == v x / pow56)
val carry56_wide: x:uint128 -> Pure (uint128 & uint64) (requires v x < pow2 117) (ensures fun (c, t) -> v t < pow56 /\ v c < pow2 61 /\ v x - v c * pow56 == v t /\ v c == v x / pow56)
let carry56_wide x = let carry = x >>. 56ul in let t = to_u64 x &. mask56 in assert_norm (pow2 56 < pow2 64); Math.Lemmas.lemma_div_lt_nat (v x) 117 56; mod_mask_lemma (to_u64 x) 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == (v x % pow2 64) % pow2 56); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v x) 56 64; assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); carry, t
{ "file_name": "code/ed25519/Hacl.Spec.BignumQ.Mul.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 10, "end_line": 209, "start_col": 0, "start_line": 198 }
module Hacl.Spec.BignumQ.Mul open FStar.Mul open Lib.IntTypes module S = Spec.Ed25519 module Lemmas = Hacl.Spec.BignumQ.Lemmas include Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask56 : x:uint64{v x == pow2 56 - 1} = assert_norm (pow2 56 - 1 == 0xffffffffffffff); u64 0xffffffffffffff inline_for_extraction noextract let mask40 : x:uint64{v x == pow2 40 - 1} = assert_norm (pow2 40 - 1 == 0xffffffffff); u64 0xffffffffff inline_for_extraction noextract val make_m: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == S.q} let make_m () = let m0 = u64 0x12631a5cf5d3ed in let m1 = u64 0xf9dea2f79cd658 in let m2 = u64 0x000000000014de in let m3 = u64 0x00000000000000 in let m4 = u64 0x00000010000000 in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val make_mu: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == pow2 512 / S.q} let make_mu m = let m0 = u64 0x9ce5a30a2c131b in let m1 = u64 0x215d086329a7ed in let m2 = u64 0xffffffffeb2106 in let m3 = u64 0xffffffffffffff in let m4 = u64 0x00000fffffffff in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == pow2 512 / S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val choose: b:uint64 -> x:qelem5 -> y:qelem5 -> Pure qelem5 (requires v b == 0 \/ v b == 1) (ensures fun z -> if v b = 1 then z == x else z == y) let choose b (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let mask = b -. u64 1 in let z0 = x0 ^. (mask &. (x0 ^. y0)) in Lemmas.lemma_choose_step b x0 y0; let z1 = x1 ^. (mask &. (x1 ^. y1)) in Lemmas.lemma_choose_step b x1 y1; let z2 = x2 ^. (mask &. (x2 ^. y2)) in Lemmas.lemma_choose_step b x2 y2; let z3 = x3 ^. (mask &. (x3 ^. y3)) in Lemmas.lemma_choose_step b x3 y3; let z4 = x4 ^. (mask &. (x4 ^. y4)) in Lemmas.lemma_choose_step b x4 y4; (z0, z1, z2, z3, z4) inline_for_extraction noextract val subm_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow56 /\ v y <= pow56) (ensures fun (b, t) -> v b <= 1 /\ qelem_fits1 t 1 /\ v x - v y == v t - v b * pow56) let subm_step x y = let b = (x -. y) >>. 63ul in //assert (if v x >= v y then v b == 0 else v b == 1); let lshift56 = (b <<. 56ul) in //assert (if v x >= v y then v lshift56 == 0 else v lshift56 == pow56); //assert (v lshift56 == v b * pow56); //assert (v ((b <<. 56ul) +! x) == v b * pow56 + v x); let t = ((b <<. 56ul) +! x) -! y in b, t inline_for_extraction noextract val subm_conditional: x:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ (if as_nat5 x >= S.q then as_nat5 r == as_nat5 x - S.q else as_nat5 r == as_nat5 x)) let subm_conditional (x0, x1, x2, x3, x4) = let (y0, y1, y2, y3, y4) = make_m () in let (b0, t0) = subm_step x0 y0 in assert (v x0 - v y0 == v t0 - v b0 * pow56); let (b1, t1) = subm_step x1 (y1 +! b0) in assert (v x1 - v y1 - v b0 == v t1 - v b1 * pow56); let (b2, t2) = subm_step x2 (y2 +! b1) in assert (v x2 - v y2 - v b1 == v t2 - v b2 * pow56); let (b3, t3) = subm_step x3 (y3 +! b2) in assert (v x3 - v y3 - v b2 == v t3 - v b3 * pow56); let (b4, t4) = subm_step x4 (y4 +! b3) in assert (v x4 - v y4 - v b3 == v t4 - v b4 * pow56); Lemmas.lemma_subm_conditional (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) (v b0) (v b1) (v b2) (v b3) (v b4); assert ( as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow56 * pow224 == as_nat5 (x0, x1, x2, x3, x4) - as_nat5 (y0, y1, y2, y3, y4)); //assert_norm (pow56 * pow224 = pow2 280); //assert (as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow2 280 == as_nat5 (x0, x1, x2, x3, x4) - S.q); Lemmas.lemma_as_nat5 (x0, x1, x2, x3, x4); Lemmas.lemma_as_nat5 (t0, t1, t2, t3, t4); //assert (if v b4 = 0 then as_nat5 (x0, x1, x2, x3, x4) >= S.q else as_nat5 (x0, x1, x2, x3, x4) < S.q); assert (if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 else v b4 == 1); let (z0, z1, z2, z3, z4) = choose b4 (x0, x1, x2, x3, x4) (t0, t1, t2, t3, t4) in assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else v b4 == 1 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); (z0, z1, z2, z3, z4) inline_for_extraction noextract val carry56: x:uint64 -> Pure (uint64 & uint64) (requires v x <= pow2 57) (ensures fun (t, c) -> v t < pow56 /\ v c <= 2 /\ v x == v c * pow56 + v t) let carry56 x = let carry = x >>. 56ul in FStar.Math.Lemmas.pow2_minus 57 56; let t = x &. mask56 in assert_norm (pow2 56 < pow2 64); mod_mask_lemma x 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); t, carry inline_for_extraction noextract val add_modq5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < S.q /\ as_nat5 y < S.q) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (as_nat5 x + as_nat5 y) % S.q) let add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = assert_norm (pow56 - 1 + pow56 - 1 == pow2 57 - 2); let (t0, c0) = carry56 (x0 +! y0) in let (t1, c1) = carry56 (x1 +! y1 +! c0) in let (t2, c2) = carry56 (x2 +! y2 +! c1) in let (t3, c3) = carry56 (x3 +! y3 +! c2) in let t4 = x4 +! y4 +! c3 in assert (as_nat5 (t0, t1, t2, t3, t4) == as_nat5 (x0, x1, x2, x3, x4) + as_nat5 (y0, y1, y2, y3, y4)); let (o0, o1, o2, o3, o4) = subm_conditional (t0, t1, t2, t3, t4) in Lemmas.lemma_add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) (t0, t1, t2, t3, t4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry56_wide: x:uint128 -> Pure (uint128 & uint64) (requires v x < pow2 117) (ensures fun (c, t) -> v t < pow56 /\ v c < pow2 61 /\ v x - v c * pow56 == v t /\ v c == v x / pow56)
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.BignumQ.Mul.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Lib.IntTypes.uint128 -> Prims.Pure (Lib.IntTypes.uint128 * Lib.IntTypes.uint64)
Prims.Pure
[]
[]
[ "Lib.IntTypes.uint128", "FStar.Pervasives.Native.Mktuple2", "Lib.IntTypes.uint64", "Prims.unit", "Prims._assert", "Prims.eq2", "Prims.int", "Lib.IntTypes.v", "Lib.IntTypes.U128", "Lib.IntTypes.SEC", "Prims.op_Addition", "FStar.Mul.op_Star", "Prims.pow2", "Lib.IntTypes.U64", "Prims.op_Modulus", "FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1", "Lib.IntTypes.range_t", "Lib.IntTypes.mod_mask", "FStar.UInt32.__uint_to_t", "Hacl.Spec.BignumQ.Mul.mask56", "Lib.IntTypes.mod_mask_lemma", "Lib.IntTypes.to_u64", "FStar.Math.Lemmas.lemma_div_lt_nat", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Amp_Dot", "Lib.IntTypes.op_Greater_Greater_Dot", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
false
false
let carry56_wide x =
let carry = x >>. 56ul in let t = to_u64 x &. mask56 in assert_norm (pow2 56 < pow2 64); Math.Lemmas.lemma_div_lt_nat (v x) 117 56; mod_mask_lemma (to_u64 x) 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == (v x % pow2 64) % pow2 56); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v x) 56 64; assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); carry, t
false
Hacl.Spec.BignumQ.Mul.fst
Hacl.Spec.BignumQ.Mul.make_mu
val make_mu: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == pow2 512 / S.q}
val make_mu: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == pow2 512 / S.q}
let make_mu m = let m0 = u64 0x9ce5a30a2c131b in let m1 = u64 0x215d086329a7ed in let m2 = u64 0xffffffffeb2106 in let m3 = u64 0xffffffffffffff in let m4 = u64 0x00000fffffffff in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == pow2 512 / S.q); (m0, m1, m2, m3, m4)
{ "file_name": "code/ed25519/Hacl.Spec.BignumQ.Mul.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 22, "end_line": 47, "start_col": 0, "start_line": 40 }
module Hacl.Spec.BignumQ.Mul open FStar.Mul open Lib.IntTypes module S = Spec.Ed25519 module Lemmas = Hacl.Spec.BignumQ.Lemmas include Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask56 : x:uint64{v x == pow2 56 - 1} = assert_norm (pow2 56 - 1 == 0xffffffffffffff); u64 0xffffffffffffff inline_for_extraction noextract let mask40 : x:uint64{v x == pow2 40 - 1} = assert_norm (pow2 40 - 1 == 0xffffffffff); u64 0xffffffffff inline_for_extraction noextract val make_m: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == S.q} let make_m () = let m0 = u64 0x12631a5cf5d3ed in let m1 = u64 0xf9dea2f79cd658 in let m2 = u64 0x000000000014de in let m3 = u64 0x00000000000000 in let m4 = u64 0x00000010000000 in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.BignumQ.Mul.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: Prims.unit -> m: Hacl.Spec.BignumQ.Definitions.qelem5 { Hacl.Spec.BignumQ.Definitions.qelem_fits5 m (1, 1, 1, 1, 1) /\ Hacl.Spec.BignumQ.Definitions.as_nat5 m == Prims.pow2 512 / Spec.Ed25519.q }
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "FStar.Pervasives.Native.Mktuple5", "Lib.IntTypes.uint64", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "Hacl.Spec.BignumQ.Definitions.as_nat5", "Prims.op_Division", "Prims.pow2", "Spec.Ed25519.q", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.range", "Lib.IntTypes.v", "Lib.IntTypes.u64", "Hacl.Spec.BignumQ.Definitions.qelem5", "Prims.l_and", "Hacl.Spec.BignumQ.Definitions.qelem_fits5", "Prims.nat" ]
[]
false
false
false
false
false
let make_mu m =
let m0 = u64 0x9ce5a30a2c131b in let m1 = u64 0x215d086329a7ed in let m2 = u64 0xffffffffeb2106 in let m3 = u64 0xffffffffffffff in let m4 = u64 0x00000fffffffff in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == pow2 512 / S.q); (m0, m1, m2, m3, m4)
false
Hacl.Spec.BignumQ.Mul.fst
Hacl.Spec.BignumQ.Mul.mul64_wide_5
val mul64_wide_5: (a:uint64) -> (b:uint64) -> Pure uint128 (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures fun z -> v z == v a * v b /\ v z <= pow2 112 - pow2 57 + 1 /\ v z < pow2 112)
val mul64_wide_5: (a:uint64) -> (b:uint64) -> Pure uint128 (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures fun z -> v z == v a * v b /\ v z <= pow2 112 - pow2 57 + 1 /\ v z < pow2 112)
let mul64_wide_5 a b = let lemma_smaller (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) < pow2 112) = if v a = 0 || v b = 0 then () else calc (<) { v a * v b <: int; (<) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56) } v a * pow2 56; (<) { Math.Lemmas.lemma_mult_le_right (pow2 56) (v a) (pow2 56) } pow2 56 * pow2 56; (==) { assert_norm (pow2 56 * pow2 56 == pow2 112) } pow2 112; } in let lemma_le (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) <= pow2 112 - pow2 57 + 1) = if v a = 0 || v b = 0 then () else assert_norm (pow2 112 - pow2 57 + 1 >= 0); calc (<=) { v a * v b <: int; (<=) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56 - 1) } v a * (pow2 56 - 1); (<=) { Math.Lemmas.lemma_mult_le_right (pow2 56 - 1) (v a) (pow2 56 - 1) } (pow2 56 - 1) * (pow2 56 - 1); (==) { assert_norm ((pow2 56 - 1) * (pow2 56 - 1) == pow2 112 - pow2 57 + 1) } pow2 112 - pow2 57 + 1; } in lemma_le a b; lemma_smaller a b; mul64_wide a b
{ "file_name": "code/ed25519/Hacl.Spec.BignumQ.Mul.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 16, "end_line": 252, "start_col": 0, "start_line": 220 }
module Hacl.Spec.BignumQ.Mul open FStar.Mul open Lib.IntTypes module S = Spec.Ed25519 module Lemmas = Hacl.Spec.BignumQ.Lemmas include Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask56 : x:uint64{v x == pow2 56 - 1} = assert_norm (pow2 56 - 1 == 0xffffffffffffff); u64 0xffffffffffffff inline_for_extraction noextract let mask40 : x:uint64{v x == pow2 40 - 1} = assert_norm (pow2 40 - 1 == 0xffffffffff); u64 0xffffffffff inline_for_extraction noextract val make_m: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == S.q} let make_m () = let m0 = u64 0x12631a5cf5d3ed in let m1 = u64 0xf9dea2f79cd658 in let m2 = u64 0x000000000014de in let m3 = u64 0x00000000000000 in let m4 = u64 0x00000010000000 in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val make_mu: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == pow2 512 / S.q} let make_mu m = let m0 = u64 0x9ce5a30a2c131b in let m1 = u64 0x215d086329a7ed in let m2 = u64 0xffffffffeb2106 in let m3 = u64 0xffffffffffffff in let m4 = u64 0x00000fffffffff in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == pow2 512 / S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val choose: b:uint64 -> x:qelem5 -> y:qelem5 -> Pure qelem5 (requires v b == 0 \/ v b == 1) (ensures fun z -> if v b = 1 then z == x else z == y) let choose b (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let mask = b -. u64 1 in let z0 = x0 ^. (mask &. (x0 ^. y0)) in Lemmas.lemma_choose_step b x0 y0; let z1 = x1 ^. (mask &. (x1 ^. y1)) in Lemmas.lemma_choose_step b x1 y1; let z2 = x2 ^. (mask &. (x2 ^. y2)) in Lemmas.lemma_choose_step b x2 y2; let z3 = x3 ^. (mask &. (x3 ^. y3)) in Lemmas.lemma_choose_step b x3 y3; let z4 = x4 ^. (mask &. (x4 ^. y4)) in Lemmas.lemma_choose_step b x4 y4; (z0, z1, z2, z3, z4) inline_for_extraction noextract val subm_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow56 /\ v y <= pow56) (ensures fun (b, t) -> v b <= 1 /\ qelem_fits1 t 1 /\ v x - v y == v t - v b * pow56) let subm_step x y = let b = (x -. y) >>. 63ul in //assert (if v x >= v y then v b == 0 else v b == 1); let lshift56 = (b <<. 56ul) in //assert (if v x >= v y then v lshift56 == 0 else v lshift56 == pow56); //assert (v lshift56 == v b * pow56); //assert (v ((b <<. 56ul) +! x) == v b * pow56 + v x); let t = ((b <<. 56ul) +! x) -! y in b, t inline_for_extraction noextract val subm_conditional: x:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ (if as_nat5 x >= S.q then as_nat5 r == as_nat5 x - S.q else as_nat5 r == as_nat5 x)) let subm_conditional (x0, x1, x2, x3, x4) = let (y0, y1, y2, y3, y4) = make_m () in let (b0, t0) = subm_step x0 y0 in assert (v x0 - v y0 == v t0 - v b0 * pow56); let (b1, t1) = subm_step x1 (y1 +! b0) in assert (v x1 - v y1 - v b0 == v t1 - v b1 * pow56); let (b2, t2) = subm_step x2 (y2 +! b1) in assert (v x2 - v y2 - v b1 == v t2 - v b2 * pow56); let (b3, t3) = subm_step x3 (y3 +! b2) in assert (v x3 - v y3 - v b2 == v t3 - v b3 * pow56); let (b4, t4) = subm_step x4 (y4 +! b3) in assert (v x4 - v y4 - v b3 == v t4 - v b4 * pow56); Lemmas.lemma_subm_conditional (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) (v b0) (v b1) (v b2) (v b3) (v b4); assert ( as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow56 * pow224 == as_nat5 (x0, x1, x2, x3, x4) - as_nat5 (y0, y1, y2, y3, y4)); //assert_norm (pow56 * pow224 = pow2 280); //assert (as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow2 280 == as_nat5 (x0, x1, x2, x3, x4) - S.q); Lemmas.lemma_as_nat5 (x0, x1, x2, x3, x4); Lemmas.lemma_as_nat5 (t0, t1, t2, t3, t4); //assert (if v b4 = 0 then as_nat5 (x0, x1, x2, x3, x4) >= S.q else as_nat5 (x0, x1, x2, x3, x4) < S.q); assert (if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 else v b4 == 1); let (z0, z1, z2, z3, z4) = choose b4 (x0, x1, x2, x3, x4) (t0, t1, t2, t3, t4) in assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else v b4 == 1 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); (z0, z1, z2, z3, z4) inline_for_extraction noextract val carry56: x:uint64 -> Pure (uint64 & uint64) (requires v x <= pow2 57) (ensures fun (t, c) -> v t < pow56 /\ v c <= 2 /\ v x == v c * pow56 + v t) let carry56 x = let carry = x >>. 56ul in FStar.Math.Lemmas.pow2_minus 57 56; let t = x &. mask56 in assert_norm (pow2 56 < pow2 64); mod_mask_lemma x 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); t, carry inline_for_extraction noextract val add_modq5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < S.q /\ as_nat5 y < S.q) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (as_nat5 x + as_nat5 y) % S.q) let add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = assert_norm (pow56 - 1 + pow56 - 1 == pow2 57 - 2); let (t0, c0) = carry56 (x0 +! y0) in let (t1, c1) = carry56 (x1 +! y1 +! c0) in let (t2, c2) = carry56 (x2 +! y2 +! c1) in let (t3, c3) = carry56 (x3 +! y3 +! c2) in let t4 = x4 +! y4 +! c3 in assert (as_nat5 (t0, t1, t2, t3, t4) == as_nat5 (x0, x1, x2, x3, x4) + as_nat5 (y0, y1, y2, y3, y4)); let (o0, o1, o2, o3, o4) = subm_conditional (t0, t1, t2, t3, t4) in Lemmas.lemma_add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) (t0, t1, t2, t3, t4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry56_wide: x:uint128 -> Pure (uint128 & uint64) (requires v x < pow2 117) (ensures fun (c, t) -> v t < pow56 /\ v c < pow2 61 /\ v x - v c * pow56 == v t /\ v c == v x / pow56) let carry56_wide x = let carry = x >>. 56ul in let t = to_u64 x &. mask56 in assert_norm (pow2 56 < pow2 64); Math.Lemmas.lemma_div_lt_nat (v x) 117 56; mod_mask_lemma (to_u64 x) 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == (v x % pow2 64) % pow2 56); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v x) 56 64; assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); carry, t inline_for_extraction noextract val mul64_wide_5: (a:uint64) -> (b:uint64) -> Pure uint128 (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures fun z -> v z == v a * v b /\ v z <= pow2 112 - pow2 57 + 1 /\
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.BignumQ.Mul.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.IntTypes.uint64 -> b: Lib.IntTypes.uint64 -> Prims.Pure Lib.IntTypes.uint128
Prims.Pure
[]
[]
[ "Lib.IntTypes.uint64", "Lib.IntTypes.mul64_wide", "Prims.unit", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Prims.l_and", "Prims.b2t", "Hacl.Spec.BignumQ.Definitions.qelem_fits1", "Prims.squash", "Prims.op_LessThanOrEqual", "Lib.IntTypes.v", "Lib.IntTypes.U128", "Prims.op_Addition", "Prims.op_Subtraction", "Prims.pow2", "Prims.Nil", "FStar.Pervasives.pattern", "FStar.Calc.calc_finish", "Prims.int", "FStar.Mul.op_Star", "Prims.Cons", "FStar.Preorder.relation", "Prims.eq2", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.lemma_mult_le_left", "FStar.Math.Lemmas.lemma_mult_le_right", "FStar.Pervasives.assert_norm", "Prims.op_BarBar", "Prims.op_Equality", "Prims.bool", "Prims.op_GreaterThanOrEqual", "Prims.op_LessThan", "Lib.IntTypes.uint128" ]
[]
false
false
false
false
false
let mul64_wide_5 a b =
let lemma_smaller (a b: uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) < pow2 112) = if v a = 0 || v b = 0 then () else calc ( < ) { v a * v b <: int; ( < ) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56) } v a * pow2 56; ( < ) { Math.Lemmas.lemma_mult_le_right (pow2 56) (v a) (pow2 56) } pow2 56 * pow2 56; ( == ) { assert_norm (pow2 56 * pow2 56 == pow2 112) } pow2 112; } in let lemma_le (a b: uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) <= pow2 112 - pow2 57 + 1) = if v a = 0 || v b = 0 then () else assert_norm (pow2 112 - pow2 57 + 1 >= 0); calc ( <= ) { v a * v b <: int; ( <= ) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56 - 1) } v a * (pow2 56 - 1); ( <= ) { Math.Lemmas.lemma_mult_le_right (pow2 56 - 1) (v a) (pow2 56 - 1) } (pow2 56 - 1) * (pow2 56 - 1); ( == ) { assert_norm ((pow2 56 - 1) * (pow2 56 - 1) == pow2 112 - pow2 57 + 1) } pow2 112 - pow2 57 + 1; } in lemma_le a b; lemma_smaller a b; mul64_wide a b
false
Hacl.Spec.BignumQ.Mul.fst
Hacl.Spec.BignumQ.Mul.add4
val add4: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d /\ v z <= pow2 116)
val add4: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d /\ v z <= pow2 116)
let add4 a b c d = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d) (pow2 128); a +. b +. c +. d
{ "file_name": "code/ed25519/Hacl.Spec.BignumQ.Mul.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 18, "end_line": 300, "start_col": 0, "start_line": 292 }
module Hacl.Spec.BignumQ.Mul open FStar.Mul open Lib.IntTypes module S = Spec.Ed25519 module Lemmas = Hacl.Spec.BignumQ.Lemmas include Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask56 : x:uint64{v x == pow2 56 - 1} = assert_norm (pow2 56 - 1 == 0xffffffffffffff); u64 0xffffffffffffff inline_for_extraction noextract let mask40 : x:uint64{v x == pow2 40 - 1} = assert_norm (pow2 40 - 1 == 0xffffffffff); u64 0xffffffffff inline_for_extraction noextract val make_m: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == S.q} let make_m () = let m0 = u64 0x12631a5cf5d3ed in let m1 = u64 0xf9dea2f79cd658 in let m2 = u64 0x000000000014de in let m3 = u64 0x00000000000000 in let m4 = u64 0x00000010000000 in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val make_mu: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == pow2 512 / S.q} let make_mu m = let m0 = u64 0x9ce5a30a2c131b in let m1 = u64 0x215d086329a7ed in let m2 = u64 0xffffffffeb2106 in let m3 = u64 0xffffffffffffff in let m4 = u64 0x00000fffffffff in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == pow2 512 / S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val choose: b:uint64 -> x:qelem5 -> y:qelem5 -> Pure qelem5 (requires v b == 0 \/ v b == 1) (ensures fun z -> if v b = 1 then z == x else z == y) let choose b (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let mask = b -. u64 1 in let z0 = x0 ^. (mask &. (x0 ^. y0)) in Lemmas.lemma_choose_step b x0 y0; let z1 = x1 ^. (mask &. (x1 ^. y1)) in Lemmas.lemma_choose_step b x1 y1; let z2 = x2 ^. (mask &. (x2 ^. y2)) in Lemmas.lemma_choose_step b x2 y2; let z3 = x3 ^. (mask &. (x3 ^. y3)) in Lemmas.lemma_choose_step b x3 y3; let z4 = x4 ^. (mask &. (x4 ^. y4)) in Lemmas.lemma_choose_step b x4 y4; (z0, z1, z2, z3, z4) inline_for_extraction noextract val subm_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow56 /\ v y <= pow56) (ensures fun (b, t) -> v b <= 1 /\ qelem_fits1 t 1 /\ v x - v y == v t - v b * pow56) let subm_step x y = let b = (x -. y) >>. 63ul in //assert (if v x >= v y then v b == 0 else v b == 1); let lshift56 = (b <<. 56ul) in //assert (if v x >= v y then v lshift56 == 0 else v lshift56 == pow56); //assert (v lshift56 == v b * pow56); //assert (v ((b <<. 56ul) +! x) == v b * pow56 + v x); let t = ((b <<. 56ul) +! x) -! y in b, t inline_for_extraction noextract val subm_conditional: x:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ (if as_nat5 x >= S.q then as_nat5 r == as_nat5 x - S.q else as_nat5 r == as_nat5 x)) let subm_conditional (x0, x1, x2, x3, x4) = let (y0, y1, y2, y3, y4) = make_m () in let (b0, t0) = subm_step x0 y0 in assert (v x0 - v y0 == v t0 - v b0 * pow56); let (b1, t1) = subm_step x1 (y1 +! b0) in assert (v x1 - v y1 - v b0 == v t1 - v b1 * pow56); let (b2, t2) = subm_step x2 (y2 +! b1) in assert (v x2 - v y2 - v b1 == v t2 - v b2 * pow56); let (b3, t3) = subm_step x3 (y3 +! b2) in assert (v x3 - v y3 - v b2 == v t3 - v b3 * pow56); let (b4, t4) = subm_step x4 (y4 +! b3) in assert (v x4 - v y4 - v b3 == v t4 - v b4 * pow56); Lemmas.lemma_subm_conditional (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) (v b0) (v b1) (v b2) (v b3) (v b4); assert ( as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow56 * pow224 == as_nat5 (x0, x1, x2, x3, x4) - as_nat5 (y0, y1, y2, y3, y4)); //assert_norm (pow56 * pow224 = pow2 280); //assert (as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow2 280 == as_nat5 (x0, x1, x2, x3, x4) - S.q); Lemmas.lemma_as_nat5 (x0, x1, x2, x3, x4); Lemmas.lemma_as_nat5 (t0, t1, t2, t3, t4); //assert (if v b4 = 0 then as_nat5 (x0, x1, x2, x3, x4) >= S.q else as_nat5 (x0, x1, x2, x3, x4) < S.q); assert (if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 else v b4 == 1); let (z0, z1, z2, z3, z4) = choose b4 (x0, x1, x2, x3, x4) (t0, t1, t2, t3, t4) in assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else v b4 == 1 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); (z0, z1, z2, z3, z4) inline_for_extraction noextract val carry56: x:uint64 -> Pure (uint64 & uint64) (requires v x <= pow2 57) (ensures fun (t, c) -> v t < pow56 /\ v c <= 2 /\ v x == v c * pow56 + v t) let carry56 x = let carry = x >>. 56ul in FStar.Math.Lemmas.pow2_minus 57 56; let t = x &. mask56 in assert_norm (pow2 56 < pow2 64); mod_mask_lemma x 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); t, carry inline_for_extraction noextract val add_modq5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < S.q /\ as_nat5 y < S.q) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (as_nat5 x + as_nat5 y) % S.q) let add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = assert_norm (pow56 - 1 + pow56 - 1 == pow2 57 - 2); let (t0, c0) = carry56 (x0 +! y0) in let (t1, c1) = carry56 (x1 +! y1 +! c0) in let (t2, c2) = carry56 (x2 +! y2 +! c1) in let (t3, c3) = carry56 (x3 +! y3 +! c2) in let t4 = x4 +! y4 +! c3 in assert (as_nat5 (t0, t1, t2, t3, t4) == as_nat5 (x0, x1, x2, x3, x4) + as_nat5 (y0, y1, y2, y3, y4)); let (o0, o1, o2, o3, o4) = subm_conditional (t0, t1, t2, t3, t4) in Lemmas.lemma_add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) (t0, t1, t2, t3, t4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry56_wide: x:uint128 -> Pure (uint128 & uint64) (requires v x < pow2 117) (ensures fun (c, t) -> v t < pow56 /\ v c < pow2 61 /\ v x - v c * pow56 == v t /\ v c == v x / pow56) let carry56_wide x = let carry = x >>. 56ul in let t = to_u64 x &. mask56 in assert_norm (pow2 56 < pow2 64); Math.Lemmas.lemma_div_lt_nat (v x) 117 56; mod_mask_lemma (to_u64 x) 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == (v x % pow2 64) % pow2 56); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v x) 56 64; assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); carry, t inline_for_extraction noextract val mul64_wide_5: (a:uint64) -> (b:uint64) -> Pure uint128 (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures fun z -> v z == v a * v b /\ v z <= pow2 112 - pow2 57 + 1 /\ v z < pow2 112) let mul64_wide_5 a b = let lemma_smaller (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) < pow2 112) = if v a = 0 || v b = 0 then () else calc (<) { v a * v b <: int; (<) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56) } v a * pow2 56; (<) { Math.Lemmas.lemma_mult_le_right (pow2 56) (v a) (pow2 56) } pow2 56 * pow2 56; (==) { assert_norm (pow2 56 * pow2 56 == pow2 112) } pow2 112; } in let lemma_le (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) <= pow2 112 - pow2 57 + 1) = if v a = 0 || v b = 0 then () else assert_norm (pow2 112 - pow2 57 + 1 >= 0); calc (<=) { v a * v b <: int; (<=) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56 - 1) } v a * (pow2 56 - 1); (<=) { Math.Lemmas.lemma_mult_le_right (pow2 56 - 1) (v a) (pow2 56 - 1) } (pow2 56 - 1) * (pow2 56 - 1); (==) { assert_norm ((pow2 56 - 1) * (pow2 56 - 1) == pow2 112 - pow2 57 + 1) } pow2 112 - pow2 57 + 1; } in lemma_le a b; lemma_smaller a b; mul64_wide a b inline_for_extraction noextract val add2: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112) (ensures fun z -> v z == v a + v b /\ v z <= pow2 116) let add2 a b = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b inline_for_extraction noextract val add3: (a:uint128) -> (b:uint128) -> (c:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 ) (ensures fun z -> v z == v a + v b + v c /\ v z <= pow2 116) let add3 a b c = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); a +. b +. c inline_for_extraction noextract val add4: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d /\
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.BignumQ.Mul.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.IntTypes.uint128 -> b: Lib.IntTypes.uint128 -> c: Lib.IntTypes.uint128 -> d: Lib.IntTypes.uint128 -> Prims.Pure Lib.IntTypes.uint128
Prims.Pure
[]
[]
[ "Lib.IntTypes.uint128", "Lib.IntTypes.op_Plus_Dot", "Lib.IntTypes.U128", "Lib.IntTypes.SEC", "Prims.unit", "FStar.Math.Lemmas.small_mod", "Prims.op_Addition", "Lib.IntTypes.v", "Prims.pow2", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan" ]
[]
false
false
false
false
false
let add4 a b c d =
assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d) (pow2 128); a +. b +. c +. d
false
Hacl.Spec.BignumQ.Mul.fst
Hacl.Spec.BignumQ.Mul.add_modq5
val add_modq5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < S.q /\ as_nat5 y < S.q) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (as_nat5 x + as_nat5 y) % S.q)
val add_modq5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < S.q /\ as_nat5 y < S.q) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (as_nat5 x + as_nat5 y) % S.q)
let add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = assert_norm (pow56 - 1 + pow56 - 1 == pow2 57 - 2); let (t0, c0) = carry56 (x0 +! y0) in let (t1, c1) = carry56 (x1 +! y1 +! c0) in let (t2, c2) = carry56 (x2 +! y2 +! c1) in let (t3, c3) = carry56 (x3 +! y3 +! c2) in let t4 = x4 +! y4 +! c3 in assert (as_nat5 (t0, t1, t2, t3, t4) == as_nat5 (x0, x1, x2, x3, x4) + as_nat5 (y0, y1, y2, y3, y4)); let (o0, o1, o2, o3, o4) = subm_conditional (t0, t1, t2, t3, t4) in Lemmas.lemma_add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) (t0, t1, t2, t3, t4); (o0, o1, o2, o3, o4)
{ "file_name": "code/ed25519/Hacl.Spec.BignumQ.Mul.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 22, "end_line": 187, "start_col": 0, "start_line": 177 }
module Hacl.Spec.BignumQ.Mul open FStar.Mul open Lib.IntTypes module S = Spec.Ed25519 module Lemmas = Hacl.Spec.BignumQ.Lemmas include Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask56 : x:uint64{v x == pow2 56 - 1} = assert_norm (pow2 56 - 1 == 0xffffffffffffff); u64 0xffffffffffffff inline_for_extraction noextract let mask40 : x:uint64{v x == pow2 40 - 1} = assert_norm (pow2 40 - 1 == 0xffffffffff); u64 0xffffffffff inline_for_extraction noextract val make_m: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == S.q} let make_m () = let m0 = u64 0x12631a5cf5d3ed in let m1 = u64 0xf9dea2f79cd658 in let m2 = u64 0x000000000014de in let m3 = u64 0x00000000000000 in let m4 = u64 0x00000010000000 in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val make_mu: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == pow2 512 / S.q} let make_mu m = let m0 = u64 0x9ce5a30a2c131b in let m1 = u64 0x215d086329a7ed in let m2 = u64 0xffffffffeb2106 in let m3 = u64 0xffffffffffffff in let m4 = u64 0x00000fffffffff in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == pow2 512 / S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val choose: b:uint64 -> x:qelem5 -> y:qelem5 -> Pure qelem5 (requires v b == 0 \/ v b == 1) (ensures fun z -> if v b = 1 then z == x else z == y) let choose b (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let mask = b -. u64 1 in let z0 = x0 ^. (mask &. (x0 ^. y0)) in Lemmas.lemma_choose_step b x0 y0; let z1 = x1 ^. (mask &. (x1 ^. y1)) in Lemmas.lemma_choose_step b x1 y1; let z2 = x2 ^. (mask &. (x2 ^. y2)) in Lemmas.lemma_choose_step b x2 y2; let z3 = x3 ^. (mask &. (x3 ^. y3)) in Lemmas.lemma_choose_step b x3 y3; let z4 = x4 ^. (mask &. (x4 ^. y4)) in Lemmas.lemma_choose_step b x4 y4; (z0, z1, z2, z3, z4) inline_for_extraction noextract val subm_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow56 /\ v y <= pow56) (ensures fun (b, t) -> v b <= 1 /\ qelem_fits1 t 1 /\ v x - v y == v t - v b * pow56) let subm_step x y = let b = (x -. y) >>. 63ul in //assert (if v x >= v y then v b == 0 else v b == 1); let lshift56 = (b <<. 56ul) in //assert (if v x >= v y then v lshift56 == 0 else v lshift56 == pow56); //assert (v lshift56 == v b * pow56); //assert (v ((b <<. 56ul) +! x) == v b * pow56 + v x); let t = ((b <<. 56ul) +! x) -! y in b, t inline_for_extraction noextract val subm_conditional: x:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ (if as_nat5 x >= S.q then as_nat5 r == as_nat5 x - S.q else as_nat5 r == as_nat5 x)) let subm_conditional (x0, x1, x2, x3, x4) = let (y0, y1, y2, y3, y4) = make_m () in let (b0, t0) = subm_step x0 y0 in assert (v x0 - v y0 == v t0 - v b0 * pow56); let (b1, t1) = subm_step x1 (y1 +! b0) in assert (v x1 - v y1 - v b0 == v t1 - v b1 * pow56); let (b2, t2) = subm_step x2 (y2 +! b1) in assert (v x2 - v y2 - v b1 == v t2 - v b2 * pow56); let (b3, t3) = subm_step x3 (y3 +! b2) in assert (v x3 - v y3 - v b2 == v t3 - v b3 * pow56); let (b4, t4) = subm_step x4 (y4 +! b3) in assert (v x4 - v y4 - v b3 == v t4 - v b4 * pow56); Lemmas.lemma_subm_conditional (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) (v b0) (v b1) (v b2) (v b3) (v b4); assert ( as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow56 * pow224 == as_nat5 (x0, x1, x2, x3, x4) - as_nat5 (y0, y1, y2, y3, y4)); //assert_norm (pow56 * pow224 = pow2 280); //assert (as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow2 280 == as_nat5 (x0, x1, x2, x3, x4) - S.q); Lemmas.lemma_as_nat5 (x0, x1, x2, x3, x4); Lemmas.lemma_as_nat5 (t0, t1, t2, t3, t4); //assert (if v b4 = 0 then as_nat5 (x0, x1, x2, x3, x4) >= S.q else as_nat5 (x0, x1, x2, x3, x4) < S.q); assert (if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 else v b4 == 1); let (z0, z1, z2, z3, z4) = choose b4 (x0, x1, x2, x3, x4) (t0, t1, t2, t3, t4) in assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else v b4 == 1 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); (z0, z1, z2, z3, z4) inline_for_extraction noextract val carry56: x:uint64 -> Pure (uint64 & uint64) (requires v x <= pow2 57) (ensures fun (t, c) -> v t < pow56 /\ v c <= 2 /\ v x == v c * pow56 + v t) let carry56 x = let carry = x >>. 56ul in FStar.Math.Lemmas.pow2_minus 57 56; let t = x &. mask56 in assert_norm (pow2 56 < pow2 64); mod_mask_lemma x 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); t, carry inline_for_extraction noextract val add_modq5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < S.q /\ as_nat5 y < S.q) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (as_nat5 x + as_nat5 y) % S.q)
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.BignumQ.Mul.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Hacl.Spec.BignumQ.Definitions.qelem5 -> y: Hacl.Spec.BignumQ.Definitions.qelem5 -> Prims.Pure Hacl.Spec.BignumQ.Definitions.qelem5
Prims.Pure
[]
[]
[ "Hacl.Spec.BignumQ.Definitions.qelem5", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple5", "Lib.IntTypes.uint64", "FStar.Pervasives.Native.Mktuple5", "Prims.unit", "Hacl.Spec.BignumQ.Lemmas.lemma_add_modq5", "Hacl.Spec.BignumQ.Mul.subm_conditional", "Prims._assert", "Prims.eq2", "Prims.int", "Hacl.Spec.BignumQ.Definitions.as_nat5", "Prims.op_Addition", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Plus_Bang", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.BignumQ.Mul.carry56", "FStar.Pervasives.assert_norm", "Prims.op_Subtraction", "Hacl.Spec.BignumQ.Definitions.pow56", "Prims.pow2" ]
[]
false
false
false
false
false
let add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) =
assert_norm (pow56 - 1 + pow56 - 1 == pow2 57 - 2); let t0, c0 = carry56 (x0 +! y0) in let t1, c1 = carry56 (x1 +! y1 +! c0) in let t2, c2 = carry56 (x2 +! y2 +! c1) in let t3, c3 = carry56 (x3 +! y3 +! c2) in let t4 = x4 +! y4 +! c3 in assert (as_nat5 (t0, t1, t2, t3, t4) == as_nat5 (x0, x1, x2, x3, x4) + as_nat5 (y0, y1, y2, y3, y4)); let o0, o1, o2, o3, o4 = subm_conditional (t0, t1, t2, t3, t4) in Lemmas.lemma_add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) (t0, t1, t2, t3, t4); (o0, o1, o2, o3, o4)
false
Hacl.Spec.BignumQ.Mul.fst
Hacl.Spec.BignumQ.Mul.add5
val add5: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> (e:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112 /\ v e < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d + v e/\ v z <= pow2 116)
val add5: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> (e:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112 /\ v e < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d + v e/\ v z <= pow2 116)
let add5 a b c d e = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d + v e) (pow2 128); a +. b +. c +. d +. e
{ "file_name": "code/ed25519/Hacl.Spec.BignumQ.Mul.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 23, "end_line": 320, "start_col": 0, "start_line": 310 }
module Hacl.Spec.BignumQ.Mul open FStar.Mul open Lib.IntTypes module S = Spec.Ed25519 module Lemmas = Hacl.Spec.BignumQ.Lemmas include Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask56 : x:uint64{v x == pow2 56 - 1} = assert_norm (pow2 56 - 1 == 0xffffffffffffff); u64 0xffffffffffffff inline_for_extraction noextract let mask40 : x:uint64{v x == pow2 40 - 1} = assert_norm (pow2 40 - 1 == 0xffffffffff); u64 0xffffffffff inline_for_extraction noextract val make_m: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == S.q} let make_m () = let m0 = u64 0x12631a5cf5d3ed in let m1 = u64 0xf9dea2f79cd658 in let m2 = u64 0x000000000014de in let m3 = u64 0x00000000000000 in let m4 = u64 0x00000010000000 in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val make_mu: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == pow2 512 / S.q} let make_mu m = let m0 = u64 0x9ce5a30a2c131b in let m1 = u64 0x215d086329a7ed in let m2 = u64 0xffffffffeb2106 in let m3 = u64 0xffffffffffffff in let m4 = u64 0x00000fffffffff in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == pow2 512 / S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val choose: b:uint64 -> x:qelem5 -> y:qelem5 -> Pure qelem5 (requires v b == 0 \/ v b == 1) (ensures fun z -> if v b = 1 then z == x else z == y) let choose b (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let mask = b -. u64 1 in let z0 = x0 ^. (mask &. (x0 ^. y0)) in Lemmas.lemma_choose_step b x0 y0; let z1 = x1 ^. (mask &. (x1 ^. y1)) in Lemmas.lemma_choose_step b x1 y1; let z2 = x2 ^. (mask &. (x2 ^. y2)) in Lemmas.lemma_choose_step b x2 y2; let z3 = x3 ^. (mask &. (x3 ^. y3)) in Lemmas.lemma_choose_step b x3 y3; let z4 = x4 ^. (mask &. (x4 ^. y4)) in Lemmas.lemma_choose_step b x4 y4; (z0, z1, z2, z3, z4) inline_for_extraction noextract val subm_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow56 /\ v y <= pow56) (ensures fun (b, t) -> v b <= 1 /\ qelem_fits1 t 1 /\ v x - v y == v t - v b * pow56) let subm_step x y = let b = (x -. y) >>. 63ul in //assert (if v x >= v y then v b == 0 else v b == 1); let lshift56 = (b <<. 56ul) in //assert (if v x >= v y then v lshift56 == 0 else v lshift56 == pow56); //assert (v lshift56 == v b * pow56); //assert (v ((b <<. 56ul) +! x) == v b * pow56 + v x); let t = ((b <<. 56ul) +! x) -! y in b, t inline_for_extraction noextract val subm_conditional: x:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ (if as_nat5 x >= S.q then as_nat5 r == as_nat5 x - S.q else as_nat5 r == as_nat5 x)) let subm_conditional (x0, x1, x2, x3, x4) = let (y0, y1, y2, y3, y4) = make_m () in let (b0, t0) = subm_step x0 y0 in assert (v x0 - v y0 == v t0 - v b0 * pow56); let (b1, t1) = subm_step x1 (y1 +! b0) in assert (v x1 - v y1 - v b0 == v t1 - v b1 * pow56); let (b2, t2) = subm_step x2 (y2 +! b1) in assert (v x2 - v y2 - v b1 == v t2 - v b2 * pow56); let (b3, t3) = subm_step x3 (y3 +! b2) in assert (v x3 - v y3 - v b2 == v t3 - v b3 * pow56); let (b4, t4) = subm_step x4 (y4 +! b3) in assert (v x4 - v y4 - v b3 == v t4 - v b4 * pow56); Lemmas.lemma_subm_conditional (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) (v b0) (v b1) (v b2) (v b3) (v b4); assert ( as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow56 * pow224 == as_nat5 (x0, x1, x2, x3, x4) - as_nat5 (y0, y1, y2, y3, y4)); //assert_norm (pow56 * pow224 = pow2 280); //assert (as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow2 280 == as_nat5 (x0, x1, x2, x3, x4) - S.q); Lemmas.lemma_as_nat5 (x0, x1, x2, x3, x4); Lemmas.lemma_as_nat5 (t0, t1, t2, t3, t4); //assert (if v b4 = 0 then as_nat5 (x0, x1, x2, x3, x4) >= S.q else as_nat5 (x0, x1, x2, x3, x4) < S.q); assert (if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 else v b4 == 1); let (z0, z1, z2, z3, z4) = choose b4 (x0, x1, x2, x3, x4) (t0, t1, t2, t3, t4) in assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else v b4 == 1 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); (z0, z1, z2, z3, z4) inline_for_extraction noextract val carry56: x:uint64 -> Pure (uint64 & uint64) (requires v x <= pow2 57) (ensures fun (t, c) -> v t < pow56 /\ v c <= 2 /\ v x == v c * pow56 + v t) let carry56 x = let carry = x >>. 56ul in FStar.Math.Lemmas.pow2_minus 57 56; let t = x &. mask56 in assert_norm (pow2 56 < pow2 64); mod_mask_lemma x 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); t, carry inline_for_extraction noextract val add_modq5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < S.q /\ as_nat5 y < S.q) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (as_nat5 x + as_nat5 y) % S.q) let add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = assert_norm (pow56 - 1 + pow56 - 1 == pow2 57 - 2); let (t0, c0) = carry56 (x0 +! y0) in let (t1, c1) = carry56 (x1 +! y1 +! c0) in let (t2, c2) = carry56 (x2 +! y2 +! c1) in let (t3, c3) = carry56 (x3 +! y3 +! c2) in let t4 = x4 +! y4 +! c3 in assert (as_nat5 (t0, t1, t2, t3, t4) == as_nat5 (x0, x1, x2, x3, x4) + as_nat5 (y0, y1, y2, y3, y4)); let (o0, o1, o2, o3, o4) = subm_conditional (t0, t1, t2, t3, t4) in Lemmas.lemma_add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) (t0, t1, t2, t3, t4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry56_wide: x:uint128 -> Pure (uint128 & uint64) (requires v x < pow2 117) (ensures fun (c, t) -> v t < pow56 /\ v c < pow2 61 /\ v x - v c * pow56 == v t /\ v c == v x / pow56) let carry56_wide x = let carry = x >>. 56ul in let t = to_u64 x &. mask56 in assert_norm (pow2 56 < pow2 64); Math.Lemmas.lemma_div_lt_nat (v x) 117 56; mod_mask_lemma (to_u64 x) 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == (v x % pow2 64) % pow2 56); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v x) 56 64; assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); carry, t inline_for_extraction noextract val mul64_wide_5: (a:uint64) -> (b:uint64) -> Pure uint128 (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures fun z -> v z == v a * v b /\ v z <= pow2 112 - pow2 57 + 1 /\ v z < pow2 112) let mul64_wide_5 a b = let lemma_smaller (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) < pow2 112) = if v a = 0 || v b = 0 then () else calc (<) { v a * v b <: int; (<) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56) } v a * pow2 56; (<) { Math.Lemmas.lemma_mult_le_right (pow2 56) (v a) (pow2 56) } pow2 56 * pow2 56; (==) { assert_norm (pow2 56 * pow2 56 == pow2 112) } pow2 112; } in let lemma_le (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) <= pow2 112 - pow2 57 + 1) = if v a = 0 || v b = 0 then () else assert_norm (pow2 112 - pow2 57 + 1 >= 0); calc (<=) { v a * v b <: int; (<=) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56 - 1) } v a * (pow2 56 - 1); (<=) { Math.Lemmas.lemma_mult_le_right (pow2 56 - 1) (v a) (pow2 56 - 1) } (pow2 56 - 1) * (pow2 56 - 1); (==) { assert_norm ((pow2 56 - 1) * (pow2 56 - 1) == pow2 112 - pow2 57 + 1) } pow2 112 - pow2 57 + 1; } in lemma_le a b; lemma_smaller a b; mul64_wide a b inline_for_extraction noextract val add2: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112) (ensures fun z -> v z == v a + v b /\ v z <= pow2 116) let add2 a b = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b inline_for_extraction noextract val add3: (a:uint128) -> (b:uint128) -> (c:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 ) (ensures fun z -> v z == v a + v b + v c /\ v z <= pow2 116) let add3 a b c = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); a +. b +. c inline_for_extraction noextract val add4: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d /\ v z <= pow2 116) let add4 a b c d = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d) (pow2 128); a +. b +. c +. d inline_for_extraction noextract val add5: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> (e:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112 /\ v e < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d + v e/\
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.BignumQ.Mul.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.IntTypes.uint128 -> b: Lib.IntTypes.uint128 -> c: Lib.IntTypes.uint128 -> d: Lib.IntTypes.uint128 -> e: Lib.IntTypes.uint128 -> Prims.Pure Lib.IntTypes.uint128
Prims.Pure
[]
[]
[ "Lib.IntTypes.uint128", "Lib.IntTypes.op_Plus_Dot", "Lib.IntTypes.U128", "Lib.IntTypes.SEC", "Prims.unit", "FStar.Math.Lemmas.small_mod", "Prims.op_Addition", "Lib.IntTypes.v", "Prims.pow2", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan" ]
[]
false
false
false
false
false
let add5 a b c d e =
assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d + v e) (pow2 128); a +. b +. c +. d +. e
false
Hacl.Spec.BignumQ.Mul.fst
Hacl.Spec.BignumQ.Mul.lemma_mult_distr_3
val lemma_mult_distr_3 (a b c n: nat) : Lemma ((a + b - c * pow2 56) * pow2 n == a * pow2 n + b * pow2 n - c * pow2 (n + 56))
val lemma_mult_distr_3 (a b c n: nat) : Lemma ((a + b - c * pow2 56) * pow2 n == a * pow2 n + b * pow2 n - c * pow2 (n + 56))
let lemma_mult_distr_3 (a b c:nat) (n:nat) : Lemma ((a + b - c * pow2 56) * pow2 n == a * pow2 n + b * pow2 n - c * pow2 (n + 56)) = Math.Lemmas.distributivity_sub_left (a + b) (c * pow2 56) (pow2 n); Math.Lemmas.distributivity_add_left a b (pow2 n); Math.Lemmas.pow2_plus 56 n
{ "file_name": "code/ed25519/Hacl.Spec.BignumQ.Mul.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 30, "end_line": 353, "start_col": 0, "start_line": 348 }
module Hacl.Spec.BignumQ.Mul open FStar.Mul open Lib.IntTypes module S = Spec.Ed25519 module Lemmas = Hacl.Spec.BignumQ.Lemmas include Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask56 : x:uint64{v x == pow2 56 - 1} = assert_norm (pow2 56 - 1 == 0xffffffffffffff); u64 0xffffffffffffff inline_for_extraction noextract let mask40 : x:uint64{v x == pow2 40 - 1} = assert_norm (pow2 40 - 1 == 0xffffffffff); u64 0xffffffffff inline_for_extraction noextract val make_m: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == S.q} let make_m () = let m0 = u64 0x12631a5cf5d3ed in let m1 = u64 0xf9dea2f79cd658 in let m2 = u64 0x000000000014de in let m3 = u64 0x00000000000000 in let m4 = u64 0x00000010000000 in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val make_mu: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == pow2 512 / S.q} let make_mu m = let m0 = u64 0x9ce5a30a2c131b in let m1 = u64 0x215d086329a7ed in let m2 = u64 0xffffffffeb2106 in let m3 = u64 0xffffffffffffff in let m4 = u64 0x00000fffffffff in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == pow2 512 / S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val choose: b:uint64 -> x:qelem5 -> y:qelem5 -> Pure qelem5 (requires v b == 0 \/ v b == 1) (ensures fun z -> if v b = 1 then z == x else z == y) let choose b (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let mask = b -. u64 1 in let z0 = x0 ^. (mask &. (x0 ^. y0)) in Lemmas.lemma_choose_step b x0 y0; let z1 = x1 ^. (mask &. (x1 ^. y1)) in Lemmas.lemma_choose_step b x1 y1; let z2 = x2 ^. (mask &. (x2 ^. y2)) in Lemmas.lemma_choose_step b x2 y2; let z3 = x3 ^. (mask &. (x3 ^. y3)) in Lemmas.lemma_choose_step b x3 y3; let z4 = x4 ^. (mask &. (x4 ^. y4)) in Lemmas.lemma_choose_step b x4 y4; (z0, z1, z2, z3, z4) inline_for_extraction noextract val subm_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow56 /\ v y <= pow56) (ensures fun (b, t) -> v b <= 1 /\ qelem_fits1 t 1 /\ v x - v y == v t - v b * pow56) let subm_step x y = let b = (x -. y) >>. 63ul in //assert (if v x >= v y then v b == 0 else v b == 1); let lshift56 = (b <<. 56ul) in //assert (if v x >= v y then v lshift56 == 0 else v lshift56 == pow56); //assert (v lshift56 == v b * pow56); //assert (v ((b <<. 56ul) +! x) == v b * pow56 + v x); let t = ((b <<. 56ul) +! x) -! y in b, t inline_for_extraction noextract val subm_conditional: x:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ (if as_nat5 x >= S.q then as_nat5 r == as_nat5 x - S.q else as_nat5 r == as_nat5 x)) let subm_conditional (x0, x1, x2, x3, x4) = let (y0, y1, y2, y3, y4) = make_m () in let (b0, t0) = subm_step x0 y0 in assert (v x0 - v y0 == v t0 - v b0 * pow56); let (b1, t1) = subm_step x1 (y1 +! b0) in assert (v x1 - v y1 - v b0 == v t1 - v b1 * pow56); let (b2, t2) = subm_step x2 (y2 +! b1) in assert (v x2 - v y2 - v b1 == v t2 - v b2 * pow56); let (b3, t3) = subm_step x3 (y3 +! b2) in assert (v x3 - v y3 - v b2 == v t3 - v b3 * pow56); let (b4, t4) = subm_step x4 (y4 +! b3) in assert (v x4 - v y4 - v b3 == v t4 - v b4 * pow56); Lemmas.lemma_subm_conditional (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) (v b0) (v b1) (v b2) (v b3) (v b4); assert ( as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow56 * pow224 == as_nat5 (x0, x1, x2, x3, x4) - as_nat5 (y0, y1, y2, y3, y4)); //assert_norm (pow56 * pow224 = pow2 280); //assert (as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow2 280 == as_nat5 (x0, x1, x2, x3, x4) - S.q); Lemmas.lemma_as_nat5 (x0, x1, x2, x3, x4); Lemmas.lemma_as_nat5 (t0, t1, t2, t3, t4); //assert (if v b4 = 0 then as_nat5 (x0, x1, x2, x3, x4) >= S.q else as_nat5 (x0, x1, x2, x3, x4) < S.q); assert (if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 else v b4 == 1); let (z0, z1, z2, z3, z4) = choose b4 (x0, x1, x2, x3, x4) (t0, t1, t2, t3, t4) in assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else v b4 == 1 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); (z0, z1, z2, z3, z4) inline_for_extraction noextract val carry56: x:uint64 -> Pure (uint64 & uint64) (requires v x <= pow2 57) (ensures fun (t, c) -> v t < pow56 /\ v c <= 2 /\ v x == v c * pow56 + v t) let carry56 x = let carry = x >>. 56ul in FStar.Math.Lemmas.pow2_minus 57 56; let t = x &. mask56 in assert_norm (pow2 56 < pow2 64); mod_mask_lemma x 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); t, carry inline_for_extraction noextract val add_modq5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < S.q /\ as_nat5 y < S.q) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (as_nat5 x + as_nat5 y) % S.q) let add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = assert_norm (pow56 - 1 + pow56 - 1 == pow2 57 - 2); let (t0, c0) = carry56 (x0 +! y0) in let (t1, c1) = carry56 (x1 +! y1 +! c0) in let (t2, c2) = carry56 (x2 +! y2 +! c1) in let (t3, c3) = carry56 (x3 +! y3 +! c2) in let t4 = x4 +! y4 +! c3 in assert (as_nat5 (t0, t1, t2, t3, t4) == as_nat5 (x0, x1, x2, x3, x4) + as_nat5 (y0, y1, y2, y3, y4)); let (o0, o1, o2, o3, o4) = subm_conditional (t0, t1, t2, t3, t4) in Lemmas.lemma_add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) (t0, t1, t2, t3, t4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry56_wide: x:uint128 -> Pure (uint128 & uint64) (requires v x < pow2 117) (ensures fun (c, t) -> v t < pow56 /\ v c < pow2 61 /\ v x - v c * pow56 == v t /\ v c == v x / pow56) let carry56_wide x = let carry = x >>. 56ul in let t = to_u64 x &. mask56 in assert_norm (pow2 56 < pow2 64); Math.Lemmas.lemma_div_lt_nat (v x) 117 56; mod_mask_lemma (to_u64 x) 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == (v x % pow2 64) % pow2 56); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v x) 56 64; assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); carry, t inline_for_extraction noextract val mul64_wide_5: (a:uint64) -> (b:uint64) -> Pure uint128 (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures fun z -> v z == v a * v b /\ v z <= pow2 112 - pow2 57 + 1 /\ v z < pow2 112) let mul64_wide_5 a b = let lemma_smaller (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) < pow2 112) = if v a = 0 || v b = 0 then () else calc (<) { v a * v b <: int; (<) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56) } v a * pow2 56; (<) { Math.Lemmas.lemma_mult_le_right (pow2 56) (v a) (pow2 56) } pow2 56 * pow2 56; (==) { assert_norm (pow2 56 * pow2 56 == pow2 112) } pow2 112; } in let lemma_le (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) <= pow2 112 - pow2 57 + 1) = if v a = 0 || v b = 0 then () else assert_norm (pow2 112 - pow2 57 + 1 >= 0); calc (<=) { v a * v b <: int; (<=) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56 - 1) } v a * (pow2 56 - 1); (<=) { Math.Lemmas.lemma_mult_le_right (pow2 56 - 1) (v a) (pow2 56 - 1) } (pow2 56 - 1) * (pow2 56 - 1); (==) { assert_norm ((pow2 56 - 1) * (pow2 56 - 1) == pow2 112 - pow2 57 + 1) } pow2 112 - pow2 57 + 1; } in lemma_le a b; lemma_smaller a b; mul64_wide a b inline_for_extraction noextract val add2: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112) (ensures fun z -> v z == v a + v b /\ v z <= pow2 116) let add2 a b = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b inline_for_extraction noextract val add3: (a:uint128) -> (b:uint128) -> (c:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 ) (ensures fun z -> v z == v a + v b + v c /\ v z <= pow2 116) let add3 a b c = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); a +. b +. c inline_for_extraction noextract val add4: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d /\ v z <= pow2 116) let add4 a b c d = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d) (pow2 128); a +. b +. c +. d inline_for_extraction noextract val add5: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> (e:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112 /\ v e < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d + v e/\ v z <= pow2 116) let add5 a b c d e = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d + v e) (pow2 128); a +. b +. c +. d +. e inline_for_extraction noextract val add_inner_carry: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a <= pow2 116 /\ v b < pow2 61) (ensures fun z -> v z == v a + v b /\ v z < pow2 117) let add_inner_carry a b = assert_norm (pow2 116 + pow2 61 < pow2 128); assert_norm (pow2 116 + pow2 61 < pow2 117); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b inline_for_extraction noextract val mul_5: x:qelem5 -> y:qelem5 -> Pure qelem_wide5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1)) (ensures fun r -> qelem_wide_fits5 r (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 r == as_nat5 x * as_nat5 y)
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.BignumQ.Mul.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Prims.nat -> b: Prims.nat -> c: Prims.nat -> n: Prims.nat -> FStar.Pervasives.Lemma (ensures (a + b - c * Prims.pow2 56) * Prims.pow2 n == a * Prims.pow2 n + b * Prims.pow2 n - c * Prims.pow2 (n + 56))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "FStar.Math.Lemmas.pow2_plus", "Prims.unit", "FStar.Math.Lemmas.distributivity_add_left", "Prims.pow2", "FStar.Math.Lemmas.distributivity_sub_left", "Prims.op_Addition", "FStar.Mul.op_Star", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.int", "Prims.op_Subtraction", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_mult_distr_3 (a b c n: nat) : Lemma ((a + b - c * pow2 56) * pow2 n == a * pow2 n + b * pow2 n - c * pow2 (n + 56)) =
Math.Lemmas.distributivity_sub_left (a + b) (c * pow2 56) (pow2 n); Math.Lemmas.distributivity_add_left a b (pow2 n); Math.Lemmas.pow2_plus 56 n
false
Hacl.Impl.Curve25519.Finv.fst
Hacl.Impl.Curve25519.Finv.finv2
val finv2: #s:field_spec -> t1:lbuffer (limb s) (4ul *! nlimb s) -> tmp:felem_wide2 s -> Stack unit (requires fun h0 -> live h0 t1 /\ live h0 tmp /\ disjoint t1 tmp /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in fsquare_times_inv h0 as0 /\ fsquare_times_inv h0 bs)) (ensures fun h0 _ h1 -> modifies (loc t1 |+| loc tmp) h0 h1 /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in let cs : felem s = gsub t1 (2ul *! nlimb s) (nlimb s) in let t0 = S.fsquare_times (feval h0 bs) 10 in let c = P.fmul t0 (feval h0 bs) in let t0 = S.fsquare_times c 20 in let t0 = P.fmul t0 c in let t0 = S.fsquare_times t0 10 in let b = P.fmul t0 (feval h0 bs) in let t0 = S.fsquare_times b 50 in let c = P.fmul t0 b in feval h1 as0 == feval h0 as0 /\ fsquare_times_inv h1 as0 /\ feval h1 bs == b /\ fsquare_times_inv h1 bs /\ feval h1 cs == c /\ fsquare_times_inv h1 cs))
val finv2: #s:field_spec -> t1:lbuffer (limb s) (4ul *! nlimb s) -> tmp:felem_wide2 s -> Stack unit (requires fun h0 -> live h0 t1 /\ live h0 tmp /\ disjoint t1 tmp /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in fsquare_times_inv h0 as0 /\ fsquare_times_inv h0 bs)) (ensures fun h0 _ h1 -> modifies (loc t1 |+| loc tmp) h0 h1 /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in let cs : felem s = gsub t1 (2ul *! nlimb s) (nlimb s) in let t0 = S.fsquare_times (feval h0 bs) 10 in let c = P.fmul t0 (feval h0 bs) in let t0 = S.fsquare_times c 20 in let t0 = P.fmul t0 c in let t0 = S.fsquare_times t0 10 in let b = P.fmul t0 (feval h0 bs) in let t0 = S.fsquare_times b 50 in let c = P.fmul t0 b in feval h1 as0 == feval h0 as0 /\ fsquare_times_inv h1 as0 /\ feval h1 bs == b /\ fsquare_times_inv h1 bs /\ feval h1 cs == c /\ fsquare_times_inv h1 cs))
let finv2 #s t1 tmp = let h0 = ST.get () in let a : felem s = sub t1 0ul (nlimb s) in let b : felem s = sub t1 (nlimb s) (nlimb s) in let c : felem s = sub t1 (2ul *! nlimb s) (nlimb s) in let t0 : felem s = sub t1 (3ul *! nlimb s) (nlimb s) in let tmp1 : felem_wide s = sub tmp 0ul (nwide s) in (* 2^20 - 2^10 *) fsquare_times #s t0 b tmp1 10ul; (* 2^20 - 2^0 *) fmul_s #s c t0 b tmp; (* 2^40 - 2^20 *) fsquare_times #s t0 c tmp1 20ul; (* 2^40 - 2^0 *) fmul_s #s t0 t0 c tmp; (* 2^50 - 2^10 *) fsquare_times #s t0 t0 tmp1 10ul; (* 2^50 - 2^0 *) fmul_s #s b t0 b tmp; (* 2^100 - 2^50 *) fsquare_times #s t0 b tmp1 50ul; (* 2^100 - 2^0 *) fmul_s #s c t0 b tmp
{ "file_name": "code/curve25519/Hacl.Impl.Curve25519.Finv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 40, "end_line": 208, "start_col": 0, "start_line": 194 }
module Hacl.Impl.Curve25519.Finv open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Curve25519.Fields module ST = FStar.HyperStack.ST module C = Hacl.Impl.Curve25519.Fields.Core module S = Hacl.Spec.Curve25519.Finv module P = Spec.Curve25519 let _: squash (inversion field_spec) = allow_inversion field_spec #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --record_options" noextract val fsquare_times_inv: #s:field_spec -> h:mem -> f:felem s -> Type0 let fsquare_times_inv #s h f = match s with | M51 -> C.f51_felem_fits h f (1, 2, 1, 1, 1) | M64 -> True val fsqr_s: #s:field_spec -> out:felem s -> f1:felem s -> tmp:felem_wide s -> Stack unit (requires fun h -> live h out /\ live h f1 /\ live h tmp /\ (disjoint out f1 \/ out == f1) /\ (disjoint out tmp) /\ disjoint tmp f1 /\ fsquare_times_inv h f1) (ensures fun h0 _ h1 -> modifies (loc out |+| loc tmp) h0 h1 /\ fsquare_times_inv h1 out /\ feval h1 out == P.fmul (feval h0 f1) (feval h0 f1)) [@ Meta.Attribute.inline_ ] let fsqr_s #s out f1 tmp = C.fsqr #s out f1 tmp noextract val fmuls_pre: #s:field_spec -> h:mem -> f1:felem s -> f2:felem s -> Type0 let fmuls_pre #s h f1 f2 = match s with | M51 -> f51_felem_fits h f1 (1, 2, 1, 1, 1) /\ f51_felem_fits h f2 (1, 2, 1, 1, 1) | M64 -> True val fmul_s: #s:field_spec -> out:felem s -> f1:felem s -> f2:felem s -> tmp:felem_wide2 s -> Stack unit (requires fun h -> live h out /\ live h f1 /\ live h f2 /\ live h tmp /\ (disjoint out f1 \/ out == f1) /\ (disjoint out f2 \/ out == f2) /\ (disjoint out tmp) /\ (disjoint f1 f2 \/ f1 == f2) /\ disjoint f1 tmp /\ disjoint f2 tmp /\ fmuls_pre h f1 f2) (ensures fun h0 _ h1 -> modifies (loc out |+| loc tmp) h0 h1 /\ fsquare_times_inv h1 out /\ feval h1 out == P.fmul (feval h0 f1) (feval h0 f2)) [@ Meta.Attribute.inline_ ] let fmul_s #s out f1 f2 tmp = C.fmul #s out f1 f2 tmp val fsquare_times: #s:field_spec -> o:felem s -> i:felem s -> tmp:felem_wide s -> n:size_t{v n > 0} -> Stack unit (requires fun h0 -> live h0 o /\ live h0 i /\ live h0 tmp /\ (disjoint o i \/ o == i) /\ disjoint o tmp /\ disjoint tmp i /\ fsquare_times_inv h0 i) (ensures fun h0 _ h1 -> modifies (loc o |+| loc tmp) h0 h1 /\ fsquare_times_inv h1 o /\ feval h1 o == S.pow (feval #s h0 i) (pow2 (v n))) [@ Meta.Attribute.specialize ] let fsquare_times #s o inp tmp n = let h0 = ST.get() in fsqr_s #s o inp tmp; S.lemma_pow_one (feval h0 inp); S.lemma_pow_add (feval h0 inp) 1 1; assert_norm (pow2 1 = 2); let inv (h:mem) (i:nat{i < v n}) = modifies (loc o |+| loc tmp) h0 h /\ fsquare_times_inv #s h o /\ feval h o == S.pow (feval #s h0 inp) (pow2 (i + 1)) in let h1 = ST.get () in assert (inv h1 0); Lib.Loops.for 0ul (n -! 1ul) inv (fun i -> let h2 = ST.get () in fsqr_s #s o o tmp; S.lemma_pow_add (feval #s h0 inp) (pow2 (v i + 1)) (pow2 (v i + 1)); Math.Lemmas.pow2_double_sum (v i + 1)) val finv1: #s:field_spec -> i:felem s -> t1:lbuffer (limb s) (4ul *! nlimb s) -> tmp:felem_wide2 s -> Stack unit (requires fun h0 -> live h0 i /\ live h0 t1 /\ live h0 tmp /\ disjoint i t1 /\ disjoint i tmp /\ disjoint t1 tmp /\ fsquare_times_inv h0 i) (ensures fun h0 _ h1 -> modifies (loc t1 |+| loc tmp) h0 h1 /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in let a = S.fsquare_times (feval h0 i) 1 in let t0 = S.fsquare_times a 2 in let b = P.fmul t0 (feval h0 i) in let a = P.fmul b a in let t0 = S.fsquare_times a 1 in let b = P.fmul t0 b in let t0 = S.fsquare_times b 5 in let b = P.fmul t0 b in feval h1 as0 == a /\ fsquare_times_inv h1 as0 /\ feval h1 bs == b /\ fsquare_times_inv h1 bs)) [@ Meta.Attribute.inline_ ] let finv1 #s i t1 tmp = let h0 = ST.get () in let a : felem s = sub t1 0ul (nlimb s) in let b : felem s = sub t1 (nlimb s) (nlimb s) in let c : felem s = sub t1 (2ul *! nlimb s) (nlimb s) in let t0 : felem s = sub t1 (3ul *! nlimb s) (nlimb s) in let tmp1 : felem_wide s = sub tmp 0ul (nwide s) in (* 2 *) fsquare_times #s a i tmp1 1ul; (* 8 *) fsquare_times #s t0 a tmp1 2ul; (* 9 *) fmul_s #s b t0 i tmp; (* 11 *) fmul_s #s a b a tmp; (* 22 *) fsquare_times #s t0 a tmp1 1ul; (* 2^5 - 2^0 = 31 *) fmul_s #s b t0 b tmp; (* 2^10 - 2^5 *) fsquare_times #s t0 b tmp1 5ul; (* 2^10 - 2^0 *) fmul_s #s b t0 b tmp val finv2: #s:field_spec -> t1:lbuffer (limb s) (4ul *! nlimb s) -> tmp:felem_wide2 s -> Stack unit (requires fun h0 -> live h0 t1 /\ live h0 tmp /\ disjoint t1 tmp /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in fsquare_times_inv h0 as0 /\ fsquare_times_inv h0 bs)) (ensures fun h0 _ h1 -> modifies (loc t1 |+| loc tmp) h0 h1 /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in let cs : felem s = gsub t1 (2ul *! nlimb s) (nlimb s) in let t0 = S.fsquare_times (feval h0 bs) 10 in let c = P.fmul t0 (feval h0 bs) in let t0 = S.fsquare_times c 20 in let t0 = P.fmul t0 c in let t0 = S.fsquare_times t0 10 in let b = P.fmul t0 (feval h0 bs) in let t0 = S.fsquare_times b 50 in let c = P.fmul t0 b in feval h1 as0 == feval h0 as0 /\ fsquare_times_inv h1 as0 /\ feval h1 bs == b /\ fsquare_times_inv h1 bs /\ feval h1 cs == c /\ fsquare_times_inv h1 cs))
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Loops.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Finv.fst.checked", "Hacl.Impl.Curve25519.Fields.Core.fsti.checked", "Hacl.Impl.Curve25519.Fields.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Curve25519.Finv.fst" }
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "P" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Finv", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Fields.Core", "short_module": "C" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 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
t1: Lib.Buffer.lbuffer (Hacl.Impl.Curve25519.Fields.Core.limb s) (4ul *! Hacl.Impl.Curve25519.Fields.Core.nlimb s) -> tmp: Hacl.Impl.Curve25519.Fields.Core.felem_wide2 s -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Curve25519.Fields.Core.field_spec", "Lib.Buffer.lbuffer", "Hacl.Impl.Curve25519.Fields.Core.limb", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "FStar.UInt32.__uint_to_t", "Hacl.Impl.Curve25519.Fields.Core.nlimb", "Hacl.Impl.Curve25519.Fields.Core.felem_wide2", "Hacl.Impl.Curve25519.Finv.fmul_s", "Prims.unit", "Hacl.Impl.Curve25519.Finv.fsquare_times", "Hacl.Impl.Curve25519.Fields.Core.felem_wide", "Lib.Buffer.sub", "Lib.Buffer.MUT", "Hacl.Impl.Curve25519.Fields.Core.wide", "Lib.IntTypes.op_Plus_Dot", "Hacl.Impl.Curve25519.Fields.Core.nwide", "Lib.Buffer.lbuffer_t", "Hacl.Impl.Curve25519.Fields.Core.felem", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
false
true
false
false
false
let finv2 #s t1 tmp =
let h0 = ST.get () in let a:felem s = sub t1 0ul (nlimb s) in let b:felem s = sub t1 (nlimb s) (nlimb s) in let c:felem s = sub t1 (2ul *! nlimb s) (nlimb s) in let t0:felem s = sub t1 (3ul *! nlimb s) (nlimb s) in let tmp1:felem_wide s = sub tmp 0ul (nwide s) in fsquare_times #s t0 b tmp1 10ul; fmul_s #s c t0 b tmp; fsquare_times #s t0 c tmp1 20ul; fmul_s #s t0 t0 c tmp; fsquare_times #s t0 t0 tmp1 10ul; fmul_s #s b t0 b tmp; fsquare_times #s t0 b tmp1 50ul; fmul_s #s c t0 b tmp
false
Hacl.Spec.BignumQ.Mul.fst
Hacl.Spec.BignumQ.Mul.div_248
val div_248: x:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 x < pow2 512) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (wide_as_nat5 x) / pow2 248)
val div_248: x:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 x < pow2 512) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (wide_as_nat5 x) / pow2 248)
let div_248 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = // x / pow2 248 == (x / pow2 224) / pow2 24 let z0 = div_2_24_step x4 x5 in let z1 = div_2_24_step x5 x6 in let z2 = div_2_24_step x6 x7 in let z3 = div_2_24_step x7 x8 in let z4 = div_2_24_step x8 x9 in assert (qelem_fits5 (z0, z1, z2, z3, z4) (1, 1, 1, 1, 1)); Lemmas.lemma_div248 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9); (z0, z1, z2, z3, z4)
{ "file_name": "code/ed25519/Hacl.Spec.BignumQ.Mul.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 22, "end_line": 674, "start_col": 0, "start_line": 665 }
module Hacl.Spec.BignumQ.Mul open FStar.Mul open Lib.IntTypes module S = Spec.Ed25519 module Lemmas = Hacl.Spec.BignumQ.Lemmas include Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask56 : x:uint64{v x == pow2 56 - 1} = assert_norm (pow2 56 - 1 == 0xffffffffffffff); u64 0xffffffffffffff inline_for_extraction noextract let mask40 : x:uint64{v x == pow2 40 - 1} = assert_norm (pow2 40 - 1 == 0xffffffffff); u64 0xffffffffff inline_for_extraction noextract val make_m: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == S.q} let make_m () = let m0 = u64 0x12631a5cf5d3ed in let m1 = u64 0xf9dea2f79cd658 in let m2 = u64 0x000000000014de in let m3 = u64 0x00000000000000 in let m4 = u64 0x00000010000000 in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val make_mu: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == pow2 512 / S.q} let make_mu m = let m0 = u64 0x9ce5a30a2c131b in let m1 = u64 0x215d086329a7ed in let m2 = u64 0xffffffffeb2106 in let m3 = u64 0xffffffffffffff in let m4 = u64 0x00000fffffffff in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == pow2 512 / S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val choose: b:uint64 -> x:qelem5 -> y:qelem5 -> Pure qelem5 (requires v b == 0 \/ v b == 1) (ensures fun z -> if v b = 1 then z == x else z == y) let choose b (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let mask = b -. u64 1 in let z0 = x0 ^. (mask &. (x0 ^. y0)) in Lemmas.lemma_choose_step b x0 y0; let z1 = x1 ^. (mask &. (x1 ^. y1)) in Lemmas.lemma_choose_step b x1 y1; let z2 = x2 ^. (mask &. (x2 ^. y2)) in Lemmas.lemma_choose_step b x2 y2; let z3 = x3 ^. (mask &. (x3 ^. y3)) in Lemmas.lemma_choose_step b x3 y3; let z4 = x4 ^. (mask &. (x4 ^. y4)) in Lemmas.lemma_choose_step b x4 y4; (z0, z1, z2, z3, z4) inline_for_extraction noextract val subm_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow56 /\ v y <= pow56) (ensures fun (b, t) -> v b <= 1 /\ qelem_fits1 t 1 /\ v x - v y == v t - v b * pow56) let subm_step x y = let b = (x -. y) >>. 63ul in //assert (if v x >= v y then v b == 0 else v b == 1); let lshift56 = (b <<. 56ul) in //assert (if v x >= v y then v lshift56 == 0 else v lshift56 == pow56); //assert (v lshift56 == v b * pow56); //assert (v ((b <<. 56ul) +! x) == v b * pow56 + v x); let t = ((b <<. 56ul) +! x) -! y in b, t inline_for_extraction noextract val subm_conditional: x:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ (if as_nat5 x >= S.q then as_nat5 r == as_nat5 x - S.q else as_nat5 r == as_nat5 x)) let subm_conditional (x0, x1, x2, x3, x4) = let (y0, y1, y2, y3, y4) = make_m () in let (b0, t0) = subm_step x0 y0 in assert (v x0 - v y0 == v t0 - v b0 * pow56); let (b1, t1) = subm_step x1 (y1 +! b0) in assert (v x1 - v y1 - v b0 == v t1 - v b1 * pow56); let (b2, t2) = subm_step x2 (y2 +! b1) in assert (v x2 - v y2 - v b1 == v t2 - v b2 * pow56); let (b3, t3) = subm_step x3 (y3 +! b2) in assert (v x3 - v y3 - v b2 == v t3 - v b3 * pow56); let (b4, t4) = subm_step x4 (y4 +! b3) in assert (v x4 - v y4 - v b3 == v t4 - v b4 * pow56); Lemmas.lemma_subm_conditional (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) (v b0) (v b1) (v b2) (v b3) (v b4); assert ( as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow56 * pow224 == as_nat5 (x0, x1, x2, x3, x4) - as_nat5 (y0, y1, y2, y3, y4)); //assert_norm (pow56 * pow224 = pow2 280); //assert (as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow2 280 == as_nat5 (x0, x1, x2, x3, x4) - S.q); Lemmas.lemma_as_nat5 (x0, x1, x2, x3, x4); Lemmas.lemma_as_nat5 (t0, t1, t2, t3, t4); //assert (if v b4 = 0 then as_nat5 (x0, x1, x2, x3, x4) >= S.q else as_nat5 (x0, x1, x2, x3, x4) < S.q); assert (if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 else v b4 == 1); let (z0, z1, z2, z3, z4) = choose b4 (x0, x1, x2, x3, x4) (t0, t1, t2, t3, t4) in assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else v b4 == 1 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); (z0, z1, z2, z3, z4) inline_for_extraction noextract val carry56: x:uint64 -> Pure (uint64 & uint64) (requires v x <= pow2 57) (ensures fun (t, c) -> v t < pow56 /\ v c <= 2 /\ v x == v c * pow56 + v t) let carry56 x = let carry = x >>. 56ul in FStar.Math.Lemmas.pow2_minus 57 56; let t = x &. mask56 in assert_norm (pow2 56 < pow2 64); mod_mask_lemma x 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); t, carry inline_for_extraction noextract val add_modq5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < S.q /\ as_nat5 y < S.q) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (as_nat5 x + as_nat5 y) % S.q) let add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = assert_norm (pow56 - 1 + pow56 - 1 == pow2 57 - 2); let (t0, c0) = carry56 (x0 +! y0) in let (t1, c1) = carry56 (x1 +! y1 +! c0) in let (t2, c2) = carry56 (x2 +! y2 +! c1) in let (t3, c3) = carry56 (x3 +! y3 +! c2) in let t4 = x4 +! y4 +! c3 in assert (as_nat5 (t0, t1, t2, t3, t4) == as_nat5 (x0, x1, x2, x3, x4) + as_nat5 (y0, y1, y2, y3, y4)); let (o0, o1, o2, o3, o4) = subm_conditional (t0, t1, t2, t3, t4) in Lemmas.lemma_add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) (t0, t1, t2, t3, t4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry56_wide: x:uint128 -> Pure (uint128 & uint64) (requires v x < pow2 117) (ensures fun (c, t) -> v t < pow56 /\ v c < pow2 61 /\ v x - v c * pow56 == v t /\ v c == v x / pow56) let carry56_wide x = let carry = x >>. 56ul in let t = to_u64 x &. mask56 in assert_norm (pow2 56 < pow2 64); Math.Lemmas.lemma_div_lt_nat (v x) 117 56; mod_mask_lemma (to_u64 x) 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == (v x % pow2 64) % pow2 56); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v x) 56 64; assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); carry, t inline_for_extraction noextract val mul64_wide_5: (a:uint64) -> (b:uint64) -> Pure uint128 (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures fun z -> v z == v a * v b /\ v z <= pow2 112 - pow2 57 + 1 /\ v z < pow2 112) let mul64_wide_5 a b = let lemma_smaller (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) < pow2 112) = if v a = 0 || v b = 0 then () else calc (<) { v a * v b <: int; (<) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56) } v a * pow2 56; (<) { Math.Lemmas.lemma_mult_le_right (pow2 56) (v a) (pow2 56) } pow2 56 * pow2 56; (==) { assert_norm (pow2 56 * pow2 56 == pow2 112) } pow2 112; } in let lemma_le (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) <= pow2 112 - pow2 57 + 1) = if v a = 0 || v b = 0 then () else assert_norm (pow2 112 - pow2 57 + 1 >= 0); calc (<=) { v a * v b <: int; (<=) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56 - 1) } v a * (pow2 56 - 1); (<=) { Math.Lemmas.lemma_mult_le_right (pow2 56 - 1) (v a) (pow2 56 - 1) } (pow2 56 - 1) * (pow2 56 - 1); (==) { assert_norm ((pow2 56 - 1) * (pow2 56 - 1) == pow2 112 - pow2 57 + 1) } pow2 112 - pow2 57 + 1; } in lemma_le a b; lemma_smaller a b; mul64_wide a b inline_for_extraction noextract val add2: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112) (ensures fun z -> v z == v a + v b /\ v z <= pow2 116) let add2 a b = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b inline_for_extraction noextract val add3: (a:uint128) -> (b:uint128) -> (c:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 ) (ensures fun z -> v z == v a + v b + v c /\ v z <= pow2 116) let add3 a b c = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); a +. b +. c inline_for_extraction noextract val add4: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d /\ v z <= pow2 116) let add4 a b c d = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d) (pow2 128); a +. b +. c +. d inline_for_extraction noextract val add5: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> (e:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112 /\ v e < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d + v e/\ v z <= pow2 116) let add5 a b c d e = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d + v e) (pow2 128); a +. b +. c +. d +. e inline_for_extraction noextract val add_inner_carry: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a <= pow2 116 /\ v b < pow2 61) (ensures fun z -> v z == v a + v b /\ v z < pow2 117) let add_inner_carry a b = assert_norm (pow2 116 + pow2 61 < pow2 128); assert_norm (pow2 116 + pow2 61 < pow2 117); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b inline_for_extraction noextract val mul_5: x:qelem5 -> y:qelem5 -> Pure qelem_wide5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1)) (ensures fun r -> qelem_wide_fits5 r (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 r == as_nat5 x * as_nat5 y) let lemma_mult_distr_3 (a b c:nat) (n:nat) : Lemma ((a + b - c * pow2 56) * pow2 n == a * pow2 n + b * pow2 n - c * pow2 (n + 56)) = Math.Lemmas.distributivity_sub_left (a + b) (c * pow2 56) (pow2 n); Math.Lemmas.distributivity_add_left a b (pow2 n); Math.Lemmas.pow2_plus 56 n #set-options "--z3rlimit 300" let mul_5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let xy00 = mul64_wide_5 x0 y0 in let xy01 = mul64_wide_5 x0 y1 in let xy02 = mul64_wide_5 x0 y2 in let xy03 = mul64_wide_5 x0 y3 in let xy04 = mul64_wide_5 x0 y4 in let xy10 = mul64_wide_5 x1 y0 in let xy11 = mul64_wide_5 x1 y1 in let xy12 = mul64_wide_5 x1 y2 in let xy13 = mul64_wide_5 x1 y3 in let xy14 = mul64_wide_5 x1 y4 in let xy20 = mul64_wide_5 x2 y0 in let xy21 = mul64_wide_5 x2 y1 in let xy22 = mul64_wide_5 x2 y2 in let xy23 = mul64_wide_5 x2 y3 in let xy24 = mul64_wide_5 x2 y4 in let xy30 = mul64_wide_5 x3 y0 in let xy31 = mul64_wide_5 x3 y1 in let xy32 = mul64_wide_5 x3 y2 in let xy33 = mul64_wide_5 x3 y3 in let xy34 = mul64_wide_5 x3 y4 in let xy40 = mul64_wide_5 x4 y0 in let xy41 = mul64_wide_5 x4 y1 in let xy42 = mul64_wide_5 x4 y2 in let xy43 = mul64_wide_5 x4 y3 in let xy44 = mul64_wide_5 x4 y4 in let z0 = xy00 in // < pow2 112 let z1 = add2 xy01 xy10 in // < pow2 113 let z2 = add3 xy02 xy11 xy20 in // < pow2 114 let z3 = add4 xy03 xy12 xy21 xy30 in // < pow2 115 let z4 = add5 xy04 xy13 xy22 xy31 xy40 in // < pow2 116 let z5 = add4 xy14 xy23 xy32 xy41 in let z6 = add3 xy24 xy33 xy42 in let z7 = add2 xy34 xy43 in let z8 = xy44 in //(z0, z1, z2, z3, z4, z5, z6, z7, z8) assert_norm (pow2 112 < pow2 117); assert_norm (pow2 112 <= pow2 116); let (c0, t0) = carry56_wide z0 in let (c1, t1) = carry56_wide (add_inner_carry z1 c0) in let (c2, t2) = carry56_wide (add_inner_carry z2 c1) in let (c3, t3) = carry56_wide (add_inner_carry z3 c2) in let (c4, t4) = carry56_wide (add_inner_carry z4 c3) in let (c5, t5) = carry56_wide (add_inner_carry z5 c4) in let (c6, t6) = carry56_wide (add_inner_carry z6 c5) in let (c7, t7) = carry56_wide (add_inner_carry z7 c6) in let (c8, t8) = carry56_wide (add_inner_carry z8 c7) in let t9 = to_u64 c8 in let lemma_t9_fits () : Lemma (v t9 < pow2 56) = // This proof was built from the bottom. We have as a constraint that v c8 has to be < pow2 112 to satisfy the postcondition. // We compute each time the maximal value such that this postcondition is satisfied calc (<) { v c0; (<) { Math.Lemmas.lemma_div_lt_nat (v z0) 112 56 } pow2 56; }; calc (<) { v c1; (<) { assert_norm (2*(pow2 112 - pow2 57 + 1) + pow2 56 <= pow2 113); Math.Lemmas.lemma_div_lt_nat (v z1 + v c0) 113 56 } pow2 57; }; calc (<) { v c2; (<) { assert_norm (3*(pow2 112 - pow2 57 + 1) + pow2 57 <= pow2 114); Math.Lemmas.lemma_div_lt_nat (v z2 + v c1) 114 56 } pow2 58; }; calc (<=) { v c3; (<=) { assert_norm (4*(pow2 112 - pow2 57 + 1) + pow2 58 <= 31153781151208965410895007785680895); assert_norm (31153781151208965410895007785680895 / pow56 == 432345564227567610); Math.Lemmas.lemma_div_le (v z3 + v c2) 31153781151208965410895007785680895 (pow2 56) } 432345564227567610; }; calc (<=) { v c4; (<=) { assert_norm (5*(pow2 112 - pow2 57 + 1) + 432345564227567610 <= 25961484292674137854422105494388735); // (pow2 59 - 2) * pow56 assert_norm (25961484292674137854422105494388735 / pow56 == 360287970189639675); Math.Lemmas.lemma_div_le (v z4 + v c3) 25961484292674137854422105494388735 (pow2 56) } 360287970189639675; }; calc (<=) { v c5; (<=) { assert_norm (4*(pow2 112 - pow2 57 + 1) + 360287970189639675 <= 20769187434139310297949203203096575); Math.Lemmas.lemma_div_le (v z5 + v c4) 20769187434139310297949203203096575 (pow2 56); assert_norm (20769187434139310297949203203096575 / pow2 56 == pow2 58 - 4) } pow2 58 - 4; }; calc (<=) { v c6; (<=) { assert_norm (3*(pow2 112 - pow2 57 + 1) + pow2 58 - 4 <= 15576890575604482741476300911804415); Math.Lemmas.lemma_div_le (v z6 + v c5) 15576890575604482741476300911804415 (pow2 56); assert_norm (15576890575604482741476300911804415 / pow2 56 == 216172782113783805) } 216172782113783805; }; calc (<=) { v c7; (<=) { assert_norm (2*(pow2 112 - pow2 57 + 1) + 216172782113783805 <= 10384593717069655185003398620512255); // (pow2 57 - 1) * pow2 56 - 1 Math.Lemmas.lemma_div_le (v z7 + v c6) 10384593717069655185003398620512255 (pow2 56); assert_norm (10384593717069655185003398620512255 / pow2 56 == pow2 57 - 2) } pow2 57 - 2; }; calc (<) { v c8; (<) { Math.Lemmas.lemma_div_lt_nat (v z8 + v c7) 112 56 } pow2 56; }; assert_norm (pow2 56 < pow2 64); Math.Lemmas.small_mod (v c8) (pow2 64) in lemma_t9_fits(); calc (==) { wide_as_nat5 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) <: int; (==) { } v t0 + v t1 * pow56 + v t2 * pow112 + v t3 * pow168 + v t4 * pow224 + v t5 * pow280 + v t6 * pow336 + v t7 * pow392 + v t8 * pow448 + v t9 * pow504; (==) { assert_norm (pow2 61 < pow2 64); Math.Lemmas.small_mod (v c8) (pow2 64) } v z0 - v c0 * pow2 56 + (v z1 + v c0 - v c1 * pow2 56) * pow56 + (v z2 + v c1 - v c2 * pow2 56) * pow112 + (v z3 + v c2 - v c3 * pow2 56) * pow168 + (v z4 + v c3 - v c4 * pow2 56) * pow224 + (v z5 + v c4 - v c5 * pow2 56) * pow280 + (v z6 + v c5 - v c6 * pow2 56) * pow336 + (v z7 + v c6 - v c7 * pow2 56) * pow392 + (v z8 + v c7 - v c8 * pow2 56) * pow448 + v c8 * pow504; (==) { lemma_mult_distr_3 (v z1) (v c0) (v c1) 56; lemma_mult_distr_3 (v z2) (v c1) (v c2) 112; lemma_mult_distr_3 (v z3) (v c2) (v c3) 168; lemma_mult_distr_3 (v z4) (v c3) (v c4) 224; lemma_mult_distr_3 (v z5) (v c4) (v c5) 280; lemma_mult_distr_3 (v z6) (v c5) (v c6) 336; lemma_mult_distr_3 (v z7) (v c6) (v c7) 392; lemma_mult_distr_3 (v z8) (v c7) (v c8) 448 } v z0 + v z1 * pow56 + v z2 * pow112 + v z3 * pow168 + v z4 * pow224 + v z5 * pow280 + v z6 * pow336 + v z7 * pow392 + v z8 * pow448; (==) { calc (==) { v z1; (==) { } v x0 * v y1 + v x1 * v y0; }; calc (==) { v z2; (==) { } v x0 * v y2 + v x1 * v y1 + v x2 * v y0; }; calc (==) { v z3; (==) { } v x0 * v y3 + v x1 * v y2 + v x2 * v y1 + v x3 * v y0; }; calc (==) { v z4; (==) { } v x0 * v y4 + v x1 * v y3 + v x2 * v y2 + v x3 * v y1 + v x4 * v y0; }; calc (==) { v z5; (==) { } v x1 * v y4 + v x2 * v y3 + v x3 * v y2 + v x4 * v y1; }; calc (==) { v z6; (==) { } v x2 * v y4 + v x3 * v y3 + v x4 * v y2; }; calc (==) { v z7; (==) { } v x3 * v y4 + v x4 * v y3; }; calc (==) { v z8; (==) { } v x4 * v y4; } } v x0 * v y0 + (v x0 * v y1 + v x1 * v y0) * pow56 + (v x0 * v y2 + v x1 * v y1 + v x2 * v y0) * pow112 + (v x0 * v y3 + v x1 * v y2 + v x2 * v y1 + v x3 * v y0) * pow168 + (v x0 * v y4 + v x1 * v y3 + v x2 * v y2 + v x3 * v y1 + v x4 * v y0) * pow224 + (v x1 * v y4 + v x2 * v y3 + v x3 * v y2 + v x4 * v y1) * pow280 + (v x2 * v y4 + v x3 * v y3 + v x4 * v y2) * pow336 + (v x3 * v y4 + v x4 * v y3) * pow392 + (v x4 * v y4) * pow448; (==) { Lemmas.lemma_mul_qelem5 (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) } (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224) * (v y0 + v y1 * pow2 56 + v y2 * pow2 112 + v y3 * pow2 168 + v y4 * pow2 224); }; (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) inline_for_extraction noextract val low_mul_5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (as_nat5 x * as_nat5 y) % pow2 264) let low_mul_5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let xy00 = mul64_wide_5 x0 y0 in let xy01 = mul64_wide_5 x0 y1 in let xy02 = mul64_wide_5 x0 y2 in let xy03 = mul64_wide_5 x0 y3 in let xy04 = mul64_wide_5 x0 y4 in let xy10 = mul64_wide_5 x1 y0 in let xy11 = mul64_wide_5 x1 y1 in let xy12 = mul64_wide_5 x1 y2 in let xy13 = mul64_wide_5 x1 y3 in let xy20 = mul64_wide_5 x2 y0 in let xy21 = mul64_wide_5 x2 y1 in let xy22 = mul64_wide_5 x2 y2 in let xy30 = mul64_wide_5 x3 y0 in let xy31 = mul64_wide_5 x3 y1 in let xy40 = mul64_wide_5 x4 y0 in assert_norm (pow2 112 < pow2 117); let (c0, t0) = carry56_wide xy00 in let (c1, t1) = carry56_wide (add_inner_carry (add2 xy01 xy10) c0) in let (c2, t2) = carry56_wide (add_inner_carry (add3 xy02 xy11 xy20) c1) in let (c3, t3) = carry56_wide (add_inner_carry (add4 xy03 xy12 xy21 xy30) c2) in let t4 = to_u64 (add_inner_carry (add5 xy04 xy13 xy22 xy31 xy40) c3) &. mask40 in calc (==) { as_nat5 (t0, t1, t2, t3, t4) <: int; (==) { } v t0 + v t1 * pow56 + v t2 * pow112 + v t3 * pow168 + v t4 * pow224; (==) { } v xy00 - v c0 * pow2 56 + (v xy01 + v xy10 + v c0 - v c1 * pow2 56) * pow56 + (v xy02 + v xy11 + v xy20 + v c1 - v c2 * pow56) * pow112 + (v xy03 + v xy12 + v xy21 + v xy30 + v c2 - v c3 * pow56) * pow168 + v t4 * pow224; (==) { logand_mask (to_u64 (add_inner_carry (add5 xy04 xy13 xy22 xy31 xy40) c3)) mask40 40; Math.Lemmas.pow2_modulo_modulo_lemma_1 (v (add_inner_carry (add5 xy04 xy13 xy22 xy31 xy40) c3)) 40 64 } v x0 * v y0 + (v x0 * v y1 + v x1 * v y0) * pow56 + (v x0 * v y2 + v x1 * v y1 + v x2 * v y0) * pow112 + (v x0 * v y3 + v x1 * v y2 + v x2 * v y1 + v x3 * v y0 - v c3 * pow56) * pow168 + ((v x0 * v y4 + v x1 * v y3 + v x2 * v y2 + v x3 * v y1 + v x4 * v y0 + v c3) % pow2 40) * pow224; }; Lemmas.lemma_mul_5_low_264 (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4); (t0, t1, t2, t3, t4) inline_for_extraction noextract val div_2_24_step: x:uint64 -> y:uint64 -> Pure uint64 (requires v x < pow56 /\ v y < pow56) (ensures fun r -> v r < pow56 /\ v r == v x / pow2 24 + pow2 32 * (v y % pow2 24)) let div_2_24_step x y = let y' = (y &. u64 0xffffff) <<. 32ul in assert_norm (pow2 24 - 1 = 0xffffff); assert_norm (pow2 24 < pow2 64); mod_mask_lemma y 24ul; assert (v (mod_mask #U64 #SEC 24ul) == 0xffffff); assert (v (y &. u64 0xffffff) == v y % pow2 24); assert (v y' == (v y % pow2 24) * pow2 32); let x' = x >>. 24ul in FStar.Math.Lemmas.pow2_minus 56 24; assert (v x' < pow2 32); let z = x' |. y' in logor_disjoint x' y' 32; assert (v z == v x / pow2 24 + pow2 32 * (v y % pow2 24)); z inline_for_extraction noextract val div_248: x:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 x < pow2 512) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (wide_as_nat5 x) / pow2 248)
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.BignumQ.Mul.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 300, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Hacl.Spec.BignumQ.Definitions.qelem_wide5 -> Prims.Pure Hacl.Spec.BignumQ.Definitions.qelem5
Prims.Pure
[]
[]
[ "Hacl.Spec.BignumQ.Definitions.qelem_wide5", "Lib.IntTypes.uint64", "FStar.Pervasives.Native.Mktuple5", "Prims.unit", "Hacl.Spec.BignumQ.Lemmas.lemma_div248", "FStar.Pervasives.Native.Mktuple10", "Prims._assert", "Hacl.Spec.BignumQ.Definitions.qelem_fits5", "Prims.nat", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Hacl.Spec.BignumQ.Mul.div_2_24_step", "Hacl.Spec.BignumQ.Definitions.qelem5" ]
[]
false
false
false
false
false
let div_248 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) =
let z0 = div_2_24_step x4 x5 in let z1 = div_2_24_step x5 x6 in let z2 = div_2_24_step x6 x7 in let z3 = div_2_24_step x7 x8 in let z4 = div_2_24_step x8 x9 in assert (qelem_fits5 (z0, z1, z2, z3, z4) (1, 1, 1, 1, 1)); Lemmas.lemma_div248 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9); (z0, z1, z2, z3, z4)
false
Hacl.Impl.Curve25519.Finv.fst
Hacl.Impl.Curve25519.Finv.finv
val finv: #s:field_spec -> o:felem s -> i:felem s -> tmp:felem_wide2 s -> Stack unit (requires fun h0 -> live h0 o /\ live h0 i /\ live h0 tmp /\ disjoint o i /\ disjoint i tmp /\ (disjoint o tmp) /\ fsquare_times_inv h0 i) (ensures fun h0 _ h1 -> modifies (loc o |+| loc tmp) h0 h1 /\ fsquare_times_inv h1 o /\ feval h1 o == P.fpow (feval #s h0 i) (pow2 255 - 21))
val finv: #s:field_spec -> o:felem s -> i:felem s -> tmp:felem_wide2 s -> Stack unit (requires fun h0 -> live h0 o /\ live h0 i /\ live h0 tmp /\ disjoint o i /\ disjoint i tmp /\ (disjoint o tmp) /\ fsquare_times_inv h0 i) (ensures fun h0 _ h1 -> modifies (loc o |+| loc tmp) h0 h1 /\ fsquare_times_inv h1 o /\ feval h1 o == P.fpow (feval #s h0 i) (pow2 255 - 21))
let finv #s o i tmp = push_frame(); let t1 = create (4ul *! nlimb s) (limb_zero s) in let h0 = ST.get () in finv0 #s i t1 tmp; let a : felem s = sub t1 0ul (nlimb s) in let t0 : felem s = sub t1 (3ul *! nlimb s) (nlimb s) in (* 2^255 - 21 *) fmul_s #s o t0 a tmp; let h1 = ST.get () in assert (feval h1 o == S.finv (feval h0 i)); pop_frame()
{ "file_name": "code/curve25519/Hacl.Impl.Curve25519.Finv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 314, "start_col": 0, "start_line": 304 }
module Hacl.Impl.Curve25519.Finv open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Curve25519.Fields module ST = FStar.HyperStack.ST module C = Hacl.Impl.Curve25519.Fields.Core module S = Hacl.Spec.Curve25519.Finv module P = Spec.Curve25519 let _: squash (inversion field_spec) = allow_inversion field_spec #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --record_options" noextract val fsquare_times_inv: #s:field_spec -> h:mem -> f:felem s -> Type0 let fsquare_times_inv #s h f = match s with | M51 -> C.f51_felem_fits h f (1, 2, 1, 1, 1) | M64 -> True val fsqr_s: #s:field_spec -> out:felem s -> f1:felem s -> tmp:felem_wide s -> Stack unit (requires fun h -> live h out /\ live h f1 /\ live h tmp /\ (disjoint out f1 \/ out == f1) /\ (disjoint out tmp) /\ disjoint tmp f1 /\ fsquare_times_inv h f1) (ensures fun h0 _ h1 -> modifies (loc out |+| loc tmp) h0 h1 /\ fsquare_times_inv h1 out /\ feval h1 out == P.fmul (feval h0 f1) (feval h0 f1)) [@ Meta.Attribute.inline_ ] let fsqr_s #s out f1 tmp = C.fsqr #s out f1 tmp noextract val fmuls_pre: #s:field_spec -> h:mem -> f1:felem s -> f2:felem s -> Type0 let fmuls_pre #s h f1 f2 = match s with | M51 -> f51_felem_fits h f1 (1, 2, 1, 1, 1) /\ f51_felem_fits h f2 (1, 2, 1, 1, 1) | M64 -> True val fmul_s: #s:field_spec -> out:felem s -> f1:felem s -> f2:felem s -> tmp:felem_wide2 s -> Stack unit (requires fun h -> live h out /\ live h f1 /\ live h f2 /\ live h tmp /\ (disjoint out f1 \/ out == f1) /\ (disjoint out f2 \/ out == f2) /\ (disjoint out tmp) /\ (disjoint f1 f2 \/ f1 == f2) /\ disjoint f1 tmp /\ disjoint f2 tmp /\ fmuls_pre h f1 f2) (ensures fun h0 _ h1 -> modifies (loc out |+| loc tmp) h0 h1 /\ fsquare_times_inv h1 out /\ feval h1 out == P.fmul (feval h0 f1) (feval h0 f2)) [@ Meta.Attribute.inline_ ] let fmul_s #s out f1 f2 tmp = C.fmul #s out f1 f2 tmp val fsquare_times: #s:field_spec -> o:felem s -> i:felem s -> tmp:felem_wide s -> n:size_t{v n > 0} -> Stack unit (requires fun h0 -> live h0 o /\ live h0 i /\ live h0 tmp /\ (disjoint o i \/ o == i) /\ disjoint o tmp /\ disjoint tmp i /\ fsquare_times_inv h0 i) (ensures fun h0 _ h1 -> modifies (loc o |+| loc tmp) h0 h1 /\ fsquare_times_inv h1 o /\ feval h1 o == S.pow (feval #s h0 i) (pow2 (v n))) [@ Meta.Attribute.specialize ] let fsquare_times #s o inp tmp n = let h0 = ST.get() in fsqr_s #s o inp tmp; S.lemma_pow_one (feval h0 inp); S.lemma_pow_add (feval h0 inp) 1 1; assert_norm (pow2 1 = 2); let inv (h:mem) (i:nat{i < v n}) = modifies (loc o |+| loc tmp) h0 h /\ fsquare_times_inv #s h o /\ feval h o == S.pow (feval #s h0 inp) (pow2 (i + 1)) in let h1 = ST.get () in assert (inv h1 0); Lib.Loops.for 0ul (n -! 1ul) inv (fun i -> let h2 = ST.get () in fsqr_s #s o o tmp; S.lemma_pow_add (feval #s h0 inp) (pow2 (v i + 1)) (pow2 (v i + 1)); Math.Lemmas.pow2_double_sum (v i + 1)) val finv1: #s:field_spec -> i:felem s -> t1:lbuffer (limb s) (4ul *! nlimb s) -> tmp:felem_wide2 s -> Stack unit (requires fun h0 -> live h0 i /\ live h0 t1 /\ live h0 tmp /\ disjoint i t1 /\ disjoint i tmp /\ disjoint t1 tmp /\ fsquare_times_inv h0 i) (ensures fun h0 _ h1 -> modifies (loc t1 |+| loc tmp) h0 h1 /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in let a = S.fsquare_times (feval h0 i) 1 in let t0 = S.fsquare_times a 2 in let b = P.fmul t0 (feval h0 i) in let a = P.fmul b a in let t0 = S.fsquare_times a 1 in let b = P.fmul t0 b in let t0 = S.fsquare_times b 5 in let b = P.fmul t0 b in feval h1 as0 == a /\ fsquare_times_inv h1 as0 /\ feval h1 bs == b /\ fsquare_times_inv h1 bs)) [@ Meta.Attribute.inline_ ] let finv1 #s i t1 tmp = let h0 = ST.get () in let a : felem s = sub t1 0ul (nlimb s) in let b : felem s = sub t1 (nlimb s) (nlimb s) in let c : felem s = sub t1 (2ul *! nlimb s) (nlimb s) in let t0 : felem s = sub t1 (3ul *! nlimb s) (nlimb s) in let tmp1 : felem_wide s = sub tmp 0ul (nwide s) in (* 2 *) fsquare_times #s a i tmp1 1ul; (* 8 *) fsquare_times #s t0 a tmp1 2ul; (* 9 *) fmul_s #s b t0 i tmp; (* 11 *) fmul_s #s a b a tmp; (* 22 *) fsquare_times #s t0 a tmp1 1ul; (* 2^5 - 2^0 = 31 *) fmul_s #s b t0 b tmp; (* 2^10 - 2^5 *) fsquare_times #s t0 b tmp1 5ul; (* 2^10 - 2^0 *) fmul_s #s b t0 b tmp val finv2: #s:field_spec -> t1:lbuffer (limb s) (4ul *! nlimb s) -> tmp:felem_wide2 s -> Stack unit (requires fun h0 -> live h0 t1 /\ live h0 tmp /\ disjoint t1 tmp /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in fsquare_times_inv h0 as0 /\ fsquare_times_inv h0 bs)) (ensures fun h0 _ h1 -> modifies (loc t1 |+| loc tmp) h0 h1 /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in let cs : felem s = gsub t1 (2ul *! nlimb s) (nlimb s) in let t0 = S.fsquare_times (feval h0 bs) 10 in let c = P.fmul t0 (feval h0 bs) in let t0 = S.fsquare_times c 20 in let t0 = P.fmul t0 c in let t0 = S.fsquare_times t0 10 in let b = P.fmul t0 (feval h0 bs) in let t0 = S.fsquare_times b 50 in let c = P.fmul t0 b in feval h1 as0 == feval h0 as0 /\ fsquare_times_inv h1 as0 /\ feval h1 bs == b /\ fsquare_times_inv h1 bs /\ feval h1 cs == c /\ fsquare_times_inv h1 cs)) [@ Meta.Attribute.inline_ ] let finv2 #s t1 tmp = let h0 = ST.get () in let a : felem s = sub t1 0ul (nlimb s) in let b : felem s = sub t1 (nlimb s) (nlimb s) in let c : felem s = sub t1 (2ul *! nlimb s) (nlimb s) in let t0 : felem s = sub t1 (3ul *! nlimb s) (nlimb s) in let tmp1 : felem_wide s = sub tmp 0ul (nwide s) in (* 2^20 - 2^10 *) fsquare_times #s t0 b tmp1 10ul; (* 2^20 - 2^0 *) fmul_s #s c t0 b tmp; (* 2^40 - 2^20 *) fsquare_times #s t0 c tmp1 20ul; (* 2^40 - 2^0 *) fmul_s #s t0 t0 c tmp; (* 2^50 - 2^10 *) fsquare_times #s t0 t0 tmp1 10ul; (* 2^50 - 2^0 *) fmul_s #s b t0 b tmp; (* 2^100 - 2^50 *) fsquare_times #s t0 b tmp1 50ul; (* 2^100 - 2^0 *) fmul_s #s c t0 b tmp val finv3: #s:field_spec -> t1:lbuffer (limb s) (4ul *! nlimb s) -> tmp:felem_wide2 s -> Stack unit (requires fun h0 -> live h0 t1 /\ live h0 tmp /\ disjoint t1 tmp /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in let cs : felem s = gsub t1 (2ul *! nlimb s) (nlimb s) in fsquare_times_inv h0 as0 /\ fsquare_times_inv h0 bs /\ fsquare_times_inv h0 cs)) (ensures fun h0 _ h1 -> modifies (loc t1 |+| loc tmp) h0 h1 /\ (let as0 : felem s = gsub t1 0ul (nlimb s) in let bs : felem s = gsub t1 (nlimb s) (nlimb s) in let cs : felem s = gsub t1 (2ul *! nlimb s) (nlimb s) in let ts0 : felem s = gsub t1 (3ul *! nlimb s) (nlimb s) in let t0 = S.fsquare_times (feval h0 cs) 100 in let t0 = P.fmul t0 (feval h0 cs) in let t0 = S.fsquare_times t0 50 in let t0 = P.fmul t0 (feval h0 bs) in let t0 = S.fsquare_times t0 5 in feval h1 as0 == feval h0 as0 /\ fsquare_times_inv h1 as0 /\ feval h1 ts0 == t0 /\ fsquare_times_inv h1 ts0)) [@ Meta.Attribute.inline_ ] let finv3 #s t1 tmp = let h0 = ST.get () in let a : felem s = sub t1 0ul (nlimb s) in let b : felem s = sub t1 (nlimb s) (nlimb s) in let c : felem s = sub t1 (2ul *! nlimb s) (nlimb s) in let t0 : felem s = sub t1 (3ul *! nlimb s) (nlimb s) in let tmp1 : felem_wide s = sub tmp 0ul (nwide s) in (* 2^200 - 2^100 *) fsquare_times #s t0 c tmp1 100ul; (* 2^200 - 2^0 *) fmul_s #s t0 t0 c tmp; (* 2^250 - 2^50 *) fsquare_times #s t0 t0 tmp1 50ul; (* 2^250 - 2^0 *) fmul_s #s t0 t0 b tmp; (* 2^255 - 2^5 *) fsquare_times #s t0 t0 tmp1 5ul val finv0: #s:field_spec -> i:felem s -> t1:lbuffer (limb s) (4ul *! nlimb s) -> tmp:felem_wide2 s -> Stack unit (requires fun h0 -> live h0 i /\ live h0 t1 /\ live h0 tmp /\ disjoint i t1 /\ disjoint i tmp /\ disjoint t1 tmp /\ fsquare_times_inv h0 i) (ensures fun h0 _ h1 -> modifies (loc t1 |+| loc tmp) h0 h1 /\ (let a_s, t0_s = S.finv0 (feval h0 i) in let a = gsub t1 0ul (nlimb s) in let t0 = gsub t1 (3ul *! nlimb s) (nlimb s) in fsquare_times_inv h1 a /\ fsquare_times_inv h1 t0 /\ (feval h1 a, feval h1 t0) == (a_s, t0_s))) [@ Meta.Attribute.inline_ ] let finv0 #s i t1 tmp = let h0 = ST.get () in let a : felem s = sub t1 0ul (nlimb s) in let b : felem s = sub t1 (nlimb s) (nlimb s) in let c : felem s = sub t1 (2ul *! nlimb s) (nlimb s) in let t0 : felem s = sub t1 (3ul *! nlimb s) (nlimb s) in finv1 #s i t1 tmp; finv2 #s t1 tmp; finv3 #s t1 tmp; let h1 = ST.get () in assert (fsquare_times_inv h1 t0); assert (fsquare_times_inv h1 a); assert (modifies (loc t1 |+| loc tmp) h0 h1); assert ( (feval h1 a, feval h1 t0) == S.finv0 (feval h0 i)) val finv: #s:field_spec -> o:felem s -> i:felem s -> tmp:felem_wide2 s -> Stack unit (requires fun h0 -> live h0 o /\ live h0 i /\ live h0 tmp /\ disjoint o i /\ disjoint i tmp /\ (disjoint o tmp) /\ fsquare_times_inv h0 i) (ensures fun h0 _ h1 -> modifies (loc o |+| loc tmp) h0 h1 /\ fsquare_times_inv h1 o /\ feval h1 o == P.fpow (feval #s h0 i) (pow2 255 - 21))
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Loops.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Finv.fst.checked", "Hacl.Impl.Curve25519.Fields.Core.fsti.checked", "Hacl.Impl.Curve25519.Fields.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Curve25519.Finv.fst" }
[ { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "P" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Finv", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Fields.Core", "short_module": "C" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 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
o: Hacl.Impl.Curve25519.Fields.Core.felem s -> i: Hacl.Impl.Curve25519.Fields.Core.felem s -> tmp: Hacl.Impl.Curve25519.Fields.Core.felem_wide2 s -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Curve25519.Fields.Core.field_spec", "Hacl.Impl.Curve25519.Fields.Core.felem", "Hacl.Impl.Curve25519.Fields.Core.felem_wide2", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Prims._assert", "Prims.eq2", "Spec.Curve25519.elem", "Hacl.Impl.Curve25519.Fields.Core.feval", "Hacl.Spec.Curve25519.Finv.finv", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.Impl.Curve25519.Finv.fmul_s", "Lib.Buffer.sub", "Lib.Buffer.MUT", "Hacl.Impl.Curve25519.Fields.Core.limb", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "FStar.UInt32.__uint_to_t", "Hacl.Impl.Curve25519.Fields.Core.nlimb", "Lib.Buffer.lbuffer_t", "Hacl.Impl.Curve25519.Finv.finv0", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.mul", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "Hacl.Impl.Curve25519.Fields.Core.limb_zero", "Lib.Buffer.lbuffer", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let finv #s o i tmp =
push_frame (); let t1 = create (4ul *! nlimb s) (limb_zero s) in let h0 = ST.get () in finv0 #s i t1 tmp; let a:felem s = sub t1 0ul (nlimb s) in let t0:felem s = sub t1 (3ul *! nlimb s) (nlimb s) in fmul_s #s o t0 a tmp; let h1 = ST.get () in assert (feval h1 o == S.finv (feval h0 i)); pop_frame ()
false
Hacl.Spec.BignumQ.Mul.fst
Hacl.Spec.BignumQ.Mul.div_2_24_step
val div_2_24_step: x:uint64 -> y:uint64 -> Pure uint64 (requires v x < pow56 /\ v y < pow56) (ensures fun r -> v r < pow56 /\ v r == v x / pow2 24 + pow2 32 * (v y % pow2 24))
val div_2_24_step: x:uint64 -> y:uint64 -> Pure uint64 (requires v x < pow56 /\ v y < pow56) (ensures fun r -> v r < pow56 /\ v r == v x / pow2 24 + pow2 32 * (v y % pow2 24))
let div_2_24_step x y = let y' = (y &. u64 0xffffff) <<. 32ul in assert_norm (pow2 24 - 1 = 0xffffff); assert_norm (pow2 24 < pow2 64); mod_mask_lemma y 24ul; assert (v (mod_mask #U64 #SEC 24ul) == 0xffffff); assert (v (y &. u64 0xffffff) == v y % pow2 24); assert (v y' == (v y % pow2 24) * pow2 32); let x' = x >>. 24ul in FStar.Math.Lemmas.pow2_minus 56 24; assert (v x' < pow2 32); let z = x' |. y' in logor_disjoint x' y' 32; assert (v z == v x / pow2 24 + pow2 32 * (v y % pow2 24)); z
{ "file_name": "code/ed25519/Hacl.Spec.BignumQ.Mul.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 652, "start_col": 0, "start_line": 638 }
module Hacl.Spec.BignumQ.Mul open FStar.Mul open Lib.IntTypes module S = Spec.Ed25519 module Lemmas = Hacl.Spec.BignumQ.Lemmas include Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask56 : x:uint64{v x == pow2 56 - 1} = assert_norm (pow2 56 - 1 == 0xffffffffffffff); u64 0xffffffffffffff inline_for_extraction noextract let mask40 : x:uint64{v x == pow2 40 - 1} = assert_norm (pow2 40 - 1 == 0xffffffffff); u64 0xffffffffff inline_for_extraction noextract val make_m: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == S.q} let make_m () = let m0 = u64 0x12631a5cf5d3ed in let m1 = u64 0xf9dea2f79cd658 in let m2 = u64 0x000000000014de in let m3 = u64 0x00000000000000 in let m4 = u64 0x00000010000000 in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val make_mu: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == pow2 512 / S.q} let make_mu m = let m0 = u64 0x9ce5a30a2c131b in let m1 = u64 0x215d086329a7ed in let m2 = u64 0xffffffffeb2106 in let m3 = u64 0xffffffffffffff in let m4 = u64 0x00000fffffffff in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == pow2 512 / S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val choose: b:uint64 -> x:qelem5 -> y:qelem5 -> Pure qelem5 (requires v b == 0 \/ v b == 1) (ensures fun z -> if v b = 1 then z == x else z == y) let choose b (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let mask = b -. u64 1 in let z0 = x0 ^. (mask &. (x0 ^. y0)) in Lemmas.lemma_choose_step b x0 y0; let z1 = x1 ^. (mask &. (x1 ^. y1)) in Lemmas.lemma_choose_step b x1 y1; let z2 = x2 ^. (mask &. (x2 ^. y2)) in Lemmas.lemma_choose_step b x2 y2; let z3 = x3 ^. (mask &. (x3 ^. y3)) in Lemmas.lemma_choose_step b x3 y3; let z4 = x4 ^. (mask &. (x4 ^. y4)) in Lemmas.lemma_choose_step b x4 y4; (z0, z1, z2, z3, z4) inline_for_extraction noextract val subm_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow56 /\ v y <= pow56) (ensures fun (b, t) -> v b <= 1 /\ qelem_fits1 t 1 /\ v x - v y == v t - v b * pow56) let subm_step x y = let b = (x -. y) >>. 63ul in //assert (if v x >= v y then v b == 0 else v b == 1); let lshift56 = (b <<. 56ul) in //assert (if v x >= v y then v lshift56 == 0 else v lshift56 == pow56); //assert (v lshift56 == v b * pow56); //assert (v ((b <<. 56ul) +! x) == v b * pow56 + v x); let t = ((b <<. 56ul) +! x) -! y in b, t inline_for_extraction noextract val subm_conditional: x:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ (if as_nat5 x >= S.q then as_nat5 r == as_nat5 x - S.q else as_nat5 r == as_nat5 x)) let subm_conditional (x0, x1, x2, x3, x4) = let (y0, y1, y2, y3, y4) = make_m () in let (b0, t0) = subm_step x0 y0 in assert (v x0 - v y0 == v t0 - v b0 * pow56); let (b1, t1) = subm_step x1 (y1 +! b0) in assert (v x1 - v y1 - v b0 == v t1 - v b1 * pow56); let (b2, t2) = subm_step x2 (y2 +! b1) in assert (v x2 - v y2 - v b1 == v t2 - v b2 * pow56); let (b3, t3) = subm_step x3 (y3 +! b2) in assert (v x3 - v y3 - v b2 == v t3 - v b3 * pow56); let (b4, t4) = subm_step x4 (y4 +! b3) in assert (v x4 - v y4 - v b3 == v t4 - v b4 * pow56); Lemmas.lemma_subm_conditional (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) (v b0) (v b1) (v b2) (v b3) (v b4); assert ( as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow56 * pow224 == as_nat5 (x0, x1, x2, x3, x4) - as_nat5 (y0, y1, y2, y3, y4)); //assert_norm (pow56 * pow224 = pow2 280); //assert (as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow2 280 == as_nat5 (x0, x1, x2, x3, x4) - S.q); Lemmas.lemma_as_nat5 (x0, x1, x2, x3, x4); Lemmas.lemma_as_nat5 (t0, t1, t2, t3, t4); //assert (if v b4 = 0 then as_nat5 (x0, x1, x2, x3, x4) >= S.q else as_nat5 (x0, x1, x2, x3, x4) < S.q); assert (if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 else v b4 == 1); let (z0, z1, z2, z3, z4) = choose b4 (x0, x1, x2, x3, x4) (t0, t1, t2, t3, t4) in assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else v b4 == 1 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); (z0, z1, z2, z3, z4) inline_for_extraction noextract val carry56: x:uint64 -> Pure (uint64 & uint64) (requires v x <= pow2 57) (ensures fun (t, c) -> v t < pow56 /\ v c <= 2 /\ v x == v c * pow56 + v t) let carry56 x = let carry = x >>. 56ul in FStar.Math.Lemmas.pow2_minus 57 56; let t = x &. mask56 in assert_norm (pow2 56 < pow2 64); mod_mask_lemma x 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); t, carry inline_for_extraction noextract val add_modq5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < S.q /\ as_nat5 y < S.q) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (as_nat5 x + as_nat5 y) % S.q) let add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = assert_norm (pow56 - 1 + pow56 - 1 == pow2 57 - 2); let (t0, c0) = carry56 (x0 +! y0) in let (t1, c1) = carry56 (x1 +! y1 +! c0) in let (t2, c2) = carry56 (x2 +! y2 +! c1) in let (t3, c3) = carry56 (x3 +! y3 +! c2) in let t4 = x4 +! y4 +! c3 in assert (as_nat5 (t0, t1, t2, t3, t4) == as_nat5 (x0, x1, x2, x3, x4) + as_nat5 (y0, y1, y2, y3, y4)); let (o0, o1, o2, o3, o4) = subm_conditional (t0, t1, t2, t3, t4) in Lemmas.lemma_add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) (t0, t1, t2, t3, t4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry56_wide: x:uint128 -> Pure (uint128 & uint64) (requires v x < pow2 117) (ensures fun (c, t) -> v t < pow56 /\ v c < pow2 61 /\ v x - v c * pow56 == v t /\ v c == v x / pow56) let carry56_wide x = let carry = x >>. 56ul in let t = to_u64 x &. mask56 in assert_norm (pow2 56 < pow2 64); Math.Lemmas.lemma_div_lt_nat (v x) 117 56; mod_mask_lemma (to_u64 x) 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == (v x % pow2 64) % pow2 56); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v x) 56 64; assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); carry, t inline_for_extraction noextract val mul64_wide_5: (a:uint64) -> (b:uint64) -> Pure uint128 (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures fun z -> v z == v a * v b /\ v z <= pow2 112 - pow2 57 + 1 /\ v z < pow2 112) let mul64_wide_5 a b = let lemma_smaller (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) < pow2 112) = if v a = 0 || v b = 0 then () else calc (<) { v a * v b <: int; (<) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56) } v a * pow2 56; (<) { Math.Lemmas.lemma_mult_le_right (pow2 56) (v a) (pow2 56) } pow2 56 * pow2 56; (==) { assert_norm (pow2 56 * pow2 56 == pow2 112) } pow2 112; } in let lemma_le (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) <= pow2 112 - pow2 57 + 1) = if v a = 0 || v b = 0 then () else assert_norm (pow2 112 - pow2 57 + 1 >= 0); calc (<=) { v a * v b <: int; (<=) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56 - 1) } v a * (pow2 56 - 1); (<=) { Math.Lemmas.lemma_mult_le_right (pow2 56 - 1) (v a) (pow2 56 - 1) } (pow2 56 - 1) * (pow2 56 - 1); (==) { assert_norm ((pow2 56 - 1) * (pow2 56 - 1) == pow2 112 - pow2 57 + 1) } pow2 112 - pow2 57 + 1; } in lemma_le a b; lemma_smaller a b; mul64_wide a b inline_for_extraction noextract val add2: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112) (ensures fun z -> v z == v a + v b /\ v z <= pow2 116) let add2 a b = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b inline_for_extraction noextract val add3: (a:uint128) -> (b:uint128) -> (c:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 ) (ensures fun z -> v z == v a + v b + v c /\ v z <= pow2 116) let add3 a b c = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); a +. b +. c inline_for_extraction noextract val add4: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d /\ v z <= pow2 116) let add4 a b c d = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d) (pow2 128); a +. b +. c +. d inline_for_extraction noextract val add5: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> (e:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112 /\ v e < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d + v e/\ v z <= pow2 116) let add5 a b c d e = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d + v e) (pow2 128); a +. b +. c +. d +. e inline_for_extraction noextract val add_inner_carry: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a <= pow2 116 /\ v b < pow2 61) (ensures fun z -> v z == v a + v b /\ v z < pow2 117) let add_inner_carry a b = assert_norm (pow2 116 + pow2 61 < pow2 128); assert_norm (pow2 116 + pow2 61 < pow2 117); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b inline_for_extraction noextract val mul_5: x:qelem5 -> y:qelem5 -> Pure qelem_wide5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1)) (ensures fun r -> qelem_wide_fits5 r (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 r == as_nat5 x * as_nat5 y) let lemma_mult_distr_3 (a b c:nat) (n:nat) : Lemma ((a + b - c * pow2 56) * pow2 n == a * pow2 n + b * pow2 n - c * pow2 (n + 56)) = Math.Lemmas.distributivity_sub_left (a + b) (c * pow2 56) (pow2 n); Math.Lemmas.distributivity_add_left a b (pow2 n); Math.Lemmas.pow2_plus 56 n #set-options "--z3rlimit 300" let mul_5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let xy00 = mul64_wide_5 x0 y0 in let xy01 = mul64_wide_5 x0 y1 in let xy02 = mul64_wide_5 x0 y2 in let xy03 = mul64_wide_5 x0 y3 in let xy04 = mul64_wide_5 x0 y4 in let xy10 = mul64_wide_5 x1 y0 in let xy11 = mul64_wide_5 x1 y1 in let xy12 = mul64_wide_5 x1 y2 in let xy13 = mul64_wide_5 x1 y3 in let xy14 = mul64_wide_5 x1 y4 in let xy20 = mul64_wide_5 x2 y0 in let xy21 = mul64_wide_5 x2 y1 in let xy22 = mul64_wide_5 x2 y2 in let xy23 = mul64_wide_5 x2 y3 in let xy24 = mul64_wide_5 x2 y4 in let xy30 = mul64_wide_5 x3 y0 in let xy31 = mul64_wide_5 x3 y1 in let xy32 = mul64_wide_5 x3 y2 in let xy33 = mul64_wide_5 x3 y3 in let xy34 = mul64_wide_5 x3 y4 in let xy40 = mul64_wide_5 x4 y0 in let xy41 = mul64_wide_5 x4 y1 in let xy42 = mul64_wide_5 x4 y2 in let xy43 = mul64_wide_5 x4 y3 in let xy44 = mul64_wide_5 x4 y4 in let z0 = xy00 in // < pow2 112 let z1 = add2 xy01 xy10 in // < pow2 113 let z2 = add3 xy02 xy11 xy20 in // < pow2 114 let z3 = add4 xy03 xy12 xy21 xy30 in // < pow2 115 let z4 = add5 xy04 xy13 xy22 xy31 xy40 in // < pow2 116 let z5 = add4 xy14 xy23 xy32 xy41 in let z6 = add3 xy24 xy33 xy42 in let z7 = add2 xy34 xy43 in let z8 = xy44 in //(z0, z1, z2, z3, z4, z5, z6, z7, z8) assert_norm (pow2 112 < pow2 117); assert_norm (pow2 112 <= pow2 116); let (c0, t0) = carry56_wide z0 in let (c1, t1) = carry56_wide (add_inner_carry z1 c0) in let (c2, t2) = carry56_wide (add_inner_carry z2 c1) in let (c3, t3) = carry56_wide (add_inner_carry z3 c2) in let (c4, t4) = carry56_wide (add_inner_carry z4 c3) in let (c5, t5) = carry56_wide (add_inner_carry z5 c4) in let (c6, t6) = carry56_wide (add_inner_carry z6 c5) in let (c7, t7) = carry56_wide (add_inner_carry z7 c6) in let (c8, t8) = carry56_wide (add_inner_carry z8 c7) in let t9 = to_u64 c8 in let lemma_t9_fits () : Lemma (v t9 < pow2 56) = // This proof was built from the bottom. We have as a constraint that v c8 has to be < pow2 112 to satisfy the postcondition. // We compute each time the maximal value such that this postcondition is satisfied calc (<) { v c0; (<) { Math.Lemmas.lemma_div_lt_nat (v z0) 112 56 } pow2 56; }; calc (<) { v c1; (<) { assert_norm (2*(pow2 112 - pow2 57 + 1) + pow2 56 <= pow2 113); Math.Lemmas.lemma_div_lt_nat (v z1 + v c0) 113 56 } pow2 57; }; calc (<) { v c2; (<) { assert_norm (3*(pow2 112 - pow2 57 + 1) + pow2 57 <= pow2 114); Math.Lemmas.lemma_div_lt_nat (v z2 + v c1) 114 56 } pow2 58; }; calc (<=) { v c3; (<=) { assert_norm (4*(pow2 112 - pow2 57 + 1) + pow2 58 <= 31153781151208965410895007785680895); assert_norm (31153781151208965410895007785680895 / pow56 == 432345564227567610); Math.Lemmas.lemma_div_le (v z3 + v c2) 31153781151208965410895007785680895 (pow2 56) } 432345564227567610; }; calc (<=) { v c4; (<=) { assert_norm (5*(pow2 112 - pow2 57 + 1) + 432345564227567610 <= 25961484292674137854422105494388735); // (pow2 59 - 2) * pow56 assert_norm (25961484292674137854422105494388735 / pow56 == 360287970189639675); Math.Lemmas.lemma_div_le (v z4 + v c3) 25961484292674137854422105494388735 (pow2 56) } 360287970189639675; }; calc (<=) { v c5; (<=) { assert_norm (4*(pow2 112 - pow2 57 + 1) + 360287970189639675 <= 20769187434139310297949203203096575); Math.Lemmas.lemma_div_le (v z5 + v c4) 20769187434139310297949203203096575 (pow2 56); assert_norm (20769187434139310297949203203096575 / pow2 56 == pow2 58 - 4) } pow2 58 - 4; }; calc (<=) { v c6; (<=) { assert_norm (3*(pow2 112 - pow2 57 + 1) + pow2 58 - 4 <= 15576890575604482741476300911804415); Math.Lemmas.lemma_div_le (v z6 + v c5) 15576890575604482741476300911804415 (pow2 56); assert_norm (15576890575604482741476300911804415 / pow2 56 == 216172782113783805) } 216172782113783805; }; calc (<=) { v c7; (<=) { assert_norm (2*(pow2 112 - pow2 57 + 1) + 216172782113783805 <= 10384593717069655185003398620512255); // (pow2 57 - 1) * pow2 56 - 1 Math.Lemmas.lemma_div_le (v z7 + v c6) 10384593717069655185003398620512255 (pow2 56); assert_norm (10384593717069655185003398620512255 / pow2 56 == pow2 57 - 2) } pow2 57 - 2; }; calc (<) { v c8; (<) { Math.Lemmas.lemma_div_lt_nat (v z8 + v c7) 112 56 } pow2 56; }; assert_norm (pow2 56 < pow2 64); Math.Lemmas.small_mod (v c8) (pow2 64) in lemma_t9_fits(); calc (==) { wide_as_nat5 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) <: int; (==) { } v t0 + v t1 * pow56 + v t2 * pow112 + v t3 * pow168 + v t4 * pow224 + v t5 * pow280 + v t6 * pow336 + v t7 * pow392 + v t8 * pow448 + v t9 * pow504; (==) { assert_norm (pow2 61 < pow2 64); Math.Lemmas.small_mod (v c8) (pow2 64) } v z0 - v c0 * pow2 56 + (v z1 + v c0 - v c1 * pow2 56) * pow56 + (v z2 + v c1 - v c2 * pow2 56) * pow112 + (v z3 + v c2 - v c3 * pow2 56) * pow168 + (v z4 + v c3 - v c4 * pow2 56) * pow224 + (v z5 + v c4 - v c5 * pow2 56) * pow280 + (v z6 + v c5 - v c6 * pow2 56) * pow336 + (v z7 + v c6 - v c7 * pow2 56) * pow392 + (v z8 + v c7 - v c8 * pow2 56) * pow448 + v c8 * pow504; (==) { lemma_mult_distr_3 (v z1) (v c0) (v c1) 56; lemma_mult_distr_3 (v z2) (v c1) (v c2) 112; lemma_mult_distr_3 (v z3) (v c2) (v c3) 168; lemma_mult_distr_3 (v z4) (v c3) (v c4) 224; lemma_mult_distr_3 (v z5) (v c4) (v c5) 280; lemma_mult_distr_3 (v z6) (v c5) (v c6) 336; lemma_mult_distr_3 (v z7) (v c6) (v c7) 392; lemma_mult_distr_3 (v z8) (v c7) (v c8) 448 } v z0 + v z1 * pow56 + v z2 * pow112 + v z3 * pow168 + v z4 * pow224 + v z5 * pow280 + v z6 * pow336 + v z7 * pow392 + v z8 * pow448; (==) { calc (==) { v z1; (==) { } v x0 * v y1 + v x1 * v y0; }; calc (==) { v z2; (==) { } v x0 * v y2 + v x1 * v y1 + v x2 * v y0; }; calc (==) { v z3; (==) { } v x0 * v y3 + v x1 * v y2 + v x2 * v y1 + v x3 * v y0; }; calc (==) { v z4; (==) { } v x0 * v y4 + v x1 * v y3 + v x2 * v y2 + v x3 * v y1 + v x4 * v y0; }; calc (==) { v z5; (==) { } v x1 * v y4 + v x2 * v y3 + v x3 * v y2 + v x4 * v y1; }; calc (==) { v z6; (==) { } v x2 * v y4 + v x3 * v y3 + v x4 * v y2; }; calc (==) { v z7; (==) { } v x3 * v y4 + v x4 * v y3; }; calc (==) { v z8; (==) { } v x4 * v y4; } } v x0 * v y0 + (v x0 * v y1 + v x1 * v y0) * pow56 + (v x0 * v y2 + v x1 * v y1 + v x2 * v y0) * pow112 + (v x0 * v y3 + v x1 * v y2 + v x2 * v y1 + v x3 * v y0) * pow168 + (v x0 * v y4 + v x1 * v y3 + v x2 * v y2 + v x3 * v y1 + v x4 * v y0) * pow224 + (v x1 * v y4 + v x2 * v y3 + v x3 * v y2 + v x4 * v y1) * pow280 + (v x2 * v y4 + v x3 * v y3 + v x4 * v y2) * pow336 + (v x3 * v y4 + v x4 * v y3) * pow392 + (v x4 * v y4) * pow448; (==) { Lemmas.lemma_mul_qelem5 (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) } (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224) * (v y0 + v y1 * pow2 56 + v y2 * pow2 112 + v y3 * pow2 168 + v y4 * pow2 224); }; (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) inline_for_extraction noextract val low_mul_5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (as_nat5 x * as_nat5 y) % pow2 264) let low_mul_5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let xy00 = mul64_wide_5 x0 y0 in let xy01 = mul64_wide_5 x0 y1 in let xy02 = mul64_wide_5 x0 y2 in let xy03 = mul64_wide_5 x0 y3 in let xy04 = mul64_wide_5 x0 y4 in let xy10 = mul64_wide_5 x1 y0 in let xy11 = mul64_wide_5 x1 y1 in let xy12 = mul64_wide_5 x1 y2 in let xy13 = mul64_wide_5 x1 y3 in let xy20 = mul64_wide_5 x2 y0 in let xy21 = mul64_wide_5 x2 y1 in let xy22 = mul64_wide_5 x2 y2 in let xy30 = mul64_wide_5 x3 y0 in let xy31 = mul64_wide_5 x3 y1 in let xy40 = mul64_wide_5 x4 y0 in assert_norm (pow2 112 < pow2 117); let (c0, t0) = carry56_wide xy00 in let (c1, t1) = carry56_wide (add_inner_carry (add2 xy01 xy10) c0) in let (c2, t2) = carry56_wide (add_inner_carry (add3 xy02 xy11 xy20) c1) in let (c3, t3) = carry56_wide (add_inner_carry (add4 xy03 xy12 xy21 xy30) c2) in let t4 = to_u64 (add_inner_carry (add5 xy04 xy13 xy22 xy31 xy40) c3) &. mask40 in calc (==) { as_nat5 (t0, t1, t2, t3, t4) <: int; (==) { } v t0 + v t1 * pow56 + v t2 * pow112 + v t3 * pow168 + v t4 * pow224; (==) { } v xy00 - v c0 * pow2 56 + (v xy01 + v xy10 + v c0 - v c1 * pow2 56) * pow56 + (v xy02 + v xy11 + v xy20 + v c1 - v c2 * pow56) * pow112 + (v xy03 + v xy12 + v xy21 + v xy30 + v c2 - v c3 * pow56) * pow168 + v t4 * pow224; (==) { logand_mask (to_u64 (add_inner_carry (add5 xy04 xy13 xy22 xy31 xy40) c3)) mask40 40; Math.Lemmas.pow2_modulo_modulo_lemma_1 (v (add_inner_carry (add5 xy04 xy13 xy22 xy31 xy40) c3)) 40 64 } v x0 * v y0 + (v x0 * v y1 + v x1 * v y0) * pow56 + (v x0 * v y2 + v x1 * v y1 + v x2 * v y0) * pow112 + (v x0 * v y3 + v x1 * v y2 + v x2 * v y1 + v x3 * v y0 - v c3 * pow56) * pow168 + ((v x0 * v y4 + v x1 * v y3 + v x2 * v y2 + v x3 * v y1 + v x4 * v y0 + v c3) % pow2 40) * pow224; }; Lemmas.lemma_mul_5_low_264 (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4); (t0, t1, t2, t3, t4) inline_for_extraction noextract val div_2_24_step: x:uint64 -> y:uint64 -> Pure uint64 (requires v x < pow56 /\ v y < pow56) (ensures fun r -> v r < pow56 /\ v r == v x / pow2 24 + pow2 32 * (v y % pow2 24))
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.BignumQ.Mul.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 300, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Lib.IntTypes.uint64 -> y: Lib.IntTypes.uint64 -> Prims.Pure Lib.IntTypes.uint64
Prims.Pure
[]
[]
[ "Lib.IntTypes.uint64", "Prims.unit", "Prims._assert", "Prims.eq2", "Prims.int", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Prims.op_Addition", "Prims.op_Division", "Prims.pow2", "FStar.Mul.op_Star", "Prims.op_Modulus", "Lib.IntTypes.logor_disjoint", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Bar_Dot", "Prims.b2t", "Prims.op_LessThan", "FStar.Math.Lemmas.pow2_minus", "Lib.IntTypes.op_Greater_Greater_Dot", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.op_Amp_Dot", "Lib.IntTypes.u64", "Lib.IntTypes.mod_mask", "Lib.IntTypes.mod_mask_lemma", "FStar.Pervasives.assert_norm", "Prims.op_Equality", "Prims.op_Subtraction", "Lib.IntTypes.op_Less_Less_Dot" ]
[]
false
false
false
false
false
let div_2_24_step x y =
let y' = (y &. u64 0xffffff) <<. 32ul in assert_norm (pow2 24 - 1 = 0xffffff); assert_norm (pow2 24 < pow2 64); mod_mask_lemma y 24ul; assert (v (mod_mask #U64 #SEC 24ul) == 0xffffff); assert (v (y &. u64 0xffffff) == v y % pow2 24); assert (v y' == (v y % pow2 24) * pow2 32); let x' = x >>. 24ul in FStar.Math.Lemmas.pow2_minus 56 24; assert (v x' < pow2 32); let z = x' |. y' in logor_disjoint x' y' 32; assert (v z == v x / pow2 24 + pow2 32 * (v y % pow2 24)); z
false
Hacl.Spec.BignumQ.Mul.fst
Hacl.Spec.BignumQ.Mul.subm_conditional
val subm_conditional: x:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ (if as_nat5 x >= S.q then as_nat5 r == as_nat5 x - S.q else as_nat5 r == as_nat5 x))
val subm_conditional: x:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ (if as_nat5 x >= S.q then as_nat5 r == as_nat5 x - S.q else as_nat5 r == as_nat5 x))
let subm_conditional (x0, x1, x2, x3, x4) = let (y0, y1, y2, y3, y4) = make_m () in let (b0, t0) = subm_step x0 y0 in assert (v x0 - v y0 == v t0 - v b0 * pow56); let (b1, t1) = subm_step x1 (y1 +! b0) in assert (v x1 - v y1 - v b0 == v t1 - v b1 * pow56); let (b2, t2) = subm_step x2 (y2 +! b1) in assert (v x2 - v y2 - v b1 == v t2 - v b2 * pow56); let (b3, t3) = subm_step x3 (y3 +! b2) in assert (v x3 - v y3 - v b2 == v t3 - v b3 * pow56); let (b4, t4) = subm_step x4 (y4 +! b3) in assert (v x4 - v y4 - v b3 == v t4 - v b4 * pow56); Lemmas.lemma_subm_conditional (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) (v b0) (v b1) (v b2) (v b3) (v b4); assert ( as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow56 * pow224 == as_nat5 (x0, x1, x2, x3, x4) - as_nat5 (y0, y1, y2, y3, y4)); //assert_norm (pow56 * pow224 = pow2 280); //assert (as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow2 280 == as_nat5 (x0, x1, x2, x3, x4) - S.q); Lemmas.lemma_as_nat5 (x0, x1, x2, x3, x4); Lemmas.lemma_as_nat5 (t0, t1, t2, t3, t4); //assert (if v b4 = 0 then as_nat5 (x0, x1, x2, x3, x4) >= S.q else as_nat5 (x0, x1, x2, x3, x4) < S.q); assert (if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 else v b4 == 1); let (z0, z1, z2, z3, z4) = choose b4 (x0, x1, x2, x3, x4) (t0, t1, t2, t3, t4) in assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else v b4 == 1 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); (z0, z1, z2, z3, z4)
{ "file_name": "code/ed25519/Hacl.Spec.BignumQ.Mul.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 22, "end_line": 141, "start_col": 0, "start_line": 102 }
module Hacl.Spec.BignumQ.Mul open FStar.Mul open Lib.IntTypes module S = Spec.Ed25519 module Lemmas = Hacl.Spec.BignumQ.Lemmas include Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask56 : x:uint64{v x == pow2 56 - 1} = assert_norm (pow2 56 - 1 == 0xffffffffffffff); u64 0xffffffffffffff inline_for_extraction noextract let mask40 : x:uint64{v x == pow2 40 - 1} = assert_norm (pow2 40 - 1 == 0xffffffffff); u64 0xffffffffff inline_for_extraction noextract val make_m: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == S.q} let make_m () = let m0 = u64 0x12631a5cf5d3ed in let m1 = u64 0xf9dea2f79cd658 in let m2 = u64 0x000000000014de in let m3 = u64 0x00000000000000 in let m4 = u64 0x00000010000000 in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val make_mu: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == pow2 512 / S.q} let make_mu m = let m0 = u64 0x9ce5a30a2c131b in let m1 = u64 0x215d086329a7ed in let m2 = u64 0xffffffffeb2106 in let m3 = u64 0xffffffffffffff in let m4 = u64 0x00000fffffffff in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == pow2 512 / S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val choose: b:uint64 -> x:qelem5 -> y:qelem5 -> Pure qelem5 (requires v b == 0 \/ v b == 1) (ensures fun z -> if v b = 1 then z == x else z == y) let choose b (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let mask = b -. u64 1 in let z0 = x0 ^. (mask &. (x0 ^. y0)) in Lemmas.lemma_choose_step b x0 y0; let z1 = x1 ^. (mask &. (x1 ^. y1)) in Lemmas.lemma_choose_step b x1 y1; let z2 = x2 ^. (mask &. (x2 ^. y2)) in Lemmas.lemma_choose_step b x2 y2; let z3 = x3 ^. (mask &. (x3 ^. y3)) in Lemmas.lemma_choose_step b x3 y3; let z4 = x4 ^. (mask &. (x4 ^. y4)) in Lemmas.lemma_choose_step b x4 y4; (z0, z1, z2, z3, z4) inline_for_extraction noextract val subm_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow56 /\ v y <= pow56) (ensures fun (b, t) -> v b <= 1 /\ qelem_fits1 t 1 /\ v x - v y == v t - v b * pow56) let subm_step x y = let b = (x -. y) >>. 63ul in //assert (if v x >= v y then v b == 0 else v b == 1); let lshift56 = (b <<. 56ul) in //assert (if v x >= v y then v lshift56 == 0 else v lshift56 == pow56); //assert (v lshift56 == v b * pow56); //assert (v ((b <<. 56ul) +! x) == v b * pow56 + v x); let t = ((b <<. 56ul) +! x) -! y in b, t inline_for_extraction noextract val subm_conditional: x:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ (if as_nat5 x >= S.q then as_nat5 r == as_nat5 x - S.q else as_nat5 r == as_nat5 x))
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.BignumQ.Mul.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Hacl.Spec.BignumQ.Definitions.qelem5 -> Prims.Pure Hacl.Spec.BignumQ.Definitions.qelem5
Prims.Pure
[]
[]
[ "Hacl.Spec.BignumQ.Definitions.qelem5", "Lib.IntTypes.uint64", "FStar.Pervasives.Native.Mktuple5", "Prims.unit", "Prims._assert", "Prims.op_GreaterThanOrEqual", "Hacl.Spec.BignumQ.Definitions.as_nat5", "Spec.Ed25519.q", "Prims.l_and", "Prims.eq2", "Prims.int", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Prims.nat", "Prims.bool", "Hacl.Spec.BignumQ.Mul.choose", "Hacl.Spec.BignumQ.Lemmas.lemma_as_nat5", "Prims.op_Subtraction", "FStar.Mul.op_Star", "Hacl.Spec.BignumQ.Definitions.pow56", "Hacl.Spec.BignumQ.Definitions.pow224", "Hacl.Spec.BignumQ.Lemmas.lemma_subm_conditional", "FStar.Pervasives.Native.tuple2", "Lib.IntTypes.int_t", "Hacl.Spec.BignumQ.Mul.subm_step", "Lib.IntTypes.op_Plus_Bang", "Hacl.Spec.BignumQ.Definitions.qelem_fits5", "Hacl.Spec.BignumQ.Mul.make_m" ]
[]
false
false
false
false
false
let subm_conditional (x0, x1, x2, x3, x4) =
let y0, y1, y2, y3, y4 = make_m () in let b0, t0 = subm_step x0 y0 in assert (v x0 - v y0 == v t0 - v b0 * pow56); let b1, t1 = subm_step x1 (y1 +! b0) in assert (v x1 - v y1 - v b0 == v t1 - v b1 * pow56); let b2, t2 = subm_step x2 (y2 +! b1) in assert (v x2 - v y2 - v b1 == v t2 - v b2 * pow56); let b3, t3 = subm_step x3 (y3 +! b2) in assert (v x3 - v y3 - v b2 == v t3 - v b3 * pow56); let b4, t4 = subm_step x4 (y4 +! b3) in assert (v x4 - v y4 - v b3 == v t4 - v b4 * pow56); Lemmas.lemma_subm_conditional (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) (v b0) (v b1) (v b2) (v b3) (v b4); assert (as_nat5 (t0, t1, t2, t3, t4) - (v b4 * pow56) * pow224 == as_nat5 (x0, x1, x2, x3, x4) - as_nat5 (y0, y1, y2, y3, y4)); Lemmas.lemma_as_nat5 (x0, x1, x2, x3, x4); Lemmas.lemma_as_nat5 (t0, t1, t2, t3, t4); assert (if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 else v b4 == 1); let z0, z1, z2, z3, z4 = choose b4 (x0, x1, x2, x3, x4) (t0, t1, t2, t3, t4) in assert (if as_nat5 (x0, x1, x2, x3, x4) >= S.q then as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); assert (if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else v b4 == 1 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); (z0, z1, z2, z3, z4)
false
Hacl.Spec.BignumQ.Mul.fst
Hacl.Spec.BignumQ.Mul.mod_264
val mod_264: t:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (wide_as_nat5 t) % pow2 264)
val mod_264: t:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (wide_as_nat5 t) % pow2 264)
let mod_264 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = Lemmas.lemma_mod_264 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9); (t0, t1, t2, t3, t4 &. mask40)
{ "file_name": "code/ed25519/Hacl.Spec.BignumQ.Mul.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 733, "start_col": 0, "start_line": 731 }
module Hacl.Spec.BignumQ.Mul open FStar.Mul open Lib.IntTypes module S = Spec.Ed25519 module Lemmas = Hacl.Spec.BignumQ.Lemmas include Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask56 : x:uint64{v x == pow2 56 - 1} = assert_norm (pow2 56 - 1 == 0xffffffffffffff); u64 0xffffffffffffff inline_for_extraction noextract let mask40 : x:uint64{v x == pow2 40 - 1} = assert_norm (pow2 40 - 1 == 0xffffffffff); u64 0xffffffffff inline_for_extraction noextract val make_m: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == S.q} let make_m () = let m0 = u64 0x12631a5cf5d3ed in let m1 = u64 0xf9dea2f79cd658 in let m2 = u64 0x000000000014de in let m3 = u64 0x00000000000000 in let m4 = u64 0x00000010000000 in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val make_mu: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == pow2 512 / S.q} let make_mu m = let m0 = u64 0x9ce5a30a2c131b in let m1 = u64 0x215d086329a7ed in let m2 = u64 0xffffffffeb2106 in let m3 = u64 0xffffffffffffff in let m4 = u64 0x00000fffffffff in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == pow2 512 / S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val choose: b:uint64 -> x:qelem5 -> y:qelem5 -> Pure qelem5 (requires v b == 0 \/ v b == 1) (ensures fun z -> if v b = 1 then z == x else z == y) let choose b (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let mask = b -. u64 1 in let z0 = x0 ^. (mask &. (x0 ^. y0)) in Lemmas.lemma_choose_step b x0 y0; let z1 = x1 ^. (mask &. (x1 ^. y1)) in Lemmas.lemma_choose_step b x1 y1; let z2 = x2 ^. (mask &. (x2 ^. y2)) in Lemmas.lemma_choose_step b x2 y2; let z3 = x3 ^. (mask &. (x3 ^. y3)) in Lemmas.lemma_choose_step b x3 y3; let z4 = x4 ^. (mask &. (x4 ^. y4)) in Lemmas.lemma_choose_step b x4 y4; (z0, z1, z2, z3, z4) inline_for_extraction noextract val subm_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow56 /\ v y <= pow56) (ensures fun (b, t) -> v b <= 1 /\ qelem_fits1 t 1 /\ v x - v y == v t - v b * pow56) let subm_step x y = let b = (x -. y) >>. 63ul in //assert (if v x >= v y then v b == 0 else v b == 1); let lshift56 = (b <<. 56ul) in //assert (if v x >= v y then v lshift56 == 0 else v lshift56 == pow56); //assert (v lshift56 == v b * pow56); //assert (v ((b <<. 56ul) +! x) == v b * pow56 + v x); let t = ((b <<. 56ul) +! x) -! y in b, t inline_for_extraction noextract val subm_conditional: x:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ (if as_nat5 x >= S.q then as_nat5 r == as_nat5 x - S.q else as_nat5 r == as_nat5 x)) let subm_conditional (x0, x1, x2, x3, x4) = let (y0, y1, y2, y3, y4) = make_m () in let (b0, t0) = subm_step x0 y0 in assert (v x0 - v y0 == v t0 - v b0 * pow56); let (b1, t1) = subm_step x1 (y1 +! b0) in assert (v x1 - v y1 - v b0 == v t1 - v b1 * pow56); let (b2, t2) = subm_step x2 (y2 +! b1) in assert (v x2 - v y2 - v b1 == v t2 - v b2 * pow56); let (b3, t3) = subm_step x3 (y3 +! b2) in assert (v x3 - v y3 - v b2 == v t3 - v b3 * pow56); let (b4, t4) = subm_step x4 (y4 +! b3) in assert (v x4 - v y4 - v b3 == v t4 - v b4 * pow56); Lemmas.lemma_subm_conditional (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) (v b0) (v b1) (v b2) (v b3) (v b4); assert ( as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow56 * pow224 == as_nat5 (x0, x1, x2, x3, x4) - as_nat5 (y0, y1, y2, y3, y4)); //assert_norm (pow56 * pow224 = pow2 280); //assert (as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow2 280 == as_nat5 (x0, x1, x2, x3, x4) - S.q); Lemmas.lemma_as_nat5 (x0, x1, x2, x3, x4); Lemmas.lemma_as_nat5 (t0, t1, t2, t3, t4); //assert (if v b4 = 0 then as_nat5 (x0, x1, x2, x3, x4) >= S.q else as_nat5 (x0, x1, x2, x3, x4) < S.q); assert (if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 else v b4 == 1); let (z0, z1, z2, z3, z4) = choose b4 (x0, x1, x2, x3, x4) (t0, t1, t2, t3, t4) in assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else v b4 == 1 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); (z0, z1, z2, z3, z4) inline_for_extraction noextract val carry56: x:uint64 -> Pure (uint64 & uint64) (requires v x <= pow2 57) (ensures fun (t, c) -> v t < pow56 /\ v c <= 2 /\ v x == v c * pow56 + v t) let carry56 x = let carry = x >>. 56ul in FStar.Math.Lemmas.pow2_minus 57 56; let t = x &. mask56 in assert_norm (pow2 56 < pow2 64); mod_mask_lemma x 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); t, carry inline_for_extraction noextract val add_modq5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < S.q /\ as_nat5 y < S.q) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (as_nat5 x + as_nat5 y) % S.q) let add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = assert_norm (pow56 - 1 + pow56 - 1 == pow2 57 - 2); let (t0, c0) = carry56 (x0 +! y0) in let (t1, c1) = carry56 (x1 +! y1 +! c0) in let (t2, c2) = carry56 (x2 +! y2 +! c1) in let (t3, c3) = carry56 (x3 +! y3 +! c2) in let t4 = x4 +! y4 +! c3 in assert (as_nat5 (t0, t1, t2, t3, t4) == as_nat5 (x0, x1, x2, x3, x4) + as_nat5 (y0, y1, y2, y3, y4)); let (o0, o1, o2, o3, o4) = subm_conditional (t0, t1, t2, t3, t4) in Lemmas.lemma_add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) (t0, t1, t2, t3, t4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry56_wide: x:uint128 -> Pure (uint128 & uint64) (requires v x < pow2 117) (ensures fun (c, t) -> v t < pow56 /\ v c < pow2 61 /\ v x - v c * pow56 == v t /\ v c == v x / pow56) let carry56_wide x = let carry = x >>. 56ul in let t = to_u64 x &. mask56 in assert_norm (pow2 56 < pow2 64); Math.Lemmas.lemma_div_lt_nat (v x) 117 56; mod_mask_lemma (to_u64 x) 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == (v x % pow2 64) % pow2 56); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v x) 56 64; assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); carry, t inline_for_extraction noextract val mul64_wide_5: (a:uint64) -> (b:uint64) -> Pure uint128 (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures fun z -> v z == v a * v b /\ v z <= pow2 112 - pow2 57 + 1 /\ v z < pow2 112) let mul64_wide_5 a b = let lemma_smaller (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) < pow2 112) = if v a = 0 || v b = 0 then () else calc (<) { v a * v b <: int; (<) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56) } v a * pow2 56; (<) { Math.Lemmas.lemma_mult_le_right (pow2 56) (v a) (pow2 56) } pow2 56 * pow2 56; (==) { assert_norm (pow2 56 * pow2 56 == pow2 112) } pow2 112; } in let lemma_le (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) <= pow2 112 - pow2 57 + 1) = if v a = 0 || v b = 0 then () else assert_norm (pow2 112 - pow2 57 + 1 >= 0); calc (<=) { v a * v b <: int; (<=) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56 - 1) } v a * (pow2 56 - 1); (<=) { Math.Lemmas.lemma_mult_le_right (pow2 56 - 1) (v a) (pow2 56 - 1) } (pow2 56 - 1) * (pow2 56 - 1); (==) { assert_norm ((pow2 56 - 1) * (pow2 56 - 1) == pow2 112 - pow2 57 + 1) } pow2 112 - pow2 57 + 1; } in lemma_le a b; lemma_smaller a b; mul64_wide a b inline_for_extraction noextract val add2: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112) (ensures fun z -> v z == v a + v b /\ v z <= pow2 116) let add2 a b = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b inline_for_extraction noextract val add3: (a:uint128) -> (b:uint128) -> (c:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 ) (ensures fun z -> v z == v a + v b + v c /\ v z <= pow2 116) let add3 a b c = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); a +. b +. c inline_for_extraction noextract val add4: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d /\ v z <= pow2 116) let add4 a b c d = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d) (pow2 128); a +. b +. c +. d inline_for_extraction noextract val add5: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> (e:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112 /\ v e < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d + v e/\ v z <= pow2 116) let add5 a b c d e = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d + v e) (pow2 128); a +. b +. c +. d +. e inline_for_extraction noextract val add_inner_carry: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a <= pow2 116 /\ v b < pow2 61) (ensures fun z -> v z == v a + v b /\ v z < pow2 117) let add_inner_carry a b = assert_norm (pow2 116 + pow2 61 < pow2 128); assert_norm (pow2 116 + pow2 61 < pow2 117); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b inline_for_extraction noextract val mul_5: x:qelem5 -> y:qelem5 -> Pure qelem_wide5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1)) (ensures fun r -> qelem_wide_fits5 r (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 r == as_nat5 x * as_nat5 y) let lemma_mult_distr_3 (a b c:nat) (n:nat) : Lemma ((a + b - c * pow2 56) * pow2 n == a * pow2 n + b * pow2 n - c * pow2 (n + 56)) = Math.Lemmas.distributivity_sub_left (a + b) (c * pow2 56) (pow2 n); Math.Lemmas.distributivity_add_left a b (pow2 n); Math.Lemmas.pow2_plus 56 n #set-options "--z3rlimit 300" let mul_5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let xy00 = mul64_wide_5 x0 y0 in let xy01 = mul64_wide_5 x0 y1 in let xy02 = mul64_wide_5 x0 y2 in let xy03 = mul64_wide_5 x0 y3 in let xy04 = mul64_wide_5 x0 y4 in let xy10 = mul64_wide_5 x1 y0 in let xy11 = mul64_wide_5 x1 y1 in let xy12 = mul64_wide_5 x1 y2 in let xy13 = mul64_wide_5 x1 y3 in let xy14 = mul64_wide_5 x1 y4 in let xy20 = mul64_wide_5 x2 y0 in let xy21 = mul64_wide_5 x2 y1 in let xy22 = mul64_wide_5 x2 y2 in let xy23 = mul64_wide_5 x2 y3 in let xy24 = mul64_wide_5 x2 y4 in let xy30 = mul64_wide_5 x3 y0 in let xy31 = mul64_wide_5 x3 y1 in let xy32 = mul64_wide_5 x3 y2 in let xy33 = mul64_wide_5 x3 y3 in let xy34 = mul64_wide_5 x3 y4 in let xy40 = mul64_wide_5 x4 y0 in let xy41 = mul64_wide_5 x4 y1 in let xy42 = mul64_wide_5 x4 y2 in let xy43 = mul64_wide_5 x4 y3 in let xy44 = mul64_wide_5 x4 y4 in let z0 = xy00 in // < pow2 112 let z1 = add2 xy01 xy10 in // < pow2 113 let z2 = add3 xy02 xy11 xy20 in // < pow2 114 let z3 = add4 xy03 xy12 xy21 xy30 in // < pow2 115 let z4 = add5 xy04 xy13 xy22 xy31 xy40 in // < pow2 116 let z5 = add4 xy14 xy23 xy32 xy41 in let z6 = add3 xy24 xy33 xy42 in let z7 = add2 xy34 xy43 in let z8 = xy44 in //(z0, z1, z2, z3, z4, z5, z6, z7, z8) assert_norm (pow2 112 < pow2 117); assert_norm (pow2 112 <= pow2 116); let (c0, t0) = carry56_wide z0 in let (c1, t1) = carry56_wide (add_inner_carry z1 c0) in let (c2, t2) = carry56_wide (add_inner_carry z2 c1) in let (c3, t3) = carry56_wide (add_inner_carry z3 c2) in let (c4, t4) = carry56_wide (add_inner_carry z4 c3) in let (c5, t5) = carry56_wide (add_inner_carry z5 c4) in let (c6, t6) = carry56_wide (add_inner_carry z6 c5) in let (c7, t7) = carry56_wide (add_inner_carry z7 c6) in let (c8, t8) = carry56_wide (add_inner_carry z8 c7) in let t9 = to_u64 c8 in let lemma_t9_fits () : Lemma (v t9 < pow2 56) = // This proof was built from the bottom. We have as a constraint that v c8 has to be < pow2 112 to satisfy the postcondition. // We compute each time the maximal value such that this postcondition is satisfied calc (<) { v c0; (<) { Math.Lemmas.lemma_div_lt_nat (v z0) 112 56 } pow2 56; }; calc (<) { v c1; (<) { assert_norm (2*(pow2 112 - pow2 57 + 1) + pow2 56 <= pow2 113); Math.Lemmas.lemma_div_lt_nat (v z1 + v c0) 113 56 } pow2 57; }; calc (<) { v c2; (<) { assert_norm (3*(pow2 112 - pow2 57 + 1) + pow2 57 <= pow2 114); Math.Lemmas.lemma_div_lt_nat (v z2 + v c1) 114 56 } pow2 58; }; calc (<=) { v c3; (<=) { assert_norm (4*(pow2 112 - pow2 57 + 1) + pow2 58 <= 31153781151208965410895007785680895); assert_norm (31153781151208965410895007785680895 / pow56 == 432345564227567610); Math.Lemmas.lemma_div_le (v z3 + v c2) 31153781151208965410895007785680895 (pow2 56) } 432345564227567610; }; calc (<=) { v c4; (<=) { assert_norm (5*(pow2 112 - pow2 57 + 1) + 432345564227567610 <= 25961484292674137854422105494388735); // (pow2 59 - 2) * pow56 assert_norm (25961484292674137854422105494388735 / pow56 == 360287970189639675); Math.Lemmas.lemma_div_le (v z4 + v c3) 25961484292674137854422105494388735 (pow2 56) } 360287970189639675; }; calc (<=) { v c5; (<=) { assert_norm (4*(pow2 112 - pow2 57 + 1) + 360287970189639675 <= 20769187434139310297949203203096575); Math.Lemmas.lemma_div_le (v z5 + v c4) 20769187434139310297949203203096575 (pow2 56); assert_norm (20769187434139310297949203203096575 / pow2 56 == pow2 58 - 4) } pow2 58 - 4; }; calc (<=) { v c6; (<=) { assert_norm (3*(pow2 112 - pow2 57 + 1) + pow2 58 - 4 <= 15576890575604482741476300911804415); Math.Lemmas.lemma_div_le (v z6 + v c5) 15576890575604482741476300911804415 (pow2 56); assert_norm (15576890575604482741476300911804415 / pow2 56 == 216172782113783805) } 216172782113783805; }; calc (<=) { v c7; (<=) { assert_norm (2*(pow2 112 - pow2 57 + 1) + 216172782113783805 <= 10384593717069655185003398620512255); // (pow2 57 - 1) * pow2 56 - 1 Math.Lemmas.lemma_div_le (v z7 + v c6) 10384593717069655185003398620512255 (pow2 56); assert_norm (10384593717069655185003398620512255 / pow2 56 == pow2 57 - 2) } pow2 57 - 2; }; calc (<) { v c8; (<) { Math.Lemmas.lemma_div_lt_nat (v z8 + v c7) 112 56 } pow2 56; }; assert_norm (pow2 56 < pow2 64); Math.Lemmas.small_mod (v c8) (pow2 64) in lemma_t9_fits(); calc (==) { wide_as_nat5 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) <: int; (==) { } v t0 + v t1 * pow56 + v t2 * pow112 + v t3 * pow168 + v t4 * pow224 + v t5 * pow280 + v t6 * pow336 + v t7 * pow392 + v t8 * pow448 + v t9 * pow504; (==) { assert_norm (pow2 61 < pow2 64); Math.Lemmas.small_mod (v c8) (pow2 64) } v z0 - v c0 * pow2 56 + (v z1 + v c0 - v c1 * pow2 56) * pow56 + (v z2 + v c1 - v c2 * pow2 56) * pow112 + (v z3 + v c2 - v c3 * pow2 56) * pow168 + (v z4 + v c3 - v c4 * pow2 56) * pow224 + (v z5 + v c4 - v c5 * pow2 56) * pow280 + (v z6 + v c5 - v c6 * pow2 56) * pow336 + (v z7 + v c6 - v c7 * pow2 56) * pow392 + (v z8 + v c7 - v c8 * pow2 56) * pow448 + v c8 * pow504; (==) { lemma_mult_distr_3 (v z1) (v c0) (v c1) 56; lemma_mult_distr_3 (v z2) (v c1) (v c2) 112; lemma_mult_distr_3 (v z3) (v c2) (v c3) 168; lemma_mult_distr_3 (v z4) (v c3) (v c4) 224; lemma_mult_distr_3 (v z5) (v c4) (v c5) 280; lemma_mult_distr_3 (v z6) (v c5) (v c6) 336; lemma_mult_distr_3 (v z7) (v c6) (v c7) 392; lemma_mult_distr_3 (v z8) (v c7) (v c8) 448 } v z0 + v z1 * pow56 + v z2 * pow112 + v z3 * pow168 + v z4 * pow224 + v z5 * pow280 + v z6 * pow336 + v z7 * pow392 + v z8 * pow448; (==) { calc (==) { v z1; (==) { } v x0 * v y1 + v x1 * v y0; }; calc (==) { v z2; (==) { } v x0 * v y2 + v x1 * v y1 + v x2 * v y0; }; calc (==) { v z3; (==) { } v x0 * v y3 + v x1 * v y2 + v x2 * v y1 + v x3 * v y0; }; calc (==) { v z4; (==) { } v x0 * v y4 + v x1 * v y3 + v x2 * v y2 + v x3 * v y1 + v x4 * v y0; }; calc (==) { v z5; (==) { } v x1 * v y4 + v x2 * v y3 + v x3 * v y2 + v x4 * v y1; }; calc (==) { v z6; (==) { } v x2 * v y4 + v x3 * v y3 + v x4 * v y2; }; calc (==) { v z7; (==) { } v x3 * v y4 + v x4 * v y3; }; calc (==) { v z8; (==) { } v x4 * v y4; } } v x0 * v y0 + (v x0 * v y1 + v x1 * v y0) * pow56 + (v x0 * v y2 + v x1 * v y1 + v x2 * v y0) * pow112 + (v x0 * v y3 + v x1 * v y2 + v x2 * v y1 + v x3 * v y0) * pow168 + (v x0 * v y4 + v x1 * v y3 + v x2 * v y2 + v x3 * v y1 + v x4 * v y0) * pow224 + (v x1 * v y4 + v x2 * v y3 + v x3 * v y2 + v x4 * v y1) * pow280 + (v x2 * v y4 + v x3 * v y3 + v x4 * v y2) * pow336 + (v x3 * v y4 + v x4 * v y3) * pow392 + (v x4 * v y4) * pow448; (==) { Lemmas.lemma_mul_qelem5 (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) } (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224) * (v y0 + v y1 * pow2 56 + v y2 * pow2 112 + v y3 * pow2 168 + v y4 * pow2 224); }; (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) inline_for_extraction noextract val low_mul_5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (as_nat5 x * as_nat5 y) % pow2 264) let low_mul_5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let xy00 = mul64_wide_5 x0 y0 in let xy01 = mul64_wide_5 x0 y1 in let xy02 = mul64_wide_5 x0 y2 in let xy03 = mul64_wide_5 x0 y3 in let xy04 = mul64_wide_5 x0 y4 in let xy10 = mul64_wide_5 x1 y0 in let xy11 = mul64_wide_5 x1 y1 in let xy12 = mul64_wide_5 x1 y2 in let xy13 = mul64_wide_5 x1 y3 in let xy20 = mul64_wide_5 x2 y0 in let xy21 = mul64_wide_5 x2 y1 in let xy22 = mul64_wide_5 x2 y2 in let xy30 = mul64_wide_5 x3 y0 in let xy31 = mul64_wide_5 x3 y1 in let xy40 = mul64_wide_5 x4 y0 in assert_norm (pow2 112 < pow2 117); let (c0, t0) = carry56_wide xy00 in let (c1, t1) = carry56_wide (add_inner_carry (add2 xy01 xy10) c0) in let (c2, t2) = carry56_wide (add_inner_carry (add3 xy02 xy11 xy20) c1) in let (c3, t3) = carry56_wide (add_inner_carry (add4 xy03 xy12 xy21 xy30) c2) in let t4 = to_u64 (add_inner_carry (add5 xy04 xy13 xy22 xy31 xy40) c3) &. mask40 in calc (==) { as_nat5 (t0, t1, t2, t3, t4) <: int; (==) { } v t0 + v t1 * pow56 + v t2 * pow112 + v t3 * pow168 + v t4 * pow224; (==) { } v xy00 - v c0 * pow2 56 + (v xy01 + v xy10 + v c0 - v c1 * pow2 56) * pow56 + (v xy02 + v xy11 + v xy20 + v c1 - v c2 * pow56) * pow112 + (v xy03 + v xy12 + v xy21 + v xy30 + v c2 - v c3 * pow56) * pow168 + v t4 * pow224; (==) { logand_mask (to_u64 (add_inner_carry (add5 xy04 xy13 xy22 xy31 xy40) c3)) mask40 40; Math.Lemmas.pow2_modulo_modulo_lemma_1 (v (add_inner_carry (add5 xy04 xy13 xy22 xy31 xy40) c3)) 40 64 } v x0 * v y0 + (v x0 * v y1 + v x1 * v y0) * pow56 + (v x0 * v y2 + v x1 * v y1 + v x2 * v y0) * pow112 + (v x0 * v y3 + v x1 * v y2 + v x2 * v y1 + v x3 * v y0 - v c3 * pow56) * pow168 + ((v x0 * v y4 + v x1 * v y3 + v x2 * v y2 + v x3 * v y1 + v x4 * v y0 + v c3) % pow2 40) * pow224; }; Lemmas.lemma_mul_5_low_264 (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4); (t0, t1, t2, t3, t4) inline_for_extraction noextract val div_2_24_step: x:uint64 -> y:uint64 -> Pure uint64 (requires v x < pow56 /\ v y < pow56) (ensures fun r -> v r < pow56 /\ v r == v x / pow2 24 + pow2 32 * (v y % pow2 24)) let div_2_24_step x y = let y' = (y &. u64 0xffffff) <<. 32ul in assert_norm (pow2 24 - 1 = 0xffffff); assert_norm (pow2 24 < pow2 64); mod_mask_lemma y 24ul; assert (v (mod_mask #U64 #SEC 24ul) == 0xffffff); assert (v (y &. u64 0xffffff) == v y % pow2 24); assert (v y' == (v y % pow2 24) * pow2 32); let x' = x >>. 24ul in FStar.Math.Lemmas.pow2_minus 56 24; assert (v x' < pow2 32); let z = x' |. y' in logor_disjoint x' y' 32; assert (v z == v x / pow2 24 + pow2 32 * (v y % pow2 24)); z inline_for_extraction noextract val div_248: x:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 x < pow2 512) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (wide_as_nat5 x) / pow2 248) let div_248 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = // x / pow2 248 == (x / pow2 224) / pow2 24 let z0 = div_2_24_step x4 x5 in let z1 = div_2_24_step x5 x6 in let z2 = div_2_24_step x6 x7 in let z3 = div_2_24_step x7 x8 in let z4 = div_2_24_step x8 x9 in assert (qelem_fits5 (z0, z1, z2, z3, z4) (1, 1, 1, 1, 1)); Lemmas.lemma_div248 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9); (z0, z1, z2, z3, z4) inline_for_extraction noextract val div_2_40_step: x:uint64 -> y:uint64 -> Pure uint64 (requires v x < pow56) (ensures fun z -> v z < pow56 /\ v z == v x / pow2 40 + pow2 16 * (v y % pow2 40)) let div_2_40_step x y = let y' = (y &. mask40) <<. 16ul in assert_norm (pow2 40 < pow2 64); mod_mask_lemma y 40ul; assert (v (mod_mask #U64 #SEC 40ul) == v mask40); assert (v y' == (v y % pow2 40) * pow2 16); let x' = x >>. 40ul in FStar.Math.Lemmas.pow2_minus 56 40; assert (v x' == v x / pow2 40); assert (v x' < pow2 16); let z = x' |. y' in logor_disjoint x' y' 16; z inline_for_extraction noextract val div_264: x:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 x < pow2 528) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (wide_as_nat5 x) / pow2 264) let div_264 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = // x / pow2 264 == (x / pow2 224) / pow2 40 let z0 = div_2_40_step x4 x5 in let z1 = div_2_40_step x5 x6 in let z2 = div_2_40_step x6 x7 in let z3 = div_2_40_step x7 x8 in let z4 = div_2_40_step x8 x9 in assert (qelem_fits5 (z0, z1, z2, z3, z4) (1, 1, 1, 1, 1)); Lemmas.lemma_div264 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9); (z0, z1, z2, z3, z4) inline_for_extraction noextract val mod_264: t:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (wide_as_nat5 t) % pow2 264)
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.BignumQ.Mul.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 300, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Hacl.Spec.BignumQ.Definitions.qelem_wide5 -> Prims.Pure Hacl.Spec.BignumQ.Definitions.qelem5
Prims.Pure
[]
[]
[ "Hacl.Spec.BignumQ.Definitions.qelem_wide5", "Lib.IntTypes.uint64", "FStar.Pervasives.Native.Mktuple5", "Lib.IntTypes.op_Amp_Dot", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Hacl.Spec.BignumQ.Mul.mask40", "Prims.unit", "Hacl.Spec.BignumQ.Lemmas.lemma_mod_264", "FStar.Pervasives.Native.Mktuple10", "Hacl.Spec.BignumQ.Definitions.qelem5" ]
[]
false
false
false
false
false
let mod_264 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) =
Lemmas.lemma_mod_264 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9); (t0, t1, t2, t3, t4 &. mask40)
false
Hacl.Spec.BignumQ.Mul.fst
Hacl.Spec.BignumQ.Mul.div_264
val div_264: x:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 x < pow2 528) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (wide_as_nat5 x) / pow2 264)
val div_264: x:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 x < pow2 528) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (wide_as_nat5 x) / pow2 264)
let div_264 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = // x / pow2 264 == (x / pow2 224) / pow2 40 let z0 = div_2_40_step x4 x5 in let z1 = div_2_40_step x5 x6 in let z2 = div_2_40_step x6 x7 in let z3 = div_2_40_step x7 x8 in let z4 = div_2_40_step x8 x9 in assert (qelem_fits5 (z0, z1, z2, z3, z4) (1, 1, 1, 1, 1)); Lemmas.lemma_div264 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9); (z0, z1, z2, z3, z4)
{ "file_name": "code/ed25519/Hacl.Spec.BignumQ.Mul.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 22, "end_line": 719, "start_col": 0, "start_line": 710 }
module Hacl.Spec.BignumQ.Mul open FStar.Mul open Lib.IntTypes module S = Spec.Ed25519 module Lemmas = Hacl.Spec.BignumQ.Lemmas include Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask56 : x:uint64{v x == pow2 56 - 1} = assert_norm (pow2 56 - 1 == 0xffffffffffffff); u64 0xffffffffffffff inline_for_extraction noextract let mask40 : x:uint64{v x == pow2 40 - 1} = assert_norm (pow2 40 - 1 == 0xffffffffff); u64 0xffffffffff inline_for_extraction noextract val make_m: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == S.q} let make_m () = let m0 = u64 0x12631a5cf5d3ed in let m1 = u64 0xf9dea2f79cd658 in let m2 = u64 0x000000000014de in let m3 = u64 0x00000000000000 in let m4 = u64 0x00000010000000 in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val make_mu: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == pow2 512 / S.q} let make_mu m = let m0 = u64 0x9ce5a30a2c131b in let m1 = u64 0x215d086329a7ed in let m2 = u64 0xffffffffeb2106 in let m3 = u64 0xffffffffffffff in let m4 = u64 0x00000fffffffff in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == pow2 512 / S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val choose: b:uint64 -> x:qelem5 -> y:qelem5 -> Pure qelem5 (requires v b == 0 \/ v b == 1) (ensures fun z -> if v b = 1 then z == x else z == y) let choose b (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let mask = b -. u64 1 in let z0 = x0 ^. (mask &. (x0 ^. y0)) in Lemmas.lemma_choose_step b x0 y0; let z1 = x1 ^. (mask &. (x1 ^. y1)) in Lemmas.lemma_choose_step b x1 y1; let z2 = x2 ^. (mask &. (x2 ^. y2)) in Lemmas.lemma_choose_step b x2 y2; let z3 = x3 ^. (mask &. (x3 ^. y3)) in Lemmas.lemma_choose_step b x3 y3; let z4 = x4 ^. (mask &. (x4 ^. y4)) in Lemmas.lemma_choose_step b x4 y4; (z0, z1, z2, z3, z4) inline_for_extraction noextract val subm_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow56 /\ v y <= pow56) (ensures fun (b, t) -> v b <= 1 /\ qelem_fits1 t 1 /\ v x - v y == v t - v b * pow56) let subm_step x y = let b = (x -. y) >>. 63ul in //assert (if v x >= v y then v b == 0 else v b == 1); let lshift56 = (b <<. 56ul) in //assert (if v x >= v y then v lshift56 == 0 else v lshift56 == pow56); //assert (v lshift56 == v b * pow56); //assert (v ((b <<. 56ul) +! x) == v b * pow56 + v x); let t = ((b <<. 56ul) +! x) -! y in b, t inline_for_extraction noextract val subm_conditional: x:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ (if as_nat5 x >= S.q then as_nat5 r == as_nat5 x - S.q else as_nat5 r == as_nat5 x)) let subm_conditional (x0, x1, x2, x3, x4) = let (y0, y1, y2, y3, y4) = make_m () in let (b0, t0) = subm_step x0 y0 in assert (v x0 - v y0 == v t0 - v b0 * pow56); let (b1, t1) = subm_step x1 (y1 +! b0) in assert (v x1 - v y1 - v b0 == v t1 - v b1 * pow56); let (b2, t2) = subm_step x2 (y2 +! b1) in assert (v x2 - v y2 - v b1 == v t2 - v b2 * pow56); let (b3, t3) = subm_step x3 (y3 +! b2) in assert (v x3 - v y3 - v b2 == v t3 - v b3 * pow56); let (b4, t4) = subm_step x4 (y4 +! b3) in assert (v x4 - v y4 - v b3 == v t4 - v b4 * pow56); Lemmas.lemma_subm_conditional (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) (v b0) (v b1) (v b2) (v b3) (v b4); assert ( as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow56 * pow224 == as_nat5 (x0, x1, x2, x3, x4) - as_nat5 (y0, y1, y2, y3, y4)); //assert_norm (pow56 * pow224 = pow2 280); //assert (as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow2 280 == as_nat5 (x0, x1, x2, x3, x4) - S.q); Lemmas.lemma_as_nat5 (x0, x1, x2, x3, x4); Lemmas.lemma_as_nat5 (t0, t1, t2, t3, t4); //assert (if v b4 = 0 then as_nat5 (x0, x1, x2, x3, x4) >= S.q else as_nat5 (x0, x1, x2, x3, x4) < S.q); assert (if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 else v b4 == 1); let (z0, z1, z2, z3, z4) = choose b4 (x0, x1, x2, x3, x4) (t0, t1, t2, t3, t4) in assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else v b4 == 1 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); (z0, z1, z2, z3, z4) inline_for_extraction noextract val carry56: x:uint64 -> Pure (uint64 & uint64) (requires v x <= pow2 57) (ensures fun (t, c) -> v t < pow56 /\ v c <= 2 /\ v x == v c * pow56 + v t) let carry56 x = let carry = x >>. 56ul in FStar.Math.Lemmas.pow2_minus 57 56; let t = x &. mask56 in assert_norm (pow2 56 < pow2 64); mod_mask_lemma x 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); t, carry inline_for_extraction noextract val add_modq5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < S.q /\ as_nat5 y < S.q) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (as_nat5 x + as_nat5 y) % S.q) let add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = assert_norm (pow56 - 1 + pow56 - 1 == pow2 57 - 2); let (t0, c0) = carry56 (x0 +! y0) in let (t1, c1) = carry56 (x1 +! y1 +! c0) in let (t2, c2) = carry56 (x2 +! y2 +! c1) in let (t3, c3) = carry56 (x3 +! y3 +! c2) in let t4 = x4 +! y4 +! c3 in assert (as_nat5 (t0, t1, t2, t3, t4) == as_nat5 (x0, x1, x2, x3, x4) + as_nat5 (y0, y1, y2, y3, y4)); let (o0, o1, o2, o3, o4) = subm_conditional (t0, t1, t2, t3, t4) in Lemmas.lemma_add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) (t0, t1, t2, t3, t4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry56_wide: x:uint128 -> Pure (uint128 & uint64) (requires v x < pow2 117) (ensures fun (c, t) -> v t < pow56 /\ v c < pow2 61 /\ v x - v c * pow56 == v t /\ v c == v x / pow56) let carry56_wide x = let carry = x >>. 56ul in let t = to_u64 x &. mask56 in assert_norm (pow2 56 < pow2 64); Math.Lemmas.lemma_div_lt_nat (v x) 117 56; mod_mask_lemma (to_u64 x) 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == (v x % pow2 64) % pow2 56); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v x) 56 64; assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); carry, t inline_for_extraction noextract val mul64_wide_5: (a:uint64) -> (b:uint64) -> Pure uint128 (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures fun z -> v z == v a * v b /\ v z <= pow2 112 - pow2 57 + 1 /\ v z < pow2 112) let mul64_wide_5 a b = let lemma_smaller (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) < pow2 112) = if v a = 0 || v b = 0 then () else calc (<) { v a * v b <: int; (<) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56) } v a * pow2 56; (<) { Math.Lemmas.lemma_mult_le_right (pow2 56) (v a) (pow2 56) } pow2 56 * pow2 56; (==) { assert_norm (pow2 56 * pow2 56 == pow2 112) } pow2 112; } in let lemma_le (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) <= pow2 112 - pow2 57 + 1) = if v a = 0 || v b = 0 then () else assert_norm (pow2 112 - pow2 57 + 1 >= 0); calc (<=) { v a * v b <: int; (<=) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56 - 1) } v a * (pow2 56 - 1); (<=) { Math.Lemmas.lemma_mult_le_right (pow2 56 - 1) (v a) (pow2 56 - 1) } (pow2 56 - 1) * (pow2 56 - 1); (==) { assert_norm ((pow2 56 - 1) * (pow2 56 - 1) == pow2 112 - pow2 57 + 1) } pow2 112 - pow2 57 + 1; } in lemma_le a b; lemma_smaller a b; mul64_wide a b inline_for_extraction noextract val add2: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112) (ensures fun z -> v z == v a + v b /\ v z <= pow2 116) let add2 a b = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b inline_for_extraction noextract val add3: (a:uint128) -> (b:uint128) -> (c:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 ) (ensures fun z -> v z == v a + v b + v c /\ v z <= pow2 116) let add3 a b c = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); a +. b +. c inline_for_extraction noextract val add4: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d /\ v z <= pow2 116) let add4 a b c d = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d) (pow2 128); a +. b +. c +. d inline_for_extraction noextract val add5: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> (e:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112 /\ v e < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d + v e/\ v z <= pow2 116) let add5 a b c d e = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d + v e) (pow2 128); a +. b +. c +. d +. e inline_for_extraction noextract val add_inner_carry: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a <= pow2 116 /\ v b < pow2 61) (ensures fun z -> v z == v a + v b /\ v z < pow2 117) let add_inner_carry a b = assert_norm (pow2 116 + pow2 61 < pow2 128); assert_norm (pow2 116 + pow2 61 < pow2 117); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b inline_for_extraction noextract val mul_5: x:qelem5 -> y:qelem5 -> Pure qelem_wide5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1)) (ensures fun r -> qelem_wide_fits5 r (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 r == as_nat5 x * as_nat5 y) let lemma_mult_distr_3 (a b c:nat) (n:nat) : Lemma ((a + b - c * pow2 56) * pow2 n == a * pow2 n + b * pow2 n - c * pow2 (n + 56)) = Math.Lemmas.distributivity_sub_left (a + b) (c * pow2 56) (pow2 n); Math.Lemmas.distributivity_add_left a b (pow2 n); Math.Lemmas.pow2_plus 56 n #set-options "--z3rlimit 300" let mul_5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let xy00 = mul64_wide_5 x0 y0 in let xy01 = mul64_wide_5 x0 y1 in let xy02 = mul64_wide_5 x0 y2 in let xy03 = mul64_wide_5 x0 y3 in let xy04 = mul64_wide_5 x0 y4 in let xy10 = mul64_wide_5 x1 y0 in let xy11 = mul64_wide_5 x1 y1 in let xy12 = mul64_wide_5 x1 y2 in let xy13 = mul64_wide_5 x1 y3 in let xy14 = mul64_wide_5 x1 y4 in let xy20 = mul64_wide_5 x2 y0 in let xy21 = mul64_wide_5 x2 y1 in let xy22 = mul64_wide_5 x2 y2 in let xy23 = mul64_wide_5 x2 y3 in let xy24 = mul64_wide_5 x2 y4 in let xy30 = mul64_wide_5 x3 y0 in let xy31 = mul64_wide_5 x3 y1 in let xy32 = mul64_wide_5 x3 y2 in let xy33 = mul64_wide_5 x3 y3 in let xy34 = mul64_wide_5 x3 y4 in let xy40 = mul64_wide_5 x4 y0 in let xy41 = mul64_wide_5 x4 y1 in let xy42 = mul64_wide_5 x4 y2 in let xy43 = mul64_wide_5 x4 y3 in let xy44 = mul64_wide_5 x4 y4 in let z0 = xy00 in // < pow2 112 let z1 = add2 xy01 xy10 in // < pow2 113 let z2 = add3 xy02 xy11 xy20 in // < pow2 114 let z3 = add4 xy03 xy12 xy21 xy30 in // < pow2 115 let z4 = add5 xy04 xy13 xy22 xy31 xy40 in // < pow2 116 let z5 = add4 xy14 xy23 xy32 xy41 in let z6 = add3 xy24 xy33 xy42 in let z7 = add2 xy34 xy43 in let z8 = xy44 in //(z0, z1, z2, z3, z4, z5, z6, z7, z8) assert_norm (pow2 112 < pow2 117); assert_norm (pow2 112 <= pow2 116); let (c0, t0) = carry56_wide z0 in let (c1, t1) = carry56_wide (add_inner_carry z1 c0) in let (c2, t2) = carry56_wide (add_inner_carry z2 c1) in let (c3, t3) = carry56_wide (add_inner_carry z3 c2) in let (c4, t4) = carry56_wide (add_inner_carry z4 c3) in let (c5, t5) = carry56_wide (add_inner_carry z5 c4) in let (c6, t6) = carry56_wide (add_inner_carry z6 c5) in let (c7, t7) = carry56_wide (add_inner_carry z7 c6) in let (c8, t8) = carry56_wide (add_inner_carry z8 c7) in let t9 = to_u64 c8 in let lemma_t9_fits () : Lemma (v t9 < pow2 56) = // This proof was built from the bottom. We have as a constraint that v c8 has to be < pow2 112 to satisfy the postcondition. // We compute each time the maximal value such that this postcondition is satisfied calc (<) { v c0; (<) { Math.Lemmas.lemma_div_lt_nat (v z0) 112 56 } pow2 56; }; calc (<) { v c1; (<) { assert_norm (2*(pow2 112 - pow2 57 + 1) + pow2 56 <= pow2 113); Math.Lemmas.lemma_div_lt_nat (v z1 + v c0) 113 56 } pow2 57; }; calc (<) { v c2; (<) { assert_norm (3*(pow2 112 - pow2 57 + 1) + pow2 57 <= pow2 114); Math.Lemmas.lemma_div_lt_nat (v z2 + v c1) 114 56 } pow2 58; }; calc (<=) { v c3; (<=) { assert_norm (4*(pow2 112 - pow2 57 + 1) + pow2 58 <= 31153781151208965410895007785680895); assert_norm (31153781151208965410895007785680895 / pow56 == 432345564227567610); Math.Lemmas.lemma_div_le (v z3 + v c2) 31153781151208965410895007785680895 (pow2 56) } 432345564227567610; }; calc (<=) { v c4; (<=) { assert_norm (5*(pow2 112 - pow2 57 + 1) + 432345564227567610 <= 25961484292674137854422105494388735); // (pow2 59 - 2) * pow56 assert_norm (25961484292674137854422105494388735 / pow56 == 360287970189639675); Math.Lemmas.lemma_div_le (v z4 + v c3) 25961484292674137854422105494388735 (pow2 56) } 360287970189639675; }; calc (<=) { v c5; (<=) { assert_norm (4*(pow2 112 - pow2 57 + 1) + 360287970189639675 <= 20769187434139310297949203203096575); Math.Lemmas.lemma_div_le (v z5 + v c4) 20769187434139310297949203203096575 (pow2 56); assert_norm (20769187434139310297949203203096575 / pow2 56 == pow2 58 - 4) } pow2 58 - 4; }; calc (<=) { v c6; (<=) { assert_norm (3*(pow2 112 - pow2 57 + 1) + pow2 58 - 4 <= 15576890575604482741476300911804415); Math.Lemmas.lemma_div_le (v z6 + v c5) 15576890575604482741476300911804415 (pow2 56); assert_norm (15576890575604482741476300911804415 / pow2 56 == 216172782113783805) } 216172782113783805; }; calc (<=) { v c7; (<=) { assert_norm (2*(pow2 112 - pow2 57 + 1) + 216172782113783805 <= 10384593717069655185003398620512255); // (pow2 57 - 1) * pow2 56 - 1 Math.Lemmas.lemma_div_le (v z7 + v c6) 10384593717069655185003398620512255 (pow2 56); assert_norm (10384593717069655185003398620512255 / pow2 56 == pow2 57 - 2) } pow2 57 - 2; }; calc (<) { v c8; (<) { Math.Lemmas.lemma_div_lt_nat (v z8 + v c7) 112 56 } pow2 56; }; assert_norm (pow2 56 < pow2 64); Math.Lemmas.small_mod (v c8) (pow2 64) in lemma_t9_fits(); calc (==) { wide_as_nat5 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) <: int; (==) { } v t0 + v t1 * pow56 + v t2 * pow112 + v t3 * pow168 + v t4 * pow224 + v t5 * pow280 + v t6 * pow336 + v t7 * pow392 + v t8 * pow448 + v t9 * pow504; (==) { assert_norm (pow2 61 < pow2 64); Math.Lemmas.small_mod (v c8) (pow2 64) } v z0 - v c0 * pow2 56 + (v z1 + v c0 - v c1 * pow2 56) * pow56 + (v z2 + v c1 - v c2 * pow2 56) * pow112 + (v z3 + v c2 - v c3 * pow2 56) * pow168 + (v z4 + v c3 - v c4 * pow2 56) * pow224 + (v z5 + v c4 - v c5 * pow2 56) * pow280 + (v z6 + v c5 - v c6 * pow2 56) * pow336 + (v z7 + v c6 - v c7 * pow2 56) * pow392 + (v z8 + v c7 - v c8 * pow2 56) * pow448 + v c8 * pow504; (==) { lemma_mult_distr_3 (v z1) (v c0) (v c1) 56; lemma_mult_distr_3 (v z2) (v c1) (v c2) 112; lemma_mult_distr_3 (v z3) (v c2) (v c3) 168; lemma_mult_distr_3 (v z4) (v c3) (v c4) 224; lemma_mult_distr_3 (v z5) (v c4) (v c5) 280; lemma_mult_distr_3 (v z6) (v c5) (v c6) 336; lemma_mult_distr_3 (v z7) (v c6) (v c7) 392; lemma_mult_distr_3 (v z8) (v c7) (v c8) 448 } v z0 + v z1 * pow56 + v z2 * pow112 + v z3 * pow168 + v z4 * pow224 + v z5 * pow280 + v z6 * pow336 + v z7 * pow392 + v z8 * pow448; (==) { calc (==) { v z1; (==) { } v x0 * v y1 + v x1 * v y0; }; calc (==) { v z2; (==) { } v x0 * v y2 + v x1 * v y1 + v x2 * v y0; }; calc (==) { v z3; (==) { } v x0 * v y3 + v x1 * v y2 + v x2 * v y1 + v x3 * v y0; }; calc (==) { v z4; (==) { } v x0 * v y4 + v x1 * v y3 + v x2 * v y2 + v x3 * v y1 + v x4 * v y0; }; calc (==) { v z5; (==) { } v x1 * v y4 + v x2 * v y3 + v x3 * v y2 + v x4 * v y1; }; calc (==) { v z6; (==) { } v x2 * v y4 + v x3 * v y3 + v x4 * v y2; }; calc (==) { v z7; (==) { } v x3 * v y4 + v x4 * v y3; }; calc (==) { v z8; (==) { } v x4 * v y4; } } v x0 * v y0 + (v x0 * v y1 + v x1 * v y0) * pow56 + (v x0 * v y2 + v x1 * v y1 + v x2 * v y0) * pow112 + (v x0 * v y3 + v x1 * v y2 + v x2 * v y1 + v x3 * v y0) * pow168 + (v x0 * v y4 + v x1 * v y3 + v x2 * v y2 + v x3 * v y1 + v x4 * v y0) * pow224 + (v x1 * v y4 + v x2 * v y3 + v x3 * v y2 + v x4 * v y1) * pow280 + (v x2 * v y4 + v x3 * v y3 + v x4 * v y2) * pow336 + (v x3 * v y4 + v x4 * v y3) * pow392 + (v x4 * v y4) * pow448; (==) { Lemmas.lemma_mul_qelem5 (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) } (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224) * (v y0 + v y1 * pow2 56 + v y2 * pow2 112 + v y3 * pow2 168 + v y4 * pow2 224); }; (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) inline_for_extraction noextract val low_mul_5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (as_nat5 x * as_nat5 y) % pow2 264) let low_mul_5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let xy00 = mul64_wide_5 x0 y0 in let xy01 = mul64_wide_5 x0 y1 in let xy02 = mul64_wide_5 x0 y2 in let xy03 = mul64_wide_5 x0 y3 in let xy04 = mul64_wide_5 x0 y4 in let xy10 = mul64_wide_5 x1 y0 in let xy11 = mul64_wide_5 x1 y1 in let xy12 = mul64_wide_5 x1 y2 in let xy13 = mul64_wide_5 x1 y3 in let xy20 = mul64_wide_5 x2 y0 in let xy21 = mul64_wide_5 x2 y1 in let xy22 = mul64_wide_5 x2 y2 in let xy30 = mul64_wide_5 x3 y0 in let xy31 = mul64_wide_5 x3 y1 in let xy40 = mul64_wide_5 x4 y0 in assert_norm (pow2 112 < pow2 117); let (c0, t0) = carry56_wide xy00 in let (c1, t1) = carry56_wide (add_inner_carry (add2 xy01 xy10) c0) in let (c2, t2) = carry56_wide (add_inner_carry (add3 xy02 xy11 xy20) c1) in let (c3, t3) = carry56_wide (add_inner_carry (add4 xy03 xy12 xy21 xy30) c2) in let t4 = to_u64 (add_inner_carry (add5 xy04 xy13 xy22 xy31 xy40) c3) &. mask40 in calc (==) { as_nat5 (t0, t1, t2, t3, t4) <: int; (==) { } v t0 + v t1 * pow56 + v t2 * pow112 + v t3 * pow168 + v t4 * pow224; (==) { } v xy00 - v c0 * pow2 56 + (v xy01 + v xy10 + v c0 - v c1 * pow2 56) * pow56 + (v xy02 + v xy11 + v xy20 + v c1 - v c2 * pow56) * pow112 + (v xy03 + v xy12 + v xy21 + v xy30 + v c2 - v c3 * pow56) * pow168 + v t4 * pow224; (==) { logand_mask (to_u64 (add_inner_carry (add5 xy04 xy13 xy22 xy31 xy40) c3)) mask40 40; Math.Lemmas.pow2_modulo_modulo_lemma_1 (v (add_inner_carry (add5 xy04 xy13 xy22 xy31 xy40) c3)) 40 64 } v x0 * v y0 + (v x0 * v y1 + v x1 * v y0) * pow56 + (v x0 * v y2 + v x1 * v y1 + v x2 * v y0) * pow112 + (v x0 * v y3 + v x1 * v y2 + v x2 * v y1 + v x3 * v y0 - v c3 * pow56) * pow168 + ((v x0 * v y4 + v x1 * v y3 + v x2 * v y2 + v x3 * v y1 + v x4 * v y0 + v c3) % pow2 40) * pow224; }; Lemmas.lemma_mul_5_low_264 (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4); (t0, t1, t2, t3, t4) inline_for_extraction noextract val div_2_24_step: x:uint64 -> y:uint64 -> Pure uint64 (requires v x < pow56 /\ v y < pow56) (ensures fun r -> v r < pow56 /\ v r == v x / pow2 24 + pow2 32 * (v y % pow2 24)) let div_2_24_step x y = let y' = (y &. u64 0xffffff) <<. 32ul in assert_norm (pow2 24 - 1 = 0xffffff); assert_norm (pow2 24 < pow2 64); mod_mask_lemma y 24ul; assert (v (mod_mask #U64 #SEC 24ul) == 0xffffff); assert (v (y &. u64 0xffffff) == v y % pow2 24); assert (v y' == (v y % pow2 24) * pow2 32); let x' = x >>. 24ul in FStar.Math.Lemmas.pow2_minus 56 24; assert (v x' < pow2 32); let z = x' |. y' in logor_disjoint x' y' 32; assert (v z == v x / pow2 24 + pow2 32 * (v y % pow2 24)); z inline_for_extraction noextract val div_248: x:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 x < pow2 512) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (wide_as_nat5 x) / pow2 248) let div_248 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = // x / pow2 248 == (x / pow2 224) / pow2 24 let z0 = div_2_24_step x4 x5 in let z1 = div_2_24_step x5 x6 in let z2 = div_2_24_step x6 x7 in let z3 = div_2_24_step x7 x8 in let z4 = div_2_24_step x8 x9 in assert (qelem_fits5 (z0, z1, z2, z3, z4) (1, 1, 1, 1, 1)); Lemmas.lemma_div248 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9); (z0, z1, z2, z3, z4) inline_for_extraction noextract val div_2_40_step: x:uint64 -> y:uint64 -> Pure uint64 (requires v x < pow56) (ensures fun z -> v z < pow56 /\ v z == v x / pow2 40 + pow2 16 * (v y % pow2 40)) let div_2_40_step x y = let y' = (y &. mask40) <<. 16ul in assert_norm (pow2 40 < pow2 64); mod_mask_lemma y 40ul; assert (v (mod_mask #U64 #SEC 40ul) == v mask40); assert (v y' == (v y % pow2 40) * pow2 16); let x' = x >>. 40ul in FStar.Math.Lemmas.pow2_minus 56 40; assert (v x' == v x / pow2 40); assert (v x' < pow2 16); let z = x' |. y' in logor_disjoint x' y' 16; z inline_for_extraction noextract val div_264: x:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 x < pow2 528) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (wide_as_nat5 x) / pow2 264)
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.BignumQ.Mul.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 300, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Hacl.Spec.BignumQ.Definitions.qelem_wide5 -> Prims.Pure Hacl.Spec.BignumQ.Definitions.qelem5
Prims.Pure
[]
[]
[ "Hacl.Spec.BignumQ.Definitions.qelem_wide5", "Lib.IntTypes.uint64", "FStar.Pervasives.Native.Mktuple5", "Prims.unit", "Hacl.Spec.BignumQ.Lemmas.lemma_div264", "FStar.Pervasives.Native.Mktuple10", "Prims._assert", "Hacl.Spec.BignumQ.Definitions.qelem_fits5", "Prims.nat", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Hacl.Spec.BignumQ.Mul.div_2_40_step", "Hacl.Spec.BignumQ.Definitions.qelem5" ]
[]
false
false
false
false
false
let div_264 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) =
let z0 = div_2_40_step x4 x5 in let z1 = div_2_40_step x5 x6 in let z2 = div_2_40_step x6 x7 in let z3 = div_2_40_step x7 x8 in let z4 = div_2_40_step x8 x9 in assert (qelem_fits5 (z0, z1, z2, z3, z4) (1, 1, 1, 1, 1)); Lemmas.lemma_div264 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9); (z0, z1, z2, z3, z4)
false
Hacl.Spec.BignumQ.Mul.fst
Hacl.Spec.BignumQ.Mul.div_2_40_step
val div_2_40_step: x:uint64 -> y:uint64 -> Pure uint64 (requires v x < pow56) (ensures fun z -> v z < pow56 /\ v z == v x / pow2 40 + pow2 16 * (v y % pow2 40))
val div_2_40_step: x:uint64 -> y:uint64 -> Pure uint64 (requires v x < pow56) (ensures fun z -> v z < pow56 /\ v z == v x / pow2 40 + pow2 16 * (v y % pow2 40))
let div_2_40_step x y = let y' = (y &. mask40) <<. 16ul in assert_norm (pow2 40 < pow2 64); mod_mask_lemma y 40ul; assert (v (mod_mask #U64 #SEC 40ul) == v mask40); assert (v y' == (v y % pow2 40) * pow2 16); let x' = x >>. 40ul in FStar.Math.Lemmas.pow2_minus 56 40; assert (v x' == v x / pow2 40); assert (v x' < pow2 16); let z = x' |. y' in logor_disjoint x' y' 16; z
{ "file_name": "code/ed25519/Hacl.Spec.BignumQ.Mul.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 697, "start_col": 0, "start_line": 684 }
module Hacl.Spec.BignumQ.Mul open FStar.Mul open Lib.IntTypes module S = Spec.Ed25519 module Lemmas = Hacl.Spec.BignumQ.Lemmas include Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask56 : x:uint64{v x == pow2 56 - 1} = assert_norm (pow2 56 - 1 == 0xffffffffffffff); u64 0xffffffffffffff inline_for_extraction noextract let mask40 : x:uint64{v x == pow2 40 - 1} = assert_norm (pow2 40 - 1 == 0xffffffffff); u64 0xffffffffff inline_for_extraction noextract val make_m: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == S.q} let make_m () = let m0 = u64 0x12631a5cf5d3ed in let m1 = u64 0xf9dea2f79cd658 in let m2 = u64 0x000000000014de in let m3 = u64 0x00000000000000 in let m4 = u64 0x00000010000000 in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val make_mu: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == pow2 512 / S.q} let make_mu m = let m0 = u64 0x9ce5a30a2c131b in let m1 = u64 0x215d086329a7ed in let m2 = u64 0xffffffffeb2106 in let m3 = u64 0xffffffffffffff in let m4 = u64 0x00000fffffffff in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == pow2 512 / S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val choose: b:uint64 -> x:qelem5 -> y:qelem5 -> Pure qelem5 (requires v b == 0 \/ v b == 1) (ensures fun z -> if v b = 1 then z == x else z == y) let choose b (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let mask = b -. u64 1 in let z0 = x0 ^. (mask &. (x0 ^. y0)) in Lemmas.lemma_choose_step b x0 y0; let z1 = x1 ^. (mask &. (x1 ^. y1)) in Lemmas.lemma_choose_step b x1 y1; let z2 = x2 ^. (mask &. (x2 ^. y2)) in Lemmas.lemma_choose_step b x2 y2; let z3 = x3 ^. (mask &. (x3 ^. y3)) in Lemmas.lemma_choose_step b x3 y3; let z4 = x4 ^. (mask &. (x4 ^. y4)) in Lemmas.lemma_choose_step b x4 y4; (z0, z1, z2, z3, z4) inline_for_extraction noextract val subm_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow56 /\ v y <= pow56) (ensures fun (b, t) -> v b <= 1 /\ qelem_fits1 t 1 /\ v x - v y == v t - v b * pow56) let subm_step x y = let b = (x -. y) >>. 63ul in //assert (if v x >= v y then v b == 0 else v b == 1); let lshift56 = (b <<. 56ul) in //assert (if v x >= v y then v lshift56 == 0 else v lshift56 == pow56); //assert (v lshift56 == v b * pow56); //assert (v ((b <<. 56ul) +! x) == v b * pow56 + v x); let t = ((b <<. 56ul) +! x) -! y in b, t inline_for_extraction noextract val subm_conditional: x:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ (if as_nat5 x >= S.q then as_nat5 r == as_nat5 x - S.q else as_nat5 r == as_nat5 x)) let subm_conditional (x0, x1, x2, x3, x4) = let (y0, y1, y2, y3, y4) = make_m () in let (b0, t0) = subm_step x0 y0 in assert (v x0 - v y0 == v t0 - v b0 * pow56); let (b1, t1) = subm_step x1 (y1 +! b0) in assert (v x1 - v y1 - v b0 == v t1 - v b1 * pow56); let (b2, t2) = subm_step x2 (y2 +! b1) in assert (v x2 - v y2 - v b1 == v t2 - v b2 * pow56); let (b3, t3) = subm_step x3 (y3 +! b2) in assert (v x3 - v y3 - v b2 == v t3 - v b3 * pow56); let (b4, t4) = subm_step x4 (y4 +! b3) in assert (v x4 - v y4 - v b3 == v t4 - v b4 * pow56); Lemmas.lemma_subm_conditional (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) (v b0) (v b1) (v b2) (v b3) (v b4); assert ( as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow56 * pow224 == as_nat5 (x0, x1, x2, x3, x4) - as_nat5 (y0, y1, y2, y3, y4)); //assert_norm (pow56 * pow224 = pow2 280); //assert (as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow2 280 == as_nat5 (x0, x1, x2, x3, x4) - S.q); Lemmas.lemma_as_nat5 (x0, x1, x2, x3, x4); Lemmas.lemma_as_nat5 (t0, t1, t2, t3, t4); //assert (if v b4 = 0 then as_nat5 (x0, x1, x2, x3, x4) >= S.q else as_nat5 (x0, x1, x2, x3, x4) < S.q); assert (if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 else v b4 == 1); let (z0, z1, z2, z3, z4) = choose b4 (x0, x1, x2, x3, x4) (t0, t1, t2, t3, t4) in assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else v b4 == 1 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); (z0, z1, z2, z3, z4) inline_for_extraction noextract val carry56: x:uint64 -> Pure (uint64 & uint64) (requires v x <= pow2 57) (ensures fun (t, c) -> v t < pow56 /\ v c <= 2 /\ v x == v c * pow56 + v t) let carry56 x = let carry = x >>. 56ul in FStar.Math.Lemmas.pow2_minus 57 56; let t = x &. mask56 in assert_norm (pow2 56 < pow2 64); mod_mask_lemma x 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); t, carry inline_for_extraction noextract val add_modq5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < S.q /\ as_nat5 y < S.q) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (as_nat5 x + as_nat5 y) % S.q) let add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = assert_norm (pow56 - 1 + pow56 - 1 == pow2 57 - 2); let (t0, c0) = carry56 (x0 +! y0) in let (t1, c1) = carry56 (x1 +! y1 +! c0) in let (t2, c2) = carry56 (x2 +! y2 +! c1) in let (t3, c3) = carry56 (x3 +! y3 +! c2) in let t4 = x4 +! y4 +! c3 in assert (as_nat5 (t0, t1, t2, t3, t4) == as_nat5 (x0, x1, x2, x3, x4) + as_nat5 (y0, y1, y2, y3, y4)); let (o0, o1, o2, o3, o4) = subm_conditional (t0, t1, t2, t3, t4) in Lemmas.lemma_add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) (t0, t1, t2, t3, t4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry56_wide: x:uint128 -> Pure (uint128 & uint64) (requires v x < pow2 117) (ensures fun (c, t) -> v t < pow56 /\ v c < pow2 61 /\ v x - v c * pow56 == v t /\ v c == v x / pow56) let carry56_wide x = let carry = x >>. 56ul in let t = to_u64 x &. mask56 in assert_norm (pow2 56 < pow2 64); Math.Lemmas.lemma_div_lt_nat (v x) 117 56; mod_mask_lemma (to_u64 x) 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == (v x % pow2 64) % pow2 56); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v x) 56 64; assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); carry, t inline_for_extraction noextract val mul64_wide_5: (a:uint64) -> (b:uint64) -> Pure uint128 (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures fun z -> v z == v a * v b /\ v z <= pow2 112 - pow2 57 + 1 /\ v z < pow2 112) let mul64_wide_5 a b = let lemma_smaller (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) < pow2 112) = if v a = 0 || v b = 0 then () else calc (<) { v a * v b <: int; (<) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56) } v a * pow2 56; (<) { Math.Lemmas.lemma_mult_le_right (pow2 56) (v a) (pow2 56) } pow2 56 * pow2 56; (==) { assert_norm (pow2 56 * pow2 56 == pow2 112) } pow2 112; } in let lemma_le (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) <= pow2 112 - pow2 57 + 1) = if v a = 0 || v b = 0 then () else assert_norm (pow2 112 - pow2 57 + 1 >= 0); calc (<=) { v a * v b <: int; (<=) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56 - 1) } v a * (pow2 56 - 1); (<=) { Math.Lemmas.lemma_mult_le_right (pow2 56 - 1) (v a) (pow2 56 - 1) } (pow2 56 - 1) * (pow2 56 - 1); (==) { assert_norm ((pow2 56 - 1) * (pow2 56 - 1) == pow2 112 - pow2 57 + 1) } pow2 112 - pow2 57 + 1; } in lemma_le a b; lemma_smaller a b; mul64_wide a b inline_for_extraction noextract val add2: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112) (ensures fun z -> v z == v a + v b /\ v z <= pow2 116) let add2 a b = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b inline_for_extraction noextract val add3: (a:uint128) -> (b:uint128) -> (c:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 ) (ensures fun z -> v z == v a + v b + v c /\ v z <= pow2 116) let add3 a b c = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); a +. b +. c inline_for_extraction noextract val add4: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d /\ v z <= pow2 116) let add4 a b c d = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d) (pow2 128); a +. b +. c +. d inline_for_extraction noextract val add5: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> (e:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112 /\ v e < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d + v e/\ v z <= pow2 116) let add5 a b c d e = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d + v e) (pow2 128); a +. b +. c +. d +. e inline_for_extraction noextract val add_inner_carry: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a <= pow2 116 /\ v b < pow2 61) (ensures fun z -> v z == v a + v b /\ v z < pow2 117) let add_inner_carry a b = assert_norm (pow2 116 + pow2 61 < pow2 128); assert_norm (pow2 116 + pow2 61 < pow2 117); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b inline_for_extraction noextract val mul_5: x:qelem5 -> y:qelem5 -> Pure qelem_wide5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1)) (ensures fun r -> qelem_wide_fits5 r (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 r == as_nat5 x * as_nat5 y) let lemma_mult_distr_3 (a b c:nat) (n:nat) : Lemma ((a + b - c * pow2 56) * pow2 n == a * pow2 n + b * pow2 n - c * pow2 (n + 56)) = Math.Lemmas.distributivity_sub_left (a + b) (c * pow2 56) (pow2 n); Math.Lemmas.distributivity_add_left a b (pow2 n); Math.Lemmas.pow2_plus 56 n #set-options "--z3rlimit 300" let mul_5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let xy00 = mul64_wide_5 x0 y0 in let xy01 = mul64_wide_5 x0 y1 in let xy02 = mul64_wide_5 x0 y2 in let xy03 = mul64_wide_5 x0 y3 in let xy04 = mul64_wide_5 x0 y4 in let xy10 = mul64_wide_5 x1 y0 in let xy11 = mul64_wide_5 x1 y1 in let xy12 = mul64_wide_5 x1 y2 in let xy13 = mul64_wide_5 x1 y3 in let xy14 = mul64_wide_5 x1 y4 in let xy20 = mul64_wide_5 x2 y0 in let xy21 = mul64_wide_5 x2 y1 in let xy22 = mul64_wide_5 x2 y2 in let xy23 = mul64_wide_5 x2 y3 in let xy24 = mul64_wide_5 x2 y4 in let xy30 = mul64_wide_5 x3 y0 in let xy31 = mul64_wide_5 x3 y1 in let xy32 = mul64_wide_5 x3 y2 in let xy33 = mul64_wide_5 x3 y3 in let xy34 = mul64_wide_5 x3 y4 in let xy40 = mul64_wide_5 x4 y0 in let xy41 = mul64_wide_5 x4 y1 in let xy42 = mul64_wide_5 x4 y2 in let xy43 = mul64_wide_5 x4 y3 in let xy44 = mul64_wide_5 x4 y4 in let z0 = xy00 in // < pow2 112 let z1 = add2 xy01 xy10 in // < pow2 113 let z2 = add3 xy02 xy11 xy20 in // < pow2 114 let z3 = add4 xy03 xy12 xy21 xy30 in // < pow2 115 let z4 = add5 xy04 xy13 xy22 xy31 xy40 in // < pow2 116 let z5 = add4 xy14 xy23 xy32 xy41 in let z6 = add3 xy24 xy33 xy42 in let z7 = add2 xy34 xy43 in let z8 = xy44 in //(z0, z1, z2, z3, z4, z5, z6, z7, z8) assert_norm (pow2 112 < pow2 117); assert_norm (pow2 112 <= pow2 116); let (c0, t0) = carry56_wide z0 in let (c1, t1) = carry56_wide (add_inner_carry z1 c0) in let (c2, t2) = carry56_wide (add_inner_carry z2 c1) in let (c3, t3) = carry56_wide (add_inner_carry z3 c2) in let (c4, t4) = carry56_wide (add_inner_carry z4 c3) in let (c5, t5) = carry56_wide (add_inner_carry z5 c4) in let (c6, t6) = carry56_wide (add_inner_carry z6 c5) in let (c7, t7) = carry56_wide (add_inner_carry z7 c6) in let (c8, t8) = carry56_wide (add_inner_carry z8 c7) in let t9 = to_u64 c8 in let lemma_t9_fits () : Lemma (v t9 < pow2 56) = // This proof was built from the bottom. We have as a constraint that v c8 has to be < pow2 112 to satisfy the postcondition. // We compute each time the maximal value such that this postcondition is satisfied calc (<) { v c0; (<) { Math.Lemmas.lemma_div_lt_nat (v z0) 112 56 } pow2 56; }; calc (<) { v c1; (<) { assert_norm (2*(pow2 112 - pow2 57 + 1) + pow2 56 <= pow2 113); Math.Lemmas.lemma_div_lt_nat (v z1 + v c0) 113 56 } pow2 57; }; calc (<) { v c2; (<) { assert_norm (3*(pow2 112 - pow2 57 + 1) + pow2 57 <= pow2 114); Math.Lemmas.lemma_div_lt_nat (v z2 + v c1) 114 56 } pow2 58; }; calc (<=) { v c3; (<=) { assert_norm (4*(pow2 112 - pow2 57 + 1) + pow2 58 <= 31153781151208965410895007785680895); assert_norm (31153781151208965410895007785680895 / pow56 == 432345564227567610); Math.Lemmas.lemma_div_le (v z3 + v c2) 31153781151208965410895007785680895 (pow2 56) } 432345564227567610; }; calc (<=) { v c4; (<=) { assert_norm (5*(pow2 112 - pow2 57 + 1) + 432345564227567610 <= 25961484292674137854422105494388735); // (pow2 59 - 2) * pow56 assert_norm (25961484292674137854422105494388735 / pow56 == 360287970189639675); Math.Lemmas.lemma_div_le (v z4 + v c3) 25961484292674137854422105494388735 (pow2 56) } 360287970189639675; }; calc (<=) { v c5; (<=) { assert_norm (4*(pow2 112 - pow2 57 + 1) + 360287970189639675 <= 20769187434139310297949203203096575); Math.Lemmas.lemma_div_le (v z5 + v c4) 20769187434139310297949203203096575 (pow2 56); assert_norm (20769187434139310297949203203096575 / pow2 56 == pow2 58 - 4) } pow2 58 - 4; }; calc (<=) { v c6; (<=) { assert_norm (3*(pow2 112 - pow2 57 + 1) + pow2 58 - 4 <= 15576890575604482741476300911804415); Math.Lemmas.lemma_div_le (v z6 + v c5) 15576890575604482741476300911804415 (pow2 56); assert_norm (15576890575604482741476300911804415 / pow2 56 == 216172782113783805) } 216172782113783805; }; calc (<=) { v c7; (<=) { assert_norm (2*(pow2 112 - pow2 57 + 1) + 216172782113783805 <= 10384593717069655185003398620512255); // (pow2 57 - 1) * pow2 56 - 1 Math.Lemmas.lemma_div_le (v z7 + v c6) 10384593717069655185003398620512255 (pow2 56); assert_norm (10384593717069655185003398620512255 / pow2 56 == pow2 57 - 2) } pow2 57 - 2; }; calc (<) { v c8; (<) { Math.Lemmas.lemma_div_lt_nat (v z8 + v c7) 112 56 } pow2 56; }; assert_norm (pow2 56 < pow2 64); Math.Lemmas.small_mod (v c8) (pow2 64) in lemma_t9_fits(); calc (==) { wide_as_nat5 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) <: int; (==) { } v t0 + v t1 * pow56 + v t2 * pow112 + v t3 * pow168 + v t4 * pow224 + v t5 * pow280 + v t6 * pow336 + v t7 * pow392 + v t8 * pow448 + v t9 * pow504; (==) { assert_norm (pow2 61 < pow2 64); Math.Lemmas.small_mod (v c8) (pow2 64) } v z0 - v c0 * pow2 56 + (v z1 + v c0 - v c1 * pow2 56) * pow56 + (v z2 + v c1 - v c2 * pow2 56) * pow112 + (v z3 + v c2 - v c3 * pow2 56) * pow168 + (v z4 + v c3 - v c4 * pow2 56) * pow224 + (v z5 + v c4 - v c5 * pow2 56) * pow280 + (v z6 + v c5 - v c6 * pow2 56) * pow336 + (v z7 + v c6 - v c7 * pow2 56) * pow392 + (v z8 + v c7 - v c8 * pow2 56) * pow448 + v c8 * pow504; (==) { lemma_mult_distr_3 (v z1) (v c0) (v c1) 56; lemma_mult_distr_3 (v z2) (v c1) (v c2) 112; lemma_mult_distr_3 (v z3) (v c2) (v c3) 168; lemma_mult_distr_3 (v z4) (v c3) (v c4) 224; lemma_mult_distr_3 (v z5) (v c4) (v c5) 280; lemma_mult_distr_3 (v z6) (v c5) (v c6) 336; lemma_mult_distr_3 (v z7) (v c6) (v c7) 392; lemma_mult_distr_3 (v z8) (v c7) (v c8) 448 } v z0 + v z1 * pow56 + v z2 * pow112 + v z3 * pow168 + v z4 * pow224 + v z5 * pow280 + v z6 * pow336 + v z7 * pow392 + v z8 * pow448; (==) { calc (==) { v z1; (==) { } v x0 * v y1 + v x1 * v y0; }; calc (==) { v z2; (==) { } v x0 * v y2 + v x1 * v y1 + v x2 * v y0; }; calc (==) { v z3; (==) { } v x0 * v y3 + v x1 * v y2 + v x2 * v y1 + v x3 * v y0; }; calc (==) { v z4; (==) { } v x0 * v y4 + v x1 * v y3 + v x2 * v y2 + v x3 * v y1 + v x4 * v y0; }; calc (==) { v z5; (==) { } v x1 * v y4 + v x2 * v y3 + v x3 * v y2 + v x4 * v y1; }; calc (==) { v z6; (==) { } v x2 * v y4 + v x3 * v y3 + v x4 * v y2; }; calc (==) { v z7; (==) { } v x3 * v y4 + v x4 * v y3; }; calc (==) { v z8; (==) { } v x4 * v y4; } } v x0 * v y0 + (v x0 * v y1 + v x1 * v y0) * pow56 + (v x0 * v y2 + v x1 * v y1 + v x2 * v y0) * pow112 + (v x0 * v y3 + v x1 * v y2 + v x2 * v y1 + v x3 * v y0) * pow168 + (v x0 * v y4 + v x1 * v y3 + v x2 * v y2 + v x3 * v y1 + v x4 * v y0) * pow224 + (v x1 * v y4 + v x2 * v y3 + v x3 * v y2 + v x4 * v y1) * pow280 + (v x2 * v y4 + v x3 * v y3 + v x4 * v y2) * pow336 + (v x3 * v y4 + v x4 * v y3) * pow392 + (v x4 * v y4) * pow448; (==) { Lemmas.lemma_mul_qelem5 (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) } (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224) * (v y0 + v y1 * pow2 56 + v y2 * pow2 112 + v y3 * pow2 168 + v y4 * pow2 224); }; (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) inline_for_extraction noextract val low_mul_5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (as_nat5 x * as_nat5 y) % pow2 264) let low_mul_5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let xy00 = mul64_wide_5 x0 y0 in let xy01 = mul64_wide_5 x0 y1 in let xy02 = mul64_wide_5 x0 y2 in let xy03 = mul64_wide_5 x0 y3 in let xy04 = mul64_wide_5 x0 y4 in let xy10 = mul64_wide_5 x1 y0 in let xy11 = mul64_wide_5 x1 y1 in let xy12 = mul64_wide_5 x1 y2 in let xy13 = mul64_wide_5 x1 y3 in let xy20 = mul64_wide_5 x2 y0 in let xy21 = mul64_wide_5 x2 y1 in let xy22 = mul64_wide_5 x2 y2 in let xy30 = mul64_wide_5 x3 y0 in let xy31 = mul64_wide_5 x3 y1 in let xy40 = mul64_wide_5 x4 y0 in assert_norm (pow2 112 < pow2 117); let (c0, t0) = carry56_wide xy00 in let (c1, t1) = carry56_wide (add_inner_carry (add2 xy01 xy10) c0) in let (c2, t2) = carry56_wide (add_inner_carry (add3 xy02 xy11 xy20) c1) in let (c3, t3) = carry56_wide (add_inner_carry (add4 xy03 xy12 xy21 xy30) c2) in let t4 = to_u64 (add_inner_carry (add5 xy04 xy13 xy22 xy31 xy40) c3) &. mask40 in calc (==) { as_nat5 (t0, t1, t2, t3, t4) <: int; (==) { } v t0 + v t1 * pow56 + v t2 * pow112 + v t3 * pow168 + v t4 * pow224; (==) { } v xy00 - v c0 * pow2 56 + (v xy01 + v xy10 + v c0 - v c1 * pow2 56) * pow56 + (v xy02 + v xy11 + v xy20 + v c1 - v c2 * pow56) * pow112 + (v xy03 + v xy12 + v xy21 + v xy30 + v c2 - v c3 * pow56) * pow168 + v t4 * pow224; (==) { logand_mask (to_u64 (add_inner_carry (add5 xy04 xy13 xy22 xy31 xy40) c3)) mask40 40; Math.Lemmas.pow2_modulo_modulo_lemma_1 (v (add_inner_carry (add5 xy04 xy13 xy22 xy31 xy40) c3)) 40 64 } v x0 * v y0 + (v x0 * v y1 + v x1 * v y0) * pow56 + (v x0 * v y2 + v x1 * v y1 + v x2 * v y0) * pow112 + (v x0 * v y3 + v x1 * v y2 + v x2 * v y1 + v x3 * v y0 - v c3 * pow56) * pow168 + ((v x0 * v y4 + v x1 * v y3 + v x2 * v y2 + v x3 * v y1 + v x4 * v y0 + v c3) % pow2 40) * pow224; }; Lemmas.lemma_mul_5_low_264 (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4); (t0, t1, t2, t3, t4) inline_for_extraction noextract val div_2_24_step: x:uint64 -> y:uint64 -> Pure uint64 (requires v x < pow56 /\ v y < pow56) (ensures fun r -> v r < pow56 /\ v r == v x / pow2 24 + pow2 32 * (v y % pow2 24)) let div_2_24_step x y = let y' = (y &. u64 0xffffff) <<. 32ul in assert_norm (pow2 24 - 1 = 0xffffff); assert_norm (pow2 24 < pow2 64); mod_mask_lemma y 24ul; assert (v (mod_mask #U64 #SEC 24ul) == 0xffffff); assert (v (y &. u64 0xffffff) == v y % pow2 24); assert (v y' == (v y % pow2 24) * pow2 32); let x' = x >>. 24ul in FStar.Math.Lemmas.pow2_minus 56 24; assert (v x' < pow2 32); let z = x' |. y' in logor_disjoint x' y' 32; assert (v z == v x / pow2 24 + pow2 32 * (v y % pow2 24)); z inline_for_extraction noextract val div_248: x:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 x < pow2 512) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (wide_as_nat5 x) / pow2 248) let div_248 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = // x / pow2 248 == (x / pow2 224) / pow2 24 let z0 = div_2_24_step x4 x5 in let z1 = div_2_24_step x5 x6 in let z2 = div_2_24_step x6 x7 in let z3 = div_2_24_step x7 x8 in let z4 = div_2_24_step x8 x9 in assert (qelem_fits5 (z0, z1, z2, z3, z4) (1, 1, 1, 1, 1)); Lemmas.lemma_div248 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9); (z0, z1, z2, z3, z4) inline_for_extraction noextract val div_2_40_step: x:uint64 -> y:uint64 -> Pure uint64 (requires v x < pow56) (ensures fun z -> v z < pow56 /\ v z == v x / pow2 40 + pow2 16 * (v y % pow2 40))
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.BignumQ.Mul.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 300, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Lib.IntTypes.uint64 -> y: Lib.IntTypes.uint64 -> Prims.Pure Lib.IntTypes.uint64
Prims.Pure
[]
[]
[ "Lib.IntTypes.uint64", "Prims.unit", "Lib.IntTypes.logor_disjoint", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Bar_Dot", "Prims._assert", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Prims.pow2", "Prims.eq2", "Prims.int", "Prims.op_Division", "FStar.Math.Lemmas.pow2_minus", "Lib.IntTypes.op_Greater_Greater_Dot", "FStar.UInt32.__uint_to_t", "FStar.Mul.op_Star", "Prims.op_Modulus", "Lib.IntTypes.range_t", "Lib.IntTypes.mod_mask", "Hacl.Spec.BignumQ.Mul.mask40", "Lib.IntTypes.mod_mask_lemma", "FStar.Pervasives.assert_norm", "Lib.IntTypes.op_Less_Less_Dot", "Lib.IntTypes.op_Amp_Dot" ]
[]
false
false
false
false
false
let div_2_40_step x y =
let y' = (y &. mask40) <<. 16ul in assert_norm (pow2 40 < pow2 64); mod_mask_lemma y 40ul; assert (v (mod_mask #U64 #SEC 40ul) == v mask40); assert (v y' == (v y % pow2 40) * pow2 16); let x' = x >>. 40ul in FStar.Math.Lemmas.pow2_minus 56 40; assert (v x' == v x / pow2 40); assert (v x' < pow2 16); let z = x' |. y' in logor_disjoint x' y' 16; z
false
Hacl.Spec.BignumQ.Mul.fst
Hacl.Spec.BignumQ.Mul.mul_modq5
val mul_modq5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < pow2 256 /\ as_nat5 y < pow2 256) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (as_nat5 x * as_nat5 y) % S.q)
val mul_modq5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < pow2 256 /\ as_nat5 y < pow2 256) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (as_nat5 x * as_nat5 y) % S.q)
let mul_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let (r0, r1, r2, r3, r4, r5, r6, r7, r8, r9) = mul_5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) in Lemmas.lemma_mul_lt (as_nat5 (x0, x1, x2, x3, x4)) (pow2 256) (as_nat5 (y0, y1, y2, y3, y4)) (pow2 256); assert_norm (pow2 256 * pow2 256 = pow2 512); let (o0, o1, o2, o3, o4) = barrett_reduction5 (r0, r1, r2, r3, r4, r5, r6, r7, r8, r9) in (o0, o1, o2, o3, o4)
{ "file_name": "code/ed25519/Hacl.Spec.BignumQ.Mul.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 22, "end_line": 862, "start_col": 0, "start_line": 857 }
module Hacl.Spec.BignumQ.Mul open FStar.Mul open Lib.IntTypes module S = Spec.Ed25519 module Lemmas = Hacl.Spec.BignumQ.Lemmas include Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask56 : x:uint64{v x == pow2 56 - 1} = assert_norm (pow2 56 - 1 == 0xffffffffffffff); u64 0xffffffffffffff inline_for_extraction noextract let mask40 : x:uint64{v x == pow2 40 - 1} = assert_norm (pow2 40 - 1 == 0xffffffffff); u64 0xffffffffff inline_for_extraction noextract val make_m: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == S.q} let make_m () = let m0 = u64 0x12631a5cf5d3ed in let m1 = u64 0xf9dea2f79cd658 in let m2 = u64 0x000000000014de in let m3 = u64 0x00000000000000 in let m4 = u64 0x00000010000000 in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val make_mu: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == pow2 512 / S.q} let make_mu m = let m0 = u64 0x9ce5a30a2c131b in let m1 = u64 0x215d086329a7ed in let m2 = u64 0xffffffffeb2106 in let m3 = u64 0xffffffffffffff in let m4 = u64 0x00000fffffffff in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == pow2 512 / S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val choose: b:uint64 -> x:qelem5 -> y:qelem5 -> Pure qelem5 (requires v b == 0 \/ v b == 1) (ensures fun z -> if v b = 1 then z == x else z == y) let choose b (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let mask = b -. u64 1 in let z0 = x0 ^. (mask &. (x0 ^. y0)) in Lemmas.lemma_choose_step b x0 y0; let z1 = x1 ^. (mask &. (x1 ^. y1)) in Lemmas.lemma_choose_step b x1 y1; let z2 = x2 ^. (mask &. (x2 ^. y2)) in Lemmas.lemma_choose_step b x2 y2; let z3 = x3 ^. (mask &. (x3 ^. y3)) in Lemmas.lemma_choose_step b x3 y3; let z4 = x4 ^. (mask &. (x4 ^. y4)) in Lemmas.lemma_choose_step b x4 y4; (z0, z1, z2, z3, z4) inline_for_extraction noextract val subm_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow56 /\ v y <= pow56) (ensures fun (b, t) -> v b <= 1 /\ qelem_fits1 t 1 /\ v x - v y == v t - v b * pow56) let subm_step x y = let b = (x -. y) >>. 63ul in //assert (if v x >= v y then v b == 0 else v b == 1); let lshift56 = (b <<. 56ul) in //assert (if v x >= v y then v lshift56 == 0 else v lshift56 == pow56); //assert (v lshift56 == v b * pow56); //assert (v ((b <<. 56ul) +! x) == v b * pow56 + v x); let t = ((b <<. 56ul) +! x) -! y in b, t inline_for_extraction noextract val subm_conditional: x:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ (if as_nat5 x >= S.q then as_nat5 r == as_nat5 x - S.q else as_nat5 r == as_nat5 x)) let subm_conditional (x0, x1, x2, x3, x4) = let (y0, y1, y2, y3, y4) = make_m () in let (b0, t0) = subm_step x0 y0 in assert (v x0 - v y0 == v t0 - v b0 * pow56); let (b1, t1) = subm_step x1 (y1 +! b0) in assert (v x1 - v y1 - v b0 == v t1 - v b1 * pow56); let (b2, t2) = subm_step x2 (y2 +! b1) in assert (v x2 - v y2 - v b1 == v t2 - v b2 * pow56); let (b3, t3) = subm_step x3 (y3 +! b2) in assert (v x3 - v y3 - v b2 == v t3 - v b3 * pow56); let (b4, t4) = subm_step x4 (y4 +! b3) in assert (v x4 - v y4 - v b3 == v t4 - v b4 * pow56); Lemmas.lemma_subm_conditional (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) (v b0) (v b1) (v b2) (v b3) (v b4); assert ( as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow56 * pow224 == as_nat5 (x0, x1, x2, x3, x4) - as_nat5 (y0, y1, y2, y3, y4)); //assert_norm (pow56 * pow224 = pow2 280); //assert (as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow2 280 == as_nat5 (x0, x1, x2, x3, x4) - S.q); Lemmas.lemma_as_nat5 (x0, x1, x2, x3, x4); Lemmas.lemma_as_nat5 (t0, t1, t2, t3, t4); //assert (if v b4 = 0 then as_nat5 (x0, x1, x2, x3, x4) >= S.q else as_nat5 (x0, x1, x2, x3, x4) < S.q); assert (if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 else v b4 == 1); let (z0, z1, z2, z3, z4) = choose b4 (x0, x1, x2, x3, x4) (t0, t1, t2, t3, t4) in assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else v b4 == 1 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); (z0, z1, z2, z3, z4) inline_for_extraction noextract val carry56: x:uint64 -> Pure (uint64 & uint64) (requires v x <= pow2 57) (ensures fun (t, c) -> v t < pow56 /\ v c <= 2 /\ v x == v c * pow56 + v t) let carry56 x = let carry = x >>. 56ul in FStar.Math.Lemmas.pow2_minus 57 56; let t = x &. mask56 in assert_norm (pow2 56 < pow2 64); mod_mask_lemma x 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); t, carry inline_for_extraction noextract val add_modq5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < S.q /\ as_nat5 y < S.q) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (as_nat5 x + as_nat5 y) % S.q) let add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = assert_norm (pow56 - 1 + pow56 - 1 == pow2 57 - 2); let (t0, c0) = carry56 (x0 +! y0) in let (t1, c1) = carry56 (x1 +! y1 +! c0) in let (t2, c2) = carry56 (x2 +! y2 +! c1) in let (t3, c3) = carry56 (x3 +! y3 +! c2) in let t4 = x4 +! y4 +! c3 in assert (as_nat5 (t0, t1, t2, t3, t4) == as_nat5 (x0, x1, x2, x3, x4) + as_nat5 (y0, y1, y2, y3, y4)); let (o0, o1, o2, o3, o4) = subm_conditional (t0, t1, t2, t3, t4) in Lemmas.lemma_add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) (t0, t1, t2, t3, t4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry56_wide: x:uint128 -> Pure (uint128 & uint64) (requires v x < pow2 117) (ensures fun (c, t) -> v t < pow56 /\ v c < pow2 61 /\ v x - v c * pow56 == v t /\ v c == v x / pow56) let carry56_wide x = let carry = x >>. 56ul in let t = to_u64 x &. mask56 in assert_norm (pow2 56 < pow2 64); Math.Lemmas.lemma_div_lt_nat (v x) 117 56; mod_mask_lemma (to_u64 x) 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == (v x % pow2 64) % pow2 56); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v x) 56 64; assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); carry, t inline_for_extraction noextract val mul64_wide_5: (a:uint64) -> (b:uint64) -> Pure uint128 (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures fun z -> v z == v a * v b /\ v z <= pow2 112 - pow2 57 + 1 /\ v z < pow2 112) let mul64_wide_5 a b = let lemma_smaller (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) < pow2 112) = if v a = 0 || v b = 0 then () else calc (<) { v a * v b <: int; (<) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56) } v a * pow2 56; (<) { Math.Lemmas.lemma_mult_le_right (pow2 56) (v a) (pow2 56) } pow2 56 * pow2 56; (==) { assert_norm (pow2 56 * pow2 56 == pow2 112) } pow2 112; } in let lemma_le (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) <= pow2 112 - pow2 57 + 1) = if v a = 0 || v b = 0 then () else assert_norm (pow2 112 - pow2 57 + 1 >= 0); calc (<=) { v a * v b <: int; (<=) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56 - 1) } v a * (pow2 56 - 1); (<=) { Math.Lemmas.lemma_mult_le_right (pow2 56 - 1) (v a) (pow2 56 - 1) } (pow2 56 - 1) * (pow2 56 - 1); (==) { assert_norm ((pow2 56 - 1) * (pow2 56 - 1) == pow2 112 - pow2 57 + 1) } pow2 112 - pow2 57 + 1; } in lemma_le a b; lemma_smaller a b; mul64_wide a b inline_for_extraction noextract val add2: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112) (ensures fun z -> v z == v a + v b /\ v z <= pow2 116) let add2 a b = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b inline_for_extraction noextract val add3: (a:uint128) -> (b:uint128) -> (c:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 ) (ensures fun z -> v z == v a + v b + v c /\ v z <= pow2 116) let add3 a b c = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); a +. b +. c inline_for_extraction noextract val add4: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d /\ v z <= pow2 116) let add4 a b c d = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d) (pow2 128); a +. b +. c +. d inline_for_extraction noextract val add5: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> (e:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112 /\ v e < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d + v e/\ v z <= pow2 116) let add5 a b c d e = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d + v e) (pow2 128); a +. b +. c +. d +. e inline_for_extraction noextract val add_inner_carry: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a <= pow2 116 /\ v b < pow2 61) (ensures fun z -> v z == v a + v b /\ v z < pow2 117) let add_inner_carry a b = assert_norm (pow2 116 + pow2 61 < pow2 128); assert_norm (pow2 116 + pow2 61 < pow2 117); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b inline_for_extraction noextract val mul_5: x:qelem5 -> y:qelem5 -> Pure qelem_wide5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1)) (ensures fun r -> qelem_wide_fits5 r (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 r == as_nat5 x * as_nat5 y) let lemma_mult_distr_3 (a b c:nat) (n:nat) : Lemma ((a + b - c * pow2 56) * pow2 n == a * pow2 n + b * pow2 n - c * pow2 (n + 56)) = Math.Lemmas.distributivity_sub_left (a + b) (c * pow2 56) (pow2 n); Math.Lemmas.distributivity_add_left a b (pow2 n); Math.Lemmas.pow2_plus 56 n #set-options "--z3rlimit 300" let mul_5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let xy00 = mul64_wide_5 x0 y0 in let xy01 = mul64_wide_5 x0 y1 in let xy02 = mul64_wide_5 x0 y2 in let xy03 = mul64_wide_5 x0 y3 in let xy04 = mul64_wide_5 x0 y4 in let xy10 = mul64_wide_5 x1 y0 in let xy11 = mul64_wide_5 x1 y1 in let xy12 = mul64_wide_5 x1 y2 in let xy13 = mul64_wide_5 x1 y3 in let xy14 = mul64_wide_5 x1 y4 in let xy20 = mul64_wide_5 x2 y0 in let xy21 = mul64_wide_5 x2 y1 in let xy22 = mul64_wide_5 x2 y2 in let xy23 = mul64_wide_5 x2 y3 in let xy24 = mul64_wide_5 x2 y4 in let xy30 = mul64_wide_5 x3 y0 in let xy31 = mul64_wide_5 x3 y1 in let xy32 = mul64_wide_5 x3 y2 in let xy33 = mul64_wide_5 x3 y3 in let xy34 = mul64_wide_5 x3 y4 in let xy40 = mul64_wide_5 x4 y0 in let xy41 = mul64_wide_5 x4 y1 in let xy42 = mul64_wide_5 x4 y2 in let xy43 = mul64_wide_5 x4 y3 in let xy44 = mul64_wide_5 x4 y4 in let z0 = xy00 in // < pow2 112 let z1 = add2 xy01 xy10 in // < pow2 113 let z2 = add3 xy02 xy11 xy20 in // < pow2 114 let z3 = add4 xy03 xy12 xy21 xy30 in // < pow2 115 let z4 = add5 xy04 xy13 xy22 xy31 xy40 in // < pow2 116 let z5 = add4 xy14 xy23 xy32 xy41 in let z6 = add3 xy24 xy33 xy42 in let z7 = add2 xy34 xy43 in let z8 = xy44 in //(z0, z1, z2, z3, z4, z5, z6, z7, z8) assert_norm (pow2 112 < pow2 117); assert_norm (pow2 112 <= pow2 116); let (c0, t0) = carry56_wide z0 in let (c1, t1) = carry56_wide (add_inner_carry z1 c0) in let (c2, t2) = carry56_wide (add_inner_carry z2 c1) in let (c3, t3) = carry56_wide (add_inner_carry z3 c2) in let (c4, t4) = carry56_wide (add_inner_carry z4 c3) in let (c5, t5) = carry56_wide (add_inner_carry z5 c4) in let (c6, t6) = carry56_wide (add_inner_carry z6 c5) in let (c7, t7) = carry56_wide (add_inner_carry z7 c6) in let (c8, t8) = carry56_wide (add_inner_carry z8 c7) in let t9 = to_u64 c8 in let lemma_t9_fits () : Lemma (v t9 < pow2 56) = // This proof was built from the bottom. We have as a constraint that v c8 has to be < pow2 112 to satisfy the postcondition. // We compute each time the maximal value such that this postcondition is satisfied calc (<) { v c0; (<) { Math.Lemmas.lemma_div_lt_nat (v z0) 112 56 } pow2 56; }; calc (<) { v c1; (<) { assert_norm (2*(pow2 112 - pow2 57 + 1) + pow2 56 <= pow2 113); Math.Lemmas.lemma_div_lt_nat (v z1 + v c0) 113 56 } pow2 57; }; calc (<) { v c2; (<) { assert_norm (3*(pow2 112 - pow2 57 + 1) + pow2 57 <= pow2 114); Math.Lemmas.lemma_div_lt_nat (v z2 + v c1) 114 56 } pow2 58; }; calc (<=) { v c3; (<=) { assert_norm (4*(pow2 112 - pow2 57 + 1) + pow2 58 <= 31153781151208965410895007785680895); assert_norm (31153781151208965410895007785680895 / pow56 == 432345564227567610); Math.Lemmas.lemma_div_le (v z3 + v c2) 31153781151208965410895007785680895 (pow2 56) } 432345564227567610; }; calc (<=) { v c4; (<=) { assert_norm (5*(pow2 112 - pow2 57 + 1) + 432345564227567610 <= 25961484292674137854422105494388735); // (pow2 59 - 2) * pow56 assert_norm (25961484292674137854422105494388735 / pow56 == 360287970189639675); Math.Lemmas.lemma_div_le (v z4 + v c3) 25961484292674137854422105494388735 (pow2 56) } 360287970189639675; }; calc (<=) { v c5; (<=) { assert_norm (4*(pow2 112 - pow2 57 + 1) + 360287970189639675 <= 20769187434139310297949203203096575); Math.Lemmas.lemma_div_le (v z5 + v c4) 20769187434139310297949203203096575 (pow2 56); assert_norm (20769187434139310297949203203096575 / pow2 56 == pow2 58 - 4) } pow2 58 - 4; }; calc (<=) { v c6; (<=) { assert_norm (3*(pow2 112 - pow2 57 + 1) + pow2 58 - 4 <= 15576890575604482741476300911804415); Math.Lemmas.lemma_div_le (v z6 + v c5) 15576890575604482741476300911804415 (pow2 56); assert_norm (15576890575604482741476300911804415 / pow2 56 == 216172782113783805) } 216172782113783805; }; calc (<=) { v c7; (<=) { assert_norm (2*(pow2 112 - pow2 57 + 1) + 216172782113783805 <= 10384593717069655185003398620512255); // (pow2 57 - 1) * pow2 56 - 1 Math.Lemmas.lemma_div_le (v z7 + v c6) 10384593717069655185003398620512255 (pow2 56); assert_norm (10384593717069655185003398620512255 / pow2 56 == pow2 57 - 2) } pow2 57 - 2; }; calc (<) { v c8; (<) { Math.Lemmas.lemma_div_lt_nat (v z8 + v c7) 112 56 } pow2 56; }; assert_norm (pow2 56 < pow2 64); Math.Lemmas.small_mod (v c8) (pow2 64) in lemma_t9_fits(); calc (==) { wide_as_nat5 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) <: int; (==) { } v t0 + v t1 * pow56 + v t2 * pow112 + v t3 * pow168 + v t4 * pow224 + v t5 * pow280 + v t6 * pow336 + v t7 * pow392 + v t8 * pow448 + v t9 * pow504; (==) { assert_norm (pow2 61 < pow2 64); Math.Lemmas.small_mod (v c8) (pow2 64) } v z0 - v c0 * pow2 56 + (v z1 + v c0 - v c1 * pow2 56) * pow56 + (v z2 + v c1 - v c2 * pow2 56) * pow112 + (v z3 + v c2 - v c3 * pow2 56) * pow168 + (v z4 + v c3 - v c4 * pow2 56) * pow224 + (v z5 + v c4 - v c5 * pow2 56) * pow280 + (v z6 + v c5 - v c6 * pow2 56) * pow336 + (v z7 + v c6 - v c7 * pow2 56) * pow392 + (v z8 + v c7 - v c8 * pow2 56) * pow448 + v c8 * pow504; (==) { lemma_mult_distr_3 (v z1) (v c0) (v c1) 56; lemma_mult_distr_3 (v z2) (v c1) (v c2) 112; lemma_mult_distr_3 (v z3) (v c2) (v c3) 168; lemma_mult_distr_3 (v z4) (v c3) (v c4) 224; lemma_mult_distr_3 (v z5) (v c4) (v c5) 280; lemma_mult_distr_3 (v z6) (v c5) (v c6) 336; lemma_mult_distr_3 (v z7) (v c6) (v c7) 392; lemma_mult_distr_3 (v z8) (v c7) (v c8) 448 } v z0 + v z1 * pow56 + v z2 * pow112 + v z3 * pow168 + v z4 * pow224 + v z5 * pow280 + v z6 * pow336 + v z7 * pow392 + v z8 * pow448; (==) { calc (==) { v z1; (==) { } v x0 * v y1 + v x1 * v y0; }; calc (==) { v z2; (==) { } v x0 * v y2 + v x1 * v y1 + v x2 * v y0; }; calc (==) { v z3; (==) { } v x0 * v y3 + v x1 * v y2 + v x2 * v y1 + v x3 * v y0; }; calc (==) { v z4; (==) { } v x0 * v y4 + v x1 * v y3 + v x2 * v y2 + v x3 * v y1 + v x4 * v y0; }; calc (==) { v z5; (==) { } v x1 * v y4 + v x2 * v y3 + v x3 * v y2 + v x4 * v y1; }; calc (==) { v z6; (==) { } v x2 * v y4 + v x3 * v y3 + v x4 * v y2; }; calc (==) { v z7; (==) { } v x3 * v y4 + v x4 * v y3; }; calc (==) { v z8; (==) { } v x4 * v y4; } } v x0 * v y0 + (v x0 * v y1 + v x1 * v y0) * pow56 + (v x0 * v y2 + v x1 * v y1 + v x2 * v y0) * pow112 + (v x0 * v y3 + v x1 * v y2 + v x2 * v y1 + v x3 * v y0) * pow168 + (v x0 * v y4 + v x1 * v y3 + v x2 * v y2 + v x3 * v y1 + v x4 * v y0) * pow224 + (v x1 * v y4 + v x2 * v y3 + v x3 * v y2 + v x4 * v y1) * pow280 + (v x2 * v y4 + v x3 * v y3 + v x4 * v y2) * pow336 + (v x3 * v y4 + v x4 * v y3) * pow392 + (v x4 * v y4) * pow448; (==) { Lemmas.lemma_mul_qelem5 (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) } (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224) * (v y0 + v y1 * pow2 56 + v y2 * pow2 112 + v y3 * pow2 168 + v y4 * pow2 224); }; (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) inline_for_extraction noextract val low_mul_5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (as_nat5 x * as_nat5 y) % pow2 264) let low_mul_5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let xy00 = mul64_wide_5 x0 y0 in let xy01 = mul64_wide_5 x0 y1 in let xy02 = mul64_wide_5 x0 y2 in let xy03 = mul64_wide_5 x0 y3 in let xy04 = mul64_wide_5 x0 y4 in let xy10 = mul64_wide_5 x1 y0 in let xy11 = mul64_wide_5 x1 y1 in let xy12 = mul64_wide_5 x1 y2 in let xy13 = mul64_wide_5 x1 y3 in let xy20 = mul64_wide_5 x2 y0 in let xy21 = mul64_wide_5 x2 y1 in let xy22 = mul64_wide_5 x2 y2 in let xy30 = mul64_wide_5 x3 y0 in let xy31 = mul64_wide_5 x3 y1 in let xy40 = mul64_wide_5 x4 y0 in assert_norm (pow2 112 < pow2 117); let (c0, t0) = carry56_wide xy00 in let (c1, t1) = carry56_wide (add_inner_carry (add2 xy01 xy10) c0) in let (c2, t2) = carry56_wide (add_inner_carry (add3 xy02 xy11 xy20) c1) in let (c3, t3) = carry56_wide (add_inner_carry (add4 xy03 xy12 xy21 xy30) c2) in let t4 = to_u64 (add_inner_carry (add5 xy04 xy13 xy22 xy31 xy40) c3) &. mask40 in calc (==) { as_nat5 (t0, t1, t2, t3, t4) <: int; (==) { } v t0 + v t1 * pow56 + v t2 * pow112 + v t3 * pow168 + v t4 * pow224; (==) { } v xy00 - v c0 * pow2 56 + (v xy01 + v xy10 + v c0 - v c1 * pow2 56) * pow56 + (v xy02 + v xy11 + v xy20 + v c1 - v c2 * pow56) * pow112 + (v xy03 + v xy12 + v xy21 + v xy30 + v c2 - v c3 * pow56) * pow168 + v t4 * pow224; (==) { logand_mask (to_u64 (add_inner_carry (add5 xy04 xy13 xy22 xy31 xy40) c3)) mask40 40; Math.Lemmas.pow2_modulo_modulo_lemma_1 (v (add_inner_carry (add5 xy04 xy13 xy22 xy31 xy40) c3)) 40 64 } v x0 * v y0 + (v x0 * v y1 + v x1 * v y0) * pow56 + (v x0 * v y2 + v x1 * v y1 + v x2 * v y0) * pow112 + (v x0 * v y3 + v x1 * v y2 + v x2 * v y1 + v x3 * v y0 - v c3 * pow56) * pow168 + ((v x0 * v y4 + v x1 * v y3 + v x2 * v y2 + v x3 * v y1 + v x4 * v y0 + v c3) % pow2 40) * pow224; }; Lemmas.lemma_mul_5_low_264 (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4); (t0, t1, t2, t3, t4) inline_for_extraction noextract val div_2_24_step: x:uint64 -> y:uint64 -> Pure uint64 (requires v x < pow56 /\ v y < pow56) (ensures fun r -> v r < pow56 /\ v r == v x / pow2 24 + pow2 32 * (v y % pow2 24)) let div_2_24_step x y = let y' = (y &. u64 0xffffff) <<. 32ul in assert_norm (pow2 24 - 1 = 0xffffff); assert_norm (pow2 24 < pow2 64); mod_mask_lemma y 24ul; assert (v (mod_mask #U64 #SEC 24ul) == 0xffffff); assert (v (y &. u64 0xffffff) == v y % pow2 24); assert (v y' == (v y % pow2 24) * pow2 32); let x' = x >>. 24ul in FStar.Math.Lemmas.pow2_minus 56 24; assert (v x' < pow2 32); let z = x' |. y' in logor_disjoint x' y' 32; assert (v z == v x / pow2 24 + pow2 32 * (v y % pow2 24)); z inline_for_extraction noextract val div_248: x:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 x < pow2 512) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (wide_as_nat5 x) / pow2 248) let div_248 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = // x / pow2 248 == (x / pow2 224) / pow2 24 let z0 = div_2_24_step x4 x5 in let z1 = div_2_24_step x5 x6 in let z2 = div_2_24_step x6 x7 in let z3 = div_2_24_step x7 x8 in let z4 = div_2_24_step x8 x9 in assert (qelem_fits5 (z0, z1, z2, z3, z4) (1, 1, 1, 1, 1)); Lemmas.lemma_div248 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9); (z0, z1, z2, z3, z4) inline_for_extraction noextract val div_2_40_step: x:uint64 -> y:uint64 -> Pure uint64 (requires v x < pow56) (ensures fun z -> v z < pow56 /\ v z == v x / pow2 40 + pow2 16 * (v y % pow2 40)) let div_2_40_step x y = let y' = (y &. mask40) <<. 16ul in assert_norm (pow2 40 < pow2 64); mod_mask_lemma y 40ul; assert (v (mod_mask #U64 #SEC 40ul) == v mask40); assert (v y' == (v y % pow2 40) * pow2 16); let x' = x >>. 40ul in FStar.Math.Lemmas.pow2_minus 56 40; assert (v x' == v x / pow2 40); assert (v x' < pow2 16); let z = x' |. y' in logor_disjoint x' y' 16; z inline_for_extraction noextract val div_264: x:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 x < pow2 528) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (wide_as_nat5 x) / pow2 264) let div_264 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = // x / pow2 264 == (x / pow2 224) / pow2 40 let z0 = div_2_40_step x4 x5 in let z1 = div_2_40_step x5 x6 in let z2 = div_2_40_step x6 x7 in let z3 = div_2_40_step x7 x8 in let z4 = div_2_40_step x8 x9 in assert (qelem_fits5 (z0, z1, z2, z3, z4) (1, 1, 1, 1, 1)); Lemmas.lemma_div264 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9); (z0, z1, z2, z3, z4) inline_for_extraction noextract val mod_264: t:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (wide_as_nat5 t) % pow2 264) let mod_264 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = Lemmas.lemma_mod_264 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9); (t0, t1, t2, t3, t4 &. mask40) inline_for_extraction noextract val subm_last_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow2 40 /\ v y <= pow2 40) (ensures fun (b, t) -> v b <= 1 /\ v t < pow2 40 /\ v x - v y == v t - pow2 40 * v b) let subm_last_step x y = assert_norm (pow2 40 < pow2 63); let b = (x -. y) >>. 63ul in assert (if v x >= v y then v b == 0 else v b == 1); let t = ((b <<. 40ul) +! x) -! y in b, t #push-options "--z3rlimit 400 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract val sub_mod_264: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < pow2 264 /\ as_nat5 y < pow2 264) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ (if as_nat5 x >= as_nat5 y then as_nat5 z == as_nat5 x - as_nat5 y else as_nat5 z == as_nat5 x - as_nat5 y + pow2 264)) let sub_mod_264 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let (c1, t0) = subm_step x0 y0 in assert (v x0 - v y0 == v t0 - v c1 * pow56); let (c2, t1) = subm_step x1 (y1 +! c1) in assert (v x1 - v y1 - v c1 == v t1 - v c2 * pow56); let (c3, t2) = subm_step x2 (y2 +! c2) in assert (v x2 - v y2 - v c2 == v t2 - v c3 * pow56); let (c4, t3) = subm_step x3 (y3 +! c3) in assert (v x3 - v y3 - v c3 == v t3 - v c4 * pow56); Lemmas.lemma_as_nat_pow264_x4 (x0, x1, x2, x3, x4); Lemmas.lemma_as_nat_pow264_x4 (y0, y1, y2, y3, y4); let (c5, t4) = subm_last_step x4 (y4 +! c4) in assert (v x4 - v y4 - v c4 == v t4 - pow2 40 * v c5); assert ( if v c5 = 0 then as_nat5 (x0, x1, x2, x3, x4) >= as_nat5 (y0, y1, y2, y3, y4) else as_nat5 (x0, x1, x2, x3, x4) < as_nat5 (y0, y1, y2, y3, y4)); assert_norm (pow2 40 < pow2 56); assert (qelem_fits5 (t0, t1, t2, t3, t4) (1, 1, 1, 1, 1)); assert (as_nat5 (t0, t1, t2, t3, t4) == v x0 - v y0 + v c1 * pow56 + (v x1 - v y1 - v c1 + v c2 * pow56) * pow56 + (v x2 - v y2 - v c2 + v c3 * pow56) * pow112 + (v x3 - v y3 - v c3 + v c4 * pow56) * pow168 + (v x4 - v y4 - v c4 + pow2 40 * v c5) * pow224); Lemmas.lemma_sub_mod_264_aux (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) (v c1) (v c2) (v c3) (v c4) (v c5); assert (as_nat5 (t0, t1, t2, t3, t4) == as_nat5 (x0, x1, x2, x3, x4) - as_nat5 (y0, y1, y2, y3, y4) + v c5 * pow2 264); Lemmas.lemma_sub_mod_264 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) (t0, t1, t2, t3, t4) c5; (t0, t1, t2, t3, t4) #pop-options // A = t, L = make_m() // b = 2^8, k = 32, mu = b^{2*k} / L = make_mu() inline_for_extraction noextract val barrett_reduction5: t:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 t < pow2 512) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (wide_as_nat5 t) % S.q) let barrett_reduction5 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = let (m0, m1, m2, m3, m4) = make_m () in let (mu0, mu1, mu2, mu3, mu4) = make_mu () in let (q0, q1, q2, q3, q4) = div_248 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) in assert (as_nat5 (q0, q1, q2, q3, q4) == wide_as_nat5 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) / pow2 248); FStar.Math.Lemmas.lemma_div_lt_nat (wide_as_nat5 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9)) 512 248; assert (as_nat5 (q0, q1, q2, q3, q4) < pow2 264); let (qmu0', qmu1', qmu2', qmu3', qmu4', qmu5', qmu6', qmu7', qmu8', qmu9') = mul_5 (q0, q1, q2, q3, q4) (mu0, mu1, mu2, mu3, mu4) in FStar.Math.Lemmas.lemma_mult_le_right (pow2 512 / S.q) (as_nat5 (q0, q1, q2, q3, q4)) (pow2 264); assert (wide_as_nat5 (qmu0', qmu1', qmu2', qmu3', qmu4', qmu5', qmu6', qmu7', qmu8', qmu9') <= pow2 512 / S.q * pow2 264); assert_norm (pow2 512 / S.q * pow2 264 < pow2 528); let (qdiv0, qdiv1, qdiv2, qdiv3, qdiv4) = div_264 (qmu0', qmu1', qmu2', qmu3', qmu4', qmu5', qmu6', qmu7', qmu8', qmu9') in //u = qdiv == (A / b^{k-1}) * mu / b^{k+1} == ((A / 2^248) * mu) / 2^264 let (r0, r1, r2, r3, r4) = mod_264 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) in //r == A mod b^{k+1} == A mod 2^264 let (qmul0, qmul1, qmul2, qmul3, qmul4) = low_mul_5 (qdiv0, qdiv1, qdiv2, qdiv3, qdiv4) (m0, m1, m2, m3, m4) in //v == qmul == u * L mod b^{k+1} == u * L mod 2^264 let (s0, s1, s2, s3, s4) = sub_mod_264 (r0, r1, r2, r3, r4) (qmul0, qmul1, qmul2, qmul3, qmul4) in //u == s == (r - v) mod b^{k+1} == (r - v) mod 2^264 let (o0, o1, o2, o3, o4) = subm_conditional (s0, s1, s2, s3, s4) in Lemmas.lemma_barrett_reduce' (wide_as_nat5 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9)); (o0, o1, o2, o3, o4) inline_for_extraction noextract val mul_modq5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < pow2 256 /\ as_nat5 y < pow2 256) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (as_nat5 x * as_nat5 y) % S.q)
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.BignumQ.Mul.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 300, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Hacl.Spec.BignumQ.Definitions.qelem5 -> y: Hacl.Spec.BignumQ.Definitions.qelem5 -> Prims.Pure Hacl.Spec.BignumQ.Definitions.qelem5
Prims.Pure
[]
[]
[ "Hacl.Spec.BignumQ.Definitions.qelem5", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple5", "Lib.IntTypes.uint64", "FStar.Pervasives.Native.Mktuple5", "Hacl.Spec.BignumQ.Mul.barrett_reduction5", "FStar.Pervasives.Native.Mktuple10", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.Mul.op_Star", "Prims.pow2", "Hacl.Spec.BignumQ.Lemmas.lemma_mul_lt", "Hacl.Spec.BignumQ.Definitions.as_nat5", "Hacl.Spec.BignumQ.Definitions.qelem_wide5", "Hacl.Spec.BignumQ.Mul.mul_5" ]
[]
false
false
false
false
false
let mul_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) =
let r0, r1, r2, r3, r4, r5, r6, r7, r8, r9 = mul_5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) in Lemmas.lemma_mul_lt (as_nat5 (x0, x1, x2, x3, x4)) (pow2 256) (as_nat5 (y0, y1, y2, y3, y4)) (pow2 256); assert_norm (pow2 256 * pow2 256 = pow2 512); let o0, o1, o2, o3, o4 = barrett_reduction5 (r0, r1, r2, r3, r4, r5, r6, r7, r8, r9) in (o0, o1, o2, o3, o4)
false
Hacl.Spec.BignumQ.Mul.fst
Hacl.Spec.BignumQ.Mul.subm_last_step
val subm_last_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow2 40 /\ v y <= pow2 40) (ensures fun (b, t) -> v b <= 1 /\ v t < pow2 40 /\ v x - v y == v t - pow2 40 * v b)
val subm_last_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow2 40 /\ v y <= pow2 40) (ensures fun (b, t) -> v b <= 1 /\ v t < pow2 40 /\ v x - v y == v t - pow2 40 * v b)
let subm_last_step x y = assert_norm (pow2 40 < pow2 63); let b = (x -. y) >>. 63ul in assert (if v x >= v y then v b == 0 else v b == 1); let t = ((b <<. 40ul) +! x) -! y in b, t
{ "file_name": "code/ed25519/Hacl.Spec.BignumQ.Mul.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 6, "end_line": 748, "start_col": 0, "start_line": 743 }
module Hacl.Spec.BignumQ.Mul open FStar.Mul open Lib.IntTypes module S = Spec.Ed25519 module Lemmas = Hacl.Spec.BignumQ.Lemmas include Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask56 : x:uint64{v x == pow2 56 - 1} = assert_norm (pow2 56 - 1 == 0xffffffffffffff); u64 0xffffffffffffff inline_for_extraction noextract let mask40 : x:uint64{v x == pow2 40 - 1} = assert_norm (pow2 40 - 1 == 0xffffffffff); u64 0xffffffffff inline_for_extraction noextract val make_m: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == S.q} let make_m () = let m0 = u64 0x12631a5cf5d3ed in let m1 = u64 0xf9dea2f79cd658 in let m2 = u64 0x000000000014de in let m3 = u64 0x00000000000000 in let m4 = u64 0x00000010000000 in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val make_mu: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == pow2 512 / S.q} let make_mu m = let m0 = u64 0x9ce5a30a2c131b in let m1 = u64 0x215d086329a7ed in let m2 = u64 0xffffffffeb2106 in let m3 = u64 0xffffffffffffff in let m4 = u64 0x00000fffffffff in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == pow2 512 / S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val choose: b:uint64 -> x:qelem5 -> y:qelem5 -> Pure qelem5 (requires v b == 0 \/ v b == 1) (ensures fun z -> if v b = 1 then z == x else z == y) let choose b (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let mask = b -. u64 1 in let z0 = x0 ^. (mask &. (x0 ^. y0)) in Lemmas.lemma_choose_step b x0 y0; let z1 = x1 ^. (mask &. (x1 ^. y1)) in Lemmas.lemma_choose_step b x1 y1; let z2 = x2 ^. (mask &. (x2 ^. y2)) in Lemmas.lemma_choose_step b x2 y2; let z3 = x3 ^. (mask &. (x3 ^. y3)) in Lemmas.lemma_choose_step b x3 y3; let z4 = x4 ^. (mask &. (x4 ^. y4)) in Lemmas.lemma_choose_step b x4 y4; (z0, z1, z2, z3, z4) inline_for_extraction noextract val subm_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow56 /\ v y <= pow56) (ensures fun (b, t) -> v b <= 1 /\ qelem_fits1 t 1 /\ v x - v y == v t - v b * pow56) let subm_step x y = let b = (x -. y) >>. 63ul in //assert (if v x >= v y then v b == 0 else v b == 1); let lshift56 = (b <<. 56ul) in //assert (if v x >= v y then v lshift56 == 0 else v lshift56 == pow56); //assert (v lshift56 == v b * pow56); //assert (v ((b <<. 56ul) +! x) == v b * pow56 + v x); let t = ((b <<. 56ul) +! x) -! y in b, t inline_for_extraction noextract val subm_conditional: x:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ (if as_nat5 x >= S.q then as_nat5 r == as_nat5 x - S.q else as_nat5 r == as_nat5 x)) let subm_conditional (x0, x1, x2, x3, x4) = let (y0, y1, y2, y3, y4) = make_m () in let (b0, t0) = subm_step x0 y0 in assert (v x0 - v y0 == v t0 - v b0 * pow56); let (b1, t1) = subm_step x1 (y1 +! b0) in assert (v x1 - v y1 - v b0 == v t1 - v b1 * pow56); let (b2, t2) = subm_step x2 (y2 +! b1) in assert (v x2 - v y2 - v b1 == v t2 - v b2 * pow56); let (b3, t3) = subm_step x3 (y3 +! b2) in assert (v x3 - v y3 - v b2 == v t3 - v b3 * pow56); let (b4, t4) = subm_step x4 (y4 +! b3) in assert (v x4 - v y4 - v b3 == v t4 - v b4 * pow56); Lemmas.lemma_subm_conditional (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) (v b0) (v b1) (v b2) (v b3) (v b4); assert ( as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow56 * pow224 == as_nat5 (x0, x1, x2, x3, x4) - as_nat5 (y0, y1, y2, y3, y4)); //assert_norm (pow56 * pow224 = pow2 280); //assert (as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow2 280 == as_nat5 (x0, x1, x2, x3, x4) - S.q); Lemmas.lemma_as_nat5 (x0, x1, x2, x3, x4); Lemmas.lemma_as_nat5 (t0, t1, t2, t3, t4); //assert (if v b4 = 0 then as_nat5 (x0, x1, x2, x3, x4) >= S.q else as_nat5 (x0, x1, x2, x3, x4) < S.q); assert (if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 else v b4 == 1); let (z0, z1, z2, z3, z4) = choose b4 (x0, x1, x2, x3, x4) (t0, t1, t2, t3, t4) in assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else v b4 == 1 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); (z0, z1, z2, z3, z4) inline_for_extraction noextract val carry56: x:uint64 -> Pure (uint64 & uint64) (requires v x <= pow2 57) (ensures fun (t, c) -> v t < pow56 /\ v c <= 2 /\ v x == v c * pow56 + v t) let carry56 x = let carry = x >>. 56ul in FStar.Math.Lemmas.pow2_minus 57 56; let t = x &. mask56 in assert_norm (pow2 56 < pow2 64); mod_mask_lemma x 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); t, carry inline_for_extraction noextract val add_modq5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < S.q /\ as_nat5 y < S.q) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (as_nat5 x + as_nat5 y) % S.q) let add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = assert_norm (pow56 - 1 + pow56 - 1 == pow2 57 - 2); let (t0, c0) = carry56 (x0 +! y0) in let (t1, c1) = carry56 (x1 +! y1 +! c0) in let (t2, c2) = carry56 (x2 +! y2 +! c1) in let (t3, c3) = carry56 (x3 +! y3 +! c2) in let t4 = x4 +! y4 +! c3 in assert (as_nat5 (t0, t1, t2, t3, t4) == as_nat5 (x0, x1, x2, x3, x4) + as_nat5 (y0, y1, y2, y3, y4)); let (o0, o1, o2, o3, o4) = subm_conditional (t0, t1, t2, t3, t4) in Lemmas.lemma_add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) (t0, t1, t2, t3, t4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry56_wide: x:uint128 -> Pure (uint128 & uint64) (requires v x < pow2 117) (ensures fun (c, t) -> v t < pow56 /\ v c < pow2 61 /\ v x - v c * pow56 == v t /\ v c == v x / pow56) let carry56_wide x = let carry = x >>. 56ul in let t = to_u64 x &. mask56 in assert_norm (pow2 56 < pow2 64); Math.Lemmas.lemma_div_lt_nat (v x) 117 56; mod_mask_lemma (to_u64 x) 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == (v x % pow2 64) % pow2 56); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v x) 56 64; assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); carry, t inline_for_extraction noextract val mul64_wide_5: (a:uint64) -> (b:uint64) -> Pure uint128 (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures fun z -> v z == v a * v b /\ v z <= pow2 112 - pow2 57 + 1 /\ v z < pow2 112) let mul64_wide_5 a b = let lemma_smaller (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) < pow2 112) = if v a = 0 || v b = 0 then () else calc (<) { v a * v b <: int; (<) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56) } v a * pow2 56; (<) { Math.Lemmas.lemma_mult_le_right (pow2 56) (v a) (pow2 56) } pow2 56 * pow2 56; (==) { assert_norm (pow2 56 * pow2 56 == pow2 112) } pow2 112; } in let lemma_le (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) <= pow2 112 - pow2 57 + 1) = if v a = 0 || v b = 0 then () else assert_norm (pow2 112 - pow2 57 + 1 >= 0); calc (<=) { v a * v b <: int; (<=) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56 - 1) } v a * (pow2 56 - 1); (<=) { Math.Lemmas.lemma_mult_le_right (pow2 56 - 1) (v a) (pow2 56 - 1) } (pow2 56 - 1) * (pow2 56 - 1); (==) { assert_norm ((pow2 56 - 1) * (pow2 56 - 1) == pow2 112 - pow2 57 + 1) } pow2 112 - pow2 57 + 1; } in lemma_le a b; lemma_smaller a b; mul64_wide a b inline_for_extraction noextract val add2: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112) (ensures fun z -> v z == v a + v b /\ v z <= pow2 116) let add2 a b = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b inline_for_extraction noextract val add3: (a:uint128) -> (b:uint128) -> (c:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 ) (ensures fun z -> v z == v a + v b + v c /\ v z <= pow2 116) let add3 a b c = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); a +. b +. c inline_for_extraction noextract val add4: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d /\ v z <= pow2 116) let add4 a b c d = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d) (pow2 128); a +. b +. c +. d inline_for_extraction noextract val add5: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> (e:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112 /\ v e < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d + v e/\ v z <= pow2 116) let add5 a b c d e = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d + v e) (pow2 128); a +. b +. c +. d +. e inline_for_extraction noextract val add_inner_carry: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a <= pow2 116 /\ v b < pow2 61) (ensures fun z -> v z == v a + v b /\ v z < pow2 117) let add_inner_carry a b = assert_norm (pow2 116 + pow2 61 < pow2 128); assert_norm (pow2 116 + pow2 61 < pow2 117); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b inline_for_extraction noextract val mul_5: x:qelem5 -> y:qelem5 -> Pure qelem_wide5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1)) (ensures fun r -> qelem_wide_fits5 r (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 r == as_nat5 x * as_nat5 y) let lemma_mult_distr_3 (a b c:nat) (n:nat) : Lemma ((a + b - c * pow2 56) * pow2 n == a * pow2 n + b * pow2 n - c * pow2 (n + 56)) = Math.Lemmas.distributivity_sub_left (a + b) (c * pow2 56) (pow2 n); Math.Lemmas.distributivity_add_left a b (pow2 n); Math.Lemmas.pow2_plus 56 n #set-options "--z3rlimit 300" let mul_5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let xy00 = mul64_wide_5 x0 y0 in let xy01 = mul64_wide_5 x0 y1 in let xy02 = mul64_wide_5 x0 y2 in let xy03 = mul64_wide_5 x0 y3 in let xy04 = mul64_wide_5 x0 y4 in let xy10 = mul64_wide_5 x1 y0 in let xy11 = mul64_wide_5 x1 y1 in let xy12 = mul64_wide_5 x1 y2 in let xy13 = mul64_wide_5 x1 y3 in let xy14 = mul64_wide_5 x1 y4 in let xy20 = mul64_wide_5 x2 y0 in let xy21 = mul64_wide_5 x2 y1 in let xy22 = mul64_wide_5 x2 y2 in let xy23 = mul64_wide_5 x2 y3 in let xy24 = mul64_wide_5 x2 y4 in let xy30 = mul64_wide_5 x3 y0 in let xy31 = mul64_wide_5 x3 y1 in let xy32 = mul64_wide_5 x3 y2 in let xy33 = mul64_wide_5 x3 y3 in let xy34 = mul64_wide_5 x3 y4 in let xy40 = mul64_wide_5 x4 y0 in let xy41 = mul64_wide_5 x4 y1 in let xy42 = mul64_wide_5 x4 y2 in let xy43 = mul64_wide_5 x4 y3 in let xy44 = mul64_wide_5 x4 y4 in let z0 = xy00 in // < pow2 112 let z1 = add2 xy01 xy10 in // < pow2 113 let z2 = add3 xy02 xy11 xy20 in // < pow2 114 let z3 = add4 xy03 xy12 xy21 xy30 in // < pow2 115 let z4 = add5 xy04 xy13 xy22 xy31 xy40 in // < pow2 116 let z5 = add4 xy14 xy23 xy32 xy41 in let z6 = add3 xy24 xy33 xy42 in let z7 = add2 xy34 xy43 in let z8 = xy44 in //(z0, z1, z2, z3, z4, z5, z6, z7, z8) assert_norm (pow2 112 < pow2 117); assert_norm (pow2 112 <= pow2 116); let (c0, t0) = carry56_wide z0 in let (c1, t1) = carry56_wide (add_inner_carry z1 c0) in let (c2, t2) = carry56_wide (add_inner_carry z2 c1) in let (c3, t3) = carry56_wide (add_inner_carry z3 c2) in let (c4, t4) = carry56_wide (add_inner_carry z4 c3) in let (c5, t5) = carry56_wide (add_inner_carry z5 c4) in let (c6, t6) = carry56_wide (add_inner_carry z6 c5) in let (c7, t7) = carry56_wide (add_inner_carry z7 c6) in let (c8, t8) = carry56_wide (add_inner_carry z8 c7) in let t9 = to_u64 c8 in let lemma_t9_fits () : Lemma (v t9 < pow2 56) = // This proof was built from the bottom. We have as a constraint that v c8 has to be < pow2 112 to satisfy the postcondition. // We compute each time the maximal value such that this postcondition is satisfied calc (<) { v c0; (<) { Math.Lemmas.lemma_div_lt_nat (v z0) 112 56 } pow2 56; }; calc (<) { v c1; (<) { assert_norm (2*(pow2 112 - pow2 57 + 1) + pow2 56 <= pow2 113); Math.Lemmas.lemma_div_lt_nat (v z1 + v c0) 113 56 } pow2 57; }; calc (<) { v c2; (<) { assert_norm (3*(pow2 112 - pow2 57 + 1) + pow2 57 <= pow2 114); Math.Lemmas.lemma_div_lt_nat (v z2 + v c1) 114 56 } pow2 58; }; calc (<=) { v c3; (<=) { assert_norm (4*(pow2 112 - pow2 57 + 1) + pow2 58 <= 31153781151208965410895007785680895); assert_norm (31153781151208965410895007785680895 / pow56 == 432345564227567610); Math.Lemmas.lemma_div_le (v z3 + v c2) 31153781151208965410895007785680895 (pow2 56) } 432345564227567610; }; calc (<=) { v c4; (<=) { assert_norm (5*(pow2 112 - pow2 57 + 1) + 432345564227567610 <= 25961484292674137854422105494388735); // (pow2 59 - 2) * pow56 assert_norm (25961484292674137854422105494388735 / pow56 == 360287970189639675); Math.Lemmas.lemma_div_le (v z4 + v c3) 25961484292674137854422105494388735 (pow2 56) } 360287970189639675; }; calc (<=) { v c5; (<=) { assert_norm (4*(pow2 112 - pow2 57 + 1) + 360287970189639675 <= 20769187434139310297949203203096575); Math.Lemmas.lemma_div_le (v z5 + v c4) 20769187434139310297949203203096575 (pow2 56); assert_norm (20769187434139310297949203203096575 / pow2 56 == pow2 58 - 4) } pow2 58 - 4; }; calc (<=) { v c6; (<=) { assert_norm (3*(pow2 112 - pow2 57 + 1) + pow2 58 - 4 <= 15576890575604482741476300911804415); Math.Lemmas.lemma_div_le (v z6 + v c5) 15576890575604482741476300911804415 (pow2 56); assert_norm (15576890575604482741476300911804415 / pow2 56 == 216172782113783805) } 216172782113783805; }; calc (<=) { v c7; (<=) { assert_norm (2*(pow2 112 - pow2 57 + 1) + 216172782113783805 <= 10384593717069655185003398620512255); // (pow2 57 - 1) * pow2 56 - 1 Math.Lemmas.lemma_div_le (v z7 + v c6) 10384593717069655185003398620512255 (pow2 56); assert_norm (10384593717069655185003398620512255 / pow2 56 == pow2 57 - 2) } pow2 57 - 2; }; calc (<) { v c8; (<) { Math.Lemmas.lemma_div_lt_nat (v z8 + v c7) 112 56 } pow2 56; }; assert_norm (pow2 56 < pow2 64); Math.Lemmas.small_mod (v c8) (pow2 64) in lemma_t9_fits(); calc (==) { wide_as_nat5 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) <: int; (==) { } v t0 + v t1 * pow56 + v t2 * pow112 + v t3 * pow168 + v t4 * pow224 + v t5 * pow280 + v t6 * pow336 + v t7 * pow392 + v t8 * pow448 + v t9 * pow504; (==) { assert_norm (pow2 61 < pow2 64); Math.Lemmas.small_mod (v c8) (pow2 64) } v z0 - v c0 * pow2 56 + (v z1 + v c0 - v c1 * pow2 56) * pow56 + (v z2 + v c1 - v c2 * pow2 56) * pow112 + (v z3 + v c2 - v c3 * pow2 56) * pow168 + (v z4 + v c3 - v c4 * pow2 56) * pow224 + (v z5 + v c4 - v c5 * pow2 56) * pow280 + (v z6 + v c5 - v c6 * pow2 56) * pow336 + (v z7 + v c6 - v c7 * pow2 56) * pow392 + (v z8 + v c7 - v c8 * pow2 56) * pow448 + v c8 * pow504; (==) { lemma_mult_distr_3 (v z1) (v c0) (v c1) 56; lemma_mult_distr_3 (v z2) (v c1) (v c2) 112; lemma_mult_distr_3 (v z3) (v c2) (v c3) 168; lemma_mult_distr_3 (v z4) (v c3) (v c4) 224; lemma_mult_distr_3 (v z5) (v c4) (v c5) 280; lemma_mult_distr_3 (v z6) (v c5) (v c6) 336; lemma_mult_distr_3 (v z7) (v c6) (v c7) 392; lemma_mult_distr_3 (v z8) (v c7) (v c8) 448 } v z0 + v z1 * pow56 + v z2 * pow112 + v z3 * pow168 + v z4 * pow224 + v z5 * pow280 + v z6 * pow336 + v z7 * pow392 + v z8 * pow448; (==) { calc (==) { v z1; (==) { } v x0 * v y1 + v x1 * v y0; }; calc (==) { v z2; (==) { } v x0 * v y2 + v x1 * v y1 + v x2 * v y0; }; calc (==) { v z3; (==) { } v x0 * v y3 + v x1 * v y2 + v x2 * v y1 + v x3 * v y0; }; calc (==) { v z4; (==) { } v x0 * v y4 + v x1 * v y3 + v x2 * v y2 + v x3 * v y1 + v x4 * v y0; }; calc (==) { v z5; (==) { } v x1 * v y4 + v x2 * v y3 + v x3 * v y2 + v x4 * v y1; }; calc (==) { v z6; (==) { } v x2 * v y4 + v x3 * v y3 + v x4 * v y2; }; calc (==) { v z7; (==) { } v x3 * v y4 + v x4 * v y3; }; calc (==) { v z8; (==) { } v x4 * v y4; } } v x0 * v y0 + (v x0 * v y1 + v x1 * v y0) * pow56 + (v x0 * v y2 + v x1 * v y1 + v x2 * v y0) * pow112 + (v x0 * v y3 + v x1 * v y2 + v x2 * v y1 + v x3 * v y0) * pow168 + (v x0 * v y4 + v x1 * v y3 + v x2 * v y2 + v x3 * v y1 + v x4 * v y0) * pow224 + (v x1 * v y4 + v x2 * v y3 + v x3 * v y2 + v x4 * v y1) * pow280 + (v x2 * v y4 + v x3 * v y3 + v x4 * v y2) * pow336 + (v x3 * v y4 + v x4 * v y3) * pow392 + (v x4 * v y4) * pow448; (==) { Lemmas.lemma_mul_qelem5 (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) } (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224) * (v y0 + v y1 * pow2 56 + v y2 * pow2 112 + v y3 * pow2 168 + v y4 * pow2 224); }; (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) inline_for_extraction noextract val low_mul_5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (as_nat5 x * as_nat5 y) % pow2 264) let low_mul_5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let xy00 = mul64_wide_5 x0 y0 in let xy01 = mul64_wide_5 x0 y1 in let xy02 = mul64_wide_5 x0 y2 in let xy03 = mul64_wide_5 x0 y3 in let xy04 = mul64_wide_5 x0 y4 in let xy10 = mul64_wide_5 x1 y0 in let xy11 = mul64_wide_5 x1 y1 in let xy12 = mul64_wide_5 x1 y2 in let xy13 = mul64_wide_5 x1 y3 in let xy20 = mul64_wide_5 x2 y0 in let xy21 = mul64_wide_5 x2 y1 in let xy22 = mul64_wide_5 x2 y2 in let xy30 = mul64_wide_5 x3 y0 in let xy31 = mul64_wide_5 x3 y1 in let xy40 = mul64_wide_5 x4 y0 in assert_norm (pow2 112 < pow2 117); let (c0, t0) = carry56_wide xy00 in let (c1, t1) = carry56_wide (add_inner_carry (add2 xy01 xy10) c0) in let (c2, t2) = carry56_wide (add_inner_carry (add3 xy02 xy11 xy20) c1) in let (c3, t3) = carry56_wide (add_inner_carry (add4 xy03 xy12 xy21 xy30) c2) in let t4 = to_u64 (add_inner_carry (add5 xy04 xy13 xy22 xy31 xy40) c3) &. mask40 in calc (==) { as_nat5 (t0, t1, t2, t3, t4) <: int; (==) { } v t0 + v t1 * pow56 + v t2 * pow112 + v t3 * pow168 + v t4 * pow224; (==) { } v xy00 - v c0 * pow2 56 + (v xy01 + v xy10 + v c0 - v c1 * pow2 56) * pow56 + (v xy02 + v xy11 + v xy20 + v c1 - v c2 * pow56) * pow112 + (v xy03 + v xy12 + v xy21 + v xy30 + v c2 - v c3 * pow56) * pow168 + v t4 * pow224; (==) { logand_mask (to_u64 (add_inner_carry (add5 xy04 xy13 xy22 xy31 xy40) c3)) mask40 40; Math.Lemmas.pow2_modulo_modulo_lemma_1 (v (add_inner_carry (add5 xy04 xy13 xy22 xy31 xy40) c3)) 40 64 } v x0 * v y0 + (v x0 * v y1 + v x1 * v y0) * pow56 + (v x0 * v y2 + v x1 * v y1 + v x2 * v y0) * pow112 + (v x0 * v y3 + v x1 * v y2 + v x2 * v y1 + v x3 * v y0 - v c3 * pow56) * pow168 + ((v x0 * v y4 + v x1 * v y3 + v x2 * v y2 + v x3 * v y1 + v x4 * v y0 + v c3) % pow2 40) * pow224; }; Lemmas.lemma_mul_5_low_264 (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4); (t0, t1, t2, t3, t4) inline_for_extraction noextract val div_2_24_step: x:uint64 -> y:uint64 -> Pure uint64 (requires v x < pow56 /\ v y < pow56) (ensures fun r -> v r < pow56 /\ v r == v x / pow2 24 + pow2 32 * (v y % pow2 24)) let div_2_24_step x y = let y' = (y &. u64 0xffffff) <<. 32ul in assert_norm (pow2 24 - 1 = 0xffffff); assert_norm (pow2 24 < pow2 64); mod_mask_lemma y 24ul; assert (v (mod_mask #U64 #SEC 24ul) == 0xffffff); assert (v (y &. u64 0xffffff) == v y % pow2 24); assert (v y' == (v y % pow2 24) * pow2 32); let x' = x >>. 24ul in FStar.Math.Lemmas.pow2_minus 56 24; assert (v x' < pow2 32); let z = x' |. y' in logor_disjoint x' y' 32; assert (v z == v x / pow2 24 + pow2 32 * (v y % pow2 24)); z inline_for_extraction noextract val div_248: x:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 x < pow2 512) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (wide_as_nat5 x) / pow2 248) let div_248 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = // x / pow2 248 == (x / pow2 224) / pow2 24 let z0 = div_2_24_step x4 x5 in let z1 = div_2_24_step x5 x6 in let z2 = div_2_24_step x6 x7 in let z3 = div_2_24_step x7 x8 in let z4 = div_2_24_step x8 x9 in assert (qelem_fits5 (z0, z1, z2, z3, z4) (1, 1, 1, 1, 1)); Lemmas.lemma_div248 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9); (z0, z1, z2, z3, z4) inline_for_extraction noextract val div_2_40_step: x:uint64 -> y:uint64 -> Pure uint64 (requires v x < pow56) (ensures fun z -> v z < pow56 /\ v z == v x / pow2 40 + pow2 16 * (v y % pow2 40)) let div_2_40_step x y = let y' = (y &. mask40) <<. 16ul in assert_norm (pow2 40 < pow2 64); mod_mask_lemma y 40ul; assert (v (mod_mask #U64 #SEC 40ul) == v mask40); assert (v y' == (v y % pow2 40) * pow2 16); let x' = x >>. 40ul in FStar.Math.Lemmas.pow2_minus 56 40; assert (v x' == v x / pow2 40); assert (v x' < pow2 16); let z = x' |. y' in logor_disjoint x' y' 16; z inline_for_extraction noextract val div_264: x:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 x < pow2 528) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (wide_as_nat5 x) / pow2 264) let div_264 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = // x / pow2 264 == (x / pow2 224) / pow2 40 let z0 = div_2_40_step x4 x5 in let z1 = div_2_40_step x5 x6 in let z2 = div_2_40_step x6 x7 in let z3 = div_2_40_step x7 x8 in let z4 = div_2_40_step x8 x9 in assert (qelem_fits5 (z0, z1, z2, z3, z4) (1, 1, 1, 1, 1)); Lemmas.lemma_div264 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9); (z0, z1, z2, z3, z4) inline_for_extraction noextract val mod_264: t:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (wide_as_nat5 t) % pow2 264) let mod_264 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = Lemmas.lemma_mod_264 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9); (t0, t1, t2, t3, t4 &. mask40) inline_for_extraction noextract val subm_last_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow2 40 /\ v y <= pow2 40) (ensures fun (b, t) -> v b <= 1 /\ v t < pow2 40 /\ v x - v y == v t - pow2 40 * v b)
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.BignumQ.Mul.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 300, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Lib.IntTypes.uint64 -> y: Lib.IntTypes.uint64 -> Prims.Pure (Lib.IntTypes.uint64 * Lib.IntTypes.uint64)
Prims.Pure
[]
[]
[ "Lib.IntTypes.uint64", "FStar.Pervasives.Native.Mktuple2", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Subtraction_Bang", "Lib.IntTypes.op_Plus_Bang", "Lib.IntTypes.op_Less_Less_Dot", "FStar.UInt32.__uint_to_t", "Prims.unit", "Prims._assert", "Prims.op_GreaterThanOrEqual", "Lib.IntTypes.v", "Prims.eq2", "Prims.int", "Prims.bool", "Lib.IntTypes.op_Greater_Greater_Dot", "Lib.IntTypes.op_Subtraction_Dot", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_LessThan", "Prims.pow2", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
false
false
let subm_last_step x y =
assert_norm (pow2 40 < pow2 63); let b = (x -. y) >>. 63ul in assert (if v x >= v y then v b == 0 else v b == 1); let t = ((b <<. 40ul) +! x) -! y in b, t
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.uint8_t
val uint8_t : Prims.eqtype
let uint8_t = U8.t
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 18, "end_line": 33, "start_col": 0, "start_line": 33 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.eqtype
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt8.t" ]
[]
false
false
false
true
false
let uint8_t =
U8.t
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.uint16_t
val uint16_t : Prims.eqtype
let uint16_t = U16.t
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 20, "end_line": 34, "start_col": 0, "start_line": 34 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.eqtype
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt16.t" ]
[]
false
false
false
true
false
let uint16_t =
U16.t
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.uint32_t
val uint32_t : Prims.eqtype
let uint32_t = U32.t
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 20, "end_line": 35, "start_col": 0, "start_line": 35 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.eqtype
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t" ]
[]
false
false
false
true
false
let uint32_t =
U32.t
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.serialize_index_t
val serialize_index_t : ok: Prims.bool -> x: MerkleTree.Low.Serialization.uint32_t -> buf: MerkleTree.Low.Serialization.uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.Monotonic.Buffer.len buf = sz} -> pos: MerkleTree.Low.Serialization.uint32_t -> FStar.HyperStack.ST.ST (Prims.bool * MerkleTree.Low.Serialization.uint32_t)
let serialize_index_t = serialize_uint32_t
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 50, "end_line": 81, "start_col": 8, "start_line": 81 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" private let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end private let serialize_uint8_t (ok:bool) (x:uint8_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos x; (true, pos + 1ul) end private let serialize_uint16_t (ok:bool) (x:uint16_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint8_t ok (Int.Cast.uint16_to_uint8 (U16.shift_right x 8ul)) buf sz pos in serialize_uint8_t ok (Int.Cast.uint16_to_uint8 x) buf sz pos private let serialize_uint32_t (ok:bool) (x:uint32_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint16_t ok (Int.Cast.uint32_to_uint16 (U32.shift_right x 16ul)) buf sz pos in serialize_uint16_t ok (Int.Cast.uint32_to_uint16 x) buf sz pos private let serialize_uint64_t (ok:bool) (x:uint64_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint32_t ok (Int.Cast.uint64_to_uint32 (U64.shift_right x 32ul)) buf sz pos in serialize_uint32_t ok (Int.Cast.uint64_to_uint32 x) buf sz pos
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ok: Prims.bool -> x: MerkleTree.Low.Serialization.uint32_t -> buf: MerkleTree.Low.Serialization.uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.Monotonic.Buffer.len buf = sz} -> pos: MerkleTree.Low.Serialization.uint32_t -> FStar.HyperStack.ST.ST (Prims.bool * MerkleTree.Low.Serialization.uint32_t)
FStar.HyperStack.ST.ST
[]
[]
[ "MerkleTree.Low.Serialization.serialize_uint32_t" ]
[]
false
true
false
false
false
let serialize_index_t =
serialize_uint32_t
false
Steel.ST.Printf.fst
Steel.ST.Printf.aux
val aux (frags: fragments) (acc: list frag_t) (fp: fragment_printer) : interpret_frags frags acc
val aux (frags: fragments) (acc: list frag_t) (fp: fragment_printer) : interpret_frags frags acc
let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc = match frags with | [] -> let f (l:lift u#0 u#1 unit) : STT unit (live_frags acc) (fun _ -> live_frags acc) = fp acc in (f <: interpret_frags [] acc) | Frag s :: rest -> coerce (aux rest (Inl s :: acc) fp) | Interpolate (Base t) :: args -> let f (x:base_typ_as_type t) : interpret_frags args (Inr (| Base t, Lift x |) :: acc) = aux args (Inr (| Base t, Lift x |) :: acc) fp in f | Interpolate (Array t) :: rest -> let f : l:UInt32.t -> #p:perm -> #v:Ghost.erased (Seq.seq (base_typ_as_type t)) -> b:lmbuffer (base_typ_as_type t) l -> interpret_frags rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) = fun l #p #v b -> aux rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) fp in f <: interpret_frags (Interpolate (Array t) :: rest) acc | Interpolate Any :: rest -> let f : unit -> #a:Type -> p:(a -> StTrivial unit) -> x:a -> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc) = fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp in elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
{ "file_name": "lib/steel/Steel.ST.Printf.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 95, "end_line": 487, "start_col": 0, "start_line": 448 }
(* Copyright 2008-2022 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Printf /// This module provides Steel.ST imperative printing functions for several /// primitive Low* types, including /// -- booleans (%b) /// -- characters (%c) /// -- strings (%s) /// -- machine integers /// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL; /// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L) /// -- and arrays of these base types formatted /// as %xN, where N is the format specifier for the array element type /// e.g., %xuy for buffers of UInt8.t /// The main function of this module is `printf` /// There are a few main differences relative to C printf /// -- The format specifiers are different (see above) /// /// -- For technical reasons explained below, an extra dummy /// argument `done` has to be provided at the end for the /// computation to have any effect. /// /// E.g., one must write /// `printf "%b %c" true 'c' done` /// rather than just /// `printf "%b %c" true 'c'` /// /// -- When printing arrays, two arguments must be passed; the /// length of the array fragment to be formatted and the array /// itself /// /// -- When extracted, rather than producing a C `printf` (which /// does not, e.g., support printing of dynamically sized /// arrays), our `printf` is specialized to a sequence of calls /// to primitive printers for each supported type /// /// Before diving into the technical details of how this module works, /// you might want to see a sample usage at the very end of this file. open FStar.Char open FStar.String open Steel.ST.Util module L = FStar.List.Tot module A = Steel.ST.Array module U32 = FStar.UInt32 #set-options "--ide_id_info_off" /// `lmbuffer a l` is /// - an array of `a` /// - governed by preorders `r` and `s` /// - with length `l` inline_for_extraction let lmbuffer a l = b: A.array a { A.length b == U32.v l } /// `StTrivial`: A effect abbreviation for a stateful computation /// with no precondition, and which does not read or change the state effect StTrivial (a:Type) = STT a emp (fun _ -> emp) /// `StBuf a b`: A effect abbreviation for a stateful computation /// that may read `b` but does not change the state /// /// NOTE: I need to provide those primitives operating on /// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise /// Karamel will complain about arity mismatch inline_for_extraction let stBuf (t:Type) : Type = (l: U32.t) -> (p: Ghost.erased (lmbuffer t l & perm)) -> (x: Ghost.erased (Seq.seq t)) -> (b: A.ptr t) -> ST unit (A.pts_to (fst p) (snd p) x) (fun _ -> A.pts_to (fst p) (snd p) x) (A.ptr_of (fst p) == b) (fun _ -> True) /// Primitive printers for all the types supported by this module assume val print_string: string -> StTrivial unit assume val print_char : char -> StTrivial unit assume val print_u8 : UInt8.t -> StTrivial unit assume val print_u16 : UInt16.t -> StTrivial unit assume val print_u32 : UInt32.t -> StTrivial unit assume val print_u64 : UInt64.t -> StTrivial unit assume val print_i8 : Int8.t -> StTrivial unit assume val print_i16 : Int16.t -> StTrivial unit assume val print_i32 : Int32.t -> StTrivial unit assume val print_i64 : Int64.t -> StTrivial unit assume val print_bool : bool -> StTrivial unit assume val print_lmbuffer_bool : stBuf bool assume val print_lmbuffer_char : stBuf char assume val print_lmbuffer_string : stBuf string assume val print_lmbuffer_u8 : stBuf UInt8.t assume val print_lmbuffer_u16 : stBuf UInt16.t assume val print_lmbuffer_u32 : stBuf UInt32.t assume val print_lmbuffer_u64 : stBuf UInt64.t assume val print_lmbuffer_i8 : stBuf Int8.t assume val print_lmbuffer_i16 : stBuf Int16.t assume val print_lmbuffer_i32 : stBuf Int32.t assume val print_lmbuffer_i64 : stBuf Int64.t /// An attribute to control reduction noextract irreducible let __printf_reduce__ = unit /// Base types supported so far noextract type base_typ = | Bool | Char | String | U8 | U16 | U32 | U64 | I8 | I16 | I32 | I64 /// Argument types are base types and arrays thereof /// Or polymorphic arguments specified by "%a" noextract type arg = | Base of base_typ | Array of base_typ | Any /// Interpreting a `base_typ` as a type [@@__printf_reduce__] noextract let base_typ_as_type (b:base_typ) : Type0 = match b with | Bool -> bool | Char -> char | String -> string | U8 -> FStar.UInt8.t | U16 -> FStar.UInt16.t | U32 -> FStar.UInt32.t | U64 -> FStar.UInt64.t | I8 -> FStar.Int8.t | I16 -> FStar.Int16.t | I32 -> FStar.Int32.t | I64 -> FStar.Int64.t /// `fragment`: A format string is parsed into a list of fragments of /// string literals and other arguments that need to be spliced in /// (interpolated) noextract type fragment = | Frag of string | Interpolate of arg noextract let fragments = list fragment /// `parse_format s`: /// Parses a list of characters in a format string into a list of fragments /// Or None, in case the format string is invalid [@@__printf_reduce__] noextract inline_for_extraction let rec parse_format (s:list char) : Tot (option fragments) (decreases (L.length s)) = let add_dir (d:arg) (ods : option fragments) = match ods with | None -> None | Some ds -> Some (Interpolate d::ds) in let head_buffer (ods:option fragments) = match ods with | Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest) | _ -> None in let cons_frag (c:char) (ods:option fragments) = match ods with | Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest) | Some rest -> Some (Frag (string_of_list [c]) :: rest) | _ -> None in match s with | [] -> Some [] | ['%'] -> None // %a... polymorphic arguments and preceded by their printers | '%' :: 'a' :: s' -> add_dir Any (parse_format s') // %x... arrays of base types | '%' :: 'x' :: s' -> head_buffer (parse_format ('%' :: s')) // %u ... Unsigned integers | '%' :: 'u' :: s' -> begin match s' with | 'y' :: s'' -> add_dir (Base U8) (parse_format s'') | 's' :: s'' -> add_dir (Base U16) (parse_format s'') | 'l' :: s'' -> add_dir (Base U32) (parse_format s'') | 'L' :: s'' -> add_dir (Base U64) (parse_format s'') | _ -> None end | '%' :: c :: s' -> begin match c with | '%' -> cons_frag '%' (parse_format s') | 'b' -> add_dir (Base Bool) (parse_format s') | 'c' -> add_dir (Base Char) (parse_format s') | 's' -> add_dir (Base String) (parse_format s') | 'y' -> add_dir (Base I8) (parse_format s') | 'i' -> add_dir (Base I16) (parse_format s') | 'l' -> add_dir (Base I32) (parse_format s') | 'L' -> add_dir (Base I64) (parse_format s') | _ -> None end | c :: s' -> cons_frag c (parse_format s') /// `parse_format_string`: a wrapper around `parse_format` [@@__printf_reduce__] noextract inline_for_extraction let parse_format_string (s:string) : option fragments = parse_format (list_of_string s) /// `lift a` lifts the type `a` to a higher universe noextract type lift (a:Type u#a) : Type u#(max a b) = | Lift : a -> lift a /// `done` is a `unit` in universe 1 noextract let done : lift unit = Lift u#0 u#1 () /// `arg_t`: interpreting an argument as a type /// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers. /// GM: Somehow, this needs to be a `let rec` (even if it not really recursive) /// or print_frags fails to verify. I don't know why; the generated /// VC and its encoding seem identical (modulo hash consing in the /// latter). [@@__printf_reduce__] noextract let rec arg_t (a:arg) : Type u#1 = match a with | Base t -> lift (base_typ_as_type t) | Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t))) | Any -> (a:Type0 & (a -> StTrivial unit) & a) /// `frag_t`: a fragment is either a string literal or a argument to be interpolated noextract let frag_t = either string (a:arg & arg_t a) /// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l` [@@__printf_reduce__; Steel.Effect.Common.__reduce__] noextract let live_frag0 (f: frag_t) : vprop = match f with | Inl _ -> emp | Inr a -> (match a with | (| Base _, _ |) -> emp | (| Any, _ |) -> emp | (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v) [@@__printf_reduce__] noextract let live_frag (f: frag_t) : vprop = live_frag0 f [@@__printf_reduce__] noextract let rec live_frags (l:list frag_t) : vprop = match l with | [] -> emp | a :: q -> live_frag a `star` live_frags q /// `interpret_frags` interprets a list of fragments as a Steel.ST function type /// Note `l` is the fragments in L-to-R order (i.e., parsing order) /// `acc` accumulates the fragment values in reverse order [@@__printf_reduce__] noextract let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 = match l with | [] -> // Always a dummy argument at the end // Ensures that all cases of this match // have the same universe, i.e., u#1 lift u#0 u#1 unit -> STT unit (live_frags acc) (fun _ -> live_frags acc) | Interpolate (Base t) :: args -> // Base types are simple: we just take one more argument x:base_typ_as_type t -> interpret_frags args (Inr (| Base t, Lift x |) :: acc) | Interpolate (Array t) :: args -> // Arrays are implicitly polymorphic in their preorders `r` and `s` // which is what forces us to be in universe 1 // Note, the length `l` is explicit l:UInt32.t -> #p:perm -> #v:Ghost.erased (Seq.seq (base_typ_as_type t)) -> b:lmbuffer (base_typ_as_type t) l -> interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) | Interpolate Any :: args -> #a:Type0 -> p:(a -> StTrivial unit) -> x:a -> interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc) | Frag s :: args -> // Literal fragments do not incur an additional argument // We just accumulate them and recur interpret_frags args (Inl s :: acc) /// `normal` A normalization marker with very specific steps enabled noextract unfold let normal (#a:Type) (x:a) : a = FStar.Pervasives.norm [iota; zeta; delta_attr [`%__printf_reduce__; `%BigOps.__reduce__]; delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string]; primops; simplify] x /// `coerce`: A utility to trigger extensional equality of types noextract let coerce (x:'a{'a == 'b}) : 'b = x /// `fragment_printer`: The type of a printer of fragments noextract let fragment_printer = (acc:list frag_t) -> STT unit (live_frags acc) (fun _ -> live_frags acc) /// `print_frags`: Having accumulated all the pieces of a format /// string and the arguments to the printed (i.e., the `list frag_t`), /// this function does the actual work of printing them all using the /// primitive printers noextract inline_for_extraction let print_lmbuffer_gen (#t: Type) (#fr: frag_t) (f: stBuf t) (l: U32.t) (#tb: Type) (b: tb) (p: perm) (#tv: Type) (v: tv) : ST unit (live_frag fr) (fun _ -> live_frag fr) (tb == lmbuffer t l /\ tv == Ghost.erased (Seq.seq t) /\ live_frag fr == A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v)) (fun _ -> True) = [@inline_let] let b' : lmbuffer t l = coerce b in let v' : Ghost.erased (Seq.seq t) = coerce v in let p' : Ghost.erased (lmbuffer t l & perm) = Ghost.hide (b', p) in rewrite (live_frag fr) (A.pts_to #t (fst p') (snd p') v'); f l _ _ (A.ptr_of b'); rewrite (A.pts_to _ _ _) (live_frag fr) noextract inline_for_extraction let print_frag (hd: frag_t) : STT unit (live_frag hd) (fun _ -> live_frag hd) = (match hd with | Inl s -> print_string s | Inr (| Base t, Lift value |) -> (match t with | Bool -> print_bool value | Char -> print_char value | String -> print_string value | U8 -> print_u8 value | U16 -> print_u16 value | U32 -> print_u32 value | U64 -> print_u64 value | I8 -> print_i8 value | I16 -> print_i16 value | I32 -> print_i32 value | I64 -> print_i64 value) | Inr (| Array t, Lift ((| l, value |), p, v ) |) -> (match t with | Bool -> print_lmbuffer_gen print_lmbuffer_bool l value p v | Char -> print_lmbuffer_gen print_lmbuffer_char l value p v | String -> print_lmbuffer_gen print_lmbuffer_string l value p v | U8 -> print_lmbuffer_gen print_lmbuffer_u8 l value p v | U16 -> print_lmbuffer_gen print_lmbuffer_u16 l value p v | U32 -> print_lmbuffer_gen print_lmbuffer_u32 l value p v | U64 -> print_lmbuffer_gen print_lmbuffer_u64 l value p v | I8 -> print_lmbuffer_gen print_lmbuffer_i8 l value p v | I16 -> print_lmbuffer_gen print_lmbuffer_i16 l value p v | I32 -> print_lmbuffer_gen print_lmbuffer_i32 l value p v | I64 -> print_lmbuffer_gen print_lmbuffer_i64 l value p v ) | Inr (| Any, (| _, printer, value |) |) -> printer value) noextract inline_for_extraction let rec print_frags (acc:list frag_t) : STT unit (live_frags acc) (fun _ -> live_frags acc) = match acc with | [] -> noop () | hd::tl -> rewrite (live_frags acc) (live_frag hd `star` live_frags tl); print_frags tl; print_frag hd; rewrite (live_frag hd `star` live_frags tl) (live_frags acc) [@@__printf_reduce__] let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f [@@__printf_reduce__] let elim_unit_arrow #t (f:unit -> t) : t = f () /// `aux frags acc`: This is the main workhorse which interprets a /// parsed format string (`frags`) as a variadic, stateful function [@@__printf_reduce__]
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.Array.fsti.checked", "Steel.Effect.Common.fsti.checked", "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.String.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Char.fsti.checked", "FStar.BigOps.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.Printf.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "Steel.ST.Array", "short_module": "A" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.String", "short_module": null }, { "abbrev": false, "full_module": "FStar.Char", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
frags: Steel.ST.Printf.fragments -> acc: Prims.list Steel.ST.Printf.frag_t -> fp: Steel.ST.Printf.fragment_printer -> Steel.ST.Printf.interpret_frags frags acc
Prims.Tot
[ "total" ]
[]
[ "Steel.ST.Printf.fragments", "Prims.list", "Steel.ST.Printf.frag_t", "Steel.ST.Printf.fragment_printer", "Steel.ST.Printf.interpret_frags", "Prims.Nil", "Steel.ST.Printf.fragment", "Steel.ST.Printf.lift", "Prims.unit", "Steel.ST.Printf.live_frags", "Steel.Effect.Common.vprop", "Prims.string", "Steel.ST.Printf.coerce", "Prims.Cons", "FStar.Pervasives.Inl", "Prims.dtuple2", "Steel.ST.Printf.arg", "Steel.ST.Printf.arg_t", "Steel.ST.Printf.aux", "Steel.ST.Printf.base_typ", "Steel.ST.Printf.base_typ_as_type", "FStar.Pervasives.Inr", "Prims.Mkdtuple2", "Steel.ST.Printf.Base", "Steel.ST.Printf.Lift", "Steel.ST.Printf.Interpolate", "Steel.ST.Printf.Array", "FStar.UInt32.t", "Steel.FractionalPermission.perm", "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Steel.ST.Printf.lmbuffer", "FStar.Pervasives.Native.tuple3", "FStar.Pervasives.Native.Mktuple3", "Steel.ST.Printf.elim_unit_arrow", "Steel.ST.Printf.no_inst", "Steel.ST.Printf.Any", "FStar.Pervasives.Mkdtuple3" ]
[ "recursion" ]
false
false
false
false
false
let rec aux (frags: fragments) (acc: list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with | [] -> let f (l: lift u#0 u#1 unit) : STT unit (live_frags acc) (fun _ -> live_frags acc) = fp acc in (f <: interpret_frags [] acc) | Frag s :: rest -> coerce (aux rest (Inl s :: acc) fp) | Interpolate (Base t) :: args -> let f (x: base_typ_as_type t) : interpret_frags args (Inr (| Base t, Lift x |) :: acc) = aux args (Inr (| Base t, Lift x |) :: acc) fp in f | Interpolate (Array t) :: rest -> let f: l: UInt32.t -> #p: perm -> #v: Ghost.erased (Seq.seq (base_typ_as_type t)) -> b: lmbuffer (base_typ_as_type t) l -> interpret_frags rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) = fun l #p #v b -> aux rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) fp in f <: interpret_frags (Interpolate (Array t) :: rest) acc | Interpolate Any :: rest -> let f: unit -> #a: Type -> p: (a -> StTrivial unit) -> x: a -> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc) = fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp in elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.uint64_t
val uint64_t : Prims.eqtype
let uint64_t = U64.t
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 20, "end_line": 36, "start_col": 0, "start_line": 36 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.eqtype
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt64.t" ]
[]
false
false
false
true
false
let uint64_t =
U64.t
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.uint8_p
val uint8_p : Type0
let uint8_p = B.buffer uint8_t
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 30, "end_line": 38, "start_col": 0, "start_line": 38 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "LowStar.Buffer.buffer", "MerkleTree.Low.Serialization.uint8_t" ]
[]
false
false
false
true
true
let uint8_p =
B.buffer uint8_t
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.serialize_offset_t
val serialize_offset_t : ok: Prims.bool -> x: MerkleTree.Low.Serialization.uint64_t -> buf: MerkleTree.Low.Serialization.uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.Monotonic.Buffer.len buf = sz} -> pos: MerkleTree.Low.Serialization.uint32_t -> FStar.HyperStack.ST.ST (Prims.bool * MerkleTree.Low.Serialization.uint32_t)
let serialize_offset_t = serialize_uint64_t
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 51, "end_line": 80, "start_col": 8, "start_line": 80 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" private let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end private let serialize_uint8_t (ok:bool) (x:uint8_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos x; (true, pos + 1ul) end private let serialize_uint16_t (ok:bool) (x:uint16_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint8_t ok (Int.Cast.uint16_to_uint8 (U16.shift_right x 8ul)) buf sz pos in serialize_uint8_t ok (Int.Cast.uint16_to_uint8 x) buf sz pos private let serialize_uint32_t (ok:bool) (x:uint32_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint16_t ok (Int.Cast.uint32_to_uint16 (U32.shift_right x 16ul)) buf sz pos in serialize_uint16_t ok (Int.Cast.uint32_to_uint16 x) buf sz pos private let serialize_uint64_t (ok:bool) (x:uint64_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint32_t ok (Int.Cast.uint64_to_uint32 (U64.shift_right x 32ul)) buf sz pos in serialize_uint32_t ok (Int.Cast.uint64_to_uint32 x) buf sz pos
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ok: Prims.bool -> x: MerkleTree.Low.Serialization.uint64_t -> buf: MerkleTree.Low.Serialization.uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.Monotonic.Buffer.len buf = sz} -> pos: MerkleTree.Low.Serialization.uint32_t -> FStar.HyperStack.ST.ST (Prims.bool * MerkleTree.Low.Serialization.uint32_t)
FStar.HyperStack.ST.ST
[]
[]
[ "MerkleTree.Low.Serialization.serialize_uint64_t" ]
[]
false
true
false
false
false
let serialize_offset_t =
serialize_uint64_t
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.hash_vv_bytes
val hash_vv_bytes (#hash_size: hash_size_t) (vv: hash_vv hash_size {V.size_of vv = merkle_tree_size_lg}) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1))
val hash_vv_bytes (#hash_size: hash_size_t) (vv: hash_vv hash_size {V.size_of vv = merkle_tree_size_lg}) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1))
let hash_vv_bytes (#hash_size:hash_size_t) (vv:hash_vv hash_size {V.size_of vv = merkle_tree_size_lg}) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = hash_vv_bytes_i vv 0ul
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 24, "end_line": 179, "start_col": 0, "start_line": 173 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" private let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end private let serialize_uint8_t (ok:bool) (x:uint8_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos x; (true, pos + 1ul) end private let serialize_uint16_t (ok:bool) (x:uint16_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint8_t ok (Int.Cast.uint16_to_uint8 (U16.shift_right x 8ul)) buf sz pos in serialize_uint8_t ok (Int.Cast.uint16_to_uint8 x) buf sz pos private let serialize_uint32_t (ok:bool) (x:uint32_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint16_t ok (Int.Cast.uint32_to_uint16 (U32.shift_right x 16ul)) buf sz pos in serialize_uint16_t ok (Int.Cast.uint32_to_uint16 x) buf sz pos private let serialize_uint64_t (ok:bool) (x:uint64_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint32_t ok (Int.Cast.uint64_to_uint32 (U64.shift_right x 32ul)) buf sz pos in serialize_uint32_t ok (Int.Cast.uint64_to_uint32 x) buf sz pos private let serialize_offset_t = serialize_uint64_t private let serialize_index_t = serialize_uint32_t private let rec serialize_hash_i (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < hash_size}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else let b = x.(i) in let ok, pos = serialize_uint8_t ok (Lib.RawIntTypes.u8_to_UInt8 b) buf sz pos in let j = i + 1ul in if j < hash_size then serialize_hash_i #hash_size ok x buf sz pos j else (ok, pos) private let serialize_hash (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else serialize_hash_i ok x buf sz pos 0ul private inline_for_extraction let u64_add_fits (x:uint64_t) (y:uint64_t): Tot (r:bool{r ==> UInt.size (U64.v x + U64.v y) 64}) = uint64_max - x >= y #push-options "--z3rlimit 100 --fuel 1 --quake 1/3" private inline_for_extraction let hash_vec_bytes (#hash_size:hash_size_t) (v:hash_vec #hash_size) : Tot uint64_t = let vs_hs = U64.mul (u32_64 (V.size_of v)) (u32_64 hash_size) in if u64_add_fits vs_hs 4UL then vs_hs + 4UL else uint64_max #pop-options private let rec serialize_hash_vec_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ loc_disjoint (B.loc_buffer buf) (loc_rvector x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let ok, pos = serialize_hash ok vi buf sz pos in let j = i + 1ul in if j < V.size_of x then serialize_hash_vec_i ok x buf sz pos j else (ok, pos) end private let serialize_hash_vec (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvreg hash_size) x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if ok && V.size_of x > 0ul then serialize_hash_vec_i ok x buf sz pos 0ul else (ok, pos) end private inline_for_extraction let rec hash_vv_bytes_i (#hash_size:hash_size_t) (vv:hash_vv hash_size) (i:uint32_t) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = if i >= V.size_of vv then 4UL else begin let vvi = V.index vv i in let r = hash_vec_bytes vvi in let rest = hash_vv_bytes_i vv (i+1ul) in if u64_add_fits r rest then begin assert (UInt.size (U64.v r + U64.v rest) 64); r + rest end else uint64_max end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
vv: MerkleTree.Low.Datastructures.hash_vv hash_size {LowStar.Vector.size_of vv = MerkleTree.Low.merkle_tree_size_lg} -> FStar.HyperStack.ST.ST MerkleTree.Low.Serialization.uint64_t
FStar.HyperStack.ST.ST
[]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "MerkleTree.Low.Datastructures.hash_vv", "Prims.b2t", "Prims.op_Equality", "LowStar.Vector.uint32_t", "LowStar.Vector.size_of", "MerkleTree.Low.Datastructures.hash_vec", "MerkleTree.Low.merkle_tree_size_lg", "MerkleTree.Low.Serialization.hash_vv_bytes_i", "FStar.UInt32.__uint_to_t", "MerkleTree.Low.Serialization.uint64_t", "FStar.Monotonic.HyperStack.mem", "LowStar.Vector.live", "Prims.eq2" ]
[]
false
true
false
false
false
let hash_vv_bytes (#hash_size: hash_size_t) (vv: hash_vv hash_size {V.size_of vv = merkle_tree_size_lg}) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) =
hash_vv_bytes_i vv 0ul
false
Hacl.Spec.BignumQ.Mul.fst
Hacl.Spec.BignumQ.Mul.sub_mod_264
val sub_mod_264: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < pow2 264 /\ as_nat5 y < pow2 264) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ (if as_nat5 x >= as_nat5 y then as_nat5 z == as_nat5 x - as_nat5 y else as_nat5 z == as_nat5 x - as_nat5 y + pow2 264))
val sub_mod_264: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < pow2 264 /\ as_nat5 y < pow2 264) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ (if as_nat5 x >= as_nat5 y then as_nat5 z == as_nat5 x - as_nat5 y else as_nat5 z == as_nat5 x - as_nat5 y + pow2 264))
let sub_mod_264 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let (c1, t0) = subm_step x0 y0 in assert (v x0 - v y0 == v t0 - v c1 * pow56); let (c2, t1) = subm_step x1 (y1 +! c1) in assert (v x1 - v y1 - v c1 == v t1 - v c2 * pow56); let (c3, t2) = subm_step x2 (y2 +! c2) in assert (v x2 - v y2 - v c2 == v t2 - v c3 * pow56); let (c4, t3) = subm_step x3 (y3 +! c3) in assert (v x3 - v y3 - v c3 == v t3 - v c4 * pow56); Lemmas.lemma_as_nat_pow264_x4 (x0, x1, x2, x3, x4); Lemmas.lemma_as_nat_pow264_x4 (y0, y1, y2, y3, y4); let (c5, t4) = subm_last_step x4 (y4 +! c4) in assert (v x4 - v y4 - v c4 == v t4 - pow2 40 * v c5); assert ( if v c5 = 0 then as_nat5 (x0, x1, x2, x3, x4) >= as_nat5 (y0, y1, y2, y3, y4) else as_nat5 (x0, x1, x2, x3, x4) < as_nat5 (y0, y1, y2, y3, y4)); assert_norm (pow2 40 < pow2 56); assert (qelem_fits5 (t0, t1, t2, t3, t4) (1, 1, 1, 1, 1)); assert (as_nat5 (t0, t1, t2, t3, t4) == v x0 - v y0 + v c1 * pow56 + (v x1 - v y1 - v c1 + v c2 * pow56) * pow56 + (v x2 - v y2 - v c2 + v c3 * pow56) * pow112 + (v x3 - v y3 - v c3 + v c4 * pow56) * pow168 + (v x4 - v y4 - v c4 + pow2 40 * v c5) * pow224); Lemmas.lemma_sub_mod_264_aux (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) (v c1) (v c2) (v c3) (v c4) (v c5); assert (as_nat5 (t0, t1, t2, t3, t4) == as_nat5 (x0, x1, x2, x3, x4) - as_nat5 (y0, y1, y2, y3, y4) + v c5 * pow2 264); Lemmas.lemma_sub_mod_264 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) (t0, t1, t2, t3, t4) c5; (t0, t1, t2, t3, t4)
{ "file_name": "code/ed25519/Hacl.Spec.BignumQ.Mul.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 22, "end_line": 798, "start_col": 0, "start_line": 766 }
module Hacl.Spec.BignumQ.Mul open FStar.Mul open Lib.IntTypes module S = Spec.Ed25519 module Lemmas = Hacl.Spec.BignumQ.Lemmas include Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask56 : x:uint64{v x == pow2 56 - 1} = assert_norm (pow2 56 - 1 == 0xffffffffffffff); u64 0xffffffffffffff inline_for_extraction noextract let mask40 : x:uint64{v x == pow2 40 - 1} = assert_norm (pow2 40 - 1 == 0xffffffffff); u64 0xffffffffff inline_for_extraction noextract val make_m: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == S.q} let make_m () = let m0 = u64 0x12631a5cf5d3ed in let m1 = u64 0xf9dea2f79cd658 in let m2 = u64 0x000000000014de in let m3 = u64 0x00000000000000 in let m4 = u64 0x00000010000000 in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val make_mu: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == pow2 512 / S.q} let make_mu m = let m0 = u64 0x9ce5a30a2c131b in let m1 = u64 0x215d086329a7ed in let m2 = u64 0xffffffffeb2106 in let m3 = u64 0xffffffffffffff in let m4 = u64 0x00000fffffffff in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == pow2 512 / S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val choose: b:uint64 -> x:qelem5 -> y:qelem5 -> Pure qelem5 (requires v b == 0 \/ v b == 1) (ensures fun z -> if v b = 1 then z == x else z == y) let choose b (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let mask = b -. u64 1 in let z0 = x0 ^. (mask &. (x0 ^. y0)) in Lemmas.lemma_choose_step b x0 y0; let z1 = x1 ^. (mask &. (x1 ^. y1)) in Lemmas.lemma_choose_step b x1 y1; let z2 = x2 ^. (mask &. (x2 ^. y2)) in Lemmas.lemma_choose_step b x2 y2; let z3 = x3 ^. (mask &. (x3 ^. y3)) in Lemmas.lemma_choose_step b x3 y3; let z4 = x4 ^. (mask &. (x4 ^. y4)) in Lemmas.lemma_choose_step b x4 y4; (z0, z1, z2, z3, z4) inline_for_extraction noextract val subm_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow56 /\ v y <= pow56) (ensures fun (b, t) -> v b <= 1 /\ qelem_fits1 t 1 /\ v x - v y == v t - v b * pow56) let subm_step x y = let b = (x -. y) >>. 63ul in //assert (if v x >= v y then v b == 0 else v b == 1); let lshift56 = (b <<. 56ul) in //assert (if v x >= v y then v lshift56 == 0 else v lshift56 == pow56); //assert (v lshift56 == v b * pow56); //assert (v ((b <<. 56ul) +! x) == v b * pow56 + v x); let t = ((b <<. 56ul) +! x) -! y in b, t inline_for_extraction noextract val subm_conditional: x:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ (if as_nat5 x >= S.q then as_nat5 r == as_nat5 x - S.q else as_nat5 r == as_nat5 x)) let subm_conditional (x0, x1, x2, x3, x4) = let (y0, y1, y2, y3, y4) = make_m () in let (b0, t0) = subm_step x0 y0 in assert (v x0 - v y0 == v t0 - v b0 * pow56); let (b1, t1) = subm_step x1 (y1 +! b0) in assert (v x1 - v y1 - v b0 == v t1 - v b1 * pow56); let (b2, t2) = subm_step x2 (y2 +! b1) in assert (v x2 - v y2 - v b1 == v t2 - v b2 * pow56); let (b3, t3) = subm_step x3 (y3 +! b2) in assert (v x3 - v y3 - v b2 == v t3 - v b3 * pow56); let (b4, t4) = subm_step x4 (y4 +! b3) in assert (v x4 - v y4 - v b3 == v t4 - v b4 * pow56); Lemmas.lemma_subm_conditional (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) (v b0) (v b1) (v b2) (v b3) (v b4); assert ( as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow56 * pow224 == as_nat5 (x0, x1, x2, x3, x4) - as_nat5 (y0, y1, y2, y3, y4)); //assert_norm (pow56 * pow224 = pow2 280); //assert (as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow2 280 == as_nat5 (x0, x1, x2, x3, x4) - S.q); Lemmas.lemma_as_nat5 (x0, x1, x2, x3, x4); Lemmas.lemma_as_nat5 (t0, t1, t2, t3, t4); //assert (if v b4 = 0 then as_nat5 (x0, x1, x2, x3, x4) >= S.q else as_nat5 (x0, x1, x2, x3, x4) < S.q); assert (if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 else v b4 == 1); let (z0, z1, z2, z3, z4) = choose b4 (x0, x1, x2, x3, x4) (t0, t1, t2, t3, t4) in assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else v b4 == 1 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); (z0, z1, z2, z3, z4) inline_for_extraction noextract val carry56: x:uint64 -> Pure (uint64 & uint64) (requires v x <= pow2 57) (ensures fun (t, c) -> v t < pow56 /\ v c <= 2 /\ v x == v c * pow56 + v t) let carry56 x = let carry = x >>. 56ul in FStar.Math.Lemmas.pow2_minus 57 56; let t = x &. mask56 in assert_norm (pow2 56 < pow2 64); mod_mask_lemma x 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); t, carry inline_for_extraction noextract val add_modq5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < S.q /\ as_nat5 y < S.q) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (as_nat5 x + as_nat5 y) % S.q) let add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = assert_norm (pow56 - 1 + pow56 - 1 == pow2 57 - 2); let (t0, c0) = carry56 (x0 +! y0) in let (t1, c1) = carry56 (x1 +! y1 +! c0) in let (t2, c2) = carry56 (x2 +! y2 +! c1) in let (t3, c3) = carry56 (x3 +! y3 +! c2) in let t4 = x4 +! y4 +! c3 in assert (as_nat5 (t0, t1, t2, t3, t4) == as_nat5 (x0, x1, x2, x3, x4) + as_nat5 (y0, y1, y2, y3, y4)); let (o0, o1, o2, o3, o4) = subm_conditional (t0, t1, t2, t3, t4) in Lemmas.lemma_add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) (t0, t1, t2, t3, t4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry56_wide: x:uint128 -> Pure (uint128 & uint64) (requires v x < pow2 117) (ensures fun (c, t) -> v t < pow56 /\ v c < pow2 61 /\ v x - v c * pow56 == v t /\ v c == v x / pow56) let carry56_wide x = let carry = x >>. 56ul in let t = to_u64 x &. mask56 in assert_norm (pow2 56 < pow2 64); Math.Lemmas.lemma_div_lt_nat (v x) 117 56; mod_mask_lemma (to_u64 x) 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == (v x % pow2 64) % pow2 56); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v x) 56 64; assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); carry, t inline_for_extraction noextract val mul64_wide_5: (a:uint64) -> (b:uint64) -> Pure uint128 (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures fun z -> v z == v a * v b /\ v z <= pow2 112 - pow2 57 + 1 /\ v z < pow2 112) let mul64_wide_5 a b = let lemma_smaller (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) < pow2 112) = if v a = 0 || v b = 0 then () else calc (<) { v a * v b <: int; (<) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56) } v a * pow2 56; (<) { Math.Lemmas.lemma_mult_le_right (pow2 56) (v a) (pow2 56) } pow2 56 * pow2 56; (==) { assert_norm (pow2 56 * pow2 56 == pow2 112) } pow2 112; } in let lemma_le (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) <= pow2 112 - pow2 57 + 1) = if v a = 0 || v b = 0 then () else assert_norm (pow2 112 - pow2 57 + 1 >= 0); calc (<=) { v a * v b <: int; (<=) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56 - 1) } v a * (pow2 56 - 1); (<=) { Math.Lemmas.lemma_mult_le_right (pow2 56 - 1) (v a) (pow2 56 - 1) } (pow2 56 - 1) * (pow2 56 - 1); (==) { assert_norm ((pow2 56 - 1) * (pow2 56 - 1) == pow2 112 - pow2 57 + 1) } pow2 112 - pow2 57 + 1; } in lemma_le a b; lemma_smaller a b; mul64_wide a b inline_for_extraction noextract val add2: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112) (ensures fun z -> v z == v a + v b /\ v z <= pow2 116) let add2 a b = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b inline_for_extraction noextract val add3: (a:uint128) -> (b:uint128) -> (c:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 ) (ensures fun z -> v z == v a + v b + v c /\ v z <= pow2 116) let add3 a b c = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); a +. b +. c inline_for_extraction noextract val add4: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d /\ v z <= pow2 116) let add4 a b c d = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d) (pow2 128); a +. b +. c +. d inline_for_extraction noextract val add5: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> (e:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112 /\ v e < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d + v e/\ v z <= pow2 116) let add5 a b c d e = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d + v e) (pow2 128); a +. b +. c +. d +. e inline_for_extraction noextract val add_inner_carry: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a <= pow2 116 /\ v b < pow2 61) (ensures fun z -> v z == v a + v b /\ v z < pow2 117) let add_inner_carry a b = assert_norm (pow2 116 + pow2 61 < pow2 128); assert_norm (pow2 116 + pow2 61 < pow2 117); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b inline_for_extraction noextract val mul_5: x:qelem5 -> y:qelem5 -> Pure qelem_wide5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1)) (ensures fun r -> qelem_wide_fits5 r (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 r == as_nat5 x * as_nat5 y) let lemma_mult_distr_3 (a b c:nat) (n:nat) : Lemma ((a + b - c * pow2 56) * pow2 n == a * pow2 n + b * pow2 n - c * pow2 (n + 56)) = Math.Lemmas.distributivity_sub_left (a + b) (c * pow2 56) (pow2 n); Math.Lemmas.distributivity_add_left a b (pow2 n); Math.Lemmas.pow2_plus 56 n #set-options "--z3rlimit 300" let mul_5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let xy00 = mul64_wide_5 x0 y0 in let xy01 = mul64_wide_5 x0 y1 in let xy02 = mul64_wide_5 x0 y2 in let xy03 = mul64_wide_5 x0 y3 in let xy04 = mul64_wide_5 x0 y4 in let xy10 = mul64_wide_5 x1 y0 in let xy11 = mul64_wide_5 x1 y1 in let xy12 = mul64_wide_5 x1 y2 in let xy13 = mul64_wide_5 x1 y3 in let xy14 = mul64_wide_5 x1 y4 in let xy20 = mul64_wide_5 x2 y0 in let xy21 = mul64_wide_5 x2 y1 in let xy22 = mul64_wide_5 x2 y2 in let xy23 = mul64_wide_5 x2 y3 in let xy24 = mul64_wide_5 x2 y4 in let xy30 = mul64_wide_5 x3 y0 in let xy31 = mul64_wide_5 x3 y1 in let xy32 = mul64_wide_5 x3 y2 in let xy33 = mul64_wide_5 x3 y3 in let xy34 = mul64_wide_5 x3 y4 in let xy40 = mul64_wide_5 x4 y0 in let xy41 = mul64_wide_5 x4 y1 in let xy42 = mul64_wide_5 x4 y2 in let xy43 = mul64_wide_5 x4 y3 in let xy44 = mul64_wide_5 x4 y4 in let z0 = xy00 in // < pow2 112 let z1 = add2 xy01 xy10 in // < pow2 113 let z2 = add3 xy02 xy11 xy20 in // < pow2 114 let z3 = add4 xy03 xy12 xy21 xy30 in // < pow2 115 let z4 = add5 xy04 xy13 xy22 xy31 xy40 in // < pow2 116 let z5 = add4 xy14 xy23 xy32 xy41 in let z6 = add3 xy24 xy33 xy42 in let z7 = add2 xy34 xy43 in let z8 = xy44 in //(z0, z1, z2, z3, z4, z5, z6, z7, z8) assert_norm (pow2 112 < pow2 117); assert_norm (pow2 112 <= pow2 116); let (c0, t0) = carry56_wide z0 in let (c1, t1) = carry56_wide (add_inner_carry z1 c0) in let (c2, t2) = carry56_wide (add_inner_carry z2 c1) in let (c3, t3) = carry56_wide (add_inner_carry z3 c2) in let (c4, t4) = carry56_wide (add_inner_carry z4 c3) in let (c5, t5) = carry56_wide (add_inner_carry z5 c4) in let (c6, t6) = carry56_wide (add_inner_carry z6 c5) in let (c7, t7) = carry56_wide (add_inner_carry z7 c6) in let (c8, t8) = carry56_wide (add_inner_carry z8 c7) in let t9 = to_u64 c8 in let lemma_t9_fits () : Lemma (v t9 < pow2 56) = // This proof was built from the bottom. We have as a constraint that v c8 has to be < pow2 112 to satisfy the postcondition. // We compute each time the maximal value such that this postcondition is satisfied calc (<) { v c0; (<) { Math.Lemmas.lemma_div_lt_nat (v z0) 112 56 } pow2 56; }; calc (<) { v c1; (<) { assert_norm (2*(pow2 112 - pow2 57 + 1) + pow2 56 <= pow2 113); Math.Lemmas.lemma_div_lt_nat (v z1 + v c0) 113 56 } pow2 57; }; calc (<) { v c2; (<) { assert_norm (3*(pow2 112 - pow2 57 + 1) + pow2 57 <= pow2 114); Math.Lemmas.lemma_div_lt_nat (v z2 + v c1) 114 56 } pow2 58; }; calc (<=) { v c3; (<=) { assert_norm (4*(pow2 112 - pow2 57 + 1) + pow2 58 <= 31153781151208965410895007785680895); assert_norm (31153781151208965410895007785680895 / pow56 == 432345564227567610); Math.Lemmas.lemma_div_le (v z3 + v c2) 31153781151208965410895007785680895 (pow2 56) } 432345564227567610; }; calc (<=) { v c4; (<=) { assert_norm (5*(pow2 112 - pow2 57 + 1) + 432345564227567610 <= 25961484292674137854422105494388735); // (pow2 59 - 2) * pow56 assert_norm (25961484292674137854422105494388735 / pow56 == 360287970189639675); Math.Lemmas.lemma_div_le (v z4 + v c3) 25961484292674137854422105494388735 (pow2 56) } 360287970189639675; }; calc (<=) { v c5; (<=) { assert_norm (4*(pow2 112 - pow2 57 + 1) + 360287970189639675 <= 20769187434139310297949203203096575); Math.Lemmas.lemma_div_le (v z5 + v c4) 20769187434139310297949203203096575 (pow2 56); assert_norm (20769187434139310297949203203096575 / pow2 56 == pow2 58 - 4) } pow2 58 - 4; }; calc (<=) { v c6; (<=) { assert_norm (3*(pow2 112 - pow2 57 + 1) + pow2 58 - 4 <= 15576890575604482741476300911804415); Math.Lemmas.lemma_div_le (v z6 + v c5) 15576890575604482741476300911804415 (pow2 56); assert_norm (15576890575604482741476300911804415 / pow2 56 == 216172782113783805) } 216172782113783805; }; calc (<=) { v c7; (<=) { assert_norm (2*(pow2 112 - pow2 57 + 1) + 216172782113783805 <= 10384593717069655185003398620512255); // (pow2 57 - 1) * pow2 56 - 1 Math.Lemmas.lemma_div_le (v z7 + v c6) 10384593717069655185003398620512255 (pow2 56); assert_norm (10384593717069655185003398620512255 / pow2 56 == pow2 57 - 2) } pow2 57 - 2; }; calc (<) { v c8; (<) { Math.Lemmas.lemma_div_lt_nat (v z8 + v c7) 112 56 } pow2 56; }; assert_norm (pow2 56 < pow2 64); Math.Lemmas.small_mod (v c8) (pow2 64) in lemma_t9_fits(); calc (==) { wide_as_nat5 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) <: int; (==) { } v t0 + v t1 * pow56 + v t2 * pow112 + v t3 * pow168 + v t4 * pow224 + v t5 * pow280 + v t6 * pow336 + v t7 * pow392 + v t8 * pow448 + v t9 * pow504; (==) { assert_norm (pow2 61 < pow2 64); Math.Lemmas.small_mod (v c8) (pow2 64) } v z0 - v c0 * pow2 56 + (v z1 + v c0 - v c1 * pow2 56) * pow56 + (v z2 + v c1 - v c2 * pow2 56) * pow112 + (v z3 + v c2 - v c3 * pow2 56) * pow168 + (v z4 + v c3 - v c4 * pow2 56) * pow224 + (v z5 + v c4 - v c5 * pow2 56) * pow280 + (v z6 + v c5 - v c6 * pow2 56) * pow336 + (v z7 + v c6 - v c7 * pow2 56) * pow392 + (v z8 + v c7 - v c8 * pow2 56) * pow448 + v c8 * pow504; (==) { lemma_mult_distr_3 (v z1) (v c0) (v c1) 56; lemma_mult_distr_3 (v z2) (v c1) (v c2) 112; lemma_mult_distr_3 (v z3) (v c2) (v c3) 168; lemma_mult_distr_3 (v z4) (v c3) (v c4) 224; lemma_mult_distr_3 (v z5) (v c4) (v c5) 280; lemma_mult_distr_3 (v z6) (v c5) (v c6) 336; lemma_mult_distr_3 (v z7) (v c6) (v c7) 392; lemma_mult_distr_3 (v z8) (v c7) (v c8) 448 } v z0 + v z1 * pow56 + v z2 * pow112 + v z3 * pow168 + v z4 * pow224 + v z5 * pow280 + v z6 * pow336 + v z7 * pow392 + v z8 * pow448; (==) { calc (==) { v z1; (==) { } v x0 * v y1 + v x1 * v y0; }; calc (==) { v z2; (==) { } v x0 * v y2 + v x1 * v y1 + v x2 * v y0; }; calc (==) { v z3; (==) { } v x0 * v y3 + v x1 * v y2 + v x2 * v y1 + v x3 * v y0; }; calc (==) { v z4; (==) { } v x0 * v y4 + v x1 * v y3 + v x2 * v y2 + v x3 * v y1 + v x4 * v y0; }; calc (==) { v z5; (==) { } v x1 * v y4 + v x2 * v y3 + v x3 * v y2 + v x4 * v y1; }; calc (==) { v z6; (==) { } v x2 * v y4 + v x3 * v y3 + v x4 * v y2; }; calc (==) { v z7; (==) { } v x3 * v y4 + v x4 * v y3; }; calc (==) { v z8; (==) { } v x4 * v y4; } } v x0 * v y0 + (v x0 * v y1 + v x1 * v y0) * pow56 + (v x0 * v y2 + v x1 * v y1 + v x2 * v y0) * pow112 + (v x0 * v y3 + v x1 * v y2 + v x2 * v y1 + v x3 * v y0) * pow168 + (v x0 * v y4 + v x1 * v y3 + v x2 * v y2 + v x3 * v y1 + v x4 * v y0) * pow224 + (v x1 * v y4 + v x2 * v y3 + v x3 * v y2 + v x4 * v y1) * pow280 + (v x2 * v y4 + v x3 * v y3 + v x4 * v y2) * pow336 + (v x3 * v y4 + v x4 * v y3) * pow392 + (v x4 * v y4) * pow448; (==) { Lemmas.lemma_mul_qelem5 (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) } (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224) * (v y0 + v y1 * pow2 56 + v y2 * pow2 112 + v y3 * pow2 168 + v y4 * pow2 224); }; (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) inline_for_extraction noextract val low_mul_5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (as_nat5 x * as_nat5 y) % pow2 264) let low_mul_5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let xy00 = mul64_wide_5 x0 y0 in let xy01 = mul64_wide_5 x0 y1 in let xy02 = mul64_wide_5 x0 y2 in let xy03 = mul64_wide_5 x0 y3 in let xy04 = mul64_wide_5 x0 y4 in let xy10 = mul64_wide_5 x1 y0 in let xy11 = mul64_wide_5 x1 y1 in let xy12 = mul64_wide_5 x1 y2 in let xy13 = mul64_wide_5 x1 y3 in let xy20 = mul64_wide_5 x2 y0 in let xy21 = mul64_wide_5 x2 y1 in let xy22 = mul64_wide_5 x2 y2 in let xy30 = mul64_wide_5 x3 y0 in let xy31 = mul64_wide_5 x3 y1 in let xy40 = mul64_wide_5 x4 y0 in assert_norm (pow2 112 < pow2 117); let (c0, t0) = carry56_wide xy00 in let (c1, t1) = carry56_wide (add_inner_carry (add2 xy01 xy10) c0) in let (c2, t2) = carry56_wide (add_inner_carry (add3 xy02 xy11 xy20) c1) in let (c3, t3) = carry56_wide (add_inner_carry (add4 xy03 xy12 xy21 xy30) c2) in let t4 = to_u64 (add_inner_carry (add5 xy04 xy13 xy22 xy31 xy40) c3) &. mask40 in calc (==) { as_nat5 (t0, t1, t2, t3, t4) <: int; (==) { } v t0 + v t1 * pow56 + v t2 * pow112 + v t3 * pow168 + v t4 * pow224; (==) { } v xy00 - v c0 * pow2 56 + (v xy01 + v xy10 + v c0 - v c1 * pow2 56) * pow56 + (v xy02 + v xy11 + v xy20 + v c1 - v c2 * pow56) * pow112 + (v xy03 + v xy12 + v xy21 + v xy30 + v c2 - v c3 * pow56) * pow168 + v t4 * pow224; (==) { logand_mask (to_u64 (add_inner_carry (add5 xy04 xy13 xy22 xy31 xy40) c3)) mask40 40; Math.Lemmas.pow2_modulo_modulo_lemma_1 (v (add_inner_carry (add5 xy04 xy13 xy22 xy31 xy40) c3)) 40 64 } v x0 * v y0 + (v x0 * v y1 + v x1 * v y0) * pow56 + (v x0 * v y2 + v x1 * v y1 + v x2 * v y0) * pow112 + (v x0 * v y3 + v x1 * v y2 + v x2 * v y1 + v x3 * v y0 - v c3 * pow56) * pow168 + ((v x0 * v y4 + v x1 * v y3 + v x2 * v y2 + v x3 * v y1 + v x4 * v y0 + v c3) % pow2 40) * pow224; }; Lemmas.lemma_mul_5_low_264 (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4); (t0, t1, t2, t3, t4) inline_for_extraction noextract val div_2_24_step: x:uint64 -> y:uint64 -> Pure uint64 (requires v x < pow56 /\ v y < pow56) (ensures fun r -> v r < pow56 /\ v r == v x / pow2 24 + pow2 32 * (v y % pow2 24)) let div_2_24_step x y = let y' = (y &. u64 0xffffff) <<. 32ul in assert_norm (pow2 24 - 1 = 0xffffff); assert_norm (pow2 24 < pow2 64); mod_mask_lemma y 24ul; assert (v (mod_mask #U64 #SEC 24ul) == 0xffffff); assert (v (y &. u64 0xffffff) == v y % pow2 24); assert (v y' == (v y % pow2 24) * pow2 32); let x' = x >>. 24ul in FStar.Math.Lemmas.pow2_minus 56 24; assert (v x' < pow2 32); let z = x' |. y' in logor_disjoint x' y' 32; assert (v z == v x / pow2 24 + pow2 32 * (v y % pow2 24)); z inline_for_extraction noextract val div_248: x:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 x < pow2 512) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (wide_as_nat5 x) / pow2 248) let div_248 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = // x / pow2 248 == (x / pow2 224) / pow2 24 let z0 = div_2_24_step x4 x5 in let z1 = div_2_24_step x5 x6 in let z2 = div_2_24_step x6 x7 in let z3 = div_2_24_step x7 x8 in let z4 = div_2_24_step x8 x9 in assert (qelem_fits5 (z0, z1, z2, z3, z4) (1, 1, 1, 1, 1)); Lemmas.lemma_div248 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9); (z0, z1, z2, z3, z4) inline_for_extraction noextract val div_2_40_step: x:uint64 -> y:uint64 -> Pure uint64 (requires v x < pow56) (ensures fun z -> v z < pow56 /\ v z == v x / pow2 40 + pow2 16 * (v y % pow2 40)) let div_2_40_step x y = let y' = (y &. mask40) <<. 16ul in assert_norm (pow2 40 < pow2 64); mod_mask_lemma y 40ul; assert (v (mod_mask #U64 #SEC 40ul) == v mask40); assert (v y' == (v y % pow2 40) * pow2 16); let x' = x >>. 40ul in FStar.Math.Lemmas.pow2_minus 56 40; assert (v x' == v x / pow2 40); assert (v x' < pow2 16); let z = x' |. y' in logor_disjoint x' y' 16; z inline_for_extraction noextract val div_264: x:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 x < pow2 528) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (wide_as_nat5 x) / pow2 264) let div_264 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = // x / pow2 264 == (x / pow2 224) / pow2 40 let z0 = div_2_40_step x4 x5 in let z1 = div_2_40_step x5 x6 in let z2 = div_2_40_step x6 x7 in let z3 = div_2_40_step x7 x8 in let z4 = div_2_40_step x8 x9 in assert (qelem_fits5 (z0, z1, z2, z3, z4) (1, 1, 1, 1, 1)); Lemmas.lemma_div264 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9); (z0, z1, z2, z3, z4) inline_for_extraction noextract val mod_264: t:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (wide_as_nat5 t) % pow2 264) let mod_264 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = Lemmas.lemma_mod_264 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9); (t0, t1, t2, t3, t4 &. mask40) inline_for_extraction noextract val subm_last_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow2 40 /\ v y <= pow2 40) (ensures fun (b, t) -> v b <= 1 /\ v t < pow2 40 /\ v x - v y == v t - pow2 40 * v b) let subm_last_step x y = assert_norm (pow2 40 < pow2 63); let b = (x -. y) >>. 63ul in assert (if v x >= v y then v b == 0 else v b == 1); let t = ((b <<. 40ul) +! x) -! y in b, t #push-options "--z3rlimit 400 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract val sub_mod_264: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < pow2 264 /\ as_nat5 y < pow2 264) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ (if as_nat5 x >= as_nat5 y then as_nat5 z == as_nat5 x - as_nat5 y else as_nat5 z == as_nat5 x - as_nat5 y + pow2 264))
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.BignumQ.Mul.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 400, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Hacl.Spec.BignumQ.Definitions.qelem5 -> y: Hacl.Spec.BignumQ.Definitions.qelem5 -> Prims.Pure Hacl.Spec.BignumQ.Definitions.qelem5
Prims.Pure
[]
[]
[ "Hacl.Spec.BignumQ.Definitions.qelem5", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple5", "Lib.IntTypes.uint64", "FStar.Pervasives.Native.Mktuple5", "Prims.unit", "Hacl.Spec.BignumQ.Lemmas.lemma_sub_mod_264", "Prims._assert", "Prims.eq2", "Prims.int", "Hacl.Spec.BignumQ.Definitions.as_nat5", "Prims.op_Addition", "Prims.op_Subtraction", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Prims.pow2", "Hacl.Spec.BignumQ.Lemmas.lemma_sub_mod_264_aux", "Hacl.Spec.BignumQ.Definitions.pow56", "Hacl.Spec.BignumQ.Definitions.pow112", "Hacl.Spec.BignumQ.Definitions.pow168", "Hacl.Spec.BignumQ.Definitions.pow224", "Hacl.Spec.BignumQ.Definitions.qelem_fits5", "Prims.nat", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Equality", "Prims.op_GreaterThanOrEqual", "Prims.bool", "FStar.Pervasives.Native.tuple2", "Lib.IntTypes.int_t", "Hacl.Spec.BignumQ.Mul.subm_last_step", "Lib.IntTypes.op_Plus_Bang", "Hacl.Spec.BignumQ.Lemmas.lemma_as_nat_pow264_x4", "Hacl.Spec.BignumQ.Mul.subm_step" ]
[]
false
false
false
false
false
let sub_mod_264 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) =
let c1, t0 = subm_step x0 y0 in assert (v x0 - v y0 == v t0 - v c1 * pow56); let c2, t1 = subm_step x1 (y1 +! c1) in assert (v x1 - v y1 - v c1 == v t1 - v c2 * pow56); let c3, t2 = subm_step x2 (y2 +! c2) in assert (v x2 - v y2 - v c2 == v t2 - v c3 * pow56); let c4, t3 = subm_step x3 (y3 +! c3) in assert (v x3 - v y3 - v c3 == v t3 - v c4 * pow56); Lemmas.lemma_as_nat_pow264_x4 (x0, x1, x2, x3, x4); Lemmas.lemma_as_nat_pow264_x4 (y0, y1, y2, y3, y4); let c5, t4 = subm_last_step x4 (y4 +! c4) in assert (v x4 - v y4 - v c4 == v t4 - pow2 40 * v c5); assert (if v c5 = 0 then as_nat5 (x0, x1, x2, x3, x4) >= as_nat5 (y0, y1, y2, y3, y4) else as_nat5 (x0, x1, x2, x3, x4) < as_nat5 (y0, y1, y2, y3, y4)); assert_norm (pow2 40 < pow2 56); assert (qelem_fits5 (t0, t1, t2, t3, t4) (1, 1, 1, 1, 1)); assert (as_nat5 (t0, t1, t2, t3, t4) == v x0 - v y0 + v c1 * pow56 + (v x1 - v y1 - v c1 + v c2 * pow56) * pow56 + (v x2 - v y2 - v c2 + v c3 * pow56) * pow112 + (v x3 - v y3 - v c3 + v c4 * pow56) * pow168 + (v x4 - v y4 - v c4 + pow2 40 * v c5) * pow224); Lemmas.lemma_sub_mod_264_aux (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) (v c1) (v c2) (v c3) (v c4) (v c5); assert (as_nat5 (t0, t1, t2, t3, t4) == as_nat5 (x0, x1, x2, x3, x4) - as_nat5 (y0, y1, y2, y3, y4) + v c5 * pow2 264); Lemmas.lemma_sub_mod_264 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) (t0, t1, t2, t3, t4) c5; (t0, t1, t2, t3, t4)
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.deserialize_index_t
val deserialize_index_t : ok: Prims.bool -> buf: MerkleTree.Low.Serialization.const_uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.ConstBuffer.length buf = FStar.UInt32.v sz} -> pos: MerkleTree.Low.Serialization.uint32_t -> FStar.HyperStack.ST.ST ((Prims.bool * MerkleTree.Low.Serialization.uint32_t) * MerkleTree.Low.Serialization.uint32_t)
let deserialize_index_t = deserialize_uint32_t
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 54, "end_line": 266, "start_col": 8, "start_line": 266 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" private let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end private let serialize_uint8_t (ok:bool) (x:uint8_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos x; (true, pos + 1ul) end private let serialize_uint16_t (ok:bool) (x:uint16_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint8_t ok (Int.Cast.uint16_to_uint8 (U16.shift_right x 8ul)) buf sz pos in serialize_uint8_t ok (Int.Cast.uint16_to_uint8 x) buf sz pos private let serialize_uint32_t (ok:bool) (x:uint32_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint16_t ok (Int.Cast.uint32_to_uint16 (U32.shift_right x 16ul)) buf sz pos in serialize_uint16_t ok (Int.Cast.uint32_to_uint16 x) buf sz pos private let serialize_uint64_t (ok:bool) (x:uint64_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint32_t ok (Int.Cast.uint64_to_uint32 (U64.shift_right x 32ul)) buf sz pos in serialize_uint32_t ok (Int.Cast.uint64_to_uint32 x) buf sz pos private let serialize_offset_t = serialize_uint64_t private let serialize_index_t = serialize_uint32_t private let rec serialize_hash_i (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < hash_size}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else let b = x.(i) in let ok, pos = serialize_uint8_t ok (Lib.RawIntTypes.u8_to_UInt8 b) buf sz pos in let j = i + 1ul in if j < hash_size then serialize_hash_i #hash_size ok x buf sz pos j else (ok, pos) private let serialize_hash (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else serialize_hash_i ok x buf sz pos 0ul private inline_for_extraction let u64_add_fits (x:uint64_t) (y:uint64_t): Tot (r:bool{r ==> UInt.size (U64.v x + U64.v y) 64}) = uint64_max - x >= y #push-options "--z3rlimit 100 --fuel 1 --quake 1/3" private inline_for_extraction let hash_vec_bytes (#hash_size:hash_size_t) (v:hash_vec #hash_size) : Tot uint64_t = let vs_hs = U64.mul (u32_64 (V.size_of v)) (u32_64 hash_size) in if u64_add_fits vs_hs 4UL then vs_hs + 4UL else uint64_max #pop-options private let rec serialize_hash_vec_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ loc_disjoint (B.loc_buffer buf) (loc_rvector x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let ok, pos = serialize_hash ok vi buf sz pos in let j = i + 1ul in if j < V.size_of x then serialize_hash_vec_i ok x buf sz pos j else (ok, pos) end private let serialize_hash_vec (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvreg hash_size) x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if ok && V.size_of x > 0ul then serialize_hash_vec_i ok x buf sz pos 0ul else (ok, pos) end private inline_for_extraction let rec hash_vv_bytes_i (#hash_size:hash_size_t) (vv:hash_vv hash_size) (i:uint32_t) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = if i >= V.size_of vv then 4UL else begin let vvi = V.index vv i in let r = hash_vec_bytes vvi in let rest = hash_vv_bytes_i vv (i+1ul) in if u64_add_fits r rest then begin assert (UInt.size (U64.v r + U64.v rest) 64); r + rest end else uint64_max end private inline_for_extraction let hash_vv_bytes (#hash_size:hash_size_t) (vv:hash_vv hash_size {V.size_of vv = merkle_tree_size_lg}) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = hash_vv_bytes_i vv 0ul private let rec serialize_hash_vv_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vv hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let h0 = HST.get() in let ok, pos = serialize_hash_vec #hash_size ok vi buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; let j = i + 1ul in if j < V.size_of x then serialize_hash_vv_i #hash_size ok x buf sz pos j else (ok, pos) end private let serialize_hash_vv (#hash_size:hash_size_t) (ok:bool) (x:hash_vv hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if (V.size_of x > 0ul) then serialize_hash_vv_i ok x buf sz pos 0ul else (ok, pos) end private let deserialize_bool (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & bool) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, false) else (true, pos + 1ul, (match CB.index buf pos with| 0uy -> false | _ -> true)) private let deserialize_uint8_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint8_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0uy) else (true, pos + 1ul, CB.index buf pos) private let deserialize_uint16_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint16_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0us) else begin let ok, pos, b0 = deserialize_uint8_t ok buf sz pos in let ok, pos, b1 = deserialize_uint8_t ok buf sz pos in (ok, pos, (U16.shift_left (Int.Cast.uint8_to_uint16 b0) 8ul) + Int.Cast.uint8_to_uint16 b1) end private let deserialize_uint32_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint32_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0ul) else begin let ok, pos, b0 = deserialize_uint16_t ok buf sz pos in let ok, pos, b1 = deserialize_uint16_t ok buf sz pos in (ok, pos, (U32.shift_left (Int.Cast.uint16_to_uint32 b0) 16ul) + Int.Cast.uint16_to_uint32 b1) end private let deserialize_uint64_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint64_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0UL) else begin let ok, pos, b0 = deserialize_uint32_t ok buf sz pos in let ok, pos, b1 = deserialize_uint32_t ok buf sz pos in (ok, pos, (U64.shift_left (u32_64 b0) 32ul) + u32_64 b1) end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ok: Prims.bool -> buf: MerkleTree.Low.Serialization.const_uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.ConstBuffer.length buf = FStar.UInt32.v sz} -> pos: MerkleTree.Low.Serialization.uint32_t -> FStar.HyperStack.ST.ST ((Prims.bool * MerkleTree.Low.Serialization.uint32_t) * MerkleTree.Low.Serialization.uint32_t)
FStar.HyperStack.ST.ST
[]
[]
[ "MerkleTree.Low.Serialization.deserialize_uint32_t" ]
[]
false
true
false
false
false
let deserialize_index_t =
deserialize_uint32_t
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.deserialize_offset_t
val deserialize_offset_t : ok: Prims.bool -> buf: MerkleTree.Low.Serialization.const_uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.ConstBuffer.length buf = FStar.UInt32.v sz} -> pos: MerkleTree.Low.Serialization.uint32_t -> FStar.HyperStack.ST.ST ((Prims.bool * MerkleTree.Low.Serialization.uint32_t) * MerkleTree.Low.Serialization.uint64_t)
let deserialize_offset_t = deserialize_uint64_t
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 55, "end_line": 265, "start_col": 8, "start_line": 265 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" private let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end private let serialize_uint8_t (ok:bool) (x:uint8_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos x; (true, pos + 1ul) end private let serialize_uint16_t (ok:bool) (x:uint16_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint8_t ok (Int.Cast.uint16_to_uint8 (U16.shift_right x 8ul)) buf sz pos in serialize_uint8_t ok (Int.Cast.uint16_to_uint8 x) buf sz pos private let serialize_uint32_t (ok:bool) (x:uint32_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint16_t ok (Int.Cast.uint32_to_uint16 (U32.shift_right x 16ul)) buf sz pos in serialize_uint16_t ok (Int.Cast.uint32_to_uint16 x) buf sz pos private let serialize_uint64_t (ok:bool) (x:uint64_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint32_t ok (Int.Cast.uint64_to_uint32 (U64.shift_right x 32ul)) buf sz pos in serialize_uint32_t ok (Int.Cast.uint64_to_uint32 x) buf sz pos private let serialize_offset_t = serialize_uint64_t private let serialize_index_t = serialize_uint32_t private let rec serialize_hash_i (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < hash_size}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else let b = x.(i) in let ok, pos = serialize_uint8_t ok (Lib.RawIntTypes.u8_to_UInt8 b) buf sz pos in let j = i + 1ul in if j < hash_size then serialize_hash_i #hash_size ok x buf sz pos j else (ok, pos) private let serialize_hash (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else serialize_hash_i ok x buf sz pos 0ul private inline_for_extraction let u64_add_fits (x:uint64_t) (y:uint64_t): Tot (r:bool{r ==> UInt.size (U64.v x + U64.v y) 64}) = uint64_max - x >= y #push-options "--z3rlimit 100 --fuel 1 --quake 1/3" private inline_for_extraction let hash_vec_bytes (#hash_size:hash_size_t) (v:hash_vec #hash_size) : Tot uint64_t = let vs_hs = U64.mul (u32_64 (V.size_of v)) (u32_64 hash_size) in if u64_add_fits vs_hs 4UL then vs_hs + 4UL else uint64_max #pop-options private let rec serialize_hash_vec_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ loc_disjoint (B.loc_buffer buf) (loc_rvector x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let ok, pos = serialize_hash ok vi buf sz pos in let j = i + 1ul in if j < V.size_of x then serialize_hash_vec_i ok x buf sz pos j else (ok, pos) end private let serialize_hash_vec (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvreg hash_size) x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if ok && V.size_of x > 0ul then serialize_hash_vec_i ok x buf sz pos 0ul else (ok, pos) end private inline_for_extraction let rec hash_vv_bytes_i (#hash_size:hash_size_t) (vv:hash_vv hash_size) (i:uint32_t) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = if i >= V.size_of vv then 4UL else begin let vvi = V.index vv i in let r = hash_vec_bytes vvi in let rest = hash_vv_bytes_i vv (i+1ul) in if u64_add_fits r rest then begin assert (UInt.size (U64.v r + U64.v rest) 64); r + rest end else uint64_max end private inline_for_extraction let hash_vv_bytes (#hash_size:hash_size_t) (vv:hash_vv hash_size {V.size_of vv = merkle_tree_size_lg}) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = hash_vv_bytes_i vv 0ul private let rec serialize_hash_vv_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vv hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let h0 = HST.get() in let ok, pos = serialize_hash_vec #hash_size ok vi buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; let j = i + 1ul in if j < V.size_of x then serialize_hash_vv_i #hash_size ok x buf sz pos j else (ok, pos) end private let serialize_hash_vv (#hash_size:hash_size_t) (ok:bool) (x:hash_vv hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if (V.size_of x > 0ul) then serialize_hash_vv_i ok x buf sz pos 0ul else (ok, pos) end private let deserialize_bool (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & bool) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, false) else (true, pos + 1ul, (match CB.index buf pos with| 0uy -> false | _ -> true)) private let deserialize_uint8_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint8_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0uy) else (true, pos + 1ul, CB.index buf pos) private let deserialize_uint16_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint16_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0us) else begin let ok, pos, b0 = deserialize_uint8_t ok buf sz pos in let ok, pos, b1 = deserialize_uint8_t ok buf sz pos in (ok, pos, (U16.shift_left (Int.Cast.uint8_to_uint16 b0) 8ul) + Int.Cast.uint8_to_uint16 b1) end private let deserialize_uint32_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint32_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0ul) else begin let ok, pos, b0 = deserialize_uint16_t ok buf sz pos in let ok, pos, b1 = deserialize_uint16_t ok buf sz pos in (ok, pos, (U32.shift_left (Int.Cast.uint16_to_uint32 b0) 16ul) + Int.Cast.uint16_to_uint32 b1) end private let deserialize_uint64_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint64_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0UL) else begin let ok, pos, b0 = deserialize_uint32_t ok buf sz pos in let ok, pos, b1 = deserialize_uint32_t ok buf sz pos in (ok, pos, (U64.shift_left (u32_64 b0) 32ul) + u32_64 b1) end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ok: Prims.bool -> buf: MerkleTree.Low.Serialization.const_uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.ConstBuffer.length buf = FStar.UInt32.v sz} -> pos: MerkleTree.Low.Serialization.uint32_t -> FStar.HyperStack.ST.ST ((Prims.bool * MerkleTree.Low.Serialization.uint32_t) * MerkleTree.Low.Serialization.uint64_t)
FStar.HyperStack.ST.ST
[]
[]
[ "MerkleTree.Low.Serialization.deserialize_uint64_t" ]
[]
false
true
false
false
false
let deserialize_offset_t =
deserialize_uint64_t
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.serialize_uint16_t
val serialize_uint16_t (ok: bool) (x: uint16_t) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1))
val serialize_uint16_t (ok: bool) (x: uint16_t) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1))
let serialize_uint16_t (ok:bool) (x:uint16_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint8_t ok (Int.Cast.uint16_to_uint8 (U16.shift_right x 8ul)) buf sz pos in serialize_uint8_t ok (Int.Cast.uint16_to_uint8 x) buf sz pos
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 62, "end_line": 66, "start_col": 8, "start_line": 62 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" private let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end private let serialize_uint8_t (ok:bool) (x:uint8_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos x; (true, pos + 1ul) end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ok: Prims.bool -> x: MerkleTree.Low.Serialization.uint16_t -> buf: MerkleTree.Low.Serialization.uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.Monotonic.Buffer.len buf = sz} -> pos: MerkleTree.Low.Serialization.uint32_t -> FStar.HyperStack.ST.ST (Prims.bool * MerkleTree.Low.Serialization.uint32_t)
FStar.HyperStack.ST.ST
[]
[]
[ "Prims.bool", "MerkleTree.Low.Serialization.uint16_t", "MerkleTree.Low.Serialization.uint8_p", "MerkleTree.Low.Serialization.uint32_t", "Prims.b2t", "Prims.op_Equality", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.len", "MerkleTree.Low.Serialization.uint8_t", "LowStar.Buffer.trivial_preorder", "MerkleTree.Low.Serialization.serialize_uint8_t", "FStar.Int.Cast.uint16_to_uint8", "FStar.Pervasives.Native.tuple2", "FStar.UInt16.shift_right", "FStar.UInt32.__uint_to_t", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.live", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer" ]
[]
false
true
false
false
false
let serialize_uint16_t (ok: bool) (x: uint16_t) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) =
let ok, pos = serialize_uint8_t ok (Int.Cast.uint16_to_uint8 (U16.shift_right x 8ul)) buf sz pos in serialize_uint8_t ok (Int.Cast.uint16_to_uint8 x) buf sz pos
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.u64_add_fits
val u64_add_fits (x y: uint64_t) : Tot (r: bool{r ==> UInt.size (U64.v x + U64.v y) 64})
val u64_add_fits (x y: uint64_t) : Tot (r: bool{r ==> UInt.size (U64.v x + U64.v y) 64})
let u64_add_fits (x:uint64_t) (y:uint64_t): Tot (r:bool{r ==> UInt.size (U64.v x + U64.v y) 64}) = uint64_max - x >= y
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 118, "end_line": 107, "start_col": 0, "start_line": 107 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" private let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end private let serialize_uint8_t (ok:bool) (x:uint8_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos x; (true, pos + 1ul) end private let serialize_uint16_t (ok:bool) (x:uint16_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint8_t ok (Int.Cast.uint16_to_uint8 (U16.shift_right x 8ul)) buf sz pos in serialize_uint8_t ok (Int.Cast.uint16_to_uint8 x) buf sz pos private let serialize_uint32_t (ok:bool) (x:uint32_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint16_t ok (Int.Cast.uint32_to_uint16 (U32.shift_right x 16ul)) buf sz pos in serialize_uint16_t ok (Int.Cast.uint32_to_uint16 x) buf sz pos private let serialize_uint64_t (ok:bool) (x:uint64_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint32_t ok (Int.Cast.uint64_to_uint32 (U64.shift_right x 32ul)) buf sz pos in serialize_uint32_t ok (Int.Cast.uint64_to_uint32 x) buf sz pos private let serialize_offset_t = serialize_uint64_t private let serialize_index_t = serialize_uint32_t private let rec serialize_hash_i (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < hash_size}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else let b = x.(i) in let ok, pos = serialize_uint8_t ok (Lib.RawIntTypes.u8_to_UInt8 b) buf sz pos in let j = i + 1ul in if j < hash_size then serialize_hash_i #hash_size ok x buf sz pos j else (ok, pos) private let serialize_hash (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else serialize_hash_i ok x buf sz pos 0ul
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: MerkleTree.Low.Serialization.uint64_t -> y: MerkleTree.Low.Serialization.uint64_t -> r: Prims.bool{r ==> FStar.UInt.size (FStar.UInt64.v x + FStar.UInt64.v y) 64}
Prims.Tot
[ "total" ]
[]
[ "MerkleTree.Low.Serialization.uint64_t", "FStar.Integers.op_Greater_Equals", "FStar.Integers.Unsigned", "FStar.Integers.W64", "FStar.Integers.op_Subtraction", "MerkleTree.Low.uint64_max", "Prims.bool", "Prims.l_imp", "Prims.b2t", "FStar.UInt.size", "FStar.Integers.op_Plus", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "FStar.UInt64.v" ]
[]
false
false
false
false
false
let u64_add_fits (x y: uint64_t) : Tot (r: bool{r ==> UInt.size (U64.v x + U64.v y) 64}) =
uint64_max - x >= y
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.serialize_bool
val serialize_bool (ok x: bool) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1))
val serialize_bool (ok x: bool) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1))
let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 5, "end_line": 52, "start_col": 8, "start_line": 45 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ok: Prims.bool -> x: Prims.bool -> buf: MerkleTree.Low.Serialization.uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.Monotonic.Buffer.len buf = sz} -> pos: MerkleTree.Low.Serialization.uint32_t -> FStar.HyperStack.ST.ST (Prims.bool * MerkleTree.Low.Serialization.uint32_t)
FStar.HyperStack.ST.ST
[]
[]
[ "Prims.bool", "MerkleTree.Low.Serialization.uint8_p", "MerkleTree.Low.Serialization.uint32_t", "Prims.b2t", "Prims.op_Equality", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.len", "MerkleTree.Low.Serialization.uint8_t", "LowStar.Buffer.trivial_preorder", "Prims.op_BarBar", "Prims.op_Negation", "FStar.Integers.op_Greater_Equals", "FStar.Integers.Unsigned", "FStar.Integers.W32", "FStar.Pervasives.Native.Mktuple2", "FStar.UInt32.__uint_to_t", "FStar.Pervasives.Native.tuple2", "FStar.Integers.op_Plus", "Prims.unit", "LowStar.Monotonic.Buffer.upd", "FStar.UInt8.__uint_to_t", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.live", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer" ]
[]
false
true
false
false
false
let serialize_bool (ok x: bool) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) =
if not ok || pos >= sz then (false, 0ul) else (B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul))
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.serialize_uint8_t
val serialize_uint8_t (ok: bool) (x: uint8_t) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1))
val serialize_uint8_t (ok: bool) (x: uint8_t) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1))
let serialize_uint8_t (ok:bool) (x:uint8_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos x; (true, pos + 1ul) end
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 5, "end_line": 60, "start_col": 8, "start_line": 54 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" private let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ok: Prims.bool -> x: MerkleTree.Low.Serialization.uint8_t -> buf: MerkleTree.Low.Serialization.uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.Monotonic.Buffer.len buf = sz} -> pos: MerkleTree.Low.Serialization.uint32_t -> FStar.HyperStack.ST.ST (Prims.bool * MerkleTree.Low.Serialization.uint32_t)
FStar.HyperStack.ST.ST
[]
[]
[ "Prims.bool", "MerkleTree.Low.Serialization.uint8_t", "MerkleTree.Low.Serialization.uint8_p", "MerkleTree.Low.Serialization.uint32_t", "Prims.b2t", "Prims.op_Equality", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.len", "LowStar.Buffer.trivial_preorder", "Prims.op_BarBar", "Prims.op_Negation", "FStar.Integers.op_Greater_Equals", "FStar.Integers.Unsigned", "FStar.Integers.W32", "FStar.Pervasives.Native.Mktuple2", "FStar.UInt32.__uint_to_t", "FStar.Pervasives.Native.tuple2", "FStar.Integers.op_Plus", "Prims.unit", "LowStar.Monotonic.Buffer.upd", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.live", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer" ]
[]
false
true
false
false
false
let serialize_uint8_t (ok: bool) (x: uint8_t) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) =
if not ok || pos >= sz then (false, 0ul) else (B.upd buf pos x; (true, pos + 1ul))
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.serialize_uint32_t
val serialize_uint32_t (ok: bool) (x: uint32_t) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1))
val serialize_uint32_t (ok: bool) (x: uint32_t) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1))
let serialize_uint32_t (ok:bool) (x:uint32_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint16_t ok (Int.Cast.uint32_to_uint16 (U32.shift_right x 16ul)) buf sz pos in serialize_uint16_t ok (Int.Cast.uint32_to_uint16 x) buf sz pos
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 64, "end_line": 72, "start_col": 8, "start_line": 68 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" private let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end private let serialize_uint8_t (ok:bool) (x:uint8_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos x; (true, pos + 1ul) end private let serialize_uint16_t (ok:bool) (x:uint16_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint8_t ok (Int.Cast.uint16_to_uint8 (U16.shift_right x 8ul)) buf sz pos in serialize_uint8_t ok (Int.Cast.uint16_to_uint8 x) buf sz pos
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ok: Prims.bool -> x: MerkleTree.Low.Serialization.uint32_t -> buf: MerkleTree.Low.Serialization.uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.Monotonic.Buffer.len buf = sz} -> pos: MerkleTree.Low.Serialization.uint32_t -> FStar.HyperStack.ST.ST (Prims.bool * MerkleTree.Low.Serialization.uint32_t)
FStar.HyperStack.ST.ST
[]
[]
[ "Prims.bool", "MerkleTree.Low.Serialization.uint32_t", "MerkleTree.Low.Serialization.uint8_p", "Prims.b2t", "Prims.op_Equality", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.len", "MerkleTree.Low.Serialization.uint8_t", "LowStar.Buffer.trivial_preorder", "MerkleTree.Low.Serialization.serialize_uint16_t", "FStar.Int.Cast.uint32_to_uint16", "FStar.Pervasives.Native.tuple2", "FStar.UInt32.shift_right", "FStar.UInt32.__uint_to_t", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.live", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer" ]
[]
false
true
false
false
false
let serialize_uint32_t (ok: bool) (x: uint32_t) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) =
let ok, pos = serialize_uint16_t ok (Int.Cast.uint32_to_uint16 (U32.shift_right x 16ul)) buf sz pos in serialize_uint16_t ok (Int.Cast.uint32_to_uint16 x) buf sz pos
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.serialize_uint64_t
val serialize_uint64_t (ok: bool) (x: uint64_t) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1))
val serialize_uint64_t (ok: bool) (x: uint64_t) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1))
let serialize_uint64_t (ok:bool) (x:uint64_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint32_t ok (Int.Cast.uint64_to_uint32 (U64.shift_right x 32ul)) buf sz pos in serialize_uint32_t ok (Int.Cast.uint64_to_uint32 x) buf sz pos
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 64, "end_line": 78, "start_col": 8, "start_line": 74 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" private let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end private let serialize_uint8_t (ok:bool) (x:uint8_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos x; (true, pos + 1ul) end private let serialize_uint16_t (ok:bool) (x:uint16_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint8_t ok (Int.Cast.uint16_to_uint8 (U16.shift_right x 8ul)) buf sz pos in serialize_uint8_t ok (Int.Cast.uint16_to_uint8 x) buf sz pos private let serialize_uint32_t (ok:bool) (x:uint32_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint16_t ok (Int.Cast.uint32_to_uint16 (U32.shift_right x 16ul)) buf sz pos in serialize_uint16_t ok (Int.Cast.uint32_to_uint16 x) buf sz pos
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ok: Prims.bool -> x: MerkleTree.Low.Serialization.uint64_t -> buf: MerkleTree.Low.Serialization.uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.Monotonic.Buffer.len buf = sz} -> pos: MerkleTree.Low.Serialization.uint32_t -> FStar.HyperStack.ST.ST (Prims.bool * MerkleTree.Low.Serialization.uint32_t)
FStar.HyperStack.ST.ST
[]
[]
[ "Prims.bool", "MerkleTree.Low.Serialization.uint64_t", "MerkleTree.Low.Serialization.uint8_p", "MerkleTree.Low.Serialization.uint32_t", "Prims.b2t", "Prims.op_Equality", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.len", "MerkleTree.Low.Serialization.uint8_t", "LowStar.Buffer.trivial_preorder", "MerkleTree.Low.Serialization.serialize_uint32_t", "FStar.Int.Cast.uint64_to_uint32", "FStar.Pervasives.Native.tuple2", "FStar.UInt64.shift_right", "FStar.UInt32.__uint_to_t", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.live", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer" ]
[]
false
true
false
false
false
let serialize_uint64_t (ok: bool) (x: uint64_t) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) =
let ok, pos = serialize_uint32_t ok (Int.Cast.uint64_to_uint32 (U64.shift_right x 32ul)) buf sz pos in serialize_uint32_t ok (Int.Cast.uint64_to_uint32 x) buf sz pos
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.serialize_hash
val serialize_hash (#hash_size: hash_size_t) (ok: bool) (x: hash #hash_size) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1))
val serialize_hash (#hash_size: hash_size_t) (ok: bool) (x: hash #hash_size) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1))
let serialize_hash (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else serialize_hash_i ok x buf sz pos 0ul
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 43, "end_line": 104, "start_col": 0, "start_line": 97 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" private let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end private let serialize_uint8_t (ok:bool) (x:uint8_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos x; (true, pos + 1ul) end private let serialize_uint16_t (ok:bool) (x:uint16_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint8_t ok (Int.Cast.uint16_to_uint8 (U16.shift_right x 8ul)) buf sz pos in serialize_uint8_t ok (Int.Cast.uint16_to_uint8 x) buf sz pos private let serialize_uint32_t (ok:bool) (x:uint32_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint16_t ok (Int.Cast.uint32_to_uint16 (U32.shift_right x 16ul)) buf sz pos in serialize_uint16_t ok (Int.Cast.uint32_to_uint16 x) buf sz pos private let serialize_uint64_t (ok:bool) (x:uint64_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint32_t ok (Int.Cast.uint64_to_uint32 (U64.shift_right x 32ul)) buf sz pos in serialize_uint32_t ok (Int.Cast.uint64_to_uint32 x) buf sz pos private let serialize_offset_t = serialize_uint64_t private let serialize_index_t = serialize_uint32_t private let rec serialize_hash_i (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < hash_size}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else let b = x.(i) in let ok, pos = serialize_uint8_t ok (Lib.RawIntTypes.u8_to_UInt8 b) buf sz pos in let j = i + 1ul in if j < hash_size then serialize_hash_i #hash_size ok x buf sz pos j else (ok, pos)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ok: Prims.bool -> x: MerkleTree.Low.Datastructures.hash -> buf: MerkleTree.Low.Serialization.uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.Monotonic.Buffer.len buf = sz} -> pos: MerkleTree.Low.Serialization.uint32_t -> FStar.HyperStack.ST.ST (Prims.bool * MerkleTree.Low.Serialization.uint32_t)
FStar.HyperStack.ST.ST
[]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "Prims.bool", "MerkleTree.Low.Datastructures.hash", "MerkleTree.Low.Serialization.uint8_p", "MerkleTree.Low.Serialization.uint32_t", "Prims.b2t", "Prims.op_Equality", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.len", "MerkleTree.Low.Serialization.uint8_t", "LowStar.Buffer.trivial_preorder", "Prims.op_BarBar", "Prims.op_Negation", "FStar.Integers.op_Greater_Equals", "FStar.Integers.Unsigned", "FStar.Integers.W32", "FStar.Pervasives.Native.Mktuple2", "FStar.UInt32.__uint_to_t", "FStar.Pervasives.Native.tuple2", "MerkleTree.Low.Serialization.serialize_hash_i", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "LowStar.Monotonic.Buffer.live", "Lib.IntTypes.uint8", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer" ]
[]
false
true
false
false
false
let serialize_hash (#hash_size: hash_size_t) (ok: bool) (x: hash #hash_size) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) =
if not ok || pos >= sz then (false, 0ul) else serialize_hash_i ok x buf sz pos 0ul
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.serialize_hash_i
val serialize_hash_i (#hash_size: hash_size_t) (ok: bool) (x: hash #hash_size) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) (i: uint32_t{i < hash_size}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1))
val serialize_hash_i (#hash_size: hash_size_t) (ok: bool) (x: hash #hash_size) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) (i: uint32_t{i < hash_size}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1))
let rec serialize_hash_i (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < hash_size}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else let b = x.(i) in let ok, pos = serialize_uint8_t ok (Lib.RawIntTypes.u8_to_UInt8 b) buf sz pos in let j = i + 1ul in if j < hash_size then serialize_hash_i #hash_size ok x buf sz pos j else (ok, pos)
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 21, "end_line": 94, "start_col": 8, "start_line": 83 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" private let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end private let serialize_uint8_t (ok:bool) (x:uint8_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos x; (true, pos + 1ul) end private let serialize_uint16_t (ok:bool) (x:uint16_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint8_t ok (Int.Cast.uint16_to_uint8 (U16.shift_right x 8ul)) buf sz pos in serialize_uint8_t ok (Int.Cast.uint16_to_uint8 x) buf sz pos private let serialize_uint32_t (ok:bool) (x:uint32_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint16_t ok (Int.Cast.uint32_to_uint16 (U32.shift_right x 16ul)) buf sz pos in serialize_uint16_t ok (Int.Cast.uint32_to_uint16 x) buf sz pos private let serialize_uint64_t (ok:bool) (x:uint64_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint32_t ok (Int.Cast.uint64_to_uint32 (U64.shift_right x 32ul)) buf sz pos in serialize_uint32_t ok (Int.Cast.uint64_to_uint32 x) buf sz pos private let serialize_offset_t = serialize_uint64_t private let serialize_index_t = serialize_uint32_t
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ok: Prims.bool -> x: MerkleTree.Low.Datastructures.hash -> buf: MerkleTree.Low.Serialization.uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.Monotonic.Buffer.len buf = sz} -> pos: MerkleTree.Low.Serialization.uint32_t -> i: MerkleTree.Low.Serialization.uint32_t{i < hash_size} -> FStar.HyperStack.ST.ST (Prims.bool * MerkleTree.Low.Serialization.uint32_t)
FStar.HyperStack.ST.ST
[]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "Prims.bool", "MerkleTree.Low.Datastructures.hash", "MerkleTree.Low.Serialization.uint8_p", "MerkleTree.Low.Serialization.uint32_t", "Prims.b2t", "Prims.op_Equality", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.len", "MerkleTree.Low.Serialization.uint8_t", "LowStar.Buffer.trivial_preorder", "FStar.Integers.op_Less", "FStar.Integers.Unsigned", "FStar.Integers.W32", "Prims.op_BarBar", "Prims.op_Negation", "FStar.Integers.op_Greater_Equals", "FStar.Pervasives.Native.Mktuple2", "FStar.UInt32.__uint_to_t", "FStar.Pervasives.Native.tuple2", "MerkleTree.Low.Serialization.serialize_hash_i", "FStar.Integers.int_t", "FStar.Integers.op_Plus", "MerkleTree.Low.Serialization.serialize_uint8_t", "Lib.RawIntTypes.u8_to_UInt8", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "LowStar.BufferOps.op_Array_Access", "Lib.IntTypes.uint8", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "LowStar.Monotonic.Buffer.live", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer" ]
[ "recursion" ]
false
true
false
false
false
let rec serialize_hash_i (#hash_size: hash_size_t) (ok: bool) (x: hash #hash_size) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) (i: uint32_t{i < hash_size}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) =
if not ok || pos >= sz then (false, 0ul) else let b = x.(i) in let ok, pos = serialize_uint8_t ok (Lib.RawIntTypes.u8_to_UInt8 b) buf sz pos in let j = i + 1ul in if j < hash_size then serialize_hash_i #hash_size ok x buf sz pos j else (ok, pos)
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.serialize_hash_vec
val serialize_hash_vec (#hash_size: hash_size_t) (ok: bool) (x: hash_vec #hash_size) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvreg hash_size) x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1))
val serialize_hash_vec (#hash_size: hash_size_t) (ok: bool) (x: hash_vec #hash_size) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvreg hash_size) x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1))
let serialize_hash_vec (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvreg hash_size) x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if ok && V.size_of x > 0ul then serialize_hash_vec_i ok x buf sz pos 0ul else (ok, pos) end
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 5, "end_line": 150, "start_col": 0, "start_line": 136 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" private let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end private let serialize_uint8_t (ok:bool) (x:uint8_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos x; (true, pos + 1ul) end private let serialize_uint16_t (ok:bool) (x:uint16_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint8_t ok (Int.Cast.uint16_to_uint8 (U16.shift_right x 8ul)) buf sz pos in serialize_uint8_t ok (Int.Cast.uint16_to_uint8 x) buf sz pos private let serialize_uint32_t (ok:bool) (x:uint32_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint16_t ok (Int.Cast.uint32_to_uint16 (U32.shift_right x 16ul)) buf sz pos in serialize_uint16_t ok (Int.Cast.uint32_to_uint16 x) buf sz pos private let serialize_uint64_t (ok:bool) (x:uint64_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint32_t ok (Int.Cast.uint64_to_uint32 (U64.shift_right x 32ul)) buf sz pos in serialize_uint32_t ok (Int.Cast.uint64_to_uint32 x) buf sz pos private let serialize_offset_t = serialize_uint64_t private let serialize_index_t = serialize_uint32_t private let rec serialize_hash_i (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < hash_size}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else let b = x.(i) in let ok, pos = serialize_uint8_t ok (Lib.RawIntTypes.u8_to_UInt8 b) buf sz pos in let j = i + 1ul in if j < hash_size then serialize_hash_i #hash_size ok x buf sz pos j else (ok, pos) private let serialize_hash (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else serialize_hash_i ok x buf sz pos 0ul private inline_for_extraction let u64_add_fits (x:uint64_t) (y:uint64_t): Tot (r:bool{r ==> UInt.size (U64.v x + U64.v y) 64}) = uint64_max - x >= y #push-options "--z3rlimit 100 --fuel 1 --quake 1/3" private inline_for_extraction let hash_vec_bytes (#hash_size:hash_size_t) (v:hash_vec #hash_size) : Tot uint64_t = let vs_hs = U64.mul (u32_64 (V.size_of v)) (u32_64 hash_size) in if u64_add_fits vs_hs 4UL then vs_hs + 4UL else uint64_max #pop-options private let rec serialize_hash_vec_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ loc_disjoint (B.loc_buffer buf) (loc_rvector x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let ok, pos = serialize_hash ok vi buf sz pos in let j = i + 1ul in if j < V.size_of x then serialize_hash_vec_i ok x buf sz pos j else (ok, pos) end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ok: Prims.bool -> x: MerkleTree.Low.Datastructures.hash_vec -> buf: MerkleTree.Low.Serialization.uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.Monotonic.Buffer.len buf = sz} -> pos: MerkleTree.Low.Serialization.uint32_t -> FStar.HyperStack.ST.ST (Prims.bool * MerkleTree.Low.Serialization.uint32_t)
FStar.HyperStack.ST.ST
[]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "Prims.bool", "MerkleTree.Low.Datastructures.hash_vec", "MerkleTree.Low.Serialization.uint8_p", "MerkleTree.Low.Serialization.uint32_t", "Prims.b2t", "Prims.op_Equality", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.len", "MerkleTree.Low.Serialization.uint8_t", "LowStar.Buffer.trivial_preorder", "Prims.op_BarBar", "Prims.op_Negation", "FStar.Integers.op_Greater_Equals", "FStar.Integers.Unsigned", "FStar.Integers.W32", "FStar.Pervasives.Native.Mktuple2", "FStar.UInt32.__uint_to_t", "FStar.Pervasives.Native.tuple2", "Prims.op_AmpAmp", "FStar.Integers.op_Greater", "LowStar.Vector.size_of", "MerkleTree.Low.Datastructures.hash", "MerkleTree.Low.Serialization.serialize_hash_vec_i", "Prims.unit", "LowStar.RVector.rv_inv_preserved", "MerkleTree.Low.Datastructures.hreg", "LowStar.Monotonic.Buffer.loc_buffer", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "MerkleTree.Low.Serialization.serialize_uint32_t", "Prims.l_and", "LowStar.Monotonic.Buffer.live", "LowStar.RVector.rv_inv", "FStar.Monotonic.HyperHeap.disjoint", "LowStar.Monotonic.Buffer.frameOf", "LowStar.Regional.__proj__Rgl__item__region_of", "MerkleTree.Low.Datastructures.hvreg", "LowStar.Monotonic.Buffer.modifies" ]
[]
false
true
false
false
false
let serialize_hash_vec (#hash_size: hash_size_t) (ok: bool) (x: hash_vec #hash_size) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvreg hash_size) x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) =
if not ok || pos >= sz then (false, 0ul) else let h0 = HST.get () in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get () in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if ok && V.size_of x > 0ul then serialize_hash_vec_i ok x buf sz pos 0ul else (ok, pos)
false
FStar.FiniteSet.Ambient.fst
FStar.FiniteSet.Ambient.all_finite_set_facts_ambient
val all_finite_set_facts_ambient:(squash all_finite_set_facts)
val all_finite_set_facts_ambient:(squash all_finite_set_facts)
let all_finite_set_facts_ambient : (squash all_finite_set_facts) = all_finite_set_facts_lemma ()
{ "file_name": "ulib/FStar.FiniteSet.Ambient.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 31, "end_line": 43, "start_col": 0, "start_line": 42 }
(* Copyright 2008-2021 John Li, Jay Lorch, Rustan Leino, Alex Summers, Dan Rosen, Nikhil Swamy, Microsoft Research, and contributors to the Dafny Project 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. Includes material from the Dafny project (https://github.com/dafny-lang/dafny) which carries this license information: Created 9 February 2008 by Rustan Leino. Converted to Boogie 2 on 28 June 2008. Edited sequence axioms 20 October 2009 by Alex Summers. Modified 2014 by Dan Rosen. Copyright (c) 2008-2014, Microsoft. Copyright by the contributors to the Dafny Project SPDX-License-Identifier: MIT *) (** This module brings properties about finite sets ambiently into the context. The properties are modeled after those in the Dafny sequence axioms, with patterns for quantifiers chosen as in those axioms. @summary Puts properties of finite sets into the ambient context *) module FStar.FiniteSet.Ambient open FStar.FiniteSet.Base
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.FiniteSet.Base.fsti.checked" ], "interface_file": false, "source_file": "FStar.FiniteSet.Ambient.fst" }
[ { "abbrev": false, "full_module": "FStar.FiniteSet.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteSet", "short_module": null }, { "abbrev": false, "full_module": "FStar.FiniteSet", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.squash FStar.FiniteSet.Base.all_finite_set_facts
Prims.Tot
[ "total" ]
[]
[ "FStar.FiniteSet.Base.all_finite_set_facts_lemma" ]
[]
false
false
true
true
false
let all_finite_set_facts_ambient:(squash all_finite_set_facts) =
all_finite_set_facts_lemma ()
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.deserialize_uint64_t
val deserialize_uint64_t (ok: bool) (buf: const_uint8_p) (sz: uint32_t{CB.length buf = U32.v sz}) (pos: uint32_t) : HST.ST (bool & uint32_t & uint64_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1))
val deserialize_uint64_t (ok: bool) (buf: const_uint8_p) (sz: uint32_t{CB.length buf = U32.v sz}) (pos: uint32_t) : HST.ST (bool & uint32_t & uint64_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1))
let deserialize_uint64_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint64_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0UL) else begin let ok, pos, b0 = deserialize_uint32_t ok buf sz pos in let ok, pos, b1 = deserialize_uint32_t ok buf sz pos in (ok, pos, (U64.shift_left (u32_64 b0) 32ul) + u32_64 b1) end
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 5, "end_line": 263, "start_col": 0, "start_line": 255 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" private let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end private let serialize_uint8_t (ok:bool) (x:uint8_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos x; (true, pos + 1ul) end private let serialize_uint16_t (ok:bool) (x:uint16_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint8_t ok (Int.Cast.uint16_to_uint8 (U16.shift_right x 8ul)) buf sz pos in serialize_uint8_t ok (Int.Cast.uint16_to_uint8 x) buf sz pos private let serialize_uint32_t (ok:bool) (x:uint32_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint16_t ok (Int.Cast.uint32_to_uint16 (U32.shift_right x 16ul)) buf sz pos in serialize_uint16_t ok (Int.Cast.uint32_to_uint16 x) buf sz pos private let serialize_uint64_t (ok:bool) (x:uint64_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint32_t ok (Int.Cast.uint64_to_uint32 (U64.shift_right x 32ul)) buf sz pos in serialize_uint32_t ok (Int.Cast.uint64_to_uint32 x) buf sz pos private let serialize_offset_t = serialize_uint64_t private let serialize_index_t = serialize_uint32_t private let rec serialize_hash_i (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < hash_size}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else let b = x.(i) in let ok, pos = serialize_uint8_t ok (Lib.RawIntTypes.u8_to_UInt8 b) buf sz pos in let j = i + 1ul in if j < hash_size then serialize_hash_i #hash_size ok x buf sz pos j else (ok, pos) private let serialize_hash (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else serialize_hash_i ok x buf sz pos 0ul private inline_for_extraction let u64_add_fits (x:uint64_t) (y:uint64_t): Tot (r:bool{r ==> UInt.size (U64.v x + U64.v y) 64}) = uint64_max - x >= y #push-options "--z3rlimit 100 --fuel 1 --quake 1/3" private inline_for_extraction let hash_vec_bytes (#hash_size:hash_size_t) (v:hash_vec #hash_size) : Tot uint64_t = let vs_hs = U64.mul (u32_64 (V.size_of v)) (u32_64 hash_size) in if u64_add_fits vs_hs 4UL then vs_hs + 4UL else uint64_max #pop-options private let rec serialize_hash_vec_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ loc_disjoint (B.loc_buffer buf) (loc_rvector x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let ok, pos = serialize_hash ok vi buf sz pos in let j = i + 1ul in if j < V.size_of x then serialize_hash_vec_i ok x buf sz pos j else (ok, pos) end private let serialize_hash_vec (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvreg hash_size) x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if ok && V.size_of x > 0ul then serialize_hash_vec_i ok x buf sz pos 0ul else (ok, pos) end private inline_for_extraction let rec hash_vv_bytes_i (#hash_size:hash_size_t) (vv:hash_vv hash_size) (i:uint32_t) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = if i >= V.size_of vv then 4UL else begin let vvi = V.index vv i in let r = hash_vec_bytes vvi in let rest = hash_vv_bytes_i vv (i+1ul) in if u64_add_fits r rest then begin assert (UInt.size (U64.v r + U64.v rest) 64); r + rest end else uint64_max end private inline_for_extraction let hash_vv_bytes (#hash_size:hash_size_t) (vv:hash_vv hash_size {V.size_of vv = merkle_tree_size_lg}) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = hash_vv_bytes_i vv 0ul private let rec serialize_hash_vv_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vv hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let h0 = HST.get() in let ok, pos = serialize_hash_vec #hash_size ok vi buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; let j = i + 1ul in if j < V.size_of x then serialize_hash_vv_i #hash_size ok x buf sz pos j else (ok, pos) end private let serialize_hash_vv (#hash_size:hash_size_t) (ok:bool) (x:hash_vv hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if (V.size_of x > 0ul) then serialize_hash_vv_i ok x buf sz pos 0ul else (ok, pos) end private let deserialize_bool (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & bool) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, false) else (true, pos + 1ul, (match CB.index buf pos with| 0uy -> false | _ -> true)) private let deserialize_uint8_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint8_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0uy) else (true, pos + 1ul, CB.index buf pos) private let deserialize_uint16_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint16_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0us) else begin let ok, pos, b0 = deserialize_uint8_t ok buf sz pos in let ok, pos, b1 = deserialize_uint8_t ok buf sz pos in (ok, pos, (U16.shift_left (Int.Cast.uint8_to_uint16 b0) 8ul) + Int.Cast.uint8_to_uint16 b1) end private let deserialize_uint32_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint32_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0ul) else begin let ok, pos, b0 = deserialize_uint16_t ok buf sz pos in let ok, pos, b1 = deserialize_uint16_t ok buf sz pos in (ok, pos, (U32.shift_left (Int.Cast.uint16_to_uint32 b0) 16ul) + Int.Cast.uint16_to_uint32 b1) end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ok: Prims.bool -> buf: MerkleTree.Low.Serialization.const_uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.ConstBuffer.length buf = FStar.UInt32.v sz} -> pos: MerkleTree.Low.Serialization.uint32_t -> FStar.HyperStack.ST.ST ((Prims.bool * MerkleTree.Low.Serialization.uint32_t) * MerkleTree.Low.Serialization.uint64_t)
FStar.HyperStack.ST.ST
[]
[]
[ "Prims.bool", "MerkleTree.Low.Serialization.const_uint8_p", "MerkleTree.Low.Serialization.uint32_t", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "LowStar.ConstBuffer.length", "MerkleTree.Low.Serialization.uint8_t", "FStar.UInt32.v", "Prims.op_BarBar", "Prims.op_Negation", "FStar.Integers.op_Greater_Equals", "FStar.Integers.Unsigned", "FStar.Integers.W32", "FStar.Pervasives.Native.Mktuple3", "MerkleTree.Low.Serialization.uint64_t", "FStar.UInt64.__uint_to_t", "FStar.Pervasives.Native.tuple3", "FStar.Integers.op_Plus", "FStar.Integers.W64", "FStar.UInt64.shift_left", "MerkleTree.Low.u32_64", "FStar.UInt32.__uint_to_t", "MerkleTree.Low.Serialization.deserialize_uint32_t", "FStar.Monotonic.HyperStack.mem", "LowStar.ConstBuffer.live", "Prims.eq2" ]
[]
false
true
false
false
false
let deserialize_uint64_t (ok: bool) (buf: const_uint8_p) (sz: uint32_t{CB.length buf = U32.v sz}) (pos: uint32_t) : HST.ST (bool & uint32_t & uint64_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) =
if not ok || pos >= sz then (false, pos, 0uL) else let ok, pos, b0 = deserialize_uint32_t ok buf sz pos in let ok, pos, b1 = deserialize_uint32_t ok buf sz pos in (ok, pos, (U64.shift_left (u32_64 b0) 32ul) + u32_64 b1)
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.hash_vv_bytes_i
val hash_vv_bytes_i (#hash_size: hash_size_t) (vv: hash_vv hash_size) (i: uint32_t) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1))
val hash_vv_bytes_i (#hash_size: hash_size_t) (vv: hash_vv hash_size) (i: uint32_t) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1))
let rec hash_vv_bytes_i (#hash_size:hash_size_t) (vv:hash_vv hash_size) (i:uint32_t) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = if i >= V.size_of vv then 4UL else begin let vvi = V.index vv i in let r = hash_vec_bytes vvi in let rest = hash_vv_bytes_i vv (i+1ul) in if u64_add_fits r rest then begin assert (UInt.size (U64.v r + U64.v rest) 64); r + rest end else uint64_max end
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 5, "end_line": 170, "start_col": 0, "start_line": 153 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" private let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end private let serialize_uint8_t (ok:bool) (x:uint8_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos x; (true, pos + 1ul) end private let serialize_uint16_t (ok:bool) (x:uint16_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint8_t ok (Int.Cast.uint16_to_uint8 (U16.shift_right x 8ul)) buf sz pos in serialize_uint8_t ok (Int.Cast.uint16_to_uint8 x) buf sz pos private let serialize_uint32_t (ok:bool) (x:uint32_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint16_t ok (Int.Cast.uint32_to_uint16 (U32.shift_right x 16ul)) buf sz pos in serialize_uint16_t ok (Int.Cast.uint32_to_uint16 x) buf sz pos private let serialize_uint64_t (ok:bool) (x:uint64_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint32_t ok (Int.Cast.uint64_to_uint32 (U64.shift_right x 32ul)) buf sz pos in serialize_uint32_t ok (Int.Cast.uint64_to_uint32 x) buf sz pos private let serialize_offset_t = serialize_uint64_t private let serialize_index_t = serialize_uint32_t private let rec serialize_hash_i (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < hash_size}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else let b = x.(i) in let ok, pos = serialize_uint8_t ok (Lib.RawIntTypes.u8_to_UInt8 b) buf sz pos in let j = i + 1ul in if j < hash_size then serialize_hash_i #hash_size ok x buf sz pos j else (ok, pos) private let serialize_hash (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else serialize_hash_i ok x buf sz pos 0ul private inline_for_extraction let u64_add_fits (x:uint64_t) (y:uint64_t): Tot (r:bool{r ==> UInt.size (U64.v x + U64.v y) 64}) = uint64_max - x >= y #push-options "--z3rlimit 100 --fuel 1 --quake 1/3" private inline_for_extraction let hash_vec_bytes (#hash_size:hash_size_t) (v:hash_vec #hash_size) : Tot uint64_t = let vs_hs = U64.mul (u32_64 (V.size_of v)) (u32_64 hash_size) in if u64_add_fits vs_hs 4UL then vs_hs + 4UL else uint64_max #pop-options private let rec serialize_hash_vec_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ loc_disjoint (B.loc_buffer buf) (loc_rvector x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let ok, pos = serialize_hash ok vi buf sz pos in let j = i + 1ul in if j < V.size_of x then serialize_hash_vec_i ok x buf sz pos j else (ok, pos) end private let serialize_hash_vec (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvreg hash_size) x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if ok && V.size_of x > 0ul then serialize_hash_vec_i ok x buf sz pos 0ul else (ok, pos) end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
vv: MerkleTree.Low.Datastructures.hash_vv hash_size -> i: MerkleTree.Low.Serialization.uint32_t -> FStar.HyperStack.ST.ST MerkleTree.Low.Serialization.uint64_t
FStar.HyperStack.ST.ST
[]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "MerkleTree.Low.Datastructures.hash_vv", "MerkleTree.Low.Serialization.uint32_t", "FStar.Integers.op_Greater_Equals", "FStar.Integers.Unsigned", "FStar.Integers.W32", "LowStar.Vector.size_of", "MerkleTree.Low.Datastructures.hash_vec", "FStar.UInt64.__uint_to_t", "MerkleTree.Low.Serialization.uint64_t", "Prims.bool", "MerkleTree.Low.Serialization.u64_add_fits", "FStar.Integers.op_Plus", "FStar.Integers.W64", "Prims.unit", "Prims._assert", "FStar.UInt.size", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "FStar.UInt64.v", "MerkleTree.Low.uint64_max", "MerkleTree.Low.Serialization.hash_vv_bytes_i", "FStar.UInt32.__uint_to_t", "MerkleTree.Low.Serialization.hash_vec_bytes", "LowStar.Vector.index", "FStar.Monotonic.HyperStack.mem", "LowStar.Vector.live", "Prims.eq2" ]
[ "recursion" ]
false
true
false
false
false
let rec hash_vv_bytes_i (#hash_size: hash_size_t) (vv: hash_vv hash_size) (i: uint32_t) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) =
if i >= V.size_of vv then 4uL else let vvi = V.index vv i in let r = hash_vec_bytes vvi in let rest = hash_vv_bytes_i vv (i + 1ul) in if u64_add_fits r rest then (assert (UInt.size (U64.v r + U64.v rest) 64); r + rest) else uint64_max
false
Vale.Lib.X64.Cpuid.fst
Vale.Lib.X64.Cpuid.va_codegen_success_Check_sha_support
val va_codegen_success_Check_sha_support : va_dummy:unit -> Tot va_pbool
val va_codegen_success_Check_sha_support : va_dummy:unit -> Tot va_pbool
let va_codegen_success_Check_sha_support () = (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 7)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_pbool_and (va_codegen_success_Cpuid_Sha ()) (va_pbool_and (va_codegen_success_And64 (va_op_dst_opr64_reg64 rRbx) (va_const_opr64 536870912)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRbx)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_ttrue ()))))))))
{ "file_name": "obj/Vale.Lib.X64.Cpuid.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 14, "end_line": 152, "start_col": 0, "start_line": 144 }
module Vale.Lib.X64.Cpuid open Vale.Def.Types_s open Vale.Arch.Types open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.State open Vale.X64.Decls open Vale.X64.InsBasic open Vale.X64.QuickCode open Vale.X64.QuickCodes open Vale.X64.CPU_Features_s //let pow2_values (u:unit) : Lemma // (pow2 29 == 0x20000000 /\ // pow2 25 == 0x2000000 /\ // pow2 1 == 0x2) // = // assert_norm (pow2 29 == 0x20000000); // assert_norm (0x2000000 == pow2 25); // assert_norm (0x2 == pow2 1); // () open Vale.Lib.Basic //-- Check_aesni_support [@ "opaque_to_smt" va_qattr] let va_code_Check_aesni_support () = (va_Block (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 1)) (va_CCons (va_code_Cpuid_AES ()) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 33554432)) (va_CCons (va_code_Shr64 (va_op_dst_opr64_reg64 rRax) (va_const_shift_amt64 24)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 2)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_CNil ())))))))))))) [@ "opaque_to_smt" va_qattr] let va_codegen_success_Check_aesni_support () = (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 1)) (va_pbool_and (va_codegen_success_Cpuid_AES ()) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_pbool_and (va_codegen_success_And64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 33554432)) (va_pbool_and (va_codegen_success_Shr64 (va_op_dst_opr64_reg64 rRax) (va_const_shift_amt64 24)) (va_pbool_and (va_codegen_success_And64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 2)) (va_pbool_and (va_codegen_success_And64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_ttrue ()))))))))))) [@ "opaque_to_smt" va_qattr] let va_qcode_Check_aesni_support (va_mods:va_mods_t) : (va_quickCode unit (va_code_Check_aesni_support ())) = (qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 42 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 44 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 45 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 1)) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 46 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Cpuid_AES ()) (fun (va_s:va_state) _ -> let (va_arg22:Vale.Def.Types_s.nat64) = va_get_reg64 rRcx va_s in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 47 column 23 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_iand_pow2_64 va_arg22 25) (let (va_arg21:Vale.Def.Types_s.nat64) = va_get_reg64 rRcx va_s in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 48 column 23 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_iand_pow2_64 va_arg21 1) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 49 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 50 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_And64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 33554432)) (fun (va_s:va_state) _ -> va_QLemma va_range1 "***** PRECONDITION NOT MET AT line 51 column 21 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" ((fun (p:prop) -> normalize p) (33554432 == Prims.pow2 25)) (fun _ -> (fun (p:prop) -> p) (33554432 == Prims.pow2 25)) (fun (_:unit) -> assert_normalize (33554432 == Prims.pow2 25)) (va_QLemma va_range1 "***** PRECONDITION NOT MET AT line 52 column 21 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" ((fun (p:prop) -> normalize p) (2 == Prims.pow2 1)) (fun _ -> (fun (p:prop) -> p) (2 == Prims.pow2 1)) (fun (_:unit) -> assert_normalize (2 == Prims.pow2 1)) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 54 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Shr64 (va_op_dst_opr64_reg64 rRax) (va_const_shift_amt64 24)) (fun (va_s:va_state) _ -> va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 55 column 27 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_ishr_pow2_diff64 1 25) (va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 56 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_ishr_zero64 24) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 58 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_And64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 2)) (fun (va_s:va_state) _ -> let (va_arg20:Vale.Def.Types_s.nat64) = va_get_reg64 rRcx va_s in let (va_arg19:Vale.Def.Types_s.nat64) = va_get_reg64 rRax va_s in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 59 column 29 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_iand_maybe_pow2_64 va_arg19 va_arg20 1) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 60 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_And64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 66 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_QEmpty (())))))))))))))))))))) [@"opaque_to_smt"] let va_lemma_Check_aesni_support va_b0 va_s0 = let (va_mods:va_mods_t) = [va_Mod_flags; va_Mod_reg64 rR9; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax; va_Mod_ok] in let va_qc = va_qcode_Check_aesni_support va_mods in let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_Check_aesni_support ()) va_qc va_s0 (fun va_s0 va_sM va_g -> let () = va_g in label va_range1 "***** POSTCONDITION NOT MET AT line 34 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_get_ok va_sM) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 39 column 56 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_get_reg64 rRax va_sM =!= 0 ==> aesni_enabled /\ pclmulqdq_enabled) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 40 column 24 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_get_reg64 rRbx va_sM == va_get_reg64 rRbx va_s0)) in assert_norm (va_qc.mods == va_mods); va_lemma_norm_mods ([va_Mod_flags; va_Mod_reg64 rR9; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax; va_Mod_ok]) va_sM va_s0; (va_sM, va_fM) [@"opaque_to_smt"] let va_wpProof_Check_aesni_support va_s0 va_k = let (va_sM, va_f0) = va_lemma_Check_aesni_support (va_code_Check_aesni_support ()) va_s0 in va_lemma_upd_update va_sM; assert (va_state_eq va_sM (va_update_flags va_sM (va_update_reg64 rR9 va_sM (va_update_reg64 rRdx va_sM (va_update_reg64 rRcx va_sM (va_update_reg64 rRbx va_sM (va_update_reg64 rRax va_sM (va_update_ok va_sM va_s0)))))))); va_lemma_norm_mods ([va_Mod_flags; va_Mod_reg64 rR9; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax]) va_sM va_s0; let va_g = () in (va_sM, va_f0, va_g) //-- //-- Check_sha_support [@ "opaque_to_smt" va_qattr] let va_code_Check_sha_support () = (va_Block (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 7)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_CCons (va_code_Cpuid_Sha ()) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRbx) (va_const_opr64 536870912)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_CNil ())))))))))
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.QuickCodes.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.InsBasic.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Lib.Basic.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.TypesNative.fsti.checked", "Vale.Arch.Types.fsti.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Vale.Lib.X64.Cpuid.fst" }
[ { "abbrev": false, "full_module": "Vale.Lib.Basic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
va_dummy: Prims.unit -> Vale.X64.Decls.va_pbool
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "Vale.X64.Decls.va_pbool_and", "Vale.X64.InsBasic.va_codegen_success_Mov64", "Vale.X64.Decls.va_op_dst_opr64_reg64", "Vale.X64.Machine_s.rR9", "Vale.X64.Decls.va_op_opr64_reg64", "Vale.X64.Machine_s.rRbx", "Vale.X64.Machine_s.rRax", "Vale.X64.Decls.va_const_opr64", "Vale.X64.Machine_s.rRcx", "Vale.X64.InsBasic.va_codegen_success_Cpuid_Sha", "Vale.X64.InsBasic.va_codegen_success_And64", "Vale.X64.Decls.va_ttrue", "Vale.X64.Decls.va_pbool" ]
[]
false
false
false
true
false
let va_codegen_success_Check_sha_support () =
(va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 7)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_pbool_and (va_codegen_success_Cpuid_Sha ()) (va_pbool_and (va_codegen_success_And64 (va_op_dst_opr64_reg64 rRbx) (va_const_opr64 536870912)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRbx)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_ttrue ()))))))))
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.deserialize_uint8_t
val deserialize_uint8_t (ok: bool) (buf: const_uint8_p) (sz: uint32_t{CB.length buf = U32.v sz}) (pos: uint32_t) : HST.ST (bool & uint32_t & uint8_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1))
val deserialize_uint8_t (ok: bool) (buf: const_uint8_p) (sz: uint32_t{CB.length buf = U32.v sz}) (pos: uint32_t) : HST.ST (bool & uint32_t & uint8_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1))
let deserialize_uint8_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint8_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0uy) else (true, pos + 1ul, CB.index buf pos)
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 42, "end_line": 230, "start_col": 0, "start_line": 226 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" private let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end private let serialize_uint8_t (ok:bool) (x:uint8_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos x; (true, pos + 1ul) end private let serialize_uint16_t (ok:bool) (x:uint16_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint8_t ok (Int.Cast.uint16_to_uint8 (U16.shift_right x 8ul)) buf sz pos in serialize_uint8_t ok (Int.Cast.uint16_to_uint8 x) buf sz pos private let serialize_uint32_t (ok:bool) (x:uint32_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint16_t ok (Int.Cast.uint32_to_uint16 (U32.shift_right x 16ul)) buf sz pos in serialize_uint16_t ok (Int.Cast.uint32_to_uint16 x) buf sz pos private let serialize_uint64_t (ok:bool) (x:uint64_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint32_t ok (Int.Cast.uint64_to_uint32 (U64.shift_right x 32ul)) buf sz pos in serialize_uint32_t ok (Int.Cast.uint64_to_uint32 x) buf sz pos private let serialize_offset_t = serialize_uint64_t private let serialize_index_t = serialize_uint32_t private let rec serialize_hash_i (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < hash_size}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else let b = x.(i) in let ok, pos = serialize_uint8_t ok (Lib.RawIntTypes.u8_to_UInt8 b) buf sz pos in let j = i + 1ul in if j < hash_size then serialize_hash_i #hash_size ok x buf sz pos j else (ok, pos) private let serialize_hash (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else serialize_hash_i ok x buf sz pos 0ul private inline_for_extraction let u64_add_fits (x:uint64_t) (y:uint64_t): Tot (r:bool{r ==> UInt.size (U64.v x + U64.v y) 64}) = uint64_max - x >= y #push-options "--z3rlimit 100 --fuel 1 --quake 1/3" private inline_for_extraction let hash_vec_bytes (#hash_size:hash_size_t) (v:hash_vec #hash_size) : Tot uint64_t = let vs_hs = U64.mul (u32_64 (V.size_of v)) (u32_64 hash_size) in if u64_add_fits vs_hs 4UL then vs_hs + 4UL else uint64_max #pop-options private let rec serialize_hash_vec_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ loc_disjoint (B.loc_buffer buf) (loc_rvector x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let ok, pos = serialize_hash ok vi buf sz pos in let j = i + 1ul in if j < V.size_of x then serialize_hash_vec_i ok x buf sz pos j else (ok, pos) end private let serialize_hash_vec (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvreg hash_size) x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if ok && V.size_of x > 0ul then serialize_hash_vec_i ok x buf sz pos 0ul else (ok, pos) end private inline_for_extraction let rec hash_vv_bytes_i (#hash_size:hash_size_t) (vv:hash_vv hash_size) (i:uint32_t) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = if i >= V.size_of vv then 4UL else begin let vvi = V.index vv i in let r = hash_vec_bytes vvi in let rest = hash_vv_bytes_i vv (i+1ul) in if u64_add_fits r rest then begin assert (UInt.size (U64.v r + U64.v rest) 64); r + rest end else uint64_max end private inline_for_extraction let hash_vv_bytes (#hash_size:hash_size_t) (vv:hash_vv hash_size {V.size_of vv = merkle_tree_size_lg}) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = hash_vv_bytes_i vv 0ul private let rec serialize_hash_vv_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vv hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let h0 = HST.get() in let ok, pos = serialize_hash_vec #hash_size ok vi buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; let j = i + 1ul in if j < V.size_of x then serialize_hash_vv_i #hash_size ok x buf sz pos j else (ok, pos) end private let serialize_hash_vv (#hash_size:hash_size_t) (ok:bool) (x:hash_vv hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if (V.size_of x > 0ul) then serialize_hash_vv_i ok x buf sz pos 0ul else (ok, pos) end private let deserialize_bool (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & bool) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, false) else (true, pos + 1ul, (match CB.index buf pos with| 0uy -> false | _ -> true))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ok: Prims.bool -> buf: MerkleTree.Low.Serialization.const_uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.ConstBuffer.length buf = FStar.UInt32.v sz} -> pos: MerkleTree.Low.Serialization.uint32_t -> FStar.HyperStack.ST.ST ((Prims.bool * MerkleTree.Low.Serialization.uint32_t) * MerkleTree.Low.Serialization.uint8_t)
FStar.HyperStack.ST.ST
[]
[]
[ "Prims.bool", "MerkleTree.Low.Serialization.const_uint8_p", "MerkleTree.Low.Serialization.uint32_t", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "LowStar.ConstBuffer.length", "MerkleTree.Low.Serialization.uint8_t", "FStar.UInt32.v", "Prims.op_BarBar", "Prims.op_Negation", "FStar.Integers.op_Greater_Equals", "FStar.Integers.Unsigned", "FStar.Integers.W32", "FStar.Pervasives.Native.Mktuple3", "FStar.UInt8.__uint_to_t", "FStar.Pervasives.Native.tuple3", "FStar.Integers.op_Plus", "FStar.UInt32.__uint_to_t", "LowStar.ConstBuffer.index", "FStar.Monotonic.HyperStack.mem", "LowStar.ConstBuffer.live", "Prims.eq2" ]
[]
false
true
false
false
false
let deserialize_uint8_t (ok: bool) (buf: const_uint8_p) (sz: uint32_t{CB.length buf = U32.v sz}) (pos: uint32_t) : HST.ST (bool & uint32_t & uint8_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) =
if not ok || pos >= sz then (false, pos, 0uy) else (true, pos + 1ul, CB.index buf pos)
false
Vale.Lib.X64.Cpuid.fst
Vale.Lib.X64.Cpuid.va_codegen_success_Check_aesni_support
val va_codegen_success_Check_aesni_support : va_dummy:unit -> Tot va_pbool
val va_codegen_success_Check_aesni_support : va_dummy:unit -> Tot va_pbool
let va_codegen_success_Check_aesni_support () = (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 1)) (va_pbool_and (va_codegen_success_Cpuid_AES ()) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_pbool_and (va_codegen_success_And64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 33554432)) (va_pbool_and (va_codegen_success_Shr64 (va_op_dst_opr64_reg64 rRax) (va_const_shift_amt64 24)) (va_pbool_and (va_codegen_success_And64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 2)) (va_pbool_and (va_codegen_success_And64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_ttrue ())))))))))))
{ "file_name": "obj/Vale.Lib.X64.Cpuid.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 81, "end_line": 48, "start_col": 0, "start_line": 38 }
module Vale.Lib.X64.Cpuid open Vale.Def.Types_s open Vale.Arch.Types open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.State open Vale.X64.Decls open Vale.X64.InsBasic open Vale.X64.QuickCode open Vale.X64.QuickCodes open Vale.X64.CPU_Features_s //let pow2_values (u:unit) : Lemma // (pow2 29 == 0x20000000 /\ // pow2 25 == 0x2000000 /\ // pow2 1 == 0x2) // = // assert_norm (pow2 29 == 0x20000000); // assert_norm (0x2000000 == pow2 25); // assert_norm (0x2 == pow2 1); // () open Vale.Lib.Basic //-- Check_aesni_support [@ "opaque_to_smt" va_qattr] let va_code_Check_aesni_support () = (va_Block (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 1)) (va_CCons (va_code_Cpuid_AES ()) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 33554432)) (va_CCons (va_code_Shr64 (va_op_dst_opr64_reg64 rRax) (va_const_shift_amt64 24)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 2)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_CNil ()))))))))))))
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.QuickCodes.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.InsBasic.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Lib.Basic.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.TypesNative.fsti.checked", "Vale.Arch.Types.fsti.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Vale.Lib.X64.Cpuid.fst" }
[ { "abbrev": false, "full_module": "Vale.Lib.Basic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
va_dummy: Prims.unit -> Vale.X64.Decls.va_pbool
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "Vale.X64.Decls.va_pbool_and", "Vale.X64.InsBasic.va_codegen_success_Mov64", "Vale.X64.Decls.va_op_dst_opr64_reg64", "Vale.X64.Machine_s.rR9", "Vale.X64.Decls.va_op_opr64_reg64", "Vale.X64.Machine_s.rRbx", "Vale.X64.Machine_s.rRcx", "Vale.X64.Decls.va_const_opr64", "Vale.X64.Machine_s.rRax", "Vale.X64.InsBasic.va_codegen_success_Cpuid_AES", "Vale.X64.InsBasic.va_codegen_success_And64", "Vale.X64.InsBasic.va_codegen_success_Shr64", "Vale.X64.Decls.va_const_shift_amt64", "Vale.X64.Decls.va_ttrue", "Vale.X64.Decls.va_pbool" ]
[]
false
false
false
true
false
let va_codegen_success_Check_aesni_support () =
(va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 1)) (va_pbool_and (va_codegen_success_Cpuid_AES ()) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_pbool_and (va_codegen_success_And64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 33554432)) (va_pbool_and (va_codegen_success_Shr64 (va_op_dst_opr64_reg64 rRax) (va_const_shift_amt64 24)) (va_pbool_and (va_codegen_success_And64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 2)) (va_pbool_and (va_codegen_success_And64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRbx ) (va_op_opr64_reg64 rR9)) (va_ttrue ())))))))))))
false
Vale.Lib.X64.Cpuid.fst
Vale.Lib.X64.Cpuid.va_code_Check_aesni_support
val va_code_Check_aesni_support : va_dummy:unit -> Tot va_code
val va_code_Check_aesni_support : va_dummy:unit -> Tot va_code
let va_code_Check_aesni_support () = (va_Block (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 1)) (va_CCons (va_code_Cpuid_AES ()) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 33554432)) (va_CCons (va_code_Shr64 (va_op_dst_opr64_reg64 rRax) (va_const_shift_amt64 24)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 2)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_CNil ()))))))))))))
{ "file_name": "obj/Vale.Lib.X64.Cpuid.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 81, "end_line": 35, "start_col": 0, "start_line": 26 }
module Vale.Lib.X64.Cpuid open Vale.Def.Types_s open Vale.Arch.Types open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.State open Vale.X64.Decls open Vale.X64.InsBasic open Vale.X64.QuickCode open Vale.X64.QuickCodes open Vale.X64.CPU_Features_s //let pow2_values (u:unit) : Lemma // (pow2 29 == 0x20000000 /\ // pow2 25 == 0x2000000 /\ // pow2 1 == 0x2) // = // assert_norm (pow2 29 == 0x20000000); // assert_norm (0x2000000 == pow2 25); // assert_norm (0x2 == pow2 1); // () open Vale.Lib.Basic //-- Check_aesni_support
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.QuickCodes.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.InsBasic.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Lib.Basic.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.TypesNative.fsti.checked", "Vale.Arch.Types.fsti.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Vale.Lib.X64.Cpuid.fst" }
[ { "abbrev": false, "full_module": "Vale.Lib.Basic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
va_dummy: Prims.unit -> Vale.X64.Decls.va_code
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "Vale.X64.Decls.va_Block", "Vale.X64.Decls.va_CCons", "Vale.X64.InsBasic.va_code_Mov64", "Vale.X64.Decls.va_op_dst_opr64_reg64", "Vale.X64.Machine_s.rR9", "Vale.X64.Decls.va_op_opr64_reg64", "Vale.X64.Machine_s.rRbx", "Vale.X64.Machine_s.rRcx", "Vale.X64.Decls.va_const_opr64", "Vale.X64.Machine_s.rRax", "Vale.X64.InsBasic.va_code_Cpuid_AES", "Vale.X64.InsBasic.va_code_And64", "Vale.X64.InsBasic.va_code_Shr64", "Vale.X64.Decls.va_const_shift_amt64", "Vale.X64.Decls.va_CNil", "Vale.X64.Decls.va_code" ]
[]
false
false
false
true
false
let va_code_Check_aesni_support () =
(va_Block (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 1)) (va_CCons (va_code_Cpuid_AES ()) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 33554432)) (va_CCons (va_code_Shr64 (va_op_dst_opr64_reg64 rRax) (va_const_shift_amt64 24)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 2)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_CNil ()))))))))))))
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.deserialize_uint32_t
val deserialize_uint32_t (ok: bool) (buf: const_uint8_p) (sz: uint32_t{CB.length buf = U32.v sz}) (pos: uint32_t) : HST.ST (bool & uint32_t & uint32_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1))
val deserialize_uint32_t (ok: bool) (buf: const_uint8_p) (sz: uint32_t{CB.length buf = U32.v sz}) (pos: uint32_t) : HST.ST (bool & uint32_t & uint32_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1))
let deserialize_uint32_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint32_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0ul) else begin let ok, pos, b0 = deserialize_uint16_t ok buf sz pos in let ok, pos, b1 = deserialize_uint16_t ok buf sz pos in (ok, pos, (U32.shift_left (Int.Cast.uint16_to_uint32 b0) 16ul) + Int.Cast.uint16_to_uint32 b1) end
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 5, "end_line": 252, "start_col": 0, "start_line": 244 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" private let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end private let serialize_uint8_t (ok:bool) (x:uint8_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos x; (true, pos + 1ul) end private let serialize_uint16_t (ok:bool) (x:uint16_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint8_t ok (Int.Cast.uint16_to_uint8 (U16.shift_right x 8ul)) buf sz pos in serialize_uint8_t ok (Int.Cast.uint16_to_uint8 x) buf sz pos private let serialize_uint32_t (ok:bool) (x:uint32_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint16_t ok (Int.Cast.uint32_to_uint16 (U32.shift_right x 16ul)) buf sz pos in serialize_uint16_t ok (Int.Cast.uint32_to_uint16 x) buf sz pos private let serialize_uint64_t (ok:bool) (x:uint64_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint32_t ok (Int.Cast.uint64_to_uint32 (U64.shift_right x 32ul)) buf sz pos in serialize_uint32_t ok (Int.Cast.uint64_to_uint32 x) buf sz pos private let serialize_offset_t = serialize_uint64_t private let serialize_index_t = serialize_uint32_t private let rec serialize_hash_i (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < hash_size}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else let b = x.(i) in let ok, pos = serialize_uint8_t ok (Lib.RawIntTypes.u8_to_UInt8 b) buf sz pos in let j = i + 1ul in if j < hash_size then serialize_hash_i #hash_size ok x buf sz pos j else (ok, pos) private let serialize_hash (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else serialize_hash_i ok x buf sz pos 0ul private inline_for_extraction let u64_add_fits (x:uint64_t) (y:uint64_t): Tot (r:bool{r ==> UInt.size (U64.v x + U64.v y) 64}) = uint64_max - x >= y #push-options "--z3rlimit 100 --fuel 1 --quake 1/3" private inline_for_extraction let hash_vec_bytes (#hash_size:hash_size_t) (v:hash_vec #hash_size) : Tot uint64_t = let vs_hs = U64.mul (u32_64 (V.size_of v)) (u32_64 hash_size) in if u64_add_fits vs_hs 4UL then vs_hs + 4UL else uint64_max #pop-options private let rec serialize_hash_vec_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ loc_disjoint (B.loc_buffer buf) (loc_rvector x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let ok, pos = serialize_hash ok vi buf sz pos in let j = i + 1ul in if j < V.size_of x then serialize_hash_vec_i ok x buf sz pos j else (ok, pos) end private let serialize_hash_vec (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvreg hash_size) x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if ok && V.size_of x > 0ul then serialize_hash_vec_i ok x buf sz pos 0ul else (ok, pos) end private inline_for_extraction let rec hash_vv_bytes_i (#hash_size:hash_size_t) (vv:hash_vv hash_size) (i:uint32_t) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = if i >= V.size_of vv then 4UL else begin let vvi = V.index vv i in let r = hash_vec_bytes vvi in let rest = hash_vv_bytes_i vv (i+1ul) in if u64_add_fits r rest then begin assert (UInt.size (U64.v r + U64.v rest) 64); r + rest end else uint64_max end private inline_for_extraction let hash_vv_bytes (#hash_size:hash_size_t) (vv:hash_vv hash_size {V.size_of vv = merkle_tree_size_lg}) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = hash_vv_bytes_i vv 0ul private let rec serialize_hash_vv_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vv hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let h0 = HST.get() in let ok, pos = serialize_hash_vec #hash_size ok vi buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; let j = i + 1ul in if j < V.size_of x then serialize_hash_vv_i #hash_size ok x buf sz pos j else (ok, pos) end private let serialize_hash_vv (#hash_size:hash_size_t) (ok:bool) (x:hash_vv hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if (V.size_of x > 0ul) then serialize_hash_vv_i ok x buf sz pos 0ul else (ok, pos) end private let deserialize_bool (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & bool) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, false) else (true, pos + 1ul, (match CB.index buf pos with| 0uy -> false | _ -> true)) private let deserialize_uint8_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint8_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0uy) else (true, pos + 1ul, CB.index buf pos) private let deserialize_uint16_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint16_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0us) else begin let ok, pos, b0 = deserialize_uint8_t ok buf sz pos in let ok, pos, b1 = deserialize_uint8_t ok buf sz pos in (ok, pos, (U16.shift_left (Int.Cast.uint8_to_uint16 b0) 8ul) + Int.Cast.uint8_to_uint16 b1) end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ok: Prims.bool -> buf: MerkleTree.Low.Serialization.const_uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.ConstBuffer.length buf = FStar.UInt32.v sz} -> pos: MerkleTree.Low.Serialization.uint32_t -> FStar.HyperStack.ST.ST ((Prims.bool * MerkleTree.Low.Serialization.uint32_t) * MerkleTree.Low.Serialization.uint32_t)
FStar.HyperStack.ST.ST
[]
[]
[ "Prims.bool", "MerkleTree.Low.Serialization.const_uint8_p", "MerkleTree.Low.Serialization.uint32_t", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "LowStar.ConstBuffer.length", "MerkleTree.Low.Serialization.uint8_t", "FStar.UInt32.v", "Prims.op_BarBar", "Prims.op_Negation", "FStar.Integers.op_Greater_Equals", "FStar.Integers.Unsigned", "FStar.Integers.W32", "FStar.Pervasives.Native.Mktuple3", "FStar.UInt32.__uint_to_t", "FStar.Pervasives.Native.tuple3", "MerkleTree.Low.Serialization.uint16_t", "FStar.Integers.op_Plus", "FStar.UInt32.shift_left", "FStar.Int.Cast.uint16_to_uint32", "MerkleTree.Low.Serialization.deserialize_uint16_t", "FStar.Monotonic.HyperStack.mem", "LowStar.ConstBuffer.live", "Prims.eq2" ]
[]
false
true
false
false
false
let deserialize_uint32_t (ok: bool) (buf: const_uint8_p) (sz: uint32_t{CB.length buf = U32.v sz}) (pos: uint32_t) : HST.ST (bool & uint32_t & uint32_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) =
if not ok || pos >= sz then (false, pos, 0ul) else let ok, pos, b0 = deserialize_uint16_t ok buf sz pos in let ok, pos, b1 = deserialize_uint16_t ok buf sz pos in (ok, pos, (U32.shift_left (Int.Cast.uint16_to_uint32 b0) 16ul) + Int.Cast.uint16_to_uint32 b1)
false
Hacl.Spec.BignumQ.Mul.fst
Hacl.Spec.BignumQ.Mul.barrett_reduction5
val barrett_reduction5: t:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 t < pow2 512) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (wide_as_nat5 t) % S.q)
val barrett_reduction5: t:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 t < pow2 512) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (wide_as_nat5 t) % S.q)
let barrett_reduction5 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = let (m0, m1, m2, m3, m4) = make_m () in let (mu0, mu1, mu2, mu3, mu4) = make_mu () in let (q0, q1, q2, q3, q4) = div_248 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) in assert (as_nat5 (q0, q1, q2, q3, q4) == wide_as_nat5 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) / pow2 248); FStar.Math.Lemmas.lemma_div_lt_nat (wide_as_nat5 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9)) 512 248; assert (as_nat5 (q0, q1, q2, q3, q4) < pow2 264); let (qmu0', qmu1', qmu2', qmu3', qmu4', qmu5', qmu6', qmu7', qmu8', qmu9') = mul_5 (q0, q1, q2, q3, q4) (mu0, mu1, mu2, mu3, mu4) in FStar.Math.Lemmas.lemma_mult_le_right (pow2 512 / S.q) (as_nat5 (q0, q1, q2, q3, q4)) (pow2 264); assert (wide_as_nat5 (qmu0', qmu1', qmu2', qmu3', qmu4', qmu5', qmu6', qmu7', qmu8', qmu9') <= pow2 512 / S.q * pow2 264); assert_norm (pow2 512 / S.q * pow2 264 < pow2 528); let (qdiv0, qdiv1, qdiv2, qdiv3, qdiv4) = div_264 (qmu0', qmu1', qmu2', qmu3', qmu4', qmu5', qmu6', qmu7', qmu8', qmu9') in //u = qdiv == (A / b^{k-1}) * mu / b^{k+1} == ((A / 2^248) * mu) / 2^264 let (r0, r1, r2, r3, r4) = mod_264 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) in //r == A mod b^{k+1} == A mod 2^264 let (qmul0, qmul1, qmul2, qmul3, qmul4) = low_mul_5 (qdiv0, qdiv1, qdiv2, qdiv3, qdiv4) (m0, m1, m2, m3, m4) in //v == qmul == u * L mod b^{k+1} == u * L mod 2^264 let (s0, s1, s2, s3, s4) = sub_mod_264 (r0, r1, r2, r3, r4) (qmul0, qmul1, qmul2, qmul3, qmul4) in //u == s == (r - v) mod b^{k+1} == (r - v) mod 2^264 let (o0, o1, o2, o3, o4) = subm_conditional (s0, s1, s2, s3, s4) in Lemmas.lemma_barrett_reduce' (wide_as_nat5 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9)); (o0, o1, o2, o3, o4)
{ "file_name": "code/ed25519/Hacl.Spec.BignumQ.Mul.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 22, "end_line": 843, "start_col": 0, "start_line": 814 }
module Hacl.Spec.BignumQ.Mul open FStar.Mul open Lib.IntTypes module S = Spec.Ed25519 module Lemmas = Hacl.Spec.BignumQ.Lemmas include Hacl.Spec.BignumQ.Definitions #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract let mask56 : x:uint64{v x == pow2 56 - 1} = assert_norm (pow2 56 - 1 == 0xffffffffffffff); u64 0xffffffffffffff inline_for_extraction noextract let mask40 : x:uint64{v x == pow2 40 - 1} = assert_norm (pow2 40 - 1 == 0xffffffffff); u64 0xffffffffff inline_for_extraction noextract val make_m: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == S.q} let make_m () = let m0 = u64 0x12631a5cf5d3ed in let m1 = u64 0xf9dea2f79cd658 in let m2 = u64 0x000000000014de in let m3 = u64 0x00000000000000 in let m4 = u64 0x00000010000000 in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val make_mu: unit -> m:qelem5{qelem_fits5 m (1, 1, 1, 1, 1) /\ as_nat5 m == pow2 512 / S.q} let make_mu m = let m0 = u64 0x9ce5a30a2c131b in let m1 = u64 0x215d086329a7ed in let m2 = u64 0xffffffffeb2106 in let m3 = u64 0xffffffffffffff in let m4 = u64 0x00000fffffffff in assert_norm (as_nat5 (m0, m1, m2, m3, m4) == pow2 512 / S.q); (m0, m1, m2, m3, m4) inline_for_extraction noextract val choose: b:uint64 -> x:qelem5 -> y:qelem5 -> Pure qelem5 (requires v b == 0 \/ v b == 1) (ensures fun z -> if v b = 1 then z == x else z == y) let choose b (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let mask = b -. u64 1 in let z0 = x0 ^. (mask &. (x0 ^. y0)) in Lemmas.lemma_choose_step b x0 y0; let z1 = x1 ^. (mask &. (x1 ^. y1)) in Lemmas.lemma_choose_step b x1 y1; let z2 = x2 ^. (mask &. (x2 ^. y2)) in Lemmas.lemma_choose_step b x2 y2; let z3 = x3 ^. (mask &. (x3 ^. y3)) in Lemmas.lemma_choose_step b x3 y3; let z4 = x4 ^. (mask &. (x4 ^. y4)) in Lemmas.lemma_choose_step b x4 y4; (z0, z1, z2, z3, z4) inline_for_extraction noextract val subm_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow56 /\ v y <= pow56) (ensures fun (b, t) -> v b <= 1 /\ qelem_fits1 t 1 /\ v x - v y == v t - v b * pow56) let subm_step x y = let b = (x -. y) >>. 63ul in //assert (if v x >= v y then v b == 0 else v b == 1); let lshift56 = (b <<. 56ul) in //assert (if v x >= v y then v lshift56 == 0 else v lshift56 == pow56); //assert (v lshift56 == v b * pow56); //assert (v ((b <<. 56ul) +! x) == v b * pow56 + v x); let t = ((b <<. 56ul) +! x) -! y in b, t inline_for_extraction noextract val subm_conditional: x:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ (if as_nat5 x >= S.q then as_nat5 r == as_nat5 x - S.q else as_nat5 r == as_nat5 x)) let subm_conditional (x0, x1, x2, x3, x4) = let (y0, y1, y2, y3, y4) = make_m () in let (b0, t0) = subm_step x0 y0 in assert (v x0 - v y0 == v t0 - v b0 * pow56); let (b1, t1) = subm_step x1 (y1 +! b0) in assert (v x1 - v y1 - v b0 == v t1 - v b1 * pow56); let (b2, t2) = subm_step x2 (y2 +! b1) in assert (v x2 - v y2 - v b1 == v t2 - v b2 * pow56); let (b3, t3) = subm_step x3 (y3 +! b2) in assert (v x3 - v y3 - v b2 == v t3 - v b3 * pow56); let (b4, t4) = subm_step x4 (y4 +! b3) in assert (v x4 - v y4 - v b3 == v t4 - v b4 * pow56); Lemmas.lemma_subm_conditional (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) (v b0) (v b1) (v b2) (v b3) (v b4); assert ( as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow56 * pow224 == as_nat5 (x0, x1, x2, x3, x4) - as_nat5 (y0, y1, y2, y3, y4)); //assert_norm (pow56 * pow224 = pow2 280); //assert (as_nat5 (t0, t1, t2, t3, t4) - v b4 * pow2 280 == as_nat5 (x0, x1, x2, x3, x4) - S.q); Lemmas.lemma_as_nat5 (x0, x1, x2, x3, x4); Lemmas.lemma_as_nat5 (t0, t1, t2, t3, t4); //assert (if v b4 = 0 then as_nat5 (x0, x1, x2, x3, x4) >= S.q else as_nat5 (x0, x1, x2, x3, x4) < S.q); assert (if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 else v b4 == 1); let (z0, z1, z2, z3, z4) = choose b4 (x0, x1, x2, x3, x4) (t0, t1, t2, t3, t4) in assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); assert ( if as_nat5 (x0, x1, x2, x3, x4) >= S.q then v b4 == 0 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (t0, t1, t2, t3, t4) else v b4 == 1 /\ as_nat5 (z0, z1, z2, z3, z4) == as_nat5 (x0, x1, x2, x3, x4)); (z0, z1, z2, z3, z4) inline_for_extraction noextract val carry56: x:uint64 -> Pure (uint64 & uint64) (requires v x <= pow2 57) (ensures fun (t, c) -> v t < pow56 /\ v c <= 2 /\ v x == v c * pow56 + v t) let carry56 x = let carry = x >>. 56ul in FStar.Math.Lemmas.pow2_minus 57 56; let t = x &. mask56 in assert_norm (pow2 56 < pow2 64); mod_mask_lemma x 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); t, carry inline_for_extraction noextract val add_modq5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < S.q /\ as_nat5 y < S.q) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (as_nat5 x + as_nat5 y) % S.q) let add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = assert_norm (pow56 - 1 + pow56 - 1 == pow2 57 - 2); let (t0, c0) = carry56 (x0 +! y0) in let (t1, c1) = carry56 (x1 +! y1 +! c0) in let (t2, c2) = carry56 (x2 +! y2 +! c1) in let (t3, c3) = carry56 (x3 +! y3 +! c2) in let t4 = x4 +! y4 +! c3 in assert (as_nat5 (t0, t1, t2, t3, t4) == as_nat5 (x0, x1, x2, x3, x4) + as_nat5 (y0, y1, y2, y3, y4)); let (o0, o1, o2, o3, o4) = subm_conditional (t0, t1, t2, t3, t4) in Lemmas.lemma_add_modq5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) (t0, t1, t2, t3, t4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry56_wide: x:uint128 -> Pure (uint128 & uint64) (requires v x < pow2 117) (ensures fun (c, t) -> v t < pow56 /\ v c < pow2 61 /\ v x - v c * pow56 == v t /\ v c == v x / pow56) let carry56_wide x = let carry = x >>. 56ul in let t = to_u64 x &. mask56 in assert_norm (pow2 56 < pow2 64); Math.Lemmas.lemma_div_lt_nat (v x) 117 56; mod_mask_lemma (to_u64 x) 56ul; assert (v (mod_mask #U64 #SEC 56ul) == v mask56); assert (v t == (v x % pow2 64) % pow2 56); FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1 (v x) 56 64; assert (v t == v x % pow2 56); assert (v x == v carry * pow2 56 + v t); carry, t inline_for_extraction noextract val mul64_wide_5: (a:uint64) -> (b:uint64) -> Pure uint128 (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures fun z -> v z == v a * v b /\ v z <= pow2 112 - pow2 57 + 1 /\ v z < pow2 112) let mul64_wide_5 a b = let lemma_smaller (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) < pow2 112) = if v a = 0 || v b = 0 then () else calc (<) { v a * v b <: int; (<) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56) } v a * pow2 56; (<) { Math.Lemmas.lemma_mult_le_right (pow2 56) (v a) (pow2 56) } pow2 56 * pow2 56; (==) { assert_norm (pow2 56 * pow2 56 == pow2 112) } pow2 112; } in let lemma_le (a b:uint64) : Lemma (requires qelem_fits1 a 1 /\ qelem_fits1 b 1) (ensures v (mul64_wide a b) <= pow2 112 - pow2 57 + 1) = if v a = 0 || v b = 0 then () else assert_norm (pow2 112 - pow2 57 + 1 >= 0); calc (<=) { v a * v b <: int; (<=) { Math.Lemmas.lemma_mult_le_left (v a) (v b) (pow2 56 - 1) } v a * (pow2 56 - 1); (<=) { Math.Lemmas.lemma_mult_le_right (pow2 56 - 1) (v a) (pow2 56 - 1) } (pow2 56 - 1) * (pow2 56 - 1); (==) { assert_norm ((pow2 56 - 1) * (pow2 56 - 1) == pow2 112 - pow2 57 + 1) } pow2 112 - pow2 57 + 1; } in lemma_le a b; lemma_smaller a b; mul64_wide a b inline_for_extraction noextract val add2: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112) (ensures fun z -> v z == v a + v b /\ v z <= pow2 116) let add2 a b = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b inline_for_extraction noextract val add3: (a:uint128) -> (b:uint128) -> (c:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 ) (ensures fun z -> v z == v a + v b + v c /\ v z <= pow2 116) let add3 a b c = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); a +. b +. c inline_for_extraction noextract val add4: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d /\ v z <= pow2 116) let add4 a b c d = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d) (pow2 128); a +. b +. c +. d inline_for_extraction noextract val add5: (a:uint128) -> (b:uint128) -> (c:uint128) -> (d:uint128) -> (e:uint128) -> Pure uint128 (requires v a < pow2 112 /\ v b < pow2 112 /\ v c < pow2 112 /\ v d < pow2 112 /\ v e < pow2 112) (ensures fun z -> v z == v a + v b + v c + v d + v e/\ v z <= pow2 116) let add5 a b c d e = assert_norm (pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 + pow2 112 < pow2 128); assert_norm (pow2 112 + pow2 112 + pow2 112 + pow2 112 + pow2 112 <= pow2 116); Math.Lemmas.small_mod (v a + v b) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d) (pow2 128); Math.Lemmas.small_mod (v a + v b + v c + v d + v e) (pow2 128); a +. b +. c +. d +. e inline_for_extraction noextract val add_inner_carry: (a:uint128) -> (b:uint128) -> Pure uint128 (requires v a <= pow2 116 /\ v b < pow2 61) (ensures fun z -> v z == v a + v b /\ v z < pow2 117) let add_inner_carry a b = assert_norm (pow2 116 + pow2 61 < pow2 128); assert_norm (pow2 116 + pow2 61 < pow2 117); Math.Lemmas.small_mod (v a + v b) (pow2 128); a +. b inline_for_extraction noextract val mul_5: x:qelem5 -> y:qelem5 -> Pure qelem_wide5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1)) (ensures fun r -> qelem_wide_fits5 r (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 r == as_nat5 x * as_nat5 y) let lemma_mult_distr_3 (a b c:nat) (n:nat) : Lemma ((a + b - c * pow2 56) * pow2 n == a * pow2 n + b * pow2 n - c * pow2 (n + 56)) = Math.Lemmas.distributivity_sub_left (a + b) (c * pow2 56) (pow2 n); Math.Lemmas.distributivity_add_left a b (pow2 n); Math.Lemmas.pow2_plus 56 n #set-options "--z3rlimit 300" let mul_5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let xy00 = mul64_wide_5 x0 y0 in let xy01 = mul64_wide_5 x0 y1 in let xy02 = mul64_wide_5 x0 y2 in let xy03 = mul64_wide_5 x0 y3 in let xy04 = mul64_wide_5 x0 y4 in let xy10 = mul64_wide_5 x1 y0 in let xy11 = mul64_wide_5 x1 y1 in let xy12 = mul64_wide_5 x1 y2 in let xy13 = mul64_wide_5 x1 y3 in let xy14 = mul64_wide_5 x1 y4 in let xy20 = mul64_wide_5 x2 y0 in let xy21 = mul64_wide_5 x2 y1 in let xy22 = mul64_wide_5 x2 y2 in let xy23 = mul64_wide_5 x2 y3 in let xy24 = mul64_wide_5 x2 y4 in let xy30 = mul64_wide_5 x3 y0 in let xy31 = mul64_wide_5 x3 y1 in let xy32 = mul64_wide_5 x3 y2 in let xy33 = mul64_wide_5 x3 y3 in let xy34 = mul64_wide_5 x3 y4 in let xy40 = mul64_wide_5 x4 y0 in let xy41 = mul64_wide_5 x4 y1 in let xy42 = mul64_wide_5 x4 y2 in let xy43 = mul64_wide_5 x4 y3 in let xy44 = mul64_wide_5 x4 y4 in let z0 = xy00 in // < pow2 112 let z1 = add2 xy01 xy10 in // < pow2 113 let z2 = add3 xy02 xy11 xy20 in // < pow2 114 let z3 = add4 xy03 xy12 xy21 xy30 in // < pow2 115 let z4 = add5 xy04 xy13 xy22 xy31 xy40 in // < pow2 116 let z5 = add4 xy14 xy23 xy32 xy41 in let z6 = add3 xy24 xy33 xy42 in let z7 = add2 xy34 xy43 in let z8 = xy44 in //(z0, z1, z2, z3, z4, z5, z6, z7, z8) assert_norm (pow2 112 < pow2 117); assert_norm (pow2 112 <= pow2 116); let (c0, t0) = carry56_wide z0 in let (c1, t1) = carry56_wide (add_inner_carry z1 c0) in let (c2, t2) = carry56_wide (add_inner_carry z2 c1) in let (c3, t3) = carry56_wide (add_inner_carry z3 c2) in let (c4, t4) = carry56_wide (add_inner_carry z4 c3) in let (c5, t5) = carry56_wide (add_inner_carry z5 c4) in let (c6, t6) = carry56_wide (add_inner_carry z6 c5) in let (c7, t7) = carry56_wide (add_inner_carry z7 c6) in let (c8, t8) = carry56_wide (add_inner_carry z8 c7) in let t9 = to_u64 c8 in let lemma_t9_fits () : Lemma (v t9 < pow2 56) = // This proof was built from the bottom. We have as a constraint that v c8 has to be < pow2 112 to satisfy the postcondition. // We compute each time the maximal value such that this postcondition is satisfied calc (<) { v c0; (<) { Math.Lemmas.lemma_div_lt_nat (v z0) 112 56 } pow2 56; }; calc (<) { v c1; (<) { assert_norm (2*(pow2 112 - pow2 57 + 1) + pow2 56 <= pow2 113); Math.Lemmas.lemma_div_lt_nat (v z1 + v c0) 113 56 } pow2 57; }; calc (<) { v c2; (<) { assert_norm (3*(pow2 112 - pow2 57 + 1) + pow2 57 <= pow2 114); Math.Lemmas.lemma_div_lt_nat (v z2 + v c1) 114 56 } pow2 58; }; calc (<=) { v c3; (<=) { assert_norm (4*(pow2 112 - pow2 57 + 1) + pow2 58 <= 31153781151208965410895007785680895); assert_norm (31153781151208965410895007785680895 / pow56 == 432345564227567610); Math.Lemmas.lemma_div_le (v z3 + v c2) 31153781151208965410895007785680895 (pow2 56) } 432345564227567610; }; calc (<=) { v c4; (<=) { assert_norm (5*(pow2 112 - pow2 57 + 1) + 432345564227567610 <= 25961484292674137854422105494388735); // (pow2 59 - 2) * pow56 assert_norm (25961484292674137854422105494388735 / pow56 == 360287970189639675); Math.Lemmas.lemma_div_le (v z4 + v c3) 25961484292674137854422105494388735 (pow2 56) } 360287970189639675; }; calc (<=) { v c5; (<=) { assert_norm (4*(pow2 112 - pow2 57 + 1) + 360287970189639675 <= 20769187434139310297949203203096575); Math.Lemmas.lemma_div_le (v z5 + v c4) 20769187434139310297949203203096575 (pow2 56); assert_norm (20769187434139310297949203203096575 / pow2 56 == pow2 58 - 4) } pow2 58 - 4; }; calc (<=) { v c6; (<=) { assert_norm (3*(pow2 112 - pow2 57 + 1) + pow2 58 - 4 <= 15576890575604482741476300911804415); Math.Lemmas.lemma_div_le (v z6 + v c5) 15576890575604482741476300911804415 (pow2 56); assert_norm (15576890575604482741476300911804415 / pow2 56 == 216172782113783805) } 216172782113783805; }; calc (<=) { v c7; (<=) { assert_norm (2*(pow2 112 - pow2 57 + 1) + 216172782113783805 <= 10384593717069655185003398620512255); // (pow2 57 - 1) * pow2 56 - 1 Math.Lemmas.lemma_div_le (v z7 + v c6) 10384593717069655185003398620512255 (pow2 56); assert_norm (10384593717069655185003398620512255 / pow2 56 == pow2 57 - 2) } pow2 57 - 2; }; calc (<) { v c8; (<) { Math.Lemmas.lemma_div_lt_nat (v z8 + v c7) 112 56 } pow2 56; }; assert_norm (pow2 56 < pow2 64); Math.Lemmas.small_mod (v c8) (pow2 64) in lemma_t9_fits(); calc (==) { wide_as_nat5 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) <: int; (==) { } v t0 + v t1 * pow56 + v t2 * pow112 + v t3 * pow168 + v t4 * pow224 + v t5 * pow280 + v t6 * pow336 + v t7 * pow392 + v t8 * pow448 + v t9 * pow504; (==) { assert_norm (pow2 61 < pow2 64); Math.Lemmas.small_mod (v c8) (pow2 64) } v z0 - v c0 * pow2 56 + (v z1 + v c0 - v c1 * pow2 56) * pow56 + (v z2 + v c1 - v c2 * pow2 56) * pow112 + (v z3 + v c2 - v c3 * pow2 56) * pow168 + (v z4 + v c3 - v c4 * pow2 56) * pow224 + (v z5 + v c4 - v c5 * pow2 56) * pow280 + (v z6 + v c5 - v c6 * pow2 56) * pow336 + (v z7 + v c6 - v c7 * pow2 56) * pow392 + (v z8 + v c7 - v c8 * pow2 56) * pow448 + v c8 * pow504; (==) { lemma_mult_distr_3 (v z1) (v c0) (v c1) 56; lemma_mult_distr_3 (v z2) (v c1) (v c2) 112; lemma_mult_distr_3 (v z3) (v c2) (v c3) 168; lemma_mult_distr_3 (v z4) (v c3) (v c4) 224; lemma_mult_distr_3 (v z5) (v c4) (v c5) 280; lemma_mult_distr_3 (v z6) (v c5) (v c6) 336; lemma_mult_distr_3 (v z7) (v c6) (v c7) 392; lemma_mult_distr_3 (v z8) (v c7) (v c8) 448 } v z0 + v z1 * pow56 + v z2 * pow112 + v z3 * pow168 + v z4 * pow224 + v z5 * pow280 + v z6 * pow336 + v z7 * pow392 + v z8 * pow448; (==) { calc (==) { v z1; (==) { } v x0 * v y1 + v x1 * v y0; }; calc (==) { v z2; (==) { } v x0 * v y2 + v x1 * v y1 + v x2 * v y0; }; calc (==) { v z3; (==) { } v x0 * v y3 + v x1 * v y2 + v x2 * v y1 + v x3 * v y0; }; calc (==) { v z4; (==) { } v x0 * v y4 + v x1 * v y3 + v x2 * v y2 + v x3 * v y1 + v x4 * v y0; }; calc (==) { v z5; (==) { } v x1 * v y4 + v x2 * v y3 + v x3 * v y2 + v x4 * v y1; }; calc (==) { v z6; (==) { } v x2 * v y4 + v x3 * v y3 + v x4 * v y2; }; calc (==) { v z7; (==) { } v x3 * v y4 + v x4 * v y3; }; calc (==) { v z8; (==) { } v x4 * v y4; } } v x0 * v y0 + (v x0 * v y1 + v x1 * v y0) * pow56 + (v x0 * v y2 + v x1 * v y1 + v x2 * v y0) * pow112 + (v x0 * v y3 + v x1 * v y2 + v x2 * v y1 + v x3 * v y0) * pow168 + (v x0 * v y4 + v x1 * v y3 + v x2 * v y2 + v x3 * v y1 + v x4 * v y0) * pow224 + (v x1 * v y4 + v x2 * v y3 + v x3 * v y2 + v x4 * v y1) * pow280 + (v x2 * v y4 + v x3 * v y3 + v x4 * v y2) * pow336 + (v x3 * v y4 + v x4 * v y3) * pow392 + (v x4 * v y4) * pow448; (==) { Lemmas.lemma_mul_qelem5 (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) } (v x0 + v x1 * pow2 56 + v x2 * pow2 112 + v x3 * pow2 168 + v x4 * pow2 224) * (v y0 + v y1 * pow2 56 + v y2 * pow2 112 + v y3 * pow2 168 + v y4 * pow2 224); }; (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) inline_for_extraction noextract val low_mul_5: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (as_nat5 x * as_nat5 y) % pow2 264) let low_mul_5 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let xy00 = mul64_wide_5 x0 y0 in let xy01 = mul64_wide_5 x0 y1 in let xy02 = mul64_wide_5 x0 y2 in let xy03 = mul64_wide_5 x0 y3 in let xy04 = mul64_wide_5 x0 y4 in let xy10 = mul64_wide_5 x1 y0 in let xy11 = mul64_wide_5 x1 y1 in let xy12 = mul64_wide_5 x1 y2 in let xy13 = mul64_wide_5 x1 y3 in let xy20 = mul64_wide_5 x2 y0 in let xy21 = mul64_wide_5 x2 y1 in let xy22 = mul64_wide_5 x2 y2 in let xy30 = mul64_wide_5 x3 y0 in let xy31 = mul64_wide_5 x3 y1 in let xy40 = mul64_wide_5 x4 y0 in assert_norm (pow2 112 < pow2 117); let (c0, t0) = carry56_wide xy00 in let (c1, t1) = carry56_wide (add_inner_carry (add2 xy01 xy10) c0) in let (c2, t2) = carry56_wide (add_inner_carry (add3 xy02 xy11 xy20) c1) in let (c3, t3) = carry56_wide (add_inner_carry (add4 xy03 xy12 xy21 xy30) c2) in let t4 = to_u64 (add_inner_carry (add5 xy04 xy13 xy22 xy31 xy40) c3) &. mask40 in calc (==) { as_nat5 (t0, t1, t2, t3, t4) <: int; (==) { } v t0 + v t1 * pow56 + v t2 * pow112 + v t3 * pow168 + v t4 * pow224; (==) { } v xy00 - v c0 * pow2 56 + (v xy01 + v xy10 + v c0 - v c1 * pow2 56) * pow56 + (v xy02 + v xy11 + v xy20 + v c1 - v c2 * pow56) * pow112 + (v xy03 + v xy12 + v xy21 + v xy30 + v c2 - v c3 * pow56) * pow168 + v t4 * pow224; (==) { logand_mask (to_u64 (add_inner_carry (add5 xy04 xy13 xy22 xy31 xy40) c3)) mask40 40; Math.Lemmas.pow2_modulo_modulo_lemma_1 (v (add_inner_carry (add5 xy04 xy13 xy22 xy31 xy40) c3)) 40 64 } v x0 * v y0 + (v x0 * v y1 + v x1 * v y0) * pow56 + (v x0 * v y2 + v x1 * v y1 + v x2 * v y0) * pow112 + (v x0 * v y3 + v x1 * v y2 + v x2 * v y1 + v x3 * v y0 - v c3 * pow56) * pow168 + ((v x0 * v y4 + v x1 * v y3 + v x2 * v y2 + v x3 * v y1 + v x4 * v y0 + v c3) % pow2 40) * pow224; }; Lemmas.lemma_mul_5_low_264 (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4); (t0, t1, t2, t3, t4) inline_for_extraction noextract val div_2_24_step: x:uint64 -> y:uint64 -> Pure uint64 (requires v x < pow56 /\ v y < pow56) (ensures fun r -> v r < pow56 /\ v r == v x / pow2 24 + pow2 32 * (v y % pow2 24)) let div_2_24_step x y = let y' = (y &. u64 0xffffff) <<. 32ul in assert_norm (pow2 24 - 1 = 0xffffff); assert_norm (pow2 24 < pow2 64); mod_mask_lemma y 24ul; assert (v (mod_mask #U64 #SEC 24ul) == 0xffffff); assert (v (y &. u64 0xffffff) == v y % pow2 24); assert (v y' == (v y % pow2 24) * pow2 32); let x' = x >>. 24ul in FStar.Math.Lemmas.pow2_minus 56 24; assert (v x' < pow2 32); let z = x' |. y' in logor_disjoint x' y' 32; assert (v z == v x / pow2 24 + pow2 32 * (v y % pow2 24)); z inline_for_extraction noextract val div_248: x:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 x < pow2 512) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (wide_as_nat5 x) / pow2 248) let div_248 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = // x / pow2 248 == (x / pow2 224) / pow2 24 let z0 = div_2_24_step x4 x5 in let z1 = div_2_24_step x5 x6 in let z2 = div_2_24_step x6 x7 in let z3 = div_2_24_step x7 x8 in let z4 = div_2_24_step x8 x9 in assert (qelem_fits5 (z0, z1, z2, z3, z4) (1, 1, 1, 1, 1)); Lemmas.lemma_div248 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9); (z0, z1, z2, z3, z4) inline_for_extraction noextract val div_2_40_step: x:uint64 -> y:uint64 -> Pure uint64 (requires v x < pow56) (ensures fun z -> v z < pow56 /\ v z == v x / pow2 40 + pow2 16 * (v y % pow2 40)) let div_2_40_step x y = let y' = (y &. mask40) <<. 16ul in assert_norm (pow2 40 < pow2 64); mod_mask_lemma y 40ul; assert (v (mod_mask #U64 #SEC 40ul) == v mask40); assert (v y' == (v y % pow2 40) * pow2 16); let x' = x >>. 40ul in FStar.Math.Lemmas.pow2_minus 56 40; assert (v x' == v x / pow2 40); assert (v x' < pow2 16); let z = x' |. y' in logor_disjoint x' y' 16; z inline_for_extraction noextract val div_264: x:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 x (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 x < pow2 528) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (wide_as_nat5 x) / pow2 264) let div_264 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) = // x / pow2 264 == (x / pow2 224) / pow2 40 let z0 = div_2_40_step x4 x5 in let z1 = div_2_40_step x5 x6 in let z2 = div_2_40_step x6 x7 in let z3 = div_2_40_step x7 x8 in let z4 = div_2_40_step x8 x9 in assert (qelem_fits5 (z0, z1, z2, z3, z4) (1, 1, 1, 1, 1)); Lemmas.lemma_div264 (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9); (z0, z1, z2, z3, z4) inline_for_extraction noextract val mod_264: t:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1)) (ensures fun r -> qelem_fits5 r (1, 1, 1, 1, 1) /\ as_nat5 r == (wide_as_nat5 t) % pow2 264) let mod_264 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) = Lemmas.lemma_mod_264 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9); (t0, t1, t2, t3, t4 &. mask40) inline_for_extraction noextract val subm_last_step: x:uint64 -> y:uint64 -> Pure (uint64 & uint64) (requires v x < pow2 40 /\ v y <= pow2 40) (ensures fun (b, t) -> v b <= 1 /\ v t < pow2 40 /\ v x - v y == v t - pow2 40 * v b) let subm_last_step x y = assert_norm (pow2 40 < pow2 63); let b = (x -. y) >>. 63ul in assert (if v x >= v y then v b == 0 else v b == 1); let t = ((b <<. 40ul) +! x) -! y in b, t #push-options "--z3rlimit 400 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract val sub_mod_264: x:qelem5 -> y:qelem5 -> Pure qelem5 (requires qelem_fits5 x (1, 1, 1, 1, 1) /\ qelem_fits5 y (1, 1, 1, 1, 1) /\ as_nat5 x < pow2 264 /\ as_nat5 y < pow2 264) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ (if as_nat5 x >= as_nat5 y then as_nat5 z == as_nat5 x - as_nat5 y else as_nat5 z == as_nat5 x - as_nat5 y + pow2 264)) let sub_mod_264 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) = let (c1, t0) = subm_step x0 y0 in assert (v x0 - v y0 == v t0 - v c1 * pow56); let (c2, t1) = subm_step x1 (y1 +! c1) in assert (v x1 - v y1 - v c1 == v t1 - v c2 * pow56); let (c3, t2) = subm_step x2 (y2 +! c2) in assert (v x2 - v y2 - v c2 == v t2 - v c3 * pow56); let (c4, t3) = subm_step x3 (y3 +! c3) in assert (v x3 - v y3 - v c3 == v t3 - v c4 * pow56); Lemmas.lemma_as_nat_pow264_x4 (x0, x1, x2, x3, x4); Lemmas.lemma_as_nat_pow264_x4 (y0, y1, y2, y3, y4); let (c5, t4) = subm_last_step x4 (y4 +! c4) in assert (v x4 - v y4 - v c4 == v t4 - pow2 40 * v c5); assert ( if v c5 = 0 then as_nat5 (x0, x1, x2, x3, x4) >= as_nat5 (y0, y1, y2, y3, y4) else as_nat5 (x0, x1, x2, x3, x4) < as_nat5 (y0, y1, y2, y3, y4)); assert_norm (pow2 40 < pow2 56); assert (qelem_fits5 (t0, t1, t2, t3, t4) (1, 1, 1, 1, 1)); assert (as_nat5 (t0, t1, t2, t3, t4) == v x0 - v y0 + v c1 * pow56 + (v x1 - v y1 - v c1 + v c2 * pow56) * pow56 + (v x2 - v y2 - v c2 + v c3 * pow56) * pow112 + (v x3 - v y3 - v c3 + v c4 * pow56) * pow168 + (v x4 - v y4 - v c4 + pow2 40 * v c5) * pow224); Lemmas.lemma_sub_mod_264_aux (v x0) (v x1) (v x2) (v x3) (v x4) (v y0) (v y1) (v y2) (v y3) (v y4) (v c1) (v c2) (v c3) (v c4) (v c5); assert (as_nat5 (t0, t1, t2, t3, t4) == as_nat5 (x0, x1, x2, x3, x4) - as_nat5 (y0, y1, y2, y3, y4) + v c5 * pow2 264); Lemmas.lemma_sub_mod_264 (x0, x1, x2, x3, x4) (y0, y1, y2, y3, y4) (t0, t1, t2, t3, t4) c5; (t0, t1, t2, t3, t4) #pop-options // A = t, L = make_m() // b = 2^8, k = 32, mu = b^{2*k} / L = make_mu() inline_for_extraction noextract val barrett_reduction5: t:qelem_wide5 -> Pure qelem5 (requires qelem_wide_fits5 t (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) /\ wide_as_nat5 t < pow2 512) (ensures fun z -> qelem_fits5 z (1, 1, 1, 1, 1) /\ as_nat5 z == (wide_as_nat5 t) % S.q)
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.BignumQ.Lemmas.fst.checked", "Hacl.Spec.BignumQ.Definitions.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.BignumQ.Mul.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.BignumQ.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.BignumQ.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.BignumQ", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 300, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Hacl.Spec.BignumQ.Definitions.qelem_wide5 -> Prims.Pure Hacl.Spec.BignumQ.Definitions.qelem5
Prims.Pure
[]
[]
[ "Hacl.Spec.BignumQ.Definitions.qelem_wide5", "Lib.IntTypes.uint64", "FStar.Pervasives.Native.Mktuple5", "Prims.unit", "Hacl.Spec.BignumQ.Lemmas.lemma_barrett_reduce'", "Hacl.Spec.BignumQ.Definitions.wide_as_nat5", "FStar.Pervasives.Native.Mktuple10", "Hacl.Spec.BignumQ.Definitions.qelem5", "Hacl.Spec.BignumQ.Mul.subm_conditional", "Hacl.Spec.BignumQ.Mul.sub_mod_264", "Hacl.Spec.BignumQ.Mul.low_mul_5", "Hacl.Spec.BignumQ.Mul.mod_264", "Hacl.Spec.BignumQ.Mul.div_264", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_LessThan", "FStar.Mul.op_Star", "Prims.op_Division", "Prims.pow2", "Spec.Ed25519.q", "Prims._assert", "Prims.op_LessThanOrEqual", "FStar.Math.Lemmas.lemma_mult_le_right", "Hacl.Spec.BignumQ.Definitions.as_nat5", "Hacl.Spec.BignumQ.Mul.mul_5", "FStar.Math.Lemmas.lemma_div_lt_nat", "Prims.eq2", "Prims.int", "Hacl.Spec.BignumQ.Mul.div_248", "Prims.l_and", "Hacl.Spec.BignumQ.Definitions.qelem_fits5", "Prims.nat", "Hacl.Spec.BignumQ.Mul.make_mu", "Hacl.Spec.BignumQ.Mul.make_m" ]
[]
false
false
false
false
false
let barrett_reduction5 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) =
let m0, m1, m2, m3, m4 = make_m () in let mu0, mu1, mu2, mu3, mu4 = make_mu () in let q0, q1, q2, q3, q4 = div_248 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) in assert (as_nat5 (q0, q1, q2, q3, q4) == wide_as_nat5 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) / pow2 248); FStar.Math.Lemmas.lemma_div_lt_nat (wide_as_nat5 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9)) 512 248; assert (as_nat5 (q0, q1, q2, q3, q4) < pow2 264); let qmu0', qmu1', qmu2', qmu3', qmu4', qmu5', qmu6', qmu7', qmu8', qmu9' = mul_5 (q0, q1, q2, q3, q4) (mu0, mu1, mu2, mu3, mu4) in FStar.Math.Lemmas.lemma_mult_le_right (pow2 512 / S.q) (as_nat5 (q0, q1, q2, q3, q4)) (pow2 264); assert (wide_as_nat5 (qmu0', qmu1', qmu2', qmu3', qmu4', qmu5', qmu6', qmu7', qmu8', qmu9') <= (pow2 512 / S.q) * pow2 264); assert_norm ((pow2 512 / S.q) * pow2 264 < pow2 528); let qdiv0, qdiv1, qdiv2, qdiv3, qdiv4 = div_264 (qmu0', qmu1', qmu2', qmu3', qmu4', qmu5', qmu6', qmu7', qmu8', qmu9') in let r0, r1, r2, r3, r4 = mod_264 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9) in let qmul0, qmul1, qmul2, qmul3, qmul4 = low_mul_5 (qdiv0, qdiv1, qdiv2, qdiv3, qdiv4) (m0, m1, m2, m3, m4) in let s0, s1, s2, s3, s4 = sub_mod_264 (r0, r1, r2, r3, r4) (qmul0, qmul1, qmul2, qmul3, qmul4) in let o0, o1, o2, o3, o4 = subm_conditional (s0, s1, s2, s3, s4) in Lemmas.lemma_barrett_reduce' (wide_as_nat5 (t0, t1, t2, t3, t4, t5, t6, t7, t8, t9)); (o0, o1, o2, o3, o4)
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.deserialize_bool
val deserialize_bool (ok: bool) (buf: const_uint8_p) (sz: uint32_t{CB.length buf = U32.v sz}) (pos: uint32_t) : HST.ST (bool & uint32_t & bool) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1))
val deserialize_bool (ok: bool) (buf: const_uint8_p) (sz: uint32_t{CB.length buf = U32.v sz}) (pos: uint32_t) : HST.ST (bool & uint32_t & bool) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1))
let deserialize_bool (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & bool) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, false) else (true, pos + 1ul, (match CB.index buf pos with| 0uy -> false | _ -> true))
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 81, "end_line": 223, "start_col": 0, "start_line": 219 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" private let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end private let serialize_uint8_t (ok:bool) (x:uint8_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos x; (true, pos + 1ul) end private let serialize_uint16_t (ok:bool) (x:uint16_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint8_t ok (Int.Cast.uint16_to_uint8 (U16.shift_right x 8ul)) buf sz pos in serialize_uint8_t ok (Int.Cast.uint16_to_uint8 x) buf sz pos private let serialize_uint32_t (ok:bool) (x:uint32_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint16_t ok (Int.Cast.uint32_to_uint16 (U32.shift_right x 16ul)) buf sz pos in serialize_uint16_t ok (Int.Cast.uint32_to_uint16 x) buf sz pos private let serialize_uint64_t (ok:bool) (x:uint64_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint32_t ok (Int.Cast.uint64_to_uint32 (U64.shift_right x 32ul)) buf sz pos in serialize_uint32_t ok (Int.Cast.uint64_to_uint32 x) buf sz pos private let serialize_offset_t = serialize_uint64_t private let serialize_index_t = serialize_uint32_t private let rec serialize_hash_i (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < hash_size}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else let b = x.(i) in let ok, pos = serialize_uint8_t ok (Lib.RawIntTypes.u8_to_UInt8 b) buf sz pos in let j = i + 1ul in if j < hash_size then serialize_hash_i #hash_size ok x buf sz pos j else (ok, pos) private let serialize_hash (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else serialize_hash_i ok x buf sz pos 0ul private inline_for_extraction let u64_add_fits (x:uint64_t) (y:uint64_t): Tot (r:bool{r ==> UInt.size (U64.v x + U64.v y) 64}) = uint64_max - x >= y #push-options "--z3rlimit 100 --fuel 1 --quake 1/3" private inline_for_extraction let hash_vec_bytes (#hash_size:hash_size_t) (v:hash_vec #hash_size) : Tot uint64_t = let vs_hs = U64.mul (u32_64 (V.size_of v)) (u32_64 hash_size) in if u64_add_fits vs_hs 4UL then vs_hs + 4UL else uint64_max #pop-options private let rec serialize_hash_vec_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ loc_disjoint (B.loc_buffer buf) (loc_rvector x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let ok, pos = serialize_hash ok vi buf sz pos in let j = i + 1ul in if j < V.size_of x then serialize_hash_vec_i ok x buf sz pos j else (ok, pos) end private let serialize_hash_vec (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvreg hash_size) x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if ok && V.size_of x > 0ul then serialize_hash_vec_i ok x buf sz pos 0ul else (ok, pos) end private inline_for_extraction let rec hash_vv_bytes_i (#hash_size:hash_size_t) (vv:hash_vv hash_size) (i:uint32_t) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = if i >= V.size_of vv then 4UL else begin let vvi = V.index vv i in let r = hash_vec_bytes vvi in let rest = hash_vv_bytes_i vv (i+1ul) in if u64_add_fits r rest then begin assert (UInt.size (U64.v r + U64.v rest) 64); r + rest end else uint64_max end private inline_for_extraction let hash_vv_bytes (#hash_size:hash_size_t) (vv:hash_vv hash_size {V.size_of vv = merkle_tree_size_lg}) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = hash_vv_bytes_i vv 0ul private let rec serialize_hash_vv_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vv hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let h0 = HST.get() in let ok, pos = serialize_hash_vec #hash_size ok vi buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; let j = i + 1ul in if j < V.size_of x then serialize_hash_vv_i #hash_size ok x buf sz pos j else (ok, pos) end private let serialize_hash_vv (#hash_size:hash_size_t) (ok:bool) (x:hash_vv hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if (V.size_of x > 0ul) then serialize_hash_vv_i ok x buf sz pos 0ul else (ok, pos) end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ok: Prims.bool -> buf: MerkleTree.Low.Serialization.const_uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.ConstBuffer.length buf = FStar.UInt32.v sz} -> pos: MerkleTree.Low.Serialization.uint32_t -> FStar.HyperStack.ST.ST ((Prims.bool * MerkleTree.Low.Serialization.uint32_t) * Prims.bool)
FStar.HyperStack.ST.ST
[]
[]
[ "Prims.bool", "MerkleTree.Low.Serialization.const_uint8_p", "MerkleTree.Low.Serialization.uint32_t", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "LowStar.ConstBuffer.length", "MerkleTree.Low.Serialization.uint8_t", "FStar.UInt32.v", "Prims.op_BarBar", "Prims.op_Negation", "FStar.Integers.op_Greater_Equals", "FStar.Integers.Unsigned", "FStar.Integers.W32", "FStar.Pervasives.Native.Mktuple3", "FStar.Pervasives.Native.tuple3", "FStar.Integers.op_Plus", "FStar.UInt32.__uint_to_t", "FStar.UInt8.t", "LowStar.ConstBuffer.index", "FStar.Monotonic.HyperStack.mem", "LowStar.ConstBuffer.live", "Prims.eq2" ]
[]
false
true
false
false
false
let deserialize_bool (ok: bool) (buf: const_uint8_p) (sz: uint32_t{CB.length buf = U32.v sz}) (pos: uint32_t) : HST.ST (bool & uint32_t & bool) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) =
if not ok || pos >= sz then (false, pos, false) else (true, pos + 1ul, (match CB.index buf pos with | 0uy -> false | _ -> true))
false
Vale.Lib.X64.Cpuid.fst
Vale.Lib.X64.Cpuid.va_code_Check_sha_support
val va_code_Check_sha_support : va_dummy:unit -> Tot va_code
val va_code_Check_sha_support : va_dummy:unit -> Tot va_code
let va_code_Check_sha_support () = (va_Block (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 7)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_CCons (va_code_Cpuid_Sha ()) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRbx) (va_const_opr64 536870912)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_CNil ())))))))))
{ "file_name": "obj/Vale.Lib.X64.Cpuid.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 78, "end_line": 141, "start_col": 0, "start_line": 135 }
module Vale.Lib.X64.Cpuid open Vale.Def.Types_s open Vale.Arch.Types open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.State open Vale.X64.Decls open Vale.X64.InsBasic open Vale.X64.QuickCode open Vale.X64.QuickCodes open Vale.X64.CPU_Features_s //let pow2_values (u:unit) : Lemma // (pow2 29 == 0x20000000 /\ // pow2 25 == 0x2000000 /\ // pow2 1 == 0x2) // = // assert_norm (pow2 29 == 0x20000000); // assert_norm (0x2000000 == pow2 25); // assert_norm (0x2 == pow2 1); // () open Vale.Lib.Basic //-- Check_aesni_support [@ "opaque_to_smt" va_qattr] let va_code_Check_aesni_support () = (va_Block (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 1)) (va_CCons (va_code_Cpuid_AES ()) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 33554432)) (va_CCons (va_code_Shr64 (va_op_dst_opr64_reg64 rRax) (va_const_shift_amt64 24)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 2)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_CNil ())))))))))))) [@ "opaque_to_smt" va_qattr] let va_codegen_success_Check_aesni_support () = (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 1)) (va_pbool_and (va_codegen_success_Cpuid_AES ()) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_pbool_and (va_codegen_success_And64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 33554432)) (va_pbool_and (va_codegen_success_Shr64 (va_op_dst_opr64_reg64 rRax) (va_const_shift_amt64 24)) (va_pbool_and (va_codegen_success_And64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 2)) (va_pbool_and (va_codegen_success_And64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_ttrue ()))))))))))) [@ "opaque_to_smt" va_qattr] let va_qcode_Check_aesni_support (va_mods:va_mods_t) : (va_quickCode unit (va_code_Check_aesni_support ())) = (qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 42 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 44 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 45 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 1)) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 46 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Cpuid_AES ()) (fun (va_s:va_state) _ -> let (va_arg22:Vale.Def.Types_s.nat64) = va_get_reg64 rRcx va_s in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 47 column 23 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_iand_pow2_64 va_arg22 25) (let (va_arg21:Vale.Def.Types_s.nat64) = va_get_reg64 rRcx va_s in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 48 column 23 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_iand_pow2_64 va_arg21 1) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 49 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 50 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_And64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 33554432)) (fun (va_s:va_state) _ -> va_QLemma va_range1 "***** PRECONDITION NOT MET AT line 51 column 21 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" ((fun (p:prop) -> normalize p) (33554432 == Prims.pow2 25)) (fun _ -> (fun (p:prop) -> p) (33554432 == Prims.pow2 25)) (fun (_:unit) -> assert_normalize (33554432 == Prims.pow2 25)) (va_QLemma va_range1 "***** PRECONDITION NOT MET AT line 52 column 21 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" ((fun (p:prop) -> normalize p) (2 == Prims.pow2 1)) (fun _ -> (fun (p:prop) -> p) (2 == Prims.pow2 1)) (fun (_:unit) -> assert_normalize (2 == Prims.pow2 1)) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 54 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Shr64 (va_op_dst_opr64_reg64 rRax) (va_const_shift_amt64 24)) (fun (va_s:va_state) _ -> va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 55 column 27 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_ishr_pow2_diff64 1 25) (va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 56 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_ishr_zero64 24) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 58 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_And64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 2)) (fun (va_s:va_state) _ -> let (va_arg20:Vale.Def.Types_s.nat64) = va_get_reg64 rRcx va_s in let (va_arg19:Vale.Def.Types_s.nat64) = va_get_reg64 rRax va_s in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 59 column 29 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_iand_maybe_pow2_64 va_arg19 va_arg20 1) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 60 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_And64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 66 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_QEmpty (())))))))))))))))))))) [@"opaque_to_smt"] let va_lemma_Check_aesni_support va_b0 va_s0 = let (va_mods:va_mods_t) = [va_Mod_flags; va_Mod_reg64 rR9; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax; va_Mod_ok] in let va_qc = va_qcode_Check_aesni_support va_mods in let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_Check_aesni_support ()) va_qc va_s0 (fun va_s0 va_sM va_g -> let () = va_g in label va_range1 "***** POSTCONDITION NOT MET AT line 34 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_get_ok va_sM) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 39 column 56 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_get_reg64 rRax va_sM =!= 0 ==> aesni_enabled /\ pclmulqdq_enabled) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 40 column 24 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_get_reg64 rRbx va_sM == va_get_reg64 rRbx va_s0)) in assert_norm (va_qc.mods == va_mods); va_lemma_norm_mods ([va_Mod_flags; va_Mod_reg64 rR9; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax; va_Mod_ok]) va_sM va_s0; (va_sM, va_fM) [@"opaque_to_smt"] let va_wpProof_Check_aesni_support va_s0 va_k = let (va_sM, va_f0) = va_lemma_Check_aesni_support (va_code_Check_aesni_support ()) va_s0 in va_lemma_upd_update va_sM; assert (va_state_eq va_sM (va_update_flags va_sM (va_update_reg64 rR9 va_sM (va_update_reg64 rRdx va_sM (va_update_reg64 rRcx va_sM (va_update_reg64 rRbx va_sM (va_update_reg64 rRax va_sM (va_update_ok va_sM va_s0)))))))); va_lemma_norm_mods ([va_Mod_flags; va_Mod_reg64 rR9; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax]) va_sM va_s0; let va_g = () in (va_sM, va_f0, va_g) //-- //-- Check_sha_support
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.QuickCodes.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.InsBasic.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Lib.Basic.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.TypesNative.fsti.checked", "Vale.Arch.Types.fsti.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Vale.Lib.X64.Cpuid.fst" }
[ { "abbrev": false, "full_module": "Vale.Lib.Basic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
va_dummy: Prims.unit -> Vale.X64.Decls.va_code
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "Vale.X64.Decls.va_Block", "Vale.X64.Decls.va_CCons", "Vale.X64.InsBasic.va_code_Mov64", "Vale.X64.Decls.va_op_dst_opr64_reg64", "Vale.X64.Machine_s.rR9", "Vale.X64.Decls.va_op_opr64_reg64", "Vale.X64.Machine_s.rRbx", "Vale.X64.Machine_s.rRax", "Vale.X64.Decls.va_const_opr64", "Vale.X64.Machine_s.rRcx", "Vale.X64.InsBasic.va_code_Cpuid_Sha", "Vale.X64.InsBasic.va_code_And64", "Vale.X64.Decls.va_CNil", "Vale.X64.Decls.va_code" ]
[]
false
false
false
true
false
let va_code_Check_sha_support () =
(va_Block (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 7)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_CCons (va_code_Cpuid_Sha ()) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRbx) (va_const_opr64 536870912) ) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_CNil ())))))))))
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.serialize_hash_vec_i
val serialize_hash_vec_i (#hash_size: hash_size_t) (ok: bool) (x: hash_vec #hash_size) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) (i: uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ loc_disjoint (B.loc_buffer buf) (loc_rvector x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1))
val serialize_hash_vec_i (#hash_size: hash_size_t) (ok: bool) (x: hash_vec #hash_size) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) (i: uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ loc_disjoint (B.loc_buffer buf) (loc_rvector x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1))
let rec serialize_hash_vec_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ loc_disjoint (B.loc_buffer buf) (loc_rvector x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let ok, pos = serialize_hash ok vi buf sz pos in let j = i + 1ul in if j < V.size_of x then serialize_hash_vec_i ok x buf sz pos j else (ok, pos) end
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 5, "end_line": 133, "start_col": 0, "start_line": 120 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" private let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end private let serialize_uint8_t (ok:bool) (x:uint8_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos x; (true, pos + 1ul) end private let serialize_uint16_t (ok:bool) (x:uint16_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint8_t ok (Int.Cast.uint16_to_uint8 (U16.shift_right x 8ul)) buf sz pos in serialize_uint8_t ok (Int.Cast.uint16_to_uint8 x) buf sz pos private let serialize_uint32_t (ok:bool) (x:uint32_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint16_t ok (Int.Cast.uint32_to_uint16 (U32.shift_right x 16ul)) buf sz pos in serialize_uint16_t ok (Int.Cast.uint32_to_uint16 x) buf sz pos private let serialize_uint64_t (ok:bool) (x:uint64_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint32_t ok (Int.Cast.uint64_to_uint32 (U64.shift_right x 32ul)) buf sz pos in serialize_uint32_t ok (Int.Cast.uint64_to_uint32 x) buf sz pos private let serialize_offset_t = serialize_uint64_t private let serialize_index_t = serialize_uint32_t private let rec serialize_hash_i (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < hash_size}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else let b = x.(i) in let ok, pos = serialize_uint8_t ok (Lib.RawIntTypes.u8_to_UInt8 b) buf sz pos in let j = i + 1ul in if j < hash_size then serialize_hash_i #hash_size ok x buf sz pos j else (ok, pos) private let serialize_hash (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else serialize_hash_i ok x buf sz pos 0ul private inline_for_extraction let u64_add_fits (x:uint64_t) (y:uint64_t): Tot (r:bool{r ==> UInt.size (U64.v x + U64.v y) 64}) = uint64_max - x >= y #push-options "--z3rlimit 100 --fuel 1 --quake 1/3" private inline_for_extraction let hash_vec_bytes (#hash_size:hash_size_t) (v:hash_vec #hash_size) : Tot uint64_t = let vs_hs = U64.mul (u32_64 (V.size_of v)) (u32_64 hash_size) in if u64_add_fits vs_hs 4UL then vs_hs + 4UL else uint64_max #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ok: Prims.bool -> x: MerkleTree.Low.Datastructures.hash_vec -> buf: MerkleTree.Low.Serialization.uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.Monotonic.Buffer.len buf = sz} -> pos: MerkleTree.Low.Serialization.uint32_t -> i: MerkleTree.Low.Serialization.uint32_t{i < LowStar.Vector.size_of x} -> FStar.HyperStack.ST.ST (Prims.bool * MerkleTree.Low.Serialization.uint32_t)
FStar.HyperStack.ST.ST
[]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "Prims.bool", "MerkleTree.Low.Datastructures.hash_vec", "MerkleTree.Low.Serialization.uint8_p", "MerkleTree.Low.Serialization.uint32_t", "Prims.b2t", "Prims.op_Equality", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.len", "MerkleTree.Low.Serialization.uint8_t", "LowStar.Buffer.trivial_preorder", "FStar.Integers.op_Less", "FStar.Integers.Unsigned", "FStar.Integers.W32", "LowStar.Vector.size_of", "MerkleTree.Low.Datastructures.hash", "Prims.op_BarBar", "Prims.op_Negation", "FStar.Integers.op_Greater_Equals", "FStar.Pervasives.Native.Mktuple2", "FStar.UInt32.__uint_to_t", "FStar.Pervasives.Native.tuple2", "MerkleTree.Low.Serialization.serialize_hash_vec_i", "FStar.Integers.int_t", "FStar.Integers.op_Plus", "MerkleTree.Low.Serialization.serialize_hash", "LowStar.Vector.index", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "LowStar.Monotonic.Buffer.live", "LowStar.RVector.rv_inv", "MerkleTree.Low.Datastructures.hreg", "LowStar.Monotonic.Buffer.loc_disjoint", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.RVector.loc_rvector", "LowStar.Monotonic.Buffer.modifies" ]
[ "recursion" ]
false
true
false
false
false
let rec serialize_hash_vec_i (#hash_size: hash_size_t) (ok: bool) (x: hash_vec #hash_size) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) (i: uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ loc_disjoint (B.loc_buffer buf) (loc_rvector x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) =
if not ok || pos >= sz then (false, 0ul) else let vi = V.index x i in let ok, pos = serialize_hash ok vi buf sz pos in let j = i + 1ul in if j < V.size_of x then serialize_hash_vec_i ok x buf sz pos j else (ok, pos)
false
Pulse.Checker.Prover.ElimPure.fst
Pulse.Checker.Prover.ElimPure.elim_pure_head
val elim_pure_head : Pulse.Syntax.Base.term
let elim_pure_head = let elim_pure_explicit_lid = mk_pulse_lib_core_lid "elim_pure_explicit" in tm_fvar (as_fv elim_pure_explicit_lid)
{ "file_name": "lib/steel/pulse/Pulse.Checker.Prover.ElimPure.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 42, "end_line": 37, "start_col": 0, "start_line": 35 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Checker.Prover.ElimPure module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module L = FStar.List.Tot module T = FStar.Tactics.V2 open FStar.List.Tot open Pulse.Syntax open Pulse.Checker.Pure open Pulse.Checker.VPropEquiv open Pulse.Typing open Pulse.Typing.Combinators module Metatheory = Pulse.Typing.Metatheory open Pulse.Reflection.Util open Pulse.Checker.Prover.Base module RU = Pulse.RuntimeUtils
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.Metatheory.fsti.checked", "Pulse.Typing.Combinators.fsti.checked", "Pulse.Typing.fst.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Checker.VPropEquiv.fsti.checked", "Pulse.Checker.Pure.fsti.checked", "Pulse.Checker.Prover.Base.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "Pulse.Checker.Prover.ElimPure.fst" }
[ { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Typing.Metatheory", "short_module": "Metatheory" }, { "abbrev": false, "full_module": "Pulse.Typing.Combinators", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.VPropEquiv", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Pure", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Pulse.Syntax.Base.term
Prims.Tot
[ "total" ]
[]
[ "Pulse.Syntax.Pure.tm_fvar", "Pulse.Syntax.Base.as_fv", "Prims.list", "Prims.string", "Pulse.Reflection.Util.mk_pulse_lib_core_lid" ]
[]
false
false
false
true
false
let elim_pure_head =
let elim_pure_explicit_lid = mk_pulse_lib_core_lid "elim_pure_explicit" in tm_fvar (as_fv elim_pure_explicit_lid)
false
Pulse.Checker.Prover.ElimPure.fst
Pulse.Checker.Prover.ElimPure.elim_pure_head_ty
val elim_pure_head_ty : FStar.Stubs.Reflection.Types.term
let elim_pure_head_ty = // let open Pulse.Steel.Wrapper in // let open Steel.Effect.Common in let squash_p = mk_squash u0 (RT.bound_var 0) in let pure_p = mk_pure (RT.bound_var 0) in let post = mk_abs squash_p R.Q_Explicit (R.pack_ln (R.Tv_FVar (R.pack_fv emp_lid))) in let cod = mk_stt_ghost_comp u0 squash_p pure_p post in mk_arrow (R.pack_ln (R.Tv_FVar (R.pack_fv R.prop_qn)), R.Q_Explicit) cod
{ "file_name": "lib/steel/pulse/Pulse.Checker.Prover.ElimPure.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 9, "end_line": 50, "start_col": 0, "start_line": 39 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Checker.Prover.ElimPure module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module L = FStar.List.Tot module T = FStar.Tactics.V2 open FStar.List.Tot open Pulse.Syntax open Pulse.Checker.Pure open Pulse.Checker.VPropEquiv open Pulse.Typing open Pulse.Typing.Combinators module Metatheory = Pulse.Typing.Metatheory open Pulse.Reflection.Util open Pulse.Checker.Prover.Base module RU = Pulse.RuntimeUtils let elim_pure_head = let elim_pure_explicit_lid = mk_pulse_lib_core_lid "elim_pure_explicit" in tm_fvar (as_fv elim_pure_explicit_lid)
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.Metatheory.fsti.checked", "Pulse.Typing.Combinators.fsti.checked", "Pulse.Typing.fst.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Checker.VPropEquiv.fsti.checked", "Pulse.Checker.Pure.fsti.checked", "Pulse.Checker.Prover.Base.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "Pulse.Checker.Prover.ElimPure.fst" }
[ { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Typing.Metatheory", "short_module": "Metatheory" }, { "abbrev": false, "full_module": "Pulse.Typing.Combinators", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.VPropEquiv", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Pure", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "Pulse.Reflection.Util.mk_arrow", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.Types.term", "FStar.Stubs.Reflection.V2.Data.aqualv", "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_FVar", "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "FStar.Reflection.Const.prop_qn", "FStar.Stubs.Reflection.V2.Data.Q_Explicit", "Pulse.Reflection.Util.mk_stt_ghost_comp", "Pulse.Syntax.Pure.u0", "Pulse.Reflection.Util.mk_abs", "Pulse.Reflection.Util.emp_lid", "Pulse.Reflection.Util.mk_pure", "FStar.Reflection.Typing.bound_var", "Pulse.Reflection.Util.mk_squash" ]
[]
false
false
false
true
false
let elim_pure_head_ty =
let squash_p = mk_squash u0 (RT.bound_var 0) in let pure_p = mk_pure (RT.bound_var 0) in let post = mk_abs squash_p R.Q_Explicit (R.pack_ln (R.Tv_FVar (R.pack_fv emp_lid))) in let cod = mk_stt_ghost_comp u0 squash_p pure_p post in mk_arrow (R.pack_ln (R.Tv_FVar (R.pack_fv R.prop_qn)), R.Q_Explicit) cod
false
Vale.Lib.X64.Cpuid.fst
Vale.Lib.X64.Cpuid.va_code_Check_adx_bmi2_support
val va_code_Check_adx_bmi2_support : va_dummy:unit -> Tot va_code
val va_code_Check_adx_bmi2_support : va_dummy:unit -> Tot va_code
let va_code_Check_adx_bmi2_support () = (va_Block (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 7)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_CCons (va_code_Cpuid_Adx_Bmi2 ()) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 524288)) (va_CCons (va_code_Shr64 (va_op_dst_opr64_reg64 rRax) (va_const_shift_amt64 11)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRbx) (va_const_opr64 256)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_CNil ()))))))))))))
{ "file_name": "obj/Vale.Lib.X64.Cpuid.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 81, "end_line": 225, "start_col": 0, "start_line": 216 }
module Vale.Lib.X64.Cpuid open Vale.Def.Types_s open Vale.Arch.Types open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.State open Vale.X64.Decls open Vale.X64.InsBasic open Vale.X64.QuickCode open Vale.X64.QuickCodes open Vale.X64.CPU_Features_s //let pow2_values (u:unit) : Lemma // (pow2 29 == 0x20000000 /\ // pow2 25 == 0x2000000 /\ // pow2 1 == 0x2) // = // assert_norm (pow2 29 == 0x20000000); // assert_norm (0x2000000 == pow2 25); // assert_norm (0x2 == pow2 1); // () open Vale.Lib.Basic //-- Check_aesni_support [@ "opaque_to_smt" va_qattr] let va_code_Check_aesni_support () = (va_Block (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 1)) (va_CCons (va_code_Cpuid_AES ()) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 33554432)) (va_CCons (va_code_Shr64 (va_op_dst_opr64_reg64 rRax) (va_const_shift_amt64 24)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 2)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_CNil ())))))))))))) [@ "opaque_to_smt" va_qattr] let va_codegen_success_Check_aesni_support () = (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 1)) (va_pbool_and (va_codegen_success_Cpuid_AES ()) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_pbool_and (va_codegen_success_And64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 33554432)) (va_pbool_and (va_codegen_success_Shr64 (va_op_dst_opr64_reg64 rRax) (va_const_shift_amt64 24)) (va_pbool_and (va_codegen_success_And64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 2)) (va_pbool_and (va_codegen_success_And64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_ttrue ()))))))))))) [@ "opaque_to_smt" va_qattr] let va_qcode_Check_aesni_support (va_mods:va_mods_t) : (va_quickCode unit (va_code_Check_aesni_support ())) = (qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 42 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 44 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 45 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 1)) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 46 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Cpuid_AES ()) (fun (va_s:va_state) _ -> let (va_arg22:Vale.Def.Types_s.nat64) = va_get_reg64 rRcx va_s in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 47 column 23 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_iand_pow2_64 va_arg22 25) (let (va_arg21:Vale.Def.Types_s.nat64) = va_get_reg64 rRcx va_s in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 48 column 23 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_iand_pow2_64 va_arg21 1) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 49 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 50 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_And64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 33554432)) (fun (va_s:va_state) _ -> va_QLemma va_range1 "***** PRECONDITION NOT MET AT line 51 column 21 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" ((fun (p:prop) -> normalize p) (33554432 == Prims.pow2 25)) (fun _ -> (fun (p:prop) -> p) (33554432 == Prims.pow2 25)) (fun (_:unit) -> assert_normalize (33554432 == Prims.pow2 25)) (va_QLemma va_range1 "***** PRECONDITION NOT MET AT line 52 column 21 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" ((fun (p:prop) -> normalize p) (2 == Prims.pow2 1)) (fun _ -> (fun (p:prop) -> p) (2 == Prims.pow2 1)) (fun (_:unit) -> assert_normalize (2 == Prims.pow2 1)) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 54 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Shr64 (va_op_dst_opr64_reg64 rRax) (va_const_shift_amt64 24)) (fun (va_s:va_state) _ -> va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 55 column 27 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_ishr_pow2_diff64 1 25) (va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 56 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_ishr_zero64 24) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 58 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_And64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 2)) (fun (va_s:va_state) _ -> let (va_arg20:Vale.Def.Types_s.nat64) = va_get_reg64 rRcx va_s in let (va_arg19:Vale.Def.Types_s.nat64) = va_get_reg64 rRax va_s in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 59 column 29 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_iand_maybe_pow2_64 va_arg19 va_arg20 1) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 60 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_And64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 66 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_QEmpty (())))))))))))))))))))) [@"opaque_to_smt"] let va_lemma_Check_aesni_support va_b0 va_s0 = let (va_mods:va_mods_t) = [va_Mod_flags; va_Mod_reg64 rR9; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax; va_Mod_ok] in let va_qc = va_qcode_Check_aesni_support va_mods in let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_Check_aesni_support ()) va_qc va_s0 (fun va_s0 va_sM va_g -> let () = va_g in label va_range1 "***** POSTCONDITION NOT MET AT line 34 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_get_ok va_sM) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 39 column 56 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_get_reg64 rRax va_sM =!= 0 ==> aesni_enabled /\ pclmulqdq_enabled) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 40 column 24 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_get_reg64 rRbx va_sM == va_get_reg64 rRbx va_s0)) in assert_norm (va_qc.mods == va_mods); va_lemma_norm_mods ([va_Mod_flags; va_Mod_reg64 rR9; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax; va_Mod_ok]) va_sM va_s0; (va_sM, va_fM) [@"opaque_to_smt"] let va_wpProof_Check_aesni_support va_s0 va_k = let (va_sM, va_f0) = va_lemma_Check_aesni_support (va_code_Check_aesni_support ()) va_s0 in va_lemma_upd_update va_sM; assert (va_state_eq va_sM (va_update_flags va_sM (va_update_reg64 rR9 va_sM (va_update_reg64 rRdx va_sM (va_update_reg64 rRcx va_sM (va_update_reg64 rRbx va_sM (va_update_reg64 rRax va_sM (va_update_ok va_sM va_s0)))))))); va_lemma_norm_mods ([va_Mod_flags; va_Mod_reg64 rR9; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax]) va_sM va_s0; let va_g = () in (va_sM, va_f0, va_g) //-- //-- Check_sha_support [@ "opaque_to_smt" va_qattr] let va_code_Check_sha_support () = (va_Block (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 7)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_CCons (va_code_Cpuid_Sha ()) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRbx) (va_const_opr64 536870912)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_CNil ()))))))))) [@ "opaque_to_smt" va_qattr] let va_codegen_success_Check_sha_support () = (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 7)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_pbool_and (va_codegen_success_Cpuid_Sha ()) (va_pbool_and (va_codegen_success_And64 (va_op_dst_opr64_reg64 rRbx) (va_const_opr64 536870912)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRbx)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_ttrue ())))))))) [@ "opaque_to_smt" va_qattr] let va_qcode_Check_sha_support (va_mods:va_mods_t) : (va_quickCode unit (va_code_Check_sha_support ())) = (qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 77 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 79 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 7)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 80 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 81 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Cpuid_Sha ()) (fun (va_s:va_state) _ -> let (va_arg11:Vale.Def.Types_s.nat64) = va_get_reg64 rRbx va_s in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 82 column 23 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_iand_pow2_64 va_arg11 29) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 83 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_And64 (va_op_dst_opr64_reg64 rRbx) (va_const_opr64 536870912)) (fun (va_s:va_state) _ -> va_QLemma va_range1 "***** PRECONDITION NOT MET AT line 84 column 21 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" ((fun (p:prop) -> normalize p) (536870912 == Prims.pow2 29)) (fun _ -> (fun (p:prop) -> p) (536870912 == Prims.pow2 29)) (fun (_:unit) -> assert_normalize (536870912 == Prims.pow2 29)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 85 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRbx)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 87 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_QEmpty (())))))))))))) [@"opaque_to_smt"] let va_lemma_Check_sha_support va_b0 va_s0 = let (va_mods:va_mods_t) = [va_Mod_flags; va_Mod_reg64 rR9; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax; va_Mod_ok] in let va_qc = va_qcode_Check_sha_support va_mods in let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_Check_sha_support ()) va_qc va_s0 (fun va_s0 va_sM va_g -> let () = va_g in label va_range1 "***** POSTCONDITION NOT MET AT line 69 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_get_ok va_sM) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 74 column 33 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_get_reg64 rRax va_sM =!= 0 ==> sha_enabled) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 75 column 24 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_get_reg64 rRbx va_sM == va_get_reg64 rRbx va_s0)) in assert_norm (va_qc.mods == va_mods); va_lemma_norm_mods ([va_Mod_flags; va_Mod_reg64 rR9; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax; va_Mod_ok]) va_sM va_s0; (va_sM, va_fM) [@"opaque_to_smt"] let va_wpProof_Check_sha_support va_s0 va_k = let (va_sM, va_f0) = va_lemma_Check_sha_support (va_code_Check_sha_support ()) va_s0 in va_lemma_upd_update va_sM; assert (va_state_eq va_sM (va_update_flags va_sM (va_update_reg64 rR9 va_sM (va_update_reg64 rRdx va_sM (va_update_reg64 rRcx va_sM (va_update_reg64 rRbx va_sM (va_update_reg64 rRax va_sM (va_update_ok va_sM va_s0)))))))); va_lemma_norm_mods ([va_Mod_flags; va_Mod_reg64 rR9; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax]) va_sM va_s0; let va_g = () in (va_sM, va_f0, va_g) //-- //-- Check_adx_bmi2_support
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.QuickCodes.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.InsBasic.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Lib.Basic.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.TypesNative.fsti.checked", "Vale.Arch.Types.fsti.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Vale.Lib.X64.Cpuid.fst" }
[ { "abbrev": false, "full_module": "Vale.Lib.Basic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
va_dummy: Prims.unit -> Vale.X64.Decls.va_code
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "Vale.X64.Decls.va_Block", "Vale.X64.Decls.va_CCons", "Vale.X64.InsBasic.va_code_Mov64", "Vale.X64.Decls.va_op_dst_opr64_reg64", "Vale.X64.Machine_s.rR9", "Vale.X64.Decls.va_op_opr64_reg64", "Vale.X64.Machine_s.rRbx", "Vale.X64.Machine_s.rRax", "Vale.X64.Decls.va_const_opr64", "Vale.X64.Machine_s.rRcx", "Vale.X64.InsBasic.va_code_Cpuid_Adx_Bmi2", "Vale.X64.InsBasic.va_code_And64", "Vale.X64.InsBasic.va_code_Shr64", "Vale.X64.Decls.va_const_shift_amt64", "Vale.X64.Decls.va_CNil", "Vale.X64.Decls.va_code" ]
[]
false
false
false
true
false
let va_code_Check_adx_bmi2_support () =
(va_Block (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 7)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_CCons (va_code_Cpuid_Adx_Bmi2 ()) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 524288)) (va_CCons (va_code_Shr64 (va_op_dst_opr64_reg64 rRax) (va_const_shift_amt64 11)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRbx) (va_const_opr64 256)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_CNil ()))))))))))))
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.deserialize_uint16_t
val deserialize_uint16_t (ok: bool) (buf: const_uint8_p) (sz: uint32_t{CB.length buf = U32.v sz}) (pos: uint32_t) : HST.ST (bool & uint32_t & uint16_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1))
val deserialize_uint16_t (ok: bool) (buf: const_uint8_p) (sz: uint32_t{CB.length buf = U32.v sz}) (pos: uint32_t) : HST.ST (bool & uint32_t & uint16_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1))
let deserialize_uint16_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint16_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0us) else begin let ok, pos, b0 = deserialize_uint8_t ok buf sz pos in let ok, pos, b1 = deserialize_uint8_t ok buf sz pos in (ok, pos, (U16.shift_left (Int.Cast.uint8_to_uint16 b0) 8ul) + Int.Cast.uint8_to_uint16 b1) end
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 5, "end_line": 241, "start_col": 0, "start_line": 233 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" private let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end private let serialize_uint8_t (ok:bool) (x:uint8_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos x; (true, pos + 1ul) end private let serialize_uint16_t (ok:bool) (x:uint16_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint8_t ok (Int.Cast.uint16_to_uint8 (U16.shift_right x 8ul)) buf sz pos in serialize_uint8_t ok (Int.Cast.uint16_to_uint8 x) buf sz pos private let serialize_uint32_t (ok:bool) (x:uint32_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint16_t ok (Int.Cast.uint32_to_uint16 (U32.shift_right x 16ul)) buf sz pos in serialize_uint16_t ok (Int.Cast.uint32_to_uint16 x) buf sz pos private let serialize_uint64_t (ok:bool) (x:uint64_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint32_t ok (Int.Cast.uint64_to_uint32 (U64.shift_right x 32ul)) buf sz pos in serialize_uint32_t ok (Int.Cast.uint64_to_uint32 x) buf sz pos private let serialize_offset_t = serialize_uint64_t private let serialize_index_t = serialize_uint32_t private let rec serialize_hash_i (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < hash_size}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else let b = x.(i) in let ok, pos = serialize_uint8_t ok (Lib.RawIntTypes.u8_to_UInt8 b) buf sz pos in let j = i + 1ul in if j < hash_size then serialize_hash_i #hash_size ok x buf sz pos j else (ok, pos) private let serialize_hash (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else serialize_hash_i ok x buf sz pos 0ul private inline_for_extraction let u64_add_fits (x:uint64_t) (y:uint64_t): Tot (r:bool{r ==> UInt.size (U64.v x + U64.v y) 64}) = uint64_max - x >= y #push-options "--z3rlimit 100 --fuel 1 --quake 1/3" private inline_for_extraction let hash_vec_bytes (#hash_size:hash_size_t) (v:hash_vec #hash_size) : Tot uint64_t = let vs_hs = U64.mul (u32_64 (V.size_of v)) (u32_64 hash_size) in if u64_add_fits vs_hs 4UL then vs_hs + 4UL else uint64_max #pop-options private let rec serialize_hash_vec_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ loc_disjoint (B.loc_buffer buf) (loc_rvector x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let ok, pos = serialize_hash ok vi buf sz pos in let j = i + 1ul in if j < V.size_of x then serialize_hash_vec_i ok x buf sz pos j else (ok, pos) end private let serialize_hash_vec (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvreg hash_size) x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if ok && V.size_of x > 0ul then serialize_hash_vec_i ok x buf sz pos 0ul else (ok, pos) end private inline_for_extraction let rec hash_vv_bytes_i (#hash_size:hash_size_t) (vv:hash_vv hash_size) (i:uint32_t) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = if i >= V.size_of vv then 4UL else begin let vvi = V.index vv i in let r = hash_vec_bytes vvi in let rest = hash_vv_bytes_i vv (i+1ul) in if u64_add_fits r rest then begin assert (UInt.size (U64.v r + U64.v rest) 64); r + rest end else uint64_max end private inline_for_extraction let hash_vv_bytes (#hash_size:hash_size_t) (vv:hash_vv hash_size {V.size_of vv = merkle_tree_size_lg}) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = hash_vv_bytes_i vv 0ul private let rec serialize_hash_vv_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vv hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let h0 = HST.get() in let ok, pos = serialize_hash_vec #hash_size ok vi buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; let j = i + 1ul in if j < V.size_of x then serialize_hash_vv_i #hash_size ok x buf sz pos j else (ok, pos) end private let serialize_hash_vv (#hash_size:hash_size_t) (ok:bool) (x:hash_vv hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if (V.size_of x > 0ul) then serialize_hash_vv_i ok x buf sz pos 0ul else (ok, pos) end private let deserialize_bool (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & bool) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, false) else (true, pos + 1ul, (match CB.index buf pos with| 0uy -> false | _ -> true)) private let deserialize_uint8_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint8_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0uy) else (true, pos + 1ul, CB.index buf pos)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ok: Prims.bool -> buf: MerkleTree.Low.Serialization.const_uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.ConstBuffer.length buf = FStar.UInt32.v sz} -> pos: MerkleTree.Low.Serialization.uint32_t -> FStar.HyperStack.ST.ST ((Prims.bool * MerkleTree.Low.Serialization.uint32_t) * MerkleTree.Low.Serialization.uint16_t)
FStar.HyperStack.ST.ST
[]
[]
[ "Prims.bool", "MerkleTree.Low.Serialization.const_uint8_p", "MerkleTree.Low.Serialization.uint32_t", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "LowStar.ConstBuffer.length", "MerkleTree.Low.Serialization.uint8_t", "FStar.UInt32.v", "Prims.op_BarBar", "Prims.op_Negation", "FStar.Integers.op_Greater_Equals", "FStar.Integers.Unsigned", "FStar.Integers.W32", "FStar.Pervasives.Native.Mktuple3", "MerkleTree.Low.Serialization.uint16_t", "FStar.UInt16.__uint_to_t", "FStar.Pervasives.Native.tuple3", "FStar.Integers.op_Plus", "FStar.Integers.W16", "FStar.UInt16.shift_left", "FStar.Int.Cast.uint8_to_uint16", "FStar.UInt32.__uint_to_t", "MerkleTree.Low.Serialization.deserialize_uint8_t", "FStar.Monotonic.HyperStack.mem", "LowStar.ConstBuffer.live", "Prims.eq2" ]
[]
false
true
false
false
false
let deserialize_uint16_t (ok: bool) (buf: const_uint8_p) (sz: uint32_t{CB.length buf = U32.v sz}) (pos: uint32_t) : HST.ST (bool & uint32_t & uint16_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) =
if not ok || pos >= sz then (false, pos, 0us) else let ok, pos, b0 = deserialize_uint8_t ok buf sz pos in let ok, pos, b1 = deserialize_uint8_t ok buf sz pos in (ok, pos, (U16.shift_left (Int.Cast.uint8_to_uint16 b0) 8ul) + Int.Cast.uint8_to_uint16 b1)
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.serialize_hash_vv
val serialize_hash_vv (#hash_size: hash_size_t) (ok: bool) (x: hash_vv hash_size) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1))
val serialize_hash_vv (#hash_size: hash_size_t) (ok: bool) (x: hash_vv hash_size) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1))
let serialize_hash_vv (#hash_size:hash_size_t) (ok:bool) (x:hash_vv hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if (V.size_of x > 0ul) then serialize_hash_vv_i ok x buf sz pos 0ul else (ok, pos) end
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 5, "end_line": 216, "start_col": 0, "start_line": 202 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" private let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end private let serialize_uint8_t (ok:bool) (x:uint8_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos x; (true, pos + 1ul) end private let serialize_uint16_t (ok:bool) (x:uint16_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint8_t ok (Int.Cast.uint16_to_uint8 (U16.shift_right x 8ul)) buf sz pos in serialize_uint8_t ok (Int.Cast.uint16_to_uint8 x) buf sz pos private let serialize_uint32_t (ok:bool) (x:uint32_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint16_t ok (Int.Cast.uint32_to_uint16 (U32.shift_right x 16ul)) buf sz pos in serialize_uint16_t ok (Int.Cast.uint32_to_uint16 x) buf sz pos private let serialize_uint64_t (ok:bool) (x:uint64_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint32_t ok (Int.Cast.uint64_to_uint32 (U64.shift_right x 32ul)) buf sz pos in serialize_uint32_t ok (Int.Cast.uint64_to_uint32 x) buf sz pos private let serialize_offset_t = serialize_uint64_t private let serialize_index_t = serialize_uint32_t private let rec serialize_hash_i (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < hash_size}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else let b = x.(i) in let ok, pos = serialize_uint8_t ok (Lib.RawIntTypes.u8_to_UInt8 b) buf sz pos in let j = i + 1ul in if j < hash_size then serialize_hash_i #hash_size ok x buf sz pos j else (ok, pos) private let serialize_hash (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else serialize_hash_i ok x buf sz pos 0ul private inline_for_extraction let u64_add_fits (x:uint64_t) (y:uint64_t): Tot (r:bool{r ==> UInt.size (U64.v x + U64.v y) 64}) = uint64_max - x >= y #push-options "--z3rlimit 100 --fuel 1 --quake 1/3" private inline_for_extraction let hash_vec_bytes (#hash_size:hash_size_t) (v:hash_vec #hash_size) : Tot uint64_t = let vs_hs = U64.mul (u32_64 (V.size_of v)) (u32_64 hash_size) in if u64_add_fits vs_hs 4UL then vs_hs + 4UL else uint64_max #pop-options private let rec serialize_hash_vec_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ loc_disjoint (B.loc_buffer buf) (loc_rvector x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let ok, pos = serialize_hash ok vi buf sz pos in let j = i + 1ul in if j < V.size_of x then serialize_hash_vec_i ok x buf sz pos j else (ok, pos) end private let serialize_hash_vec (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvreg hash_size) x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if ok && V.size_of x > 0ul then serialize_hash_vec_i ok x buf sz pos 0ul else (ok, pos) end private inline_for_extraction let rec hash_vv_bytes_i (#hash_size:hash_size_t) (vv:hash_vv hash_size) (i:uint32_t) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = if i >= V.size_of vv then 4UL else begin let vvi = V.index vv i in let r = hash_vec_bytes vvi in let rest = hash_vv_bytes_i vv (i+1ul) in if u64_add_fits r rest then begin assert (UInt.size (U64.v r + U64.v rest) 64); r + rest end else uint64_max end private inline_for_extraction let hash_vv_bytes (#hash_size:hash_size_t) (vv:hash_vv hash_size {V.size_of vv = merkle_tree_size_lg}) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = hash_vv_bytes_i vv 0ul private let rec serialize_hash_vv_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vv hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let h0 = HST.get() in let ok, pos = serialize_hash_vec #hash_size ok vi buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; let j = i + 1ul in if j < V.size_of x then serialize_hash_vv_i #hash_size ok x buf sz pos j else (ok, pos) end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ok: Prims.bool -> x: MerkleTree.Low.Datastructures.hash_vv hash_size -> buf: MerkleTree.Low.Serialization.uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.Monotonic.Buffer.len buf = sz} -> pos: MerkleTree.Low.Serialization.uint32_t -> FStar.HyperStack.ST.ST (Prims.bool * MerkleTree.Low.Serialization.uint32_t)
FStar.HyperStack.ST.ST
[]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "Prims.bool", "MerkleTree.Low.Datastructures.hash_vv", "MerkleTree.Low.Serialization.uint8_p", "MerkleTree.Low.Serialization.uint32_t", "Prims.b2t", "Prims.op_Equality", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.len", "MerkleTree.Low.Serialization.uint8_t", "LowStar.Buffer.trivial_preorder", "Prims.op_BarBar", "Prims.op_Negation", "FStar.Integers.op_Greater_Equals", "FStar.Integers.Unsigned", "FStar.Integers.W32", "FStar.Pervasives.Native.Mktuple2", "FStar.UInt32.__uint_to_t", "FStar.Pervasives.Native.tuple2", "FStar.Integers.op_Greater", "LowStar.Vector.size_of", "MerkleTree.Low.Datastructures.hash_vec", "MerkleTree.Low.Serialization.serialize_hash_vv_i", "Prims.unit", "LowStar.RVector.rv_inv_preserved", "MerkleTree.Low.Datastructures.hvreg", "LowStar.Monotonic.Buffer.loc_buffer", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "MerkleTree.Low.Serialization.serialize_uint32_t", "Prims.l_and", "LowStar.Monotonic.Buffer.live", "LowStar.RVector.rv_inv", "FStar.Monotonic.HyperHeap.disjoint", "LowStar.Monotonic.Buffer.frameOf", "LowStar.Regional.__proj__Rgl__item__region_of", "LowStar.Regional.regional", "MerkleTree.Low.Datastructures.hvvreg", "LowStar.Monotonic.Buffer.modifies" ]
[]
false
true
false
false
false
let serialize_hash_vv (#hash_size: hash_size_t) (ok: bool) (x: hash_vv hash_size) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) =
if not ok || pos >= sz then (false, 0ul) else let h0 = HST.get () in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get () in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if (V.size_of x > 0ul) then serialize_hash_vv_i ok x buf sz pos 0ul else (ok, pos)
false
Pulse.Checker.Prover.ElimPure.fst
Pulse.Checker.Prover.ElimPure.mk_elim_pure
val mk_elim_pure (p: term) : st_term
val mk_elim_pure (p: term) : st_term
let mk_elim_pure (p:term) : st_term = let t = Tm_STApp { head = elim_pure_head; arg_qual = None; arg = p } in wtag (Some STT_Ghost) t
{ "file_name": "lib/steel/pulse/Pulse.Checker.Prover.ElimPure.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 27, "end_line": 68, "start_col": 0, "start_line": 62 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Checker.Prover.ElimPure module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module L = FStar.List.Tot module T = FStar.Tactics.V2 open FStar.List.Tot open Pulse.Syntax open Pulse.Checker.Pure open Pulse.Checker.VPropEquiv open Pulse.Typing open Pulse.Typing.Combinators module Metatheory = Pulse.Typing.Metatheory open Pulse.Reflection.Util open Pulse.Checker.Prover.Base module RU = Pulse.RuntimeUtils let elim_pure_head = let elim_pure_explicit_lid = mk_pulse_lib_core_lid "elim_pure_explicit" in tm_fvar (as_fv elim_pure_explicit_lid) let elim_pure_head_ty = // let open Pulse.Steel.Wrapper in // let open Steel.Effect.Common in let squash_p = mk_squash u0 (RT.bound_var 0) in let pure_p = mk_pure (RT.bound_var 0) in let post = mk_abs squash_p R.Q_Explicit (R.pack_ln (R.Tv_FVar (R.pack_fv emp_lid))) in let cod = mk_stt_ghost_comp u0 squash_p pure_p post in mk_arrow (R.pack_ln (R.Tv_FVar (R.pack_fv R.prop_qn)), R.Q_Explicit) cod // Following crashes in extraction // `(p:prop -> stt_ghost (squash p) emp_inames // (pure p) // (fun _ -> emp)) let tm_fstar t = tm_fstar t Range.range_0 let elim_pure_head_typing (g:env) : tot_typing g elim_pure_head (tm_fstar elim_pure_head_ty) = admit()
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.Metatheory.fsti.checked", "Pulse.Typing.Combinators.fsti.checked", "Pulse.Typing.fst.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Checker.VPropEquiv.fsti.checked", "Pulse.Checker.Pure.fsti.checked", "Pulse.Checker.Prover.Base.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "Pulse.Checker.Prover.ElimPure.fst" }
[ { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Typing.Metatheory", "short_module": "Metatheory" }, { "abbrev": false, "full_module": "Pulse.Typing.Combinators", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.VPropEquiv", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Pure", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.st_term
Prims.Tot
[ "total" ]
[]
[ "Pulse.Syntax.Base.term", "Pulse.Typing.wtag", "FStar.Pervasives.Native.Some", "Pulse.Syntax.Base.ctag", "Pulse.Syntax.Base.STT_Ghost", "Pulse.Syntax.Base.st_term'", "Pulse.Syntax.Base.Tm_STApp", "Pulse.Syntax.Base.Mkst_term'__Tm_STApp__payload", "Pulse.Checker.Prover.ElimPure.elim_pure_head", "FStar.Pervasives.Native.None", "Pulse.Syntax.Base.qualifier", "Pulse.Syntax.Base.st_term" ]
[]
false
false
false
true
false
let mk_elim_pure (p: term) : st_term =
let t = Tm_STApp ({ head = elim_pure_head; arg_qual = None; arg = p }) in wtag (Some STT_Ghost) t
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.serialize_hash_vv_i
val serialize_hash_vv_i (#hash_size: hash_size_t) (ok: bool) (x: hash_vv hash_size) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) (i: uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1))
val serialize_hash_vv_i (#hash_size: hash_size_t) (ok: bool) (x: hash_vv hash_size) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) (i: uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1))
let rec serialize_hash_vv_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vv hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let h0 = HST.get() in let ok, pos = serialize_hash_vec #hash_size ok vi buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; let j = i + 1ul in if j < V.size_of x then serialize_hash_vv_i #hash_size ok x buf sz pos j else (ok, pos) end
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 5, "end_line": 199, "start_col": 0, "start_line": 182 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" private let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end private let serialize_uint8_t (ok:bool) (x:uint8_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos x; (true, pos + 1ul) end private let serialize_uint16_t (ok:bool) (x:uint16_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint8_t ok (Int.Cast.uint16_to_uint8 (U16.shift_right x 8ul)) buf sz pos in serialize_uint8_t ok (Int.Cast.uint16_to_uint8 x) buf sz pos private let serialize_uint32_t (ok:bool) (x:uint32_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint16_t ok (Int.Cast.uint32_to_uint16 (U32.shift_right x 16ul)) buf sz pos in serialize_uint16_t ok (Int.Cast.uint32_to_uint16 x) buf sz pos private let serialize_uint64_t (ok:bool) (x:uint64_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint32_t ok (Int.Cast.uint64_to_uint32 (U64.shift_right x 32ul)) buf sz pos in serialize_uint32_t ok (Int.Cast.uint64_to_uint32 x) buf sz pos private let serialize_offset_t = serialize_uint64_t private let serialize_index_t = serialize_uint32_t private let rec serialize_hash_i (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < hash_size}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else let b = x.(i) in let ok, pos = serialize_uint8_t ok (Lib.RawIntTypes.u8_to_UInt8 b) buf sz pos in let j = i + 1ul in if j < hash_size then serialize_hash_i #hash_size ok x buf sz pos j else (ok, pos) private let serialize_hash (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else serialize_hash_i ok x buf sz pos 0ul private inline_for_extraction let u64_add_fits (x:uint64_t) (y:uint64_t): Tot (r:bool{r ==> UInt.size (U64.v x + U64.v y) 64}) = uint64_max - x >= y #push-options "--z3rlimit 100 --fuel 1 --quake 1/3" private inline_for_extraction let hash_vec_bytes (#hash_size:hash_size_t) (v:hash_vec #hash_size) : Tot uint64_t = let vs_hs = U64.mul (u32_64 (V.size_of v)) (u32_64 hash_size) in if u64_add_fits vs_hs 4UL then vs_hs + 4UL else uint64_max #pop-options private let rec serialize_hash_vec_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ loc_disjoint (B.loc_buffer buf) (loc_rvector x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let ok, pos = serialize_hash ok vi buf sz pos in let j = i + 1ul in if j < V.size_of x then serialize_hash_vec_i ok x buf sz pos j else (ok, pos) end private let serialize_hash_vec (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvreg hash_size) x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if ok && V.size_of x > 0ul then serialize_hash_vec_i ok x buf sz pos 0ul else (ok, pos) end private inline_for_extraction let rec hash_vv_bytes_i (#hash_size:hash_size_t) (vv:hash_vv hash_size) (i:uint32_t) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = if i >= V.size_of vv then 4UL else begin let vvi = V.index vv i in let r = hash_vec_bytes vvi in let rest = hash_vv_bytes_i vv (i+1ul) in if u64_add_fits r rest then begin assert (UInt.size (U64.v r + U64.v rest) 64); r + rest end else uint64_max end private inline_for_extraction let hash_vv_bytes (#hash_size:hash_size_t) (vv:hash_vv hash_size {V.size_of vv = merkle_tree_size_lg}) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = hash_vv_bytes_i vv 0ul
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ok: Prims.bool -> x: MerkleTree.Low.Datastructures.hash_vv hash_size -> buf: MerkleTree.Low.Serialization.uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.Monotonic.Buffer.len buf = sz} -> pos: MerkleTree.Low.Serialization.uint32_t -> i: MerkleTree.Low.Serialization.uint32_t{i < LowStar.Vector.size_of x} -> FStar.HyperStack.ST.ST (Prims.bool * MerkleTree.Low.Serialization.uint32_t)
FStar.HyperStack.ST.ST
[]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "Prims.bool", "MerkleTree.Low.Datastructures.hash_vv", "MerkleTree.Low.Serialization.uint8_p", "MerkleTree.Low.Serialization.uint32_t", "Prims.b2t", "Prims.op_Equality", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.len", "MerkleTree.Low.Serialization.uint8_t", "LowStar.Buffer.trivial_preorder", "FStar.Integers.op_Less", "FStar.Integers.Unsigned", "FStar.Integers.W32", "LowStar.Vector.size_of", "MerkleTree.Low.Datastructures.hash_vec", "Prims.op_BarBar", "Prims.op_Negation", "FStar.Integers.op_Greater_Equals", "FStar.Pervasives.Native.Mktuple2", "FStar.UInt32.__uint_to_t", "FStar.Pervasives.Native.tuple2", "MerkleTree.Low.Serialization.serialize_hash_vv_i", "FStar.Integers.int_t", "FStar.Integers.op_Plus", "Prims.unit", "LowStar.RVector.rv_inv_preserved", "MerkleTree.Low.Datastructures.hvreg", "LowStar.Monotonic.Buffer.loc_buffer", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "MerkleTree.Low.Serialization.serialize_hash_vec", "LowStar.Vector.index", "Prims.l_and", "LowStar.Monotonic.Buffer.live", "LowStar.RVector.rv_inv", "FStar.Monotonic.HyperHeap.disjoint", "LowStar.Monotonic.Buffer.frameOf", "LowStar.Regional.__proj__Rgl__item__region_of", "LowStar.Regional.regional", "MerkleTree.Low.Datastructures.hvvreg", "LowStar.Monotonic.Buffer.modifies" ]
[ "recursion" ]
false
true
false
false
false
let rec serialize_hash_vv_i (#hash_size: hash_size_t) (ok: bool) (x: hash_vv hash_size) (buf: uint8_p) (sz: uint32_t{B.len buf = sz}) (pos: uint32_t) (i: uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) =
if not ok || pos >= sz then (false, 0ul) else let vi = V.index x i in let h0 = HST.get () in let ok, pos = serialize_hash_vec #hash_size ok vi buf sz pos in let h1 = HST.get () in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; let j = i + 1ul in if j < V.size_of x then serialize_hash_vv_i #hash_size ok x buf sz pos j else (ok, pos)
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.mt_serialize_path
val mt_serialize_path: #hsz:Ghost.erased hash_size_t -> p:const_path_p -> output:uint8_p -> sz:uint64_t -> HST.ST uint64_t (requires (fun h0 -> let ncp = CB.cast p in let phv = B.get h0 ncp 0 in Path?.hash_size phv = Ghost.reveal hsz /\ path_safe h0 (B.frameOf (CB.cast p)) ncp /\ RV.rv_inv #(hash #hsz) #hash_size_t #(hreg hsz) h0 (Path?.hashes phv) /\ B.live h0 output /\ B.length output = U64.v sz /\ HS.disjoint (B.frameOf output) (B.frameOf ncp))) (ensures (fun h0 _ h1 -> path_safe h1 (B.frameOf (CB.cast p)) (CB.cast p) /\ modifies (B.loc_buffer output) h0 h1))
val mt_serialize_path: #hsz:Ghost.erased hash_size_t -> p:const_path_p -> output:uint8_p -> sz:uint64_t -> HST.ST uint64_t (requires (fun h0 -> let ncp = CB.cast p in let phv = B.get h0 ncp 0 in Path?.hash_size phv = Ghost.reveal hsz /\ path_safe h0 (B.frameOf (CB.cast p)) ncp /\ RV.rv_inv #(hash #hsz) #hash_size_t #(hreg hsz) h0 (Path?.hashes phv) /\ B.live h0 output /\ B.length output = U64.v sz /\ HS.disjoint (B.frameOf output) (B.frameOf ncp))) (ensures (fun h0 _ h1 -> path_safe h1 (B.frameOf (CB.cast p)) (CB.cast p) /\ modifies (B.loc_buffer output) h0 h1))
let mt_serialize_path #hsz p output sz = let hsz = Path?.hash_size !*(CB.cast p) in let sz = FStar.Int.Cast.uint64_to_uint32 sz in let ncp = CB.cast p in let h0 = HST.get() in let ok, pos = serialize_uint32_t true hsz output sz 0ul in let h1 = HST.get() in let ncpd = !*ncp in let ok, pos = serialize_hash_vec #hsz ok (Path?.hashes ncpd) output sz pos in if ok then (FStar.Int.Cast.uint32_to_uint64 pos) else 0UL
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 59, "end_line": 503, "start_col": 0, "start_line": 494 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" private let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end private let serialize_uint8_t (ok:bool) (x:uint8_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos x; (true, pos + 1ul) end private let serialize_uint16_t (ok:bool) (x:uint16_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint8_t ok (Int.Cast.uint16_to_uint8 (U16.shift_right x 8ul)) buf sz pos in serialize_uint8_t ok (Int.Cast.uint16_to_uint8 x) buf sz pos private let serialize_uint32_t (ok:bool) (x:uint32_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint16_t ok (Int.Cast.uint32_to_uint16 (U32.shift_right x 16ul)) buf sz pos in serialize_uint16_t ok (Int.Cast.uint32_to_uint16 x) buf sz pos private let serialize_uint64_t (ok:bool) (x:uint64_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint32_t ok (Int.Cast.uint64_to_uint32 (U64.shift_right x 32ul)) buf sz pos in serialize_uint32_t ok (Int.Cast.uint64_to_uint32 x) buf sz pos private let serialize_offset_t = serialize_uint64_t private let serialize_index_t = serialize_uint32_t private let rec serialize_hash_i (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < hash_size}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else let b = x.(i) in let ok, pos = serialize_uint8_t ok (Lib.RawIntTypes.u8_to_UInt8 b) buf sz pos in let j = i + 1ul in if j < hash_size then serialize_hash_i #hash_size ok x buf sz pos j else (ok, pos) private let serialize_hash (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else serialize_hash_i ok x buf sz pos 0ul private inline_for_extraction let u64_add_fits (x:uint64_t) (y:uint64_t): Tot (r:bool{r ==> UInt.size (U64.v x + U64.v y) 64}) = uint64_max - x >= y #push-options "--z3rlimit 100 --fuel 1 --quake 1/3" private inline_for_extraction let hash_vec_bytes (#hash_size:hash_size_t) (v:hash_vec #hash_size) : Tot uint64_t = let vs_hs = U64.mul (u32_64 (V.size_of v)) (u32_64 hash_size) in if u64_add_fits vs_hs 4UL then vs_hs + 4UL else uint64_max #pop-options private let rec serialize_hash_vec_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ loc_disjoint (B.loc_buffer buf) (loc_rvector x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let ok, pos = serialize_hash ok vi buf sz pos in let j = i + 1ul in if j < V.size_of x then serialize_hash_vec_i ok x buf sz pos j else (ok, pos) end private let serialize_hash_vec (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvreg hash_size) x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if ok && V.size_of x > 0ul then serialize_hash_vec_i ok x buf sz pos 0ul else (ok, pos) end private inline_for_extraction let rec hash_vv_bytes_i (#hash_size:hash_size_t) (vv:hash_vv hash_size) (i:uint32_t) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = if i >= V.size_of vv then 4UL else begin let vvi = V.index vv i in let r = hash_vec_bytes vvi in let rest = hash_vv_bytes_i vv (i+1ul) in if u64_add_fits r rest then begin assert (UInt.size (U64.v r + U64.v rest) 64); r + rest end else uint64_max end private inline_for_extraction let hash_vv_bytes (#hash_size:hash_size_t) (vv:hash_vv hash_size {V.size_of vv = merkle_tree_size_lg}) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = hash_vv_bytes_i vv 0ul private let rec serialize_hash_vv_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vv hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let h0 = HST.get() in let ok, pos = serialize_hash_vec #hash_size ok vi buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; let j = i + 1ul in if j < V.size_of x then serialize_hash_vv_i #hash_size ok x buf sz pos j else (ok, pos) end private let serialize_hash_vv (#hash_size:hash_size_t) (ok:bool) (x:hash_vv hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if (V.size_of x > 0ul) then serialize_hash_vv_i ok x buf sz pos 0ul else (ok, pos) end private let deserialize_bool (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & bool) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, false) else (true, pos + 1ul, (match CB.index buf pos with| 0uy -> false | _ -> true)) private let deserialize_uint8_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint8_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0uy) else (true, pos + 1ul, CB.index buf pos) private let deserialize_uint16_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint16_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0us) else begin let ok, pos, b0 = deserialize_uint8_t ok buf sz pos in let ok, pos, b1 = deserialize_uint8_t ok buf sz pos in (ok, pos, (U16.shift_left (Int.Cast.uint8_to_uint16 b0) 8ul) + Int.Cast.uint8_to_uint16 b1) end private let deserialize_uint32_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint32_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0ul) else begin let ok, pos, b0 = deserialize_uint16_t ok buf sz pos in let ok, pos, b1 = deserialize_uint16_t ok buf sz pos in (ok, pos, (U32.shift_left (Int.Cast.uint16_to_uint32 b0) 16ul) + Int.Cast.uint16_to_uint32 b1) end private let deserialize_uint64_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint64_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0UL) else begin let ok, pos, b0 = deserialize_uint32_t ok buf sz pos in let ok, pos, b1 = deserialize_uint32_t ok buf sz pos in (ok, pos, (U64.shift_left (u32_64 b0) 32ul) + u32_64 b1) end private let deserialize_offset_t = deserialize_uint64_t private let deserialize_index_t = deserialize_uint32_t private let deserialize_hash (#hash_size:hash_size_t) (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (r:HST.erid) (pos:uint32_t) : HST.ST (bool & uint32_t & hash #hash_size) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 (k, _, h) h1 -> (k ==> Rgl?.r_inv (hreg hash_size) h1 h) /\ loc_disjoint (loc_buffer (CB.cast buf)) (loc_buffer h) /\ modifies B.loc_none h0 h1)) = let rg = hreg hash_size in if not ok || pos >= sz then (false, pos, rg_dummy rg) else if sz - pos < hash_size then (false, pos, rg_dummy rg) else begin let hash = rg_alloc rg r in Lib.RawBuffer.blit (CB.cast buf) pos hash 0ul hash_size; (true, pos + hash_size, hash) end private let rec deserialize_hash_vec_i (#hash_size:hash_size_t) (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (r:HST.erid) (pos:uint32_t) (res:hash_vec #hash_size) (i:uint32_t{i < V.size_of res}) : HST.ST (bool & uint32_t) (requires (fun h0 -> CB.live h0 buf /\ V.live h0 res)) (ensures (fun h0 _ h1 -> B.modifies (B.loc_buffer (V.Vec?.vs res)) h0 h1)) = if not ok || pos >= sz then (false, pos) else begin let ok, pos, h = deserialize_hash ok buf sz r pos in if not ok then (false, pos) else begin V.assign res i h; (* * AR: 04/01: The call deserialize_hash_vec_i below needs liveness of buf * So we have to frame buf liveness for the V.assign call * V.assign provides a modifies postcondition in terms of * loc_vector_within, which is a recursive predicate and * I guess hard to reason about directly * Whereas to reason about liveness of buf, we only need an * overapproximation that V.assign modifies V.Vec?.vs res * Looking at the Vector library, I found the following lemma * that does the trick *) V.loc_vector_within_included res i (i + 1ul); let j = i + 1ul in if j < V.size_of res then deserialize_hash_vec_i ok buf sz r pos res j else (true, pos) end end private let deserialize_hash_vec (#hash_size:hash_size_t) (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (r:HST.erid) (pos:uint32_t) : HST.ST (bool & uint32_t & hash_vec #hash_size) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> B.modifies B.loc_none h0 h1)) = let rg = hvreg hash_size in if not ok || pos >= sz then (false, pos, rg_dummy rg) else begin let ok, pos, n = deserialize_uint32_t ok buf sz pos in if not ok then (false, pos, V.alloc_empty hash) else if n = 0ul then (true, pos, V.alloc_empty hash) else begin let hrg = hreg hash_size in let res = V.alloc n (rg_dummy hrg) in let ok, pos = deserialize_hash_vec_i ok buf sz r pos res 0ul in (ok, pos, res) end end private let rec deserialize_hash_vv_i (#hash_size:hash_size_t) (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (r:HST.erid) (pos:uint32_t) (res:hash_vv hash_size) (i:uint32_t{i < V.size_of res}) : HST.ST (bool & uint32_t) (requires (fun h0 -> CB.live h0 buf /\ V.live h0 res /\ B.loc_disjoint (CB.loc_buffer buf) (V.loc_vector res))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer (V.Vec?.vs res)) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let ok, pos, hv = deserialize_hash_vec ok buf sz r pos in let h0 = HST.get() in if not ok then (false, pos) else begin V.assign res i hv; (* * AR: 04/01: The call deserialize_hash_vv_i below needs liveness of buf * So we have to frame buf liveness for the V.assign call * V.assign provides a modifies postcondition in terms of * loc_vector_within, which is a recursive predicate and * I guess hard to reason about directly * Whereas to reason about liveness of buf, we only need an * overapproximation that V.assign modifies V.Vec?.vs res * Looking at the Vector library, I found the following lemma * that does the trick *) V.loc_vector_within_included res i (i + 1ul); let j = i + 1ul in if j = V.size_of res then (true, pos) else deserialize_hash_vv_i ok buf sz r pos res j end end private let deserialize_hash_vv (#hash_size:hash_size_t) (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (r:HST.erid) (pos:uint32_t) : HST.ST (bool & uint32_t & hash_vv hash_size) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> modifies B.loc_none h0 h1)) = if not ok || pos >= sz then (false, pos, V.alloc_empty hash_vec) else begin let ok, pos, n = deserialize_uint32_t ok buf sz pos in if not ok then (false, pos, V.alloc_empty hash_vec) else if n = 0ul then (true, pos, V.alloc_empty hash_vec) else begin let rg = hvreg hash_size in let res = V.alloc n (rg_dummy rg) in let ok, pos = deserialize_hash_vv_i ok buf sz r pos res 0ul in (ok, pos, res) end end #push-options "--z3rlimit 10" val mt_serialize_size: mt:const_mt_p -> HST.ST uint64_t (requires (fun h0 -> mt_safe h0 (CB.cast mt))) (ensures (fun _ _ h1 -> mt_safe h1 (CB.cast mt))) let mt_serialize_size mt = let mtv = !*(CB.cast mt) in let hs = MT?.hs mtv in let rhs_ok = MT?.rhs_ok mtv in let rhs = MT?.rhs mtv in let hs_sz = hash_vv_bytes hs in if hs_sz < uint32_max then 1UL + // format version 4UL + // hash_size 8UL + // offset 4UL + 4UL + // i, j hs_sz + // hs 1UL + // rhs_ok hash_vec_bytes rhs + // rhs u32_64 (MT?.hash_size mtv) // mroot else uint64_max #pop-options #push-options "--z3rlimit 15 --initial_fuel 1 --max_fuel 1" val mt_serialize: mt:const_mt_p -> output:uint8_p -> sz:uint64_t -> HST.ST uint64_t (requires (fun h0 -> mt_safe h0 (CB.cast mt) /\ B.live h0 output /\ B.length output = U64.v sz /\ HS.disjoint (B.frameOf output) (B.frameOf (CB.cast mt)))) (ensures (fun h0 _ h1 -> mt_safe h1 (CB.cast mt) /\ modifies (B.loc_buffer output) h0 h1)) let mt_serialize mt output sz = let mt = CB.cast mt in let sz = FStar.Int.Cast.uint64_to_uint32 sz in let mtv = !*mt in let h0 = HST.get() in let ok, pos = serialize_uint8_t true 1uy output sz 0ul in // format version = 1uy let h1 = HST.get() in mt_safe_preserved mt (B.loc_buffer output) h0 h1; let ok, pos = serialize_uint32_t ok (MT?.hash_size mtv) output sz pos in let h2 = HST.get() in mt_safe_preserved mt (B.loc_buffer output) h1 h2; let ok, pos = serialize_offset_t ok (MT?.offset mtv) output sz pos in let h3 = HST.get() in mt_safe_preserved mt (B.loc_buffer output) h2 h3; let ok, pos = serialize_uint32_t ok (MT?.i mtv) output sz pos in let h4 = HST.get() in mt_safe_preserved mt (B.loc_buffer output) h3 h4; let ok, pos = serialize_uint32_t ok (MT?.j mtv) output sz pos in let h5 = HST.get() in mt_safe_preserved mt (B.loc_buffer output) h4 h5; let ok, pos = serialize_hash_vv ok (MT?.hs mtv) output sz pos in let h6 = HST.get() in mt_safe_preserved mt (B.loc_buffer output) h5 h6; let ok, pos = serialize_bool ok (MT?.rhs_ok mtv) output sz pos in let h7 = HST.get() in mt_safe_preserved mt (B.loc_buffer output) h6 h7; let ok, pos = serialize_hash_vec ok (MT?.rhs mtv) output sz pos in let h8 = HST.get() in mt_safe_preserved mt (B.loc_buffer output) h7 h8; let ok, pos = serialize_hash ok (MT?.mroot mtv) output sz pos in let h9 = HST.get() in mt_safe_preserved mt (B.loc_buffer output) h8 h9; if ok then (FStar.Int.Cast.uint32_to_uint64 pos) else 0UL #pop-options #push-options "--z3rlimit 15 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1" val mt_deserialize: #hsz:Ghost.erased hash_size_t -> rid:HST.erid -> input:const_uint8_p -> sz:uint64_t{CB.length input = U64.v sz} -> hash_spec:Ghost.erased(MTS.hash_fun_t #(U32.v (Ghost.reveal hsz))) -> hash_fun:hash_fun_t #(Ghost.reveal hsz) #hash_spec -> HST.ST (B.pointer_or_null merkle_tree) (requires (fun h0 -> CB.live h0 input /\ HS.disjoint rid (B.frameOf (CB.cast input)))) (ensures (fun h0 r h1 -> modifies B.loc_none h0 h1 /\ (not (g_is_null r)) ==> MT?.hash_size (B.get h1 r 0) = Ghost.reveal hsz)) let mt_deserialize #ghsz rid input sz hash_spec hash_fun = let sz = FStar.Int.Cast.uint64_to_uint32 sz in let hrid = HST.new_region rid in let hvrid = HST.new_region rid in let hvvrid = HST.new_region rid in let ok, pos, format_version = deserialize_uint8_t true input sz 0ul in let ok = ok && format_version = 1uy in let ok, pos, hsz = deserialize_uint32_t ok input sz pos in if hsz = 0ul then B.null #merkle_tree else begin let ok, pos, offset = deserialize_offset_t ok input sz pos in let ok, pos, i = deserialize_index_t ok input sz pos in let ok, pos, j = deserialize_index_t ok input sz pos in let ok, pos, hs = deserialize_hash_vv #hsz ok input sz hvvrid pos in let ok, pos, rhs_ok = deserialize_bool ok input sz pos in let ok, pos, rhs = deserialize_hash_vec #hsz ok input sz hvrid pos in let ok, pos, mroot = deserialize_hash #hsz ok input sz hrid pos in begin if not ok || not (merkle_tree_conditions #hsz offset i j hs rhs_ok rhs mroot) then B.null #merkle_tree else begin assume (hsz = Ghost.reveal ghsz); // We trust the user to provide a suitable hash_fun. B.malloc rid (MT hsz offset i j hs rhs_ok rhs mroot hash_spec hash_fun) 1ul end end end val mt_serialize_path: #hsz:Ghost.erased hash_size_t -> p:const_path_p -> output:uint8_p -> sz:uint64_t -> HST.ST uint64_t (requires (fun h0 -> let ncp = CB.cast p in let phv = B.get h0 ncp 0 in Path?.hash_size phv = Ghost.reveal hsz /\ path_safe h0 (B.frameOf (CB.cast p)) ncp /\ RV.rv_inv #(hash #hsz) #hash_size_t #(hreg hsz) h0 (Path?.hashes phv) /\ B.live h0 output /\ B.length output = U64.v sz /\ HS.disjoint (B.frameOf output) (B.frameOf ncp))) (ensures (fun h0 _ h1 -> path_safe h1 (B.frameOf (CB.cast p)) (CB.cast p) /\
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: MerkleTree.Low.const_path_p -> output: MerkleTree.Low.Serialization.uint8_p -> sz: MerkleTree.Low.Serialization.uint64_t -> FStar.HyperStack.ST.ST MerkleTree.Low.Serialization.uint64_t
FStar.HyperStack.ST.ST
[]
[]
[ "FStar.Ghost.erased", "MerkleTree.Low.Datastructures.hash_size_t", "MerkleTree.Low.const_path_p", "MerkleTree.Low.Serialization.uint8_p", "MerkleTree.Low.Serialization.uint64_t", "Prims.bool", "MerkleTree.Low.Serialization.uint32_t", "FStar.Int.Cast.uint32_to_uint64", "FStar.UInt64.__uint_to_t", "FStar.Pervasives.Native.tuple2", "MerkleTree.Low.Serialization.serialize_hash_vec", "MerkleTree.Low.__proj__Path__item__hashes", "MerkleTree.Low.path", "LowStar.BufferOps.op_Bang_Star", "LowStar.ConstBuffer.qbuf_pre", "LowStar.ConstBuffer.as_qbuf", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "MerkleTree.Low.Serialization.serialize_uint32_t", "FStar.UInt32.__uint_to_t", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.ConstBuffer.cast", "FStar.UInt32.t", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.UInt32.v", "Prims.op_Modulus", "FStar.UInt64.v", "Prims.pow2", "FStar.Int.Cast.uint64_to_uint32", "MerkleTree.Low.__proj__Path__item__hash_size" ]
[]
false
true
false
false
false
let mt_serialize_path #hsz p output sz =
let hsz = Path?.hash_size !*(CB.cast p) in let sz = FStar.Int.Cast.uint64_to_uint32 sz in let ncp = CB.cast p in let h0 = HST.get () in let ok, pos = serialize_uint32_t true hsz output sz 0ul in let h1 = HST.get () in let ncpd = !*ncp in let ok, pos = serialize_hash_vec #hsz ok (Path?.hashes ncpd) output sz pos in if ok then (FStar.Int.Cast.uint32_to_uint64 pos) else 0uL
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.deserialize_hash_vec_i
val deserialize_hash_vec_i (#hash_size: hash_size_t) (ok: bool) (buf: const_uint8_p) (sz: uint32_t{CB.length buf = U32.v sz}) (r: HST.erid) (pos: uint32_t) (res: hash_vec #hash_size) (i: uint32_t{i < V.size_of res}) : HST.ST (bool & uint32_t) (requires (fun h0 -> CB.live h0 buf /\ V.live h0 res)) (ensures (fun h0 _ h1 -> B.modifies (B.loc_buffer (V.Vec?.vs res)) h0 h1))
val deserialize_hash_vec_i (#hash_size: hash_size_t) (ok: bool) (buf: const_uint8_p) (sz: uint32_t{CB.length buf = U32.v sz}) (r: HST.erid) (pos: uint32_t) (res: hash_vec #hash_size) (i: uint32_t{i < V.size_of res}) : HST.ST (bool & uint32_t) (requires (fun h0 -> CB.live h0 buf /\ V.live h0 res)) (ensures (fun h0 _ h1 -> B.modifies (B.loc_buffer (V.Vec?.vs res)) h0 h1))
let rec deserialize_hash_vec_i (#hash_size:hash_size_t) (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (r:HST.erid) (pos:uint32_t) (res:hash_vec #hash_size) (i:uint32_t{i < V.size_of res}) : HST.ST (bool & uint32_t) (requires (fun h0 -> CB.live h0 buf /\ V.live h0 res)) (ensures (fun h0 _ h1 -> B.modifies (B.loc_buffer (V.Vec?.vs res)) h0 h1)) = if not ok || pos >= sz then (false, pos) else begin let ok, pos, h = deserialize_hash ok buf sz r pos in if not ok then (false, pos) else begin V.assign res i h; (* * AR: 04/01: The call deserialize_hash_vec_i below needs liveness of buf * So we have to frame buf liveness for the V.assign call * V.assign provides a modifies postcondition in terms of * loc_vector_within, which is a recursive predicate and * I guess hard to reason about directly * Whereas to reason about liveness of buf, we only need an * overapproximation that V.assign modifies V.Vec?.vs res * Looking at the Vector library, I found the following lemma * that does the trick *) V.loc_vector_within_included res i (i + 1ul); let j = i + 1ul in if j < V.size_of res then deserialize_hash_vec_i ok buf sz r pos res j else (true, pos) end end
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 5, "end_line": 315, "start_col": 0, "start_line": 287 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" private let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end private let serialize_uint8_t (ok:bool) (x:uint8_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos x; (true, pos + 1ul) end private let serialize_uint16_t (ok:bool) (x:uint16_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint8_t ok (Int.Cast.uint16_to_uint8 (U16.shift_right x 8ul)) buf sz pos in serialize_uint8_t ok (Int.Cast.uint16_to_uint8 x) buf sz pos private let serialize_uint32_t (ok:bool) (x:uint32_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint16_t ok (Int.Cast.uint32_to_uint16 (U32.shift_right x 16ul)) buf sz pos in serialize_uint16_t ok (Int.Cast.uint32_to_uint16 x) buf sz pos private let serialize_uint64_t (ok:bool) (x:uint64_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint32_t ok (Int.Cast.uint64_to_uint32 (U64.shift_right x 32ul)) buf sz pos in serialize_uint32_t ok (Int.Cast.uint64_to_uint32 x) buf sz pos private let serialize_offset_t = serialize_uint64_t private let serialize_index_t = serialize_uint32_t private let rec serialize_hash_i (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < hash_size}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else let b = x.(i) in let ok, pos = serialize_uint8_t ok (Lib.RawIntTypes.u8_to_UInt8 b) buf sz pos in let j = i + 1ul in if j < hash_size then serialize_hash_i #hash_size ok x buf sz pos j else (ok, pos) private let serialize_hash (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else serialize_hash_i ok x buf sz pos 0ul private inline_for_extraction let u64_add_fits (x:uint64_t) (y:uint64_t): Tot (r:bool{r ==> UInt.size (U64.v x + U64.v y) 64}) = uint64_max - x >= y #push-options "--z3rlimit 100 --fuel 1 --quake 1/3" private inline_for_extraction let hash_vec_bytes (#hash_size:hash_size_t) (v:hash_vec #hash_size) : Tot uint64_t = let vs_hs = U64.mul (u32_64 (V.size_of v)) (u32_64 hash_size) in if u64_add_fits vs_hs 4UL then vs_hs + 4UL else uint64_max #pop-options private let rec serialize_hash_vec_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ loc_disjoint (B.loc_buffer buf) (loc_rvector x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let ok, pos = serialize_hash ok vi buf sz pos in let j = i + 1ul in if j < V.size_of x then serialize_hash_vec_i ok x buf sz pos j else (ok, pos) end private let serialize_hash_vec (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvreg hash_size) x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if ok && V.size_of x > 0ul then serialize_hash_vec_i ok x buf sz pos 0ul else (ok, pos) end private inline_for_extraction let rec hash_vv_bytes_i (#hash_size:hash_size_t) (vv:hash_vv hash_size) (i:uint32_t) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = if i >= V.size_of vv then 4UL else begin let vvi = V.index vv i in let r = hash_vec_bytes vvi in let rest = hash_vv_bytes_i vv (i+1ul) in if u64_add_fits r rest then begin assert (UInt.size (U64.v r + U64.v rest) 64); r + rest end else uint64_max end private inline_for_extraction let hash_vv_bytes (#hash_size:hash_size_t) (vv:hash_vv hash_size {V.size_of vv = merkle_tree_size_lg}) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = hash_vv_bytes_i vv 0ul private let rec serialize_hash_vv_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vv hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let h0 = HST.get() in let ok, pos = serialize_hash_vec #hash_size ok vi buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; let j = i + 1ul in if j < V.size_of x then serialize_hash_vv_i #hash_size ok x buf sz pos j else (ok, pos) end private let serialize_hash_vv (#hash_size:hash_size_t) (ok:bool) (x:hash_vv hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if (V.size_of x > 0ul) then serialize_hash_vv_i ok x buf sz pos 0ul else (ok, pos) end private let deserialize_bool (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & bool) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, false) else (true, pos + 1ul, (match CB.index buf pos with| 0uy -> false | _ -> true)) private let deserialize_uint8_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint8_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0uy) else (true, pos + 1ul, CB.index buf pos) private let deserialize_uint16_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint16_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0us) else begin let ok, pos, b0 = deserialize_uint8_t ok buf sz pos in let ok, pos, b1 = deserialize_uint8_t ok buf sz pos in (ok, pos, (U16.shift_left (Int.Cast.uint8_to_uint16 b0) 8ul) + Int.Cast.uint8_to_uint16 b1) end private let deserialize_uint32_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint32_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0ul) else begin let ok, pos, b0 = deserialize_uint16_t ok buf sz pos in let ok, pos, b1 = deserialize_uint16_t ok buf sz pos in (ok, pos, (U32.shift_left (Int.Cast.uint16_to_uint32 b0) 16ul) + Int.Cast.uint16_to_uint32 b1) end private let deserialize_uint64_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint64_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0UL) else begin let ok, pos, b0 = deserialize_uint32_t ok buf sz pos in let ok, pos, b1 = deserialize_uint32_t ok buf sz pos in (ok, pos, (U64.shift_left (u32_64 b0) 32ul) + u32_64 b1) end private let deserialize_offset_t = deserialize_uint64_t private let deserialize_index_t = deserialize_uint32_t private let deserialize_hash (#hash_size:hash_size_t) (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (r:HST.erid) (pos:uint32_t) : HST.ST (bool & uint32_t & hash #hash_size) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 (k, _, h) h1 -> (k ==> Rgl?.r_inv (hreg hash_size) h1 h) /\ loc_disjoint (loc_buffer (CB.cast buf)) (loc_buffer h) /\ modifies B.loc_none h0 h1)) = let rg = hreg hash_size in if not ok || pos >= sz then (false, pos, rg_dummy rg) else if sz - pos < hash_size then (false, pos, rg_dummy rg) else begin let hash = rg_alloc rg r in Lib.RawBuffer.blit (CB.cast buf) pos hash 0ul hash_size; (true, pos + hash_size, hash) end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ok: Prims.bool -> buf: MerkleTree.Low.Serialization.const_uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.ConstBuffer.length buf = FStar.UInt32.v sz} -> r: FStar.HyperStack.ST.erid -> pos: MerkleTree.Low.Serialization.uint32_t -> res: MerkleTree.Low.Datastructures.hash_vec -> i: MerkleTree.Low.Serialization.uint32_t{i < LowStar.Vector.size_of res} -> FStar.HyperStack.ST.ST (Prims.bool * MerkleTree.Low.Serialization.uint32_t)
FStar.HyperStack.ST.ST
[]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "Prims.bool", "MerkleTree.Low.Serialization.const_uint8_p", "MerkleTree.Low.Serialization.uint32_t", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "LowStar.ConstBuffer.length", "MerkleTree.Low.Serialization.uint8_t", "FStar.UInt32.v", "FStar.HyperStack.ST.erid", "MerkleTree.Low.Datastructures.hash_vec", "FStar.Integers.op_Less", "FStar.Integers.Unsigned", "FStar.Integers.W32", "LowStar.Vector.size_of", "MerkleTree.Low.Datastructures.hash", "Prims.op_BarBar", "Prims.op_Negation", "FStar.Integers.op_Greater_Equals", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple2", "MerkleTree.Low.Serialization.deserialize_hash_vec_i", "FStar.Integers.int_t", "FStar.Integers.op_Plus", "FStar.UInt32.__uint_to_t", "Prims.unit", "LowStar.Vector.loc_vector_within_included", "LowStar.Vector.assign", "FStar.Pervasives.Native.tuple3", "MerkleTree.Low.Serialization.deserialize_hash", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "LowStar.ConstBuffer.live", "LowStar.Vector.live", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Buffer.trivial_preorder", "LowStar.Vector.__proj__Vec__item__vs" ]
[ "recursion" ]
false
true
false
false
false
let rec deserialize_hash_vec_i (#hash_size: hash_size_t) (ok: bool) (buf: const_uint8_p) (sz: uint32_t{CB.length buf = U32.v sz}) (r: HST.erid) (pos: uint32_t) (res: hash_vec #hash_size) (i: uint32_t{i < V.size_of res}) : HST.ST (bool & uint32_t) (requires (fun h0 -> CB.live h0 buf /\ V.live h0 res)) (ensures (fun h0 _ h1 -> B.modifies (B.loc_buffer (V.Vec?.vs res)) h0 h1)) =
if not ok || pos >= sz then (false, pos) else let ok, pos, h = deserialize_hash ok buf sz r pos in if not ok then (false, pos) else (V.assign res i h; V.loc_vector_within_included res i (i + 1ul); let j = i + 1ul in if j < V.size_of res then deserialize_hash_vec_i ok buf sz r pos res j else (true, pos))
false
Pulse.Checker.Prover.ElimPure.fst
Pulse.Checker.Prover.ElimPure.is_elim_pure
val is_elim_pure (vp: term) : T.Tac bool
val is_elim_pure (vp: term) : T.Tac bool
let is_elim_pure (vp:term) : T.Tac bool = match vp.t with | Tm_Pure {t=Tm_FStar _} -> true | _ -> false
{ "file_name": "lib/steel/pulse/Pulse.Checker.Prover.ElimPure.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 14, "end_line": 90, "start_col": 0, "start_line": 87 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Checker.Prover.ElimPure module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module L = FStar.List.Tot module T = FStar.Tactics.V2 open FStar.List.Tot open Pulse.Syntax open Pulse.Checker.Pure open Pulse.Checker.VPropEquiv open Pulse.Typing open Pulse.Typing.Combinators module Metatheory = Pulse.Typing.Metatheory open Pulse.Reflection.Util open Pulse.Checker.Prover.Base module RU = Pulse.RuntimeUtils let elim_pure_head = let elim_pure_explicit_lid = mk_pulse_lib_core_lid "elim_pure_explicit" in tm_fvar (as_fv elim_pure_explicit_lid) let elim_pure_head_ty = // let open Pulse.Steel.Wrapper in // let open Steel.Effect.Common in let squash_p = mk_squash u0 (RT.bound_var 0) in let pure_p = mk_pure (RT.bound_var 0) in let post = mk_abs squash_p R.Q_Explicit (R.pack_ln (R.Tv_FVar (R.pack_fv emp_lid))) in let cod = mk_stt_ghost_comp u0 squash_p pure_p post in mk_arrow (R.pack_ln (R.Tv_FVar (R.pack_fv R.prop_qn)), R.Q_Explicit) cod // Following crashes in extraction // `(p:prop -> stt_ghost (squash p) emp_inames // (pure p) // (fun _ -> emp)) let tm_fstar t = tm_fstar t Range.range_0 let elim_pure_head_typing (g:env) : tot_typing g elim_pure_head (tm_fstar elim_pure_head_ty) = admit() let mk_elim_pure (p:term) : st_term = let t = Tm_STApp { head = elim_pure_head; arg_qual = None; arg = p } in wtag (Some STT_Ghost) t let elim_pure_comp (p:host_term) = let st : st_comp = { u=u_zero; res=tm_fstar (mk_squash u0 p); pre=tm_pure (tm_fstar p); post=tm_emp } in C_STGhost st #push-options "--admit_smt_queries true" let elim_pure_typing (g:env) (p:host_term) (p_prop:tot_typing g (tm_fstar p) (tm_fstar RT.tm_prop)) : st_typing g (mk_elim_pure (tm_fstar p)) (elim_pure_comp p) = T_STApp g elim_pure_head (tm_fstar RT.tm_prop) None (elim_pure_comp p) _ (elim_pure_head_typing g) p_prop #pop-options
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.Metatheory.fsti.checked", "Pulse.Typing.Combinators.fsti.checked", "Pulse.Typing.fst.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Checker.VPropEquiv.fsti.checked", "Pulse.Checker.Pure.fsti.checked", "Pulse.Checker.Prover.Base.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": true, "source_file": "Pulse.Checker.Prover.ElimPure.fst" }
[ { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": true, "full_module": "Pulse.Typing.Metatheory", "short_module": "Metatheory" }, { "abbrev": false, "full_module": "Pulse.Typing.Combinators", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.VPropEquiv", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Pure", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "Pulse.Checker.Prover.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Base", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Checker.Prover", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
vp: Pulse.Syntax.Base.term -> FStar.Tactics.Effect.Tac Prims.bool
FStar.Tactics.Effect.Tac
[]
[]
[ "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.__proj__Mkterm__item__t", "Pulse.Syntax.Base.host_term", "Pulse.Syntax.Base.range", "Pulse.Syntax.Base.term'", "Prims.bool" ]
[]
false
true
false
false
false
let is_elim_pure (vp: term) : T.Tac bool =
match vp.t with | Tm_Pure { t = Tm_FStar _ } -> true | _ -> false
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.deserialize_hash_vv_i
val deserialize_hash_vv_i (#hash_size: hash_size_t) (ok: bool) (buf: const_uint8_p) (sz: uint32_t{CB.length buf = U32.v sz}) (r: HST.erid) (pos: uint32_t) (res: hash_vv hash_size) (i: uint32_t{i < V.size_of res}) : HST.ST (bool & uint32_t) (requires (fun h0 -> CB.live h0 buf /\ V.live h0 res /\ B.loc_disjoint (CB.loc_buffer buf) (V.loc_vector res) )) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer (V.Vec?.vs res)) h0 h1))
val deserialize_hash_vv_i (#hash_size: hash_size_t) (ok: bool) (buf: const_uint8_p) (sz: uint32_t{CB.length buf = U32.v sz}) (r: HST.erid) (pos: uint32_t) (res: hash_vv hash_size) (i: uint32_t{i < V.size_of res}) : HST.ST (bool & uint32_t) (requires (fun h0 -> CB.live h0 buf /\ V.live h0 res /\ B.loc_disjoint (CB.loc_buffer buf) (V.loc_vector res) )) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer (V.Vec?.vs res)) h0 h1))
let rec deserialize_hash_vv_i (#hash_size:hash_size_t) (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (r:HST.erid) (pos:uint32_t) (res:hash_vv hash_size) (i:uint32_t{i < V.size_of res}) : HST.ST (bool & uint32_t) (requires (fun h0 -> CB.live h0 buf /\ V.live h0 res /\ B.loc_disjoint (CB.loc_buffer buf) (V.loc_vector res))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer (V.Vec?.vs res)) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let ok, pos, hv = deserialize_hash_vec ok buf sz r pos in let h0 = HST.get() in if not ok then (false, pos) else begin V.assign res i hv; (* * AR: 04/01: The call deserialize_hash_vv_i below needs liveness of buf * So we have to frame buf liveness for the V.assign call * V.assign provides a modifies postcondition in terms of * loc_vector_within, which is a recursive predicate and * I guess hard to reason about directly * Whereas to reason about liveness of buf, we only need an * overapproximation that V.assign modifies V.Vec?.vs res * Looking at the Vector library, I found the following lemma * that does the trick *) V.loc_vector_within_included res i (i + 1ul); let j = i + 1ul in if j = V.size_of res then (true, pos) else deserialize_hash_vv_i ok buf sz r pos res j end end
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 5, "end_line": 370, "start_col": 0, "start_line": 339 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" private let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end private let serialize_uint8_t (ok:bool) (x:uint8_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos x; (true, pos + 1ul) end private let serialize_uint16_t (ok:bool) (x:uint16_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint8_t ok (Int.Cast.uint16_to_uint8 (U16.shift_right x 8ul)) buf sz pos in serialize_uint8_t ok (Int.Cast.uint16_to_uint8 x) buf sz pos private let serialize_uint32_t (ok:bool) (x:uint32_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint16_t ok (Int.Cast.uint32_to_uint16 (U32.shift_right x 16ul)) buf sz pos in serialize_uint16_t ok (Int.Cast.uint32_to_uint16 x) buf sz pos private let serialize_uint64_t (ok:bool) (x:uint64_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint32_t ok (Int.Cast.uint64_to_uint32 (U64.shift_right x 32ul)) buf sz pos in serialize_uint32_t ok (Int.Cast.uint64_to_uint32 x) buf sz pos private let serialize_offset_t = serialize_uint64_t private let serialize_index_t = serialize_uint32_t private let rec serialize_hash_i (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < hash_size}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else let b = x.(i) in let ok, pos = serialize_uint8_t ok (Lib.RawIntTypes.u8_to_UInt8 b) buf sz pos in let j = i + 1ul in if j < hash_size then serialize_hash_i #hash_size ok x buf sz pos j else (ok, pos) private let serialize_hash (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else serialize_hash_i ok x buf sz pos 0ul private inline_for_extraction let u64_add_fits (x:uint64_t) (y:uint64_t): Tot (r:bool{r ==> UInt.size (U64.v x + U64.v y) 64}) = uint64_max - x >= y #push-options "--z3rlimit 100 --fuel 1 --quake 1/3" private inline_for_extraction let hash_vec_bytes (#hash_size:hash_size_t) (v:hash_vec #hash_size) : Tot uint64_t = let vs_hs = U64.mul (u32_64 (V.size_of v)) (u32_64 hash_size) in if u64_add_fits vs_hs 4UL then vs_hs + 4UL else uint64_max #pop-options private let rec serialize_hash_vec_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ loc_disjoint (B.loc_buffer buf) (loc_rvector x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let ok, pos = serialize_hash ok vi buf sz pos in let j = i + 1ul in if j < V.size_of x then serialize_hash_vec_i ok x buf sz pos j else (ok, pos) end private let serialize_hash_vec (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvreg hash_size) x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if ok && V.size_of x > 0ul then serialize_hash_vec_i ok x buf sz pos 0ul else (ok, pos) end private inline_for_extraction let rec hash_vv_bytes_i (#hash_size:hash_size_t) (vv:hash_vv hash_size) (i:uint32_t) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = if i >= V.size_of vv then 4UL else begin let vvi = V.index vv i in let r = hash_vec_bytes vvi in let rest = hash_vv_bytes_i vv (i+1ul) in if u64_add_fits r rest then begin assert (UInt.size (U64.v r + U64.v rest) 64); r + rest end else uint64_max end private inline_for_extraction let hash_vv_bytes (#hash_size:hash_size_t) (vv:hash_vv hash_size {V.size_of vv = merkle_tree_size_lg}) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = hash_vv_bytes_i vv 0ul private let rec serialize_hash_vv_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vv hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let h0 = HST.get() in let ok, pos = serialize_hash_vec #hash_size ok vi buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; let j = i + 1ul in if j < V.size_of x then serialize_hash_vv_i #hash_size ok x buf sz pos j else (ok, pos) end private let serialize_hash_vv (#hash_size:hash_size_t) (ok:bool) (x:hash_vv hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if (V.size_of x > 0ul) then serialize_hash_vv_i ok x buf sz pos 0ul else (ok, pos) end private let deserialize_bool (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & bool) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, false) else (true, pos + 1ul, (match CB.index buf pos with| 0uy -> false | _ -> true)) private let deserialize_uint8_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint8_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0uy) else (true, pos + 1ul, CB.index buf pos) private let deserialize_uint16_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint16_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0us) else begin let ok, pos, b0 = deserialize_uint8_t ok buf sz pos in let ok, pos, b1 = deserialize_uint8_t ok buf sz pos in (ok, pos, (U16.shift_left (Int.Cast.uint8_to_uint16 b0) 8ul) + Int.Cast.uint8_to_uint16 b1) end private let deserialize_uint32_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint32_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0ul) else begin let ok, pos, b0 = deserialize_uint16_t ok buf sz pos in let ok, pos, b1 = deserialize_uint16_t ok buf sz pos in (ok, pos, (U32.shift_left (Int.Cast.uint16_to_uint32 b0) 16ul) + Int.Cast.uint16_to_uint32 b1) end private let deserialize_uint64_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint64_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0UL) else begin let ok, pos, b0 = deserialize_uint32_t ok buf sz pos in let ok, pos, b1 = deserialize_uint32_t ok buf sz pos in (ok, pos, (U64.shift_left (u32_64 b0) 32ul) + u32_64 b1) end private let deserialize_offset_t = deserialize_uint64_t private let deserialize_index_t = deserialize_uint32_t private let deserialize_hash (#hash_size:hash_size_t) (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (r:HST.erid) (pos:uint32_t) : HST.ST (bool & uint32_t & hash #hash_size) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 (k, _, h) h1 -> (k ==> Rgl?.r_inv (hreg hash_size) h1 h) /\ loc_disjoint (loc_buffer (CB.cast buf)) (loc_buffer h) /\ modifies B.loc_none h0 h1)) = let rg = hreg hash_size in if not ok || pos >= sz then (false, pos, rg_dummy rg) else if sz - pos < hash_size then (false, pos, rg_dummy rg) else begin let hash = rg_alloc rg r in Lib.RawBuffer.blit (CB.cast buf) pos hash 0ul hash_size; (true, pos + hash_size, hash) end private let rec deserialize_hash_vec_i (#hash_size:hash_size_t) (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (r:HST.erid) (pos:uint32_t) (res:hash_vec #hash_size) (i:uint32_t{i < V.size_of res}) : HST.ST (bool & uint32_t) (requires (fun h0 -> CB.live h0 buf /\ V.live h0 res)) (ensures (fun h0 _ h1 -> B.modifies (B.loc_buffer (V.Vec?.vs res)) h0 h1)) = if not ok || pos >= sz then (false, pos) else begin let ok, pos, h = deserialize_hash ok buf sz r pos in if not ok then (false, pos) else begin V.assign res i h; (* * AR: 04/01: The call deserialize_hash_vec_i below needs liveness of buf * So we have to frame buf liveness for the V.assign call * V.assign provides a modifies postcondition in terms of * loc_vector_within, which is a recursive predicate and * I guess hard to reason about directly * Whereas to reason about liveness of buf, we only need an * overapproximation that V.assign modifies V.Vec?.vs res * Looking at the Vector library, I found the following lemma * that does the trick *) V.loc_vector_within_included res i (i + 1ul); let j = i + 1ul in if j < V.size_of res then deserialize_hash_vec_i ok buf sz r pos res j else (true, pos) end end private let deserialize_hash_vec (#hash_size:hash_size_t) (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (r:HST.erid) (pos:uint32_t) : HST.ST (bool & uint32_t & hash_vec #hash_size) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> B.modifies B.loc_none h0 h1)) = let rg = hvreg hash_size in if not ok || pos >= sz then (false, pos, rg_dummy rg) else begin let ok, pos, n = deserialize_uint32_t ok buf sz pos in if not ok then (false, pos, V.alloc_empty hash) else if n = 0ul then (true, pos, V.alloc_empty hash) else begin let hrg = hreg hash_size in let res = V.alloc n (rg_dummy hrg) in let ok, pos = deserialize_hash_vec_i ok buf sz r pos res 0ul in (ok, pos, res) end end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ok: Prims.bool -> buf: MerkleTree.Low.Serialization.const_uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.ConstBuffer.length buf = FStar.UInt32.v sz} -> r: FStar.HyperStack.ST.erid -> pos: MerkleTree.Low.Serialization.uint32_t -> res: MerkleTree.Low.Datastructures.hash_vv hash_size -> i: MerkleTree.Low.Serialization.uint32_t{i < LowStar.Vector.size_of res} -> FStar.HyperStack.ST.ST (Prims.bool * MerkleTree.Low.Serialization.uint32_t)
FStar.HyperStack.ST.ST
[]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "Prims.bool", "MerkleTree.Low.Serialization.const_uint8_p", "MerkleTree.Low.Serialization.uint32_t", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "LowStar.ConstBuffer.length", "MerkleTree.Low.Serialization.uint8_t", "FStar.UInt32.v", "FStar.HyperStack.ST.erid", "MerkleTree.Low.Datastructures.hash_vv", "FStar.Integers.op_Less", "FStar.Integers.Unsigned", "FStar.Integers.W32", "LowStar.Vector.size_of", "MerkleTree.Low.Datastructures.hash_vec", "Prims.op_BarBar", "Prims.op_Negation", "FStar.Integers.op_Greater_Equals", "FStar.Pervasives.Native.Mktuple2", "FStar.UInt32.__uint_to_t", "FStar.Pervasives.Native.tuple2", "FStar.UInt32.t", "MerkleTree.Low.Serialization.deserialize_hash_vv_i", "FStar.Integers.int_t", "FStar.Integers.op_Plus", "Prims.unit", "LowStar.Vector.loc_vector_within_included", "LowStar.Vector.assign", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "FStar.Pervasives.Native.tuple3", "MerkleTree.Low.Serialization.deserialize_hash_vec", "Prims.l_and", "LowStar.ConstBuffer.live", "LowStar.Vector.live", "LowStar.Monotonic.Buffer.loc_disjoint", "LowStar.ConstBuffer.loc_buffer", "LowStar.Vector.loc_vector", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Buffer.trivial_preorder", "LowStar.Vector.__proj__Vec__item__vs" ]
[ "recursion" ]
false
true
false
false
false
let rec deserialize_hash_vv_i (#hash_size: hash_size_t) (ok: bool) (buf: const_uint8_p) (sz: uint32_t{CB.length buf = U32.v sz}) (r: HST.erid) (pos: uint32_t) (res: hash_vv hash_size) (i: uint32_t{i < V.size_of res}) : HST.ST (bool & uint32_t) (requires (fun h0 -> CB.live h0 buf /\ V.live h0 res /\ B.loc_disjoint (CB.loc_buffer buf) (V.loc_vector res) )) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer (V.Vec?.vs res)) h0 h1)) =
if not ok || pos >= sz then (false, 0ul) else let ok, pos, hv = deserialize_hash_vec ok buf sz r pos in let h0 = HST.get () in if not ok then (false, pos) else (V.assign res i hv; V.loc_vector_within_included res i (i + 1ul); let j = i + 1ul in if j = V.size_of res then (true, pos) else deserialize_hash_vv_i ok buf sz r pos res j)
false
Vale.Lib.X64.Cpuid.fst
Vale.Lib.X64.Cpuid.va_code_Check_avx_support
val va_code_Check_avx_support : va_dummy:unit -> Tot va_code
val va_code_Check_avx_support : va_dummy:unit -> Tot va_code
let va_code_Check_avx_support () = (va_Block (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 1)) (va_CCons (va_code_Cpuid_Avx ()) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 268435456)) (va_CCons (va_code_Shr64 (va_op_dst_opr64_reg64 rRax) (va_const_shift_amt64 27)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_CNil ()))))))))))
{ "file_name": "obj/Vale.Lib.X64.Cpuid.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 79, "end_line": 332, "start_col": 0, "start_line": 325 }
module Vale.Lib.X64.Cpuid open Vale.Def.Types_s open Vale.Arch.Types open Vale.X64.Machine_s open Vale.X64.Memory open Vale.X64.State open Vale.X64.Decls open Vale.X64.InsBasic open Vale.X64.QuickCode open Vale.X64.QuickCodes open Vale.X64.CPU_Features_s //let pow2_values (u:unit) : Lemma // (pow2 29 == 0x20000000 /\ // pow2 25 == 0x2000000 /\ // pow2 1 == 0x2) // = // assert_norm (pow2 29 == 0x20000000); // assert_norm (0x2000000 == pow2 25); // assert_norm (0x2 == pow2 1); // () open Vale.Lib.Basic //-- Check_aesni_support [@ "opaque_to_smt" va_qattr] let va_code_Check_aesni_support () = (va_Block (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 1)) (va_CCons (va_code_Cpuid_AES ()) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 33554432)) (va_CCons (va_code_Shr64 (va_op_dst_opr64_reg64 rRax) (va_const_shift_amt64 24)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 2)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_CNil ())))))))))))) [@ "opaque_to_smt" va_qattr] let va_codegen_success_Check_aesni_support () = (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 1)) (va_pbool_and (va_codegen_success_Cpuid_AES ()) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_pbool_and (va_codegen_success_And64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 33554432)) (va_pbool_and (va_codegen_success_Shr64 (va_op_dst_opr64_reg64 rRax) (va_const_shift_amt64 24)) (va_pbool_and (va_codegen_success_And64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 2)) (va_pbool_and (va_codegen_success_And64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_ttrue ()))))))))))) [@ "opaque_to_smt" va_qattr] let va_qcode_Check_aesni_support (va_mods:va_mods_t) : (va_quickCode unit (va_code_Check_aesni_support ())) = (qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 42 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 44 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 45 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 1)) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 46 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Cpuid_AES ()) (fun (va_s:va_state) _ -> let (va_arg22:Vale.Def.Types_s.nat64) = va_get_reg64 rRcx va_s in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 47 column 23 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_iand_pow2_64 va_arg22 25) (let (va_arg21:Vale.Def.Types_s.nat64) = va_get_reg64 rRcx va_s in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 48 column 23 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_iand_pow2_64 va_arg21 1) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 49 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 50 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_And64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 33554432)) (fun (va_s:va_state) _ -> va_QLemma va_range1 "***** PRECONDITION NOT MET AT line 51 column 21 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" ((fun (p:prop) -> normalize p) (33554432 == Prims.pow2 25)) (fun _ -> (fun (p:prop) -> p) (33554432 == Prims.pow2 25)) (fun (_:unit) -> assert_normalize (33554432 == Prims.pow2 25)) (va_QLemma va_range1 "***** PRECONDITION NOT MET AT line 52 column 21 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" ((fun (p:prop) -> normalize p) (2 == Prims.pow2 1)) (fun _ -> (fun (p:prop) -> p) (2 == Prims.pow2 1)) (fun (_:unit) -> assert_normalize (2 == Prims.pow2 1)) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 54 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Shr64 (va_op_dst_opr64_reg64 rRax) (va_const_shift_amt64 24)) (fun (va_s:va_state) _ -> va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 55 column 27 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_ishr_pow2_diff64 1 25) (va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 56 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_ishr_zero64 24) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 58 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_And64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 2)) (fun (va_s:va_state) _ -> let (va_arg20:Vale.Def.Types_s.nat64) = va_get_reg64 rRcx va_s in let (va_arg19:Vale.Def.Types_s.nat64) = va_get_reg64 rRax va_s in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 59 column 29 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_iand_maybe_pow2_64 va_arg19 va_arg20 1) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 60 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_And64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 66 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_QEmpty (())))))))))))))))))))) [@"opaque_to_smt"] let va_lemma_Check_aesni_support va_b0 va_s0 = let (va_mods:va_mods_t) = [va_Mod_flags; va_Mod_reg64 rR9; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax; va_Mod_ok] in let va_qc = va_qcode_Check_aesni_support va_mods in let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_Check_aesni_support ()) va_qc va_s0 (fun va_s0 va_sM va_g -> let () = va_g in label va_range1 "***** POSTCONDITION NOT MET AT line 34 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_get_ok va_sM) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 39 column 56 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_get_reg64 rRax va_sM =!= 0 ==> aesni_enabled /\ pclmulqdq_enabled) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 40 column 24 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_get_reg64 rRbx va_sM == va_get_reg64 rRbx va_s0)) in assert_norm (va_qc.mods == va_mods); va_lemma_norm_mods ([va_Mod_flags; va_Mod_reg64 rR9; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax; va_Mod_ok]) va_sM va_s0; (va_sM, va_fM) [@"opaque_to_smt"] let va_wpProof_Check_aesni_support va_s0 va_k = let (va_sM, va_f0) = va_lemma_Check_aesni_support (va_code_Check_aesni_support ()) va_s0 in va_lemma_upd_update va_sM; assert (va_state_eq va_sM (va_update_flags va_sM (va_update_reg64 rR9 va_sM (va_update_reg64 rRdx va_sM (va_update_reg64 rRcx va_sM (va_update_reg64 rRbx va_sM (va_update_reg64 rRax va_sM (va_update_ok va_sM va_s0)))))))); va_lemma_norm_mods ([va_Mod_flags; va_Mod_reg64 rR9; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax]) va_sM va_s0; let va_g = () in (va_sM, va_f0, va_g) //-- //-- Check_sha_support [@ "opaque_to_smt" va_qattr] let va_code_Check_sha_support () = (va_Block (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 7)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_CCons (va_code_Cpuid_Sha ()) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRbx) (va_const_opr64 536870912)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_CNil ()))))))))) [@ "opaque_to_smt" va_qattr] let va_codegen_success_Check_sha_support () = (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 7)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_pbool_and (va_codegen_success_Cpuid_Sha ()) (va_pbool_and (va_codegen_success_And64 (va_op_dst_opr64_reg64 rRbx) (va_const_opr64 536870912)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRbx)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_ttrue ())))))))) [@ "opaque_to_smt" va_qattr] let va_qcode_Check_sha_support (va_mods:va_mods_t) : (va_quickCode unit (va_code_Check_sha_support ())) = (qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 77 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 79 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 7)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 80 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 81 column 14 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Cpuid_Sha ()) (fun (va_s:va_state) _ -> let (va_arg11:Vale.Def.Types_s.nat64) = va_get_reg64 rRbx va_s in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 82 column 23 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_iand_pow2_64 va_arg11 29) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 83 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_And64 (va_op_dst_opr64_reg64 rRbx) (va_const_opr64 536870912)) (fun (va_s:va_state) _ -> va_QLemma va_range1 "***** PRECONDITION NOT MET AT line 84 column 21 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" ((fun (p:prop) -> normalize p) (536870912 == Prims.pow2 29)) (fun _ -> (fun (p:prop) -> p) (536870912 == Prims.pow2 29)) (fun (_:unit) -> assert_normalize (536870912 == Prims.pow2 29)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 85 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRbx)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 87 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_QEmpty (())))))))))))) [@"opaque_to_smt"] let va_lemma_Check_sha_support va_b0 va_s0 = let (va_mods:va_mods_t) = [va_Mod_flags; va_Mod_reg64 rR9; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax; va_Mod_ok] in let va_qc = va_qcode_Check_sha_support va_mods in let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_Check_sha_support ()) va_qc va_s0 (fun va_s0 va_sM va_g -> let () = va_g in label va_range1 "***** POSTCONDITION NOT MET AT line 69 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_get_ok va_sM) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 74 column 33 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_get_reg64 rRax va_sM =!= 0 ==> sha_enabled) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 75 column 24 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_get_reg64 rRbx va_sM == va_get_reg64 rRbx va_s0)) in assert_norm (va_qc.mods == va_mods); va_lemma_norm_mods ([va_Mod_flags; va_Mod_reg64 rR9; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax; va_Mod_ok]) va_sM va_s0; (va_sM, va_fM) [@"opaque_to_smt"] let va_wpProof_Check_sha_support va_s0 va_k = let (va_sM, va_f0) = va_lemma_Check_sha_support (va_code_Check_sha_support ()) va_s0 in va_lemma_upd_update va_sM; assert (va_state_eq va_sM (va_update_flags va_sM (va_update_reg64 rR9 va_sM (va_update_reg64 rRdx va_sM (va_update_reg64 rRcx va_sM (va_update_reg64 rRbx va_sM (va_update_reg64 rRax va_sM (va_update_ok va_sM va_s0)))))))); va_lemma_norm_mods ([va_Mod_flags; va_Mod_reg64 rR9; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax]) va_sM va_s0; let va_g = () in (va_sM, va_f0, va_g) //-- //-- Check_adx_bmi2_support [@ "opaque_to_smt" va_qattr] let va_code_Check_adx_bmi2_support () = (va_Block (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 7)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_CCons (va_code_Cpuid_Adx_Bmi2 ()) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 524288)) (va_CCons (va_code_Shr64 (va_op_dst_opr64_reg64 rRax) (va_const_shift_amt64 11)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRbx) (va_const_opr64 256)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_CNil ())))))))))))) [@ "opaque_to_smt" va_qattr] let va_codegen_success_Check_adx_bmi2_support () = (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 7)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_pbool_and (va_codegen_success_Cpuid_Adx_Bmi2 ()) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRbx)) (va_pbool_and (va_codegen_success_And64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 524288)) (va_pbool_and (va_codegen_success_Shr64 (va_op_dst_opr64_reg64 rRax) (va_const_shift_amt64 11)) (va_pbool_and (va_codegen_success_And64 (va_op_dst_opr64_reg64 rRbx) (va_const_opr64 256)) (va_pbool_and (va_codegen_success_And64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRbx)) (va_pbool_and (va_codegen_success_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_ttrue ()))))))))))) [@ "opaque_to_smt" va_qattr] let va_qcode_Check_adx_bmi2_support (va_mods:va_mods_t) : (va_quickCode unit (va_code_Check_adx_bmi2_support ())) = (qblock va_mods (fun (va_s:va_state) -> let (va_old_s:va_state) = va_s in va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 98 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 100 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 7)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 101 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 102 column 19 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Cpuid_Adx_Bmi2 ()) (fun (va_s:va_state) _ -> let (va_arg22:Vale.Def.Types_s.nat64) = va_get_reg64 rRbx va_s in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 103 column 23 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_iand_pow2_64 va_arg22 8) (let (va_arg21:Vale.Def.Types_s.nat64) = va_get_reg64 rRbx va_s in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 104 column 23 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_iand_pow2_64 va_arg21 19) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 105 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRbx)) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 107 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_And64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 524288)) (fun (va_s:va_state) _ -> va_QLemma va_range1 "***** PRECONDITION NOT MET AT line 109 column 21 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" ((fun (p:prop) -> normalize p) (256 == Prims.pow2 8)) (fun _ -> (fun (p:prop) -> p) (256 == Prims.pow2 8)) (fun (_:unit) -> assert_normalize (256 == Prims.pow2 8)) (va_QLemma va_range1 "***** PRECONDITION NOT MET AT line 110 column 21 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" ((fun (p:prop) -> normalize p) (524288 == Prims.pow2 19)) (fun _ -> (fun (p:prop) -> p) (524288 == Prims.pow2 19)) (fun (_:unit) -> assert_normalize (524288 == Prims.pow2 19)) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 112 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Shr64 (va_op_dst_opr64_reg64 rRax) (va_const_shift_amt64 11)) (fun (va_s:va_state) _ -> va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 113 column 27 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_ishr_pow2_diff64 8 19) (va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 114 column 22 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_ishr_zero64 11) (va_QBind va_range1 "***** PRECONDITION NOT MET AT line 116 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_And64 (va_op_dst_opr64_reg64 rRbx) (va_const_opr64 256)) (fun (va_s:va_state) _ -> let (va_arg20:Vale.Def.Types_s.nat64) = va_get_reg64 rRbx va_s in let (va_arg19:Vale.Def.Types_s.nat64) = va_get_reg64 rRax va_s in va_qPURE va_range1 "***** PRECONDITION NOT MET AT line 117 column 29 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (fun (_:unit) -> Vale.Arch.TypesNative.lemma_iand_maybe_pow2_64 va_arg19 va_arg20 8) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 118 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_And64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRbx)) (va_QSeq va_range1 "***** PRECONDITION NOT MET AT line 120 column 10 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_quick_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_QEmpty (())))))))))))))))))))) [@"opaque_to_smt"] let va_lemma_Check_adx_bmi2_support va_b0 va_s0 = let (va_mods:va_mods_t) = [va_Mod_flags; va_Mod_reg64 rR9; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax; va_Mod_ok] in let va_qc = va_qcode_Check_adx_bmi2_support va_mods in let (va_sM, va_fM, va_g) = va_wp_sound_code_norm (va_code_Check_adx_bmi2_support ()) va_qc va_s0 (fun va_s0 va_sM va_g -> let () = va_g in label va_range1 "***** POSTCONDITION NOT MET AT line 90 column 1 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_get_ok va_sM) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 95 column 49 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_get_reg64 rRax va_sM =!= 0 ==> adx_enabled /\ bmi2_enabled) /\ label va_range1 "***** POSTCONDITION NOT MET AT line 96 column 24 of file /home/gebner/fstar_dataset/projects/hacl-star/vale/code/lib/util/x64/Vale.Lib.X64.Cpuid.vaf *****" (va_get_reg64 rRbx va_sM == va_get_reg64 rRbx va_s0)) in assert_norm (va_qc.mods == va_mods); va_lemma_norm_mods ([va_Mod_flags; va_Mod_reg64 rR9; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax; va_Mod_ok]) va_sM va_s0; (va_sM, va_fM) [@"opaque_to_smt"] let va_wpProof_Check_adx_bmi2_support va_s0 va_k = let (va_sM, va_f0) = va_lemma_Check_adx_bmi2_support (va_code_Check_adx_bmi2_support ()) va_s0 in va_lemma_upd_update va_sM; assert (va_state_eq va_sM (va_update_flags va_sM (va_update_reg64 rR9 va_sM (va_update_reg64 rRdx va_sM (va_update_reg64 rRcx va_sM (va_update_reg64 rRbx va_sM (va_update_reg64 rRax va_sM (va_update_ok va_sM va_s0)))))))); va_lemma_norm_mods ([va_Mod_flags; va_Mod_reg64 rR9; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax]) va_sM va_s0; let va_g = () in (va_sM, va_f0, va_g) //-- //-- Check_avx_support
{ "checked_file": "/", "dependencies": [ "Vale.X64.State.fsti.checked", "Vale.X64.QuickCodes.fsti.checked", "Vale.X64.QuickCode.fst.checked", "Vale.X64.Memory.fsti.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.InsBasic.fsti.checked", "Vale.X64.Decls.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.Lib.Basic.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.TypesNative.fsti.checked", "Vale.Arch.Types.fsti.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Vale.Lib.X64.Cpuid.fst" }
[ { "abbrev": false, "full_module": "Vale.Lib.Basic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.CPU_Features_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCodes", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.QuickCode", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsBasic", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Decls", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.State", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Memory", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
va_dummy: Prims.unit -> Vale.X64.Decls.va_code
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "Vale.X64.Decls.va_Block", "Vale.X64.Decls.va_CCons", "Vale.X64.InsBasic.va_code_Mov64", "Vale.X64.Decls.va_op_dst_opr64_reg64", "Vale.X64.Machine_s.rR9", "Vale.X64.Decls.va_op_opr64_reg64", "Vale.X64.Machine_s.rRbx", "Vale.X64.Machine_s.rRcx", "Vale.X64.Decls.va_const_opr64", "Vale.X64.Machine_s.rRax", "Vale.X64.InsBasic.va_code_Cpuid_Avx", "Vale.X64.InsBasic.va_code_And64", "Vale.X64.InsBasic.va_code_Shr64", "Vale.X64.Decls.va_const_shift_amt64", "Vale.X64.Decls.va_CNil", "Vale.X64.Decls.va_code" ]
[]
false
false
false
true
false
let va_code_Check_avx_support () =
(va_Block (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rR9) (va_op_opr64_reg64 rRbx)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRcx) (va_const_opr64 0)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 1)) (va_CCons (va_code_Cpuid_Avx ()) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRax) (va_op_opr64_reg64 rRcx)) (va_CCons (va_code_And64 (va_op_dst_opr64_reg64 rRax) (va_const_opr64 268435456)) (va_CCons (va_code_Shr64 (va_op_dst_opr64_reg64 rRax) (va_const_shift_amt64 27)) (va_CCons (va_code_Mov64 (va_op_dst_opr64_reg64 rRbx) (va_op_opr64_reg64 rR9)) (va_CNil ()))))))))))
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.deserialize_hash_vec
val deserialize_hash_vec (#hash_size: hash_size_t) (ok: bool) (buf: const_uint8_p) (sz: uint32_t{CB.length buf = U32.v sz}) (r: HST.erid) (pos: uint32_t) : HST.ST (bool & uint32_t & hash_vec #hash_size) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> B.modifies B.loc_none h0 h1))
val deserialize_hash_vec (#hash_size: hash_size_t) (ok: bool) (buf: const_uint8_p) (sz: uint32_t{CB.length buf = U32.v sz}) (r: HST.erid) (pos: uint32_t) : HST.ST (bool & uint32_t & hash_vec #hash_size) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> B.modifies B.loc_none h0 h1))
let deserialize_hash_vec (#hash_size:hash_size_t) (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (r:HST.erid) (pos:uint32_t) : HST.ST (bool & uint32_t & hash_vec #hash_size) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> B.modifies B.loc_none h0 h1)) = let rg = hvreg hash_size in if not ok || pos >= sz then (false, pos, rg_dummy rg) else begin let ok, pos, n = deserialize_uint32_t ok buf sz pos in if not ok then (false, pos, V.alloc_empty hash) else if n = 0ul then (true, pos, V.alloc_empty hash) else begin let hrg = hreg hash_size in let res = V.alloc n (rg_dummy hrg) in let ok, pos = deserialize_hash_vec_i ok buf sz r pos res 0ul in (ok, pos, res) end end
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 5, "end_line": 336, "start_col": 0, "start_line": 318 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" private let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end private let serialize_uint8_t (ok:bool) (x:uint8_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos x; (true, pos + 1ul) end private let serialize_uint16_t (ok:bool) (x:uint16_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint8_t ok (Int.Cast.uint16_to_uint8 (U16.shift_right x 8ul)) buf sz pos in serialize_uint8_t ok (Int.Cast.uint16_to_uint8 x) buf sz pos private let serialize_uint32_t (ok:bool) (x:uint32_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint16_t ok (Int.Cast.uint32_to_uint16 (U32.shift_right x 16ul)) buf sz pos in serialize_uint16_t ok (Int.Cast.uint32_to_uint16 x) buf sz pos private let serialize_uint64_t (ok:bool) (x:uint64_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint32_t ok (Int.Cast.uint64_to_uint32 (U64.shift_right x 32ul)) buf sz pos in serialize_uint32_t ok (Int.Cast.uint64_to_uint32 x) buf sz pos private let serialize_offset_t = serialize_uint64_t private let serialize_index_t = serialize_uint32_t private let rec serialize_hash_i (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < hash_size}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else let b = x.(i) in let ok, pos = serialize_uint8_t ok (Lib.RawIntTypes.u8_to_UInt8 b) buf sz pos in let j = i + 1ul in if j < hash_size then serialize_hash_i #hash_size ok x buf sz pos j else (ok, pos) private let serialize_hash (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else serialize_hash_i ok x buf sz pos 0ul private inline_for_extraction let u64_add_fits (x:uint64_t) (y:uint64_t): Tot (r:bool{r ==> UInt.size (U64.v x + U64.v y) 64}) = uint64_max - x >= y #push-options "--z3rlimit 100 --fuel 1 --quake 1/3" private inline_for_extraction let hash_vec_bytes (#hash_size:hash_size_t) (v:hash_vec #hash_size) : Tot uint64_t = let vs_hs = U64.mul (u32_64 (V.size_of v)) (u32_64 hash_size) in if u64_add_fits vs_hs 4UL then vs_hs + 4UL else uint64_max #pop-options private let rec serialize_hash_vec_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ loc_disjoint (B.loc_buffer buf) (loc_rvector x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let ok, pos = serialize_hash ok vi buf sz pos in let j = i + 1ul in if j < V.size_of x then serialize_hash_vec_i ok x buf sz pos j else (ok, pos) end private let serialize_hash_vec (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvreg hash_size) x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if ok && V.size_of x > 0ul then serialize_hash_vec_i ok x buf sz pos 0ul else (ok, pos) end private inline_for_extraction let rec hash_vv_bytes_i (#hash_size:hash_size_t) (vv:hash_vv hash_size) (i:uint32_t) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = if i >= V.size_of vv then 4UL else begin let vvi = V.index vv i in let r = hash_vec_bytes vvi in let rest = hash_vv_bytes_i vv (i+1ul) in if u64_add_fits r rest then begin assert (UInt.size (U64.v r + U64.v rest) 64); r + rest end else uint64_max end private inline_for_extraction let hash_vv_bytes (#hash_size:hash_size_t) (vv:hash_vv hash_size {V.size_of vv = merkle_tree_size_lg}) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = hash_vv_bytes_i vv 0ul private let rec serialize_hash_vv_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vv hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let h0 = HST.get() in let ok, pos = serialize_hash_vec #hash_size ok vi buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; let j = i + 1ul in if j < V.size_of x then serialize_hash_vv_i #hash_size ok x buf sz pos j else (ok, pos) end private let serialize_hash_vv (#hash_size:hash_size_t) (ok:bool) (x:hash_vv hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if (V.size_of x > 0ul) then serialize_hash_vv_i ok x buf sz pos 0ul else (ok, pos) end private let deserialize_bool (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & bool) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, false) else (true, pos + 1ul, (match CB.index buf pos with| 0uy -> false | _ -> true)) private let deserialize_uint8_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint8_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0uy) else (true, pos + 1ul, CB.index buf pos) private let deserialize_uint16_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint16_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0us) else begin let ok, pos, b0 = deserialize_uint8_t ok buf sz pos in let ok, pos, b1 = deserialize_uint8_t ok buf sz pos in (ok, pos, (U16.shift_left (Int.Cast.uint8_to_uint16 b0) 8ul) + Int.Cast.uint8_to_uint16 b1) end private let deserialize_uint32_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint32_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0ul) else begin let ok, pos, b0 = deserialize_uint16_t ok buf sz pos in let ok, pos, b1 = deserialize_uint16_t ok buf sz pos in (ok, pos, (U32.shift_left (Int.Cast.uint16_to_uint32 b0) 16ul) + Int.Cast.uint16_to_uint32 b1) end private let deserialize_uint64_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint64_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0UL) else begin let ok, pos, b0 = deserialize_uint32_t ok buf sz pos in let ok, pos, b1 = deserialize_uint32_t ok buf sz pos in (ok, pos, (U64.shift_left (u32_64 b0) 32ul) + u32_64 b1) end private let deserialize_offset_t = deserialize_uint64_t private let deserialize_index_t = deserialize_uint32_t private let deserialize_hash (#hash_size:hash_size_t) (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (r:HST.erid) (pos:uint32_t) : HST.ST (bool & uint32_t & hash #hash_size) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 (k, _, h) h1 -> (k ==> Rgl?.r_inv (hreg hash_size) h1 h) /\ loc_disjoint (loc_buffer (CB.cast buf)) (loc_buffer h) /\ modifies B.loc_none h0 h1)) = let rg = hreg hash_size in if not ok || pos >= sz then (false, pos, rg_dummy rg) else if sz - pos < hash_size then (false, pos, rg_dummy rg) else begin let hash = rg_alloc rg r in Lib.RawBuffer.blit (CB.cast buf) pos hash 0ul hash_size; (true, pos + hash_size, hash) end private let rec deserialize_hash_vec_i (#hash_size:hash_size_t) (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (r:HST.erid) (pos:uint32_t) (res:hash_vec #hash_size) (i:uint32_t{i < V.size_of res}) : HST.ST (bool & uint32_t) (requires (fun h0 -> CB.live h0 buf /\ V.live h0 res)) (ensures (fun h0 _ h1 -> B.modifies (B.loc_buffer (V.Vec?.vs res)) h0 h1)) = if not ok || pos >= sz then (false, pos) else begin let ok, pos, h = deserialize_hash ok buf sz r pos in if not ok then (false, pos) else begin V.assign res i h; (* * AR: 04/01: The call deserialize_hash_vec_i below needs liveness of buf * So we have to frame buf liveness for the V.assign call * V.assign provides a modifies postcondition in terms of * loc_vector_within, which is a recursive predicate and * I guess hard to reason about directly * Whereas to reason about liveness of buf, we only need an * overapproximation that V.assign modifies V.Vec?.vs res * Looking at the Vector library, I found the following lemma * that does the trick *) V.loc_vector_within_included res i (i + 1ul); let j = i + 1ul in if j < V.size_of res then deserialize_hash_vec_i ok buf sz r pos res j else (true, pos) end end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ok: Prims.bool -> buf: MerkleTree.Low.Serialization.const_uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.ConstBuffer.length buf = FStar.UInt32.v sz} -> r: FStar.HyperStack.ST.erid -> pos: MerkleTree.Low.Serialization.uint32_t -> FStar.HyperStack.ST.ST ((Prims.bool * MerkleTree.Low.Serialization.uint32_t) * MerkleTree.Low.Datastructures.hash_vec)
FStar.HyperStack.ST.ST
[]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "Prims.bool", "MerkleTree.Low.Serialization.const_uint8_p", "MerkleTree.Low.Serialization.uint32_t", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "LowStar.ConstBuffer.length", "MerkleTree.Low.Serialization.uint8_t", "FStar.UInt32.v", "FStar.HyperStack.ST.erid", "Prims.op_BarBar", "Prims.op_Negation", "FStar.Integers.op_Greater_Equals", "FStar.Integers.Unsigned", "FStar.Integers.W32", "FStar.Pervasives.Native.Mktuple3", "MerkleTree.Low.Datastructures.hash_vec", "LowStar.Regional.rg_dummy", "FStar.Pervasives.Native.tuple3", "LowStar.Vector.alloc_empty", "MerkleTree.Low.Datastructures.hash", "FStar.UInt32.t", "FStar.UInt32.__uint_to_t", "FStar.Pervasives.Native.tuple2", "MerkleTree.Low.Serialization.deserialize_hash_vec_i", "LowStar.Vector.vector", "LowStar.Vector.alloc", "LowStar.Regional.regional", "MerkleTree.Low.Datastructures.hreg", "MerkleTree.Low.Serialization.deserialize_uint32_t", "MerkleTree.Low.Datastructures.hvreg", "FStar.Monotonic.HyperStack.mem", "LowStar.ConstBuffer.live", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none" ]
[]
false
true
false
false
false
let deserialize_hash_vec (#hash_size: hash_size_t) (ok: bool) (buf: const_uint8_p) (sz: uint32_t{CB.length buf = U32.v sz}) (r: HST.erid) (pos: uint32_t) : HST.ST (bool & uint32_t & hash_vec #hash_size) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> B.modifies B.loc_none h0 h1)) =
let rg = hvreg hash_size in if not ok || pos >= sz then (false, pos, rg_dummy rg) else let ok, pos, n = deserialize_uint32_t ok buf sz pos in if not ok then (false, pos, V.alloc_empty hash) else if n = 0ul then (true, pos, V.alloc_empty hash) else let hrg = hreg hash_size in let res = V.alloc n (rg_dummy hrg) in let ok, pos = deserialize_hash_vec_i ok buf sz r pos res 0ul in (ok, pos, res)
false
MerkleTree.Low.Serialization.fst
MerkleTree.Low.Serialization.deserialize_hash
val deserialize_hash (#hash_size: hash_size_t) (ok: bool) (buf: const_uint8_p) (sz: uint32_t{CB.length buf = U32.v sz}) (r: HST.erid) (pos: uint32_t) : HST.ST (bool & uint32_t & hash #hash_size) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 (k, _, h) h1 -> (k ==> Rgl?.r_inv (hreg hash_size) h1 h) /\ loc_disjoint (loc_buffer (CB.cast buf)) (loc_buffer h) /\ modifies B.loc_none h0 h1))
val deserialize_hash (#hash_size: hash_size_t) (ok: bool) (buf: const_uint8_p) (sz: uint32_t{CB.length buf = U32.v sz}) (r: HST.erid) (pos: uint32_t) : HST.ST (bool & uint32_t & hash #hash_size) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 (k, _, h) h1 -> (k ==> Rgl?.r_inv (hreg hash_size) h1 h) /\ loc_disjoint (loc_buffer (CB.cast buf)) (loc_buffer h) /\ modifies B.loc_none h0 h1))
let deserialize_hash (#hash_size:hash_size_t) (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (r:HST.erid) (pos:uint32_t) : HST.ST (bool & uint32_t & hash #hash_size) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 (k, _, h) h1 -> (k ==> Rgl?.r_inv (hreg hash_size) h1 h) /\ loc_disjoint (loc_buffer (CB.cast buf)) (loc_buffer h) /\ modifies B.loc_none h0 h1)) = let rg = hreg hash_size in if not ok || pos >= sz then (false, pos, rg_dummy rg) else if sz - pos < hash_size then (false, pos, rg_dummy rg) else begin let hash = rg_alloc rg r in Lib.RawBuffer.blit (CB.cast buf) pos hash 0ul hash_size; (true, pos + hash_size, hash) end
{ "file_name": "src/MerkleTree.Low.Serialization.fst", "git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
{ "end_col": 5, "end_line": 284, "start_col": 0, "start_line": 269 }
module MerkleTree.Low.Serialization open FStar.Integers open FStar.Mul open LowStar.Modifies open LowStar.BufferOps open LowStar.Vector open LowStar.RVector open LowStar.Regional open LowStar.Regional.Instances open MerkleTree.Low module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module HH = FStar.Monotonic.HyperHeap module B = LowStar.Buffer module CB = LowStar.ConstBuffer module V = LowStar.Vector module RV = LowStar.RVector module RVI = LowStar.Regional.Instances module U16 = FStar.UInt16 module U32 = FStar.UInt32 module U64 = FStar.UInt64 module U8 = FStar.UInt8 open MerkleTree.Low.Datastructures open MerkleTree.Low.Hashfunctions module MTS = MerkleTree.Spec let uint8_t = U8.t let uint16_t = U16.t let uint32_t = U32.t let uint64_t = U64.t let uint8_p = B.buffer uint8_t type const_uint8_p = const_pointer uint8_t #reset-options "--z3rlimit 5 --initial_fuel 0 --max_fuel 0 --initial_ifuel 0 --max_ifuel 0" private let serialize_bool (ok:bool) (x:bool) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos (if x then 1uy else 0uy); (true, pos + 1ul) end private let serialize_uint8_t (ok:bool) (x:uint8_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin B.upd buf pos x; (true, pos + 1ul) end private let serialize_uint16_t (ok:bool) (x:uint16_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint8_t ok (Int.Cast.uint16_to_uint8 (U16.shift_right x 8ul)) buf sz pos in serialize_uint8_t ok (Int.Cast.uint16_to_uint8 x) buf sz pos private let serialize_uint32_t (ok:bool) (x:uint32_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint16_t ok (Int.Cast.uint32_to_uint16 (U32.shift_right x 16ul)) buf sz pos in serialize_uint16_t ok (Int.Cast.uint32_to_uint16 x) buf sz pos private let serialize_uint64_t (ok:bool) (x:uint64_t) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = let ok, pos = serialize_uint32_t ok (Int.Cast.uint64_to_uint32 (U64.shift_right x 32ul)) buf sz pos in serialize_uint32_t ok (Int.Cast.uint64_to_uint32 x) buf sz pos private let serialize_offset_t = serialize_uint64_t private let serialize_index_t = serialize_uint32_t private let rec serialize_hash_i (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < hash_size}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else let b = x.(i) in let ok, pos = serialize_uint8_t ok (Lib.RawIntTypes.u8_to_UInt8 b) buf sz pos in let j = i + 1ul in if j < hash_size then serialize_hash_i #hash_size ok x buf sz pos j else (ok, pos) private let serialize_hash (#hash_size:hash_size_t) (ok:bool) (x:hash #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ B.live h0 x /\ B.len x = hash_size)) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else serialize_hash_i ok x buf sz pos 0ul private inline_for_extraction let u64_add_fits (x:uint64_t) (y:uint64_t): Tot (r:bool{r ==> UInt.size (U64.v x + U64.v y) 64}) = uint64_max - x >= y #push-options "--z3rlimit 100 --fuel 1 --quake 1/3" private inline_for_extraction let hash_vec_bytes (#hash_size:hash_size_t) (v:hash_vec #hash_size) : Tot uint64_t = let vs_hs = U64.mul (u32_64 (V.size_of v)) (u32_64 hash_size) in if u64_add_fits vs_hs 4UL then vs_hs + 4UL else uint64_max #pop-options private let rec serialize_hash_vec_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ loc_disjoint (B.loc_buffer buf) (loc_rvector x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let ok, pos = serialize_hash ok vi buf sz pos in let j = i + 1ul in if j < V.size_of x then serialize_hash_vec_i ok x buf sz pos j else (ok, pos) end private let serialize_hash_vec (#hash_size:hash_size_t) (ok:bool) (x:hash_vec #hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvreg hash_size) x))) (ensures (fun h0 _ h1 -> RV.rv_inv h1 x /\ modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if ok && V.size_of x > 0ul then serialize_hash_vec_i ok x buf sz pos 0ul else (ok, pos) end private inline_for_extraction let rec hash_vv_bytes_i (#hash_size:hash_size_t) (vv:hash_vv hash_size) (i:uint32_t) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = if i >= V.size_of vv then 4UL else begin let vvi = V.index vv i in let r = hash_vec_bytes vvi in let rest = hash_vv_bytes_i vv (i+1ul) in if u64_add_fits r rest then begin assert (UInt.size (U64.v r + U64.v rest) 64); r + rest end else uint64_max end private inline_for_extraction let hash_vv_bytes (#hash_size:hash_size_t) (vv:hash_vv hash_size {V.size_of vv = merkle_tree_size_lg}) : HST.ST uint64_t (requires (fun h0 -> V.live h0 vv)) (ensures (fun h0 _ h1 -> h0 == h1)) = hash_vv_bytes_i vv 0ul private let rec serialize_hash_vv_i (#hash_size:hash_size_t) (ok:bool) (x:hash_vv hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) (i:uint32_t{i < V.size_of x}) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let vi = V.index x i in let h0 = HST.get() in let ok, pos = serialize_hash_vec #hash_size ok vi buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; let j = i + 1ul in if j < V.size_of x then serialize_hash_vv_i #hash_size ok x buf sz pos j else (ok, pos) end private let serialize_hash_vv (#hash_size:hash_size_t) (ok:bool) (x:hash_vv hash_size) (buf:uint8_p) (sz:uint32_t{B.len buf = sz}) (pos:uint32_t) : HST.ST (bool & uint32_t) (requires (fun h0 -> B.live h0 buf /\ RV.rv_inv h0 x /\ HS.disjoint (B.frameOf buf) (Rgl?.region_of (hvvreg hash_size) x))) (ensures (fun h0 _ h1 -> modifies (B.loc_buffer buf) h0 h1)) = if not ok || pos >= sz then (false, 0ul) else begin let h0 = HST.get() in let ok, pos = serialize_uint32_t ok (V.size_of x) buf sz pos in let h1 = HST.get() in RV.rv_inv_preserved x (B.loc_buffer buf) h0 h1; if (V.size_of x > 0ul) then serialize_hash_vv_i ok x buf sz pos 0ul else (ok, pos) end private let deserialize_bool (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & bool) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, false) else (true, pos + 1ul, (match CB.index buf pos with| 0uy -> false | _ -> true)) private let deserialize_uint8_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint8_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0uy) else (true, pos + 1ul, CB.index buf pos) private let deserialize_uint16_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint16_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0us) else begin let ok, pos, b0 = deserialize_uint8_t ok buf sz pos in let ok, pos, b1 = deserialize_uint8_t ok buf sz pos in (ok, pos, (U16.shift_left (Int.Cast.uint8_to_uint16 b0) 8ul) + Int.Cast.uint8_to_uint16 b1) end private let deserialize_uint32_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint32_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0ul) else begin let ok, pos, b0 = deserialize_uint16_t ok buf sz pos in let ok, pos, b1 = deserialize_uint16_t ok buf sz pos in (ok, pos, (U32.shift_left (Int.Cast.uint16_to_uint32 b0) 16ul) + Int.Cast.uint16_to_uint32 b1) end private let deserialize_uint64_t (ok:bool) (buf:const_uint8_p) (sz:uint32_t{CB.length buf = U32.v sz}) (pos:uint32_t): HST.ST (bool & uint32_t & uint64_t) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 _ h1 -> h0 == h1)) = if not ok || pos >= sz then (false, pos, 0UL) else begin let ok, pos, b0 = deserialize_uint32_t ok buf sz pos in let ok, pos, b1 = deserialize_uint32_t ok buf sz pos in (ok, pos, (U64.shift_left (u32_64 b0) 32ul) + u32_64 b1) end private let deserialize_offset_t = deserialize_uint64_t private let deserialize_index_t = deserialize_uint32_t
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.Low.Hashfunctions.fst.checked", "MerkleTree.Low.Datastructures.fst.checked", "MerkleTree.Low.fst.checked", "LowStar.Vector.fst.checked", "LowStar.RVector.fst.checked", "LowStar.Regional.Instances.fst.checked", "LowStar.Regional.fst.checked", "LowStar.Modifies.fst.checked", "LowStar.ConstBuffer.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.RawIntTypes.fsti.checked", "Lib.RawBuffer.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Monotonic.HyperHeap.fsti.checked", "FStar.Integers.fst.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.Low.Serialization.fst" }
[ { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": false, "full_module": "MerkleTree.Low.Hashfunctions", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low.Datastructures", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": true, "full_module": "LowStar.Regional.Instances", "short_module": "RVI" }, { "abbrev": true, "full_module": "LowStar.RVector", "short_module": "RV" }, { "abbrev": true, "full_module": "LowStar.Vector", "short_module": "V" }, { "abbrev": true, "full_module": "LowStar.ConstBuffer", "short_module": "CB" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.Monotonic.HyperHeap", "short_module": "HH" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional.Instances", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Regional", "short_module": null }, { "abbrev": false, "full_module": "LowStar.RVector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Vector", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Modifies", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ok: Prims.bool -> buf: MerkleTree.Low.Serialization.const_uint8_p -> sz: MerkleTree.Low.Serialization.uint32_t{LowStar.ConstBuffer.length buf = FStar.UInt32.v sz} -> r: FStar.HyperStack.ST.erid -> pos: MerkleTree.Low.Serialization.uint32_t -> FStar.HyperStack.ST.ST ((Prims.bool * MerkleTree.Low.Serialization.uint32_t) * MerkleTree.Low.Datastructures.hash)
FStar.HyperStack.ST.ST
[]
[]
[ "MerkleTree.Low.Datastructures.hash_size_t", "Prims.bool", "MerkleTree.Low.Serialization.const_uint8_p", "MerkleTree.Low.Serialization.uint32_t", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "LowStar.ConstBuffer.length", "MerkleTree.Low.Serialization.uint8_t", "FStar.UInt32.v", "FStar.HyperStack.ST.erid", "Prims.op_BarBar", "Prims.op_Negation", "FStar.Integers.op_Greater_Equals", "FStar.Integers.Unsigned", "FStar.Integers.W32", "FStar.Pervasives.Native.Mktuple3", "MerkleTree.Low.Datastructures.hash", "LowStar.Regional.rg_dummy", "FStar.Pervasives.Native.tuple3", "FStar.Integers.op_Less", "FStar.Integers.op_Subtraction", "FStar.Integers.op_Plus", "Prims.unit", "Lib.RawBuffer.blit", "LowStar.ConstBuffer.cast", "FStar.UInt32.__uint_to_t", "LowStar.Regional.rg_alloc", "LowStar.Regional.regional", "MerkleTree.Low.Datastructures.hreg", "FStar.Monotonic.HyperStack.mem", "LowStar.ConstBuffer.live", "Prims.l_and", "Prims.l_imp", "LowStar.Regional.__proj__Rgl__item__r_inv", "LowStar.Monotonic.Buffer.loc_disjoint", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.ConstBuffer.qbuf_pre", "LowStar.ConstBuffer.as_qbuf", "Lib.IntTypes.uint8", "LowStar.Buffer.trivial_preorder", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none" ]
[]
false
true
false
false
false
let deserialize_hash (#hash_size: hash_size_t) (ok: bool) (buf: const_uint8_p) (sz: uint32_t{CB.length buf = U32.v sz}) (r: HST.erid) (pos: uint32_t) : HST.ST (bool & uint32_t & hash #hash_size) (requires (fun h0 -> CB.live h0 buf)) (ensures (fun h0 (k, _, h) h1 -> (k ==> Rgl?.r_inv (hreg hash_size) h1 h) /\ loc_disjoint (loc_buffer (CB.cast buf)) (loc_buffer h) /\ modifies B.loc_none h0 h1)) =
let rg = hreg hash_size in if not ok || pos >= sz then (false, pos, rg_dummy rg) else if sz - pos < hash_size then (false, pos, rg_dummy rg) else let hash = rg_alloc rg r in Lib.RawBuffer.blit (CB.cast buf) pos hash 0ul hash_size; (true, pos + hash_size, hash)
false