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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
InterpreterTarget.fst | InterpreterTarget.unzip | val unzip (x: list ('a & 'b)) : list 'a & list 'b | val unzip (x: list ('a & 'b)) : list 'a & list 'b | let rec unzip (x: list ('a & 'b))
: list 'a & list 'b
= match x with
| [] -> [], []
| (x,y)::tl ->
let xs, ys = unzip tl in
x::xs, y::ys | {
"file_name": "src/3d/InterpreterTarget.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 18,
"end_line": 1092,
"start_col": 0,
"start_line": 1086
} | (*
Copyright 2021 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module InterpreterTarget
(* The abstract syntax for the code produced by 3d, targeting prelude/Interpreter.fst *)
open FStar.All
open FStar.List.Tot
module A = Ast
module T = Target
module H = Hashtable
noeq
type inv =
| Inv_conj : inv -> inv -> inv
| Inv_ptr : expr -> inv
| Inv_copy_buf: expr -> inv
noeq
type eloc =
| Eloc_output : eloc
| Eloc_union : eloc -> eloc -> eloc
| Eloc_ptr : expr -> eloc
| Eloc_copy_buf: e:expr { T.Identifier? (fst e) } -> eloc
noeq
type disj =
| Disj_pair : l:eloc{ Eloc_copy_buf? l } -> eloc -> disj
| Disj_conj : disj -> disj -> disj
let index a = option a
let disj_pair l m : index disj =
match l, m with
| None, i
| i, None -> None
| Some l, Some m -> Some (Disj_pair l m)
let subst_index (s:'a -> ML 'a) (i:index 'a) =
match i with
| None -> None
| Some i -> Some (s i)
let join_index j d0 d1 =
match d0, d1 with
| None, d
| d, None -> d
| Some d0, Some d1 -> Some (j d0 d1)
let join_inv = join_index Inv_conj
let join_eloc = join_index Eloc_union
let join_disj = join_index Disj_conj
let rec subst_inv' subst (i:inv)
: inv
= match i with
| Inv_conj i j ->
Inv_conj (subst_inv' subst i)
(subst_inv' subst j)
| Inv_ptr x ->
Inv_ptr (T.subst_expr subst x)
| Inv_copy_buf x ->
Inv_copy_buf (T.subst_expr subst x)
let subst_inv s = subst_index (subst_inv' s)
let eq_tags e e' =
match e, e' with
| Eloc_output, Eloc_output
| Eloc_union _ _, Eloc_union _ _
| Eloc_ptr _, Eloc_ptr _
| Eloc_copy_buf _, Eloc_copy_buf _ -> true
| _ -> false
let rec subst_eloc' subst (e:eloc)
: ML (e':eloc { eq_tags e e' })
= match e with
| Eloc_output -> e
| Eloc_union i j ->
Eloc_union (subst_eloc' subst i)
(subst_eloc' subst j)
| Eloc_ptr x -> Eloc_ptr (T.subst_expr subst x)
| Eloc_copy_buf x ->
let y = T.subst_expr subst x in
if not (T.Identifier? (fst y))
then (
Ast.error "Unexpected non-identifier in subst_eloc" (snd x)
)
else
Eloc_copy_buf y
let subst_eloc s = subst_index (subst_eloc' s)
let rec subst_disj' subst (d:disj)
: ML disj
= match d with
| Disj_pair e1 e2 ->
Disj_pair (subst_eloc' subst e1)
(subst_eloc' subst e2)
| Disj_conj d1 d2 ->
Disj_conj (subst_disj' subst d1)
(subst_disj' subst d2)
let subst_disj s = subst_index (subst_disj' s)
noeq
type on_success =
| On_success : bool -> on_success
| On_success_named : A.ident -> list expr -> on_success
| On_success_union : on_success -> on_success -> on_success
let typ_indexes = index inv & index eloc & index disj & on_success
let typ_indexes_nil : typ_indexes = None, None, None, On_success false
let typ_indexes_union (i, e, d, b) (i', e', d', b') =
join_inv i i',
join_eloc e e',
join_disj d d',
On_success_union b b'
let env = H.t A.ident' type_decl
let create_env (_:unit) : ML env = H.create 100
let rec free_vars_of_expr (e:T.expr)
: ML (list A.ident)
= let open T in
match fst e with
| Constant _ -> []
| Identifier i -> [i]
| App _ args -> List.collect free_vars_of_expr args
| Record _ args -> List.collect (fun (_, e) -> free_vars_of_expr e) args
let map_index (def:'b) (f:'a -> ML 'b) (i:index 'a) : ML 'b =
match i with
| None -> def
| Some i -> f i
let rec free_vars_of_inv' (i:inv)
: ML (list A.ident)
= match i with
| Inv_conj i j -> free_vars_of_inv' i @ free_vars_of_inv' j
| Inv_ptr x -> free_vars_of_expr x
| Inv_copy_buf x -> free_vars_of_expr x
let free_vars_of_inv = map_index [] free_vars_of_inv'
let rec free_vars_of_eloc' (e:eloc)
: ML (list A.ident)
= match e with
| Eloc_output -> []
| Eloc_union i j -> free_vars_of_eloc' i @ free_vars_of_eloc' j
| Eloc_ptr x -> free_vars_of_expr x
| Eloc_copy_buf x -> free_vars_of_expr x
let free_vars_of_eloc = map_index [] free_vars_of_eloc'
let rec free_vars_of_disj' (d:disj)
: ML (list A.ident)
= match d with
| Disj_conj d0 d1 -> free_vars_of_disj' d0 @ free_vars_of_disj' d1
| Disj_pair i j -> free_vars_of_eloc' i @ free_vars_of_eloc' j
let free_vars_of_disj = map_index [] free_vars_of_disj'
let free_vars_of_typ_indexes (i:typ_indexes) =
let i, j, d, _ = i in
free_vars_of_inv i @
free_vars_of_eloc j @
free_vars_of_disj d
let filter_args_for_inv (args:list expr)
(td:type_decl)
: ML (list expr)
= let fvs = free_vars_of_typ_indexes td.typ_indexes in
let args =
List.map2
(fun (b, _) a ->
if Some? (List.tryFind (fun j -> A.ident_name b = A.ident_name j) fvs)
then [a]
else [])
td.name.td_params
args
in
List.flatten args
let itype_of_ident (hd:A.ident)
: option itype
= match hd.v.name with
| "UINT8" -> Some UInt8
| "UINT16" -> Some UInt16
| "UINT32" -> Some UInt32
| "UINT64" -> Some UInt64
| "UINT8BE" -> Some UInt8BE
| "UINT16BE" -> Some UInt16BE
| "UINT32BE" -> Some UInt32BE
| "UINT64BE" -> Some UInt64BE
| "unit" -> Some Unit
| "all_bytes" -> Some AllBytes
| "all_zeros" -> Some AllZeros
| _ -> None
let dtyp_of_app (en: env) (hd:A.ident) (args:list T.index)
: ML dtyp
= match itype_of_ident hd, args with
| Some i, [] ->
DT_IType i
| _ ->
let readable = match H.try_find en hd.v with
| None -> failwith "type not found"
| Some td -> td.allow_reading
in
DT_App readable hd
(List.map
(function Inl _ -> failwith "Unexpected type application"
| Inr e -> e)
args)
let tag_of_parser p
= let open T in
match p.p_parser with
| Parse_return _ -> "Parse_return"
| Parse_app _ _ -> "Parse_app"
| Parse_nlist _ _ -> "Parse_nlist"
| Parse_t_at_most _ _ -> "Parse_t_at_most"
| Parse_t_exact _ _ -> "Parse_t_exact"
| Parse_pair _ _ _ -> "Parse_pair"
| Parse_dep_pair _ _ _ -> "Parse_dep_pair"
| Parse_dep_pair_with_refinement _ _ _ _ -> "Parse_dep_pair_with_refinement"
| Parse_dep_pair_with_action _ _ _ -> "Parse_dep_pair_with_action"
| Parse_dep_pair_with_refinement_and_action _ _ _ _ _ -> "Parse_dep_pair_with_refinement_and_action"
| Parse_map _ _ -> "Parse_map"
| Parse_refinement _ _ _ -> "Parse_refinement"
| Parse_refinement_with_action _ _ _ _ -> "Parse_refinement_with_action"
| Parse_with_dep_action _ _ _ -> "Parse_with_dep_action"
| Parse_with_action _ _ _ -> "Parse_with_action"
| Parse_weaken_left _ _ -> "Parse_weaken_left"
| Parse_weaken_right _ _ -> "Parse_weaken_right"
| Parse_if_else _ _ _ -> "Parse_if_else"
| Parse_impos -> "Parse_impos"
| Parse_with_comment _ _ -> "Parse_with_comment"
| Parse_string _ _ -> "Parse_string"
| Parse_with_probe _ _ _ _ -> "Parse_with_probe"
let as_lam (x:T.lam 'a)
: lam 'a
= let i =
match fst x with
| None -> A.(with_dummy_range (to_ident' "_"))
| Some i -> i
in
i, snd x
let id_as_expr (i:A.ident) = T.mk_expr (T.Identifier i)
let rec typ_indexes_of_action (a:T.action)
: ML typ_indexes
= let open T in
let of_atomic_action (a:T.atomic_action)
: ML typ_indexes
= match a with
| Action_return _
| Action_abort
| Action_field_pos_32
| Action_field_pos_64 -> typ_indexes_nil
| Action_field_ptr_after _ write_to ->
Some (Inv_ptr (id_as_expr write_to)),
Some (Eloc_ptr (id_as_expr write_to)),
None,
On_success false
| Action_field_ptr_after_with_setter _ _ _ ->
None,
Some Eloc_output,
None,
On_success false
| Action_field_ptr ->
None, None, None, On_success true
| Action_deref x ->
Some (Inv_ptr (id_as_expr x)), None, None, On_success false
| Action_assignment x _ ->
Some (Inv_ptr (id_as_expr x)),
Some (Eloc_ptr (id_as_expr x)),
None,
On_success false
| Action_call f args ->
None,
Some Eloc_output,
None,
On_success false
in
match a with
| Atomic_action aa -> of_atomic_action aa
| Action_seq hd tl
| Action_let _ hd tl ->
typ_indexes_union (of_atomic_action hd) (typ_indexes_of_action tl)
| Action_ite _ a0 a1 ->
typ_indexes_union (typ_indexes_of_action a0) (typ_indexes_of_action a1)
| Action_act a ->
typ_indexes_of_action a
let rec typ_indexes_of_parser (en:env) (p:T.parser)
: ML typ_indexes
= let typ_indexes_of_parser = typ_indexes_of_parser en in
match p.p_parser with
| T.Parse_impos ->
typ_indexes_nil
| T.Parse_app hd args ->
let dt = dtyp_of_app en hd args in
begin
match dt with
| DT_IType _ ->
typ_indexes_nil
| DT_App _ hd args ->
let td =
match H.try_find en hd.v with
| Some td -> td
| _ -> failwith (Printf.sprintf "Type decl not found for %s" (A.ident_to_string hd))
in
let inv, eloc, disj, _ = td.typ_indexes in
let subst =
match T.mk_subst td.name.td_params args with
| None ->
failwith (Printf.sprintf "Unexpected number of arguments to type %s" (A.ident_to_string td.name.td_name))
| Some s -> s
in
subst_inv subst inv,
subst_eloc subst eloc,
subst_disj subst disj,
On_success_named hd args
end
| T.Parse_if_else _ p q
| T.Parse_pair _ p q ->
typ_indexes_union (typ_indexes_of_parser p) (typ_indexes_of_parser q)
| T.Parse_dep_pair _ p (_, q)
| T.Parse_dep_pair_with_refinement _ p _ (_, q) ->
typ_indexes_union (typ_indexes_of_parser p) (typ_indexes_of_parser q)
| T.Parse_weaken_left p _
| T.Parse_weaken_right p _
| T.Parse_refinement _ p _
| T.Parse_with_comment p _
| T.Parse_nlist _ p
| T.Parse_t_at_most _ p
| T.Parse_t_exact _ p ->
typ_indexes_of_parser p
| T.Parse_dep_pair_with_action p (_, a) (_, q)
| T.Parse_dep_pair_with_refinement_and_action _ p _ (_, a) (_, q) ->
typ_indexes_union
(typ_indexes_of_parser p)
(typ_indexes_union
(typ_indexes_of_action a)
(typ_indexes_of_parser q))
| T.Parse_with_action _ p a ->
typ_indexes_union
(typ_indexes_of_parser p)
(typ_indexes_of_action a)
| T.Parse_with_dep_action _ p (_, a) ->
typ_indexes_union
(typ_indexes_of_parser p)
(typ_indexes_of_action a)
| T.Parse_string p _ ->
typ_indexes_nil
| T.Parse_refinement_with_action n p f (_, a) ->
typ_indexes_union
(typ_indexes_of_parser p)
(typ_indexes_of_action a)
| T.Parse_with_probe p _ _ dest ->
let i, l, d, s = typ_indexes_of_parser p in
typ_indexes_union
(i, l, d, s)
(Some (Inv_copy_buf (id_as_expr dest)),
Some (Eloc_copy_buf (id_as_expr dest)),
disj_pair (Some (Eloc_copy_buf (id_as_expr dest))) l,
On_success true)
| T.Parse_map _ _
| T.Parse_return _ -> failwith "Unnecessary"
let typ_of_parser (en: env) : Tot (T.parser -> ML typ)
= let rec typ_of_parser (p:T.parser)
: ML typ
= let rec dtyp_of_parser (p:T.parser)
: ML dtyp
= match p.p_parser with
| T.Parse_app hd args ->
dtyp_of_app en hd args
| T.Parse_weaken_left p _
| T.Parse_weaken_right p _
| T.Parse_with_comment p _ ->
dtyp_of_parser p
| _ ->
failwith
(Printf.sprintf "Expected a named type, got %s"
(tag_of_parser p))
in
let fn = nes p.p_fieldname in
match p.p_parser with
| T.Parse_impos ->
T_false fn
| T.Parse_app _ _ ->
T_denoted fn (dtyp_of_parser p)
| T.Parse_pair _ p q ->
T_pair (nes p.p_fieldname) (typ_of_parser p) (typ_of_parser q)
| T.Parse_with_comment p c ->
T_with_comment fn (typ_of_parser p) (String.concat "; " c)
| T.Parse_nlist n p ->
T_nlist fn n (typ_of_parser p)
| T.Parse_t_at_most n p ->
T_at_most fn n (typ_of_parser p)
| T.Parse_t_exact n p ->
T_exact fn n (typ_of_parser p)
| T.Parse_if_else e p1 p2 ->
T_if_else e (typ_of_parser p1) (typ_of_parser p2)
| T.Parse_dep_pair _ p k ->
let i, k = as_lam k in
let d = dtyp_of_parser p in
if allow_reader_of_dtyp d
then
T_dep_pair (nes p.p_fieldname)
d
(i, typ_of_parser k)
else
failwith "typ_of_parser: Parse_dep_pair: tag not readable"
| T.Parse_dep_pair_with_refinement _ p r k ->
let i, r = as_lam r in
let j, k = as_lam k in
let d = dtyp_of_parser p in
if allow_reader_of_dtyp d
then
T_dep_pair_with_refinement fn d (i, r) (j, typ_of_parser k)
else
failwith "typ_of_parser: Parse_dep_pair_with_refinement: tag not readable"
| T.Parse_dep_pair_with_action p a k ->
let (i, k) = as_lam k in
let d = dtyp_of_parser p in
if allow_reader_of_dtyp d
then
T_dep_pair_with_action fn d (i, typ_of_parser k) (as_lam a)
else
failwith "typ_of_parser: Parse_dep_pair_with_action: tag not readable"
| T.Parse_dep_pair_with_refinement_and_action _ p r a k ->
let a = as_lam a in
let (i, k) = as_lam k in
let r = as_lam r in
let d = dtyp_of_parser p in
if allow_reader_of_dtyp d
then
T_dep_pair_with_refinement_and_action fn d r (i, typ_of_parser k) a
else
failwith "typ_of_parser: Parse_dep_pair_with_refinement_and_action: tag not readable"
| T.Parse_with_action _ p a ->
T_with_action fn (typ_of_parser p) a
| T.Parse_with_dep_action _ p a ->
let a = as_lam a in
let d = dtyp_of_parser p in
if allow_reader_of_dtyp d
then
T_with_dep_action fn d a
else
failwith "typ_of_parser: Parse_with_dep_action: tag not readable"
| T.Parse_string p z ->
let d = dtyp_of_parser p in
if allow_reader_of_dtyp d
then
T_string fn d z
else
failwith "typ_of_parser: Parse_string: element not readable"
| T.Parse_refinement _ p f ->
let d = dtyp_of_parser p in
if allow_reader_of_dtyp d
then
T_refine fn d (as_lam f)
else
failwith "typ_of_parser: Parse_refinement: element not readable"
| T.Parse_refinement_with_action _ p f a ->
let d = dtyp_of_parser p in
if allow_reader_of_dtyp d
then
T_refine_with_action fn d (as_lam f) (as_lam a)
else
failwith "typ_of_parser: Parse_refinement_with_action: element not readable"
| T.Parse_weaken_left p _
| T.Parse_weaken_right p _ ->
typ_of_parser p
| T.Parse_with_probe p probe_fn len dest ->
let d = dtyp_of_parser p in
T_probe_then_validate fn d probe_fn len dest
| T.Parse_map _ _
| T.Parse_return _ -> failwith "Unnecessary"
in typ_of_parser
let rec allow_reading_of_typ (t:typ)
: Tot bool
=
match t with
| T_with_comment _ t _ ->
allow_reading_of_typ t
| T_denoted _ dt ->
begin
match dt with
| DT_IType i -> allow_reader_of_itype i
| DT_App readable _ _ -> readable
end
| _ -> false
let check_validity_of_typ_indexes (td:T.type_decl) indexes =
let rec atomic_locs_of l =
match l with
| Eloc_output -> [l]
| Eloc_union l1 l2 -> atomic_locs_of l1 @ atomic_locs_of l2
| Eloc_ptr _ -> [l]
| Eloc_copy_buf _ -> [l]
in
let rec valid_disj (d:disj) : ML unit =
match d with
| Disj_conj d1 d2 ->
valid_disj d1;
valid_disj d2
| Disj_pair (Eloc_copy_buf (T.Identifier x, rx)) l2 ->
let l2_locs = atomic_locs_of l2 in
if List.existsb
(function
| Eloc_copy_buf (T.Identifier y, ry) -> A.eq_idents x y
| _ -> false)
l2_locs
then (
A.error (Printf.sprintf "Nested mutation of the copy buffer [%s]" (T.print_ident x))
td.decl_name.td_name.range
)
else ()
in
let _, _, disj, _ = indexes in
match disj with
| None -> ()
| Some disj -> valid_disj disj
let translate_decls (en:env) (ds:T.decls)
: ML (list decl)
= List.map
(fun d ->
match d with
| (T.Type_decl td, attrs) ->
let t = typ_of_parser en td.decl_parser in
let ar = allow_reading_of_typ t in
let refined =
if td.decl_is_enum
then match td.decl_typ with
| T.TD_abbrev t ->
if T.T_refine? t
then Some t
else None
| _ -> None
else None
in
let typ_indexes = typ_indexes_of_parser en td.decl_parser in
check_validity_of_typ_indexes td typ_indexes;
let td =
{ name = td.decl_name;
typ = typ_of_parser en td.decl_parser;
kind = td.decl_parser.p_kind;
typ_indexes;
allow_reading = ar;
attrs = attrs;
enum_typ = refined
}
in
H.insert en td.name.td_name.v td;
Inr td
| d ->
Inl (d <: not_type_decl))
ds
let print_ityp (i:itype) =
match i with
| UInt8 -> "UInt8"
| UInt16 -> "UInt16"
| UInt32 -> "UInt32"
| UInt64 -> "UInt64"
| UInt8BE -> "UInt8BE"
| UInt16BE -> "UInt16BE"
| UInt32BE -> "UInt32BE"
| UInt64BE -> "UInt64BE"
| Unit -> "Unit"
| AllBytes -> "AllBytes"
| AllZeros -> "AllZeros"
let print_ident (mname:string) (i:A.ident) =
T.print_maybe_qualified_ident mname i
let print_derived_name (mname:string) (tag:string) (i:A.ident) =
Printf.sprintf "%s%s_%s"
(T.maybe_mname_prefix mname i)
tag
(T.print_ident i)
let print_dtyp (mname:string) (dt:dtyp) =
match dt with
| DT_IType i ->
Printf.sprintf "(DT_IType %s)" (print_ityp i)
| DT_App _ hd args ->
Printf.sprintf "(%s %s)"
(print_derived_name mname "dtyp" hd)
(List.map (T.print_expr mname) args |> String.concat " ")
let print_lam (mname:string) (p:'a -> ML string) (x:lam 'a) =
Printf.sprintf "(fun %s -> %s)"
(print_ident mname (fst x))
(p (snd x))
let rec print_action (mname:string) (a:T.action)
: ML string
= let print_atomic_action (a:T.atomic_action)
: ML string
= match a with
| T.Action_return e ->
Printf.sprintf "(Action_return %s)"
(T.print_expr mname e)
| T.Action_abort ->
"Action_abort"
| T.Action_field_pos_64 ->
"Action_field_pos_64"
| T.Action_field_pos_32 ->
"(Action_field_pos_32 EverParse3d.Actions.BackendFlagValue.backend_flag_value)"
| T.Action_field_ptr ->
"(Action_field_ptr EverParse3d.Actions.BackendFlagValue.backend_flag_value)"
| T.Action_field_ptr_after sz write_to ->
Printf.sprintf
"(Action_field_ptr_after EverParse3d.Actions.BackendFlagValue.backend_flag_value %s %s)"
(T.print_expr mname sz)
(T.print_ident write_to)
| T.Action_field_ptr_after_with_setter sz write_to_field write_to_obj ->
Printf.sprintf
"(Action_field_ptr_after_with_setter EverParse3d.Actions.BackendFlagValue.backend_flag_value %s (%s %s))"
(T.print_expr mname sz)
(T.print_ident write_to_field)
(T.print_expr mname write_to_obj)
| T.Action_deref i ->
Printf.sprintf "(Action_deref %s)"
(print_ident mname i)
| T.Action_assignment lhs rhs ->
Printf.sprintf "(Action_assignment %s %s)"
(print_ident mname lhs)
(T.print_expr mname rhs)
| T.Action_call hd args ->
Printf.sprintf "(Action_call (mk_action_binding (%s %s)))"
(print_ident mname hd)
(List.map (T.print_expr mname) args |> String.concat " ")
in
match a with
| T.Atomic_action a ->
Printf.sprintf "(Atomic_action %s)"
(print_atomic_action a)
| T.Action_seq hd tl ->
Printf.sprintf "(Action_seq %s %s)"
(print_atomic_action hd)
(print_action mname tl)
| T.Action_ite hd then_ else_ ->
Printf.sprintf "(Action_ite %s (fun _ -> %s) (fun _ -> %s))"
(T.print_expr mname hd)
(print_action mname then_)
(print_action mname else_)
| T.Action_let i a k ->
Printf.sprintf "(Action_let %s %s)"
(print_atomic_action a)
(print_lam mname (print_action mname) (i, k))
| T.Action_act a ->
Printf.sprintf "(Action_act %s)"
(print_action mname a)
let rec print_typ (mname:string) (t:typ)
: ML string
= match t with
| T_false fn ->
Printf.sprintf "(T_false \"%s\")" fn
| T_denoted fn dt ->
Printf.sprintf "(T_denoted \"%s\" %s)"
fn
(print_dtyp mname dt)
| T_pair fn t1 t2 ->
Printf.sprintf "(T_pair \"%s\" %s %s)"
fn
(print_typ mname t1)
(print_typ mname t2)
| T_dep_pair fn t k ->
Printf.sprintf "(T_dep_pair \"%s\" %s %s)"
fn
(print_dtyp mname t)
(print_lam mname (print_typ mname) k)
| T_refine fn d r ->
Printf.sprintf "(T_refine \"%s\" %s %s)"
fn
(print_dtyp mname d)
(print_lam mname (T.print_expr mname) r)
| T_refine_with_action fn d r a ->
Printf.sprintf "(T_refine_with_action \"%s\" %s %s %s)"
fn
(print_dtyp mname d)
(print_lam mname (T.print_expr mname) r)
(print_lam mname (print_action mname) a)
| T_dep_pair_with_refinement fn d r k ->
Printf.sprintf "(T_dep_pair_with_refinement \"%s\" %s %s %s)"
fn
(print_dtyp mname d)
(print_lam mname (T.print_expr mname) r)
(print_lam mname (print_typ mname) k)
| T_dep_pair_with_action fn d k a ->
Printf.sprintf "(T_dep_pair_with_action \"%s\" %s %s %s)"
fn
(print_dtyp mname d)
(print_lam mname (print_typ mname) k)
(print_lam mname (print_action mname) a)
| T_dep_pair_with_refinement_and_action fn d r k a ->
Printf.sprintf "(T_dep_pair_with_refinement_and_action \"%s\" %s %s %s %s)"
fn
(print_dtyp mname d)
(print_lam mname (T.print_expr mname) r)
(print_lam mname (print_typ mname) k)
(print_lam mname (print_action mname) a)
| T_if_else e t1 t2 ->
Printf.sprintf "(T_cases %s %s %s)"
(T.print_expr mname e)
(print_typ mname t1)
(print_typ mname t2)
| T_with_action fn p a ->
Printf.sprintf "(T_with_action \"%s\" %s %s)"
fn
(print_typ mname p)
(print_action mname a)
| T_with_dep_action fn d a ->
Printf.sprintf "(T_with_dep_action \"%s\" %s %s)"
fn
(print_dtyp mname d)
(print_lam mname (print_action mname) a)
| T_with_comment fn t c ->
Printf.sprintf "(T_with_comment \"%s\" %s \"%s\")"
fn
(print_typ mname t)
c
| T_nlist fn n t ->
Printf.sprintf "(T_nlist \"%s\" %s %s)"
fn
(T.print_expr mname n)
(print_typ mname t)
| T_at_most fn n t ->
Printf.sprintf "(T_at_most \"%s\" %s %s)"
fn
(T.print_expr mname n)
(print_typ mname t)
| T_exact fn n t ->
Printf.sprintf "(T_exact \"%s\" %s %s)"
fn
(T.print_expr mname n)
(print_typ mname t)
| T_string fn d z ->
Printf.sprintf "(T_string \"%s\" %s %s)"
fn
(print_dtyp mname d)
(T.print_expr mname z)
| T_probe_then_validate fn dt probe_fn len dest ->
Printf.sprintf "(t_probe_then_validate \"%s\" %s %s %s %s)"
fn
(T.print_maybe_qualified_ident mname probe_fn)
(T.print_expr mname len)
(T.print_maybe_qualified_ident mname dest)
(print_dtyp mname dt)
let print_param mname (p:T.param) =
Printf.sprintf "(%s:%s)"
(print_ident mname (fst p))
(T.print_typ mname (snd p))
let print_typedef_name mname (n:T.typedef_name) =
Printf.sprintf "%s %s"
(print_ident mname n.td_name)
(List.map (print_param mname) n.td_params |> String.concat " ")
let print_type_decl mname (td:type_decl) =
FStar.Printf.sprintf
"[@@specialize; noextract_to \"krml\"]\n\
noextract\n\
let def_%s = ( %s <: Tot (typ _ _ _ _ _) by (T.norm [delta_attr [`%%specialize]; zeta; iota; primops]; T.smt()))\n"
(print_typedef_name mname td.name)
(print_typ mname td.typ)
let print_args mname (es:list expr) =
List.map (T.print_expr mname) es |> String.concat " "
let print_index (f: 'a -> ML string) (i:index 'a)
: ML string
= map_index "Trivial" (fun s -> Printf.sprintf "(NonTrivial %s)" (f s)) i
let rec print_inv' mname (i:inv)
: ML string
= match i with
| Inv_conj i j -> Printf.sprintf "(A.conj_inv %s %s)" (print_inv' mname i) (print_inv' mname j)
| Inv_ptr x -> Printf.sprintf "(A.ptr_inv %s)" (T.print_expr mname x)
| Inv_copy_buf x -> Printf.sprintf "(A.copy_buffer_inv %s)" (T.print_expr mname x)
let print_inv mname = print_index (print_inv' mname)
let rec print_eloc' mname (e:eloc)
: ML string
= match e with
| Eloc_output -> "output_loc" //This is a bit sketchy
| Eloc_union i j -> Printf.sprintf "(A.eloc_union %s %s)" (print_eloc' mname i) (print_eloc' mname j)
| Eloc_ptr x -> Printf.sprintf "(A.ptr_loc %s)" (T.print_expr mname x)
| Eloc_copy_buf x -> Printf.sprintf "(A.copy_buffer_loc %s)" (T.print_expr mname x)
let print_eloc mname = print_index (print_eloc' mname)
let rec print_disj' mname (d:disj)
: ML string
= match d with
| Disj_pair i j -> Printf.sprintf "(A.disjoint %s %s)" (print_eloc' mname i) (print_eloc' mname j)
| Disj_conj i j -> Printf.sprintf "(join_disj %s %s)" (print_disj' mname i) (print_disj' mname j)
let print_disj mname = print_index (print_disj' mname)
let print_td_iface is_entrypoint mname root_name binders args
inv eloc disj ar pk_wk pk_nz =
let kind_t =
Printf.sprintf "[@@noextract_to \"krml\"]\n\
inline_for_extraction\n\
noextract\n\
val kind_%s : P.parser_kind %b P.%s"
root_name
pk_nz
pk_wk
in
let def'_t =
Printf.sprintf "[@@noextract_to \"krml\"]\n\
noextract\n\
val def'_%s %s: typ kind_%s %s %s %s %b"
root_name
binders
root_name
inv disj eloc
ar
in
let validator_t =
Printf.sprintf "val validate_%s %s : validator_of %s (def'_%s %s)"
root_name
binders
(if is_entrypoint then "#false" else "")
root_name args
in
let dtyp_t =
Printf.sprintf "[@@specialize; noextract_to \"krml\"]\n\
noextract\n\
val dtyp_%s %s : dtyp_of (def'_%s %s)"
root_name
binders
root_name args
in
String.concat "\n\n" [kind_t; def'_t; validator_t; dtyp_t]
let print_binders mname binders =
List.map (print_param mname) binders |>
String.concat " "
let print_binders_as_args mname binders =
List.map (fun (i, _) -> print_ident mname i) binders |>
String.concat " "
let print_binding mname (td:type_decl)
: ML (string & string)
= let tdn = td.name in
let k = td.kind in
let typ = td.typ in
let root_name = print_ident mname tdn.td_name in
let print_binders = print_binders mname in
let print_args = print_binders_as_args mname in
let binders = print_binders tdn.td_params in
let args = print_args tdn.td_params in
let def = print_type_decl mname td in
let weak_kind = A.print_weak_kind k.pk_weak_kind in
let pk_of_binding =
Printf.sprintf "[@@noextract_to \"krml\"]\n\
inline_for_extraction noextract\n\
let kind_%s : P.parser_kind %s %s = coerce (_ by (T.norm [delta_only [`%%weak_kind_glb]; zeta; iota; primops]; T.trefl())) %s\n"
root_name
(string_of_bool k.pk_nz)
weak_kind
(T.print_kind mname k)
in
let inv, eloc, disj =
let inv, eloc, disj, _ = td.typ_indexes in
print_inv mname inv,
print_eloc mname eloc,
print_disj mname disj
in
let def' =
Printf.sprintf
"[@@specialize; noextract_to \"krml\"]\n\
noextract\n\
let def'_%s %s\n\
: typ kind_%s %s %s %s %s\n\
= coerce (_ by (coerce_validator [`%%kind_%s])) (def_%s %s)"
root_name
binders
root_name
inv disj eloc
(string_of_bool td.allow_reading)
root_name
root_name
args
in
let as_type_or_parser tag =
Printf.sprintf "[@@noextract_to \"krml\"]\n\
noextract\n
let %s_%s %s = (as_%s (def'_%s %s))"
tag
root_name
binders
tag
root_name
args
in
let validate_binding =
let cinline =
if td.name.td_entrypoint
|| td.attrs.is_exported
then ""
else "; CInline"
in
Printf.sprintf "[@@normalize_for_extraction specialization_steps%s]\n\
let validate_%s %s = as_validator \"%s\" (def'_%s %s)\n"
cinline
root_name
binders
root_name
root_name
args
in
let dtyp : string =
let reader =
if td.allow_reading
then Printf.sprintf "(Some (as_reader (def_%s %s)))"
root_name
args
else "None"
in
let coerce_validator =
Printf.sprintf "(T.norm [delta_only [`%%parser_%s; `%%type_%s; `%%coerce]]; T.trefl())"
root_name
root_name
in
Printf.sprintf "[@@specialize; noextract_to \"krml\"]\n\
noextract\n\
let dtyp_%s %s\n\
: dtyp kind_%s %b %s %s %s\n\
= mk_dtyp_app\n\
kind_%s\n\
%s\n\
%s\n\
%s\n\
(type_%s %s)\n\
(coerce (_ by (T.norm [delta_only [`%%type_%s]]; T.trefl())) (parser_%s %s))\n\
%s\n\
%b\n\
(coerce (_ by %s) (validate_%s %s))\n\
(_ by (T.norm [delta_only [`%%Some?]; iota]; T.trefl()))\n"
root_name binders
root_name td.allow_reading
inv disj eloc
root_name
inv disj eloc
root_name args
root_name
root_name args
reader
td.allow_reading
coerce_validator root_name args
in
let enum_typ_of_binding =
match td.enum_typ with
| None -> ""
| Some t ->
Printf.sprintf "let %s = %s\n"
root_name
(T.print_typ mname t)
in
let impl =
String.concat "\n"
[def;
pk_of_binding;
def';
(as_type_or_parser "type");
(as_type_or_parser "parser");
validate_binding;
dtyp;
enum_typ_of_binding]
in
// impl, ""
if Some? td.enum_typ
&& (td.name.td_entrypoint || td.attrs.is_exported)
then "", impl //exported enums are fully revealed
else if td.name.td_entrypoint
|| td.attrs.is_exported
then
let iface =
print_td_iface td.name.td_entrypoint
mname root_name binders args
inv eloc disj td.allow_reading
weak_kind k.pk_nz
in
impl, iface
else impl, ""
let print_decl mname (d:decl)
: ML (string & string) =
match d with
| Inl d ->
begin
match fst d with
| T.Assumption _ -> T.print_assumption mname d, ""
| T.Definition _ -> "", T.print_definition mname d
| _ -> "", ""
end
| Inr td -> print_binding mname td | {
"checked_file": "/",
"dependencies": [
"Target.fsti.checked",
"prims.fst.checked",
"Hashtable.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.All.fst.checked",
"Ast.fst.checked"
],
"interface_file": true,
"source_file": "InterpreterTarget.fst"
} | [
{
"abbrev": true,
"full_module": "Hashtable",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Ast",
"short_module": "A"
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Binding",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Ast",
"short_module": "A"
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Prims.list ('a * 'b) -> Prims.list 'a * Prims.list 'b | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"Prims.Nil",
"Prims.Cons",
"InterpreterTarget.unzip"
] | [
"recursion"
] | false | false | false | true | false | let rec unzip (x: list ('a & 'b)) : list 'a & list 'b =
| match x with
| [] -> [], []
| (x, y) :: tl ->
let xs, ys = unzip tl in
x :: xs, y :: ys | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.alloca_aes128_gcm | val alloca_aes128_gcm:alloca_st AES128_GCM | val alloca_aes128_gcm:alloca_st AES128_GCM | let alloca_aes128_gcm: alloca_st AES128_GCM =
alloca_aes_gcm Vale_AES128 | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 28,
"end_line": 193,
"start_col": 0,
"start_line": 192
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success
#pop-options
inline_for_extraction noextract
let create_in_aes_gcm (i: vale_impl):
create_in_st (alg_of_vale_impl i) =
fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale then (
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then (
let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success
) else
UnsupportedAlgorithm
) else
UnsupportedAlgorithm
let create_in_aes128_gcm: create_in_st AES128_GCM = create_in_aes_gcm Vale_AES128
let create_in_aes256_gcm: create_in_st AES256_GCM = create_in_aes_gcm Vale_AES256
let create_in #a r dst k =
match a with
| AES128_GCM -> create_in_aes128_gcm r dst k
| AES256_GCM -> create_in_aes256_gcm r dst k
| CHACHA20_POLY1305 -> create_in_chacha20_poly1305 r dst k
| _ -> UnsupportedAlgorithm
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
inline_for_extraction noextract
let alloca_chacha20_poly1305: alloca_st CHACHA20_POLY1305 =
fun k ->
let h0 = ST.get () in
let ek = B.alloca 0uy 32ul in
let p = B.alloca (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.loc_none h0 h3;
p
#pop-options
inline_for_extraction noextract
let alloca_aes_gcm (i: vale_impl):
alloca_st (alg_of_vale_impl i) =
fun k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
let ek = B.alloca 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.alloca (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
p | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.AEAD.alloca_st Spec.Agile.AEAD.AES128_GCM | Prims.Tot | [
"total"
] | [] | [
"EverCrypt.AEAD.alloca_aes_gcm",
"Spec.Cipher.Expansion.Vale_AES128"
] | [] | false | false | false | true | false | let alloca_aes128_gcm:alloca_st AES128_GCM =
| alloca_aes_gcm Vale_AES128 | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.create_in_aes256_gcm | val create_in_aes256_gcm:create_in_st AES256_GCM | val create_in_aes256_gcm:create_in_st AES256_GCM | let create_in_aes256_gcm: create_in_st AES256_GCM = create_in_aes_gcm Vale_AES256 | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 81,
"end_line": 153,
"start_col": 0,
"start_line": 153
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success
#pop-options
inline_for_extraction noextract
let create_in_aes_gcm (i: vale_impl):
create_in_st (alg_of_vale_impl i) =
fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale then (
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then (
let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success
) else
UnsupportedAlgorithm
) else
UnsupportedAlgorithm | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.AEAD.create_in_st Spec.Agile.AEAD.AES256_GCM | Prims.Tot | [
"total"
] | [] | [
"EverCrypt.AEAD.create_in_aes_gcm",
"Spec.Cipher.Expansion.Vale_AES256"
] | [] | false | false | false | true | false | let create_in_aes256_gcm:create_in_st AES256_GCM =
| create_in_aes_gcm Vale_AES256 | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.footprint_s | val footprint_s: #a:alg -> state_s a -> GTot B.loc | val footprint_s: #a:alg -> state_s a -> GTot B.loc | let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 56,
"end_line": 65,
"start_col": 0,
"start_line": 65
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: EverCrypt.AEAD.state_s a -> Prims.GTot LowStar.Monotonic.Buffer.loc | Prims.GTot | [
"sometrivial"
] | [] | [
"Spec.Agile.AEAD.alg",
"EverCrypt.AEAD.state_s",
"Spec.Cipher.Expansion.impl",
"FStar.Ghost.erased",
"Spec.Agile.AEAD.kv",
"LowStar.Buffer.buffer",
"FStar.UInt8.t",
"LowStar.Monotonic.Buffer.loc_addr_of_buffer",
"LowStar.Buffer.trivial_preorder",
"LowStar.Monotonic.Buffer.loc"
] | [] | false | false | false | false | false | let footprint_s #a (Ek _ _ ek) =
| B.loc_addr_of_buffer ek | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.as_kv | val as_kv: (#a: alg) -> state_s a -> GTot (kv a) | val as_kv: (#a: alg) -> state_s a -> GTot (kv a) | let as_kv #a (Ek _ kv _) =
G.reveal kv | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 13,
"end_line": 103,
"start_col": 0,
"start_line": 102
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: EverCrypt.AEAD.state_s a -> Prims.GTot (Spec.Agile.AEAD.kv a) | Prims.GTot | [
"sometrivial"
] | [] | [
"Spec.Agile.AEAD.alg",
"EverCrypt.AEAD.state_s",
"Spec.Cipher.Expansion.impl",
"FStar.Ghost.erased",
"Spec.Agile.AEAD.kv",
"LowStar.Buffer.buffer",
"FStar.UInt8.t",
"FStar.Ghost.reveal"
] | [] | false | false | false | false | false | let as_kv #a (Ek _ kv _) =
| G.reveal kv | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.freeable_s | val freeable_s: #(a: alg) -> state_s a -> Type0 | val freeable_s: #(a: alg) -> state_s a -> Type0 | let freeable_s #a (Ek _ _ ek) = B.freeable ek | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 63,
"start_col": 0,
"start_line": 63
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a) | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: EverCrypt.AEAD.state_s a -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Spec.Agile.AEAD.alg",
"EverCrypt.AEAD.state_s",
"Spec.Cipher.Expansion.impl",
"FStar.Ghost.erased",
"Spec.Agile.AEAD.kv",
"LowStar.Buffer.buffer",
"FStar.UInt8.t",
"LowStar.Monotonic.Buffer.freeable",
"LowStar.Buffer.trivial_preorder"
] | [] | false | false | false | false | true | let freeable_s #a (Ek _ _ ek) =
| B.freeable ek | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.alloca_aes256_gcm | val alloca_aes256_gcm:alloca_st AES256_GCM | val alloca_aes256_gcm:alloca_st AES256_GCM | let alloca_aes256_gcm: alloca_st AES256_GCM =
alloca_aes_gcm Vale_AES256 | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 28,
"end_line": 197,
"start_col": 0,
"start_line": 196
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success
#pop-options
inline_for_extraction noextract
let create_in_aes_gcm (i: vale_impl):
create_in_st (alg_of_vale_impl i) =
fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale then (
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then (
let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success
) else
UnsupportedAlgorithm
) else
UnsupportedAlgorithm
let create_in_aes128_gcm: create_in_st AES128_GCM = create_in_aes_gcm Vale_AES128
let create_in_aes256_gcm: create_in_st AES256_GCM = create_in_aes_gcm Vale_AES256
let create_in #a r dst k =
match a with
| AES128_GCM -> create_in_aes128_gcm r dst k
| AES256_GCM -> create_in_aes256_gcm r dst k
| CHACHA20_POLY1305 -> create_in_chacha20_poly1305 r dst k
| _ -> UnsupportedAlgorithm
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
inline_for_extraction noextract
let alloca_chacha20_poly1305: alloca_st CHACHA20_POLY1305 =
fun k ->
let h0 = ST.get () in
let ek = B.alloca 0uy 32ul in
let p = B.alloca (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.loc_none h0 h3;
p
#pop-options
inline_for_extraction noextract
let alloca_aes_gcm (i: vale_impl):
alloca_st (alg_of_vale_impl i) =
fun k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
let ek = B.alloca 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.alloca (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
p
inline_for_extraction noextract
let alloca_aes128_gcm: alloca_st AES128_GCM =
alloca_aes_gcm Vale_AES128 | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.AEAD.alloca_st Spec.Agile.AEAD.AES256_GCM | Prims.Tot | [
"total"
] | [] | [
"EverCrypt.AEAD.alloca_aes_gcm",
"Spec.Cipher.Expansion.Vale_AES256"
] | [] | false | false | false | true | false | let alloca_aes256_gcm:alloca_st AES256_GCM =
| alloca_aes_gcm Vale_AES256 | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.create_in_aes128_gcm | val create_in_aes128_gcm:create_in_st AES128_GCM | val create_in_aes128_gcm:create_in_st AES128_GCM | let create_in_aes128_gcm: create_in_st AES128_GCM = create_in_aes_gcm Vale_AES128 | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 81,
"end_line": 152,
"start_col": 0,
"start_line": 152
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success
#pop-options
inline_for_extraction noextract
let create_in_aes_gcm (i: vale_impl):
create_in_st (alg_of_vale_impl i) =
fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale then (
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then (
let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success
) else
UnsupportedAlgorithm
) else
UnsupportedAlgorithm | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.AEAD.create_in_st Spec.Agile.AEAD.AES128_GCM | Prims.Tot | [
"total"
] | [] | [
"EverCrypt.AEAD.create_in_aes_gcm",
"Spec.Cipher.Expansion.Vale_AES128"
] | [] | false | false | false | true | false | let create_in_aes128_gcm:create_in_st AES128_GCM =
| create_in_aes_gcm Vale_AES128 | false |
Vale.AES.PPC64LE.GHash.fsti | Vale.AES.PPC64LE.GHash.va_subscript_FStar__Seq__Base__seq | val va_subscript_FStar__Seq__Base__seq : s: FStar.Seq.Base.seq _ -> i: Prims.nat{i < FStar.Seq.Base.length s} -> _ | let va_subscript_FStar__Seq__Base__seq = Seq.index | {
"file_name": "obj/Vale.AES.PPC64LE.GHash.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 57,
"end_line": 37,
"start_col": 7,
"start_line": 37
} | module Vale.AES.PPC64LE.GHash
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.AES.AES_BE_s
open Vale.PPC64LE.Machine_s
open Vale.PPC64LE.Memory
open Vale.PPC64LE.State
open Vale.PPC64LE.Decls
open Vale.PPC64LE.InsBasic
open Vale.PPC64LE.InsMem
open Vale.PPC64LE.InsVector
open Vale.PPC64LE.QuickCode
open Vale.PPC64LE.QuickCodes
open Vale.AES.AES_helpers
open Vale.Poly1305.Math // For lemma_poly_bits64()
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.Arch.TypesNative
open Vale.AES.PPC64LE.PolyOps
open Vale.AES.PPC64LE.GF128_Mul
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Bits_s
open Vale.Math.Poly2.Bits
open Vale.Math.Poly2.Lemmas
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.AES.GHash_BE
#reset-options "--z3rlimit 50" | {
"checked_file": "/",
"dependencies": [
"Vale.PPC64LE.State.fsti.checked",
"Vale.PPC64LE.QuickCodes.fsti.checked",
"Vale.PPC64LE.QuickCode.fst.checked",
"Vale.PPC64LE.Memory.fsti.checked",
"Vale.PPC64LE.Machine_s.fst.checked",
"Vale.PPC64LE.InsVector.fsti.checked",
"Vale.PPC64LE.InsMem.fsti.checked",
"Vale.PPC64LE.InsBasic.fsti.checked",
"Vale.PPC64LE.Decls.fsti.checked",
"Vale.Poly1305.Math.fsti.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Lemmas.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Math.Poly2.Bits.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.AES.PPC64LE.PolyOps.fsti.checked",
"Vale.AES.PPC64LE.GF128_Mul.fsti.checked",
"Vale.AES.GHash_BE.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.fsti.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.AES_helpers.fsti.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.PPC64LE.GHash.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math // For lemma_poly_bits64()",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq _ -> i: Prims.nat{i < FStar.Seq.Base.length s} -> _ | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.index",
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length"
] | [] | false | false | false | false | false | let va_subscript_FStar__Seq__Base__seq =
| Seq.index | false |
|
Hacl.Impl.P256.Group.fst | Hacl.Impl.P256.Group.refl | val refl (p: LSeq.lseq uint64 12 {point_inv_seq p}) : GTot S.aff_point | val refl (p: LSeq.lseq uint64 12 {point_inv_seq p}) : GTot S.aff_point | let refl (p:LSeq.lseq uint64 12{point_inv_seq p}) : GTot S.aff_point =
S.to_aff_point (from_mont_point (as_point_nat_seq p)) | {
"file_name": "code/ecdsap256/Hacl.Impl.P256.Group.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 27,
"start_col": 0,
"start_line": 26
} | module Hacl.Impl.P256.Group
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module BE = Hacl.Impl.Exponentiation.Definitions
module S = Spec.P256
module SL = Spec.P256.Lemmas
open Hacl.Impl.P256.Point
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True | {
"checked_file": "/",
"dependencies": [
"Spec.P256.Lemmas.fsti.checked",
"Spec.P256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.P256.PointDouble.fsti.checked",
"Hacl.Impl.P256.PointAdd.fsti.checked",
"Hacl.Impl.P256.Point.fsti.checked",
"Hacl.Impl.Exponentiation.Definitions.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.Impl.P256.Group.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Lib.Sequence.lseq Lib.IntTypes.uint64 12 {Hacl.Impl.P256.Point.point_inv_seq p}
-> Prims.GTot Spec.P256.PointOps.aff_point | Prims.GTot | [
"sometrivial"
] | [] | [
"Lib.Sequence.lseq",
"Lib.IntTypes.uint64",
"Hacl.Impl.P256.Point.point_inv_seq",
"Spec.P256.PointOps.to_aff_point",
"Hacl.Impl.P256.Point.from_mont_point",
"Hacl.Impl.P256.Point.as_point_nat_seq",
"Spec.P256.PointOps.aff_point"
] | [] | false | false | false | false | false | let refl (p: LSeq.lseq uint64 12 {point_inv_seq p}) : GTot S.aff_point =
| S.to_aff_point (from_mont_point (as_point_nat_seq p)) | false |
Hacl.Impl.P256.Group.fst | Hacl.Impl.P256.Group.linv_ctx | val linv_ctx (a: LSeq.lseq uint64 0) : Type0 | val linv_ctx (a: LSeq.lseq uint64 0) : Type0 | let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True | {
"file_name": "code/ecdsap256/Hacl.Impl.P256.Group.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 23,
"start_col": 0,
"start_line": 23
} | module Hacl.Impl.P256.Group
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module BE = Hacl.Impl.Exponentiation.Definitions
module S = Spec.P256
module SL = Spec.P256.Lemmas
open Hacl.Impl.P256.Point
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0" | {
"checked_file": "/",
"dependencies": [
"Spec.P256.Lemmas.fsti.checked",
"Spec.P256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.P256.PointDouble.fsti.checked",
"Hacl.Impl.P256.PointAdd.fsti.checked",
"Hacl.Impl.P256.Point.fsti.checked",
"Hacl.Impl.Exponentiation.Definitions.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.Impl.P256.Group.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Lib.Sequence.lseq Lib.IntTypes.uint64 0 -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.Sequence.lseq",
"Lib.IntTypes.uint64",
"Prims.l_True"
] | [] | false | false | false | false | true | let linv_ctx (a: LSeq.lseq uint64 0) : Type0 =
| True | false |
Hacl.P256.PrecompTable.fst | Hacl.P256.PrecompTable.precomp_g_pow2_128_table_list_w4 | val precomp_g_pow2_128_table_list_w4:x: list uint64 {FStar.List.Tot.length x = 192} | val precomp_g_pow2_128_table_list_w4:x: list uint64 {FStar.List.Tot.length x = 192} | let precomp_g_pow2_128_table_list_w4: x:list uint64{FStar.List.Tot.length x = 192} =
normalize_term (SPT.precomp_base_table_list mk_p256_precomp_base_table proj_g_pow2_128 15) | {
"file_name": "code/ecdsap256/Hacl.P256.PrecompTable.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 92,
"end_line": 241,
"start_col": 0,
"start_line": 240
} | module Hacl.P256.PrecompTable
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module SPT = Hacl.Spec.PrecompBaseTable
module SPT256 = Hacl.Spec.PrecompBaseTable256
module SPTK = Hacl.Spec.P256.PrecompTable
module S = Spec.P256
module SL = Spec.P256.Lemmas
open Hacl.Impl.P256.Point
include Hacl.Impl.P256.Group
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let proj_point_to_list p =
SPTK.proj_point_to_list_lemma p;
SPTK.proj_point_to_list p
let lemma_refl x =
SPTK.proj_point_to_list_lemma x
//-----------------
inline_for_extraction noextract
let proj_g_pow2_64 : S.proj_point =
[@inline_let]
let rX : S.felem = 0x000931f4ae428a4ad81ee0aa89cf5247ce85d4dd696c61b4bb9d4761e57b7fbe in
[@inline_let]
let rY : S.felem = 0x7e88e5e6a142d5c2269f21a158e82ab2c79fcecb26e397b96fd5b9fbcd0a69a5 in
[@inline_let]
let rZ : S.felem = 0x02626dc2dd5e06cd19de5e6afb6c5dbdd3e41dc1472e7b8ef11eb0662e41c44b in
(rX, rY, rZ)
val lemma_proj_g_pow2_64_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops S.base_point 64 == proj_g_pow2_64)
let lemma_proj_g_pow2_64_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops S.base_point 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64);
let rX : S.felem = 0x000931f4ae428a4ad81ee0aa89cf5247ce85d4dd696c61b4bb9d4761e57b7fbe in
let rY : S.felem = 0x7e88e5e6a142d5c2269f21a158e82ab2c79fcecb26e397b96fd5b9fbcd0a69a5 in
let rZ : S.felem = 0x02626dc2dd5e06cd19de5e6afb6c5dbdd3e41dc1472e7b8ef11eb0662e41c44b in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
inline_for_extraction noextract
let proj_g_pow2_128 : S.proj_point =
[@inline_let]
let rX : S.felem = 0x04c3aaf6c6c00704e96eda89461d63fd2c97ee1e6786fc785e6afac7aa92f9b1 in
[@inline_let]
let rY : S.felem = 0x14f1edaeb8e9c8d4797d164a3946c7ff50a7c8cd59139a4dbce354e6e4df09c3 in
[@inline_let]
let rZ : S.felem = 0x80119ced9a5ce83c4e31f8de1a38f89d5f9ff9f637dca86d116a4217f83e55d2 in
(rX, rY, rZ)
val lemma_proj_g_pow2_128_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_64 64 == proj_g_pow2_128)
let lemma_proj_g_pow2_128_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_64 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64);
let rX : S.felem = 0x04c3aaf6c6c00704e96eda89461d63fd2c97ee1e6786fc785e6afac7aa92f9b1 in
let rY : S.felem = 0x14f1edaeb8e9c8d4797d164a3946c7ff50a7c8cd59139a4dbce354e6e4df09c3 in
let rZ : S.felem = 0x80119ced9a5ce83c4e31f8de1a38f89d5f9ff9f637dca86d116a4217f83e55d2 in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
inline_for_extraction noextract
let proj_g_pow2_192 : S.proj_point =
[@inline_let]
let rX : S.felem = 0xc762a9c8ae1b2f7434ff8da70fe105e0d4f188594989f193de0dbdbf5f60cb9a in
[@inline_let]
let rY : S.felem = 0x1eddaf51836859e1369f1ae8d9ab02e4123b6f151d9b796e297a38fa5613d9bc in
[@inline_let]
let rZ : S.felem = 0xcb433ab3f67815707e398dc7910cc4ec6ea115360060fc73c35b53dce02e2c72 in
(rX, rY, rZ)
val lemma_proj_g_pow2_192_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_128 64 == proj_g_pow2_192)
let lemma_proj_g_pow2_192_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_128 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64);
let rX : S.felem = 0xc762a9c8ae1b2f7434ff8da70fe105e0d4f188594989f193de0dbdbf5f60cb9a in
let rY : S.felem = 0x1eddaf51836859e1369f1ae8d9ab02e4123b6f151d9b796e297a38fa5613d9bc in
let rZ : S.felem = 0xcb433ab3f67815707e398dc7910cc4ec6ea115360060fc73c35b53dce02e2c72 in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
// let proj_g_pow2_64 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64)
// let proj_g_pow2_128 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64)
// let proj_g_pow2_192 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64)
inline_for_extraction noextract
let proj_g_pow2_64_list : SPTK.point_list =
normalize_term (SPTK.proj_point_to_list proj_g_pow2_64)
inline_for_extraction noextract
let proj_g_pow2_128_list : SPTK.point_list =
normalize_term (SPTK.proj_point_to_list proj_g_pow2_128)
inline_for_extraction noextract
let proj_g_pow2_192_list : SPTK.point_list =
normalize_term (SPTK.proj_point_to_list proj_g_pow2_192)
let proj_g_pow2_64_lseq : LSeq.lseq uint64 12 =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_64);
Seq.seq_of_list proj_g_pow2_64_list
let proj_g_pow2_128_lseq : LSeq.lseq uint64 12 =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_128);
Seq.seq_of_list proj_g_pow2_128_list
let proj_g_pow2_192_lseq : LSeq.lseq uint64 12 =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_192);
Seq.seq_of_list proj_g_pow2_192_list
val proj_g_pow2_64_lemma: unit ->
Lemma (S.to_aff_point proj_g_pow2_64 == pow_point (pow2 64) g_aff)
let proj_g_pow2_64_lemma () =
lemma_proj_g_pow2_64_eval ();
SPT256.a_pow2_64_lemma S.mk_p256_concrete_ops S.base_point
val proj_g_pow2_128_lemma: unit ->
Lemma (S.to_aff_point proj_g_pow2_128 == pow_point (pow2 128) g_aff)
let proj_g_pow2_128_lemma () =
lemma_proj_g_pow2_128_eval ();
lemma_proj_g_pow2_64_eval ();
SPT256.a_pow2_128_lemma S.mk_p256_concrete_ops S.base_point
val proj_g_pow2_192_lemma: unit ->
Lemma (S.to_aff_point proj_g_pow2_192 == pow_point (pow2 192) g_aff)
let proj_g_pow2_192_lemma () =
lemma_proj_g_pow2_192_eval ();
lemma_proj_g_pow2_128_eval ();
lemma_proj_g_pow2_64_eval ();
SPT256.a_pow2_192_lemma S.mk_p256_concrete_ops S.base_point
let proj_g_pow2_64_lseq_lemma () =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_64);
proj_g_pow2_64_lemma ();
SPTK.proj_point_to_list_lemma proj_g_pow2_64
let proj_g_pow2_128_lseq_lemma () =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_128);
proj_g_pow2_128_lemma ();
SPTK.proj_point_to_list_lemma proj_g_pow2_128
let proj_g_pow2_192_lseq_lemma () =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_192);
proj_g_pow2_192_lemma ();
SPTK.proj_point_to_list_lemma proj_g_pow2_192
let mk_proj_g_pow2_64 () =
createL proj_g_pow2_64_list
let mk_proj_g_pow2_128 () =
createL proj_g_pow2_128_list
let mk_proj_g_pow2_192 () =
createL proj_g_pow2_192_list
//----------------
/// window size = 4; precomputed table = [[0]G, [1]G, ..., [15]G]
inline_for_extraction noextract
let precomp_basepoint_table_list_w4: x:list uint64{FStar.List.Tot.length x = 192} =
normalize_term (SPT.precomp_base_table_list mk_p256_precomp_base_table S.base_point 15)
let precomp_basepoint_table_lseq_w4 : LSeq.lseq uint64 192 =
normalize_term_spec (SPT.precomp_base_table_list mk_p256_precomp_base_table S.base_point 15);
Seq.seq_of_list precomp_basepoint_table_list_w4
let precomp_basepoint_table_lemma_w4 () =
normalize_term_spec (SPT.precomp_base_table_list mk_p256_precomp_base_table S.base_point 15);
SPT.precomp_base_table_lemma mk_p256_precomp_base_table S.base_point 16 precomp_basepoint_table_lseq_w4
let precomp_basepoint_table_w4:
x:glbuffer uint64 192ul{witnessed x precomp_basepoint_table_lseq_w4 /\ recallable x} =
createL_global precomp_basepoint_table_list_w4
/// window size = 4; precomputed table = [[0]([pow2 64]G), [1]([pow2 64]G), ..., [15]([pow2 64]G)]
inline_for_extraction noextract
let precomp_g_pow2_64_table_list_w4: x:list uint64{FStar.List.Tot.length x = 192} =
normalize_term (SPT.precomp_base_table_list mk_p256_precomp_base_table proj_g_pow2_64 15)
let precomp_g_pow2_64_table_lseq_w4 : LSeq.lseq uint64 192 =
normalize_term_spec (SPT.precomp_base_table_list mk_p256_precomp_base_table proj_g_pow2_64 15);
Seq.seq_of_list precomp_g_pow2_64_table_list_w4
let precomp_g_pow2_64_table_lemma_w4 () =
normalize_term_spec (SPT.precomp_base_table_list mk_p256_precomp_base_table proj_g_pow2_64 15);
SPT.precomp_base_table_lemma mk_p256_precomp_base_table
proj_g_pow2_64 16 precomp_g_pow2_64_table_lseq_w4;
proj_g_pow2_64_lemma ()
let precomp_g_pow2_64_table_w4:
x:glbuffer uint64 192ul{witnessed x precomp_g_pow2_64_table_lseq_w4 /\ recallable x} =
createL_global precomp_g_pow2_64_table_list_w4
/// window size = 4; precomputed table = [[0]([pow2 128]G), [1]([pow2 128]G),...,[15]([pow2 128]G)] | {
"checked_file": "/",
"dependencies": [
"Spec.P256.Lemmas.fsti.checked",
"Spec.P256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.PrecompBaseTable256.fsti.checked",
"Hacl.Spec.PrecompBaseTable.fsti.checked",
"Hacl.Spec.P256.PrecompTable.fsti.checked",
"Hacl.Impl.P256.Point.fsti.checked",
"Hacl.Impl.P256.Group.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.P256.PrecompTable.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Group",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.PrecompTable",
"short_module": "SPTK"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable256",
"short_module": "SPT256"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable",
"short_module": "SPT"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Group",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable",
"short_module": "SPT"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x:
Prims.list (Lib.IntTypes.int_t Lib.IntTypes.U64 Lib.IntTypes.SEC)
{FStar.List.Tot.Base.length x = 192} | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.normalize_term",
"Prims.list",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.List.Tot.Base.length",
"Hacl.Spec.PrecompBaseTable.precomp_base_table_list",
"Spec.P256.PointOps.proj_point",
"FStar.UInt32.uint_to_t",
"Hacl.P256.PrecompTable.mk_p256_precomp_base_table",
"Hacl.P256.PrecompTable.proj_g_pow2_128"
] | [] | false | false | false | false | false | let precomp_g_pow2_128_table_list_w4:x: list uint64 {FStar.List.Tot.length x = 192} =
| normalize_term (SPT.precomp_base_table_list mk_p256_precomp_base_table proj_g_pow2_128 15) | false |
Hacl.Impl.P256.Group.fst | Hacl.Impl.P256.Group.point_zero | val point_zero : BE.lone_st U64 12ul 0ul mk_to_p256_comm_monoid | val point_zero : BE.lone_st U64 12ul 0ul mk_to_p256_comm_monoid | let point_zero ctx one =
let h0 = ST.get () in
SL.to_aff_point_at_infinity_lemma ();
make_point_at_inf one | {
"file_name": "code/ecdsap256/Hacl.Impl.P256.Group.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 23,
"end_line": 61,
"start_col": 0,
"start_line": 58
} | module Hacl.Impl.P256.Group
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module BE = Hacl.Impl.Exponentiation.Definitions
module S = Spec.P256
module SL = Spec.P256.Lemmas
open Hacl.Impl.P256.Point
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True
unfold
let refl (p:LSeq.lseq uint64 12{point_inv_seq p}) : GTot S.aff_point =
S.to_aff_point (from_mont_point (as_point_nat_seq p))
inline_for_extraction noextract
let mk_to_p256_comm_monoid : BE.to_comm_monoid U64 12ul 0ul = {
BE.a_spec = S.aff_point;
BE.comm_monoid = S.mk_p256_comm_monoid;
BE.linv_ctx = linv_ctx;
BE.linv = point_inv_seq;
BE.refl = refl;
}
inline_for_extraction noextract
val point_add : BE.lmul_st U64 12ul 0ul mk_to_p256_comm_monoid
let point_add ctx x y xy =
let h0 = ST.get () in
SL.to_aff_point_add_lemma
(from_mont_point (as_point_nat h0 x)) (from_mont_point (as_point_nat h0 y));
Hacl.Impl.P256.PointAdd.point_add xy x y
inline_for_extraction noextract
val point_double : BE.lsqr_st U64 12ul 0ul mk_to_p256_comm_monoid
let point_double ctx x xx =
let h0 = ST.get () in
SL.to_aff_point_double_lemma (from_mont_point (as_point_nat h0 x));
Hacl.Impl.P256.PointDouble.point_double xx x
inline_for_extraction noextract | {
"checked_file": "/",
"dependencies": [
"Spec.P256.Lemmas.fsti.checked",
"Spec.P256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.P256.PointDouble.fsti.checked",
"Hacl.Impl.P256.PointAdd.fsti.checked",
"Hacl.Impl.P256.Point.fsti.checked",
"Hacl.Impl.Exponentiation.Definitions.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.Impl.P256.Group.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Impl.Exponentiation.Definitions.lone_st Lib.IntTypes.U64
12ul
0ul
Hacl.Impl.P256.Group.mk_to_p256_comm_monoid | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.P256.Point.make_point_at_inf",
"Prims.unit",
"Spec.P256.Lemmas.to_aff_point_at_infinity_lemma",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | false | false | false | false | false | let point_zero ctx one =
| let h0 = ST.get () in
SL.to_aff_point_at_infinity_lemma ();
make_point_at_inf one | false |
Hacl.Impl.P256.Group.fst | Hacl.Impl.P256.Group.point_double | val point_double : BE.lsqr_st U64 12ul 0ul mk_to_p256_comm_monoid | val point_double : BE.lsqr_st U64 12ul 0ul mk_to_p256_comm_monoid | let point_double ctx x xx =
let h0 = ST.get () in
SL.to_aff_point_double_lemma (from_mont_point (as_point_nat h0 x));
Hacl.Impl.P256.PointDouble.point_double xx x | {
"file_name": "code/ecdsap256/Hacl.Impl.P256.Group.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 46,
"end_line": 53,
"start_col": 0,
"start_line": 50
} | module Hacl.Impl.P256.Group
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module BE = Hacl.Impl.Exponentiation.Definitions
module S = Spec.P256
module SL = Spec.P256.Lemmas
open Hacl.Impl.P256.Point
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True
unfold
let refl (p:LSeq.lseq uint64 12{point_inv_seq p}) : GTot S.aff_point =
S.to_aff_point (from_mont_point (as_point_nat_seq p))
inline_for_extraction noextract
let mk_to_p256_comm_monoid : BE.to_comm_monoid U64 12ul 0ul = {
BE.a_spec = S.aff_point;
BE.comm_monoid = S.mk_p256_comm_monoid;
BE.linv_ctx = linv_ctx;
BE.linv = point_inv_seq;
BE.refl = refl;
}
inline_for_extraction noextract
val point_add : BE.lmul_st U64 12ul 0ul mk_to_p256_comm_monoid
let point_add ctx x y xy =
let h0 = ST.get () in
SL.to_aff_point_add_lemma
(from_mont_point (as_point_nat h0 x)) (from_mont_point (as_point_nat h0 y));
Hacl.Impl.P256.PointAdd.point_add xy x y
inline_for_extraction noextract | {
"checked_file": "/",
"dependencies": [
"Spec.P256.Lemmas.fsti.checked",
"Spec.P256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.P256.PointDouble.fsti.checked",
"Hacl.Impl.P256.PointAdd.fsti.checked",
"Hacl.Impl.P256.Point.fsti.checked",
"Hacl.Impl.Exponentiation.Definitions.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.Impl.P256.Group.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Impl.Exponentiation.Definitions.lsqr_st Lib.IntTypes.U64
12ul
0ul
Hacl.Impl.P256.Group.mk_to_p256_comm_monoid | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.P256.PointDouble.point_double",
"Prims.unit",
"Spec.P256.Lemmas.to_aff_point_double_lemma",
"Hacl.Impl.P256.Point.from_mont_point",
"Hacl.Impl.P256.Point.as_point_nat",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | false | false | false | false | false | let point_double ctx x xx =
| let h0 = ST.get () in
SL.to_aff_point_double_lemma (from_mont_point (as_point_nat h0 x));
Hacl.Impl.P256.PointDouble.point_double xx x | false |
Vale.AES.PPC64LE.GHash.fsti | Vale.AES.PPC64LE.GHash.hkeys_b_powers | val hkeys_b_powers : hkeys_b: Vale.PPC64LE.Memory.buffer128 ->
heap0: Vale.PPC64LE.InsBasic.vale_heap ->
layout: Vale.Arch.HeapImpl.vale_heap_layout ->
ptr: Prims.int ->
h: Vale.Math.Poly2_s.poly
-> Prims.logical | let hkeys_b_powers (hkeys_b:buffer128) (heap0:vale_heap) (layout:vale_heap_layout) (ptr:int) (h:poly) =
validSrcAddrs128 heap0 ptr hkeys_b 3 layout Secret /\
of_quad32 (reverse_bytes_quad32 (buffer128_read hkeys_b 0 heap0)) == gf128_power h 1 /\
of_quad32 (reverse_bytes_quad32 (buffer128_read hkeys_b 1 heap0)) == gf128_power h 2 | {
"file_name": "obj/Vale.AES.PPC64LE.GHash.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 86,
"end_line": 42,
"start_col": 0,
"start_line": 39
} | module Vale.AES.PPC64LE.GHash
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.AES.AES_BE_s
open Vale.PPC64LE.Machine_s
open Vale.PPC64LE.Memory
open Vale.PPC64LE.State
open Vale.PPC64LE.Decls
open Vale.PPC64LE.InsBasic
open Vale.PPC64LE.InsMem
open Vale.PPC64LE.InsVector
open Vale.PPC64LE.QuickCode
open Vale.PPC64LE.QuickCodes
open Vale.AES.AES_helpers
open Vale.Poly1305.Math // For lemma_poly_bits64()
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.Arch.TypesNative
open Vale.AES.PPC64LE.PolyOps
open Vale.AES.PPC64LE.GF128_Mul
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Bits_s
open Vale.Math.Poly2.Bits
open Vale.Math.Poly2.Lemmas
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.AES.GHash_BE
#reset-options "--z3rlimit 50"
unfold let va_subscript_FStar__Seq__Base__seq = Seq.index | {
"checked_file": "/",
"dependencies": [
"Vale.PPC64LE.State.fsti.checked",
"Vale.PPC64LE.QuickCodes.fsti.checked",
"Vale.PPC64LE.QuickCode.fst.checked",
"Vale.PPC64LE.Memory.fsti.checked",
"Vale.PPC64LE.Machine_s.fst.checked",
"Vale.PPC64LE.InsVector.fsti.checked",
"Vale.PPC64LE.InsMem.fsti.checked",
"Vale.PPC64LE.InsBasic.fsti.checked",
"Vale.PPC64LE.Decls.fsti.checked",
"Vale.Poly1305.Math.fsti.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Lemmas.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Math.Poly2.Bits.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.AES.PPC64LE.PolyOps.fsti.checked",
"Vale.AES.PPC64LE.GF128_Mul.fsti.checked",
"Vale.AES.GHash_BE.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.fsti.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.AES_helpers.fsti.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.PPC64LE.GHash.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math // For lemma_poly_bits64()",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
hkeys_b: Vale.PPC64LE.Memory.buffer128 ->
heap0: Vale.PPC64LE.InsBasic.vale_heap ->
layout: Vale.Arch.HeapImpl.vale_heap_layout ->
ptr: Prims.int ->
h: Vale.Math.Poly2_s.poly
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.PPC64LE.Memory.buffer128",
"Vale.PPC64LE.InsBasic.vale_heap",
"Vale.Arch.HeapImpl.vale_heap_layout",
"Prims.int",
"Vale.Math.Poly2_s.poly",
"Prims.l_and",
"Vale.PPC64LE.Decls.validSrcAddrs128",
"Vale.Arch.HeapTypes_s.Secret",
"Prims.eq2",
"Vale.Math.Poly2.Bits_s.of_quad32",
"Vale.Def.Types_s.reverse_bytes_quad32",
"Vale.PPC64LE.Decls.buffer128_read",
"Vale.AES.GHash_BE.gf128_power",
"Prims.logical"
] | [] | false | false | false | true | true | let hkeys_b_powers
(hkeys_b: buffer128)
(heap0: vale_heap)
(layout: vale_heap_layout)
(ptr: int)
(h: poly)
=
| validSrcAddrs128 heap0 ptr hkeys_b 3 layout Secret /\
of_quad32 (reverse_bytes_quad32 (buffer128_read hkeys_b 0 heap0)) == gf128_power h 1 /\
of_quad32 (reverse_bytes_quad32 (buffer128_read hkeys_b 1 heap0)) == gf128_power h 2 | false |
|
IfcExampleReify3.fst | IfcExampleReify3.is_x | val is_x (hi: id) (x: int) : INT_STORE bool (fun s0 p -> p ((index s0 hi = x), s0)) | val is_x (hi: id) (x: int) : INT_STORE bool (fun s0 p -> p ((index s0 hi = x), s0)) | let is_x (hi:id) (x:int) :INT_STORE bool (fun s0 p -> p ((index s0 hi = x), s0)) =
read hi = x | {
"file_name": "examples/rel/IfcExampleReify3.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 13,
"end_line": 33,
"start_col": 0,
"start_line": 32
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module IfcExampleReify3
open FStar.DM4F.Heap.IntStoreFixed
open FStar.DM4F.IntStoreFixed
open Rel
type label =
| Low
| High
type env = id -> Tot label
type low_equiv (env:env) (h : rel heap) =
forall (x:id). {:pattern (Low? (env x))} (Low? (env x) ==> sel (R?.l h) x = sel (R?.r h) x) | {
"checked_file": "/",
"dependencies": [
"Rel.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.DM4F.IntStoreFixed.fst.checked",
"FStar.DM4F.Heap.IntStoreFixed.fsti.checked"
],
"interface_file": false,
"source_file": "IfcExampleReify3.fst"
} | [
{
"abbrev": false,
"full_module": "Rel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F.IntStoreFixed",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F.Heap.IntStoreFixed",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | hi: FStar.DM4F.Heap.IntStoreFixed.id -> x: Prims.int
-> FStar.DM4F.IntStoreFixed.INT_STORE Prims.bool | FStar.DM4F.IntStoreFixed.INT_STORE | [] | [] | [
"FStar.DM4F.Heap.IntStoreFixed.id",
"Prims.int",
"Prims.op_Equality",
"Prims.bool",
"FStar.DM4F.IntStoreFixed.read",
"FStar.DM4F.Heap.IntStoreFixed.heap",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"FStar.DM4F.Heap.IntStoreFixed.index"
] | [] | false | true | false | false | false | let is_x (hi: id) (x: int) : INT_STORE bool (fun s0 p -> p ((index s0 hi = x), s0)) =
| read hi = x | false |
IfcExampleReify3.fst | IfcExampleReify3.p1 | val p1 : x: FStar.DM4F.Heap.IntStoreFixed.id ->
y: FStar.DM4F.Heap.IntStoreFixed.id ->
hi: FStar.DM4F.Heap.IntStoreFixed.id
-> FStar.DM4F.IntStoreFixed.INT_STORE Prims.unit | let p1 x y hi =
begin if is_x hi 0 then
let vx = read x in
let vy = read y in
write x (vx + vy)
else
let vx = read x in
let vy = read y in
let vhi = read hi in
write x (vx + vy + vhi)
end ;
let vx = read x in
let vhi = read hi in
write x (vx - vhi) | {
"file_name": "examples/rel/IfcExampleReify3.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 20,
"end_line": 48,
"start_col": 1,
"start_line": 35
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module IfcExampleReify3
open FStar.DM4F.Heap.IntStoreFixed
open FStar.DM4F.IntStoreFixed
open Rel
type label =
| Low
| High
type env = id -> Tot label
type low_equiv (env:env) (h : rel heap) =
forall (x:id). {:pattern (Low? (env x))} (Low? (env x) ==> sel (R?.l h) x = sel (R?.r h) x)
(* AR: need to investigate what's happening without this is_x in p1 *)
let is_x (hi:id) (x:int) :INT_STORE bool (fun s0 p -> p ((index s0 hi = x), s0)) =
read hi = x | {
"checked_file": "/",
"dependencies": [
"Rel.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.DM4F.IntStoreFixed.fst.checked",
"FStar.DM4F.Heap.IntStoreFixed.fsti.checked"
],
"interface_file": false,
"source_file": "IfcExampleReify3.fst"
} | [
{
"abbrev": false,
"full_module": "Rel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F.IntStoreFixed",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F.Heap.IntStoreFixed",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
x: FStar.DM4F.Heap.IntStoreFixed.id ->
y: FStar.DM4F.Heap.IntStoreFixed.id ->
hi: FStar.DM4F.Heap.IntStoreFixed.id
-> FStar.DM4F.IntStoreFixed.INT_STORE Prims.unit | FStar.DM4F.IntStoreFixed.INT_STORE | [] | [] | [
"FStar.DM4F.Heap.IntStoreFixed.id",
"FStar.DM4F.IntStoreFixed.write",
"Prims.op_Subtraction",
"Prims.unit",
"Prims.int",
"FStar.DM4F.IntStoreFixed.read",
"Prims.op_Addition",
"Prims.bool",
"IfcExampleReify3.is_x"
] | [] | false | true | false | false | false | let p1 x y hi =
| if is_x hi 0
then
let vx = read x in
let vy = read y in
write x (vx + vy)
else
(let vx = read x in
let vy = read y in
let vhi = read hi in
write x (vx + vy + vhi));
let vx = read x in
let vhi = read hi in
write x (vx - vhi) | false |
|
IfcExampleReify3.fst | IfcExampleReify3.p1_r | val p1_r : x: FStar.DM4F.Heap.IntStoreFixed.id ->
y: FStar.DM4F.Heap.IntStoreFixed.id ->
hi: FStar.DM4F.Heap.IntStoreFixed.id ->
h: FStar.DM4F.Heap.IntStoreFixed.heap
-> FStar.DM4F.Heap.IntStoreFixed.heap | let p1_r x y hi h = (snd (reify (p1 x y hi) h)) | {
"file_name": "examples/rel/IfcExampleReify3.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 47,
"end_line": 51,
"start_col": 0,
"start_line": 51
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module IfcExampleReify3
open FStar.DM4F.Heap.IntStoreFixed
open FStar.DM4F.IntStoreFixed
open Rel
type label =
| Low
| High
type env = id -> Tot label
type low_equiv (env:env) (h : rel heap) =
forall (x:id). {:pattern (Low? (env x))} (Low? (env x) ==> sel (R?.l h) x = sel (R?.r h) x)
(* AR: need to investigate what's happening without this is_x in p1 *)
let is_x (hi:id) (x:int) :INT_STORE bool (fun s0 p -> p ((index s0 hi = x), s0)) =
read hi = x
let p1 x y hi =
begin if is_x hi 0 then
let vx = read x in
let vy = read y in
write x (vx + vy)
else
let vx = read x in
let vy = read y in
let vhi = read hi in
write x (vx + vy + vhi)
end ;
let vx = read x in
let vhi = read hi in
write x (vx - vhi) | {
"checked_file": "/",
"dependencies": [
"Rel.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.DM4F.IntStoreFixed.fst.checked",
"FStar.DM4F.Heap.IntStoreFixed.fsti.checked"
],
"interface_file": false,
"source_file": "IfcExampleReify3.fst"
} | [
{
"abbrev": false,
"full_module": "Rel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F.IntStoreFixed",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F.Heap.IntStoreFixed",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
x: FStar.DM4F.Heap.IntStoreFixed.id ->
y: FStar.DM4F.Heap.IntStoreFixed.id ->
hi: FStar.DM4F.Heap.IntStoreFixed.id ->
h: FStar.DM4F.Heap.IntStoreFixed.heap
-> FStar.DM4F.Heap.IntStoreFixed.heap | Prims.Tot | [
"total"
] | [] | [
"FStar.DM4F.Heap.IntStoreFixed.id",
"FStar.DM4F.Heap.IntStoreFixed.heap",
"FStar.Pervasives.Native.snd",
"Prims.unit",
"IfcExampleReify3.p1"
] | [] | false | false | false | true | false | let p1_r x y hi h =
| (snd (reify (p1 x y hi) h)) | false |
|
Vale.AES.PPC64LE.GHash.fsti | Vale.AES.PPC64LE.GHash.va_wp_GhashUnroll_n | val va_wp_GhashUnroll_n
(exactly2: bool)
(in_b: buffer128)
(index: nat)
(h_BE y_prev: quad32)
(data: (seq quad32))
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | val va_wp_GhashUnroll_n
(exactly2: bool)
(in_b: buffer128)
(index: nat)
(h_BE y_prev: quad32)
(data: (seq quad32))
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | let va_wp_GhashUnroll_n (exactly2:bool) (in_b:buffer128) (index:nat) (h_BE:quad32) (y_prev:quad32)
(data:(seq quad32)) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in
let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in (exactly2 ==> n == 2) /\
(~exactly2 ==> n == 1) /\ in_b_blocks in_b index n (va_get_mem_heaplet 1 va_s0)
(va_get_mem_layout va_s0) (va_get_reg 7 va_s0) data /\ Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 1 va_s0) == prev /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 5 va_s0) ==
Vale.Math.Poly2.swap (Vale.AES.GHash_BE.gf128_power h 1) 64 /\ Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 6 va_s0) == Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.div
(Vale.AES.GHash_BE.gf128_power h 1) (Vale.Math.Poly2_s.monomial 64))
(Vale.Math.Poly2_s.monomial 64) /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 7 va_s0) ==
Vale.Math.Poly2_s.mod (Vale.AES.GHash_BE.gf128_power h 1) (Vale.Math.Poly2_s.monomial 64) /\
(exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 12 va_s0) == Vale.Math.Poly2.swap
(Vale.AES.GHash_BE.gf128_power h 2) 64) /\ (exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 13 va_s0) == Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.div
(Vale.AES.GHash_BE.gf128_power h 2) (Vale.Math.Poly2_s.monomial 64))
(Vale.Math.Poly2_s.monomial 64)) /\ (exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec
14 va_s0) == Vale.Math.Poly2_s.mod (Vale.AES.GHash_BE.gf128_power h 2)
(Vale.Math.Poly2_s.monomial 64))) /\ (forall (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32)
(va_x_v2:quad32) (va_x_v3:quad32) (va_x_v4:quad32) (va_x_v8:quad32) (va_x_v9:quad32)
(va_x_v10:quad32) (va_x_v11:quad32) . let va_sM = va_upd_vec 11 va_x_v11 (va_upd_vec 10
va_x_v10 (va_upd_vec 9 va_x_v9 (va_upd_vec 8 va_x_v8 (va_upd_vec 4 va_x_v4 (va_upd_vec 3
va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 (va_upd_reg 10
va_x_r10 va_s0))))))))) in va_get_ok va_sM /\ (let (h:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let (prev:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let (pdata:(Prims.int -> Vale.AES.GHash_BE.poly128))
= Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128 data in let (n:Prims.nat) = FStar.Seq.Base.length
#quad32 data in va_get_vec 1 va_sM == Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data) ==>
va_k va_sM (()))) | {
"file_name": "obj/Vale.AES.PPC64LE.GHash.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 21,
"end_line": 188,
"start_col": 0,
"start_line": 158
} | module Vale.AES.PPC64LE.GHash
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.AES.AES_BE_s
open Vale.PPC64LE.Machine_s
open Vale.PPC64LE.Memory
open Vale.PPC64LE.State
open Vale.PPC64LE.Decls
open Vale.PPC64LE.InsBasic
open Vale.PPC64LE.InsMem
open Vale.PPC64LE.InsVector
open Vale.PPC64LE.QuickCode
open Vale.PPC64LE.QuickCodes
open Vale.AES.AES_helpers
open Vale.Poly1305.Math // For lemma_poly_bits64()
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.Arch.TypesNative
open Vale.AES.PPC64LE.PolyOps
open Vale.AES.PPC64LE.GF128_Mul
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Bits_s
open Vale.Math.Poly2.Bits
open Vale.Math.Poly2.Lemmas
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.AES.GHash_BE
#reset-options "--z3rlimit 50"
unfold let va_subscript_FStar__Seq__Base__seq = Seq.index
let hkeys_b_powers (hkeys_b:buffer128) (heap0:vale_heap) (layout:vale_heap_layout) (ptr:int) (h:poly) =
validSrcAddrs128 heap0 ptr hkeys_b 3 layout Secret /\
of_quad32 (reverse_bytes_quad32 (buffer128_read hkeys_b 0 heap0)) == gf128_power h 1 /\
of_quad32 (reverse_bytes_quad32 (buffer128_read hkeys_b 1 heap0)) == gf128_power h 2
let in_b_blocks
(in_b:buffer128) (in_index count:int) (heap_s:vale_heap) (layout:vale_heap_layout) (ptr:int) (data:seq quad32)
=
validSrcAddrsOffset128 heap_s ptr in_b in_index count layout Secret /\
(forall (i:nat).{:pattern (index data i)}
i < count /\ i < length data ==>
reverse_bytes_quad32 (buffer128_read in_b (in_index + i) heap_s) == index data i)
//-- ReduceLast
val va_code_ReduceLast : va_dummy:unit -> Tot va_code
val va_codegen_success_ReduceLast : va_dummy:unit -> Tot va_pbool
val va_lemma_ReduceLast : va_b0:va_code -> va_s0:va_state -> h_BE:quad32 -> y_prev:quad32 ->
data:(seq quad32)
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_ReduceLast ()) va_s0 /\ va_get_ok va_s0 /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in va_get_vec 8 va_s0 ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 3254779904 0 0 /\ n > 0 /\ add (add
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 2 va_s0)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 3 va_s0)) 64)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 4 va_s0)) 128) ==
Vale.AES.GHash_BE.ghash_unroll_back h prev pdata 0 n (n - 1))))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in let xi =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_sM) in Vale.Math.Poly2.Bits_s.to_quad32 xi ==
Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data /\ xi == Vale.Math.Poly2.Bits_s.of_quad32
(Vale.Math.Poly2.Bits_s.to_quad32 xi)) /\ va_state_eq va_sM (va_update_vec 10 va_sM
(va_update_vec 9 va_sM (va_update_vec 8 va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM
(va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0 va_sM (va_update_ok va_sM
va_s0)))))))))))
[@ va_qattr]
let va_wp_ReduceLast (h_BE:quad32) (y_prev:quad32) (data:(seq quad32)) (va_s0:va_state)
(va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in
let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in va_get_vec 8 va_s0 ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 3254779904 0 0 /\ n > 0 /\ add (add
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 2 va_s0)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 3 va_s0)) 64)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 4 va_s0)) 128) ==
Vale.AES.GHash_BE.ghash_unroll_back h prev pdata 0 n (n - 1)) /\ (forall (va_x_v0:quad32)
(va_x_v1:quad32) (va_x_v2:quad32) (va_x_v3:quad32) (va_x_v4:quad32) (va_x_v8:quad32)
(va_x_v9:quad32) (va_x_v10:quad32) . let va_sM = va_upd_vec 10 va_x_v10 (va_upd_vec 9 va_x_v9
(va_upd_vec 8 va_x_v8 (va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2
(va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 va_s0))))))) in va_get_ok va_sM /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in let xi =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_sM) in Vale.Math.Poly2.Bits_s.to_quad32 xi ==
Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data /\ xi == Vale.Math.Poly2.Bits_s.of_quad32
(Vale.Math.Poly2.Bits_s.to_quad32 xi)) ==> va_k va_sM (())))
val va_wpProof_ReduceLast : h_BE:quad32 -> y_prev:quad32 -> data:(seq quad32) -> va_s0:va_state ->
va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_ReduceLast h_BE y_prev data va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_ReduceLast ()) ([va_Mod_vec 10;
va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec
0]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_ReduceLast (h_BE:quad32) (y_prev:quad32) (data:(seq quad32)) : (va_quickCode unit
(va_code_ReduceLast ())) =
(va_QProc (va_code_ReduceLast ()) ([va_Mod_vec 10; va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 4;
va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0]) (va_wp_ReduceLast h_BE y_prev data)
(va_wpProof_ReduceLast h_BE y_prev data))
//--
//-- GhashUnroll_n
val va_code_GhashUnroll_n : exactly2:bool -> Tot va_code
val va_codegen_success_GhashUnroll_n : exactly2:bool -> Tot va_pbool
val va_lemma_GhashUnroll_n : va_b0:va_code -> va_s0:va_state -> exactly2:bool -> in_b:buffer128 ->
index:nat -> h_BE:quad32 -> y_prev:quad32 -> data:(seq quad32)
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_GhashUnroll_n exactly2) va_s0 /\ va_get_ok va_s0 /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in (exactly2 ==> n == 2) /\
(~exactly2 ==> n == 1) /\ in_b_blocks in_b index n (va_get_mem_heaplet 1 va_s0)
(va_get_mem_layout va_s0) (va_get_reg 7 va_s0) data /\ Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 1 va_s0) == prev /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 5 va_s0) ==
Vale.Math.Poly2.swap (Vale.AES.GHash_BE.gf128_power h 1) 64 /\ Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 6 va_s0) == Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.div
(Vale.AES.GHash_BE.gf128_power h 1) (Vale.Math.Poly2_s.monomial 64))
(Vale.Math.Poly2_s.monomial 64) /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 7 va_s0) ==
Vale.Math.Poly2_s.mod (Vale.AES.GHash_BE.gf128_power h 1) (Vale.Math.Poly2_s.monomial 64) /\
(exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 12 va_s0) == Vale.Math.Poly2.swap
(Vale.AES.GHash_BE.gf128_power h 2) 64) /\ (exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 13 va_s0) == Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.div
(Vale.AES.GHash_BE.gf128_power h 2) (Vale.Math.Poly2_s.monomial 64))
(Vale.Math.Poly2_s.monomial 64)) /\ (exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec
14 va_s0) == Vale.Math.Poly2_s.mod (Vale.AES.GHash_BE.gf128_power h 2)
(Vale.Math.Poly2_s.monomial 64)))))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in va_get_vec 1 va_sM ==
Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data) /\ va_state_eq va_sM (va_update_vec 11
va_sM (va_update_vec 10 va_sM (va_update_vec 9 va_sM (va_update_vec 8 va_sM (va_update_vec 4
va_sM (va_update_vec 3 va_sM (va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0
va_sM (va_update_reg 10 va_sM (va_update_ok va_sM va_s0))))))))))))) | {
"checked_file": "/",
"dependencies": [
"Vale.PPC64LE.State.fsti.checked",
"Vale.PPC64LE.QuickCodes.fsti.checked",
"Vale.PPC64LE.QuickCode.fst.checked",
"Vale.PPC64LE.Memory.fsti.checked",
"Vale.PPC64LE.Machine_s.fst.checked",
"Vale.PPC64LE.InsVector.fsti.checked",
"Vale.PPC64LE.InsMem.fsti.checked",
"Vale.PPC64LE.InsBasic.fsti.checked",
"Vale.PPC64LE.Decls.fsti.checked",
"Vale.Poly1305.Math.fsti.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Lemmas.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Math.Poly2.Bits.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.AES.PPC64LE.PolyOps.fsti.checked",
"Vale.AES.PPC64LE.GF128_Mul.fsti.checked",
"Vale.AES.GHash_BE.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.fsti.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.AES_helpers.fsti.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.PPC64LE.GHash.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math // For lemma_poly_bits64()",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
exactly2: Prims.bool ->
in_b: Vale.PPC64LE.Memory.buffer128 ->
index: Prims.nat ->
h_BE: Vale.PPC64LE.Memory.quad32 ->
y_prev: Vale.PPC64LE.Memory.quad32 ->
data: FStar.Seq.Base.seq Vale.PPC64LE.Memory.quad32 ->
va_s0: Vale.PPC64LE.Decls.va_state ->
va_k: (_: Vale.PPC64LE.Decls.va_state -> _: Prims.unit -> Type0)
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Vale.PPC64LE.Memory.buffer128",
"Prims.nat",
"Vale.PPC64LE.Memory.quad32",
"FStar.Seq.Base.seq",
"Vale.PPC64LE.Decls.va_state",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Vale.PPC64LE.Decls.va_get_ok",
"Prims.l_imp",
"Prims.eq2",
"Prims.int",
"Prims.l_not",
"Vale.AES.PPC64LE.GHash.in_b_blocks",
"Vale.PPC64LE.Decls.va_get_mem_heaplet",
"Vale.PPC64LE.Decls.va_get_mem_layout",
"Vale.PPC64LE.Decls.va_get_reg",
"Vale.Math.Poly2_s.poly",
"Vale.Math.Poly2.Bits_s.of_quad32",
"Vale.PPC64LE.Decls.va_get_vec",
"Vale.Math.Poly2.swap",
"Vale.AES.GHash_BE.gf128_power",
"Vale.Math.Poly2_s.mul",
"Vale.Math.Poly2_s.div",
"Vale.Math.Poly2_s.monomial",
"Vale.Math.Poly2_s.mod",
"FStar.Seq.Base.length",
"Vale.AES.GHash_BE.poly128",
"Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128",
"Prims.l_Forall",
"Vale.PPC64LE.Memory.nat64",
"Vale.Def.Types_s.quad32",
"Vale.AES.GHash_BE.ghash_incremental",
"Vale.PPC64LE.Machine_s.state",
"Vale.PPC64LE.Decls.va_upd_vec",
"Vale.PPC64LE.Decls.va_upd_reg"
] | [] | false | false | false | true | true | let va_wp_GhashUnroll_n
(exactly2: bool)
(in_b: buffer128)
(index: nat)
(h_BE y_prev: quad32)
(data: (seq quad32))
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 =
| (va_get_ok va_s0 /\
(let h:Vale.Math.Poly2_s.poly = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in
let prev:Vale.Math.Poly2_s.poly = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in
let pdata:(Prims.int -> Vale.AES.GHash_BE.poly128) =
Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128 data
in
let n:Prims.nat = FStar.Seq.Base.length #quad32 data in
(exactly2 ==> n == 2) /\ (~exactly2 ==> n == 1) /\
in_b_blocks in_b
index
n
(va_get_mem_heaplet 1 va_s0)
(va_get_mem_layout va_s0)
(va_get_reg 7 va_s0)
data /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_s0) == prev /\
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 5 va_s0) ==
Vale.Math.Poly2.swap (Vale.AES.GHash_BE.gf128_power h 1) 64 /\
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 6 va_s0) ==
Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.div (Vale.AES.GHash_BE.gf128_power h 1)
(Vale.Math.Poly2_s.monomial 64))
(Vale.Math.Poly2_s.monomial 64) /\
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 7 va_s0) ==
Vale.Math.Poly2_s.mod (Vale.AES.GHash_BE.gf128_power h 1) (Vale.Math.Poly2_s.monomial 64) /\
(exactly2 ==>
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 12 va_s0) ==
Vale.Math.Poly2.swap (Vale.AES.GHash_BE.gf128_power h 2) 64) /\
(exactly2 ==>
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 13 va_s0) ==
Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.div (Vale.AES.GHash_BE.gf128_power h 2)
(Vale.Math.Poly2_s.monomial 64))
(Vale.Math.Poly2_s.monomial 64)) /\
(exactly2 ==>
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 14 va_s0) ==
Vale.Math.Poly2_s.mod (Vale.AES.GHash_BE.gf128_power h 2) (Vale.Math.Poly2_s.monomial 64))) /\
(forall (va_x_r10: nat64) (va_x_v0: quad32) (va_x_v1: quad32) (va_x_v2: quad32) (va_x_v3: quad32)
(va_x_v4: quad32) (va_x_v8: quad32) (va_x_v9: quad32) (va_x_v10: quad32) (va_x_v11: quad32).
let va_sM =
va_upd_vec 11
va_x_v11
(va_upd_vec 10
va_x_v10
(va_upd_vec 9
va_x_v9
(va_upd_vec 8
va_x_v8
(va_upd_vec 4
va_x_v4
(va_upd_vec 3
va_x_v3
(va_upd_vec 2
va_x_v2
(va_upd_vec 1
va_x_v1
(va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 va_s0)))))))))
in
va_get_ok va_sM /\
(let h:Vale.Math.Poly2_s.poly = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in
let prev:Vale.Math.Poly2_s.poly = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in
let pdata:(Prims.int -> Vale.AES.GHash_BE.poly128) =
Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128 data
in
let n:Prims.nat = FStar.Seq.Base.length #quad32 data in
va_get_vec 1 va_sM == Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data) ==>
va_k va_sM (()))) | false |
Hacl.Impl.P256.Group.fst | Hacl.Impl.P256.Group.mk_p256_concrete_ops | val mk_p256_concrete_ops:BE.concrete_ops U64 12ul 0ul | val mk_p256_concrete_ops:BE.concrete_ops U64 12ul 0ul | let mk_p256_concrete_ops : BE.concrete_ops U64 12ul 0ul = {
BE.to = mk_to_p256_comm_monoid;
BE.lone = point_zero;
BE.lmul = point_add;
BE.lsqr = point_double;
} | {
"file_name": "code/ecdsap256/Hacl.Impl.P256.Group.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 1,
"end_line": 70,
"start_col": 0,
"start_line": 65
} | module Hacl.Impl.P256.Group
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module BE = Hacl.Impl.Exponentiation.Definitions
module S = Spec.P256
module SL = Spec.P256.Lemmas
open Hacl.Impl.P256.Point
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True
unfold
let refl (p:LSeq.lseq uint64 12{point_inv_seq p}) : GTot S.aff_point =
S.to_aff_point (from_mont_point (as_point_nat_seq p))
inline_for_extraction noextract
let mk_to_p256_comm_monoid : BE.to_comm_monoid U64 12ul 0ul = {
BE.a_spec = S.aff_point;
BE.comm_monoid = S.mk_p256_comm_monoid;
BE.linv_ctx = linv_ctx;
BE.linv = point_inv_seq;
BE.refl = refl;
}
inline_for_extraction noextract
val point_add : BE.lmul_st U64 12ul 0ul mk_to_p256_comm_monoid
let point_add ctx x y xy =
let h0 = ST.get () in
SL.to_aff_point_add_lemma
(from_mont_point (as_point_nat h0 x)) (from_mont_point (as_point_nat h0 y));
Hacl.Impl.P256.PointAdd.point_add xy x y
inline_for_extraction noextract
val point_double : BE.lsqr_st U64 12ul 0ul mk_to_p256_comm_monoid
let point_double ctx x xx =
let h0 = ST.get () in
SL.to_aff_point_double_lemma (from_mont_point (as_point_nat h0 x));
Hacl.Impl.P256.PointDouble.point_double xx x
inline_for_extraction noextract
val point_zero : BE.lone_st U64 12ul 0ul mk_to_p256_comm_monoid
let point_zero ctx one =
let h0 = ST.get () in
SL.to_aff_point_at_infinity_lemma ();
make_point_at_inf one | {
"checked_file": "/",
"dependencies": [
"Spec.P256.Lemmas.fsti.checked",
"Spec.P256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.P256.PointDouble.fsti.checked",
"Hacl.Impl.P256.PointAdd.fsti.checked",
"Hacl.Impl.P256.Point.fsti.checked",
"Hacl.Impl.Exponentiation.Definitions.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.Impl.P256.Group.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Impl.Exponentiation.Definitions.concrete_ops Lib.IntTypes.U64
(12ul <: FStar.UInt32.t)
(0ul <: FStar.UInt32.t) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Exponentiation.Definitions.Mkconcrete_ops",
"Lib.IntTypes.U64",
"FStar.UInt32.uint_to_t",
"FStar.Ghost.hide",
"Hacl.Impl.Exponentiation.Definitions.to_comm_monoid",
"Hacl.Impl.P256.Group.mk_to_p256_comm_monoid",
"Hacl.Impl.P256.Group.point_zero",
"Hacl.Impl.P256.Group.point_add",
"Hacl.Impl.P256.Group.point_double"
] | [] | false | false | false | false | false | let mk_p256_concrete_ops:BE.concrete_ops U64 12ul 0ul =
| {
BE.to = mk_to_p256_comm_monoid;
BE.lone = point_zero;
BE.lmul = point_add;
BE.lsqr = point_double
} | false |
Vale.AES.PPC64LE.GHash.fsti | Vale.AES.PPC64LE.GHash.va_wp_Ghash_buffer | val va_wp_Ghash_buffer
(hkeys_b in_b: buffer128)
(h_BE y_prev: quad32)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | val va_wp_Ghash_buffer
(hkeys_b in_b: buffer128)
(h_BE y_prev: quad32)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | let va_wp_Ghash_buffer (hkeys_b:buffer128) (in_b:buffer128) (h_BE:quad32) (y_prev:quad32)
(va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in hkeys_b_powers
hkeys_b (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0) (va_get_reg 5 va_s0) h /\
Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 7 va_s0) in_b
(va_get_reg 6 va_s0) (va_get_mem_layout va_s0) Secret /\ Vale.PPC64LE.Decls.buffer_length
#Vale.PPC64LE.Memory.vuint128 in_b == va_get_reg 6 va_s0 /\ va_get_reg 7 va_s0 + 16
`op_Multiply` va_get_reg 6 va_s0 < pow2_64 /\ va_get_vec 1 va_s0 == y_prev) /\ (forall
(va_x_r7:nat64) (va_x_r6:nat64) (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32)
(va_x_v2:quad32) (va_x_v3:quad32) (va_x_v4:quad32) (va_x_v5:quad32) (va_x_v6:quad32)
(va_x_v7:quad32) (va_x_v8:quad32) (va_x_v9:quad32) (va_x_v10:quad32) (va_x_v11:quad32)
(va_x_v12:quad32) (va_x_v13:quad32) (va_x_v14:quad32) (va_x_cr0:cr0_t) . let va_sM = va_upd_cr0
va_x_cr0 (va_upd_vec 14 va_x_v14 (va_upd_vec 13 va_x_v13 (va_upd_vec 12 va_x_v12 (va_upd_vec 11
va_x_v11 (va_upd_vec 10 va_x_v10 (va_upd_vec 9 va_x_v9 (va_upd_vec 8 va_x_v8 (va_upd_vec 7
va_x_v7 (va_upd_vec 6 va_x_v6 (va_upd_vec 5 va_x_v5 (va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3
(va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10
(va_upd_reg 6 va_x_r6 (va_upd_reg 7 va_x_r7 va_s0)))))))))))))))))) in va_get_ok va_sM /\ (let
(h:poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in va_get_vec 1 va_sM ==
Vale.AES.GHash_BE.ghash_incremental0 h_BE y_prev (Vale.Arch.Types.reverse_bytes_quad32_seq
(Vale.PPC64LE.Decls.s128 (va_get_mem_heaplet 1 va_sM) in_b)) /\ (va_get_reg 6 va_s0 == 0 ==>
va_get_vec 1 va_sM == va_get_vec 1 va_s0)) ==> va_k va_sM (()))) | {
"file_name": "obj/Vale.AES.PPC64LE.GHash.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 68,
"end_line": 316,
"start_col": 0,
"start_line": 296
} | module Vale.AES.PPC64LE.GHash
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.AES.AES_BE_s
open Vale.PPC64LE.Machine_s
open Vale.PPC64LE.Memory
open Vale.PPC64LE.State
open Vale.PPC64LE.Decls
open Vale.PPC64LE.InsBasic
open Vale.PPC64LE.InsMem
open Vale.PPC64LE.InsVector
open Vale.PPC64LE.QuickCode
open Vale.PPC64LE.QuickCodes
open Vale.AES.AES_helpers
open Vale.Poly1305.Math // For lemma_poly_bits64()
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.Arch.TypesNative
open Vale.AES.PPC64LE.PolyOps
open Vale.AES.PPC64LE.GF128_Mul
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Bits_s
open Vale.Math.Poly2.Bits
open Vale.Math.Poly2.Lemmas
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.AES.GHash_BE
#reset-options "--z3rlimit 50"
unfold let va_subscript_FStar__Seq__Base__seq = Seq.index
let hkeys_b_powers (hkeys_b:buffer128) (heap0:vale_heap) (layout:vale_heap_layout) (ptr:int) (h:poly) =
validSrcAddrs128 heap0 ptr hkeys_b 3 layout Secret /\
of_quad32 (reverse_bytes_quad32 (buffer128_read hkeys_b 0 heap0)) == gf128_power h 1 /\
of_quad32 (reverse_bytes_quad32 (buffer128_read hkeys_b 1 heap0)) == gf128_power h 2
let in_b_blocks
(in_b:buffer128) (in_index count:int) (heap_s:vale_heap) (layout:vale_heap_layout) (ptr:int) (data:seq quad32)
=
validSrcAddrsOffset128 heap_s ptr in_b in_index count layout Secret /\
(forall (i:nat).{:pattern (index data i)}
i < count /\ i < length data ==>
reverse_bytes_quad32 (buffer128_read in_b (in_index + i) heap_s) == index data i)
//-- ReduceLast
val va_code_ReduceLast : va_dummy:unit -> Tot va_code
val va_codegen_success_ReduceLast : va_dummy:unit -> Tot va_pbool
val va_lemma_ReduceLast : va_b0:va_code -> va_s0:va_state -> h_BE:quad32 -> y_prev:quad32 ->
data:(seq quad32)
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_ReduceLast ()) va_s0 /\ va_get_ok va_s0 /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in va_get_vec 8 va_s0 ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 3254779904 0 0 /\ n > 0 /\ add (add
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 2 va_s0)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 3 va_s0)) 64)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 4 va_s0)) 128) ==
Vale.AES.GHash_BE.ghash_unroll_back h prev pdata 0 n (n - 1))))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in let xi =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_sM) in Vale.Math.Poly2.Bits_s.to_quad32 xi ==
Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data /\ xi == Vale.Math.Poly2.Bits_s.of_quad32
(Vale.Math.Poly2.Bits_s.to_quad32 xi)) /\ va_state_eq va_sM (va_update_vec 10 va_sM
(va_update_vec 9 va_sM (va_update_vec 8 va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM
(va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0 va_sM (va_update_ok va_sM
va_s0)))))))))))
[@ va_qattr]
let va_wp_ReduceLast (h_BE:quad32) (y_prev:quad32) (data:(seq quad32)) (va_s0:va_state)
(va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in
let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in va_get_vec 8 va_s0 ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 3254779904 0 0 /\ n > 0 /\ add (add
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 2 va_s0)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 3 va_s0)) 64)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 4 va_s0)) 128) ==
Vale.AES.GHash_BE.ghash_unroll_back h prev pdata 0 n (n - 1)) /\ (forall (va_x_v0:quad32)
(va_x_v1:quad32) (va_x_v2:quad32) (va_x_v3:quad32) (va_x_v4:quad32) (va_x_v8:quad32)
(va_x_v9:quad32) (va_x_v10:quad32) . let va_sM = va_upd_vec 10 va_x_v10 (va_upd_vec 9 va_x_v9
(va_upd_vec 8 va_x_v8 (va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2
(va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 va_s0))))))) in va_get_ok va_sM /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in let xi =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_sM) in Vale.Math.Poly2.Bits_s.to_quad32 xi ==
Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data /\ xi == Vale.Math.Poly2.Bits_s.of_quad32
(Vale.Math.Poly2.Bits_s.to_quad32 xi)) ==> va_k va_sM (())))
val va_wpProof_ReduceLast : h_BE:quad32 -> y_prev:quad32 -> data:(seq quad32) -> va_s0:va_state ->
va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_ReduceLast h_BE y_prev data va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_ReduceLast ()) ([va_Mod_vec 10;
va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec
0]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_ReduceLast (h_BE:quad32) (y_prev:quad32) (data:(seq quad32)) : (va_quickCode unit
(va_code_ReduceLast ())) =
(va_QProc (va_code_ReduceLast ()) ([va_Mod_vec 10; va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 4;
va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0]) (va_wp_ReduceLast h_BE y_prev data)
(va_wpProof_ReduceLast h_BE y_prev data))
//--
//-- GhashUnroll_n
val va_code_GhashUnroll_n : exactly2:bool -> Tot va_code
val va_codegen_success_GhashUnroll_n : exactly2:bool -> Tot va_pbool
val va_lemma_GhashUnroll_n : va_b0:va_code -> va_s0:va_state -> exactly2:bool -> in_b:buffer128 ->
index:nat -> h_BE:quad32 -> y_prev:quad32 -> data:(seq quad32)
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_GhashUnroll_n exactly2) va_s0 /\ va_get_ok va_s0 /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in (exactly2 ==> n == 2) /\
(~exactly2 ==> n == 1) /\ in_b_blocks in_b index n (va_get_mem_heaplet 1 va_s0)
(va_get_mem_layout va_s0) (va_get_reg 7 va_s0) data /\ Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 1 va_s0) == prev /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 5 va_s0) ==
Vale.Math.Poly2.swap (Vale.AES.GHash_BE.gf128_power h 1) 64 /\ Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 6 va_s0) == Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.div
(Vale.AES.GHash_BE.gf128_power h 1) (Vale.Math.Poly2_s.monomial 64))
(Vale.Math.Poly2_s.monomial 64) /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 7 va_s0) ==
Vale.Math.Poly2_s.mod (Vale.AES.GHash_BE.gf128_power h 1) (Vale.Math.Poly2_s.monomial 64) /\
(exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 12 va_s0) == Vale.Math.Poly2.swap
(Vale.AES.GHash_BE.gf128_power h 2) 64) /\ (exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 13 va_s0) == Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.div
(Vale.AES.GHash_BE.gf128_power h 2) (Vale.Math.Poly2_s.monomial 64))
(Vale.Math.Poly2_s.monomial 64)) /\ (exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec
14 va_s0) == Vale.Math.Poly2_s.mod (Vale.AES.GHash_BE.gf128_power h 2)
(Vale.Math.Poly2_s.monomial 64)))))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in va_get_vec 1 va_sM ==
Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data) /\ va_state_eq va_sM (va_update_vec 11
va_sM (va_update_vec 10 va_sM (va_update_vec 9 va_sM (va_update_vec 8 va_sM (va_update_vec 4
va_sM (va_update_vec 3 va_sM (va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0
va_sM (va_update_reg 10 va_sM (va_update_ok va_sM va_s0)))))))))))))
[@ va_qattr]
let va_wp_GhashUnroll_n (exactly2:bool) (in_b:buffer128) (index:nat) (h_BE:quad32) (y_prev:quad32)
(data:(seq quad32)) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in
let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in (exactly2 ==> n == 2) /\
(~exactly2 ==> n == 1) /\ in_b_blocks in_b index n (va_get_mem_heaplet 1 va_s0)
(va_get_mem_layout va_s0) (va_get_reg 7 va_s0) data /\ Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 1 va_s0) == prev /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 5 va_s0) ==
Vale.Math.Poly2.swap (Vale.AES.GHash_BE.gf128_power h 1) 64 /\ Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 6 va_s0) == Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.div
(Vale.AES.GHash_BE.gf128_power h 1) (Vale.Math.Poly2_s.monomial 64))
(Vale.Math.Poly2_s.monomial 64) /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 7 va_s0) ==
Vale.Math.Poly2_s.mod (Vale.AES.GHash_BE.gf128_power h 1) (Vale.Math.Poly2_s.monomial 64) /\
(exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 12 va_s0) == Vale.Math.Poly2.swap
(Vale.AES.GHash_BE.gf128_power h 2) 64) /\ (exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 13 va_s0) == Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.div
(Vale.AES.GHash_BE.gf128_power h 2) (Vale.Math.Poly2_s.monomial 64))
(Vale.Math.Poly2_s.monomial 64)) /\ (exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec
14 va_s0) == Vale.Math.Poly2_s.mod (Vale.AES.GHash_BE.gf128_power h 2)
(Vale.Math.Poly2_s.monomial 64))) /\ (forall (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32)
(va_x_v2:quad32) (va_x_v3:quad32) (va_x_v4:quad32) (va_x_v8:quad32) (va_x_v9:quad32)
(va_x_v10:quad32) (va_x_v11:quad32) . let va_sM = va_upd_vec 11 va_x_v11 (va_upd_vec 10
va_x_v10 (va_upd_vec 9 va_x_v9 (va_upd_vec 8 va_x_v8 (va_upd_vec 4 va_x_v4 (va_upd_vec 3
va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 (va_upd_reg 10
va_x_r10 va_s0))))))))) in va_get_ok va_sM /\ (let (h:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let (prev:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let (pdata:(Prims.int -> Vale.AES.GHash_BE.poly128))
= Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128 data in let (n:Prims.nat) = FStar.Seq.Base.length
#quad32 data in va_get_vec 1 va_sM == Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data) ==>
va_k va_sM (())))
val va_wpProof_GhashUnroll_n : exactly2:bool -> in_b:buffer128 -> index:nat -> h_BE:quad32 ->
y_prev:quad32 -> data:(seq quad32) -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_GhashUnroll_n exactly2 in_b index h_BE y_prev data va_s0
va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_GhashUnroll_n exactly2) ([va_Mod_vec
11; va_Mod_vec 10; va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2;
va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_GhashUnroll_n (exactly2:bool) (in_b:buffer128) (index:nat) (h_BE:quad32)
(y_prev:quad32) (data:(seq quad32)) : (va_quickCode unit (va_code_GhashUnroll_n exactly2)) =
(va_QProc (va_code_GhashUnroll_n exactly2) ([va_Mod_vec 11; va_Mod_vec 10; va_Mod_vec 9;
va_Mod_vec 8; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg
10]) (va_wp_GhashUnroll_n exactly2 in_b index h_BE y_prev data) (va_wpProof_GhashUnroll_n
exactly2 in_b index h_BE y_prev data))
//--
//-- Ghash_register
val va_code_Ghash_register : va_dummy:unit -> Tot va_code
val va_codegen_success_Ghash_register : va_dummy:unit -> Tot va_pbool
val va_lemma_Ghash_register : va_b0:va_code -> va_s0:va_state -> hkeys_b:buffer128 -> h_BE:quad32
-> y_prev:quad32
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Ghash_register ()) va_s0 /\ va_get_ok va_s0 /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(data:(FStar.Seq.Base.seq quad32)) = FStar.Seq.Base.create #quad32 1 (va_get_vec 9 va_s0) in
let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in hkeys_b_powers hkeys_b (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0)
(va_get_reg 5 va_s0) h /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_s0) == prev)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(data:(FStar.Seq.Base.seq quad32)) = FStar.Seq.Base.create #quad32 1 (va_get_vec 9 va_s0) in
let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in va_get_vec 1 va_sM == Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data) /\
va_state_eq va_sM (va_update_vec 10 va_sM (va_update_vec 9 va_sM (va_update_vec 8 va_sM
(va_update_vec 7 va_sM (va_update_vec 6 va_sM (va_update_vec 5 va_sM (va_update_vec 4 va_sM
(va_update_vec 3 va_sM (va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0 va_sM
(va_update_reg 10 va_sM (va_update_ok va_sM va_s0)))))))))))))))
[@ va_qattr]
let va_wp_Ghash_register (hkeys_b:buffer128) (h_BE:quad32) (y_prev:quad32) (va_s0:va_state)
(va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in
let (data:(FStar.Seq.Base.seq quad32)) = FStar.Seq.Base.create #quad32 1 (va_get_vec 9 va_s0)
in let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in hkeys_b_powers hkeys_b (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0)
(va_get_reg 5 va_s0) h /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_s0) == prev) /\
(forall (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32) (va_x_v2:quad32) (va_x_v3:quad32)
(va_x_v4:quad32) (va_x_v5:quad32) (va_x_v6:quad32) (va_x_v7:quad32) (va_x_v8:quad32)
(va_x_v9:quad32) (va_x_v10:quad32) . let va_sM = va_upd_vec 10 va_x_v10 (va_upd_vec 9 va_x_v9
(va_upd_vec 8 va_x_v8 (va_upd_vec 7 va_x_v7 (va_upd_vec 6 va_x_v6 (va_upd_vec 5 va_x_v5
(va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1
(va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 va_s0))))))))))) in va_get_ok va_sM /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(data:(FStar.Seq.Base.seq quad32)) = FStar.Seq.Base.create #quad32 1 (va_get_vec 9 va_s0) in
let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in va_get_vec 1 va_sM == Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data) ==> va_k
va_sM (())))
val va_wpProof_Ghash_register : hkeys_b:buffer128 -> h_BE:quad32 -> y_prev:quad32 -> va_s0:va_state
-> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Ghash_register hkeys_b h_BE y_prev va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Ghash_register ()) ([va_Mod_vec 10;
va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 7; va_Mod_vec 6; va_Mod_vec 5; va_Mod_vec 4; va_Mod_vec
3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_Ghash_register (hkeys_b:buffer128) (h_BE:quad32) (y_prev:quad32) : (va_quickCode unit
(va_code_Ghash_register ())) =
(va_QProc (va_code_Ghash_register ()) ([va_Mod_vec 10; va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 7;
va_Mod_vec 6; va_Mod_vec 5; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec
0; va_Mod_reg 10]) (va_wp_Ghash_register hkeys_b h_BE y_prev) (va_wpProof_Ghash_register
hkeys_b h_BE y_prev))
//--
//-- Ghash_buffer
val va_code_Ghash_buffer : va_dummy:unit -> Tot va_code
val va_codegen_success_Ghash_buffer : va_dummy:unit -> Tot va_pbool
val va_lemma_Ghash_buffer : va_b0:va_code -> va_s0:va_state -> hkeys_b:buffer128 -> in_b:buffer128
-> h_BE:quad32 -> y_prev:quad32
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Ghash_buffer ()) va_s0 /\ va_get_ok va_s0 /\ (let
(h:poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in hkeys_b_powers hkeys_b (va_get_mem_heaplet
0 va_s0) (va_get_mem_layout va_s0) (va_get_reg 5 va_s0) h /\
Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 7 va_s0) in_b
(va_get_reg 6 va_s0) (va_get_mem_layout va_s0) Secret /\ Vale.PPC64LE.Decls.buffer_length
#Vale.PPC64LE.Memory.vuint128 in_b == va_get_reg 6 va_s0 /\ va_get_reg 7 va_s0 + 16
`op_Multiply` va_get_reg 6 va_s0 < pow2_64 /\ va_get_vec 1 va_s0 == y_prev)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in va_get_vec 1 va_sM ==
Vale.AES.GHash_BE.ghash_incremental0 h_BE y_prev (Vale.Arch.Types.reverse_bytes_quad32_seq
(Vale.PPC64LE.Decls.s128 (va_get_mem_heaplet 1 va_sM) in_b)) /\ (va_get_reg 6 va_s0 == 0 ==>
va_get_vec 1 va_sM == va_get_vec 1 va_s0)) /\ va_state_eq va_sM (va_update_cr0 va_sM
(va_update_vec 14 va_sM (va_update_vec 13 va_sM (va_update_vec 12 va_sM (va_update_vec 11 va_sM
(va_update_vec 10 va_sM (va_update_vec 9 va_sM (va_update_vec 8 va_sM (va_update_vec 7 va_sM
(va_update_vec 6 va_sM (va_update_vec 5 va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM
(va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM
(va_update_reg 6 va_sM (va_update_reg 7 va_sM (va_update_ok va_sM va_s0)))))))))))))))))))))) | {
"checked_file": "/",
"dependencies": [
"Vale.PPC64LE.State.fsti.checked",
"Vale.PPC64LE.QuickCodes.fsti.checked",
"Vale.PPC64LE.QuickCode.fst.checked",
"Vale.PPC64LE.Memory.fsti.checked",
"Vale.PPC64LE.Machine_s.fst.checked",
"Vale.PPC64LE.InsVector.fsti.checked",
"Vale.PPC64LE.InsMem.fsti.checked",
"Vale.PPC64LE.InsBasic.fsti.checked",
"Vale.PPC64LE.Decls.fsti.checked",
"Vale.Poly1305.Math.fsti.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Lemmas.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Math.Poly2.Bits.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.AES.PPC64LE.PolyOps.fsti.checked",
"Vale.AES.PPC64LE.GF128_Mul.fsti.checked",
"Vale.AES.GHash_BE.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.fsti.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.AES_helpers.fsti.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.PPC64LE.GHash.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math // For lemma_poly_bits64()",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
hkeys_b: Vale.PPC64LE.Memory.buffer128 ->
in_b: Vale.PPC64LE.Memory.buffer128 ->
h_BE: Vale.PPC64LE.Memory.quad32 ->
y_prev: Vale.PPC64LE.Memory.quad32 ->
va_s0: Vale.PPC64LE.Decls.va_state ->
va_k: (_: Vale.PPC64LE.Decls.va_state -> _: Prims.unit -> Type0)
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.PPC64LE.Memory.buffer128",
"Vale.PPC64LE.Memory.quad32",
"Vale.PPC64LE.Decls.va_state",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Vale.PPC64LE.Decls.va_get_ok",
"Vale.AES.PPC64LE.GHash.hkeys_b_powers",
"Vale.PPC64LE.Decls.va_get_mem_heaplet",
"Vale.PPC64LE.Decls.va_get_mem_layout",
"Vale.PPC64LE.Decls.va_get_reg",
"Vale.PPC64LE.Decls.validSrcAddrs128",
"Vale.Arch.HeapTypes_s.Secret",
"Prims.eq2",
"Prims.nat",
"Vale.PPC64LE.Decls.buffer_length",
"Vale.PPC64LE.Memory.vuint128",
"Prims.op_LessThan",
"Prims.op_Addition",
"Prims.op_Multiply",
"Vale.PPC64LE.Machine_s.pow2_64",
"Vale.Def.Types_s.quad32",
"Vale.PPC64LE.Decls.va_get_vec",
"Vale.Math.Poly2_s.poly",
"Vale.Math.Poly2.Bits_s.of_quad32",
"Prims.l_Forall",
"Vale.PPC64LE.Memory.nat64",
"Vale.PPC64LE.Machine_s.cr0_t",
"Prims.l_imp",
"Vale.AES.GHash_BE.ghash_incremental0",
"Vale.Arch.Types.reverse_bytes_quad32_seq",
"Vale.PPC64LE.Decls.s128",
"Prims.int",
"Vale.PPC64LE.Machine_s.quad32",
"Vale.PPC64LE.Machine_s.state",
"Vale.PPC64LE.Decls.va_upd_cr0",
"Vale.PPC64LE.Decls.va_upd_vec",
"Vale.PPC64LE.Decls.va_upd_reg"
] | [] | false | false | false | true | true | let va_wp_Ghash_buffer
(hkeys_b in_b: buffer128)
(h_BE y_prev: quad32)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 =
| (va_get_ok va_s0 /\
(let h:poly = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in
hkeys_b_powers hkeys_b
(va_get_mem_heaplet 0 va_s0)
(va_get_mem_layout va_s0)
(va_get_reg 5 va_s0)
h /\
Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 1 va_s0)
(va_get_reg 7 va_s0)
in_b
(va_get_reg 6 va_s0)
(va_get_mem_layout va_s0)
Secret /\
Vale.PPC64LE.Decls.buffer_length #Vale.PPC64LE.Memory.vuint128 in_b == va_get_reg 6 va_s0 /\
va_get_reg 7 va_s0 + 16 `op_Multiply` (va_get_reg 6 va_s0) < pow2_64 /\
va_get_vec 1 va_s0 == y_prev) /\
(forall (va_x_r7: nat64) (va_x_r6: nat64) (va_x_r10: nat64) (va_x_v0: quad32) (va_x_v1: quad32)
(va_x_v2: quad32) (va_x_v3: quad32) (va_x_v4: quad32) (va_x_v5: quad32) (va_x_v6: quad32)
(va_x_v7: quad32) (va_x_v8: quad32) (va_x_v9: quad32) (va_x_v10: quad32) (va_x_v11: quad32)
(va_x_v12: quad32) (va_x_v13: quad32) (va_x_v14: quad32) (va_x_cr0: cr0_t).
let va_sM =
va_upd_cr0 va_x_cr0
(va_upd_vec 14
va_x_v14
(va_upd_vec 13
va_x_v13
(va_upd_vec 12
va_x_v12
(va_upd_vec 11
va_x_v11
(va_upd_vec 10
va_x_v10
(va_upd_vec 9
va_x_v9
(va_upd_vec 8
va_x_v8
(va_upd_vec 7
va_x_v7
(va_upd_vec 6
va_x_v6
(va_upd_vec 5
va_x_v5
(va_upd_vec 4
va_x_v4
(va_upd_vec 3
va_x_v3
(va_upd_vec 2
va_x_v2
(va_upd_vec 1
va_x_v1
(va_upd_vec 0
va_x_v0
(va_upd_reg 10
va_x_r10
(va_upd_reg 6
va_x_r6
(va_upd_reg 7
va_x_r7
va_s0)))))))))))))
)))))
in
va_get_ok va_sM /\
(let h:poly = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in
va_get_vec 1 va_sM ==
Vale.AES.GHash_BE.ghash_incremental0 h_BE
y_prev
(Vale.Arch.Types.reverse_bytes_quad32_seq (Vale.PPC64LE.Decls.s128 (va_get_mem_heaplet 1
va_sM)
in_b)) /\ (va_get_reg 6 va_s0 == 0 ==> va_get_vec 1 va_sM == va_get_vec 1 va_s0)) ==>
va_k va_sM (()))) | false |
Vale.AES.PPC64LE.GHash.fsti | Vale.AES.PPC64LE.GHash.va_wp_Ghash_register | val va_wp_Ghash_register
(hkeys_b: buffer128)
(h_BE y_prev: quad32)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | val va_wp_Ghash_register
(hkeys_b: buffer128)
(h_BE y_prev: quad32)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | let va_wp_Ghash_register (hkeys_b:buffer128) (h_BE:quad32) (y_prev:quad32) (va_s0:va_state)
(va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in
let (data:(FStar.Seq.Base.seq quad32)) = FStar.Seq.Base.create #quad32 1 (va_get_vec 9 va_s0)
in let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in hkeys_b_powers hkeys_b (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0)
(va_get_reg 5 va_s0) h /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_s0) == prev) /\
(forall (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32) (va_x_v2:quad32) (va_x_v3:quad32)
(va_x_v4:quad32) (va_x_v5:quad32) (va_x_v6:quad32) (va_x_v7:quad32) (va_x_v8:quad32)
(va_x_v9:quad32) (va_x_v10:quad32) . let va_sM = va_upd_vec 10 va_x_v10 (va_upd_vec 9 va_x_v9
(va_upd_vec 8 va_x_v8 (va_upd_vec 7 va_x_v7 (va_upd_vec 6 va_x_v6 (va_upd_vec 5 va_x_v5
(va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1
(va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 va_s0))))))))))) in va_get_ok va_sM /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(data:(FStar.Seq.Base.seq quad32)) = FStar.Seq.Base.create #quad32 1 (va_get_vec 9 va_s0) in
let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in va_get_vec 1 va_sM == Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data) ==> va_k
va_sM (()))) | {
"file_name": "obj/Vale.AES.PPC64LE.GHash.fsti",
"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": 233
} | module Vale.AES.PPC64LE.GHash
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.AES.AES_BE_s
open Vale.PPC64LE.Machine_s
open Vale.PPC64LE.Memory
open Vale.PPC64LE.State
open Vale.PPC64LE.Decls
open Vale.PPC64LE.InsBasic
open Vale.PPC64LE.InsMem
open Vale.PPC64LE.InsVector
open Vale.PPC64LE.QuickCode
open Vale.PPC64LE.QuickCodes
open Vale.AES.AES_helpers
open Vale.Poly1305.Math // For lemma_poly_bits64()
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.Arch.TypesNative
open Vale.AES.PPC64LE.PolyOps
open Vale.AES.PPC64LE.GF128_Mul
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Bits_s
open Vale.Math.Poly2.Bits
open Vale.Math.Poly2.Lemmas
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.AES.GHash_BE
#reset-options "--z3rlimit 50"
unfold let va_subscript_FStar__Seq__Base__seq = Seq.index
let hkeys_b_powers (hkeys_b:buffer128) (heap0:vale_heap) (layout:vale_heap_layout) (ptr:int) (h:poly) =
validSrcAddrs128 heap0 ptr hkeys_b 3 layout Secret /\
of_quad32 (reverse_bytes_quad32 (buffer128_read hkeys_b 0 heap0)) == gf128_power h 1 /\
of_quad32 (reverse_bytes_quad32 (buffer128_read hkeys_b 1 heap0)) == gf128_power h 2
let in_b_blocks
(in_b:buffer128) (in_index count:int) (heap_s:vale_heap) (layout:vale_heap_layout) (ptr:int) (data:seq quad32)
=
validSrcAddrsOffset128 heap_s ptr in_b in_index count layout Secret /\
(forall (i:nat).{:pattern (index data i)}
i < count /\ i < length data ==>
reverse_bytes_quad32 (buffer128_read in_b (in_index + i) heap_s) == index data i)
//-- ReduceLast
val va_code_ReduceLast : va_dummy:unit -> Tot va_code
val va_codegen_success_ReduceLast : va_dummy:unit -> Tot va_pbool
val va_lemma_ReduceLast : va_b0:va_code -> va_s0:va_state -> h_BE:quad32 -> y_prev:quad32 ->
data:(seq quad32)
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_ReduceLast ()) va_s0 /\ va_get_ok va_s0 /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in va_get_vec 8 va_s0 ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 3254779904 0 0 /\ n > 0 /\ add (add
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 2 va_s0)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 3 va_s0)) 64)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 4 va_s0)) 128) ==
Vale.AES.GHash_BE.ghash_unroll_back h prev pdata 0 n (n - 1))))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in let xi =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_sM) in Vale.Math.Poly2.Bits_s.to_quad32 xi ==
Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data /\ xi == Vale.Math.Poly2.Bits_s.of_quad32
(Vale.Math.Poly2.Bits_s.to_quad32 xi)) /\ va_state_eq va_sM (va_update_vec 10 va_sM
(va_update_vec 9 va_sM (va_update_vec 8 va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM
(va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0 va_sM (va_update_ok va_sM
va_s0)))))))))))
[@ va_qattr]
let va_wp_ReduceLast (h_BE:quad32) (y_prev:quad32) (data:(seq quad32)) (va_s0:va_state)
(va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in
let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in va_get_vec 8 va_s0 ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 3254779904 0 0 /\ n > 0 /\ add (add
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 2 va_s0)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 3 va_s0)) 64)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 4 va_s0)) 128) ==
Vale.AES.GHash_BE.ghash_unroll_back h prev pdata 0 n (n - 1)) /\ (forall (va_x_v0:quad32)
(va_x_v1:quad32) (va_x_v2:quad32) (va_x_v3:quad32) (va_x_v4:quad32) (va_x_v8:quad32)
(va_x_v9:quad32) (va_x_v10:quad32) . let va_sM = va_upd_vec 10 va_x_v10 (va_upd_vec 9 va_x_v9
(va_upd_vec 8 va_x_v8 (va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2
(va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 va_s0))))))) in va_get_ok va_sM /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in let xi =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_sM) in Vale.Math.Poly2.Bits_s.to_quad32 xi ==
Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data /\ xi == Vale.Math.Poly2.Bits_s.of_quad32
(Vale.Math.Poly2.Bits_s.to_quad32 xi)) ==> va_k va_sM (())))
val va_wpProof_ReduceLast : h_BE:quad32 -> y_prev:quad32 -> data:(seq quad32) -> va_s0:va_state ->
va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_ReduceLast h_BE y_prev data va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_ReduceLast ()) ([va_Mod_vec 10;
va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec
0]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_ReduceLast (h_BE:quad32) (y_prev:quad32) (data:(seq quad32)) : (va_quickCode unit
(va_code_ReduceLast ())) =
(va_QProc (va_code_ReduceLast ()) ([va_Mod_vec 10; va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 4;
va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0]) (va_wp_ReduceLast h_BE y_prev data)
(va_wpProof_ReduceLast h_BE y_prev data))
//--
//-- GhashUnroll_n
val va_code_GhashUnroll_n : exactly2:bool -> Tot va_code
val va_codegen_success_GhashUnroll_n : exactly2:bool -> Tot va_pbool
val va_lemma_GhashUnroll_n : va_b0:va_code -> va_s0:va_state -> exactly2:bool -> in_b:buffer128 ->
index:nat -> h_BE:quad32 -> y_prev:quad32 -> data:(seq quad32)
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_GhashUnroll_n exactly2) va_s0 /\ va_get_ok va_s0 /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in (exactly2 ==> n == 2) /\
(~exactly2 ==> n == 1) /\ in_b_blocks in_b index n (va_get_mem_heaplet 1 va_s0)
(va_get_mem_layout va_s0) (va_get_reg 7 va_s0) data /\ Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 1 va_s0) == prev /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 5 va_s0) ==
Vale.Math.Poly2.swap (Vale.AES.GHash_BE.gf128_power h 1) 64 /\ Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 6 va_s0) == Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.div
(Vale.AES.GHash_BE.gf128_power h 1) (Vale.Math.Poly2_s.monomial 64))
(Vale.Math.Poly2_s.monomial 64) /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 7 va_s0) ==
Vale.Math.Poly2_s.mod (Vale.AES.GHash_BE.gf128_power h 1) (Vale.Math.Poly2_s.monomial 64) /\
(exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 12 va_s0) == Vale.Math.Poly2.swap
(Vale.AES.GHash_BE.gf128_power h 2) 64) /\ (exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 13 va_s0) == Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.div
(Vale.AES.GHash_BE.gf128_power h 2) (Vale.Math.Poly2_s.monomial 64))
(Vale.Math.Poly2_s.monomial 64)) /\ (exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec
14 va_s0) == Vale.Math.Poly2_s.mod (Vale.AES.GHash_BE.gf128_power h 2)
(Vale.Math.Poly2_s.monomial 64)))))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in va_get_vec 1 va_sM ==
Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data) /\ va_state_eq va_sM (va_update_vec 11
va_sM (va_update_vec 10 va_sM (va_update_vec 9 va_sM (va_update_vec 8 va_sM (va_update_vec 4
va_sM (va_update_vec 3 va_sM (va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0
va_sM (va_update_reg 10 va_sM (va_update_ok va_sM va_s0)))))))))))))
[@ va_qattr]
let va_wp_GhashUnroll_n (exactly2:bool) (in_b:buffer128) (index:nat) (h_BE:quad32) (y_prev:quad32)
(data:(seq quad32)) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in
let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in (exactly2 ==> n == 2) /\
(~exactly2 ==> n == 1) /\ in_b_blocks in_b index n (va_get_mem_heaplet 1 va_s0)
(va_get_mem_layout va_s0) (va_get_reg 7 va_s0) data /\ Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 1 va_s0) == prev /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 5 va_s0) ==
Vale.Math.Poly2.swap (Vale.AES.GHash_BE.gf128_power h 1) 64 /\ Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 6 va_s0) == Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.div
(Vale.AES.GHash_BE.gf128_power h 1) (Vale.Math.Poly2_s.monomial 64))
(Vale.Math.Poly2_s.monomial 64) /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 7 va_s0) ==
Vale.Math.Poly2_s.mod (Vale.AES.GHash_BE.gf128_power h 1) (Vale.Math.Poly2_s.monomial 64) /\
(exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 12 va_s0) == Vale.Math.Poly2.swap
(Vale.AES.GHash_BE.gf128_power h 2) 64) /\ (exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 13 va_s0) == Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.div
(Vale.AES.GHash_BE.gf128_power h 2) (Vale.Math.Poly2_s.monomial 64))
(Vale.Math.Poly2_s.monomial 64)) /\ (exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec
14 va_s0) == Vale.Math.Poly2_s.mod (Vale.AES.GHash_BE.gf128_power h 2)
(Vale.Math.Poly2_s.monomial 64))) /\ (forall (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32)
(va_x_v2:quad32) (va_x_v3:quad32) (va_x_v4:quad32) (va_x_v8:quad32) (va_x_v9:quad32)
(va_x_v10:quad32) (va_x_v11:quad32) . let va_sM = va_upd_vec 11 va_x_v11 (va_upd_vec 10
va_x_v10 (va_upd_vec 9 va_x_v9 (va_upd_vec 8 va_x_v8 (va_upd_vec 4 va_x_v4 (va_upd_vec 3
va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 (va_upd_reg 10
va_x_r10 va_s0))))))))) in va_get_ok va_sM /\ (let (h:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let (prev:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let (pdata:(Prims.int -> Vale.AES.GHash_BE.poly128))
= Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128 data in let (n:Prims.nat) = FStar.Seq.Base.length
#quad32 data in va_get_vec 1 va_sM == Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data) ==>
va_k va_sM (())))
val va_wpProof_GhashUnroll_n : exactly2:bool -> in_b:buffer128 -> index:nat -> h_BE:quad32 ->
y_prev:quad32 -> data:(seq quad32) -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_GhashUnroll_n exactly2 in_b index h_BE y_prev data va_s0
va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_GhashUnroll_n exactly2) ([va_Mod_vec
11; va_Mod_vec 10; va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2;
va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_GhashUnroll_n (exactly2:bool) (in_b:buffer128) (index:nat) (h_BE:quad32)
(y_prev:quad32) (data:(seq quad32)) : (va_quickCode unit (va_code_GhashUnroll_n exactly2)) =
(va_QProc (va_code_GhashUnroll_n exactly2) ([va_Mod_vec 11; va_Mod_vec 10; va_Mod_vec 9;
va_Mod_vec 8; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg
10]) (va_wp_GhashUnroll_n exactly2 in_b index h_BE y_prev data) (va_wpProof_GhashUnroll_n
exactly2 in_b index h_BE y_prev data))
//--
//-- Ghash_register
val va_code_Ghash_register : va_dummy:unit -> Tot va_code
val va_codegen_success_Ghash_register : va_dummy:unit -> Tot va_pbool
val va_lemma_Ghash_register : va_b0:va_code -> va_s0:va_state -> hkeys_b:buffer128 -> h_BE:quad32
-> y_prev:quad32
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Ghash_register ()) va_s0 /\ va_get_ok va_s0 /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(data:(FStar.Seq.Base.seq quad32)) = FStar.Seq.Base.create #quad32 1 (va_get_vec 9 va_s0) in
let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in hkeys_b_powers hkeys_b (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0)
(va_get_reg 5 va_s0) h /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_s0) == prev)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(data:(FStar.Seq.Base.seq quad32)) = FStar.Seq.Base.create #quad32 1 (va_get_vec 9 va_s0) in
let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in va_get_vec 1 va_sM == Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data) /\
va_state_eq va_sM (va_update_vec 10 va_sM (va_update_vec 9 va_sM (va_update_vec 8 va_sM
(va_update_vec 7 va_sM (va_update_vec 6 va_sM (va_update_vec 5 va_sM (va_update_vec 4 va_sM
(va_update_vec 3 va_sM (va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0 va_sM
(va_update_reg 10 va_sM (va_update_ok va_sM va_s0))))))))))))))) | {
"checked_file": "/",
"dependencies": [
"Vale.PPC64LE.State.fsti.checked",
"Vale.PPC64LE.QuickCodes.fsti.checked",
"Vale.PPC64LE.QuickCode.fst.checked",
"Vale.PPC64LE.Memory.fsti.checked",
"Vale.PPC64LE.Machine_s.fst.checked",
"Vale.PPC64LE.InsVector.fsti.checked",
"Vale.PPC64LE.InsMem.fsti.checked",
"Vale.PPC64LE.InsBasic.fsti.checked",
"Vale.PPC64LE.Decls.fsti.checked",
"Vale.Poly1305.Math.fsti.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Lemmas.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Math.Poly2.Bits.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.AES.PPC64LE.PolyOps.fsti.checked",
"Vale.AES.PPC64LE.GF128_Mul.fsti.checked",
"Vale.AES.GHash_BE.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.fsti.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.AES_helpers.fsti.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.PPC64LE.GHash.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math // For lemma_poly_bits64()",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
hkeys_b: Vale.PPC64LE.Memory.buffer128 ->
h_BE: Vale.PPC64LE.Memory.quad32 ->
y_prev: Vale.PPC64LE.Memory.quad32 ->
va_s0: Vale.PPC64LE.Decls.va_state ->
va_k: (_: Vale.PPC64LE.Decls.va_state -> _: Prims.unit -> Type0)
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.PPC64LE.Memory.buffer128",
"Vale.PPC64LE.Memory.quad32",
"Vale.PPC64LE.Decls.va_state",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Vale.PPC64LE.Decls.va_get_ok",
"Vale.AES.PPC64LE.GHash.hkeys_b_powers",
"Vale.PPC64LE.Decls.va_get_mem_heaplet",
"Vale.PPC64LE.Decls.va_get_mem_layout",
"Vale.PPC64LE.Decls.va_get_reg",
"Prims.eq2",
"Vale.Math.Poly2_s.poly",
"Vale.Math.Poly2.Bits_s.of_quad32",
"Vale.PPC64LE.Decls.va_get_vec",
"Prims.int",
"Vale.AES.GHash_BE.poly128",
"Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.quad32",
"FStar.Seq.Base.create",
"Prims.l_Forall",
"Vale.PPC64LE.Memory.nat64",
"Prims.l_imp",
"Vale.AES.GHash_BE.ghash_incremental",
"Vale.PPC64LE.Machine_s.state",
"Vale.PPC64LE.Decls.va_upd_vec",
"Vale.PPC64LE.Decls.va_upd_reg"
] | [] | false | false | false | true | true | let va_wp_Ghash_register
(hkeys_b: buffer128)
(h_BE y_prev: quad32)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 =
| (va_get_ok va_s0 /\
(let h:Vale.Math.Poly2_s.poly = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in
let data:(FStar.Seq.Base.seq quad32) = FStar.Seq.Base.create #quad32 1 (va_get_vec 9 va_s0) in
let prev:Vale.Math.Poly2_s.poly = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in
let pdata:(Prims.int -> Vale.AES.GHash_BE.poly128) =
Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128 data
in
hkeys_b_powers hkeys_b
(va_get_mem_heaplet 0 va_s0)
(va_get_mem_layout va_s0)
(va_get_reg 5 va_s0)
h /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_s0) == prev) /\
(forall (va_x_r10: nat64) (va_x_v0: quad32) (va_x_v1: quad32) (va_x_v2: quad32) (va_x_v3: quad32)
(va_x_v4: quad32) (va_x_v5: quad32) (va_x_v6: quad32) (va_x_v7: quad32) (va_x_v8: quad32)
(va_x_v9: quad32) (va_x_v10: quad32).
let va_sM =
va_upd_vec 10
va_x_v10
(va_upd_vec 9
va_x_v9
(va_upd_vec 8
va_x_v8
(va_upd_vec 7
va_x_v7
(va_upd_vec 6
va_x_v6
(va_upd_vec 5
va_x_v5
(va_upd_vec 4
va_x_v4
(va_upd_vec 3
va_x_v3
(va_upd_vec 2
va_x_v2
(va_upd_vec 1
va_x_v1
(va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 va_s0)))
))))))))
in
va_get_ok va_sM /\
(let h:Vale.Math.Poly2_s.poly = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in
let data:(FStar.Seq.Base.seq quad32) =
FStar.Seq.Base.create #quad32 1 (va_get_vec 9 va_s0)
in
let prev:Vale.Math.Poly2_s.poly = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in
let pdata:(Prims.int -> Vale.AES.GHash_BE.poly128) =
Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128 data
in
va_get_vec 1 va_sM == Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data) ==>
va_k va_sM (()))) | false |
Hacl.Impl.P256.Group.fst | Hacl.Impl.P256.Group.mk_to_p256_comm_monoid | val mk_to_p256_comm_monoid:BE.to_comm_monoid U64 12ul 0ul | val mk_to_p256_comm_monoid:BE.to_comm_monoid U64 12ul 0ul | let mk_to_p256_comm_monoid : BE.to_comm_monoid U64 12ul 0ul = {
BE.a_spec = S.aff_point;
BE.comm_monoid = S.mk_p256_comm_monoid;
BE.linv_ctx = linv_ctx;
BE.linv = point_inv_seq;
BE.refl = refl;
} | {
"file_name": "code/ecdsap256/Hacl.Impl.P256.Group.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 1,
"end_line": 36,
"start_col": 0,
"start_line": 30
} | module Hacl.Impl.P256.Group
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module BE = Hacl.Impl.Exponentiation.Definitions
module S = Spec.P256
module SL = Spec.P256.Lemmas
open Hacl.Impl.P256.Point
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True
unfold
let refl (p:LSeq.lseq uint64 12{point_inv_seq p}) : GTot S.aff_point =
S.to_aff_point (from_mont_point (as_point_nat_seq p)) | {
"checked_file": "/",
"dependencies": [
"Spec.P256.Lemmas.fsti.checked",
"Spec.P256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.P256.PointDouble.fsti.checked",
"Hacl.Impl.P256.PointAdd.fsti.checked",
"Hacl.Impl.P256.Point.fsti.checked",
"Hacl.Impl.Exponentiation.Definitions.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.Impl.P256.Group.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Impl.Exponentiation.Definitions.to_comm_monoid Lib.IntTypes.U64
(12ul <: FStar.UInt32.t)
(0ul <: FStar.UInt32.t) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Exponentiation.Definitions.Mkto_comm_monoid",
"Lib.IntTypes.U64",
"FStar.UInt32.uint_to_t",
"Spec.P256.PointOps.aff_point",
"Spec.P256.mk_p256_comm_monoid",
"Hacl.Impl.P256.Group.linv_ctx",
"Hacl.Impl.P256.Point.point_inv_seq",
"Hacl.Impl.P256.Group.refl"
] | [] | false | false | false | false | false | let mk_to_p256_comm_monoid:BE.to_comm_monoid U64 12ul 0ul =
| {
BE.a_spec = S.aff_point;
BE.comm_monoid = S.mk_p256_comm_monoid;
BE.linv_ctx = linv_ctx;
BE.linv = point_inv_seq;
BE.refl = refl
} | false |
Hacl.Impl.P256.Group.fst | Hacl.Impl.P256.Group.point_add | val point_add : BE.lmul_st U64 12ul 0ul mk_to_p256_comm_monoid | val point_add : BE.lmul_st U64 12ul 0ul mk_to_p256_comm_monoid | let point_add ctx x y xy =
let h0 = ST.get () in
SL.to_aff_point_add_lemma
(from_mont_point (as_point_nat h0 x)) (from_mont_point (as_point_nat h0 y));
Hacl.Impl.P256.PointAdd.point_add xy x y | {
"file_name": "code/ecdsap256/Hacl.Impl.P256.Group.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 42,
"end_line": 45,
"start_col": 0,
"start_line": 41
} | module Hacl.Impl.P256.Group
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module BE = Hacl.Impl.Exponentiation.Definitions
module S = Spec.P256
module SL = Spec.P256.Lemmas
open Hacl.Impl.P256.Point
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True
unfold
let refl (p:LSeq.lseq uint64 12{point_inv_seq p}) : GTot S.aff_point =
S.to_aff_point (from_mont_point (as_point_nat_seq p))
inline_for_extraction noextract
let mk_to_p256_comm_monoid : BE.to_comm_monoid U64 12ul 0ul = {
BE.a_spec = S.aff_point;
BE.comm_monoid = S.mk_p256_comm_monoid;
BE.linv_ctx = linv_ctx;
BE.linv = point_inv_seq;
BE.refl = refl;
}
inline_for_extraction noextract | {
"checked_file": "/",
"dependencies": [
"Spec.P256.Lemmas.fsti.checked",
"Spec.P256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.P256.PointDouble.fsti.checked",
"Hacl.Impl.P256.PointAdd.fsti.checked",
"Hacl.Impl.P256.Point.fsti.checked",
"Hacl.Impl.Exponentiation.Definitions.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.Impl.P256.Group.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Impl.Exponentiation.Definitions.lmul_st Lib.IntTypes.U64
12ul
0ul
Hacl.Impl.P256.Group.mk_to_p256_comm_monoid | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.P256.PointAdd.point_add",
"Prims.unit",
"Spec.P256.Lemmas.to_aff_point_add_lemma",
"Hacl.Impl.P256.Point.from_mont_point",
"Hacl.Impl.P256.Point.as_point_nat",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | false | false | false | false | false | let point_add ctx x y xy =
| let h0 = ST.get () in
SL.to_aff_point_add_lemma (from_mont_point (as_point_nat h0 x))
(from_mont_point (as_point_nat h0 y));
Hacl.Impl.P256.PointAdd.point_add xy x y | false |
Hacl.P256.PrecompTable.fst | Hacl.P256.PrecompTable.precomp_g_pow2_64_table_lseq_w4 | val precomp_g_pow2_64_table_lseq_w4 : LSeq.lseq uint64 192 | val precomp_g_pow2_64_table_lseq_w4 : LSeq.lseq uint64 192 | let precomp_g_pow2_64_table_lseq_w4 : LSeq.lseq uint64 192 =
normalize_term_spec (SPT.precomp_base_table_list mk_p256_precomp_base_table proj_g_pow2_64 15);
Seq.seq_of_list precomp_g_pow2_64_table_list_w4 | {
"file_name": "code/ecdsap256/Hacl.P256.PrecompTable.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 49,
"end_line": 224,
"start_col": 0,
"start_line": 222
} | module Hacl.P256.PrecompTable
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module SPT = Hacl.Spec.PrecompBaseTable
module SPT256 = Hacl.Spec.PrecompBaseTable256
module SPTK = Hacl.Spec.P256.PrecompTable
module S = Spec.P256
module SL = Spec.P256.Lemmas
open Hacl.Impl.P256.Point
include Hacl.Impl.P256.Group
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let proj_point_to_list p =
SPTK.proj_point_to_list_lemma p;
SPTK.proj_point_to_list p
let lemma_refl x =
SPTK.proj_point_to_list_lemma x
//-----------------
inline_for_extraction noextract
let proj_g_pow2_64 : S.proj_point =
[@inline_let]
let rX : S.felem = 0x000931f4ae428a4ad81ee0aa89cf5247ce85d4dd696c61b4bb9d4761e57b7fbe in
[@inline_let]
let rY : S.felem = 0x7e88e5e6a142d5c2269f21a158e82ab2c79fcecb26e397b96fd5b9fbcd0a69a5 in
[@inline_let]
let rZ : S.felem = 0x02626dc2dd5e06cd19de5e6afb6c5dbdd3e41dc1472e7b8ef11eb0662e41c44b in
(rX, rY, rZ)
val lemma_proj_g_pow2_64_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops S.base_point 64 == proj_g_pow2_64)
let lemma_proj_g_pow2_64_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops S.base_point 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64);
let rX : S.felem = 0x000931f4ae428a4ad81ee0aa89cf5247ce85d4dd696c61b4bb9d4761e57b7fbe in
let rY : S.felem = 0x7e88e5e6a142d5c2269f21a158e82ab2c79fcecb26e397b96fd5b9fbcd0a69a5 in
let rZ : S.felem = 0x02626dc2dd5e06cd19de5e6afb6c5dbdd3e41dc1472e7b8ef11eb0662e41c44b in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
inline_for_extraction noextract
let proj_g_pow2_128 : S.proj_point =
[@inline_let]
let rX : S.felem = 0x04c3aaf6c6c00704e96eda89461d63fd2c97ee1e6786fc785e6afac7aa92f9b1 in
[@inline_let]
let rY : S.felem = 0x14f1edaeb8e9c8d4797d164a3946c7ff50a7c8cd59139a4dbce354e6e4df09c3 in
[@inline_let]
let rZ : S.felem = 0x80119ced9a5ce83c4e31f8de1a38f89d5f9ff9f637dca86d116a4217f83e55d2 in
(rX, rY, rZ)
val lemma_proj_g_pow2_128_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_64 64 == proj_g_pow2_128)
let lemma_proj_g_pow2_128_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_64 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64);
let rX : S.felem = 0x04c3aaf6c6c00704e96eda89461d63fd2c97ee1e6786fc785e6afac7aa92f9b1 in
let rY : S.felem = 0x14f1edaeb8e9c8d4797d164a3946c7ff50a7c8cd59139a4dbce354e6e4df09c3 in
let rZ : S.felem = 0x80119ced9a5ce83c4e31f8de1a38f89d5f9ff9f637dca86d116a4217f83e55d2 in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
inline_for_extraction noextract
let proj_g_pow2_192 : S.proj_point =
[@inline_let]
let rX : S.felem = 0xc762a9c8ae1b2f7434ff8da70fe105e0d4f188594989f193de0dbdbf5f60cb9a in
[@inline_let]
let rY : S.felem = 0x1eddaf51836859e1369f1ae8d9ab02e4123b6f151d9b796e297a38fa5613d9bc in
[@inline_let]
let rZ : S.felem = 0xcb433ab3f67815707e398dc7910cc4ec6ea115360060fc73c35b53dce02e2c72 in
(rX, rY, rZ)
val lemma_proj_g_pow2_192_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_128 64 == proj_g_pow2_192)
let lemma_proj_g_pow2_192_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_128 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64);
let rX : S.felem = 0xc762a9c8ae1b2f7434ff8da70fe105e0d4f188594989f193de0dbdbf5f60cb9a in
let rY : S.felem = 0x1eddaf51836859e1369f1ae8d9ab02e4123b6f151d9b796e297a38fa5613d9bc in
let rZ : S.felem = 0xcb433ab3f67815707e398dc7910cc4ec6ea115360060fc73c35b53dce02e2c72 in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
// let proj_g_pow2_64 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64)
// let proj_g_pow2_128 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64)
// let proj_g_pow2_192 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64)
inline_for_extraction noextract
let proj_g_pow2_64_list : SPTK.point_list =
normalize_term (SPTK.proj_point_to_list proj_g_pow2_64)
inline_for_extraction noextract
let proj_g_pow2_128_list : SPTK.point_list =
normalize_term (SPTK.proj_point_to_list proj_g_pow2_128)
inline_for_extraction noextract
let proj_g_pow2_192_list : SPTK.point_list =
normalize_term (SPTK.proj_point_to_list proj_g_pow2_192)
let proj_g_pow2_64_lseq : LSeq.lseq uint64 12 =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_64);
Seq.seq_of_list proj_g_pow2_64_list
let proj_g_pow2_128_lseq : LSeq.lseq uint64 12 =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_128);
Seq.seq_of_list proj_g_pow2_128_list
let proj_g_pow2_192_lseq : LSeq.lseq uint64 12 =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_192);
Seq.seq_of_list proj_g_pow2_192_list
val proj_g_pow2_64_lemma: unit ->
Lemma (S.to_aff_point proj_g_pow2_64 == pow_point (pow2 64) g_aff)
let proj_g_pow2_64_lemma () =
lemma_proj_g_pow2_64_eval ();
SPT256.a_pow2_64_lemma S.mk_p256_concrete_ops S.base_point
val proj_g_pow2_128_lemma: unit ->
Lemma (S.to_aff_point proj_g_pow2_128 == pow_point (pow2 128) g_aff)
let proj_g_pow2_128_lemma () =
lemma_proj_g_pow2_128_eval ();
lemma_proj_g_pow2_64_eval ();
SPT256.a_pow2_128_lemma S.mk_p256_concrete_ops S.base_point
val proj_g_pow2_192_lemma: unit ->
Lemma (S.to_aff_point proj_g_pow2_192 == pow_point (pow2 192) g_aff)
let proj_g_pow2_192_lemma () =
lemma_proj_g_pow2_192_eval ();
lemma_proj_g_pow2_128_eval ();
lemma_proj_g_pow2_64_eval ();
SPT256.a_pow2_192_lemma S.mk_p256_concrete_ops S.base_point
let proj_g_pow2_64_lseq_lemma () =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_64);
proj_g_pow2_64_lemma ();
SPTK.proj_point_to_list_lemma proj_g_pow2_64
let proj_g_pow2_128_lseq_lemma () =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_128);
proj_g_pow2_128_lemma ();
SPTK.proj_point_to_list_lemma proj_g_pow2_128
let proj_g_pow2_192_lseq_lemma () =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_192);
proj_g_pow2_192_lemma ();
SPTK.proj_point_to_list_lemma proj_g_pow2_192
let mk_proj_g_pow2_64 () =
createL proj_g_pow2_64_list
let mk_proj_g_pow2_128 () =
createL proj_g_pow2_128_list
let mk_proj_g_pow2_192 () =
createL proj_g_pow2_192_list
//----------------
/// window size = 4; precomputed table = [[0]G, [1]G, ..., [15]G]
inline_for_extraction noextract
let precomp_basepoint_table_list_w4: x:list uint64{FStar.List.Tot.length x = 192} =
normalize_term (SPT.precomp_base_table_list mk_p256_precomp_base_table S.base_point 15)
let precomp_basepoint_table_lseq_w4 : LSeq.lseq uint64 192 =
normalize_term_spec (SPT.precomp_base_table_list mk_p256_precomp_base_table S.base_point 15);
Seq.seq_of_list precomp_basepoint_table_list_w4
let precomp_basepoint_table_lemma_w4 () =
normalize_term_spec (SPT.precomp_base_table_list mk_p256_precomp_base_table S.base_point 15);
SPT.precomp_base_table_lemma mk_p256_precomp_base_table S.base_point 16 precomp_basepoint_table_lseq_w4
let precomp_basepoint_table_w4:
x:glbuffer uint64 192ul{witnessed x precomp_basepoint_table_lseq_w4 /\ recallable x} =
createL_global precomp_basepoint_table_list_w4
/// window size = 4; precomputed table = [[0]([pow2 64]G), [1]([pow2 64]G), ..., [15]([pow2 64]G)]
inline_for_extraction noextract
let precomp_g_pow2_64_table_list_w4: x:list uint64{FStar.List.Tot.length x = 192} =
normalize_term (SPT.precomp_base_table_list mk_p256_precomp_base_table proj_g_pow2_64 15) | {
"checked_file": "/",
"dependencies": [
"Spec.P256.Lemmas.fsti.checked",
"Spec.P256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.PrecompBaseTable256.fsti.checked",
"Hacl.Spec.PrecompBaseTable.fsti.checked",
"Hacl.Spec.P256.PrecompTable.fsti.checked",
"Hacl.Impl.P256.Point.fsti.checked",
"Hacl.Impl.P256.Group.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.P256.PrecompTable.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.PrecompTable",
"short_module": "SPTK"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable256",
"short_module": "SPT256"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Group",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable",
"short_module": "SPT"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Lib.Sequence.lseq Lib.IntTypes.uint64 192 | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.seq_of_list",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Hacl.P256.PrecompTable.precomp_g_pow2_64_table_list_w4",
"Prims.unit",
"FStar.Pervasives.normalize_term_spec",
"Prims.list",
"Lib.IntTypes.uint_t",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.List.Tot.Base.length",
"FStar.Mul.op_Star",
"Prims.op_Addition",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"FStar.UInt32.uint_to_t",
"Hacl.Spec.PrecompBaseTable.precomp_base_table_list",
"Spec.P256.PointOps.proj_point",
"Hacl.P256.PrecompTable.mk_p256_precomp_base_table",
"Hacl.P256.PrecompTable.proj_g_pow2_64",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint64"
] | [] | false | false | false | false | false | let precomp_g_pow2_64_table_lseq_w4:LSeq.lseq uint64 192 =
| normalize_term_spec (SPT.precomp_base_table_list mk_p256_precomp_base_table proj_g_pow2_64 15);
Seq.seq_of_list precomp_g_pow2_64_table_list_w4 | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.alg_of_vale_impl | val alg_of_vale_impl : i: EverCrypt.CTR.Keys.vale_impl -> Spec.Agile.AEAD.alg | let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 47,
"start_col": 0,
"start_line": 44
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305 | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: EverCrypt.CTR.Keys.vale_impl -> Spec.Agile.AEAD.alg | Prims.Tot | [
"total"
] | [] | [
"EverCrypt.CTR.Keys.vale_impl",
"Spec.Agile.AEAD.AES128_GCM",
"Spec.Agile.AEAD.AES256_GCM",
"Spec.Agile.AEAD.alg"
] | [] | false | false | false | true | false | let alg_of_vale_impl (i: vale_impl) =
| match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM | false |
|
IfcExampleReify3.fst | IfcExampleReify3.ni_p1 | val ni_p1 (x y hi : id) (env:env) (h :rel heap) :
Lemma
(requires (x <> y /\ x <> hi /\ y <> hi /\
Low? (env x) /\
Low? (env y) /\
High? (env hi) /\
low_equiv env h))
(ensures (low_equiv env (R (p1_r x y hi (R?.l h)) (p1_r x y hi (R?.r h))))) | val ni_p1 (x y hi : id) (env:env) (h :rel heap) :
Lemma
(requires (x <> y /\ x <> hi /\ y <> hi /\
Low? (env x) /\
Low? (env y) /\
High? (env hi) /\
low_equiv env h))
(ensures (low_equiv env (R (p1_r x y hi (R?.l h)) (p1_r x y hi (R?.r h))))) | let ni_p1 x y hi env h = p1_x x y hi (R?.l h) ; p1_x x y hi (R?.r h) | {
"file_name": "examples/rel/IfcExampleReify3.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 68,
"end_line": 70,
"start_col": 0,
"start_line": 70
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module IfcExampleReify3
open FStar.DM4F.Heap.IntStoreFixed
open FStar.DM4F.IntStoreFixed
open Rel
type label =
| Low
| High
type env = id -> Tot label
type low_equiv (env:env) (h : rel heap) =
forall (x:id). {:pattern (Low? (env x))} (Low? (env x) ==> sel (R?.l h) x = sel (R?.r h) x)
(* AR: need to investigate what's happening without this is_x in p1 *)
let is_x (hi:id) (x:int) :INT_STORE bool (fun s0 p -> p ((index s0 hi = x), s0)) =
read hi = x
let p1 x y hi =
begin if is_x hi 0 then
let vx = read x in
let vy = read y in
write x (vx + vy)
else
let vx = read x in
let vy = read y in
let vhi = read hi in
write x (vx + vy + vhi)
end ;
let vx = read x in
let vhi = read hi in
write x (vx - vhi)
unfold
let p1_r x y hi h = (snd (reify (p1 x y hi) h))
#set-options "--z3rlimit 10"
val p1_x (x y hi : id) (h:heap) :
Lemma (requires (x <> y /\ x <> hi /\ y <> hi))
(ensures (let h' = p1_r x y hi h in
(sel h' y = sel h y) /\
(sel h' x = sel h x + sel h y) /\
(sel h' hi = sel h hi)))
let p1_x x y hi h = ()
val ni_p1 (x y hi : id) (env:env) (h :rel heap) :
Lemma
(requires (x <> y /\ x <> hi /\ y <> hi /\
Low? (env x) /\
Low? (env y) /\
High? (env hi) /\
low_equiv env h)) | {
"checked_file": "/",
"dependencies": [
"Rel.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.DM4F.IntStoreFixed.fst.checked",
"FStar.DM4F.Heap.IntStoreFixed.fsti.checked"
],
"interface_file": false,
"source_file": "IfcExampleReify3.fst"
} | [
{
"abbrev": false,
"full_module": "Rel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F.IntStoreFixed",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DM4F.Heap.IntStoreFixed",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
x: FStar.DM4F.Heap.IntStoreFixed.id ->
y: FStar.DM4F.Heap.IntStoreFixed.id ->
hi: FStar.DM4F.Heap.IntStoreFixed.id ->
env: IfcExampleReify3.env ->
h: Rel.rel FStar.DM4F.Heap.IntStoreFixed.heap
-> FStar.Pervasives.Lemma
(requires
x <> y /\ x <> hi /\ y <> hi /\ Low? (env x) /\ Low? (env y) /\ High? (env hi) /\
IfcExampleReify3.low_equiv env h)
(ensures
IfcExampleReify3.low_equiv env
(Rel.R (IfcExampleReify3.p1_r x y hi (R?.l h)) (IfcExampleReify3.p1_r x y hi (R?.r h)))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.DM4F.Heap.IntStoreFixed.id",
"IfcExampleReify3.env",
"Rel.rel",
"FStar.DM4F.Heap.IntStoreFixed.heap",
"IfcExampleReify3.p1_x",
"Rel.__proj__R__item__r",
"Prims.unit",
"Rel.__proj__R__item__l"
] | [] | true | false | true | false | false | let ni_p1 x y hi env h =
| p1_x x y hi (R?.l h);
p1_x x y hi (R?.r h) | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.supported_alg_of_impl | val supported_alg_of_impl (i: impl) : supported_alg | val supported_alg_of_impl (i: impl) : supported_alg | let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305 | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 38,
"end_line": 41,
"start_col": 0,
"start_line": 37
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other. | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Spec.Cipher.Expansion.impl -> Spec.Agile.AEAD.supported_alg | Prims.Tot | [
"total"
] | [] | [
"Spec.Cipher.Expansion.impl",
"Spec.Agile.AEAD.AES128_GCM",
"Spec.Agile.AEAD.AES256_GCM",
"Spec.Agile.AEAD.CHACHA20_POLY1305",
"Spec.Agile.AEAD.supported_alg"
] | [] | false | false | false | true | false | let supported_alg_of_impl (i: impl) : supported_alg =
| match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305 | false |
Hacl.SHA2.Vec256.fst | Hacl.SHA2.Vec256.sha384_4 | val sha384_4 (dst0 dst1 dst2 dst3: lbuffer uint8 48ul) (input_len:size_t) (input0 input1 input2 input3: lbuffer uint8 input_len) :
Stack unit
(requires fun h0 -> v input_len `less_than_max_input_length` SHA2_384 /\
live4 h0 input0 input1 input2 input3 /\
live4 h0 dst0 dst1 dst2 dst3 /\
internally_disjoint4 dst0 dst1 dst2 dst3)
(ensures fun h0 _ h1 -> modifies (loc dst0 |+| loc dst1 |+| loc dst2 |+| loc dst3) h0 h1 /\
as_seq h1 dst0 == Spec.hash SHA2_384 (as_seq h0 input0) /\
as_seq h1 dst1 == Spec.hash SHA2_384 (as_seq h0 input1) /\
as_seq h1 dst2 == Spec.hash SHA2_384 (as_seq h0 input2) /\
as_seq h1 dst3 == Spec.hash SHA2_384 (as_seq h0 input3)) | val sha384_4 (dst0 dst1 dst2 dst3: lbuffer uint8 48ul) (input_len:size_t) (input0 input1 input2 input3: lbuffer uint8 input_len) :
Stack unit
(requires fun h0 -> v input_len `less_than_max_input_length` SHA2_384 /\
live4 h0 input0 input1 input2 input3 /\
live4 h0 dst0 dst1 dst2 dst3 /\
internally_disjoint4 dst0 dst1 dst2 dst3)
(ensures fun h0 _ h1 -> modifies (loc dst0 |+| loc dst1 |+| loc dst2 |+| loc dst3) h0 h1 /\
as_seq h1 dst0 == Spec.hash SHA2_384 (as_seq h0 input0) /\
as_seq h1 dst1 == Spec.hash SHA2_384 (as_seq h0 input1) /\
as_seq h1 dst2 == Spec.hash SHA2_384 (as_seq h0 input2) /\
as_seq h1 dst3 == Spec.hash SHA2_384 (as_seq h0 input3)) | let sha384_4 dst0 dst1 dst2 dst3 input_len input0 input1 input2 input3 =
let ib = ntup4 (input0,(input1,(input2,input3))) in
let rb = ntup4 (dst0,(dst1,(dst2,dst3))) in
let h0 = ST.get() in
assert (live_multi h0 ib);
assert (live_multi h0 rb);
assert (internally_disjoint rb);
loc_multi4 rb;
hash #SHA2_384 #M256 sha384_init4 sha384_update_nblocks4 sha384_update_last4 sha384_finish4 rb input_len ib;
let h1 = ST.get() in
Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_384 #M256 (v input_len) (as_seq_multi h0 ib);
assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst0);
assert ((as_seq_multi h1 rb).(|1|) == as_seq h1 dst1);
assert ((as_seq_multi h1 rb).(|2|) == as_seq h1 dst2);
assert ((as_seq_multi h1 rb).(|3|) == as_seq h1 dst3) | {
"file_name": "code/sha2-mb/Hacl.SHA2.Vec256.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 149,
"start_col": 0,
"start_line": 135
} | module Hacl.SHA2.Vec256
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Buffer
open Lib.MultiBuffer
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
open Hacl.Impl.SHA2.Generic
module ST = FStar.HyperStack.ST
module Spec = Spec.Agile.Hash
module SpecVec = Hacl.Spec.SHA2.Vec
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
[@CInline] private let sha224_init8 = init #SHA2_224 #M256
[@CInline] private let sha224_update8 = update #SHA2_224 #M256
[@CInline] private let sha224_update_nblocks8 = update_nblocks #SHA2_224 #M256 sha224_update8
[@CInline] private let sha224_update_last8 = update_last #SHA2_224 #M256 sha224_update8
[@CInline] private let sha224_finish8 = finish #SHA2_224 #M256
val sha224_8
(dst0 dst1 dst2 dst3 dst4 dst5 dst6 dst7 : lbuffer uint8 28ul)
(input_len:size_t) (input0 input1 input2 input3 input4 input5 input6 input7 : lbuffer uint8 input_len) :
Stack unit
(requires fun h0 -> v input_len `less_than_max_input_length` SHA2_224 /\
live8 h0 input0 input1 input2 input3 input4 input5 input6 input7 /\
live8 h0 dst0 dst1 dst2 dst3 dst4 dst5 dst6 dst7 /\
internally_disjoint8 dst0 dst1 dst2 dst3 dst4 dst5 dst6 dst7)
(ensures fun h0 _ h1 ->
modifies (loc dst0 |+| (loc dst1 |+| (loc dst2 |+| (loc dst3 |+| (loc dst4 |+| (loc dst5 |+| (loc dst6 |+| loc dst7))))))) h0 h1 /\
as_seq h1 dst0 == Spec.hash SHA2_224 (as_seq h0 input0) /\
as_seq h1 dst1 == Spec.hash SHA2_224 (as_seq h0 input1) /\
as_seq h1 dst2 == Spec.hash SHA2_224 (as_seq h0 input2) /\
as_seq h1 dst3 == Spec.hash SHA2_224 (as_seq h0 input3) /\
as_seq h1 dst4 == Spec.hash SHA2_224 (as_seq h0 input4) /\
as_seq h1 dst5 == Spec.hash SHA2_224 (as_seq h0 input5) /\
as_seq h1 dst6 == Spec.hash SHA2_224 (as_seq h0 input6) /\
as_seq h1 dst7 == Spec.hash SHA2_224 (as_seq h0 input7))
let sha224_8 dst0 dst1 dst2 dst3 dst4 dst5 dst6 dst7 input_len input0 input1 input2 input3 input4 input5 input6 input7 =
let ib = ntup8 (input0,(input1,(input2,(input3,(input4,(input5,(input6,input7))))))) in
let rb = ntup8 (dst0,(dst1,(dst2,(dst3,(dst4,(dst5,(dst6,dst7))))))) in
let h0 = ST.get() in
assert (live_multi h0 ib);
assert (live_multi h0 rb);
assert (internally_disjoint rb);
loc_multi8 rb;
hash #SHA2_224 #M256 sha224_init8 sha224_update_nblocks8 sha224_update_last8 sha224_finish8 rb input_len ib;
let h1 = ST.get() in
Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_224 #M256 (v input_len) (as_seq_multi h0 ib);
assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst0);
assert ((as_seq_multi h1 rb).(|1|) == as_seq h1 dst1);
assert ((as_seq_multi h1 rb).(|2|) == as_seq h1 dst2);
assert ((as_seq_multi h1 rb).(|3|) == as_seq h1 dst3);
assert ((as_seq_multi h1 rb).(|4|) == as_seq h1 dst4);
assert ((as_seq_multi h1 rb).(|5|) == as_seq h1 dst5);
assert ((as_seq_multi h1 rb).(|6|) == as_seq h1 dst6);
assert ((as_seq_multi h1 rb).(|7|) == as_seq h1 dst7)
[@CInline] private let sha256_init8 = init #SHA2_256 #M256
[@CInline] private let sha256_update8 = update #SHA2_256 #M256
[@CInline] private let sha256_update_nblocks8 = update_nblocks #SHA2_256 #M256 sha256_update8
[@CInline] private let sha256_update_last8 = update_last #SHA2_256 #M256 sha256_update8
[@CInline] private let sha256_finish8 = finish #SHA2_256 #M256
val sha256_8
(dst0 dst1 dst2 dst3 dst4 dst5 dst6 dst7 : lbuffer uint8 32ul)
(input_len:size_t) (input0 input1 input2 input3 input4 input5 input6 input7 : lbuffer uint8 input_len) :
Stack unit
(requires fun h0 -> v input_len `less_than_max_input_length` SHA2_256 /\
live8 h0 input0 input1 input2 input3 input4 input5 input6 input7 /\
live8 h0 dst0 dst1 dst2 dst3 dst4 dst5 dst6 dst7 /\
internally_disjoint8 dst0 dst1 dst2 dst3 dst4 dst5 dst6 dst7)
(ensures fun h0 _ h1 ->
modifies (loc dst0 |+| (loc dst1 |+| (loc dst2 |+| (loc dst3 |+| (loc dst4 |+| (loc dst5 |+| (loc dst6 |+| loc dst7))))))) h0 h1 /\
as_seq h1 dst0 == Spec.hash SHA2_256 (as_seq h0 input0) /\
as_seq h1 dst1 == Spec.hash SHA2_256 (as_seq h0 input1) /\
as_seq h1 dst2 == Spec.hash SHA2_256 (as_seq h0 input2) /\
as_seq h1 dst3 == Spec.hash SHA2_256 (as_seq h0 input3) /\
as_seq h1 dst4 == Spec.hash SHA2_256 (as_seq h0 input4) /\
as_seq h1 dst5 == Spec.hash SHA2_256 (as_seq h0 input5) /\
as_seq h1 dst6 == Spec.hash SHA2_256 (as_seq h0 input6) /\
as_seq h1 dst7 == Spec.hash SHA2_256 (as_seq h0 input7))
let sha256_8 dst0 dst1 dst2 dst3 dst4 dst5 dst6 dst7 input_len input0 input1 input2 input3 input4 input5 input6 input7 =
let ib = ntup8 (input0,(input1,(input2,(input3,(input4,(input5,(input6,input7))))))) in
let rb = ntup8 (dst0,(dst1,(dst2,(dst3,(dst4,(dst5,(dst6,dst7))))))) in
let h0 = ST.get() in
assert (live_multi h0 ib);
assert (live_multi h0 rb);
assert (internally_disjoint rb);
loc_multi8 rb;
hash #SHA2_256 #M256 sha256_init8 sha256_update_nblocks8 sha256_update_last8 sha256_finish8 rb input_len ib;
let h1 = ST.get() in
Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_256 #M256 (v input_len) (as_seq_multi h0 ib);
assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst0);
assert ((as_seq_multi h1 rb).(|1|) == as_seq h1 dst1);
assert ((as_seq_multi h1 rb).(|2|) == as_seq h1 dst2);
assert ((as_seq_multi h1 rb).(|3|) == as_seq h1 dst3);
assert ((as_seq_multi h1 rb).(|4|) == as_seq h1 dst4);
assert ((as_seq_multi h1 rb).(|5|) == as_seq h1 dst5);
assert ((as_seq_multi h1 rb).(|6|) == as_seq h1 dst6);
assert ((as_seq_multi h1 rb).(|7|) == as_seq h1 dst7)
[@CInline] private let sha384_init4 = init #SHA2_384 #M256
[@CInline] private let sha384_update4 = update #SHA2_384 #M256
[@CInline] private let sha384_update_nblocks4 = update_nblocks #SHA2_384 #M256 sha384_update4
[@CInline] private let sha384_update_last4 = update_last #SHA2_384 #M256 sha384_update4
[@CInline] private let sha384_finish4 = finish #SHA2_384 #M256
val sha384_4 (dst0 dst1 dst2 dst3: lbuffer uint8 48ul) (input_len:size_t) (input0 input1 input2 input3: lbuffer uint8 input_len) :
Stack unit
(requires fun h0 -> v input_len `less_than_max_input_length` SHA2_384 /\
live4 h0 input0 input1 input2 input3 /\
live4 h0 dst0 dst1 dst2 dst3 /\
internally_disjoint4 dst0 dst1 dst2 dst3)
(ensures fun h0 _ h1 -> modifies (loc dst0 |+| loc dst1 |+| loc dst2 |+| loc dst3) h0 h1 /\
as_seq h1 dst0 == Spec.hash SHA2_384 (as_seq h0 input0) /\
as_seq h1 dst1 == Spec.hash SHA2_384 (as_seq h0 input1) /\
as_seq h1 dst2 == Spec.hash SHA2_384 (as_seq h0 input2) /\
as_seq h1 dst3 == Spec.hash SHA2_384 (as_seq h0 input3)) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.NTuple.fsti.checked",
"Lib.MultiBuffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Equiv.fst.checked",
"Hacl.Impl.SHA2.Generic.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.SHA2.Vec256.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": "SpecVec"
},
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.SHA2.Generic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.MultiBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"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.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
dst0: Lib.Buffer.lbuffer Lib.IntTypes.uint8 48ul ->
dst1: Lib.Buffer.lbuffer Lib.IntTypes.uint8 48ul ->
dst2: Lib.Buffer.lbuffer Lib.IntTypes.uint8 48ul ->
dst3: Lib.Buffer.lbuffer Lib.IntTypes.uint8 48ul ->
input_len: Lib.IntTypes.size_t ->
input0: Lib.Buffer.lbuffer Lib.IntTypes.uint8 input_len ->
input1: Lib.Buffer.lbuffer Lib.IntTypes.uint8 input_len ->
input2: Lib.Buffer.lbuffer Lib.IntTypes.uint8 input_len ->
input3: Lib.Buffer.lbuffer Lib.IntTypes.uint8 input_len
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.size_t",
"Prims._assert",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Hash.Definitions.hash_len",
"Spec.Hash.Definitions.SHA2_384",
"Lib.MultiBuffer.op_Lens_Access",
"FStar.Seq.Properties.lseq",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Vec.M256",
"Lib.MultiBuffer.as_seq_multi",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Prims.unit",
"Hacl.Spec.SHA2.Equiv.hash_agile_lemma",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Impl.SHA2.Generic.hash",
"Hacl.SHA2.Vec256.sha384_init4",
"Hacl.SHA2.Vec256.sha384_update_nblocks4",
"Hacl.SHA2.Vec256.sha384_update_last4",
"Hacl.SHA2.Vec256.sha384_finish4",
"Lib.MultiBuffer.loc_multi4",
"Lib.MultiBuffer.internally_disjoint",
"Lib.MultiBuffer.live_multi",
"Lib.NTuple.ntuple",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.NTuple.ntup4",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.tuple2"
] | [] | false | true | false | false | false | let sha384_4 dst0 dst1 dst2 dst3 input_len input0 input1 input2 input3 =
| let ib = ntup4 (input0, (input1, (input2, input3))) in
let rb = ntup4 (dst0, (dst1, (dst2, dst3))) in
let h0 = ST.get () in
assert (live_multi h0 ib);
assert (live_multi h0 rb);
assert (internally_disjoint rb);
loc_multi4 rb;
hash #SHA2_384
#M256
sha384_init4
sha384_update_nblocks4
sha384_update_last4
sha384_finish4
rb
input_len
ib;
let h1 = ST.get () in
Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_384 #M256 (v input_len) (as_seq_multi h0 ib);
assert ((as_seq_multi h1 rb).(| 0 |) == as_seq h1 dst0);
assert ((as_seq_multi h1 rb).(| 1 |) == as_seq h1 dst1);
assert ((as_seq_multi h1 rb).(| 2 |) == as_seq h1 dst2);
assert ((as_seq_multi h1 rb).(| 3 |) == as_seq h1 dst3) | false |
Hacl.SHA2.Vec256.fst | Hacl.SHA2.Vec256.sha512_4 | val sha512_4 (dst0 dst1 dst2 dst3: lbuffer uint8 64ul) (input_len:size_t) (input0 input1 input2 input3: lbuffer uint8 input_len) :
Stack unit
(requires fun h0 -> v input_len `less_than_max_input_length` SHA2_512 /\
live4 h0 input0 input1 input2 input3 /\
live4 h0 dst0 dst1 dst2 dst3 /\
internally_disjoint4 dst0 dst1 dst2 dst3)
(ensures fun h0 _ h1 -> modifies (loc dst0 |+| loc dst1 |+| loc dst2 |+| loc dst3) h0 h1 /\
as_seq h1 dst0 == Spec.hash SHA2_512 (as_seq h0 input0) /\
as_seq h1 dst1 == Spec.hash SHA2_512 (as_seq h0 input1) /\
as_seq h1 dst2 == Spec.hash SHA2_512 (as_seq h0 input2) /\
as_seq h1 dst3 == Spec.hash SHA2_512 (as_seq h0 input3)) | val sha512_4 (dst0 dst1 dst2 dst3: lbuffer uint8 64ul) (input_len:size_t) (input0 input1 input2 input3: lbuffer uint8 input_len) :
Stack unit
(requires fun h0 -> v input_len `less_than_max_input_length` SHA2_512 /\
live4 h0 input0 input1 input2 input3 /\
live4 h0 dst0 dst1 dst2 dst3 /\
internally_disjoint4 dst0 dst1 dst2 dst3)
(ensures fun h0 _ h1 -> modifies (loc dst0 |+| loc dst1 |+| loc dst2 |+| loc dst3) h0 h1 /\
as_seq h1 dst0 == Spec.hash SHA2_512 (as_seq h0 input0) /\
as_seq h1 dst1 == Spec.hash SHA2_512 (as_seq h0 input1) /\
as_seq h1 dst2 == Spec.hash SHA2_512 (as_seq h0 input2) /\
as_seq h1 dst3 == Spec.hash SHA2_512 (as_seq h0 input3)) | let sha512_4 dst0 dst1 dst2 dst3 input_len input0 input1 input2 input3 =
let ib = ntup4 (input0,(input1,(input2,input3))) in
let rb = ntup4 (dst0,(dst1,(dst2,dst3))) in
let h0 = ST.get() in
assert (live_multi h0 ib);
assert (live_multi h0 rb);
assert (internally_disjoint rb);
loc_multi4 rb;
hash #SHA2_512 #M256 sha512_init4 sha512_update_nblocks4 sha512_update_last4 sha512_finish4 rb input_len ib;
let h1 = ST.get() in
Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_512 #M256 (v input_len) (as_seq_multi h0 ib);
assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst0);
assert ((as_seq_multi h1 rb).(|1|) == as_seq h1 dst1);
assert ((as_seq_multi h1 rb).(|2|) == as_seq h1 dst2);
assert ((as_seq_multi h1 rb).(|3|) == as_seq h1 dst3) | {
"file_name": "code/sha2-mb/Hacl.SHA2.Vec256.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 186,
"start_col": 0,
"start_line": 172
} | module Hacl.SHA2.Vec256
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Buffer
open Lib.MultiBuffer
open Spec.Hash.Definitions
open Hacl.Spec.SHA2.Vec
open Hacl.Impl.SHA2.Generic
module ST = FStar.HyperStack.ST
module Spec = Spec.Agile.Hash
module SpecVec = Hacl.Spec.SHA2.Vec
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
[@CInline] private let sha224_init8 = init #SHA2_224 #M256
[@CInline] private let sha224_update8 = update #SHA2_224 #M256
[@CInline] private let sha224_update_nblocks8 = update_nblocks #SHA2_224 #M256 sha224_update8
[@CInline] private let sha224_update_last8 = update_last #SHA2_224 #M256 sha224_update8
[@CInline] private let sha224_finish8 = finish #SHA2_224 #M256
val sha224_8
(dst0 dst1 dst2 dst3 dst4 dst5 dst6 dst7 : lbuffer uint8 28ul)
(input_len:size_t) (input0 input1 input2 input3 input4 input5 input6 input7 : lbuffer uint8 input_len) :
Stack unit
(requires fun h0 -> v input_len `less_than_max_input_length` SHA2_224 /\
live8 h0 input0 input1 input2 input3 input4 input5 input6 input7 /\
live8 h0 dst0 dst1 dst2 dst3 dst4 dst5 dst6 dst7 /\
internally_disjoint8 dst0 dst1 dst2 dst3 dst4 dst5 dst6 dst7)
(ensures fun h0 _ h1 ->
modifies (loc dst0 |+| (loc dst1 |+| (loc dst2 |+| (loc dst3 |+| (loc dst4 |+| (loc dst5 |+| (loc dst6 |+| loc dst7))))))) h0 h1 /\
as_seq h1 dst0 == Spec.hash SHA2_224 (as_seq h0 input0) /\
as_seq h1 dst1 == Spec.hash SHA2_224 (as_seq h0 input1) /\
as_seq h1 dst2 == Spec.hash SHA2_224 (as_seq h0 input2) /\
as_seq h1 dst3 == Spec.hash SHA2_224 (as_seq h0 input3) /\
as_seq h1 dst4 == Spec.hash SHA2_224 (as_seq h0 input4) /\
as_seq h1 dst5 == Spec.hash SHA2_224 (as_seq h0 input5) /\
as_seq h1 dst6 == Spec.hash SHA2_224 (as_seq h0 input6) /\
as_seq h1 dst7 == Spec.hash SHA2_224 (as_seq h0 input7))
let sha224_8 dst0 dst1 dst2 dst3 dst4 dst5 dst6 dst7 input_len input0 input1 input2 input3 input4 input5 input6 input7 =
let ib = ntup8 (input0,(input1,(input2,(input3,(input4,(input5,(input6,input7))))))) in
let rb = ntup8 (dst0,(dst1,(dst2,(dst3,(dst4,(dst5,(dst6,dst7))))))) in
let h0 = ST.get() in
assert (live_multi h0 ib);
assert (live_multi h0 rb);
assert (internally_disjoint rb);
loc_multi8 rb;
hash #SHA2_224 #M256 sha224_init8 sha224_update_nblocks8 sha224_update_last8 sha224_finish8 rb input_len ib;
let h1 = ST.get() in
Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_224 #M256 (v input_len) (as_seq_multi h0 ib);
assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst0);
assert ((as_seq_multi h1 rb).(|1|) == as_seq h1 dst1);
assert ((as_seq_multi h1 rb).(|2|) == as_seq h1 dst2);
assert ((as_seq_multi h1 rb).(|3|) == as_seq h1 dst3);
assert ((as_seq_multi h1 rb).(|4|) == as_seq h1 dst4);
assert ((as_seq_multi h1 rb).(|5|) == as_seq h1 dst5);
assert ((as_seq_multi h1 rb).(|6|) == as_seq h1 dst6);
assert ((as_seq_multi h1 rb).(|7|) == as_seq h1 dst7)
[@CInline] private let sha256_init8 = init #SHA2_256 #M256
[@CInline] private let sha256_update8 = update #SHA2_256 #M256
[@CInline] private let sha256_update_nblocks8 = update_nblocks #SHA2_256 #M256 sha256_update8
[@CInline] private let sha256_update_last8 = update_last #SHA2_256 #M256 sha256_update8
[@CInline] private let sha256_finish8 = finish #SHA2_256 #M256
val sha256_8
(dst0 dst1 dst2 dst3 dst4 dst5 dst6 dst7 : lbuffer uint8 32ul)
(input_len:size_t) (input0 input1 input2 input3 input4 input5 input6 input7 : lbuffer uint8 input_len) :
Stack unit
(requires fun h0 -> v input_len `less_than_max_input_length` SHA2_256 /\
live8 h0 input0 input1 input2 input3 input4 input5 input6 input7 /\
live8 h0 dst0 dst1 dst2 dst3 dst4 dst5 dst6 dst7 /\
internally_disjoint8 dst0 dst1 dst2 dst3 dst4 dst5 dst6 dst7)
(ensures fun h0 _ h1 ->
modifies (loc dst0 |+| (loc dst1 |+| (loc dst2 |+| (loc dst3 |+| (loc dst4 |+| (loc dst5 |+| (loc dst6 |+| loc dst7))))))) h0 h1 /\
as_seq h1 dst0 == Spec.hash SHA2_256 (as_seq h0 input0) /\
as_seq h1 dst1 == Spec.hash SHA2_256 (as_seq h0 input1) /\
as_seq h1 dst2 == Spec.hash SHA2_256 (as_seq h0 input2) /\
as_seq h1 dst3 == Spec.hash SHA2_256 (as_seq h0 input3) /\
as_seq h1 dst4 == Spec.hash SHA2_256 (as_seq h0 input4) /\
as_seq h1 dst5 == Spec.hash SHA2_256 (as_seq h0 input5) /\
as_seq h1 dst6 == Spec.hash SHA2_256 (as_seq h0 input6) /\
as_seq h1 dst7 == Spec.hash SHA2_256 (as_seq h0 input7))
let sha256_8 dst0 dst1 dst2 dst3 dst4 dst5 dst6 dst7 input_len input0 input1 input2 input3 input4 input5 input6 input7 =
let ib = ntup8 (input0,(input1,(input2,(input3,(input4,(input5,(input6,input7))))))) in
let rb = ntup8 (dst0,(dst1,(dst2,(dst3,(dst4,(dst5,(dst6,dst7))))))) in
let h0 = ST.get() in
assert (live_multi h0 ib);
assert (live_multi h0 rb);
assert (internally_disjoint rb);
loc_multi8 rb;
hash #SHA2_256 #M256 sha256_init8 sha256_update_nblocks8 sha256_update_last8 sha256_finish8 rb input_len ib;
let h1 = ST.get() in
Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_256 #M256 (v input_len) (as_seq_multi h0 ib);
assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst0);
assert ((as_seq_multi h1 rb).(|1|) == as_seq h1 dst1);
assert ((as_seq_multi h1 rb).(|2|) == as_seq h1 dst2);
assert ((as_seq_multi h1 rb).(|3|) == as_seq h1 dst3);
assert ((as_seq_multi h1 rb).(|4|) == as_seq h1 dst4);
assert ((as_seq_multi h1 rb).(|5|) == as_seq h1 dst5);
assert ((as_seq_multi h1 rb).(|6|) == as_seq h1 dst6);
assert ((as_seq_multi h1 rb).(|7|) == as_seq h1 dst7)
[@CInline] private let sha384_init4 = init #SHA2_384 #M256
[@CInline] private let sha384_update4 = update #SHA2_384 #M256
[@CInline] private let sha384_update_nblocks4 = update_nblocks #SHA2_384 #M256 sha384_update4
[@CInline] private let sha384_update_last4 = update_last #SHA2_384 #M256 sha384_update4
[@CInline] private let sha384_finish4 = finish #SHA2_384 #M256
val sha384_4 (dst0 dst1 dst2 dst3: lbuffer uint8 48ul) (input_len:size_t) (input0 input1 input2 input3: lbuffer uint8 input_len) :
Stack unit
(requires fun h0 -> v input_len `less_than_max_input_length` SHA2_384 /\
live4 h0 input0 input1 input2 input3 /\
live4 h0 dst0 dst1 dst2 dst3 /\
internally_disjoint4 dst0 dst1 dst2 dst3)
(ensures fun h0 _ h1 -> modifies (loc dst0 |+| loc dst1 |+| loc dst2 |+| loc dst3) h0 h1 /\
as_seq h1 dst0 == Spec.hash SHA2_384 (as_seq h0 input0) /\
as_seq h1 dst1 == Spec.hash SHA2_384 (as_seq h0 input1) /\
as_seq h1 dst2 == Spec.hash SHA2_384 (as_seq h0 input2) /\
as_seq h1 dst3 == Spec.hash SHA2_384 (as_seq h0 input3))
let sha384_4 dst0 dst1 dst2 dst3 input_len input0 input1 input2 input3 =
let ib = ntup4 (input0,(input1,(input2,input3))) in
let rb = ntup4 (dst0,(dst1,(dst2,dst3))) in
let h0 = ST.get() in
assert (live_multi h0 ib);
assert (live_multi h0 rb);
assert (internally_disjoint rb);
loc_multi4 rb;
hash #SHA2_384 #M256 sha384_init4 sha384_update_nblocks4 sha384_update_last4 sha384_finish4 rb input_len ib;
let h1 = ST.get() in
Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_384 #M256 (v input_len) (as_seq_multi h0 ib);
assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst0);
assert ((as_seq_multi h1 rb).(|1|) == as_seq h1 dst1);
assert ((as_seq_multi h1 rb).(|2|) == as_seq h1 dst2);
assert ((as_seq_multi h1 rb).(|3|) == as_seq h1 dst3)
[@CInline] private let sha512_init4 = init #SHA2_512 #M256
[@CInline] private let sha512_update4 = update #SHA2_512 #M256
[@CInline] private let sha512_update_nblocks4 = update_nblocks #SHA2_512 #M256 sha512_update4
[@CInline] private let sha512_update_last4 = update_last #SHA2_512 #M256 sha512_update4
[@CInline] private let sha512_finish4 = finish #SHA2_512 #M256
val sha512_4 (dst0 dst1 dst2 dst3: lbuffer uint8 64ul) (input_len:size_t) (input0 input1 input2 input3: lbuffer uint8 input_len) :
Stack unit
(requires fun h0 -> v input_len `less_than_max_input_length` SHA2_512 /\
live4 h0 input0 input1 input2 input3 /\
live4 h0 dst0 dst1 dst2 dst3 /\
internally_disjoint4 dst0 dst1 dst2 dst3)
(ensures fun h0 _ h1 -> modifies (loc dst0 |+| loc dst1 |+| loc dst2 |+| loc dst3) h0 h1 /\
as_seq h1 dst0 == Spec.hash SHA2_512 (as_seq h0 input0) /\
as_seq h1 dst1 == Spec.hash SHA2_512 (as_seq h0 input1) /\
as_seq h1 dst2 == Spec.hash SHA2_512 (as_seq h0 input2) /\
as_seq h1 dst3 == Spec.hash SHA2_512 (as_seq h0 input3)) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.NTuple.fsti.checked",
"Lib.MultiBuffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.Equiv.fst.checked",
"Hacl.Impl.SHA2.Generic.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.SHA2.Vec256.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": "SpecVec"
},
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.SHA2.Generic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.MultiBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"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.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
dst0: Lib.Buffer.lbuffer Lib.IntTypes.uint8 64ul ->
dst1: Lib.Buffer.lbuffer Lib.IntTypes.uint8 64ul ->
dst2: Lib.Buffer.lbuffer Lib.IntTypes.uint8 64ul ->
dst3: Lib.Buffer.lbuffer Lib.IntTypes.uint8 64ul ->
input_len: Lib.IntTypes.size_t ->
input0: Lib.Buffer.lbuffer Lib.IntTypes.uint8 input_len ->
input1: Lib.Buffer.lbuffer Lib.IntTypes.uint8 input_len ->
input2: Lib.Buffer.lbuffer Lib.IntTypes.uint8 input_len ->
input3: Lib.Buffer.lbuffer Lib.IntTypes.uint8 input_len
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.size_t",
"Prims._assert",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Hash.Definitions.hash_len",
"Spec.Hash.Definitions.SHA2_512",
"Lib.MultiBuffer.op_Lens_Access",
"FStar.Seq.Properties.lseq",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Vec.M256",
"Lib.MultiBuffer.as_seq_multi",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Prims.unit",
"Hacl.Spec.SHA2.Equiv.hash_agile_lemma",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Impl.SHA2.Generic.hash",
"Hacl.SHA2.Vec256.sha512_init4",
"Hacl.SHA2.Vec256.sha512_update_nblocks4",
"Hacl.SHA2.Vec256.sha512_update_last4",
"Hacl.SHA2.Vec256.sha512_finish4",
"Lib.MultiBuffer.loc_multi4",
"Lib.MultiBuffer.internally_disjoint",
"Lib.MultiBuffer.live_multi",
"Lib.NTuple.ntuple",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.NTuple.ntup4",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.tuple2"
] | [] | false | true | false | false | false | let sha512_4 dst0 dst1 dst2 dst3 input_len input0 input1 input2 input3 =
| let ib = ntup4 (input0, (input1, (input2, input3))) in
let rb = ntup4 (dst0, (dst1, (dst2, dst3))) in
let h0 = ST.get () in
assert (live_multi h0 ib);
assert (live_multi h0 rb);
assert (internally_disjoint rb);
loc_multi4 rb;
hash #SHA2_512
#M256
sha512_init4
sha512_update_nblocks4
sha512_update_last4
sha512_finish4
rb
input_len
ib;
let h1 = ST.get () in
Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_512 #M256 (v input_len) (as_seq_multi h0 ib);
assert ((as_seq_multi h1 rb).(| 0 |) == as_seq h1 dst0);
assert ((as_seq_multi h1 rb).(| 1 |) == as_seq h1 dst1);
assert ((as_seq_multi h1 rb).(| 2 |) == as_seq h1 dst2);
assert ((as_seq_multi h1 rb).(| 3 |) == as_seq h1 dst3) | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.create_in | val create_in: #a:alg -> create_in_st a | val create_in: #a:alg -> create_in_st a | let create_in #a r dst k =
match a with
| AES128_GCM -> create_in_aes128_gcm r dst k
| AES256_GCM -> create_in_aes256_gcm r dst k
| CHACHA20_POLY1305 -> create_in_chacha20_poly1305 r dst k
| _ -> UnsupportedAlgorithm | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 160,
"start_col": 0,
"start_line": 155
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success
#pop-options
inline_for_extraction noextract
let create_in_aes_gcm (i: vale_impl):
create_in_st (alg_of_vale_impl i) =
fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale then (
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then (
let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success
) else
UnsupportedAlgorithm
) else
UnsupportedAlgorithm
let create_in_aes128_gcm: create_in_st AES128_GCM = create_in_aes_gcm Vale_AES128
let create_in_aes256_gcm: create_in_st AES256_GCM = create_in_aes_gcm Vale_AES256 | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.AEAD.create_in_st a | Prims.Tot | [
"total"
] | [] | [
"Spec.Agile.AEAD.alg",
"FStar.Monotonic.HyperHeap.rid",
"LowStar.Buffer.pointer",
"LowStar.Buffer.pointer_or_null",
"EverCrypt.AEAD.state_s",
"LowStar.Buffer.buffer",
"EverCrypt.CTR.Keys.uint8",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.Integers.op_Greater_Equals",
"FStar.Integers.Signed",
"FStar.Integers.Winfinite",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"Spec.Agile.AEAD.key_length",
"EverCrypt.AEAD.create_in_aes128_gcm",
"EverCrypt.Error.error_code",
"EverCrypt.AEAD.create_in_aes256_gcm",
"EverCrypt.AEAD.create_in_chacha20_poly1305",
"EverCrypt.Error.UnsupportedAlgorithm"
] | [] | false | false | false | false | false | let create_in #a r dst k =
| match a with
| AES128_GCM -> create_in_aes128_gcm r dst k
| AES256_GCM -> create_in_aes256_gcm r dst k
| CHACHA20_POLY1305 -> create_in_chacha20_poly1305 r dst k
| _ -> UnsupportedAlgorithm | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.alg_of_state | val alg_of_state (a: G.erased alg) (s: state (G.reveal a)): Stack alg
(requires (fun h0 -> invariant #(G.reveal a) h0 s))
(ensures (fun h0 a' h1 ->
a' == G.reveal a /\
h0 == h1)) | val alg_of_state (a: G.erased alg) (s: state (G.reveal a)): Stack alg
(requires (fun h0 -> invariant #(G.reveal a) h0 s))
(ensures (fun h0 a' h1 ->
a' == G.reveal a /\
h0 == h1)) | let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 100,
"start_col": 0,
"start_line": 94
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// ------------------- | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.Ghost.erased Spec.Agile.AEAD.alg -> s: EverCrypt.AEAD.state (FStar.Ghost.reveal a)
-> FStar.HyperStack.ST.Stack Spec.Agile.AEAD.alg | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.Ghost.erased",
"Spec.Agile.AEAD.alg",
"EverCrypt.AEAD.state",
"FStar.Ghost.reveal",
"Spec.Cipher.Expansion.impl",
"Spec.Agile.AEAD.kv",
"LowStar.Buffer.buffer",
"FStar.UInt8.t",
"Spec.Agile.AEAD.CHACHA20_POLY1305",
"Spec.Agile.AEAD.AES128_GCM",
"Spec.Agile.AEAD.AES256_GCM",
"EverCrypt.AEAD.state_s",
"LowStar.BufferOps.op_Bang_Star",
"LowStar.Buffer.trivial_preorder"
] | [] | false | true | false | false | false | let alg_of_state a s =
| let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.encrypt_aes128_gcm | val encrypt_aes128_gcm: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)
-> encrypt_st AES128_GCM | val encrypt_aes128_gcm: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)
-> encrypt_st AES128_GCM | let encrypt_aes128_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES128_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES128 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable" | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 324,
"start_col": 0,
"start_line": 317
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success
#pop-options
inline_for_extraction noextract
let create_in_aes_gcm (i: vale_impl):
create_in_st (alg_of_vale_impl i) =
fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale then (
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then (
let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success
) else
UnsupportedAlgorithm
) else
UnsupportedAlgorithm
let create_in_aes128_gcm: create_in_st AES128_GCM = create_in_aes_gcm Vale_AES128
let create_in_aes256_gcm: create_in_st AES256_GCM = create_in_aes_gcm Vale_AES256
let create_in #a r dst k =
match a with
| AES128_GCM -> create_in_aes128_gcm r dst k
| AES256_GCM -> create_in_aes256_gcm r dst k
| CHACHA20_POLY1305 -> create_in_chacha20_poly1305 r dst k
| _ -> UnsupportedAlgorithm
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
inline_for_extraction noextract
let alloca_chacha20_poly1305: alloca_st CHACHA20_POLY1305 =
fun k ->
let h0 = ST.get () in
let ek = B.alloca 0uy 32ul in
let p = B.alloca (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.loc_none h0 h3;
p
#pop-options
inline_for_extraction noextract
let alloca_aes_gcm (i: vale_impl):
alloca_st (alg_of_vale_impl i) =
fun k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
let ek = B.alloca 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.alloca (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
p
inline_for_extraction noextract
let alloca_aes128_gcm: alloca_st AES128_GCM =
alloca_aes_gcm Vale_AES128
inline_for_extraction noextract
let alloca_aes256_gcm: alloca_st AES256_GCM =
alloca_aes_gcm Vale_AES256
let alloca #a k =
match a with
| AES128_GCM -> alloca_aes128_gcm k
| AES256_GCM -> alloca_aes256_gcm k
| CHACHA20_POLY1305 -> alloca_chacha20_poly1305 k
inline_for_extraction noextract
let aes_gcm_encrypt (i: vale_impl):
Vale.Wrapper.X64.GCMencryptOpt.encrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMencryptOpt.gcm128_encrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMencryptOpt256.gcm256_encrypt_opt_stdcall
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties.slice_slice'"
inline_for_extraction noextract
let encrypt_aes_gcm (i: vale_impl): encrypt_st (alg_of_vale_impl i) =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if B.is_null s then
InvalidKey
else
let a = alg_of_vale_impl i in
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len = 0ul then
InvalidIVLength
else
let open LowStar.BufferOps in
let Ek _ kv ek = !*s in
assert (
let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.AES_s.is_aes_key_LE (vale_alg_of_alg a) k_w);
push_frame();
let scratch_b = B.sub ek (concrete_xkey_len i) 176ul in
let ek = B.sub ek 0ul (concrete_xkey_len i) in
let keys_b = B.sub ek 0ul (key_offset i) in
let hkeys_b = B.sub ek (key_offset i) 128ul in
let h0 = get() in
// The iv can be arbitrary length, hence we need to allocate a new one to perform the hashing
let tmp_iv = B.alloca 0uy 16ul in
// There is no SMTPat on le_bytes_to_seq_quad32_to_bytes and the converse,
// so we need an explicit lemma
let lemma_hkeys_reqs () : Lemma
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.OptPublic.hkeys_reqs_pub
(Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 hkeys_b)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))))
= let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
let hkeys_quad = Vale.AES.OptPublic.get_hkeys_reqs (Vale.Def.Types_s.reverse_bytes_quad32 (
Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))) in
let hkeys = Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 (Vale.Def.Types_s.le_seq_quad32_to_bytes hkeys_quad) in
assert (Seq.equal (B.as_seq h0 hkeys_b) hkeys);
calc (==) {
Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 hkeys);
(==) { Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes hkeys_quad }
hkeys_quad;
}
in lemma_hkeys_reqs ();
// We perform the hashing of the iv. The extra buffer and the hashed iv are the same
Vale.Wrapper.X64.GCM_IV.compute_iv (vale_alg_of_alg a)
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w )
iv iv_len
tmp_iv tmp_iv
hkeys_b;
let h0 = get() in
aes_gcm_encrypt i
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w)
(Ghost.hide (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv)))
plain
(uint32_to_uint64 plain_len)
ad
(uint32_to_uint64 ad_len)
tmp_iv
cipher
tag
keys_b
hkeys_b
scratch_b;
let h1 = get() in
// This assert is needed for z3 to pick up sequence equality for ciphertext
// and tag. It could be avoided if the spec returned both instead of appending them
assert (
let kv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (G.reveal kv) in
let iv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv) in
// `ad` is called `auth` in Vale world; "additional data", "authenticated
// data", potato, potato
let ad_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 ad) in
let plain_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 plain) in
let cipher_nat, tag_nat =
Vale.AES.GCM_s.gcm_encrypt_LE (vale_alg_of_alg a) kv_nat iv_nat plain_nat ad_nat
in
Seq.equal (B.as_seq h1 cipher) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 cipher_nat) /\
Seq.equal (B.as_seq h1 tag) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 tag_nat));
pop_frame();
Success | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.squash EverCrypt.TargetConfig.hacl_can_compile_vale
-> EverCrypt.AEAD.encrypt_st Spec.Agile.AEAD.AES128_GCM | Prims.Tot | [
"total"
] | [] | [
"Prims.squash",
"Prims.b2t",
"EverCrypt.TargetConfig.hacl_can_compile_vale",
"LowStar.Buffer.pointer_or_null",
"EverCrypt.AEAD.state_s",
"Spec.Agile.AEAD.AES128_GCM",
"EverCrypt.AEAD.iv_p",
"FStar.UInt32.t",
"Prims.l_and",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.Integers.within_bounds",
"FStar.Integers.Unsigned",
"FStar.Integers.W32",
"FStar.Integers.v",
"LowStar.Monotonic.Buffer.length",
"EverCrypt.CTR.Keys.uint8",
"LowStar.Buffer.trivial_preorder",
"FStar.Integers.op_Greater",
"FStar.Integers.Signed",
"FStar.Integers.Winfinite",
"EverCrypt.AEAD.ad_p",
"FStar.Integers.op_Less_Equals",
"Prims.pow2",
"EverCrypt.AEAD.plain_p",
"Spec.Agile.AEAD.max_length",
"LowStar.Buffer.buffer",
"Prims.nat",
"Spec.Agile.AEAD.tag_length",
"EverCrypt.AEAD.encrypt_aes_gcm",
"Spec.Cipher.Expansion.Vale_AES128",
"EverCrypt.Error.error_code",
"Prims.bool",
"LowStar.Failure.failwith",
"Prims.unit",
"FStar.Pervasives.false_elim",
"EverCrypt.AEAD.encrypt_st"
] | [] | false | false | false | true | false | let encrypt_aes128_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale))
: encrypt_st AES128_GCM =
| fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale
then encrypt_aes_gcm Vale_AES128 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable" | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.alloca | val alloca: #a:alg -> alloca_st a | val alloca: #a:alg -> alloca_st a | let alloca #a k =
match a with
| AES128_GCM -> alloca_aes128_gcm k
| AES256_GCM -> alloca_aes256_gcm k
| CHACHA20_POLY1305 -> alloca_chacha20_poly1305 k | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 51,
"end_line": 203,
"start_col": 0,
"start_line": 199
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success
#pop-options
inline_for_extraction noextract
let create_in_aes_gcm (i: vale_impl):
create_in_st (alg_of_vale_impl i) =
fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale then (
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then (
let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success
) else
UnsupportedAlgorithm
) else
UnsupportedAlgorithm
let create_in_aes128_gcm: create_in_st AES128_GCM = create_in_aes_gcm Vale_AES128
let create_in_aes256_gcm: create_in_st AES256_GCM = create_in_aes_gcm Vale_AES256
let create_in #a r dst k =
match a with
| AES128_GCM -> create_in_aes128_gcm r dst k
| AES256_GCM -> create_in_aes256_gcm r dst k
| CHACHA20_POLY1305 -> create_in_chacha20_poly1305 r dst k
| _ -> UnsupportedAlgorithm
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
inline_for_extraction noextract
let alloca_chacha20_poly1305: alloca_st CHACHA20_POLY1305 =
fun k ->
let h0 = ST.get () in
let ek = B.alloca 0uy 32ul in
let p = B.alloca (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.loc_none h0 h3;
p
#pop-options
inline_for_extraction noextract
let alloca_aes_gcm (i: vale_impl):
alloca_st (alg_of_vale_impl i) =
fun k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
let ek = B.alloca 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.alloca (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
p
inline_for_extraction noextract
let alloca_aes128_gcm: alloca_st AES128_GCM =
alloca_aes_gcm Vale_AES128
inline_for_extraction noextract
let alloca_aes256_gcm: alloca_st AES256_GCM =
alloca_aes_gcm Vale_AES256 | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.AEAD.alloca_st a | Prims.Tot | [
"total"
] | [] | [
"Spec.Agile.AEAD.alg",
"LowStar.Buffer.buffer",
"EverCrypt.CTR.Keys.uint8",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.Integers.op_Greater_Equals",
"FStar.Integers.Signed",
"FStar.Integers.Winfinite",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"Spec.Agile.AEAD.key_length",
"EverCrypt.AEAD.alloca_aes128_gcm",
"LowStar.Buffer.pointer",
"EverCrypt.AEAD.state_s",
"Spec.Agile.AEAD.AES128_GCM",
"EverCrypt.AEAD.alloca_aes256_gcm",
"Spec.Agile.AEAD.AES256_GCM",
"EverCrypt.AEAD.alloca_chacha20_poly1305",
"Spec.Agile.AEAD.CHACHA20_POLY1305"
] | [] | false | false | false | false | false | let alloca #a k =
| match a with
| AES128_GCM -> alloca_aes128_gcm k
| AES256_GCM -> alloca_aes256_gcm k
| CHACHA20_POLY1305 -> alloca_chacha20_poly1305 k | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.valid | val valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0 | val valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0 | let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 18,
"end_line": 19,
"start_col": 0,
"start_line": 10
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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: LowParse.Spec.Base.parser k t ->
h: FStar.Monotonic.HyperStack.mem ->
s: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> Prims.GTot Type0 | Prims.GTot | [
"sometrivial"
] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.Base.Spec.valid'"
] | [] | false | false | false | false | true | let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0 =
| valid' p h s pos | false |
Vale.AES.PPC64LE.GHash.fsti | Vale.AES.PPC64LE.GHash.va_wp_ReduceLast | val va_wp_ReduceLast
(h_BE y_prev: quad32)
(data: (seq quad32))
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | val va_wp_ReduceLast
(h_BE y_prev: quad32)
(data: (seq quad32))
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | let va_wp_ReduceLast (h_BE:quad32) (y_prev:quad32) (data:(seq quad32)) (va_s0:va_state)
(va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in
let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in va_get_vec 8 va_s0 ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 3254779904 0 0 /\ n > 0 /\ add (add
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 2 va_s0)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 3 va_s0)) 64)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 4 va_s0)) 128) ==
Vale.AES.GHash_BE.ghash_unroll_back h prev pdata 0 n (n - 1)) /\ (forall (va_x_v0:quad32)
(va_x_v1:quad32) (va_x_v2:quad32) (va_x_v3:quad32) (va_x_v4:quad32) (va_x_v8:quad32)
(va_x_v9:quad32) (va_x_v10:quad32) . let va_sM = va_upd_vec 10 va_x_v10 (va_upd_vec 9 va_x_v9
(va_upd_vec 8 va_x_v8 (va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2
(va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 va_s0))))))) in va_get_ok va_sM /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in let xi =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_sM) in Vale.Math.Poly2.Bits_s.to_quad32 xi ==
Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data /\ xi == Vale.Math.Poly2.Bits_s.of_quad32
(Vale.Math.Poly2.Bits_s.to_quad32 xi)) ==> va_k va_sM (()))) | {
"file_name": "obj/Vale.AES.PPC64LE.GHash.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 64,
"end_line": 103,
"start_col": 0,
"start_line": 82
} | module Vale.AES.PPC64LE.GHash
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.AES.AES_BE_s
open Vale.PPC64LE.Machine_s
open Vale.PPC64LE.Memory
open Vale.PPC64LE.State
open Vale.PPC64LE.Decls
open Vale.PPC64LE.InsBasic
open Vale.PPC64LE.InsMem
open Vale.PPC64LE.InsVector
open Vale.PPC64LE.QuickCode
open Vale.PPC64LE.QuickCodes
open Vale.AES.AES_helpers
open Vale.Poly1305.Math // For lemma_poly_bits64()
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.Arch.TypesNative
open Vale.AES.PPC64LE.PolyOps
open Vale.AES.PPC64LE.GF128_Mul
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Bits_s
open Vale.Math.Poly2.Bits
open Vale.Math.Poly2.Lemmas
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.AES.GHash_BE
#reset-options "--z3rlimit 50"
unfold let va_subscript_FStar__Seq__Base__seq = Seq.index
let hkeys_b_powers (hkeys_b:buffer128) (heap0:vale_heap) (layout:vale_heap_layout) (ptr:int) (h:poly) =
validSrcAddrs128 heap0 ptr hkeys_b 3 layout Secret /\
of_quad32 (reverse_bytes_quad32 (buffer128_read hkeys_b 0 heap0)) == gf128_power h 1 /\
of_quad32 (reverse_bytes_quad32 (buffer128_read hkeys_b 1 heap0)) == gf128_power h 2
let in_b_blocks
(in_b:buffer128) (in_index count:int) (heap_s:vale_heap) (layout:vale_heap_layout) (ptr:int) (data:seq quad32)
=
validSrcAddrsOffset128 heap_s ptr in_b in_index count layout Secret /\
(forall (i:nat).{:pattern (index data i)}
i < count /\ i < length data ==>
reverse_bytes_quad32 (buffer128_read in_b (in_index + i) heap_s) == index data i)
//-- ReduceLast
val va_code_ReduceLast : va_dummy:unit -> Tot va_code
val va_codegen_success_ReduceLast : va_dummy:unit -> Tot va_pbool
val va_lemma_ReduceLast : va_b0:va_code -> va_s0:va_state -> h_BE:quad32 -> y_prev:quad32 ->
data:(seq quad32)
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_ReduceLast ()) va_s0 /\ va_get_ok va_s0 /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in va_get_vec 8 va_s0 ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 3254779904 0 0 /\ n > 0 /\ add (add
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 2 va_s0)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 3 va_s0)) 64)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 4 va_s0)) 128) ==
Vale.AES.GHash_BE.ghash_unroll_back h prev pdata 0 n (n - 1))))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in let xi =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_sM) in Vale.Math.Poly2.Bits_s.to_quad32 xi ==
Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data /\ xi == Vale.Math.Poly2.Bits_s.of_quad32
(Vale.Math.Poly2.Bits_s.to_quad32 xi)) /\ va_state_eq va_sM (va_update_vec 10 va_sM
(va_update_vec 9 va_sM (va_update_vec 8 va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM
(va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0 va_sM (va_update_ok va_sM
va_s0))))))))))) | {
"checked_file": "/",
"dependencies": [
"Vale.PPC64LE.State.fsti.checked",
"Vale.PPC64LE.QuickCodes.fsti.checked",
"Vale.PPC64LE.QuickCode.fst.checked",
"Vale.PPC64LE.Memory.fsti.checked",
"Vale.PPC64LE.Machine_s.fst.checked",
"Vale.PPC64LE.InsVector.fsti.checked",
"Vale.PPC64LE.InsMem.fsti.checked",
"Vale.PPC64LE.InsBasic.fsti.checked",
"Vale.PPC64LE.Decls.fsti.checked",
"Vale.Poly1305.Math.fsti.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Lemmas.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Math.Poly2.Bits.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.AES.PPC64LE.PolyOps.fsti.checked",
"Vale.AES.PPC64LE.GF128_Mul.fsti.checked",
"Vale.AES.GHash_BE.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.fsti.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.AES_helpers.fsti.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.PPC64LE.GHash.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math // For lemma_poly_bits64()",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h_BE: Vale.PPC64LE.Memory.quad32 ->
y_prev: Vale.PPC64LE.Memory.quad32 ->
data: FStar.Seq.Base.seq Vale.PPC64LE.Memory.quad32 ->
va_s0: Vale.PPC64LE.Decls.va_state ->
va_k: (_: Vale.PPC64LE.Decls.va_state -> _: Prims.unit -> Type0)
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.PPC64LE.Memory.quad32",
"FStar.Seq.Base.seq",
"Vale.PPC64LE.Decls.va_state",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Vale.PPC64LE.Decls.va_get_ok",
"Prims.eq2",
"Vale.Def.Words_s.four",
"Vale.Def.Types_s.nat32",
"Vale.PPC64LE.Decls.va_get_vec",
"Vale.Def.Words_s.Mkfour",
"Prims.op_GreaterThan",
"Vale.Math.Poly2_s.poly",
"Vale.Math.Poly2_s.add",
"Vale.Math.Poly2.Bits_s.of_quad32",
"Vale.Math.Poly2_s.shift",
"Vale.AES.GHash_BE.ghash_unroll_back",
"Prims.op_Subtraction",
"Prims.nat",
"FStar.Seq.Base.length",
"Prims.int",
"Vale.AES.GHash_BE.poly128",
"Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128",
"Prims.l_Forall",
"Prims.l_imp",
"Vale.Def.Types_s.quad32",
"Vale.Math.Poly2.Bits_s.to_quad32",
"Vale.AES.GHash_BE.ghash_incremental",
"Vale.PPC64LE.Machine_s.state",
"Vale.PPC64LE.Decls.va_upd_vec"
] | [] | false | false | false | true | true | let va_wp_ReduceLast
(h_BE y_prev: quad32)
(data: (seq quad32))
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 =
| (va_get_ok va_s0 /\
(let h:Vale.Math.Poly2_s.poly = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in
let prev:Vale.Math.Poly2_s.poly = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in
let pdata:(Prims.int -> Vale.AES.GHash_BE.poly128) =
Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128 data
in
let n:Prims.nat = FStar.Seq.Base.length #quad32 data in
va_get_vec 8 va_s0 == Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 3254779904 0 0 /\ n > 0 /\
add (add (Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 2 va_s0))
(Vale.Math.Poly2_s.shift (Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 3 va_s0)) 64))
(Vale.Math.Poly2_s.shift (Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 4 va_s0)) 128) ==
Vale.AES.GHash_BE.ghash_unroll_back h prev pdata 0 n (n - 1)) /\
(forall (va_x_v0: quad32)
(va_x_v1: quad32)
(va_x_v2: quad32)
(va_x_v3: quad32)
(va_x_v4: quad32)
(va_x_v8: quad32)
(va_x_v9: quad32)
(va_x_v10: quad32).
let va_sM =
va_upd_vec 10
va_x_v10
(va_upd_vec 9
va_x_v9
(va_upd_vec 8
va_x_v8
(va_upd_vec 4
va_x_v4
(va_upd_vec 3
va_x_v3
(va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 va_s0)))
))))
in
va_get_ok va_sM /\
(let h:Vale.Math.Poly2_s.poly = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in
let prev:Vale.Math.Poly2_s.poly = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in
let pdata:(Prims.int -> Vale.AES.GHash_BE.poly128) =
Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128 data
in
let n:Prims.nat = FStar.Seq.Base.length #quad32 data in
let xi = Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_sM) in
Vale.Math.Poly2.Bits_s.to_quad32 xi == Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data /\
xi == Vale.Math.Poly2.Bits_s.of_quad32 (Vale.Math.Poly2.Bits_s.to_quad32 xi)) ==>
va_k va_sM (()))) | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.invariant_s | val invariant_s: (#a:alg) -> HS.mem -> state_s a -> Type0 | val invariant_s: (#a:alg) -> HS.mem -> state_s a -> Type0 | let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i) | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 43,
"end_line": 82,
"start_col": 0,
"start_line": 67
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | h: FStar.Monotonic.HyperStack.mem -> _: EverCrypt.AEAD.state_s a -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Spec.Agile.AEAD.alg",
"FStar.Monotonic.HyperStack.mem",
"EverCrypt.AEAD.state_s",
"Spec.Cipher.Expansion.impl",
"FStar.Ghost.erased",
"Spec.Agile.AEAD.kv",
"LowStar.Buffer.buffer",
"FStar.UInt8.t",
"Prims.l_and",
"Prims.b2t",
"Spec.Agile.AEAD.is_supported_alg",
"Prims.op_Equality",
"EverCrypt.AEAD.supported_alg_of_impl",
"LowStar.Monotonic.Buffer.live",
"LowStar.Buffer.trivial_preorder",
"FStar.Integers.op_Greater_Equals",
"FStar.Integers.Signed",
"FStar.Integers.Winfinite",
"LowStar.Monotonic.Buffer.length",
"Spec.Cipher.Expansion.concrete_xkey_length",
"FStar.Seq.Base.equal",
"LowStar.Monotonic.Buffer.as_seq",
"LowStar.Buffer.gsub",
"FStar.UInt32.__uint_to_t",
"FStar.UInt32.uint_to_t",
"Spec.Cipher.Expansion.concrete_expand",
"FStar.Ghost.reveal",
"EverCrypt.AEAD.config_pre",
"Prims.int",
"FStar.Integers.op_Plus",
"Spec.Cipher.Expansion.vale_xkey_length",
"Spec.Agile.AEAD.cipher_alg_of_supported_alg",
"Prims.nat",
"Prims.logical"
] | [] | false | false | false | false | true | let invariant_s #a h (Ek i kv ek) =
| is_supported_alg a /\ a = supported_alg_of_impl i /\ B.live h ek /\
B.length ek >= concrete_xkey_length i /\
(B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i))))
`S.equal`
(concrete_expand i (G.reveal kv)) /\ config_pre a /\
(match i with
| Vale_AES128
| Vale_AES256 -> B.length ek = vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 -> B.length ek = concrete_xkey_length i) | false |
Vale.AES.PPC64LE.GHash.fsti | Vale.AES.PPC64LE.GHash.in_b_blocks | val in_b_blocks : in_b: Vale.PPC64LE.Memory.buffer128 ->
in_index: Prims.int ->
count: Prims.int ->
heap_s: Vale.PPC64LE.InsBasic.vale_heap ->
layout: Vale.Arch.HeapImpl.vale_heap_layout ->
ptr: Prims.int ->
data: FStar.Seq.Base.seq Vale.PPC64LE.Memory.quad32
-> Prims.logical | let in_b_blocks
(in_b:buffer128) (in_index count:int) (heap_s:vale_heap) (layout:vale_heap_layout) (ptr:int) (data:seq quad32)
=
validSrcAddrsOffset128 heap_s ptr in_b in_index count layout Secret /\
(forall (i:nat).{:pattern (index data i)}
i < count /\ i < length data ==>
reverse_bytes_quad32 (buffer128_read in_b (in_index + i) heap_s) == index data i) | {
"file_name": "obj/Vale.AES.PPC64LE.GHash.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 87,
"end_line": 50,
"start_col": 0,
"start_line": 44
} | module Vale.AES.PPC64LE.GHash
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.AES.AES_BE_s
open Vale.PPC64LE.Machine_s
open Vale.PPC64LE.Memory
open Vale.PPC64LE.State
open Vale.PPC64LE.Decls
open Vale.PPC64LE.InsBasic
open Vale.PPC64LE.InsMem
open Vale.PPC64LE.InsVector
open Vale.PPC64LE.QuickCode
open Vale.PPC64LE.QuickCodes
open Vale.AES.AES_helpers
open Vale.Poly1305.Math // For lemma_poly_bits64()
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.Arch.TypesNative
open Vale.AES.PPC64LE.PolyOps
open Vale.AES.PPC64LE.GF128_Mul
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Bits_s
open Vale.Math.Poly2.Bits
open Vale.Math.Poly2.Lemmas
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.AES.GHash_BE
#reset-options "--z3rlimit 50"
unfold let va_subscript_FStar__Seq__Base__seq = Seq.index
let hkeys_b_powers (hkeys_b:buffer128) (heap0:vale_heap) (layout:vale_heap_layout) (ptr:int) (h:poly) =
validSrcAddrs128 heap0 ptr hkeys_b 3 layout Secret /\
of_quad32 (reverse_bytes_quad32 (buffer128_read hkeys_b 0 heap0)) == gf128_power h 1 /\
of_quad32 (reverse_bytes_quad32 (buffer128_read hkeys_b 1 heap0)) == gf128_power h 2 | {
"checked_file": "/",
"dependencies": [
"Vale.PPC64LE.State.fsti.checked",
"Vale.PPC64LE.QuickCodes.fsti.checked",
"Vale.PPC64LE.QuickCode.fst.checked",
"Vale.PPC64LE.Memory.fsti.checked",
"Vale.PPC64LE.Machine_s.fst.checked",
"Vale.PPC64LE.InsVector.fsti.checked",
"Vale.PPC64LE.InsMem.fsti.checked",
"Vale.PPC64LE.InsBasic.fsti.checked",
"Vale.PPC64LE.Decls.fsti.checked",
"Vale.Poly1305.Math.fsti.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Lemmas.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Math.Poly2.Bits.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.AES.PPC64LE.PolyOps.fsti.checked",
"Vale.AES.PPC64LE.GF128_Mul.fsti.checked",
"Vale.AES.GHash_BE.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.fsti.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.AES_helpers.fsti.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.PPC64LE.GHash.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math // For lemma_poly_bits64()",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
in_b: Vale.PPC64LE.Memory.buffer128 ->
in_index: Prims.int ->
count: Prims.int ->
heap_s: Vale.PPC64LE.InsBasic.vale_heap ->
layout: Vale.Arch.HeapImpl.vale_heap_layout ->
ptr: Prims.int ->
data: FStar.Seq.Base.seq Vale.PPC64LE.Memory.quad32
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.PPC64LE.Memory.buffer128",
"Prims.int",
"Vale.PPC64LE.InsBasic.vale_heap",
"Vale.Arch.HeapImpl.vale_heap_layout",
"FStar.Seq.Base.seq",
"Vale.PPC64LE.Memory.quad32",
"Prims.l_and",
"Vale.PPC64LE.Decls.validSrcAddrsOffset128",
"Vale.Arch.HeapTypes_s.Secret",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Prims.eq2",
"Vale.Def.Types_s.quad32",
"Vale.Def.Types_s.reverse_bytes_quad32",
"Vale.PPC64LE.Decls.buffer128_read",
"Prims.op_Addition",
"FStar.Seq.Base.index",
"Prims.logical"
] | [] | false | false | false | true | true | let in_b_blocks
(in_b: buffer128)
(in_index count: int)
(heap_s: vale_heap)
(layout: vale_heap_layout)
(ptr: int)
(data: seq quad32)
=
| validSrcAddrsOffset128 heap_s ptr in_b in_index count layout Secret /\
(forall (i: nat). {:pattern (index data i)}
i < count /\ i < length data ==>
reverse_bytes_quad32 (buffer128_read in_b (in_index + i) heap_s) == index data i) | false |
|
Vale.AES.PPC64LE.GHash.fsti | Vale.AES.PPC64LE.GHash.va_quick_Ghash_register | val va_quick_Ghash_register (hkeys_b: buffer128) (h_BE y_prev: quad32)
: (va_quickCode unit (va_code_Ghash_register ())) | val va_quick_Ghash_register (hkeys_b: buffer128) (h_BE y_prev: quad32)
: (va_quickCode unit (va_code_Ghash_register ())) | let va_quick_Ghash_register (hkeys_b:buffer128) (h_BE:quad32) (y_prev:quad32) : (va_quickCode unit
(va_code_Ghash_register ())) =
(va_QProc (va_code_Ghash_register ()) ([va_Mod_vec 10; va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 7;
va_Mod_vec 6; va_Mod_vec 5; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec
0; va_Mod_reg 10]) (va_wp_Ghash_register hkeys_b h_BE y_prev) (va_wpProof_Ghash_register
hkeys_b h_BE y_prev)) | {
"file_name": "obj/Vale.AES.PPC64LE.GHash.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 25,
"end_line": 267,
"start_col": 0,
"start_line": 262
} | module Vale.AES.PPC64LE.GHash
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.AES.AES_BE_s
open Vale.PPC64LE.Machine_s
open Vale.PPC64LE.Memory
open Vale.PPC64LE.State
open Vale.PPC64LE.Decls
open Vale.PPC64LE.InsBasic
open Vale.PPC64LE.InsMem
open Vale.PPC64LE.InsVector
open Vale.PPC64LE.QuickCode
open Vale.PPC64LE.QuickCodes
open Vale.AES.AES_helpers
open Vale.Poly1305.Math // For lemma_poly_bits64()
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.Arch.TypesNative
open Vale.AES.PPC64LE.PolyOps
open Vale.AES.PPC64LE.GF128_Mul
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Bits_s
open Vale.Math.Poly2.Bits
open Vale.Math.Poly2.Lemmas
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.AES.GHash_BE
#reset-options "--z3rlimit 50"
unfold let va_subscript_FStar__Seq__Base__seq = Seq.index
let hkeys_b_powers (hkeys_b:buffer128) (heap0:vale_heap) (layout:vale_heap_layout) (ptr:int) (h:poly) =
validSrcAddrs128 heap0 ptr hkeys_b 3 layout Secret /\
of_quad32 (reverse_bytes_quad32 (buffer128_read hkeys_b 0 heap0)) == gf128_power h 1 /\
of_quad32 (reverse_bytes_quad32 (buffer128_read hkeys_b 1 heap0)) == gf128_power h 2
let in_b_blocks
(in_b:buffer128) (in_index count:int) (heap_s:vale_heap) (layout:vale_heap_layout) (ptr:int) (data:seq quad32)
=
validSrcAddrsOffset128 heap_s ptr in_b in_index count layout Secret /\
(forall (i:nat).{:pattern (index data i)}
i < count /\ i < length data ==>
reverse_bytes_quad32 (buffer128_read in_b (in_index + i) heap_s) == index data i)
//-- ReduceLast
val va_code_ReduceLast : va_dummy:unit -> Tot va_code
val va_codegen_success_ReduceLast : va_dummy:unit -> Tot va_pbool
val va_lemma_ReduceLast : va_b0:va_code -> va_s0:va_state -> h_BE:quad32 -> y_prev:quad32 ->
data:(seq quad32)
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_ReduceLast ()) va_s0 /\ va_get_ok va_s0 /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in va_get_vec 8 va_s0 ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 3254779904 0 0 /\ n > 0 /\ add (add
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 2 va_s0)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 3 va_s0)) 64)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 4 va_s0)) 128) ==
Vale.AES.GHash_BE.ghash_unroll_back h prev pdata 0 n (n - 1))))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in let xi =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_sM) in Vale.Math.Poly2.Bits_s.to_quad32 xi ==
Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data /\ xi == Vale.Math.Poly2.Bits_s.of_quad32
(Vale.Math.Poly2.Bits_s.to_quad32 xi)) /\ va_state_eq va_sM (va_update_vec 10 va_sM
(va_update_vec 9 va_sM (va_update_vec 8 va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM
(va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0 va_sM (va_update_ok va_sM
va_s0)))))))))))
[@ va_qattr]
let va_wp_ReduceLast (h_BE:quad32) (y_prev:quad32) (data:(seq quad32)) (va_s0:va_state)
(va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in
let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in va_get_vec 8 va_s0 ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 3254779904 0 0 /\ n > 0 /\ add (add
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 2 va_s0)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 3 va_s0)) 64)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 4 va_s0)) 128) ==
Vale.AES.GHash_BE.ghash_unroll_back h prev pdata 0 n (n - 1)) /\ (forall (va_x_v0:quad32)
(va_x_v1:quad32) (va_x_v2:quad32) (va_x_v3:quad32) (va_x_v4:quad32) (va_x_v8:quad32)
(va_x_v9:quad32) (va_x_v10:quad32) . let va_sM = va_upd_vec 10 va_x_v10 (va_upd_vec 9 va_x_v9
(va_upd_vec 8 va_x_v8 (va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2
(va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 va_s0))))))) in va_get_ok va_sM /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in let xi =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_sM) in Vale.Math.Poly2.Bits_s.to_quad32 xi ==
Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data /\ xi == Vale.Math.Poly2.Bits_s.of_quad32
(Vale.Math.Poly2.Bits_s.to_quad32 xi)) ==> va_k va_sM (())))
val va_wpProof_ReduceLast : h_BE:quad32 -> y_prev:quad32 -> data:(seq quad32) -> va_s0:va_state ->
va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_ReduceLast h_BE y_prev data va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_ReduceLast ()) ([va_Mod_vec 10;
va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec
0]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_ReduceLast (h_BE:quad32) (y_prev:quad32) (data:(seq quad32)) : (va_quickCode unit
(va_code_ReduceLast ())) =
(va_QProc (va_code_ReduceLast ()) ([va_Mod_vec 10; va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 4;
va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0]) (va_wp_ReduceLast h_BE y_prev data)
(va_wpProof_ReduceLast h_BE y_prev data))
//--
//-- GhashUnroll_n
val va_code_GhashUnroll_n : exactly2:bool -> Tot va_code
val va_codegen_success_GhashUnroll_n : exactly2:bool -> Tot va_pbool
val va_lemma_GhashUnroll_n : va_b0:va_code -> va_s0:va_state -> exactly2:bool -> in_b:buffer128 ->
index:nat -> h_BE:quad32 -> y_prev:quad32 -> data:(seq quad32)
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_GhashUnroll_n exactly2) va_s0 /\ va_get_ok va_s0 /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in (exactly2 ==> n == 2) /\
(~exactly2 ==> n == 1) /\ in_b_blocks in_b index n (va_get_mem_heaplet 1 va_s0)
(va_get_mem_layout va_s0) (va_get_reg 7 va_s0) data /\ Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 1 va_s0) == prev /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 5 va_s0) ==
Vale.Math.Poly2.swap (Vale.AES.GHash_BE.gf128_power h 1) 64 /\ Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 6 va_s0) == Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.div
(Vale.AES.GHash_BE.gf128_power h 1) (Vale.Math.Poly2_s.monomial 64))
(Vale.Math.Poly2_s.monomial 64) /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 7 va_s0) ==
Vale.Math.Poly2_s.mod (Vale.AES.GHash_BE.gf128_power h 1) (Vale.Math.Poly2_s.monomial 64) /\
(exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 12 va_s0) == Vale.Math.Poly2.swap
(Vale.AES.GHash_BE.gf128_power h 2) 64) /\ (exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 13 va_s0) == Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.div
(Vale.AES.GHash_BE.gf128_power h 2) (Vale.Math.Poly2_s.monomial 64))
(Vale.Math.Poly2_s.monomial 64)) /\ (exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec
14 va_s0) == Vale.Math.Poly2_s.mod (Vale.AES.GHash_BE.gf128_power h 2)
(Vale.Math.Poly2_s.monomial 64)))))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in va_get_vec 1 va_sM ==
Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data) /\ va_state_eq va_sM (va_update_vec 11
va_sM (va_update_vec 10 va_sM (va_update_vec 9 va_sM (va_update_vec 8 va_sM (va_update_vec 4
va_sM (va_update_vec 3 va_sM (va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0
va_sM (va_update_reg 10 va_sM (va_update_ok va_sM va_s0)))))))))))))
[@ va_qattr]
let va_wp_GhashUnroll_n (exactly2:bool) (in_b:buffer128) (index:nat) (h_BE:quad32) (y_prev:quad32)
(data:(seq quad32)) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in
let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in (exactly2 ==> n == 2) /\
(~exactly2 ==> n == 1) /\ in_b_blocks in_b index n (va_get_mem_heaplet 1 va_s0)
(va_get_mem_layout va_s0) (va_get_reg 7 va_s0) data /\ Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 1 va_s0) == prev /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 5 va_s0) ==
Vale.Math.Poly2.swap (Vale.AES.GHash_BE.gf128_power h 1) 64 /\ Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 6 va_s0) == Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.div
(Vale.AES.GHash_BE.gf128_power h 1) (Vale.Math.Poly2_s.monomial 64))
(Vale.Math.Poly2_s.monomial 64) /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 7 va_s0) ==
Vale.Math.Poly2_s.mod (Vale.AES.GHash_BE.gf128_power h 1) (Vale.Math.Poly2_s.monomial 64) /\
(exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 12 va_s0) == Vale.Math.Poly2.swap
(Vale.AES.GHash_BE.gf128_power h 2) 64) /\ (exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 13 va_s0) == Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.div
(Vale.AES.GHash_BE.gf128_power h 2) (Vale.Math.Poly2_s.monomial 64))
(Vale.Math.Poly2_s.monomial 64)) /\ (exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec
14 va_s0) == Vale.Math.Poly2_s.mod (Vale.AES.GHash_BE.gf128_power h 2)
(Vale.Math.Poly2_s.monomial 64))) /\ (forall (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32)
(va_x_v2:quad32) (va_x_v3:quad32) (va_x_v4:quad32) (va_x_v8:quad32) (va_x_v9:quad32)
(va_x_v10:quad32) (va_x_v11:quad32) . let va_sM = va_upd_vec 11 va_x_v11 (va_upd_vec 10
va_x_v10 (va_upd_vec 9 va_x_v9 (va_upd_vec 8 va_x_v8 (va_upd_vec 4 va_x_v4 (va_upd_vec 3
va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 (va_upd_reg 10
va_x_r10 va_s0))))))))) in va_get_ok va_sM /\ (let (h:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let (prev:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let (pdata:(Prims.int -> Vale.AES.GHash_BE.poly128))
= Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128 data in let (n:Prims.nat) = FStar.Seq.Base.length
#quad32 data in va_get_vec 1 va_sM == Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data) ==>
va_k va_sM (())))
val va_wpProof_GhashUnroll_n : exactly2:bool -> in_b:buffer128 -> index:nat -> h_BE:quad32 ->
y_prev:quad32 -> data:(seq quad32) -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_GhashUnroll_n exactly2 in_b index h_BE y_prev data va_s0
va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_GhashUnroll_n exactly2) ([va_Mod_vec
11; va_Mod_vec 10; va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2;
va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_GhashUnroll_n (exactly2:bool) (in_b:buffer128) (index:nat) (h_BE:quad32)
(y_prev:quad32) (data:(seq quad32)) : (va_quickCode unit (va_code_GhashUnroll_n exactly2)) =
(va_QProc (va_code_GhashUnroll_n exactly2) ([va_Mod_vec 11; va_Mod_vec 10; va_Mod_vec 9;
va_Mod_vec 8; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg
10]) (va_wp_GhashUnroll_n exactly2 in_b index h_BE y_prev data) (va_wpProof_GhashUnroll_n
exactly2 in_b index h_BE y_prev data))
//--
//-- Ghash_register
val va_code_Ghash_register : va_dummy:unit -> Tot va_code
val va_codegen_success_Ghash_register : va_dummy:unit -> Tot va_pbool
val va_lemma_Ghash_register : va_b0:va_code -> va_s0:va_state -> hkeys_b:buffer128 -> h_BE:quad32
-> y_prev:quad32
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Ghash_register ()) va_s0 /\ va_get_ok va_s0 /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(data:(FStar.Seq.Base.seq quad32)) = FStar.Seq.Base.create #quad32 1 (va_get_vec 9 va_s0) in
let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in hkeys_b_powers hkeys_b (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0)
(va_get_reg 5 va_s0) h /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_s0) == prev)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(data:(FStar.Seq.Base.seq quad32)) = FStar.Seq.Base.create #quad32 1 (va_get_vec 9 va_s0) in
let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in va_get_vec 1 va_sM == Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data) /\
va_state_eq va_sM (va_update_vec 10 va_sM (va_update_vec 9 va_sM (va_update_vec 8 va_sM
(va_update_vec 7 va_sM (va_update_vec 6 va_sM (va_update_vec 5 va_sM (va_update_vec 4 va_sM
(va_update_vec 3 va_sM (va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0 va_sM
(va_update_reg 10 va_sM (va_update_ok va_sM va_s0)))))))))))))))
[@ va_qattr]
let va_wp_Ghash_register (hkeys_b:buffer128) (h_BE:quad32) (y_prev:quad32) (va_s0:va_state)
(va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in
let (data:(FStar.Seq.Base.seq quad32)) = FStar.Seq.Base.create #quad32 1 (va_get_vec 9 va_s0)
in let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in hkeys_b_powers hkeys_b (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0)
(va_get_reg 5 va_s0) h /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_s0) == prev) /\
(forall (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32) (va_x_v2:quad32) (va_x_v3:quad32)
(va_x_v4:quad32) (va_x_v5:quad32) (va_x_v6:quad32) (va_x_v7:quad32) (va_x_v8:quad32)
(va_x_v9:quad32) (va_x_v10:quad32) . let va_sM = va_upd_vec 10 va_x_v10 (va_upd_vec 9 va_x_v9
(va_upd_vec 8 va_x_v8 (va_upd_vec 7 va_x_v7 (va_upd_vec 6 va_x_v6 (va_upd_vec 5 va_x_v5
(va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1
(va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 va_s0))))))))))) in va_get_ok va_sM /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(data:(FStar.Seq.Base.seq quad32)) = FStar.Seq.Base.create #quad32 1 (va_get_vec 9 va_s0) in
let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in va_get_vec 1 va_sM == Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data) ==> va_k
va_sM (())))
val va_wpProof_Ghash_register : hkeys_b:buffer128 -> h_BE:quad32 -> y_prev:quad32 -> va_s0:va_state
-> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Ghash_register hkeys_b h_BE y_prev va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Ghash_register ()) ([va_Mod_vec 10;
va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 7; va_Mod_vec 6; va_Mod_vec 5; va_Mod_vec 4; va_Mod_vec
3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10]) va_s0 va_k ((va_sM, va_f0, va_g)))) | {
"checked_file": "/",
"dependencies": [
"Vale.PPC64LE.State.fsti.checked",
"Vale.PPC64LE.QuickCodes.fsti.checked",
"Vale.PPC64LE.QuickCode.fst.checked",
"Vale.PPC64LE.Memory.fsti.checked",
"Vale.PPC64LE.Machine_s.fst.checked",
"Vale.PPC64LE.InsVector.fsti.checked",
"Vale.PPC64LE.InsMem.fsti.checked",
"Vale.PPC64LE.InsBasic.fsti.checked",
"Vale.PPC64LE.Decls.fsti.checked",
"Vale.Poly1305.Math.fsti.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Lemmas.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Math.Poly2.Bits.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.AES.PPC64LE.PolyOps.fsti.checked",
"Vale.AES.PPC64LE.GF128_Mul.fsti.checked",
"Vale.AES.GHash_BE.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.fsti.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.AES_helpers.fsti.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.PPC64LE.GHash.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math // For lemma_poly_bits64()",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
hkeys_b: Vale.PPC64LE.Memory.buffer128 ->
h_BE: Vale.PPC64LE.Memory.quad32 ->
y_prev: Vale.PPC64LE.Memory.quad32
-> Vale.PPC64LE.QuickCode.va_quickCode Prims.unit
(Vale.AES.PPC64LE.GHash.va_code_Ghash_register ()) | Prims.Tot | [
"total"
] | [] | [
"Vale.PPC64LE.Memory.buffer128",
"Vale.PPC64LE.Memory.quad32",
"Vale.PPC64LE.QuickCode.va_QProc",
"Prims.unit",
"Vale.AES.PPC64LE.GHash.va_code_Ghash_register",
"Prims.Cons",
"Vale.PPC64LE.QuickCode.mod_t",
"Vale.PPC64LE.QuickCode.va_Mod_vec",
"Vale.PPC64LE.QuickCode.va_Mod_reg",
"Prims.Nil",
"Vale.AES.PPC64LE.GHash.va_wp_Ghash_register",
"Vale.AES.PPC64LE.GHash.va_wpProof_Ghash_register",
"Vale.PPC64LE.QuickCode.va_quickCode"
] | [] | false | false | false | false | false | let va_quick_Ghash_register (hkeys_b: buffer128) (h_BE y_prev: quad32)
: (va_quickCode unit (va_code_Ghash_register ())) =
| (va_QProc (va_code_Ghash_register ())
([
va_Mod_vec 10; va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 7; va_Mod_vec 6; va_Mod_vec 5;
va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10
])
(va_wp_Ghash_register hkeys_b h_BE y_prev)
(va_wpProof_Ghash_register hkeys_b h_BE y_prev)) | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.decrypt_aes128_gcm | val decrypt_aes128_gcm: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)
-> decrypt_st AES128_GCM | val decrypt_aes128_gcm: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)
-> decrypt_st AES128_GCM | let decrypt_aes128_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
decrypt_st AES128_GCM =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
decrypt_aes_gcm Vale_AES128 s iv iv_len ad ad_len cipher cipher_len tag dst
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable" | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 562,
"start_col": 0,
"start_line": 555
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success
#pop-options
inline_for_extraction noextract
let create_in_aes_gcm (i: vale_impl):
create_in_st (alg_of_vale_impl i) =
fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale then (
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then (
let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success
) else
UnsupportedAlgorithm
) else
UnsupportedAlgorithm
let create_in_aes128_gcm: create_in_st AES128_GCM = create_in_aes_gcm Vale_AES128
let create_in_aes256_gcm: create_in_st AES256_GCM = create_in_aes_gcm Vale_AES256
let create_in #a r dst k =
match a with
| AES128_GCM -> create_in_aes128_gcm r dst k
| AES256_GCM -> create_in_aes256_gcm r dst k
| CHACHA20_POLY1305 -> create_in_chacha20_poly1305 r dst k
| _ -> UnsupportedAlgorithm
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
inline_for_extraction noextract
let alloca_chacha20_poly1305: alloca_st CHACHA20_POLY1305 =
fun k ->
let h0 = ST.get () in
let ek = B.alloca 0uy 32ul in
let p = B.alloca (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.loc_none h0 h3;
p
#pop-options
inline_for_extraction noextract
let alloca_aes_gcm (i: vale_impl):
alloca_st (alg_of_vale_impl i) =
fun k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
let ek = B.alloca 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.alloca (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
p
inline_for_extraction noextract
let alloca_aes128_gcm: alloca_st AES128_GCM =
alloca_aes_gcm Vale_AES128
inline_for_extraction noextract
let alloca_aes256_gcm: alloca_st AES256_GCM =
alloca_aes_gcm Vale_AES256
let alloca #a k =
match a with
| AES128_GCM -> alloca_aes128_gcm k
| AES256_GCM -> alloca_aes256_gcm k
| CHACHA20_POLY1305 -> alloca_chacha20_poly1305 k
inline_for_extraction noextract
let aes_gcm_encrypt (i: vale_impl):
Vale.Wrapper.X64.GCMencryptOpt.encrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMencryptOpt.gcm128_encrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMencryptOpt256.gcm256_encrypt_opt_stdcall
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties.slice_slice'"
inline_for_extraction noextract
let encrypt_aes_gcm (i: vale_impl): encrypt_st (alg_of_vale_impl i) =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if B.is_null s then
InvalidKey
else
let a = alg_of_vale_impl i in
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len = 0ul then
InvalidIVLength
else
let open LowStar.BufferOps in
let Ek _ kv ek = !*s in
assert (
let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.AES_s.is_aes_key_LE (vale_alg_of_alg a) k_w);
push_frame();
let scratch_b = B.sub ek (concrete_xkey_len i) 176ul in
let ek = B.sub ek 0ul (concrete_xkey_len i) in
let keys_b = B.sub ek 0ul (key_offset i) in
let hkeys_b = B.sub ek (key_offset i) 128ul in
let h0 = get() in
// The iv can be arbitrary length, hence we need to allocate a new one to perform the hashing
let tmp_iv = B.alloca 0uy 16ul in
// There is no SMTPat on le_bytes_to_seq_quad32_to_bytes and the converse,
// so we need an explicit lemma
let lemma_hkeys_reqs () : Lemma
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.OptPublic.hkeys_reqs_pub
(Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 hkeys_b)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))))
= let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
let hkeys_quad = Vale.AES.OptPublic.get_hkeys_reqs (Vale.Def.Types_s.reverse_bytes_quad32 (
Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))) in
let hkeys = Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 (Vale.Def.Types_s.le_seq_quad32_to_bytes hkeys_quad) in
assert (Seq.equal (B.as_seq h0 hkeys_b) hkeys);
calc (==) {
Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 hkeys);
(==) { Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes hkeys_quad }
hkeys_quad;
}
in lemma_hkeys_reqs ();
// We perform the hashing of the iv. The extra buffer and the hashed iv are the same
Vale.Wrapper.X64.GCM_IV.compute_iv (vale_alg_of_alg a)
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w )
iv iv_len
tmp_iv tmp_iv
hkeys_b;
let h0 = get() in
aes_gcm_encrypt i
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w)
(Ghost.hide (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv)))
plain
(uint32_to_uint64 plain_len)
ad
(uint32_to_uint64 ad_len)
tmp_iv
cipher
tag
keys_b
hkeys_b
scratch_b;
let h1 = get() in
// This assert is needed for z3 to pick up sequence equality for ciphertext
// and tag. It could be avoided if the spec returned both instead of appending them
assert (
let kv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (G.reveal kv) in
let iv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv) in
// `ad` is called `auth` in Vale world; "additional data", "authenticated
// data", potato, potato
let ad_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 ad) in
let plain_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 plain) in
let cipher_nat, tag_nat =
Vale.AES.GCM_s.gcm_encrypt_LE (vale_alg_of_alg a) kv_nat iv_nat plain_nat ad_nat
in
Seq.equal (B.as_seq h1 cipher) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 cipher_nat) /\
Seq.equal (B.as_seq h1 tag) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 tag_nat));
pop_frame();
Success
let encrypt_aes128_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES128_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES128 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt_aes256_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES256_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES256 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt #a s iv iv_len ad ad_len plain plain_len cipher tag =
if B.is_null s then
InvalidKey
else
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
match i with
| Vale_AES128 ->
encrypt_aes128_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Vale_AES256 ->
encrypt_aes256_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Hacl_CHACHA20 ->
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len <> 12ul then
InvalidIVLength
else begin
// Length restrictions
assert_norm (pow2 31 + pow2 32 / 64 <= pow2 32 - 1);
EverCrypt.Chacha20Poly1305.aead_encrypt
ek iv ad_len ad plain_len plain cipher tag;
Success
end
inline_for_extraction noextract
let encrypt_expand_aes_gcm (i: vale_impl): encrypt_expand_st false (alg_of_vale_impl i) =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s (alg_of_vale_impl i)) = alloca k in
let r = encrypt_aes_gcm i s iv iv_len ad ad_len plain plain_len cipher tag in
assert(r == Success);
pop_frame ();
Success
let encrypt_expand_aes128_gcm_no_check : encrypt_expand_st false AES128_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale"
let encrypt_expand_aes256_gcm_no_check : encrypt_expand_st false AES256_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len plain plain_len cipher tag
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale"
let encrypt_expand_aes128_gcm : encrypt_expand_st true AES128_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then
encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else
UnsupportedAlgorithm
else
UnsupportedAlgorithm
let encrypt_expand_aes256_gcm : encrypt_expand_st true AES256_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then
encrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len plain plain_len cipher tag
else
UnsupportedAlgorithm
else
UnsupportedAlgorithm
let encrypt_expand_chacha20_poly1305 : encrypt_expand_st false CHACHA20_POLY1305 =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s CHACHA20_POLY1305) = alloca k in
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
EverCrypt.Chacha20Poly1305.aead_encrypt ek iv ad_len ad plain_len plain cipher tag;
pop_frame ();
Success
let encrypt_expand #a k iv iv_len ad ad_len plain plain_len cipher tag =
match a with
| AES128_GCM ->
encrypt_expand_aes128_gcm k iv iv_len ad ad_len plain plain_len cipher tag
| AES256_GCM ->
encrypt_expand_aes256_gcm k iv iv_len ad ad_len plain plain_len cipher tag
| CHACHA20_POLY1305 ->
encrypt_expand_chacha20_poly1305 k iv iv_len ad ad_len plain plain_len cipher tag
inline_for_extraction noextract
let aes_gcm_decrypt (i: vale_impl):
Vale.Wrapper.X64.GCMdecryptOpt.decrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMdecryptOpt.gcm128_decrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMdecryptOpt256.gcm256_decrypt_opt_stdcall
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties.slice_slice'"
inline_for_extraction noextract
let decrypt_aes_gcm (i: vale_impl): decrypt_st (alg_of_vale_impl i) =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if B.is_null s then
InvalidKey
else
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len = 0ul then
InvalidIVLength
else
let a = alg_of_vale_impl i in
let open LowStar.BufferOps in
let Ek _ kv ek = !*s in
assert (
let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.AES_s.is_aes_key_LE (vale_alg_of_alg a) k_w);
push_frame();
let scratch_b = B.sub ek (concrete_xkey_len i) 176ul in
let ek = B.sub ek 0ul (concrete_xkey_len i) in
let keys_b = B.sub ek 0ul (key_offset i) in
let hkeys_b = B.sub ek (key_offset i) 128ul in
let h0 = get() in
// The iv can be arbitrary length, hence we need to allocate a new one to perform the hashing
let tmp_iv = B.alloca 0uy 16ul in
// There is no SMTPat on le_bytes_to_seq_quad32_to_bytes and the converse,
// so we need an explicit lemma
let lemma_hkeys_reqs () : Lemma
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.OptPublic.hkeys_reqs_pub
(Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 hkeys_b)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))))
= let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
let hkeys_quad = Vale.AES.OptPublic.get_hkeys_reqs (Vale.Def.Types_s.reverse_bytes_quad32 (
Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))) in
let hkeys = Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 (Vale.Def.Types_s.le_seq_quad32_to_bytes hkeys_quad) in
assert (Seq.equal (B.as_seq h0 hkeys_b) hkeys);
calc (==) {
Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 hkeys);
(==) { Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes hkeys_quad }
hkeys_quad;
}
in lemma_hkeys_reqs ();
// We perform the hashing of the iv. The extra buffer and the hashed iv are the same
Vale.Wrapper.X64.GCM_IV.compute_iv (vale_alg_of_alg a)
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w )
iv iv_len
tmp_iv tmp_iv
hkeys_b;
let r = aes_gcm_decrypt i
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w)
(Ghost.hide (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv)))
cipher
(uint32_to_uint64 cipher_len)
ad
(uint32_to_uint64 ad_len)
tmp_iv
dst
tag
keys_b
hkeys_b
scratch_b in
let h1 = get() in
// This assert is needed for z3 to pick up sequence equality for ciphertext
// It could be avoided if the spec returned both instead of appending them
assert (
let kv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (G.reveal kv) in
let iv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv) in
// `ad` is called `auth` in Vale world; "additional data", "authenticated
// data", potato, potato
let ad_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 ad) in
let cipher_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 cipher) in
let tag_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 tag) in
let plain_nat, success =
Vale.AES.GCM_s.gcm_decrypt_LE (vale_alg_of_alg a) kv_nat iv_nat cipher_nat ad_nat tag_nat
in
Seq.equal (B.as_seq h1 dst) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 plain_nat) /\
(UInt64.v r = 0) == success);
assert (
let kv = G.reveal kv in
let cipher_tag = B.as_seq h0 cipher `S.append` B.as_seq h0 tag in
Seq.equal (Seq.slice cipher_tag (S.length cipher_tag - tag_length a) (S.length cipher_tag))
(B.as_seq h0 tag) /\
Seq.equal (Seq.slice cipher_tag 0 (S.length cipher_tag - tag_length a)) (B.as_seq h0 cipher));
pop_frame();
if r = 0uL then
Success
else
AuthenticationFailure | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.squash EverCrypt.TargetConfig.hacl_can_compile_vale
-> EverCrypt.AEAD.decrypt_st Spec.Agile.AEAD.AES128_GCM | Prims.Tot | [
"total"
] | [] | [
"Prims.squash",
"Prims.b2t",
"EverCrypt.TargetConfig.hacl_can_compile_vale",
"LowStar.Buffer.pointer_or_null",
"EverCrypt.AEAD.state_s",
"Spec.Agile.AEAD.AES128_GCM",
"EverCrypt.AEAD.iv_p",
"FStar.UInt32.t",
"Prims.l_and",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.Integers.within_bounds",
"FStar.Integers.Unsigned",
"FStar.Integers.W32",
"FStar.Integers.v",
"LowStar.Monotonic.Buffer.length",
"EverCrypt.CTR.Keys.uint8",
"LowStar.Buffer.trivial_preorder",
"FStar.Integers.op_Greater",
"FStar.Integers.Signed",
"FStar.Integers.Winfinite",
"EverCrypt.AEAD.ad_p",
"FStar.Integers.op_Less_Equals",
"Prims.pow2",
"EverCrypt.AEAD.cipher_p",
"LowStar.Buffer.buffer",
"Spec.Agile.AEAD.tag_length",
"Prims.nat",
"EverCrypt.AEAD.decrypt_aes_gcm",
"Spec.Cipher.Expansion.Vale_AES128",
"EverCrypt.Error.error_code",
"Prims.bool",
"LowStar.Failure.failwith",
"Prims.unit",
"FStar.Pervasives.false_elim",
"EverCrypt.AEAD.decrypt_st"
] | [] | false | false | false | true | false | let decrypt_aes128_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale))
: decrypt_st AES128_GCM =
| fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale
then decrypt_aes_gcm Vale_AES128 s iv iv_len ad ad_len cipher cipher_len tag dst
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable" | false |
CQueue.fst | CQueue.llist_fragment_tail_to_head | val llist_fragment_tail_to_head
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead ptail: ref (ccell_ptrvalue a))
: SteelGhost (Ghost.erased (ccell_ptrvalue a))
opened
((llist_fragment_tail l phead) `star` (vptr ptail))
(fun head -> (vptr phead) `star` (llist_fragment_head l phead (Ghost.reveal head)))
(fun h -> Ghost.reveal ptail == sel_llist_fragment_tail l phead h)
(fun h head h' ->
let v = sel_llist_fragment_head l phead head h' in
fst v == ptail /\ snd v == h (vptr ptail) /\ h' (vptr phead) == Ghost.reveal head)
(decreases (L.length (Ghost.reveal l))) | val llist_fragment_tail_to_head
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead ptail: ref (ccell_ptrvalue a))
: SteelGhost (Ghost.erased (ccell_ptrvalue a))
opened
((llist_fragment_tail l phead) `star` (vptr ptail))
(fun head -> (vptr phead) `star` (llist_fragment_head l phead (Ghost.reveal head)))
(fun h -> Ghost.reveal ptail == sel_llist_fragment_tail l phead h)
(fun h head h' ->
let v = sel_llist_fragment_head l phead head h' in
fst v == ptail /\ snd v == h (vptr ptail) /\ h' (vptr phead) == Ghost.reveal head)
(decreases (L.length (Ghost.reveal l))) | let rec llist_fragment_tail_to_head
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(ptail: ref (ccell_ptrvalue a))
: SteelGhost (Ghost.erased (ccell_ptrvalue a)) opened
(llist_fragment_tail l phead `star` vptr ptail)
(fun head -> vptr phead `star` llist_fragment_head l phead (Ghost.reveal head))
(fun h -> Ghost.reveal ptail == sel_llist_fragment_tail l phead h)
(fun h head h' ->
let v = sel_llist_fragment_head l phead head h' in
fst v == ptail /\
snd v == h (vptr ptail) /\
h' (vptr phead) == Ghost.reveal head
)
(decreases (L.length (Ghost.reveal l)))
=
if Nil? l
then begin
let g = gget (llist_fragment_tail l phead) in
assert (Ghost.reveal g == ptail);
elim_llist_fragment_tail_nil l phead;
change_equal_slprop
(vptr ptail)
(vptr phead);
let head = gget (vptr phead) in
intro_llist_fragment_head_nil l phead head;
head
end else begin
let us = elim_llist_fragment_tail_snoc l phead in
let tail = gget (vptr ptail) in
assert (ccell_next us.ll_unsnoc_tail == ptail);
intro_llist_fragment_head_nil [] (ccell_next us.ll_unsnoc_tail) tail;
change_equal_slprop
(vptr ptail)
(vptr (ccell_next us.ll_unsnoc_tail));
intro_ccell us.ll_unsnoc_tail;
let lc = intro_llist_fragment_head_cons us.ll_unsnoc_ptail us.ll_unsnoc_tail tail [] in
let head = llist_fragment_tail_to_head us.ll_unsnoc_l phead us.ll_unsnoc_ptail in
let g = gget (llist_fragment_head us.ll_unsnoc_l phead head) in
let g : Ghost.erased (ref (ccell_ptrvalue a) & ccell_ptrvalue a) = Ghost.hide (Ghost.reveal g) in
assert (Ghost.reveal g == (Ghost.reveal us.ll_unsnoc_ptail, Ghost.reveal us.ll_unsnoc_tail));
let l' = llist_fragment_head_append us.ll_unsnoc_l phead head lc us.ll_unsnoc_ptail us.ll_unsnoc_tail in
change_equal_slprop
(llist_fragment_head l' phead head)
(llist_fragment_head l phead head);
head
end | {
"file_name": "share/steel/examples/steel/CQueue.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 1086,
"start_col": 0,
"start_line": 1038
} | module CQueue
open CQueue.LList
#set-options "--ide_id_info_off"
//Re-define squash, since this module explicitly
//replies on proving equalities of the form `t_of v == squash p`
//which are delicate in the presence of optimizations that
//unfold `Prims.squash (p /\ q)`to _:unit{p /\ q}
//See Issue #2496
let squash (p:Type u#a) : Type0 = squash p
(* BEGIN library *)
let intro_vrewrite_no_norm (#opened:inames)
(v: vprop) (#t: Type) (f: (t_of v) -> GTot t)
: SteelGhost unit opened v (fun _ -> vrewrite v f)
(fun _ -> True) (fun h _ h' -> h' (vrewrite v f) == f (h v))
=
intro_vrewrite v f
let elim_vrewrite_no_norm (#opened:inames)
(v: vprop)
(#t: Type)
(f: ((t_of v) -> GTot t))
: SteelGhost unit opened (vrewrite v f) (fun _ -> v)
(fun _ -> True)
(fun h _ h' -> h (vrewrite v f) == f (h' v))
=
elim_vrewrite v f
let vconst_sel
(#a: Type)
(x: a)
: Tot (selector a (hp_of emp))
= fun _ -> x
[@@ __steel_reduce__]
let vconst'
(#a: Type)
(x: a)
: GTot vprop'
= {
hp = hp_of emp;
t = a;
sel = vconst_sel x;
}
[@@ __steel_reduce__]
let vconst (#a: Type) (x: a) : Tot vprop = VUnit (vconst' x)
let intro_vconst
(#opened: _)
(#a: Type)
(x: a)
: SteelGhost unit opened
emp
(fun _ -> vconst x)
(fun _ -> True)
(fun _ _ h' -> h' (vconst x) == x)
=
change_slprop_rel
emp
(vconst x)
(fun _ y -> y == x)
(fun _ -> ())
let elim_vconst
(#opened: _)
(#a: Type)
(x: a)
: SteelGhost unit opened
(vconst x)
(fun _ -> emp)
(fun _ -> True)
(fun h _ _ -> h (vconst x) == x)
=
change_slprop_rel
(vconst x)
emp
(fun y _ -> y == x)
(fun _ -> ())
let vpure_sel'
(p: prop)
: Tot (selector' (squash p) (Steel.Memory.pure p))
= fun (m: Steel.Memory.hmem (Steel.Memory.pure p)) -> pure_interp p m
let vpure_sel
(p: prop)
: Tot (selector (squash p) (Steel.Memory.pure p))
= vpure_sel' p
[@@ __steel_reduce__]
let vpure'
(p: prop)
: GTot vprop'
= {
hp = Steel.Memory.pure p;
t = squash p;
sel = vpure_sel p;
}
[@@ __steel_reduce__]
let vpure (p: prop) : Tot vprop = VUnit (vpure' p)
let intro_vpure
(#opened: _)
(p: prop)
: SteelGhost unit opened
emp
(fun _ -> vpure p)
(fun _ -> p)
(fun _ _ h' -> p)
=
change_slprop_rel
emp
(vpure p)
(fun _ _ -> p)
(fun m -> pure_interp p m)
let elim_vpure
(#opened: _)
(p: prop)
: SteelGhost unit opened
(vpure p)
(fun _ -> emp)
(fun _ -> True)
(fun _ _ _ -> p)
=
change_slprop_rel
(vpure p)
emp
(fun _ _ -> p)
(fun m -> pure_interp p m; reveal_emp (); intro_emp m)
val intro_vdep2 (#opened:inames)
(v: vprop)
(q: vprop)
(x: t_of v)
(p: (t_of v -> Tot vprop))
: SteelGhost unit opened
(v `star` q)
(fun _ -> vdep v p)
(requires (fun h ->
q == p x /\
x == h v
))
(ensures (fun h _ h' ->
let x2 = h' (vdep v p) in
q == p (h v) /\
dfst x2 == (h v) /\
dsnd x2 == (h q)
))
let intro_vdep2
v q x p
=
intro_vdep v q p
let vbind0_payload
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
(x: t_of a)
: Tot vprop
= vpure (t == t_of (b x)) `star` b x
let vbind0_rewrite
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
(x: normal (t_of (vdep a (vbind0_payload a t b))))
: Tot t
= snd (dsnd x)
[@@__steel_reduce__; __reduce__]
let vbind0
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: Tot vprop
= a `vdep` vbind0_payload a t b `vrewrite` vbind0_rewrite a t b
let vbind_hp // necessary to hide the attribute on hp_of
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: Tot (slprop u#1)
= hp_of (vbind0 a t b)
let vbind_sel // same for hp_sel
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: GTot (selector t (vbind_hp a t b))
= sel_of (vbind0 a t b)
[@@__steel_reduce__]
let vbind'
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: GTot vprop'
= {
hp = vbind_hp a t b;
t = t;
sel = vbind_sel a t b;
}
[@@__steel_reduce__]
let vbind
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: Tot vprop
= VUnit (vbind' a t b)
let intro_vbind
(#opened: _)
(a: vprop)
(b' : vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: SteelGhost unit opened
(a `star` b')
(fun _ -> vbind a t b)
(fun h -> t_of b' == t /\ b' == b (h a))
(fun h _ h' ->
t_of b' == t /\
b' == b (h a) /\
h' (vbind a t b) == h b'
)
=
intro_vpure (t == t_of b');
intro_vdep
a
(vpure (t == t_of b') `star` b')
(vbind0_payload a t b);
intro_vrewrite
(a `vdep` vbind0_payload a t b)
(vbind0_rewrite a t b);
change_slprop_rel
(vbind0 a t b)
(vbind a t b)
(fun x y -> x == y)
(fun _ -> ())
let elim_vbind
(#opened: _)
(a: vprop)
(t: Type0)
(b: (t_of a -> Tot vprop))
: SteelGhost (Ghost.erased (t_of a)) opened
(vbind a t b)
(fun res -> a `star` b (Ghost.reveal res))
(fun h -> True)
(fun h res h' ->
h' a == Ghost.reveal res /\
t == t_of (b (Ghost.reveal res)) /\
h' (b (Ghost.reveal res)) == h (vbind a t b)
)
=
change_slprop_rel
(vbind a t b)
(vbind0 a t b)
(fun x y -> x == y)
(fun _ -> ());
elim_vrewrite
(a `vdep` vbind0_payload a t b)
(vbind0_rewrite a t b);
let res = elim_vdep a (vbind0_payload a t b) in
change_equal_slprop
(vbind0_payload a t b (Ghost.reveal res))
(vpure (t == t_of (b (Ghost.reveal res))) `star` b (Ghost.reveal res));
elim_vpure (t == t_of (b (Ghost.reveal res)));
res
let (==) (#a:_) (x y: a) : prop = x == y
let snoc_inj (#a: Type) (hd1 hd2: list a) (tl1 tl2: a) : Lemma
(requires (hd1 `L.append` [tl1] == hd2 `L.append` [tl2]))
(ensures (hd1 == hd2 /\ tl1 == tl2))
[SMTPat (hd1 `L.append` [tl1]); SMTPat (hd2 `L.append` [tl2])]
= L.lemma_snoc_unsnoc (hd1, tl1);
L.lemma_snoc_unsnoc (hd2, tl2)
[@"opaque_to_smt"]
let unsnoc (#a: Type) (l: list a) : Pure (list a & a)
(requires (Cons? l))
(ensures (fun (hd, tl) -> l == hd `L.append` [tl] /\ L.length hd < L.length l))
=
L.lemma_unsnoc_snoc l;
L.append_length (fst (L.unsnoc l)) [snd (L.unsnoc l)];
L.unsnoc l
let unsnoc_hd (#a: Type) (l: list a) : Pure (list a) (requires (Cons? l)) (ensures (fun l' -> L.length l' <
L.length l)) = fst (unsnoc l)
let unsnoc_tl (#a: Type) (l: list a) : Pure (a) (requires (Cons? l)) (ensures (fun _ -> True)) = snd (unsnoc l)
[@@"opaque_to_smt"]
let snoc (#a: Type) (l: list a) (x: a) : Pure (list a)
(requires True)
(ensures (fun l' ->
Cons? l' /\
unsnoc_hd l' == l /\
unsnoc_tl l' == x
))
=
let l' = L.snoc (l, x) in
L.append_length l [x];
snoc_inj l (unsnoc_hd l') x (unsnoc_tl l');
l'
let snoc_unsnoc
(#a: Type)
(l: list a)
: Lemma
(requires (Cons? l))
(ensures (snoc (unsnoc_hd l) (unsnoc_tl l) == l))
= ()
unfold
let coerce
(#a: Type)
(x: a)
(b: Type)
: Pure b
(requires (a == b))
(ensures (fun y -> a == b /\ x == y))
= x
(* END library *)
let t a = cllist_lvalue a
let v (a: Type0) = list a
let datas
(#a: Type0)
(l: v a)
: Tot (list a)
= l
(* view from the tail *)
let llist_fragment_tail_cons_data_refine
(#a: Type)
(l: Ghost.erased (list a) { Cons? (Ghost.reveal l) })
(d: a)
: Tot prop
= d == unsnoc_tl (Ghost.reveal l)
[@@ __steel_reduce__]
let llist_fragment_tail_cons_lvalue_payload
(#a: Type)
(l: Ghost.erased (list a) { Cons? (Ghost.reveal l) })
(c: ccell_lvalue a)
: Tot vprop
= vptr (ccell_data c) `vrefine` llist_fragment_tail_cons_data_refine l
let ccell_is_lvalue_refine
(a: Type)
(c: ccell_ptrvalue a)
: Tot prop
= ccell_ptrvalue_is_null c == false
[@@ __steel_reduce__ ]
let llist_fragment_tail_cons_next_payload
(#a: Type)
(l: Ghost.erased (list a) { Cons? (Ghost.reveal l) })
(ptail: ref (ccell_ptrvalue a))
: Tot vprop
= vptr ptail `vrefine` ccell_is_lvalue_refine a `vdep` llist_fragment_tail_cons_lvalue_payload l
[@@ __steel_reduce__ ]
let llist_fragment_tail_cons_rewrite
(#a: Type)
(l: Ghost.erased (list a) { Cons? (Ghost.reveal l) })
(llist_fragment_tail: vprop { t_of llist_fragment_tail == ref (ccell_ptrvalue a) })
(x: normal (t_of (llist_fragment_tail `vdep` (llist_fragment_tail_cons_next_payload l))))
: Tot (ref (ccell_ptrvalue a))
= let (| _, (| c, _ |) |) = x in
ccell_next c
let rec llist_fragment_tail (#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) : Pure vprop
(requires True)
(ensures (fun v -> t_of v == ref (ccell_ptrvalue a)))
(decreases (Ghost.reveal (L.length l)))
= if Nil? l
then vconst phead
else llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead `vdep` llist_fragment_tail_cons_next_payload l `vrewrite` llist_fragment_tail_cons_rewrite l (llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead)
let llist_fragment_tail_eq
(#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a))
: Lemma
(llist_fragment_tail l phead == (
if Nil? l
then vconst phead
else llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead `vdep` llist_fragment_tail_cons_next_payload l `vrewrite` llist_fragment_tail_cons_rewrite l (llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead)
))
= assert_norm
(llist_fragment_tail l phead == (
if Nil? l
then vconst phead
else llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead `vdep` llist_fragment_tail_cons_next_payload l `vrewrite` llist_fragment_tail_cons_rewrite l (llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead)
))
let llist_fragment_tail_eq_cons
(#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a))
: Lemma
(requires (Cons? l))
(ensures (Cons? l /\
llist_fragment_tail l phead == (
llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead `vdep` llist_fragment_tail_cons_next_payload l `vrewrite` llist_fragment_tail_cons_rewrite l (llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead)
)))
= llist_fragment_tail_eq l phead
unfold
let sel_llist_fragment_tail
(#a:Type) (#p:vprop)
(l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a))
(h: rmem p { FStar.Tactics.with_tactic selector_tactic (can_be_split p (llist_fragment_tail l phead) /\ True) })
: GTot (ref (ccell_ptrvalue a))
=
coerce (h (llist_fragment_tail l phead)) (ref (ccell_ptrvalue a))
val intro_llist_fragment_tail_nil
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
: SteelGhost unit opened
emp
(fun _ -> llist_fragment_tail l phead)
(fun _ -> Nil? l)
(fun _ _ h' -> sel_llist_fragment_tail l phead h' == phead)
let intro_llist_fragment_tail_nil
l phead
=
intro_vconst phead;
change_equal_slprop
(vconst phead)
(llist_fragment_tail l phead)
val elim_llist_fragment_tail_nil
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
: SteelGhost unit opened
(llist_fragment_tail l phead)
(fun _ -> emp)
(fun _ -> Nil? l)
(fun h _ _ -> sel_llist_fragment_tail l phead h == phead)
let elim_llist_fragment_tail_nil
l phead
=
change_equal_slprop
(llist_fragment_tail l phead)
(vconst phead);
elim_vconst phead
val intro_llist_fragment_tail_snoc
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(ptail: Ghost.erased (ref (ccell_ptrvalue a)))
(tail: Ghost.erased (ccell_lvalue a))
: SteelGhost (Ghost.erased (list a)) opened
(llist_fragment_tail l phead `star` vptr ptail `star` vptr (ccell_data tail))
(fun res -> llist_fragment_tail res phead)
(fun h ->
sel_llist_fragment_tail l phead h == Ghost.reveal ptail /\
sel ptail h == Ghost.reveal tail
)
(fun h res h' ->
Ghost.reveal res == snoc (Ghost.reveal l) (sel (ccell_data tail) h) /\
sel_llist_fragment_tail res phead h' == ccell_next tail
)
#push-options "--z3rlimit 16"
let intro_llist_fragment_tail_snoc
#_ #a l phead ptail tail
=
let d = gget (vptr (ccell_data tail)) in
let l' : (l' : Ghost.erased (list a) { Cons? (Ghost.reveal l') }) = Ghost.hide (snoc (Ghost.reveal l) (Ghost.reveal d)) in
intro_vrefine (vptr (ccell_data tail)) (llist_fragment_tail_cons_data_refine l');
intro_vrefine (vptr ptail) (ccell_is_lvalue_refine a);
intro_vdep
(vptr ptail `vrefine` ccell_is_lvalue_refine a)
(vptr (ccell_data tail) `vrefine` llist_fragment_tail_cons_data_refine l')
(llist_fragment_tail_cons_lvalue_payload l');
change_equal_slprop
(llist_fragment_tail l phead)
(llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead);
intro_vdep
(llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead)
(vptr ptail `vrefine` ccell_is_lvalue_refine a `vdep` llist_fragment_tail_cons_lvalue_payload l')
(llist_fragment_tail_cons_next_payload l');
intro_vrewrite_no_norm
(llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead `vdep` llist_fragment_tail_cons_next_payload l')
(llist_fragment_tail_cons_rewrite l' (llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead));
llist_fragment_tail_eq_cons l' phead;
change_equal_slprop
(llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead `vdep` llist_fragment_tail_cons_next_payload l' `vrewrite` llist_fragment_tail_cons_rewrite l' (llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead))
(llist_fragment_tail l' phead);
let g' = gget (llist_fragment_tail l' phead) in
assert (Ghost.reveal g' == ccell_next tail);
noop ();
l'
#pop-options
[@@erasable]
noeq
type ll_unsnoc_t (a: Type) = {
ll_unsnoc_l: list a;
ll_unsnoc_ptail: ref (ccell_ptrvalue a);
ll_unsnoc_tail: ccell_lvalue a;
}
val elim_llist_fragment_tail_snoc
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
: SteelGhost (ll_unsnoc_t a) opened
(llist_fragment_tail l phead)
(fun res -> llist_fragment_tail res.ll_unsnoc_l phead `star` vptr res.ll_unsnoc_ptail `star` vptr (ccell_data res.ll_unsnoc_tail))
(fun _ -> Cons? l)
(fun h res h' ->
Cons? l /\
Ghost.reveal res.ll_unsnoc_l == unsnoc_hd l /\
sel res.ll_unsnoc_ptail h' == res.ll_unsnoc_tail /\
sel (ccell_data res.ll_unsnoc_tail) h'== unsnoc_tl l /\
sel_llist_fragment_tail res.ll_unsnoc_l phead h' == res.ll_unsnoc_ptail /\
sel_llist_fragment_tail l phead h == (ccell_next res.ll_unsnoc_tail)
)
#push-options "--z3rlimit 32"
#restart-solver
let elim_llist_fragment_tail_snoc
#_ #a l phead
=
let l0 : (l0: Ghost.erased (list a) { Cons? l0 }) = Ghost.hide (Ghost.reveal l) in
llist_fragment_tail_eq_cons l0 phead;
change_equal_slprop
(llist_fragment_tail l phead)
(llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead `vdep` llist_fragment_tail_cons_next_payload l0 `vrewrite` llist_fragment_tail_cons_rewrite l0 (llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead));
elim_vrewrite_no_norm
(llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead `vdep` llist_fragment_tail_cons_next_payload l0)
(llist_fragment_tail_cons_rewrite l0 (llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead));
let ptail = elim_vdep
(llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead)
(llist_fragment_tail_cons_next_payload l0)
in
let ptail0 : Ghost.erased (ref (ccell_ptrvalue a)) = ptail in
change_equal_slprop
(llist_fragment_tail_cons_next_payload l0 (Ghost.reveal ptail))
(vptr (Ghost.reveal ptail0) `vrefine` ccell_is_lvalue_refine a `vdep` llist_fragment_tail_cons_lvalue_payload l0);
let tail = elim_vdep
(vptr (Ghost.reveal ptail0) `vrefine` ccell_is_lvalue_refine a)
(llist_fragment_tail_cons_lvalue_payload l0)
in
elim_vrefine (vptr (Ghost.reveal ptail0)) (ccell_is_lvalue_refine a);
let res = {
ll_unsnoc_l = unsnoc_hd l0;
ll_unsnoc_ptail = Ghost.reveal ptail0;
ll_unsnoc_tail = Ghost.reveal tail;
} in
change_equal_slprop
(vptr (Ghost.reveal ptail0))
(vptr res.ll_unsnoc_ptail);
change_equal_slprop
(llist_fragment_tail_cons_lvalue_payload l0 (Ghost.reveal tail))
(vptr (ccell_data res.ll_unsnoc_tail) `vrefine` llist_fragment_tail_cons_data_refine l0);
elim_vrefine
(vptr (ccell_data res.ll_unsnoc_tail))
(llist_fragment_tail_cons_data_refine l0);
change_equal_slprop
(llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead)
(llist_fragment_tail res.ll_unsnoc_l phead);
res
#pop-options
let rec llist_fragment_tail_append
(#opened: _)
(#a: Type)
(phead0: ref (ccell_ptrvalue a))
(l1: Ghost.erased (list a))
(phead1: Ghost.erased (ref (ccell_ptrvalue a)))
(l2: Ghost.erased (list a))
: SteelGhost (Ghost.erased (list a)) opened
(llist_fragment_tail l1 phead0 `star` llist_fragment_tail l2 phead1)
(fun res -> llist_fragment_tail res phead0)
(fun h ->
Ghost.reveal phead1 == (sel_llist_fragment_tail l1 phead0) h
)
(fun h res h' ->
Ghost.reveal res == Ghost.reveal l1 `L.append` Ghost.reveal l2 /\
(sel_llist_fragment_tail res phead0) h' == (sel_llist_fragment_tail l2 phead1) h
)
(decreases (L.length (Ghost.reveal l2)))
=
let g1 = gget (llist_fragment_tail l1 phead0) in
assert (Ghost.reveal phead1 == Ghost.reveal g1);
if Nil? l2
then begin
L.append_l_nil (Ghost.reveal l1);
elim_llist_fragment_tail_nil l2 phead1;
l1
end else begin
let res = elim_llist_fragment_tail_snoc l2 (Ghost.reveal phead1) in
let d = gget (vptr (ccell_data res.ll_unsnoc_tail)) in
L.append_assoc (Ghost.reveal l1) (Ghost.reveal res.ll_unsnoc_l) [Ghost.reveal d];
let l3 = llist_fragment_tail_append phead0 l1 phead1 res.ll_unsnoc_l in
intro_llist_fragment_tail_snoc l3 phead0 res.ll_unsnoc_ptail res.ll_unsnoc_tail
end
let queue_tail_refine
(#a: Type)
(tail1: ref (ccell_ptrvalue a))
(tail2: ref (ccell_ptrvalue a))
(tl: normal (t_of (vptr tail2)))
: Tot prop
= ccell_ptrvalue_is_null tl == true /\ tail1 == tail2
[@@__steel_reduce__]
let queue_tail_dep2
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
(tail1: t_of (llist_fragment_tail l (cllist_head x)))
(tail2: ref (ccell_ptrvalue a))
: Tot vprop
= vptr tail2 `vrefine` queue_tail_refine tail1 tail2
[@@__steel_reduce__]
let queue_tail_dep1
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
(tail1: t_of (llist_fragment_tail l (cllist_head x)))
: Tot vprop
= vptr (cllist_tail x) `vdep` queue_tail_dep2 x l tail1
[@@__steel_reduce__; __reduce__]
let queue_tail
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
: Tot vprop
=
llist_fragment_tail l (cllist_head x) `vdep` queue_tail_dep1 x l
val intro_queue_tail
(#opened: _)
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
(tail: ref (ccell_ptrvalue a))
: SteelGhost unit opened
(llist_fragment_tail l (cllist_head x) `star` vptr (cllist_tail x) `star` vptr tail)
(fun _ -> queue_tail x l)
(fun h ->
sel_llist_fragment_tail l (cllist_head x) h == tail /\
sel (cllist_tail x) h == tail /\
ccell_ptrvalue_is_null (sel tail h)
)
(fun _ _ _ -> True)
let intro_queue_tail
x l tail
=
intro_vrefine (vptr tail) (queue_tail_refine tail tail);
intro_vdep2
(vptr (cllist_tail x))
(vptr tail `vrefine` queue_tail_refine tail tail)
tail
(queue_tail_dep2 x l tail);
intro_vdep2
(llist_fragment_tail l (cllist_head x))
(vptr (cllist_tail x) `vdep` queue_tail_dep2 x l tail)
tail
(queue_tail_dep1 x l)
val elim_queue_tail
(#opened: _)
(#a: Type)
(x: t a)
(l: Ghost.erased (list a))
: SteelGhost (Ghost.erased (ref (ccell_ptrvalue a))) opened
(queue_tail x l)
(fun tail -> llist_fragment_tail l (cllist_head x) `star` vptr (cllist_tail x) `star` vptr tail)
(fun h -> True)
(fun _ tail h ->
sel_llist_fragment_tail l (cllist_head x) h == Ghost.reveal tail /\
sel (cllist_tail x) h == Ghost.reveal tail /\
ccell_ptrvalue_is_null (h (vptr tail))
)
let elim_queue_tail
#_ #a x l
=
let tail0 = elim_vdep
(llist_fragment_tail l (cllist_head x))
(queue_tail_dep1 x l)
in
let tail : Ghost.erased (ref (ccell_ptrvalue a)) = tail0 in
change_equal_slprop
(queue_tail_dep1 x l (Ghost.reveal tail0))
(vptr (cllist_tail x) `vdep` queue_tail_dep2 x l tail0);
let tail2 = elim_vdep
(vptr (cllist_tail x))
(queue_tail_dep2 x l tail0)
in
let tail3 : Ghost.erased (ref (ccell_ptrvalue a)) = tail2 in
change_equal_slprop
(queue_tail_dep2 x l tail0 (Ghost.reveal tail2))
(vptr tail3 `vrefine` queue_tail_refine tail0 tail3);
elim_vrefine (vptr tail3) (queue_tail_refine tail0 tail3);
change_equal_slprop
(vptr tail3)
(vptr tail);
tail
(* view from the head *)
let llist_fragment_head_data_refine
(#a: Type)
(d: a)
(c: vcell a)
: Tot prop
= c.vcell_data == d
let llist_fragment_head_payload
(#a: Type)
(head: ccell_ptrvalue a)
(d: a)
(llist_fragment_head: (ref (ccell_ptrvalue a) -> ccell_ptrvalue a -> Tot vprop))
(x: t_of (ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine d)))
: Tot vprop
=
llist_fragment_head (ccell_next (fst x)) (snd x).vcell_next
let rec llist_fragment_head (#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a) : Tot vprop
(decreases (Ghost.reveal l))
=
if Nil? l
then vconst (phead, head)
else
vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd (Ghost.reveal l))))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd (Ghost.reveal l)) (llist_fragment_head (L.tl (Ghost.reveal l))))
let t_of_llist_fragment_head
(#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a)
: Lemma
(t_of (llist_fragment_head l phead head) == ref (ccell_ptrvalue a) & ccell_ptrvalue a)
= ()
unfold
let sel_llist_fragment_head
(#a:Type) (#p:vprop)
(l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a)
(h: rmem p { FStar.Tactics.with_tactic selector_tactic (can_be_split p (llist_fragment_head l phead head) /\ True) })
: GTot (ref (ccell_ptrvalue a) & ccell_ptrvalue a)
=
coerce (h (llist_fragment_head l phead head)) (ref (ccell_ptrvalue a) & ccell_ptrvalue a)
val intro_llist_fragment_head_nil
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(head: ccell_ptrvalue a)
: SteelGhost unit opened
emp
(fun _ -> llist_fragment_head l phead head)
(fun _ -> Nil? l)
(fun _ _ h' -> sel_llist_fragment_head l phead head h' == (phead, head))
let intro_llist_fragment_head_nil
l phead head
=
intro_vconst (phead, head);
change_equal_slprop
(vconst (phead, head))
(llist_fragment_head l phead head)
val elim_llist_fragment_head_nil
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(head: ccell_ptrvalue a)
: SteelGhost unit opened
(llist_fragment_head l phead head)
(fun _ -> emp)
(fun _ -> Nil? l)
(fun h _ _ -> sel_llist_fragment_head l phead head h == (phead, head))
let elim_llist_fragment_head_nil
l phead head
=
change_equal_slprop
(llist_fragment_head l phead head)
(vconst (phead, head));
elim_vconst (phead, head)
let llist_fragment_head_eq_cons
(#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a)
: Lemma
(requires (Cons? (Ghost.reveal l)))
(ensures (
llist_fragment_head l phead head ==
vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd (Ghost.reveal l))))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd (Ghost.reveal l)) (llist_fragment_head (L.tl (Ghost.reveal l))))
))
= assert_norm
(llist_fragment_head l phead head == (
if Nil? l
then vconst (phead, head)
else
vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd (Ghost.reveal l))))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd (Ghost.reveal l)) (llist_fragment_head (L.tl (Ghost.reveal l))))
))
val intro_llist_fragment_head_cons
(#opened: _)
(#a: Type) (phead: ref (ccell_ptrvalue a)) (head: ccell_lvalue a) (next: (ccell_ptrvalue a)) (tl: Ghost.erased (list a))
: SteelGhost (Ghost.erased (list a)) opened
(ccell head `star` llist_fragment_head tl (ccell_next head) next)
(fun res -> llist_fragment_head res phead head)
(fun h -> (h (ccell head)).vcell_next == next)
(fun h res h' ->
Ghost.reveal res == (h (ccell head)).vcell_data :: Ghost.reveal tl /\
h' (llist_fragment_head res phead head) == h (llist_fragment_head tl (ccell_next head) next)
)
let intro_llist_fragment_head_cons
#_ #a phead head next tl
=
let vc = gget (ccell head) in
let l' : (l' : Ghost.erased (list a) { Cons? l' }) = Ghost.hide (vc.vcell_data :: tl) in
intro_ccell_is_lvalue head;
intro_vrefine (ccell head) (llist_fragment_head_data_refine (L.hd l'));
intro_vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd l')))
(llist_fragment_head tl (ccell_next head) next)
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd l') (llist_fragment_head (L.tl l')));
llist_fragment_head_eq_cons l' phead head;
change_equal_slprop
(vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd l')))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd l') (llist_fragment_head (L.tl l'))))
(llist_fragment_head l' phead head);
l'
[@@erasable]
noeq
type ll_uncons_t
(a: Type)
= {
ll_uncons_pnext: Ghost.erased (ref (ccell_ptrvalue a));
ll_uncons_next: Ghost.erased (ccell_ptrvalue a);
ll_uncons_tl: Ghost.erased (list a);
}
val elim_llist_fragment_head_cons
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(head: ccell_ptrvalue a)
: SteelGhost (ll_uncons_t a) opened
(llist_fragment_head l phead head)
(fun res -> ccell head `star` llist_fragment_head res.ll_uncons_tl res.ll_uncons_pnext res.ll_uncons_next)
(fun _ -> Cons? (Ghost.reveal l))
(fun h res h' ->
ccell_ptrvalue_is_null head == false /\
Ghost.reveal l == (h' (ccell head)).vcell_data :: Ghost.reveal res.ll_uncons_tl /\
Ghost.reveal res.ll_uncons_pnext == ccell_next head /\
Ghost.reveal res.ll_uncons_next == (h' (ccell head)).vcell_next /\
h' (llist_fragment_head res.ll_uncons_tl res.ll_uncons_pnext res.ll_uncons_next) == h (llist_fragment_head l phead head)
)
let elim_llist_fragment_head_cons
#_ #a l0 phead head
=
let l : (l : Ghost.erased (list a) { Cons? l }) = l0 in
change_equal_slprop
(llist_fragment_head l0 phead head)
(llist_fragment_head l phead head);
llist_fragment_head_eq_cons l phead head;
change_equal_slprop
(llist_fragment_head l phead head)
(vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd l)))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd l) (llist_fragment_head (L.tl l))));
let x = elim_vbind
(ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd l)))
(ref (ccell_ptrvalue a) & ccell_ptrvalue a)
(llist_fragment_head_payload head (L.hd l) (llist_fragment_head (L.tl l)))
in
let head2 = gget (ccell_is_lvalue head) in
elim_ccell_is_lvalue head;
elim_vrefine (ccell head) (llist_fragment_head_data_refine (L.hd l));
let vhead2 = gget (ccell head) in
let res = {
ll_uncons_pnext = ccell_next head2;
ll_uncons_next = vhead2.vcell_next;
ll_uncons_tl = L.tl l;
} in
change_equal_slprop
(llist_fragment_head_payload head (L.hd l) (llist_fragment_head (L.tl l)) (Ghost.reveal x))
(llist_fragment_head res.ll_uncons_tl res.ll_uncons_pnext res.ll_uncons_next);
res
let rec llist_fragment_head_append
(#opened: _)
(#a: Type)
(l1: Ghost.erased (list a))
(phead1: ref (ccell_ptrvalue a))
(head1: ccell_ptrvalue a)
(l2: Ghost.erased (list a))
(phead2: ref (ccell_ptrvalue a))
(head2: ccell_ptrvalue a)
: SteelGhost (Ghost.erased (list a)) opened
(llist_fragment_head l1 phead1 head1 `star` llist_fragment_head l2 phead2 head2)
(fun l -> llist_fragment_head l phead1 head1)
(fun h -> sel_llist_fragment_head l1 phead1 head1 h == (Ghost.reveal phead2, Ghost.reveal head2))
(fun h l h' ->
Ghost.reveal l == Ghost.reveal l1 `L.append` Ghost.reveal l2 /\
h' (llist_fragment_head l phead1 head1) == h (llist_fragment_head l2 phead2 head2)
)
(decreases (Ghost.reveal l1))
=
if Nil? l1
then begin
elim_llist_fragment_head_nil l1 phead1 head1;
change_equal_slprop
(llist_fragment_head l2 phead2 head2)
(llist_fragment_head l2 phead1 head1);
l2
end else begin
let u = elim_llist_fragment_head_cons l1 phead1 head1 in
let head1' : Ghost.erased (ccell_lvalue a) = head1 in
let l3 = llist_fragment_head_append u.ll_uncons_tl u.ll_uncons_pnext u.ll_uncons_next l2 phead2 head2 in
change_equal_slprop
(llist_fragment_head l3 u.ll_uncons_pnext u.ll_uncons_next)
(llist_fragment_head l3 (ccell_next head1') u.ll_uncons_next);
change_equal_slprop
(ccell head1)
(ccell head1');
let l4 = intro_llist_fragment_head_cons phead1 head1' u.ll_uncons_next l3 in
change_equal_slprop
(llist_fragment_head l4 phead1 head1')
(llist_fragment_head l4 phead1 head1);
l4
end
let rec llist_fragment_head_to_tail
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead: ref (ccell_ptrvalue a))
(head: ccell_ptrvalue a)
: SteelGhost (Ghost.erased (ref (ccell_ptrvalue a))) opened
(vptr phead `star` llist_fragment_head l phead head)
(fun res -> llist_fragment_tail l phead `star` vptr res)
(fun h -> h (vptr phead) == head)
(fun h res h' ->
let v = sel_llist_fragment_head l phead head h in
fst v == Ghost.reveal res /\
fst v == sel_llist_fragment_tail l phead h' /\
snd v == h' (vptr res)
)
(decreases (L.length (Ghost.reveal l)))
=
if Nil? l
then begin
let ptail = Ghost.hide phead in
let gh = gget (vptr phead) in
assert (Ghost.reveal gh == head);
elim_llist_fragment_head_nil l phead head;
intro_llist_fragment_tail_nil l phead;
change_equal_slprop
(vptr phead)
(vptr ptail);
ptail
end else begin
intro_llist_fragment_tail_nil [] phead;
change_equal_slprop
(vptr phead)
(vptr (Ghost.reveal (Ghost.hide phead)));
let uc = elim_llist_fragment_head_cons l phead head in
let head' = elim_ccell_ghost head in
change_equal_slprop
(vptr (ccell_next head'))
(vptr uc.ll_uncons_pnext);
let lc = intro_llist_fragment_tail_snoc [] phead phead head' in
let ptail = llist_fragment_head_to_tail
uc.ll_uncons_tl
uc.ll_uncons_pnext
uc.ll_uncons_next
in
let l' = llist_fragment_tail_append phead lc uc.ll_uncons_pnext uc.ll_uncons_tl in
change_equal_slprop
(llist_fragment_tail l' phead)
(llist_fragment_tail l phead);
ptail
end
#push-options "--z3rlimit 16"
#restart-solver | {
"checked_file": "/",
"dependencies": [
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"CQueue.LList.fsti.checked"
],
"interface_file": true,
"source_file": "CQueue.fst"
} | [
{
"abbrev": false,
"full_module": "CQueue.LList",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.Reference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
l: FStar.Ghost.erased (Prims.list a) ->
phead: Steel.Reference.ref (CQueue.Cell.ccell_ptrvalue a) ->
ptail: Steel.Reference.ref (CQueue.Cell.ccell_ptrvalue a)
-> Steel.Effect.Atomic.SteelGhost (FStar.Ghost.erased (CQueue.Cell.ccell_ptrvalue a)) | Steel.Effect.Atomic.SteelGhost | [
""
] | [] | [
"Steel.Memory.inames",
"FStar.Ghost.erased",
"Prims.list",
"Steel.Reference.ref",
"CQueue.Cell.ccell_ptrvalue",
"Prims.uu___is_Nil",
"FStar.Ghost.reveal",
"Prims.unit",
"CQueue.intro_llist_fragment_head_nil",
"Steel.Effect.Common.t_of",
"Steel.Reference.vptr",
"Steel.Effect.Common.VUnit",
"Steel.Reference.vptr'",
"Steel.FractionalPermission.full_perm",
"Steel.Effect.Atomic.gget",
"Steel.Effect.Atomic.change_equal_slprop",
"CQueue.elim_llist_fragment_tail_nil",
"Prims._assert",
"CQueue.op_Equals_Equals",
"CQueue.llist_fragment_tail",
"Prims.bool",
"CQueue.llist_fragment_head",
"CQueue.llist_fragment_head_append",
"FStar.Ghost.hide",
"CQueue.__proj__Mkll_unsnoc_t__item__ll_unsnoc_l",
"CQueue.__proj__Mkll_unsnoc_t__item__ll_unsnoc_ptail",
"CQueue.__proj__Mkll_unsnoc_t__item__ll_unsnoc_tail",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"CQueue.Cell.ccell_lvalue",
"CQueue.llist_fragment_tail_to_head",
"CQueue.intro_llist_fragment_head_cons",
"Prims.Nil",
"CQueue.Cell.intro_ccell",
"CQueue.Cell.ccell_next",
"CQueue.ll_unsnoc_t",
"CQueue.elim_llist_fragment_tail_snoc",
"Steel.Effect.Common.star",
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.rmem",
"CQueue.sel_llist_fragment_tail",
"Prims.l_and",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.snd",
"CQueue.sel_llist_fragment_head"
] | [
"recursion"
] | false | true | false | false | false | let rec llist_fragment_tail_to_head
(#opened: _)
(#a: Type)
(l: Ghost.erased (list a))
(phead ptail: ref (ccell_ptrvalue a))
: SteelGhost (Ghost.erased (ccell_ptrvalue a))
opened
((llist_fragment_tail l phead) `star` (vptr ptail))
(fun head -> (vptr phead) `star` (llist_fragment_head l phead (Ghost.reveal head)))
(fun h -> Ghost.reveal ptail == sel_llist_fragment_tail l phead h)
(fun h head h' ->
let v = sel_llist_fragment_head l phead head h' in
fst v == ptail /\ snd v == h (vptr ptail) /\ h' (vptr phead) == Ghost.reveal head)
(decreases (L.length (Ghost.reveal l))) =
| if Nil? l
then
let g = gget (llist_fragment_tail l phead) in
assert (Ghost.reveal g == ptail);
elim_llist_fragment_tail_nil l phead;
change_equal_slprop (vptr ptail) (vptr phead);
let head = gget (vptr phead) in
intro_llist_fragment_head_nil l phead head;
head
else
let us = elim_llist_fragment_tail_snoc l phead in
let tail = gget (vptr ptail) in
assert (ccell_next us.ll_unsnoc_tail == ptail);
intro_llist_fragment_head_nil [] (ccell_next us.ll_unsnoc_tail) tail;
change_equal_slprop (vptr ptail) (vptr (ccell_next us.ll_unsnoc_tail));
intro_ccell us.ll_unsnoc_tail;
let lc = intro_llist_fragment_head_cons us.ll_unsnoc_ptail us.ll_unsnoc_tail tail [] in
let head = llist_fragment_tail_to_head us.ll_unsnoc_l phead us.ll_unsnoc_ptail in
let g = gget (llist_fragment_head us.ll_unsnoc_l phead head) in
let g:Ghost.erased (ref (ccell_ptrvalue a) & ccell_ptrvalue a) = Ghost.hide (Ghost.reveal g) in
assert (Ghost.reveal g == (Ghost.reveal us.ll_unsnoc_ptail, Ghost.reveal us.ll_unsnoc_tail));
let l' =
llist_fragment_head_append us.ll_unsnoc_l phead head lc us.ll_unsnoc_ptail us.ll_unsnoc_tail
in
change_equal_slprop (llist_fragment_head l' phead head) (llist_fragment_head l phead head);
head | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.encrypt_expand | val encrypt_expand: #a:supported_alg -> encrypt_expand_st true (G.reveal a) | val encrypt_expand: #a:supported_alg -> encrypt_expand_st true (G.reveal a) | let encrypt_expand #a k iv iv_len ad ad_len plain plain_len cipher tag =
match a with
| AES128_GCM ->
encrypt_expand_aes128_gcm k iv iv_len ad ad_len plain plain_len cipher tag
| AES256_GCM ->
encrypt_expand_aes256_gcm k iv iv_len ad ad_len plain plain_len cipher tag
| CHACHA20_POLY1305 ->
encrypt_expand_chacha20_poly1305 k iv iv_len ad ad_len plain plain_len cipher tag | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 85,
"end_line": 432,
"start_col": 0,
"start_line": 425
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success
#pop-options
inline_for_extraction noextract
let create_in_aes_gcm (i: vale_impl):
create_in_st (alg_of_vale_impl i) =
fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale then (
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then (
let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success
) else
UnsupportedAlgorithm
) else
UnsupportedAlgorithm
let create_in_aes128_gcm: create_in_st AES128_GCM = create_in_aes_gcm Vale_AES128
let create_in_aes256_gcm: create_in_st AES256_GCM = create_in_aes_gcm Vale_AES256
let create_in #a r dst k =
match a with
| AES128_GCM -> create_in_aes128_gcm r dst k
| AES256_GCM -> create_in_aes256_gcm r dst k
| CHACHA20_POLY1305 -> create_in_chacha20_poly1305 r dst k
| _ -> UnsupportedAlgorithm
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
inline_for_extraction noextract
let alloca_chacha20_poly1305: alloca_st CHACHA20_POLY1305 =
fun k ->
let h0 = ST.get () in
let ek = B.alloca 0uy 32ul in
let p = B.alloca (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.loc_none h0 h3;
p
#pop-options
inline_for_extraction noextract
let alloca_aes_gcm (i: vale_impl):
alloca_st (alg_of_vale_impl i) =
fun k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
let ek = B.alloca 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.alloca (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
p
inline_for_extraction noextract
let alloca_aes128_gcm: alloca_st AES128_GCM =
alloca_aes_gcm Vale_AES128
inline_for_extraction noextract
let alloca_aes256_gcm: alloca_st AES256_GCM =
alloca_aes_gcm Vale_AES256
let alloca #a k =
match a with
| AES128_GCM -> alloca_aes128_gcm k
| AES256_GCM -> alloca_aes256_gcm k
| CHACHA20_POLY1305 -> alloca_chacha20_poly1305 k
inline_for_extraction noextract
let aes_gcm_encrypt (i: vale_impl):
Vale.Wrapper.X64.GCMencryptOpt.encrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMencryptOpt.gcm128_encrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMencryptOpt256.gcm256_encrypt_opt_stdcall
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties.slice_slice'"
inline_for_extraction noextract
let encrypt_aes_gcm (i: vale_impl): encrypt_st (alg_of_vale_impl i) =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if B.is_null s then
InvalidKey
else
let a = alg_of_vale_impl i in
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len = 0ul then
InvalidIVLength
else
let open LowStar.BufferOps in
let Ek _ kv ek = !*s in
assert (
let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.AES_s.is_aes_key_LE (vale_alg_of_alg a) k_w);
push_frame();
let scratch_b = B.sub ek (concrete_xkey_len i) 176ul in
let ek = B.sub ek 0ul (concrete_xkey_len i) in
let keys_b = B.sub ek 0ul (key_offset i) in
let hkeys_b = B.sub ek (key_offset i) 128ul in
let h0 = get() in
// The iv can be arbitrary length, hence we need to allocate a new one to perform the hashing
let tmp_iv = B.alloca 0uy 16ul in
// There is no SMTPat on le_bytes_to_seq_quad32_to_bytes and the converse,
// so we need an explicit lemma
let lemma_hkeys_reqs () : Lemma
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.OptPublic.hkeys_reqs_pub
(Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 hkeys_b)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))))
= let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
let hkeys_quad = Vale.AES.OptPublic.get_hkeys_reqs (Vale.Def.Types_s.reverse_bytes_quad32 (
Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))) in
let hkeys = Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 (Vale.Def.Types_s.le_seq_quad32_to_bytes hkeys_quad) in
assert (Seq.equal (B.as_seq h0 hkeys_b) hkeys);
calc (==) {
Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 hkeys);
(==) { Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes hkeys_quad }
hkeys_quad;
}
in lemma_hkeys_reqs ();
// We perform the hashing of the iv. The extra buffer and the hashed iv are the same
Vale.Wrapper.X64.GCM_IV.compute_iv (vale_alg_of_alg a)
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w )
iv iv_len
tmp_iv tmp_iv
hkeys_b;
let h0 = get() in
aes_gcm_encrypt i
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w)
(Ghost.hide (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv)))
plain
(uint32_to_uint64 plain_len)
ad
(uint32_to_uint64 ad_len)
tmp_iv
cipher
tag
keys_b
hkeys_b
scratch_b;
let h1 = get() in
// This assert is needed for z3 to pick up sequence equality for ciphertext
// and tag. It could be avoided if the spec returned both instead of appending them
assert (
let kv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (G.reveal kv) in
let iv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv) in
// `ad` is called `auth` in Vale world; "additional data", "authenticated
// data", potato, potato
let ad_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 ad) in
let plain_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 plain) in
let cipher_nat, tag_nat =
Vale.AES.GCM_s.gcm_encrypt_LE (vale_alg_of_alg a) kv_nat iv_nat plain_nat ad_nat
in
Seq.equal (B.as_seq h1 cipher) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 cipher_nat) /\
Seq.equal (B.as_seq h1 tag) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 tag_nat));
pop_frame();
Success
let encrypt_aes128_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES128_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES128 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt_aes256_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES256_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES256 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt #a s iv iv_len ad ad_len plain plain_len cipher tag =
if B.is_null s then
InvalidKey
else
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
match i with
| Vale_AES128 ->
encrypt_aes128_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Vale_AES256 ->
encrypt_aes256_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Hacl_CHACHA20 ->
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len <> 12ul then
InvalidIVLength
else begin
// Length restrictions
assert_norm (pow2 31 + pow2 32 / 64 <= pow2 32 - 1);
EverCrypt.Chacha20Poly1305.aead_encrypt
ek iv ad_len ad plain_len plain cipher tag;
Success
end
inline_for_extraction noextract
let encrypt_expand_aes_gcm (i: vale_impl): encrypt_expand_st false (alg_of_vale_impl i) =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s (alg_of_vale_impl i)) = alloca k in
let r = encrypt_aes_gcm i s iv iv_len ad ad_len plain plain_len cipher tag in
assert(r == Success);
pop_frame ();
Success
let encrypt_expand_aes128_gcm_no_check : encrypt_expand_st false AES128_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale"
let encrypt_expand_aes256_gcm_no_check : encrypt_expand_st false AES256_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len plain plain_len cipher tag
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale"
let encrypt_expand_aes128_gcm : encrypt_expand_st true AES128_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then
encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else
UnsupportedAlgorithm
else
UnsupportedAlgorithm
let encrypt_expand_aes256_gcm : encrypt_expand_st true AES256_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then
encrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len plain plain_len cipher tag
else
UnsupportedAlgorithm
else
UnsupportedAlgorithm
let encrypt_expand_chacha20_poly1305 : encrypt_expand_st false CHACHA20_POLY1305 =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s CHACHA20_POLY1305) = alloca k in
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
EverCrypt.Chacha20Poly1305.aead_encrypt ek iv ad_len ad plain_len plain cipher tag;
pop_frame ();
Success | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.AEAD.encrypt_expand_st true (FStar.Ghost.reveal (FStar.Ghost.hide a)) | Prims.Tot | [
"total"
] | [] | [
"Spec.Agile.AEAD.supported_alg",
"LowStar.Buffer.buffer",
"EverCrypt.CTR.Keys.uint8",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.Integers.op_Greater_Equals",
"FStar.Integers.Signed",
"FStar.Integers.Winfinite",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"Spec.Agile.AEAD.key_length",
"FStar.Ghost.reveal",
"FStar.Ghost.hide",
"EverCrypt.AEAD.iv_p",
"FStar.UInt32.t",
"Prims.l_and",
"FStar.Integers.within_bounds",
"FStar.Integers.Unsigned",
"FStar.Integers.W32",
"FStar.Integers.v",
"FStar.Integers.op_Greater",
"EverCrypt.AEAD.ad_p",
"FStar.Integers.op_Less_Equals",
"Prims.pow2",
"EverCrypt.AEAD.plain_p",
"Spec.Agile.AEAD.max_length",
"Prims.nat",
"Spec.Agile.AEAD.tag_length",
"EverCrypt.AEAD.encrypt_expand_aes128_gcm",
"EverCrypt.Error.error_code",
"EverCrypt.AEAD.encrypt_expand_aes256_gcm",
"EverCrypt.AEAD.encrypt_expand_chacha20_poly1305"
] | [] | false | false | false | false | false | let encrypt_expand #a k iv iv_len ad ad_len plain plain_len cipher tag =
| match a with
| AES128_GCM -> encrypt_expand_aes128_gcm k iv iv_len ad ad_len plain plain_len cipher tag
| AES256_GCM -> encrypt_expand_aes256_gcm k iv iv_len ad ad_len plain plain_len cipher tag
| CHACHA20_POLY1305 ->
encrypt_expand_chacha20_poly1305 k iv iv_len ad ad_len plain plain_len cipher tag | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.encrypt_expand_aes128_gcm_no_check | val encrypt_expand_aes128_gcm_no_check: encrypt_expand_st false AES128_GCM | val encrypt_expand_aes128_gcm_no_check: encrypt_expand_st false AES128_GCM | let encrypt_expand_aes128_gcm_no_check : encrypt_expand_st false AES128_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale" | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 92,
"end_line": 375,
"start_col": 0,
"start_line": 370
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success
#pop-options
inline_for_extraction noextract
let create_in_aes_gcm (i: vale_impl):
create_in_st (alg_of_vale_impl i) =
fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale then (
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then (
let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success
) else
UnsupportedAlgorithm
) else
UnsupportedAlgorithm
let create_in_aes128_gcm: create_in_st AES128_GCM = create_in_aes_gcm Vale_AES128
let create_in_aes256_gcm: create_in_st AES256_GCM = create_in_aes_gcm Vale_AES256
let create_in #a r dst k =
match a with
| AES128_GCM -> create_in_aes128_gcm r dst k
| AES256_GCM -> create_in_aes256_gcm r dst k
| CHACHA20_POLY1305 -> create_in_chacha20_poly1305 r dst k
| _ -> UnsupportedAlgorithm
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
inline_for_extraction noextract
let alloca_chacha20_poly1305: alloca_st CHACHA20_POLY1305 =
fun k ->
let h0 = ST.get () in
let ek = B.alloca 0uy 32ul in
let p = B.alloca (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.loc_none h0 h3;
p
#pop-options
inline_for_extraction noextract
let alloca_aes_gcm (i: vale_impl):
alloca_st (alg_of_vale_impl i) =
fun k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
let ek = B.alloca 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.alloca (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
p
inline_for_extraction noextract
let alloca_aes128_gcm: alloca_st AES128_GCM =
alloca_aes_gcm Vale_AES128
inline_for_extraction noextract
let alloca_aes256_gcm: alloca_st AES256_GCM =
alloca_aes_gcm Vale_AES256
let alloca #a k =
match a with
| AES128_GCM -> alloca_aes128_gcm k
| AES256_GCM -> alloca_aes256_gcm k
| CHACHA20_POLY1305 -> alloca_chacha20_poly1305 k
inline_for_extraction noextract
let aes_gcm_encrypt (i: vale_impl):
Vale.Wrapper.X64.GCMencryptOpt.encrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMencryptOpt.gcm128_encrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMencryptOpt256.gcm256_encrypt_opt_stdcall
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties.slice_slice'"
inline_for_extraction noextract
let encrypt_aes_gcm (i: vale_impl): encrypt_st (alg_of_vale_impl i) =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if B.is_null s then
InvalidKey
else
let a = alg_of_vale_impl i in
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len = 0ul then
InvalidIVLength
else
let open LowStar.BufferOps in
let Ek _ kv ek = !*s in
assert (
let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.AES_s.is_aes_key_LE (vale_alg_of_alg a) k_w);
push_frame();
let scratch_b = B.sub ek (concrete_xkey_len i) 176ul in
let ek = B.sub ek 0ul (concrete_xkey_len i) in
let keys_b = B.sub ek 0ul (key_offset i) in
let hkeys_b = B.sub ek (key_offset i) 128ul in
let h0 = get() in
// The iv can be arbitrary length, hence we need to allocate a new one to perform the hashing
let tmp_iv = B.alloca 0uy 16ul in
// There is no SMTPat on le_bytes_to_seq_quad32_to_bytes and the converse,
// so we need an explicit lemma
let lemma_hkeys_reqs () : Lemma
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.OptPublic.hkeys_reqs_pub
(Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 hkeys_b)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))))
= let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
let hkeys_quad = Vale.AES.OptPublic.get_hkeys_reqs (Vale.Def.Types_s.reverse_bytes_quad32 (
Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))) in
let hkeys = Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 (Vale.Def.Types_s.le_seq_quad32_to_bytes hkeys_quad) in
assert (Seq.equal (B.as_seq h0 hkeys_b) hkeys);
calc (==) {
Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 hkeys);
(==) { Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes hkeys_quad }
hkeys_quad;
}
in lemma_hkeys_reqs ();
// We perform the hashing of the iv. The extra buffer and the hashed iv are the same
Vale.Wrapper.X64.GCM_IV.compute_iv (vale_alg_of_alg a)
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w )
iv iv_len
tmp_iv tmp_iv
hkeys_b;
let h0 = get() in
aes_gcm_encrypt i
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w)
(Ghost.hide (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv)))
plain
(uint32_to_uint64 plain_len)
ad
(uint32_to_uint64 ad_len)
tmp_iv
cipher
tag
keys_b
hkeys_b
scratch_b;
let h1 = get() in
// This assert is needed for z3 to pick up sequence equality for ciphertext
// and tag. It could be avoided if the spec returned both instead of appending them
assert (
let kv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (G.reveal kv) in
let iv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv) in
// `ad` is called `auth` in Vale world; "additional data", "authenticated
// data", potato, potato
let ad_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 ad) in
let plain_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 plain) in
let cipher_nat, tag_nat =
Vale.AES.GCM_s.gcm_encrypt_LE (vale_alg_of_alg a) kv_nat iv_nat plain_nat ad_nat
in
Seq.equal (B.as_seq h1 cipher) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 cipher_nat) /\
Seq.equal (B.as_seq h1 tag) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 tag_nat));
pop_frame();
Success
let encrypt_aes128_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES128_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES128 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt_aes256_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES256_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES256 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt #a s iv iv_len ad ad_len plain plain_len cipher tag =
if B.is_null s then
InvalidKey
else
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
match i with
| Vale_AES128 ->
encrypt_aes128_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Vale_AES256 ->
encrypt_aes256_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Hacl_CHACHA20 ->
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len <> 12ul then
InvalidIVLength
else begin
// Length restrictions
assert_norm (pow2 31 + pow2 32 / 64 <= pow2 32 - 1);
EverCrypt.Chacha20Poly1305.aead_encrypt
ek iv ad_len ad plain_len plain cipher tag;
Success
end
inline_for_extraction noextract
let encrypt_expand_aes_gcm (i: vale_impl): encrypt_expand_st false (alg_of_vale_impl i) =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s (alg_of_vale_impl i)) = alloca k in
let r = encrypt_aes_gcm i s iv iv_len ad ad_len plain plain_len cipher tag in
assert(r == Success);
pop_frame ();
Success | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.AEAD.encrypt_expand_st false Spec.Agile.AEAD.AES128_GCM | Prims.Tot | [
"total"
] | [] | [
"LowStar.Buffer.buffer",
"EverCrypt.CTR.Keys.uint8",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.Integers.op_Greater_Equals",
"FStar.Integers.Signed",
"FStar.Integers.Winfinite",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"Spec.Agile.AEAD.key_length",
"Spec.Agile.AEAD.AES128_GCM",
"EverCrypt.AEAD.iv_p",
"FStar.UInt32.t",
"Prims.l_and",
"FStar.Integers.within_bounds",
"FStar.Integers.Unsigned",
"FStar.Integers.W32",
"FStar.Integers.v",
"FStar.Integers.op_Greater",
"EverCrypt.AEAD.ad_p",
"FStar.Integers.op_Less_Equals",
"Prims.pow2",
"EverCrypt.AEAD.plain_p",
"Spec.Agile.AEAD.max_length",
"Prims.nat",
"Spec.Agile.AEAD.tag_length",
"EverCrypt.TargetConfig.hacl_can_compile_vale",
"EverCrypt.AEAD.encrypt_expand_aes_gcm",
"Spec.Cipher.Expansion.Vale_AES128",
"EverCrypt.Error.error_code",
"Prims.bool",
"LowStar.Failure.failwith",
"EverCrypt.AEAD.encrypt_expand_st"
] | [] | false | false | false | false | false | let encrypt_expand_aes128_gcm_no_check:encrypt_expand_st false AES128_GCM =
| fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale
then encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale" | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.decrypt_expand_aes128_gcm_no_check | val decrypt_expand_aes128_gcm_no_check: decrypt_expand_st false AES128_GCM | val decrypt_expand_aes128_gcm_no_check: decrypt_expand_st false AES128_GCM | let decrypt_expand_aes128_gcm_no_check : decrypt_expand_st false AES128_GCM =
fun k iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
decrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len cipher cipher_len tag dst
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale" | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 92,
"end_line": 635,
"start_col": 0,
"start_line": 630
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success
#pop-options
inline_for_extraction noextract
let create_in_aes_gcm (i: vale_impl):
create_in_st (alg_of_vale_impl i) =
fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale then (
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then (
let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success
) else
UnsupportedAlgorithm
) else
UnsupportedAlgorithm
let create_in_aes128_gcm: create_in_st AES128_GCM = create_in_aes_gcm Vale_AES128
let create_in_aes256_gcm: create_in_st AES256_GCM = create_in_aes_gcm Vale_AES256
let create_in #a r dst k =
match a with
| AES128_GCM -> create_in_aes128_gcm r dst k
| AES256_GCM -> create_in_aes256_gcm r dst k
| CHACHA20_POLY1305 -> create_in_chacha20_poly1305 r dst k
| _ -> UnsupportedAlgorithm
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
inline_for_extraction noextract
let alloca_chacha20_poly1305: alloca_st CHACHA20_POLY1305 =
fun k ->
let h0 = ST.get () in
let ek = B.alloca 0uy 32ul in
let p = B.alloca (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.loc_none h0 h3;
p
#pop-options
inline_for_extraction noextract
let alloca_aes_gcm (i: vale_impl):
alloca_st (alg_of_vale_impl i) =
fun k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
let ek = B.alloca 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.alloca (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
p
inline_for_extraction noextract
let alloca_aes128_gcm: alloca_st AES128_GCM =
alloca_aes_gcm Vale_AES128
inline_for_extraction noextract
let alloca_aes256_gcm: alloca_st AES256_GCM =
alloca_aes_gcm Vale_AES256
let alloca #a k =
match a with
| AES128_GCM -> alloca_aes128_gcm k
| AES256_GCM -> alloca_aes256_gcm k
| CHACHA20_POLY1305 -> alloca_chacha20_poly1305 k
inline_for_extraction noextract
let aes_gcm_encrypt (i: vale_impl):
Vale.Wrapper.X64.GCMencryptOpt.encrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMencryptOpt.gcm128_encrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMencryptOpt256.gcm256_encrypt_opt_stdcall
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties.slice_slice'"
inline_for_extraction noextract
let encrypt_aes_gcm (i: vale_impl): encrypt_st (alg_of_vale_impl i) =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if B.is_null s then
InvalidKey
else
let a = alg_of_vale_impl i in
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len = 0ul then
InvalidIVLength
else
let open LowStar.BufferOps in
let Ek _ kv ek = !*s in
assert (
let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.AES_s.is_aes_key_LE (vale_alg_of_alg a) k_w);
push_frame();
let scratch_b = B.sub ek (concrete_xkey_len i) 176ul in
let ek = B.sub ek 0ul (concrete_xkey_len i) in
let keys_b = B.sub ek 0ul (key_offset i) in
let hkeys_b = B.sub ek (key_offset i) 128ul in
let h0 = get() in
// The iv can be arbitrary length, hence we need to allocate a new one to perform the hashing
let tmp_iv = B.alloca 0uy 16ul in
// There is no SMTPat on le_bytes_to_seq_quad32_to_bytes and the converse,
// so we need an explicit lemma
let lemma_hkeys_reqs () : Lemma
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.OptPublic.hkeys_reqs_pub
(Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 hkeys_b)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))))
= let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
let hkeys_quad = Vale.AES.OptPublic.get_hkeys_reqs (Vale.Def.Types_s.reverse_bytes_quad32 (
Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))) in
let hkeys = Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 (Vale.Def.Types_s.le_seq_quad32_to_bytes hkeys_quad) in
assert (Seq.equal (B.as_seq h0 hkeys_b) hkeys);
calc (==) {
Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 hkeys);
(==) { Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes hkeys_quad }
hkeys_quad;
}
in lemma_hkeys_reqs ();
// We perform the hashing of the iv. The extra buffer and the hashed iv are the same
Vale.Wrapper.X64.GCM_IV.compute_iv (vale_alg_of_alg a)
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w )
iv iv_len
tmp_iv tmp_iv
hkeys_b;
let h0 = get() in
aes_gcm_encrypt i
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w)
(Ghost.hide (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv)))
plain
(uint32_to_uint64 plain_len)
ad
(uint32_to_uint64 ad_len)
tmp_iv
cipher
tag
keys_b
hkeys_b
scratch_b;
let h1 = get() in
// This assert is needed for z3 to pick up sequence equality for ciphertext
// and tag. It could be avoided if the spec returned both instead of appending them
assert (
let kv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (G.reveal kv) in
let iv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv) in
// `ad` is called `auth` in Vale world; "additional data", "authenticated
// data", potato, potato
let ad_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 ad) in
let plain_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 plain) in
let cipher_nat, tag_nat =
Vale.AES.GCM_s.gcm_encrypt_LE (vale_alg_of_alg a) kv_nat iv_nat plain_nat ad_nat
in
Seq.equal (B.as_seq h1 cipher) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 cipher_nat) /\
Seq.equal (B.as_seq h1 tag) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 tag_nat));
pop_frame();
Success
let encrypt_aes128_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES128_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES128 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt_aes256_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES256_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES256 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt #a s iv iv_len ad ad_len plain plain_len cipher tag =
if B.is_null s then
InvalidKey
else
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
match i with
| Vale_AES128 ->
encrypt_aes128_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Vale_AES256 ->
encrypt_aes256_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Hacl_CHACHA20 ->
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len <> 12ul then
InvalidIVLength
else begin
// Length restrictions
assert_norm (pow2 31 + pow2 32 / 64 <= pow2 32 - 1);
EverCrypt.Chacha20Poly1305.aead_encrypt
ek iv ad_len ad plain_len plain cipher tag;
Success
end
inline_for_extraction noextract
let encrypt_expand_aes_gcm (i: vale_impl): encrypt_expand_st false (alg_of_vale_impl i) =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s (alg_of_vale_impl i)) = alloca k in
let r = encrypt_aes_gcm i s iv iv_len ad ad_len plain plain_len cipher tag in
assert(r == Success);
pop_frame ();
Success
let encrypt_expand_aes128_gcm_no_check : encrypt_expand_st false AES128_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale"
let encrypt_expand_aes256_gcm_no_check : encrypt_expand_st false AES256_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len plain plain_len cipher tag
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale"
let encrypt_expand_aes128_gcm : encrypt_expand_st true AES128_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then
encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else
UnsupportedAlgorithm
else
UnsupportedAlgorithm
let encrypt_expand_aes256_gcm : encrypt_expand_st true AES256_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then
encrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len plain plain_len cipher tag
else
UnsupportedAlgorithm
else
UnsupportedAlgorithm
let encrypt_expand_chacha20_poly1305 : encrypt_expand_st false CHACHA20_POLY1305 =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s CHACHA20_POLY1305) = alloca k in
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
EverCrypt.Chacha20Poly1305.aead_encrypt ek iv ad_len ad plain_len plain cipher tag;
pop_frame ();
Success
let encrypt_expand #a k iv iv_len ad ad_len plain plain_len cipher tag =
match a with
| AES128_GCM ->
encrypt_expand_aes128_gcm k iv iv_len ad ad_len plain plain_len cipher tag
| AES256_GCM ->
encrypt_expand_aes256_gcm k iv iv_len ad ad_len plain plain_len cipher tag
| CHACHA20_POLY1305 ->
encrypt_expand_chacha20_poly1305 k iv iv_len ad ad_len plain plain_len cipher tag
inline_for_extraction noextract
let aes_gcm_decrypt (i: vale_impl):
Vale.Wrapper.X64.GCMdecryptOpt.decrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMdecryptOpt.gcm128_decrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMdecryptOpt256.gcm256_decrypt_opt_stdcall
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties.slice_slice'"
inline_for_extraction noextract
let decrypt_aes_gcm (i: vale_impl): decrypt_st (alg_of_vale_impl i) =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if B.is_null s then
InvalidKey
else
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len = 0ul then
InvalidIVLength
else
let a = alg_of_vale_impl i in
let open LowStar.BufferOps in
let Ek _ kv ek = !*s in
assert (
let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.AES_s.is_aes_key_LE (vale_alg_of_alg a) k_w);
push_frame();
let scratch_b = B.sub ek (concrete_xkey_len i) 176ul in
let ek = B.sub ek 0ul (concrete_xkey_len i) in
let keys_b = B.sub ek 0ul (key_offset i) in
let hkeys_b = B.sub ek (key_offset i) 128ul in
let h0 = get() in
// The iv can be arbitrary length, hence we need to allocate a new one to perform the hashing
let tmp_iv = B.alloca 0uy 16ul in
// There is no SMTPat on le_bytes_to_seq_quad32_to_bytes and the converse,
// so we need an explicit lemma
let lemma_hkeys_reqs () : Lemma
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.OptPublic.hkeys_reqs_pub
(Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 hkeys_b)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))))
= let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
let hkeys_quad = Vale.AES.OptPublic.get_hkeys_reqs (Vale.Def.Types_s.reverse_bytes_quad32 (
Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))) in
let hkeys = Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 (Vale.Def.Types_s.le_seq_quad32_to_bytes hkeys_quad) in
assert (Seq.equal (B.as_seq h0 hkeys_b) hkeys);
calc (==) {
Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 hkeys);
(==) { Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes hkeys_quad }
hkeys_quad;
}
in lemma_hkeys_reqs ();
// We perform the hashing of the iv. The extra buffer and the hashed iv are the same
Vale.Wrapper.X64.GCM_IV.compute_iv (vale_alg_of_alg a)
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w )
iv iv_len
tmp_iv tmp_iv
hkeys_b;
let r = aes_gcm_decrypt i
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w)
(Ghost.hide (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv)))
cipher
(uint32_to_uint64 cipher_len)
ad
(uint32_to_uint64 ad_len)
tmp_iv
dst
tag
keys_b
hkeys_b
scratch_b in
let h1 = get() in
// This assert is needed for z3 to pick up sequence equality for ciphertext
// It could be avoided if the spec returned both instead of appending them
assert (
let kv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (G.reveal kv) in
let iv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv) in
// `ad` is called `auth` in Vale world; "additional data", "authenticated
// data", potato, potato
let ad_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 ad) in
let cipher_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 cipher) in
let tag_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 tag) in
let plain_nat, success =
Vale.AES.GCM_s.gcm_decrypt_LE (vale_alg_of_alg a) kv_nat iv_nat cipher_nat ad_nat tag_nat
in
Seq.equal (B.as_seq h1 dst) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 plain_nat) /\
(UInt64.v r = 0) == success);
assert (
let kv = G.reveal kv in
let cipher_tag = B.as_seq h0 cipher `S.append` B.as_seq h0 tag in
Seq.equal (Seq.slice cipher_tag (S.length cipher_tag - tag_length a) (S.length cipher_tag))
(B.as_seq h0 tag) /\
Seq.equal (Seq.slice cipher_tag 0 (S.length cipher_tag - tag_length a)) (B.as_seq h0 cipher));
pop_frame();
if r = 0uL then
Success
else
AuthenticationFailure
let decrypt_aes128_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
decrypt_st AES128_GCM =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
decrypt_aes_gcm Vale_AES128 s iv iv_len ad ad_len cipher cipher_len tag dst
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let decrypt_aes256_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
decrypt_st AES256_GCM =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
decrypt_aes_gcm Vale_AES256 s iv iv_len ad ad_len cipher cipher_len tag dst
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let decrypt_chacha20_poly1305 : decrypt_st CHACHA20_POLY1305 =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if B.is_null s then
InvalidKey
else
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len <> 12ul then
InvalidIVLength
else begin
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
[@ inline_let ] let bound = pow2 32 - 1 - 16 in
assert (v cipher_len <= bound);
assert_norm (bound + 16 <= pow2 32 - 1);
assert_norm (pow2 31 + bound / 64 <= pow2 32 - 1);
let h0 = ST.get () in
let r = EverCrypt.Chacha20Poly1305.aead_decrypt
ek iv ad_len ad cipher_len dst cipher tag
in
assert (
let cipher_tag = B.as_seq h0 cipher `S.append` B.as_seq h0 tag in
let tag_s = S.slice cipher_tag (S.length cipher_tag - tag_length CHACHA20_POLY1305) (S.length cipher_tag) in
let cipher_s = S.slice cipher_tag 0 (S.length cipher_tag - tag_length CHACHA20_POLY1305) in
S.equal cipher_s (B.as_seq h0 cipher) /\ S.equal tag_s (B.as_seq h0 tag));
if r = 0ul then
Success
else
AuthenticationFailure
end
let decrypt #a s iv iv_len ad ad_len cipher cipher_len tag dst =
if B.is_null s then
InvalidKey
else
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
match i with
| Vale_AES128 ->
decrypt_aes128_gcm () s iv iv_len ad ad_len cipher cipher_len tag dst
| Vale_AES256 ->
decrypt_aes256_gcm () s iv iv_len ad ad_len cipher cipher_len tag dst
| Hacl_CHACHA20 ->
decrypt_chacha20_poly1305 s iv iv_len ad ad_len cipher cipher_len tag dst
inline_for_extraction noextract
let decrypt_expand_aes_gcm (i: vale_impl): decrypt_expand_st false (alg_of_vale_impl i) =
fun k iv iv_len ad ad_len cipher cipher_len tag dst ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s (alg_of_vale_impl i)) = alloca k in
let r = decrypt_aes_gcm i s iv iv_len ad ad_len cipher cipher_len tag dst in
pop_frame ();
r | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.AEAD.decrypt_expand_st false Spec.Agile.AEAD.AES128_GCM | Prims.Tot | [
"total"
] | [] | [
"LowStar.Buffer.buffer",
"EverCrypt.CTR.Keys.uint8",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.Integers.op_Greater_Equals",
"FStar.Integers.Signed",
"FStar.Integers.Winfinite",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"Spec.Agile.AEAD.key_length",
"Spec.Agile.AEAD.AES128_GCM",
"EverCrypt.AEAD.iv_p",
"FStar.UInt32.t",
"Prims.l_and",
"FStar.Integers.within_bounds",
"FStar.Integers.Unsigned",
"FStar.Integers.W32",
"FStar.Integers.v",
"FStar.Integers.op_Greater",
"EverCrypt.AEAD.ad_p",
"FStar.Integers.op_Less_Equals",
"Prims.pow2",
"EverCrypt.AEAD.cipher_p",
"Spec.Agile.AEAD.tag_length",
"Prims.nat",
"EverCrypt.TargetConfig.hacl_can_compile_vale",
"EverCrypt.AEAD.decrypt_expand_aes_gcm",
"Spec.Cipher.Expansion.Vale_AES128",
"EverCrypt.Error.error_code",
"Prims.bool",
"LowStar.Failure.failwith",
"EverCrypt.AEAD.decrypt_expand_st"
] | [] | false | false | false | false | false | let decrypt_expand_aes128_gcm_no_check:decrypt_expand_st false AES128_GCM =
| fun k iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale
then decrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len cipher cipher_len tag dst
else LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale" | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.encrypt_aes256_gcm | val encrypt_aes256_gcm: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)
-> encrypt_st AES256_GCM | val encrypt_aes256_gcm: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)
-> encrypt_st AES256_GCM | let encrypt_aes256_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES256_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES256 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable" | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 333,
"start_col": 0,
"start_line": 326
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success
#pop-options
inline_for_extraction noextract
let create_in_aes_gcm (i: vale_impl):
create_in_st (alg_of_vale_impl i) =
fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale then (
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then (
let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success
) else
UnsupportedAlgorithm
) else
UnsupportedAlgorithm
let create_in_aes128_gcm: create_in_st AES128_GCM = create_in_aes_gcm Vale_AES128
let create_in_aes256_gcm: create_in_st AES256_GCM = create_in_aes_gcm Vale_AES256
let create_in #a r dst k =
match a with
| AES128_GCM -> create_in_aes128_gcm r dst k
| AES256_GCM -> create_in_aes256_gcm r dst k
| CHACHA20_POLY1305 -> create_in_chacha20_poly1305 r dst k
| _ -> UnsupportedAlgorithm
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
inline_for_extraction noextract
let alloca_chacha20_poly1305: alloca_st CHACHA20_POLY1305 =
fun k ->
let h0 = ST.get () in
let ek = B.alloca 0uy 32ul in
let p = B.alloca (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.loc_none h0 h3;
p
#pop-options
inline_for_extraction noextract
let alloca_aes_gcm (i: vale_impl):
alloca_st (alg_of_vale_impl i) =
fun k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
let ek = B.alloca 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.alloca (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
p
inline_for_extraction noextract
let alloca_aes128_gcm: alloca_st AES128_GCM =
alloca_aes_gcm Vale_AES128
inline_for_extraction noextract
let alloca_aes256_gcm: alloca_st AES256_GCM =
alloca_aes_gcm Vale_AES256
let alloca #a k =
match a with
| AES128_GCM -> alloca_aes128_gcm k
| AES256_GCM -> alloca_aes256_gcm k
| CHACHA20_POLY1305 -> alloca_chacha20_poly1305 k
inline_for_extraction noextract
let aes_gcm_encrypt (i: vale_impl):
Vale.Wrapper.X64.GCMencryptOpt.encrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMencryptOpt.gcm128_encrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMencryptOpt256.gcm256_encrypt_opt_stdcall
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties.slice_slice'"
inline_for_extraction noextract
let encrypt_aes_gcm (i: vale_impl): encrypt_st (alg_of_vale_impl i) =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if B.is_null s then
InvalidKey
else
let a = alg_of_vale_impl i in
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len = 0ul then
InvalidIVLength
else
let open LowStar.BufferOps in
let Ek _ kv ek = !*s in
assert (
let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.AES_s.is_aes_key_LE (vale_alg_of_alg a) k_w);
push_frame();
let scratch_b = B.sub ek (concrete_xkey_len i) 176ul in
let ek = B.sub ek 0ul (concrete_xkey_len i) in
let keys_b = B.sub ek 0ul (key_offset i) in
let hkeys_b = B.sub ek (key_offset i) 128ul in
let h0 = get() in
// The iv can be arbitrary length, hence we need to allocate a new one to perform the hashing
let tmp_iv = B.alloca 0uy 16ul in
// There is no SMTPat on le_bytes_to_seq_quad32_to_bytes and the converse,
// so we need an explicit lemma
let lemma_hkeys_reqs () : Lemma
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.OptPublic.hkeys_reqs_pub
(Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 hkeys_b)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))))
= let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
let hkeys_quad = Vale.AES.OptPublic.get_hkeys_reqs (Vale.Def.Types_s.reverse_bytes_quad32 (
Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))) in
let hkeys = Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 (Vale.Def.Types_s.le_seq_quad32_to_bytes hkeys_quad) in
assert (Seq.equal (B.as_seq h0 hkeys_b) hkeys);
calc (==) {
Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 hkeys);
(==) { Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes hkeys_quad }
hkeys_quad;
}
in lemma_hkeys_reqs ();
// We perform the hashing of the iv. The extra buffer and the hashed iv are the same
Vale.Wrapper.X64.GCM_IV.compute_iv (vale_alg_of_alg a)
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w )
iv iv_len
tmp_iv tmp_iv
hkeys_b;
let h0 = get() in
aes_gcm_encrypt i
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w)
(Ghost.hide (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv)))
plain
(uint32_to_uint64 plain_len)
ad
(uint32_to_uint64 ad_len)
tmp_iv
cipher
tag
keys_b
hkeys_b
scratch_b;
let h1 = get() in
// This assert is needed for z3 to pick up sequence equality for ciphertext
// and tag. It could be avoided if the spec returned both instead of appending them
assert (
let kv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (G.reveal kv) in
let iv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv) in
// `ad` is called `auth` in Vale world; "additional data", "authenticated
// data", potato, potato
let ad_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 ad) in
let plain_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 plain) in
let cipher_nat, tag_nat =
Vale.AES.GCM_s.gcm_encrypt_LE (vale_alg_of_alg a) kv_nat iv_nat plain_nat ad_nat
in
Seq.equal (B.as_seq h1 cipher) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 cipher_nat) /\
Seq.equal (B.as_seq h1 tag) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 tag_nat));
pop_frame();
Success
let encrypt_aes128_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES128_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES128 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable" | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.squash EverCrypt.TargetConfig.hacl_can_compile_vale
-> EverCrypt.AEAD.encrypt_st Spec.Agile.AEAD.AES256_GCM | Prims.Tot | [
"total"
] | [] | [
"Prims.squash",
"Prims.b2t",
"EverCrypt.TargetConfig.hacl_can_compile_vale",
"LowStar.Buffer.pointer_or_null",
"EverCrypt.AEAD.state_s",
"Spec.Agile.AEAD.AES256_GCM",
"EverCrypt.AEAD.iv_p",
"FStar.UInt32.t",
"Prims.l_and",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.Integers.within_bounds",
"FStar.Integers.Unsigned",
"FStar.Integers.W32",
"FStar.Integers.v",
"LowStar.Monotonic.Buffer.length",
"EverCrypt.CTR.Keys.uint8",
"LowStar.Buffer.trivial_preorder",
"FStar.Integers.op_Greater",
"FStar.Integers.Signed",
"FStar.Integers.Winfinite",
"EverCrypt.AEAD.ad_p",
"FStar.Integers.op_Less_Equals",
"Prims.pow2",
"EverCrypt.AEAD.plain_p",
"Spec.Agile.AEAD.max_length",
"LowStar.Buffer.buffer",
"Prims.nat",
"Spec.Agile.AEAD.tag_length",
"EverCrypt.AEAD.encrypt_aes_gcm",
"Spec.Cipher.Expansion.Vale_AES256",
"EverCrypt.Error.error_code",
"Prims.bool",
"LowStar.Failure.failwith",
"Prims.unit",
"FStar.Pervasives.false_elim",
"EverCrypt.AEAD.encrypt_st"
] | [] | false | false | false | true | false | let encrypt_aes256_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale))
: encrypt_st AES256_GCM =
| fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale
then encrypt_aes_gcm Vale_AES256 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable" | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.aes_gcm_encrypt | val aes_gcm_encrypt (i: vale_impl)
: Vale.Wrapper.X64.GCMencryptOpt.encrypt_opt_stdcall_st (vale_alg_of_vale_impl i) | val aes_gcm_encrypt (i: vale_impl)
: Vale.Wrapper.X64.GCMencryptOpt.encrypt_opt_stdcall_st (vale_alg_of_vale_impl i) | let aes_gcm_encrypt (i: vale_impl):
Vale.Wrapper.X64.GCMencryptOpt.encrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMencryptOpt.gcm128_encrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMencryptOpt256.gcm256_encrypt_opt_stdcall | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 79,
"end_line": 210,
"start_col": 0,
"start_line": 206
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success
#pop-options
inline_for_extraction noextract
let create_in_aes_gcm (i: vale_impl):
create_in_st (alg_of_vale_impl i) =
fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale then (
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then (
let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success
) else
UnsupportedAlgorithm
) else
UnsupportedAlgorithm
let create_in_aes128_gcm: create_in_st AES128_GCM = create_in_aes_gcm Vale_AES128
let create_in_aes256_gcm: create_in_st AES256_GCM = create_in_aes_gcm Vale_AES256
let create_in #a r dst k =
match a with
| AES128_GCM -> create_in_aes128_gcm r dst k
| AES256_GCM -> create_in_aes256_gcm r dst k
| CHACHA20_POLY1305 -> create_in_chacha20_poly1305 r dst k
| _ -> UnsupportedAlgorithm
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
inline_for_extraction noextract
let alloca_chacha20_poly1305: alloca_st CHACHA20_POLY1305 =
fun k ->
let h0 = ST.get () in
let ek = B.alloca 0uy 32ul in
let p = B.alloca (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.loc_none h0 h3;
p
#pop-options
inline_for_extraction noextract
let alloca_aes_gcm (i: vale_impl):
alloca_st (alg_of_vale_impl i) =
fun k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
let ek = B.alloca 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.alloca (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
p
inline_for_extraction noextract
let alloca_aes128_gcm: alloca_st AES128_GCM =
alloca_aes_gcm Vale_AES128
inline_for_extraction noextract
let alloca_aes256_gcm: alloca_st AES256_GCM =
alloca_aes_gcm Vale_AES256
let alloca #a k =
match a with
| AES128_GCM -> alloca_aes128_gcm k
| AES256_GCM -> alloca_aes256_gcm k
| CHACHA20_POLY1305 -> alloca_chacha20_poly1305 k | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: EverCrypt.CTR.Keys.vale_impl
-> Vale.Wrapper.X64.GCMencryptOpt.encrypt_opt_stdcall_st (EverCrypt.CTR.Keys.vale_alg_of_vale_impl
i) | Prims.Tot | [
"total"
] | [] | [
"EverCrypt.CTR.Keys.vale_impl",
"Vale.Wrapper.X64.GCMencryptOpt.gcm128_encrypt_opt_stdcall",
"Vale.Wrapper.X64.GCMencryptOpt256.gcm256_encrypt_opt_stdcall",
"Vale.Wrapper.X64.GCMencryptOpt.encrypt_opt_stdcall_st",
"EverCrypt.CTR.Keys.vale_alg_of_vale_impl"
] | [] | false | false | false | false | false | let aes_gcm_encrypt (i: vale_impl)
: Vale.Wrapper.X64.GCMencryptOpt.encrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
| match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMencryptOpt.gcm128_encrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMencryptOpt256.gcm256_encrypt_opt_stdcall | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.encrypt_expand_aes256_gcm_no_check | val encrypt_expand_aes256_gcm_no_check: encrypt_expand_st false AES256_GCM | val encrypt_expand_aes256_gcm_no_check: encrypt_expand_st false AES256_GCM | let encrypt_expand_aes256_gcm_no_check : encrypt_expand_st false AES256_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len plain plain_len cipher tag
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale" | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 92,
"end_line": 382,
"start_col": 0,
"start_line": 377
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success
#pop-options
inline_for_extraction noextract
let create_in_aes_gcm (i: vale_impl):
create_in_st (alg_of_vale_impl i) =
fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale then (
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then (
let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success
) else
UnsupportedAlgorithm
) else
UnsupportedAlgorithm
let create_in_aes128_gcm: create_in_st AES128_GCM = create_in_aes_gcm Vale_AES128
let create_in_aes256_gcm: create_in_st AES256_GCM = create_in_aes_gcm Vale_AES256
let create_in #a r dst k =
match a with
| AES128_GCM -> create_in_aes128_gcm r dst k
| AES256_GCM -> create_in_aes256_gcm r dst k
| CHACHA20_POLY1305 -> create_in_chacha20_poly1305 r dst k
| _ -> UnsupportedAlgorithm
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
inline_for_extraction noextract
let alloca_chacha20_poly1305: alloca_st CHACHA20_POLY1305 =
fun k ->
let h0 = ST.get () in
let ek = B.alloca 0uy 32ul in
let p = B.alloca (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.loc_none h0 h3;
p
#pop-options
inline_for_extraction noextract
let alloca_aes_gcm (i: vale_impl):
alloca_st (alg_of_vale_impl i) =
fun k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
let ek = B.alloca 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.alloca (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
p
inline_for_extraction noextract
let alloca_aes128_gcm: alloca_st AES128_GCM =
alloca_aes_gcm Vale_AES128
inline_for_extraction noextract
let alloca_aes256_gcm: alloca_st AES256_GCM =
alloca_aes_gcm Vale_AES256
let alloca #a k =
match a with
| AES128_GCM -> alloca_aes128_gcm k
| AES256_GCM -> alloca_aes256_gcm k
| CHACHA20_POLY1305 -> alloca_chacha20_poly1305 k
inline_for_extraction noextract
let aes_gcm_encrypt (i: vale_impl):
Vale.Wrapper.X64.GCMencryptOpt.encrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMencryptOpt.gcm128_encrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMencryptOpt256.gcm256_encrypt_opt_stdcall
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties.slice_slice'"
inline_for_extraction noextract
let encrypt_aes_gcm (i: vale_impl): encrypt_st (alg_of_vale_impl i) =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if B.is_null s then
InvalidKey
else
let a = alg_of_vale_impl i in
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len = 0ul then
InvalidIVLength
else
let open LowStar.BufferOps in
let Ek _ kv ek = !*s in
assert (
let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.AES_s.is_aes_key_LE (vale_alg_of_alg a) k_w);
push_frame();
let scratch_b = B.sub ek (concrete_xkey_len i) 176ul in
let ek = B.sub ek 0ul (concrete_xkey_len i) in
let keys_b = B.sub ek 0ul (key_offset i) in
let hkeys_b = B.sub ek (key_offset i) 128ul in
let h0 = get() in
// The iv can be arbitrary length, hence we need to allocate a new one to perform the hashing
let tmp_iv = B.alloca 0uy 16ul in
// There is no SMTPat on le_bytes_to_seq_quad32_to_bytes and the converse,
// so we need an explicit lemma
let lemma_hkeys_reqs () : Lemma
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.OptPublic.hkeys_reqs_pub
(Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 hkeys_b)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))))
= let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
let hkeys_quad = Vale.AES.OptPublic.get_hkeys_reqs (Vale.Def.Types_s.reverse_bytes_quad32 (
Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))) in
let hkeys = Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 (Vale.Def.Types_s.le_seq_quad32_to_bytes hkeys_quad) in
assert (Seq.equal (B.as_seq h0 hkeys_b) hkeys);
calc (==) {
Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 hkeys);
(==) { Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes hkeys_quad }
hkeys_quad;
}
in lemma_hkeys_reqs ();
// We perform the hashing of the iv. The extra buffer and the hashed iv are the same
Vale.Wrapper.X64.GCM_IV.compute_iv (vale_alg_of_alg a)
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w )
iv iv_len
tmp_iv tmp_iv
hkeys_b;
let h0 = get() in
aes_gcm_encrypt i
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w)
(Ghost.hide (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv)))
plain
(uint32_to_uint64 plain_len)
ad
(uint32_to_uint64 ad_len)
tmp_iv
cipher
tag
keys_b
hkeys_b
scratch_b;
let h1 = get() in
// This assert is needed for z3 to pick up sequence equality for ciphertext
// and tag. It could be avoided if the spec returned both instead of appending them
assert (
let kv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (G.reveal kv) in
let iv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv) in
// `ad` is called `auth` in Vale world; "additional data", "authenticated
// data", potato, potato
let ad_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 ad) in
let plain_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 plain) in
let cipher_nat, tag_nat =
Vale.AES.GCM_s.gcm_encrypt_LE (vale_alg_of_alg a) kv_nat iv_nat plain_nat ad_nat
in
Seq.equal (B.as_seq h1 cipher) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 cipher_nat) /\
Seq.equal (B.as_seq h1 tag) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 tag_nat));
pop_frame();
Success
let encrypt_aes128_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES128_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES128 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt_aes256_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES256_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES256 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt #a s iv iv_len ad ad_len plain plain_len cipher tag =
if B.is_null s then
InvalidKey
else
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
match i with
| Vale_AES128 ->
encrypt_aes128_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Vale_AES256 ->
encrypt_aes256_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Hacl_CHACHA20 ->
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len <> 12ul then
InvalidIVLength
else begin
// Length restrictions
assert_norm (pow2 31 + pow2 32 / 64 <= pow2 32 - 1);
EverCrypt.Chacha20Poly1305.aead_encrypt
ek iv ad_len ad plain_len plain cipher tag;
Success
end
inline_for_extraction noextract
let encrypt_expand_aes_gcm (i: vale_impl): encrypt_expand_st false (alg_of_vale_impl i) =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s (alg_of_vale_impl i)) = alloca k in
let r = encrypt_aes_gcm i s iv iv_len ad ad_len plain plain_len cipher tag in
assert(r == Success);
pop_frame ();
Success
let encrypt_expand_aes128_gcm_no_check : encrypt_expand_st false AES128_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale" | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.AEAD.encrypt_expand_st false Spec.Agile.AEAD.AES256_GCM | Prims.Tot | [
"total"
] | [] | [
"LowStar.Buffer.buffer",
"EverCrypt.CTR.Keys.uint8",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.Integers.op_Greater_Equals",
"FStar.Integers.Signed",
"FStar.Integers.Winfinite",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"Spec.Agile.AEAD.key_length",
"Spec.Agile.AEAD.AES256_GCM",
"EverCrypt.AEAD.iv_p",
"FStar.UInt32.t",
"Prims.l_and",
"FStar.Integers.within_bounds",
"FStar.Integers.Unsigned",
"FStar.Integers.W32",
"FStar.Integers.v",
"FStar.Integers.op_Greater",
"EverCrypt.AEAD.ad_p",
"FStar.Integers.op_Less_Equals",
"Prims.pow2",
"EverCrypt.AEAD.plain_p",
"Spec.Agile.AEAD.max_length",
"Prims.nat",
"Spec.Agile.AEAD.tag_length",
"EverCrypt.TargetConfig.hacl_can_compile_vale",
"EverCrypt.AEAD.encrypt_expand_aes_gcm",
"Spec.Cipher.Expansion.Vale_AES256",
"EverCrypt.Error.error_code",
"Prims.bool",
"LowStar.Failure.failwith",
"EverCrypt.AEAD.encrypt_expand_st"
] | [] | false | false | false | false | false | let encrypt_expand_aes256_gcm_no_check:encrypt_expand_st false AES256_GCM =
| fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale
then encrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len plain plain_len cipher tag
else LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale" | false |
Vale.AES.PPC64LE.GHash.fsti | Vale.AES.PPC64LE.GHash.va_quick_GhashUnroll_n | val va_quick_GhashUnroll_n
(exactly2: bool)
(in_b: buffer128)
(index: nat)
(h_BE y_prev: quad32)
(data: (seq quad32))
: (va_quickCode unit (va_code_GhashUnroll_n exactly2)) | val va_quick_GhashUnroll_n
(exactly2: bool)
(in_b: buffer128)
(index: nat)
(h_BE y_prev: quad32)
(data: (seq quad32))
: (va_quickCode unit (va_code_GhashUnroll_n exactly2)) | let va_quick_GhashUnroll_n (exactly2:bool) (in_b:buffer128) (index:nat) (h_BE:quad32)
(y_prev:quad32) (data:(seq quad32)) : (va_quickCode unit (va_code_GhashUnroll_n exactly2)) =
(va_QProc (va_code_GhashUnroll_n exactly2) ([va_Mod_vec 11; va_Mod_vec 10; va_Mod_vec 9;
va_Mod_vec 8; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg
10]) (va_wp_GhashUnroll_n exactly2 in_b index h_BE y_prev data) (va_wpProof_GhashUnroll_n
exactly2 in_b index h_BE y_prev data)) | {
"file_name": "obj/Vale.AES.PPC64LE.GHash.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 42,
"end_line": 204,
"start_col": 0,
"start_line": 199
} | module Vale.AES.PPC64LE.GHash
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.AES.AES_BE_s
open Vale.PPC64LE.Machine_s
open Vale.PPC64LE.Memory
open Vale.PPC64LE.State
open Vale.PPC64LE.Decls
open Vale.PPC64LE.InsBasic
open Vale.PPC64LE.InsMem
open Vale.PPC64LE.InsVector
open Vale.PPC64LE.QuickCode
open Vale.PPC64LE.QuickCodes
open Vale.AES.AES_helpers
open Vale.Poly1305.Math // For lemma_poly_bits64()
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.Arch.TypesNative
open Vale.AES.PPC64LE.PolyOps
open Vale.AES.PPC64LE.GF128_Mul
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Bits_s
open Vale.Math.Poly2.Bits
open Vale.Math.Poly2.Lemmas
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.AES.GHash_BE
#reset-options "--z3rlimit 50"
unfold let va_subscript_FStar__Seq__Base__seq = Seq.index
let hkeys_b_powers (hkeys_b:buffer128) (heap0:vale_heap) (layout:vale_heap_layout) (ptr:int) (h:poly) =
validSrcAddrs128 heap0 ptr hkeys_b 3 layout Secret /\
of_quad32 (reverse_bytes_quad32 (buffer128_read hkeys_b 0 heap0)) == gf128_power h 1 /\
of_quad32 (reverse_bytes_quad32 (buffer128_read hkeys_b 1 heap0)) == gf128_power h 2
let in_b_blocks
(in_b:buffer128) (in_index count:int) (heap_s:vale_heap) (layout:vale_heap_layout) (ptr:int) (data:seq quad32)
=
validSrcAddrsOffset128 heap_s ptr in_b in_index count layout Secret /\
(forall (i:nat).{:pattern (index data i)}
i < count /\ i < length data ==>
reverse_bytes_quad32 (buffer128_read in_b (in_index + i) heap_s) == index data i)
//-- ReduceLast
val va_code_ReduceLast : va_dummy:unit -> Tot va_code
val va_codegen_success_ReduceLast : va_dummy:unit -> Tot va_pbool
val va_lemma_ReduceLast : va_b0:va_code -> va_s0:va_state -> h_BE:quad32 -> y_prev:quad32 ->
data:(seq quad32)
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_ReduceLast ()) va_s0 /\ va_get_ok va_s0 /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in va_get_vec 8 va_s0 ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 3254779904 0 0 /\ n > 0 /\ add (add
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 2 va_s0)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 3 va_s0)) 64)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 4 va_s0)) 128) ==
Vale.AES.GHash_BE.ghash_unroll_back h prev pdata 0 n (n - 1))))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in let xi =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_sM) in Vale.Math.Poly2.Bits_s.to_quad32 xi ==
Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data /\ xi == Vale.Math.Poly2.Bits_s.of_quad32
(Vale.Math.Poly2.Bits_s.to_quad32 xi)) /\ va_state_eq va_sM (va_update_vec 10 va_sM
(va_update_vec 9 va_sM (va_update_vec 8 va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM
(va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0 va_sM (va_update_ok va_sM
va_s0)))))))))))
[@ va_qattr]
let va_wp_ReduceLast (h_BE:quad32) (y_prev:quad32) (data:(seq quad32)) (va_s0:va_state)
(va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in
let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in va_get_vec 8 va_s0 ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 3254779904 0 0 /\ n > 0 /\ add (add
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 2 va_s0)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 3 va_s0)) 64)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 4 va_s0)) 128) ==
Vale.AES.GHash_BE.ghash_unroll_back h prev pdata 0 n (n - 1)) /\ (forall (va_x_v0:quad32)
(va_x_v1:quad32) (va_x_v2:quad32) (va_x_v3:quad32) (va_x_v4:quad32) (va_x_v8:quad32)
(va_x_v9:quad32) (va_x_v10:quad32) . let va_sM = va_upd_vec 10 va_x_v10 (va_upd_vec 9 va_x_v9
(va_upd_vec 8 va_x_v8 (va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2
(va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 va_s0))))))) in va_get_ok va_sM /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in let xi =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_sM) in Vale.Math.Poly2.Bits_s.to_quad32 xi ==
Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data /\ xi == Vale.Math.Poly2.Bits_s.of_quad32
(Vale.Math.Poly2.Bits_s.to_quad32 xi)) ==> va_k va_sM (())))
val va_wpProof_ReduceLast : h_BE:quad32 -> y_prev:quad32 -> data:(seq quad32) -> va_s0:va_state ->
va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_ReduceLast h_BE y_prev data va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_ReduceLast ()) ([va_Mod_vec 10;
va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec
0]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_ReduceLast (h_BE:quad32) (y_prev:quad32) (data:(seq quad32)) : (va_quickCode unit
(va_code_ReduceLast ())) =
(va_QProc (va_code_ReduceLast ()) ([va_Mod_vec 10; va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 4;
va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0]) (va_wp_ReduceLast h_BE y_prev data)
(va_wpProof_ReduceLast h_BE y_prev data))
//--
//-- GhashUnroll_n
val va_code_GhashUnroll_n : exactly2:bool -> Tot va_code
val va_codegen_success_GhashUnroll_n : exactly2:bool -> Tot va_pbool
val va_lemma_GhashUnroll_n : va_b0:va_code -> va_s0:va_state -> exactly2:bool -> in_b:buffer128 ->
index:nat -> h_BE:quad32 -> y_prev:quad32 -> data:(seq quad32)
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_GhashUnroll_n exactly2) va_s0 /\ va_get_ok va_s0 /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in (exactly2 ==> n == 2) /\
(~exactly2 ==> n == 1) /\ in_b_blocks in_b index n (va_get_mem_heaplet 1 va_s0)
(va_get_mem_layout va_s0) (va_get_reg 7 va_s0) data /\ Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 1 va_s0) == prev /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 5 va_s0) ==
Vale.Math.Poly2.swap (Vale.AES.GHash_BE.gf128_power h 1) 64 /\ Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 6 va_s0) == Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.div
(Vale.AES.GHash_BE.gf128_power h 1) (Vale.Math.Poly2_s.monomial 64))
(Vale.Math.Poly2_s.monomial 64) /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 7 va_s0) ==
Vale.Math.Poly2_s.mod (Vale.AES.GHash_BE.gf128_power h 1) (Vale.Math.Poly2_s.monomial 64) /\
(exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 12 va_s0) == Vale.Math.Poly2.swap
(Vale.AES.GHash_BE.gf128_power h 2) 64) /\ (exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 13 va_s0) == Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.div
(Vale.AES.GHash_BE.gf128_power h 2) (Vale.Math.Poly2_s.monomial 64))
(Vale.Math.Poly2_s.monomial 64)) /\ (exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec
14 va_s0) == Vale.Math.Poly2_s.mod (Vale.AES.GHash_BE.gf128_power h 2)
(Vale.Math.Poly2_s.monomial 64)))))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in va_get_vec 1 va_sM ==
Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data) /\ va_state_eq va_sM (va_update_vec 11
va_sM (va_update_vec 10 va_sM (va_update_vec 9 va_sM (va_update_vec 8 va_sM (va_update_vec 4
va_sM (va_update_vec 3 va_sM (va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0
va_sM (va_update_reg 10 va_sM (va_update_ok va_sM va_s0)))))))))))))
[@ va_qattr]
let va_wp_GhashUnroll_n (exactly2:bool) (in_b:buffer128) (index:nat) (h_BE:quad32) (y_prev:quad32)
(data:(seq quad32)) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in
let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in (exactly2 ==> n == 2) /\
(~exactly2 ==> n == 1) /\ in_b_blocks in_b index n (va_get_mem_heaplet 1 va_s0)
(va_get_mem_layout va_s0) (va_get_reg 7 va_s0) data /\ Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 1 va_s0) == prev /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 5 va_s0) ==
Vale.Math.Poly2.swap (Vale.AES.GHash_BE.gf128_power h 1) 64 /\ Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 6 va_s0) == Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.div
(Vale.AES.GHash_BE.gf128_power h 1) (Vale.Math.Poly2_s.monomial 64))
(Vale.Math.Poly2_s.monomial 64) /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 7 va_s0) ==
Vale.Math.Poly2_s.mod (Vale.AES.GHash_BE.gf128_power h 1) (Vale.Math.Poly2_s.monomial 64) /\
(exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 12 va_s0) == Vale.Math.Poly2.swap
(Vale.AES.GHash_BE.gf128_power h 2) 64) /\ (exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 13 va_s0) == Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.div
(Vale.AES.GHash_BE.gf128_power h 2) (Vale.Math.Poly2_s.monomial 64))
(Vale.Math.Poly2_s.monomial 64)) /\ (exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec
14 va_s0) == Vale.Math.Poly2_s.mod (Vale.AES.GHash_BE.gf128_power h 2)
(Vale.Math.Poly2_s.monomial 64))) /\ (forall (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32)
(va_x_v2:quad32) (va_x_v3:quad32) (va_x_v4:quad32) (va_x_v8:quad32) (va_x_v9:quad32)
(va_x_v10:quad32) (va_x_v11:quad32) . let va_sM = va_upd_vec 11 va_x_v11 (va_upd_vec 10
va_x_v10 (va_upd_vec 9 va_x_v9 (va_upd_vec 8 va_x_v8 (va_upd_vec 4 va_x_v4 (va_upd_vec 3
va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 (va_upd_reg 10
va_x_r10 va_s0))))))))) in va_get_ok va_sM /\ (let (h:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let (prev:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let (pdata:(Prims.int -> Vale.AES.GHash_BE.poly128))
= Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128 data in let (n:Prims.nat) = FStar.Seq.Base.length
#quad32 data in va_get_vec 1 va_sM == Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data) ==>
va_k va_sM (())))
val va_wpProof_GhashUnroll_n : exactly2:bool -> in_b:buffer128 -> index:nat -> h_BE:quad32 ->
y_prev:quad32 -> data:(seq quad32) -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_GhashUnroll_n exactly2 in_b index h_BE y_prev data va_s0
va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_GhashUnroll_n exactly2) ([va_Mod_vec
11; va_Mod_vec 10; va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2;
va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10]) va_s0 va_k ((va_sM, va_f0, va_g)))) | {
"checked_file": "/",
"dependencies": [
"Vale.PPC64LE.State.fsti.checked",
"Vale.PPC64LE.QuickCodes.fsti.checked",
"Vale.PPC64LE.QuickCode.fst.checked",
"Vale.PPC64LE.Memory.fsti.checked",
"Vale.PPC64LE.Machine_s.fst.checked",
"Vale.PPC64LE.InsVector.fsti.checked",
"Vale.PPC64LE.InsMem.fsti.checked",
"Vale.PPC64LE.InsBasic.fsti.checked",
"Vale.PPC64LE.Decls.fsti.checked",
"Vale.Poly1305.Math.fsti.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Lemmas.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Math.Poly2.Bits.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.AES.PPC64LE.PolyOps.fsti.checked",
"Vale.AES.PPC64LE.GF128_Mul.fsti.checked",
"Vale.AES.GHash_BE.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.fsti.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.AES_helpers.fsti.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.PPC64LE.GHash.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math // For lemma_poly_bits64()",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
exactly2: Prims.bool ->
in_b: Vale.PPC64LE.Memory.buffer128 ->
index: Prims.nat ->
h_BE: Vale.PPC64LE.Memory.quad32 ->
y_prev: Vale.PPC64LE.Memory.quad32 ->
data: FStar.Seq.Base.seq Vale.PPC64LE.Memory.quad32
-> Vale.PPC64LE.QuickCode.va_quickCode Prims.unit
(Vale.AES.PPC64LE.GHash.va_code_GhashUnroll_n exactly2) | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Vale.PPC64LE.Memory.buffer128",
"Prims.nat",
"Vale.PPC64LE.Memory.quad32",
"FStar.Seq.Base.seq",
"Vale.PPC64LE.QuickCode.va_QProc",
"Prims.unit",
"Vale.AES.PPC64LE.GHash.va_code_GhashUnroll_n",
"Prims.Cons",
"Vale.PPC64LE.QuickCode.mod_t",
"Vale.PPC64LE.QuickCode.va_Mod_vec",
"Vale.PPC64LE.QuickCode.va_Mod_reg",
"Prims.Nil",
"Vale.AES.PPC64LE.GHash.va_wp_GhashUnroll_n",
"Vale.AES.PPC64LE.GHash.va_wpProof_GhashUnroll_n",
"Vale.PPC64LE.QuickCode.va_quickCode"
] | [] | false | false | false | false | false | let va_quick_GhashUnroll_n
(exactly2: bool)
(in_b: buffer128)
(index: nat)
(h_BE y_prev: quad32)
(data: (seq quad32))
: (va_quickCode unit (va_code_GhashUnroll_n exactly2)) =
| (va_QProc (va_code_GhashUnroll_n exactly2)
([
va_Mod_vec 11; va_Mod_vec 10; va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 4; va_Mod_vec 3;
va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10
])
(va_wp_GhashUnroll_n exactly2 in_b index h_BE y_prev data)
(va_wpProof_GhashUnroll_n exactly2 in_b index h_BE y_prev data)) | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.valid_exact | val valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0 | val valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0 | let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
= valid_exact' p h s pos pos' | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 29,
"end_line": 195,
"start_col": 0,
"start_line": 185
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x))
let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos)
let get_valid_pos_post
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (
let pos' = get_valid_pos p h sl pos in
valid_pos p h sl pos pos'
))
[SMTPat (get_valid_pos p h sl pos)]
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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: LowParse.Spec.Base.parser k t ->
h: FStar.Monotonic.HyperStack.mem ->
s: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> Prims.GTot Type0 | Prims.GTot | [
"sometrivial"
] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.Base.Spec.valid_exact'"
] | [] | false | false | false | false | true | let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos pos': U32.t)
: GTot Type0 =
| valid_exact' p h s pos pos' | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.aes_gcm_decrypt | val aes_gcm_decrypt (i: vale_impl)
: Vale.Wrapper.X64.GCMdecryptOpt.decrypt_opt_stdcall_st (vale_alg_of_vale_impl i) | val aes_gcm_decrypt (i: vale_impl)
: Vale.Wrapper.X64.GCMdecryptOpt.decrypt_opt_stdcall_st (vale_alg_of_vale_impl i) | let aes_gcm_decrypt (i: vale_impl):
Vale.Wrapper.X64.GCMdecryptOpt.decrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMdecryptOpt.gcm128_decrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMdecryptOpt256.gcm256_decrypt_opt_stdcall | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 79,
"end_line": 439,
"start_col": 0,
"start_line": 435
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success
#pop-options
inline_for_extraction noextract
let create_in_aes_gcm (i: vale_impl):
create_in_st (alg_of_vale_impl i) =
fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale then (
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then (
let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success
) else
UnsupportedAlgorithm
) else
UnsupportedAlgorithm
let create_in_aes128_gcm: create_in_st AES128_GCM = create_in_aes_gcm Vale_AES128
let create_in_aes256_gcm: create_in_st AES256_GCM = create_in_aes_gcm Vale_AES256
let create_in #a r dst k =
match a with
| AES128_GCM -> create_in_aes128_gcm r dst k
| AES256_GCM -> create_in_aes256_gcm r dst k
| CHACHA20_POLY1305 -> create_in_chacha20_poly1305 r dst k
| _ -> UnsupportedAlgorithm
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
inline_for_extraction noextract
let alloca_chacha20_poly1305: alloca_st CHACHA20_POLY1305 =
fun k ->
let h0 = ST.get () in
let ek = B.alloca 0uy 32ul in
let p = B.alloca (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.loc_none h0 h3;
p
#pop-options
inline_for_extraction noextract
let alloca_aes_gcm (i: vale_impl):
alloca_st (alg_of_vale_impl i) =
fun k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
let ek = B.alloca 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.alloca (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
p
inline_for_extraction noextract
let alloca_aes128_gcm: alloca_st AES128_GCM =
alloca_aes_gcm Vale_AES128
inline_for_extraction noextract
let alloca_aes256_gcm: alloca_st AES256_GCM =
alloca_aes_gcm Vale_AES256
let alloca #a k =
match a with
| AES128_GCM -> alloca_aes128_gcm k
| AES256_GCM -> alloca_aes256_gcm k
| CHACHA20_POLY1305 -> alloca_chacha20_poly1305 k
inline_for_extraction noextract
let aes_gcm_encrypt (i: vale_impl):
Vale.Wrapper.X64.GCMencryptOpt.encrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMencryptOpt.gcm128_encrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMencryptOpt256.gcm256_encrypt_opt_stdcall
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties.slice_slice'"
inline_for_extraction noextract
let encrypt_aes_gcm (i: vale_impl): encrypt_st (alg_of_vale_impl i) =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if B.is_null s then
InvalidKey
else
let a = alg_of_vale_impl i in
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len = 0ul then
InvalidIVLength
else
let open LowStar.BufferOps in
let Ek _ kv ek = !*s in
assert (
let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.AES_s.is_aes_key_LE (vale_alg_of_alg a) k_w);
push_frame();
let scratch_b = B.sub ek (concrete_xkey_len i) 176ul in
let ek = B.sub ek 0ul (concrete_xkey_len i) in
let keys_b = B.sub ek 0ul (key_offset i) in
let hkeys_b = B.sub ek (key_offset i) 128ul in
let h0 = get() in
// The iv can be arbitrary length, hence we need to allocate a new one to perform the hashing
let tmp_iv = B.alloca 0uy 16ul in
// There is no SMTPat on le_bytes_to_seq_quad32_to_bytes and the converse,
// so we need an explicit lemma
let lemma_hkeys_reqs () : Lemma
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.OptPublic.hkeys_reqs_pub
(Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 hkeys_b)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))))
= let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
let hkeys_quad = Vale.AES.OptPublic.get_hkeys_reqs (Vale.Def.Types_s.reverse_bytes_quad32 (
Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))) in
let hkeys = Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 (Vale.Def.Types_s.le_seq_quad32_to_bytes hkeys_quad) in
assert (Seq.equal (B.as_seq h0 hkeys_b) hkeys);
calc (==) {
Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 hkeys);
(==) { Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes hkeys_quad }
hkeys_quad;
}
in lemma_hkeys_reqs ();
// We perform the hashing of the iv. The extra buffer and the hashed iv are the same
Vale.Wrapper.X64.GCM_IV.compute_iv (vale_alg_of_alg a)
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w )
iv iv_len
tmp_iv tmp_iv
hkeys_b;
let h0 = get() in
aes_gcm_encrypt i
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w)
(Ghost.hide (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv)))
plain
(uint32_to_uint64 plain_len)
ad
(uint32_to_uint64 ad_len)
tmp_iv
cipher
tag
keys_b
hkeys_b
scratch_b;
let h1 = get() in
// This assert is needed for z3 to pick up sequence equality for ciphertext
// and tag. It could be avoided if the spec returned both instead of appending them
assert (
let kv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (G.reveal kv) in
let iv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv) in
// `ad` is called `auth` in Vale world; "additional data", "authenticated
// data", potato, potato
let ad_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 ad) in
let plain_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 plain) in
let cipher_nat, tag_nat =
Vale.AES.GCM_s.gcm_encrypt_LE (vale_alg_of_alg a) kv_nat iv_nat plain_nat ad_nat
in
Seq.equal (B.as_seq h1 cipher) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 cipher_nat) /\
Seq.equal (B.as_seq h1 tag) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 tag_nat));
pop_frame();
Success
let encrypt_aes128_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES128_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES128 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt_aes256_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES256_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES256 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt #a s iv iv_len ad ad_len plain plain_len cipher tag =
if B.is_null s then
InvalidKey
else
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
match i with
| Vale_AES128 ->
encrypt_aes128_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Vale_AES256 ->
encrypt_aes256_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Hacl_CHACHA20 ->
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len <> 12ul then
InvalidIVLength
else begin
// Length restrictions
assert_norm (pow2 31 + pow2 32 / 64 <= pow2 32 - 1);
EverCrypt.Chacha20Poly1305.aead_encrypt
ek iv ad_len ad plain_len plain cipher tag;
Success
end
inline_for_extraction noextract
let encrypt_expand_aes_gcm (i: vale_impl): encrypt_expand_st false (alg_of_vale_impl i) =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s (alg_of_vale_impl i)) = alloca k in
let r = encrypt_aes_gcm i s iv iv_len ad ad_len plain plain_len cipher tag in
assert(r == Success);
pop_frame ();
Success
let encrypt_expand_aes128_gcm_no_check : encrypt_expand_st false AES128_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale"
let encrypt_expand_aes256_gcm_no_check : encrypt_expand_st false AES256_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len plain plain_len cipher tag
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale"
let encrypt_expand_aes128_gcm : encrypt_expand_st true AES128_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then
encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else
UnsupportedAlgorithm
else
UnsupportedAlgorithm
let encrypt_expand_aes256_gcm : encrypt_expand_st true AES256_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then
encrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len plain plain_len cipher tag
else
UnsupportedAlgorithm
else
UnsupportedAlgorithm
let encrypt_expand_chacha20_poly1305 : encrypt_expand_st false CHACHA20_POLY1305 =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s CHACHA20_POLY1305) = alloca k in
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
EverCrypt.Chacha20Poly1305.aead_encrypt ek iv ad_len ad plain_len plain cipher tag;
pop_frame ();
Success
let encrypt_expand #a k iv iv_len ad ad_len plain plain_len cipher tag =
match a with
| AES128_GCM ->
encrypt_expand_aes128_gcm k iv iv_len ad ad_len plain plain_len cipher tag
| AES256_GCM ->
encrypt_expand_aes256_gcm k iv iv_len ad ad_len plain plain_len cipher tag
| CHACHA20_POLY1305 ->
encrypt_expand_chacha20_poly1305 k iv iv_len ad ad_len plain plain_len cipher tag | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: EverCrypt.CTR.Keys.vale_impl
-> Vale.Wrapper.X64.GCMdecryptOpt.decrypt_opt_stdcall_st (EverCrypt.CTR.Keys.vale_alg_of_vale_impl
i) | Prims.Tot | [
"total"
] | [] | [
"EverCrypt.CTR.Keys.vale_impl",
"Vale.Wrapper.X64.GCMdecryptOpt.gcm128_decrypt_opt_stdcall",
"Vale.Wrapper.X64.GCMdecryptOpt256.gcm256_decrypt_opt_stdcall",
"Vale.Wrapper.X64.GCMdecryptOpt.decrypt_opt_stdcall_st",
"EverCrypt.CTR.Keys.vale_alg_of_vale_impl"
] | [] | false | false | false | false | false | let aes_gcm_decrypt (i: vale_impl)
: Vale.Wrapper.X64.GCMdecryptOpt.decrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
| match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMdecryptOpt.gcm128_decrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMdecryptOpt256.gcm256_decrypt_opt_stdcall | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.alloca_chacha20_poly1305 | val alloca_chacha20_poly1305:alloca_st CHACHA20_POLY1305 | val alloca_chacha20_poly1305:alloca_st CHACHA20_POLY1305 | let alloca_chacha20_poly1305: alloca_st CHACHA20_POLY1305 =
fun k ->
let h0 = ST.get () in
let ek = B.alloca 0uy 32ul in
let p = B.alloca (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.loc_none h0 h3;
p | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 173,
"start_col": 0,
"start_line": 165
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success
#pop-options
inline_for_extraction noextract
let create_in_aes_gcm (i: vale_impl):
create_in_st (alg_of_vale_impl i) =
fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale then (
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then (
let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success
) else
UnsupportedAlgorithm
) else
UnsupportedAlgorithm
let create_in_aes128_gcm: create_in_st AES128_GCM = create_in_aes_gcm Vale_AES128
let create_in_aes256_gcm: create_in_st AES256_GCM = create_in_aes_gcm Vale_AES256
let create_in #a r dst k =
match a with
| AES128_GCM -> create_in_aes128_gcm r dst k
| AES256_GCM -> create_in_aes256_gcm r dst k
| CHACHA20_POLY1305 -> create_in_chacha20_poly1305 r dst k
| _ -> UnsupportedAlgorithm
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5" | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.QI.EAGER_THRESHOLD=5"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.AEAD.alloca_st Spec.Agile.AEAD.CHACHA20_POLY1305 | Prims.Tot | [
"total"
] | [] | [
"LowStar.Buffer.buffer",
"EverCrypt.CTR.Keys.uint8",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.Integers.op_Greater_Equals",
"FStar.Integers.Signed",
"FStar.Integers.Winfinite",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"Spec.Agile.AEAD.key_length",
"Spec.Agile.AEAD.CHACHA20_POLY1305",
"Prims.unit",
"LowStar.Monotonic.Buffer.modifies_only_not_unused_in",
"LowStar.Monotonic.Buffer.loc_none",
"LowStar.Buffer.pointer",
"EverCrypt.AEAD.state_s",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowStar.Monotonic.Buffer.blit",
"FStar.UInt8.t",
"FStar.UInt32.__uint_to_t",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.l_and",
"Prims.eq2",
"Prims.nat",
"FStar.UInt32.v",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Prims.op_Negation",
"LowStar.Monotonic.Buffer.g_is_null",
"LowStar.Buffer.alloca",
"EverCrypt.AEAD.Ek",
"Spec.Cipher.Expansion.Hacl_CHACHA20",
"FStar.Ghost.hide",
"Spec.Agile.AEAD.kv",
"LowStar.Monotonic.Buffer.as_seq",
"FStar.UInt8.__uint_to_t"
] | [] | false | false | false | true | false | let alloca_chacha20_poly1305:alloca_st CHACHA20_POLY1305 =
| fun k ->
let h0 = ST.get () in
let ek = B.alloca 0uy 32ul in
let p = B.alloca (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
let h3 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h3;
p | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.decrypt_expand | val decrypt_expand: #a:supported_alg -> decrypt_expand_st true (G.reveal a) | val decrypt_expand: #a:supported_alg -> decrypt_expand_st true (G.reveal a) | let decrypt_expand #a k iv iv_len ad ad_len cipher cipher_len tag dst =
match a with
| AES128_GCM ->
decrypt_expand_aes128_gcm k iv iv_len ad ad_len cipher cipher_len tag dst
| AES256_GCM ->
decrypt_expand_aes256_gcm k iv iv_len ad ad_len cipher cipher_len tag dst
| CHACHA20_POLY1305 ->
decrypt_expand_chacha20_poly1305 k iv iv_len ad ad_len cipher cipher_len tag dst | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 84,
"end_line": 690,
"start_col": 0,
"start_line": 683
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success
#pop-options
inline_for_extraction noextract
let create_in_aes_gcm (i: vale_impl):
create_in_st (alg_of_vale_impl i) =
fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale then (
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then (
let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success
) else
UnsupportedAlgorithm
) else
UnsupportedAlgorithm
let create_in_aes128_gcm: create_in_st AES128_GCM = create_in_aes_gcm Vale_AES128
let create_in_aes256_gcm: create_in_st AES256_GCM = create_in_aes_gcm Vale_AES256
let create_in #a r dst k =
match a with
| AES128_GCM -> create_in_aes128_gcm r dst k
| AES256_GCM -> create_in_aes256_gcm r dst k
| CHACHA20_POLY1305 -> create_in_chacha20_poly1305 r dst k
| _ -> UnsupportedAlgorithm
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
inline_for_extraction noextract
let alloca_chacha20_poly1305: alloca_st CHACHA20_POLY1305 =
fun k ->
let h0 = ST.get () in
let ek = B.alloca 0uy 32ul in
let p = B.alloca (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.loc_none h0 h3;
p
#pop-options
inline_for_extraction noextract
let alloca_aes_gcm (i: vale_impl):
alloca_st (alg_of_vale_impl i) =
fun k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
let ek = B.alloca 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.alloca (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
p
inline_for_extraction noextract
let alloca_aes128_gcm: alloca_st AES128_GCM =
alloca_aes_gcm Vale_AES128
inline_for_extraction noextract
let alloca_aes256_gcm: alloca_st AES256_GCM =
alloca_aes_gcm Vale_AES256
let alloca #a k =
match a with
| AES128_GCM -> alloca_aes128_gcm k
| AES256_GCM -> alloca_aes256_gcm k
| CHACHA20_POLY1305 -> alloca_chacha20_poly1305 k
inline_for_extraction noextract
let aes_gcm_encrypt (i: vale_impl):
Vale.Wrapper.X64.GCMencryptOpt.encrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMencryptOpt.gcm128_encrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMencryptOpt256.gcm256_encrypt_opt_stdcall
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties.slice_slice'"
inline_for_extraction noextract
let encrypt_aes_gcm (i: vale_impl): encrypt_st (alg_of_vale_impl i) =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if B.is_null s then
InvalidKey
else
let a = alg_of_vale_impl i in
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len = 0ul then
InvalidIVLength
else
let open LowStar.BufferOps in
let Ek _ kv ek = !*s in
assert (
let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.AES_s.is_aes_key_LE (vale_alg_of_alg a) k_w);
push_frame();
let scratch_b = B.sub ek (concrete_xkey_len i) 176ul in
let ek = B.sub ek 0ul (concrete_xkey_len i) in
let keys_b = B.sub ek 0ul (key_offset i) in
let hkeys_b = B.sub ek (key_offset i) 128ul in
let h0 = get() in
// The iv can be arbitrary length, hence we need to allocate a new one to perform the hashing
let tmp_iv = B.alloca 0uy 16ul in
// There is no SMTPat on le_bytes_to_seq_quad32_to_bytes and the converse,
// so we need an explicit lemma
let lemma_hkeys_reqs () : Lemma
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.OptPublic.hkeys_reqs_pub
(Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 hkeys_b)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))))
= let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
let hkeys_quad = Vale.AES.OptPublic.get_hkeys_reqs (Vale.Def.Types_s.reverse_bytes_quad32 (
Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))) in
let hkeys = Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 (Vale.Def.Types_s.le_seq_quad32_to_bytes hkeys_quad) in
assert (Seq.equal (B.as_seq h0 hkeys_b) hkeys);
calc (==) {
Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 hkeys);
(==) { Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes hkeys_quad }
hkeys_quad;
}
in lemma_hkeys_reqs ();
// We perform the hashing of the iv. The extra buffer and the hashed iv are the same
Vale.Wrapper.X64.GCM_IV.compute_iv (vale_alg_of_alg a)
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w )
iv iv_len
tmp_iv tmp_iv
hkeys_b;
let h0 = get() in
aes_gcm_encrypt i
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w)
(Ghost.hide (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv)))
plain
(uint32_to_uint64 plain_len)
ad
(uint32_to_uint64 ad_len)
tmp_iv
cipher
tag
keys_b
hkeys_b
scratch_b;
let h1 = get() in
// This assert is needed for z3 to pick up sequence equality for ciphertext
// and tag. It could be avoided if the spec returned both instead of appending them
assert (
let kv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (G.reveal kv) in
let iv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv) in
// `ad` is called `auth` in Vale world; "additional data", "authenticated
// data", potato, potato
let ad_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 ad) in
let plain_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 plain) in
let cipher_nat, tag_nat =
Vale.AES.GCM_s.gcm_encrypt_LE (vale_alg_of_alg a) kv_nat iv_nat plain_nat ad_nat
in
Seq.equal (B.as_seq h1 cipher) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 cipher_nat) /\
Seq.equal (B.as_seq h1 tag) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 tag_nat));
pop_frame();
Success
let encrypt_aes128_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES128_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES128 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt_aes256_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES256_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES256 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt #a s iv iv_len ad ad_len plain plain_len cipher tag =
if B.is_null s then
InvalidKey
else
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
match i with
| Vale_AES128 ->
encrypt_aes128_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Vale_AES256 ->
encrypt_aes256_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Hacl_CHACHA20 ->
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len <> 12ul then
InvalidIVLength
else begin
// Length restrictions
assert_norm (pow2 31 + pow2 32 / 64 <= pow2 32 - 1);
EverCrypt.Chacha20Poly1305.aead_encrypt
ek iv ad_len ad plain_len plain cipher tag;
Success
end
inline_for_extraction noextract
let encrypt_expand_aes_gcm (i: vale_impl): encrypt_expand_st false (alg_of_vale_impl i) =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s (alg_of_vale_impl i)) = alloca k in
let r = encrypt_aes_gcm i s iv iv_len ad ad_len plain plain_len cipher tag in
assert(r == Success);
pop_frame ();
Success
let encrypt_expand_aes128_gcm_no_check : encrypt_expand_st false AES128_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale"
let encrypt_expand_aes256_gcm_no_check : encrypt_expand_st false AES256_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len plain plain_len cipher tag
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale"
let encrypt_expand_aes128_gcm : encrypt_expand_st true AES128_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then
encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else
UnsupportedAlgorithm
else
UnsupportedAlgorithm
let encrypt_expand_aes256_gcm : encrypt_expand_st true AES256_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then
encrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len plain plain_len cipher tag
else
UnsupportedAlgorithm
else
UnsupportedAlgorithm
let encrypt_expand_chacha20_poly1305 : encrypt_expand_st false CHACHA20_POLY1305 =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s CHACHA20_POLY1305) = alloca k in
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
EverCrypt.Chacha20Poly1305.aead_encrypt ek iv ad_len ad plain_len plain cipher tag;
pop_frame ();
Success
let encrypt_expand #a k iv iv_len ad ad_len plain plain_len cipher tag =
match a with
| AES128_GCM ->
encrypt_expand_aes128_gcm k iv iv_len ad ad_len plain plain_len cipher tag
| AES256_GCM ->
encrypt_expand_aes256_gcm k iv iv_len ad ad_len plain plain_len cipher tag
| CHACHA20_POLY1305 ->
encrypt_expand_chacha20_poly1305 k iv iv_len ad ad_len plain plain_len cipher tag
inline_for_extraction noextract
let aes_gcm_decrypt (i: vale_impl):
Vale.Wrapper.X64.GCMdecryptOpt.decrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMdecryptOpt.gcm128_decrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMdecryptOpt256.gcm256_decrypt_opt_stdcall
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties.slice_slice'"
inline_for_extraction noextract
let decrypt_aes_gcm (i: vale_impl): decrypt_st (alg_of_vale_impl i) =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if B.is_null s then
InvalidKey
else
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len = 0ul then
InvalidIVLength
else
let a = alg_of_vale_impl i in
let open LowStar.BufferOps in
let Ek _ kv ek = !*s in
assert (
let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.AES_s.is_aes_key_LE (vale_alg_of_alg a) k_w);
push_frame();
let scratch_b = B.sub ek (concrete_xkey_len i) 176ul in
let ek = B.sub ek 0ul (concrete_xkey_len i) in
let keys_b = B.sub ek 0ul (key_offset i) in
let hkeys_b = B.sub ek (key_offset i) 128ul in
let h0 = get() in
// The iv can be arbitrary length, hence we need to allocate a new one to perform the hashing
let tmp_iv = B.alloca 0uy 16ul in
// There is no SMTPat on le_bytes_to_seq_quad32_to_bytes and the converse,
// so we need an explicit lemma
let lemma_hkeys_reqs () : Lemma
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.OptPublic.hkeys_reqs_pub
(Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 hkeys_b)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))))
= let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
let hkeys_quad = Vale.AES.OptPublic.get_hkeys_reqs (Vale.Def.Types_s.reverse_bytes_quad32 (
Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))) in
let hkeys = Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 (Vale.Def.Types_s.le_seq_quad32_to_bytes hkeys_quad) in
assert (Seq.equal (B.as_seq h0 hkeys_b) hkeys);
calc (==) {
Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 hkeys);
(==) { Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes hkeys_quad }
hkeys_quad;
}
in lemma_hkeys_reqs ();
// We perform the hashing of the iv. The extra buffer and the hashed iv are the same
Vale.Wrapper.X64.GCM_IV.compute_iv (vale_alg_of_alg a)
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w )
iv iv_len
tmp_iv tmp_iv
hkeys_b;
let r = aes_gcm_decrypt i
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w)
(Ghost.hide (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv)))
cipher
(uint32_to_uint64 cipher_len)
ad
(uint32_to_uint64 ad_len)
tmp_iv
dst
tag
keys_b
hkeys_b
scratch_b in
let h1 = get() in
// This assert is needed for z3 to pick up sequence equality for ciphertext
// It could be avoided if the spec returned both instead of appending them
assert (
let kv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (G.reveal kv) in
let iv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv) in
// `ad` is called `auth` in Vale world; "additional data", "authenticated
// data", potato, potato
let ad_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 ad) in
let cipher_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 cipher) in
let tag_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 tag) in
let plain_nat, success =
Vale.AES.GCM_s.gcm_decrypt_LE (vale_alg_of_alg a) kv_nat iv_nat cipher_nat ad_nat tag_nat
in
Seq.equal (B.as_seq h1 dst) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 plain_nat) /\
(UInt64.v r = 0) == success);
assert (
let kv = G.reveal kv in
let cipher_tag = B.as_seq h0 cipher `S.append` B.as_seq h0 tag in
Seq.equal (Seq.slice cipher_tag (S.length cipher_tag - tag_length a) (S.length cipher_tag))
(B.as_seq h0 tag) /\
Seq.equal (Seq.slice cipher_tag 0 (S.length cipher_tag - tag_length a)) (B.as_seq h0 cipher));
pop_frame();
if r = 0uL then
Success
else
AuthenticationFailure
let decrypt_aes128_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
decrypt_st AES128_GCM =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
decrypt_aes_gcm Vale_AES128 s iv iv_len ad ad_len cipher cipher_len tag dst
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let decrypt_aes256_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
decrypt_st AES256_GCM =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
decrypt_aes_gcm Vale_AES256 s iv iv_len ad ad_len cipher cipher_len tag dst
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let decrypt_chacha20_poly1305 : decrypt_st CHACHA20_POLY1305 =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if B.is_null s then
InvalidKey
else
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len <> 12ul then
InvalidIVLength
else begin
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
[@ inline_let ] let bound = pow2 32 - 1 - 16 in
assert (v cipher_len <= bound);
assert_norm (bound + 16 <= pow2 32 - 1);
assert_norm (pow2 31 + bound / 64 <= pow2 32 - 1);
let h0 = ST.get () in
let r = EverCrypt.Chacha20Poly1305.aead_decrypt
ek iv ad_len ad cipher_len dst cipher tag
in
assert (
let cipher_tag = B.as_seq h0 cipher `S.append` B.as_seq h0 tag in
let tag_s = S.slice cipher_tag (S.length cipher_tag - tag_length CHACHA20_POLY1305) (S.length cipher_tag) in
let cipher_s = S.slice cipher_tag 0 (S.length cipher_tag - tag_length CHACHA20_POLY1305) in
S.equal cipher_s (B.as_seq h0 cipher) /\ S.equal tag_s (B.as_seq h0 tag));
if r = 0ul then
Success
else
AuthenticationFailure
end
let decrypt #a s iv iv_len ad ad_len cipher cipher_len tag dst =
if B.is_null s then
InvalidKey
else
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
match i with
| Vale_AES128 ->
decrypt_aes128_gcm () s iv iv_len ad ad_len cipher cipher_len tag dst
| Vale_AES256 ->
decrypt_aes256_gcm () s iv iv_len ad ad_len cipher cipher_len tag dst
| Hacl_CHACHA20 ->
decrypt_chacha20_poly1305 s iv iv_len ad ad_len cipher cipher_len tag dst
inline_for_extraction noextract
let decrypt_expand_aes_gcm (i: vale_impl): decrypt_expand_st false (alg_of_vale_impl i) =
fun k iv iv_len ad ad_len cipher cipher_len tag dst ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s (alg_of_vale_impl i)) = alloca k in
let r = decrypt_aes_gcm i s iv iv_len ad ad_len cipher cipher_len tag dst in
pop_frame ();
r
let decrypt_expand_aes128_gcm_no_check : decrypt_expand_st false AES128_GCM =
fun k iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
decrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len cipher cipher_len tag dst
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale"
let decrypt_expand_aes256_gcm_no_check : decrypt_expand_st false AES256_GCM =
fun k iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
decrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len cipher cipher_len tag dst
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale"
let decrypt_expand_aes128_gcm : decrypt_expand_st true AES128_GCM =
fun k iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then
decrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len cipher cipher_len tag dst
else
UnsupportedAlgorithm
else
UnsupportedAlgorithm
let decrypt_expand_aes256_gcm : decrypt_expand_st true AES256_GCM =
fun k iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then
decrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len cipher cipher_len tag dst
else
UnsupportedAlgorithm
else
UnsupportedAlgorithm
let decrypt_expand_chacha20_poly1305 : decrypt_expand_st false CHACHA20_POLY1305 =
fun k iv iv_len ad ad_len cipher cipher_len tag dst ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s CHACHA20_POLY1305) = alloca k in
let r = decrypt_chacha20_poly1305 s iv iv_len ad ad_len cipher cipher_len tag dst in
pop_frame ();
r | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.AEAD.decrypt_expand_st true (FStar.Ghost.reveal (FStar.Ghost.hide a)) | Prims.Tot | [
"total"
] | [] | [
"Spec.Agile.AEAD.supported_alg",
"LowStar.Buffer.buffer",
"EverCrypt.CTR.Keys.uint8",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.Integers.op_Greater_Equals",
"FStar.Integers.Signed",
"FStar.Integers.Winfinite",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"Spec.Agile.AEAD.key_length",
"FStar.Ghost.reveal",
"FStar.Ghost.hide",
"EverCrypt.AEAD.iv_p",
"FStar.UInt32.t",
"Prims.l_and",
"FStar.Integers.within_bounds",
"FStar.Integers.Unsigned",
"FStar.Integers.W32",
"FStar.Integers.v",
"FStar.Integers.op_Greater",
"EverCrypt.AEAD.ad_p",
"FStar.Integers.op_Less_Equals",
"Prims.pow2",
"EverCrypt.AEAD.cipher_p",
"Spec.Agile.AEAD.tag_length",
"Prims.nat",
"EverCrypt.AEAD.decrypt_expand_aes128_gcm",
"EverCrypt.Error.error_code",
"EverCrypt.AEAD.decrypt_expand_aes256_gcm",
"EverCrypt.AEAD.decrypt_expand_chacha20_poly1305"
] | [] | false | false | false | false | false | let decrypt_expand #a k iv iv_len ad ad_len cipher cipher_len tag dst =
| match a with
| AES128_GCM -> decrypt_expand_aes128_gcm k iv iv_len ad ad_len cipher cipher_len tag dst
| AES256_GCM -> decrypt_expand_aes256_gcm k iv iv_len ad ad_len cipher cipher_len tag dst
| CHACHA20_POLY1305 ->
decrypt_expand_chacha20_poly1305 k iv iv_len ad ad_len cipher cipher_len tag dst | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.decrypt_aes256_gcm | val decrypt_aes256_gcm: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)
-> decrypt_st AES256_GCM | val decrypt_aes256_gcm: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)
-> decrypt_st AES256_GCM | let decrypt_aes256_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
decrypt_st AES256_GCM =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
decrypt_aes_gcm Vale_AES256 s iv iv_len ad ad_len cipher cipher_len tag dst
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable" | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 571,
"start_col": 0,
"start_line": 564
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success
#pop-options
inline_for_extraction noextract
let create_in_aes_gcm (i: vale_impl):
create_in_st (alg_of_vale_impl i) =
fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale then (
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then (
let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success
) else
UnsupportedAlgorithm
) else
UnsupportedAlgorithm
let create_in_aes128_gcm: create_in_st AES128_GCM = create_in_aes_gcm Vale_AES128
let create_in_aes256_gcm: create_in_st AES256_GCM = create_in_aes_gcm Vale_AES256
let create_in #a r dst k =
match a with
| AES128_GCM -> create_in_aes128_gcm r dst k
| AES256_GCM -> create_in_aes256_gcm r dst k
| CHACHA20_POLY1305 -> create_in_chacha20_poly1305 r dst k
| _ -> UnsupportedAlgorithm
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
inline_for_extraction noextract
let alloca_chacha20_poly1305: alloca_st CHACHA20_POLY1305 =
fun k ->
let h0 = ST.get () in
let ek = B.alloca 0uy 32ul in
let p = B.alloca (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.loc_none h0 h3;
p
#pop-options
inline_for_extraction noextract
let alloca_aes_gcm (i: vale_impl):
alloca_st (alg_of_vale_impl i) =
fun k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
let ek = B.alloca 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.alloca (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
p
inline_for_extraction noextract
let alloca_aes128_gcm: alloca_st AES128_GCM =
alloca_aes_gcm Vale_AES128
inline_for_extraction noextract
let alloca_aes256_gcm: alloca_st AES256_GCM =
alloca_aes_gcm Vale_AES256
let alloca #a k =
match a with
| AES128_GCM -> alloca_aes128_gcm k
| AES256_GCM -> alloca_aes256_gcm k
| CHACHA20_POLY1305 -> alloca_chacha20_poly1305 k
inline_for_extraction noextract
let aes_gcm_encrypt (i: vale_impl):
Vale.Wrapper.X64.GCMencryptOpt.encrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMencryptOpt.gcm128_encrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMencryptOpt256.gcm256_encrypt_opt_stdcall
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties.slice_slice'"
inline_for_extraction noextract
let encrypt_aes_gcm (i: vale_impl): encrypt_st (alg_of_vale_impl i) =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if B.is_null s then
InvalidKey
else
let a = alg_of_vale_impl i in
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len = 0ul then
InvalidIVLength
else
let open LowStar.BufferOps in
let Ek _ kv ek = !*s in
assert (
let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.AES_s.is_aes_key_LE (vale_alg_of_alg a) k_w);
push_frame();
let scratch_b = B.sub ek (concrete_xkey_len i) 176ul in
let ek = B.sub ek 0ul (concrete_xkey_len i) in
let keys_b = B.sub ek 0ul (key_offset i) in
let hkeys_b = B.sub ek (key_offset i) 128ul in
let h0 = get() in
// The iv can be arbitrary length, hence we need to allocate a new one to perform the hashing
let tmp_iv = B.alloca 0uy 16ul in
// There is no SMTPat on le_bytes_to_seq_quad32_to_bytes and the converse,
// so we need an explicit lemma
let lemma_hkeys_reqs () : Lemma
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.OptPublic.hkeys_reqs_pub
(Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 hkeys_b)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))))
= let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
let hkeys_quad = Vale.AES.OptPublic.get_hkeys_reqs (Vale.Def.Types_s.reverse_bytes_quad32 (
Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))) in
let hkeys = Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 (Vale.Def.Types_s.le_seq_quad32_to_bytes hkeys_quad) in
assert (Seq.equal (B.as_seq h0 hkeys_b) hkeys);
calc (==) {
Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 hkeys);
(==) { Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes hkeys_quad }
hkeys_quad;
}
in lemma_hkeys_reqs ();
// We perform the hashing of the iv. The extra buffer and the hashed iv are the same
Vale.Wrapper.X64.GCM_IV.compute_iv (vale_alg_of_alg a)
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w )
iv iv_len
tmp_iv tmp_iv
hkeys_b;
let h0 = get() in
aes_gcm_encrypt i
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w)
(Ghost.hide (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv)))
plain
(uint32_to_uint64 plain_len)
ad
(uint32_to_uint64 ad_len)
tmp_iv
cipher
tag
keys_b
hkeys_b
scratch_b;
let h1 = get() in
// This assert is needed for z3 to pick up sequence equality for ciphertext
// and tag. It could be avoided if the spec returned both instead of appending them
assert (
let kv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (G.reveal kv) in
let iv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv) in
// `ad` is called `auth` in Vale world; "additional data", "authenticated
// data", potato, potato
let ad_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 ad) in
let plain_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 plain) in
let cipher_nat, tag_nat =
Vale.AES.GCM_s.gcm_encrypt_LE (vale_alg_of_alg a) kv_nat iv_nat plain_nat ad_nat
in
Seq.equal (B.as_seq h1 cipher) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 cipher_nat) /\
Seq.equal (B.as_seq h1 tag) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 tag_nat));
pop_frame();
Success
let encrypt_aes128_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES128_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES128 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt_aes256_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES256_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES256 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt #a s iv iv_len ad ad_len plain plain_len cipher tag =
if B.is_null s then
InvalidKey
else
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
match i with
| Vale_AES128 ->
encrypt_aes128_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Vale_AES256 ->
encrypt_aes256_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Hacl_CHACHA20 ->
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len <> 12ul then
InvalidIVLength
else begin
// Length restrictions
assert_norm (pow2 31 + pow2 32 / 64 <= pow2 32 - 1);
EverCrypt.Chacha20Poly1305.aead_encrypt
ek iv ad_len ad plain_len plain cipher tag;
Success
end
inline_for_extraction noextract
let encrypt_expand_aes_gcm (i: vale_impl): encrypt_expand_st false (alg_of_vale_impl i) =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s (alg_of_vale_impl i)) = alloca k in
let r = encrypt_aes_gcm i s iv iv_len ad ad_len plain plain_len cipher tag in
assert(r == Success);
pop_frame ();
Success
let encrypt_expand_aes128_gcm_no_check : encrypt_expand_st false AES128_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale"
let encrypt_expand_aes256_gcm_no_check : encrypt_expand_st false AES256_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len plain plain_len cipher tag
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale"
let encrypt_expand_aes128_gcm : encrypt_expand_st true AES128_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then
encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else
UnsupportedAlgorithm
else
UnsupportedAlgorithm
let encrypt_expand_aes256_gcm : encrypt_expand_st true AES256_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then
encrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len plain plain_len cipher tag
else
UnsupportedAlgorithm
else
UnsupportedAlgorithm
let encrypt_expand_chacha20_poly1305 : encrypt_expand_st false CHACHA20_POLY1305 =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s CHACHA20_POLY1305) = alloca k in
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
EverCrypt.Chacha20Poly1305.aead_encrypt ek iv ad_len ad plain_len plain cipher tag;
pop_frame ();
Success
let encrypt_expand #a k iv iv_len ad ad_len plain plain_len cipher tag =
match a with
| AES128_GCM ->
encrypt_expand_aes128_gcm k iv iv_len ad ad_len plain plain_len cipher tag
| AES256_GCM ->
encrypt_expand_aes256_gcm k iv iv_len ad ad_len plain plain_len cipher tag
| CHACHA20_POLY1305 ->
encrypt_expand_chacha20_poly1305 k iv iv_len ad ad_len plain plain_len cipher tag
inline_for_extraction noextract
let aes_gcm_decrypt (i: vale_impl):
Vale.Wrapper.X64.GCMdecryptOpt.decrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMdecryptOpt.gcm128_decrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMdecryptOpt256.gcm256_decrypt_opt_stdcall
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties.slice_slice'"
inline_for_extraction noextract
let decrypt_aes_gcm (i: vale_impl): decrypt_st (alg_of_vale_impl i) =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if B.is_null s then
InvalidKey
else
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len = 0ul then
InvalidIVLength
else
let a = alg_of_vale_impl i in
let open LowStar.BufferOps in
let Ek _ kv ek = !*s in
assert (
let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.AES_s.is_aes_key_LE (vale_alg_of_alg a) k_w);
push_frame();
let scratch_b = B.sub ek (concrete_xkey_len i) 176ul in
let ek = B.sub ek 0ul (concrete_xkey_len i) in
let keys_b = B.sub ek 0ul (key_offset i) in
let hkeys_b = B.sub ek (key_offset i) 128ul in
let h0 = get() in
// The iv can be arbitrary length, hence we need to allocate a new one to perform the hashing
let tmp_iv = B.alloca 0uy 16ul in
// There is no SMTPat on le_bytes_to_seq_quad32_to_bytes and the converse,
// so we need an explicit lemma
let lemma_hkeys_reqs () : Lemma
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.OptPublic.hkeys_reqs_pub
(Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 hkeys_b)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))))
= let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
let hkeys_quad = Vale.AES.OptPublic.get_hkeys_reqs (Vale.Def.Types_s.reverse_bytes_quad32 (
Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))) in
let hkeys = Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 (Vale.Def.Types_s.le_seq_quad32_to_bytes hkeys_quad) in
assert (Seq.equal (B.as_seq h0 hkeys_b) hkeys);
calc (==) {
Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 hkeys);
(==) { Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes hkeys_quad }
hkeys_quad;
}
in lemma_hkeys_reqs ();
// We perform the hashing of the iv. The extra buffer and the hashed iv are the same
Vale.Wrapper.X64.GCM_IV.compute_iv (vale_alg_of_alg a)
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w )
iv iv_len
tmp_iv tmp_iv
hkeys_b;
let r = aes_gcm_decrypt i
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w)
(Ghost.hide (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv)))
cipher
(uint32_to_uint64 cipher_len)
ad
(uint32_to_uint64 ad_len)
tmp_iv
dst
tag
keys_b
hkeys_b
scratch_b in
let h1 = get() in
// This assert is needed for z3 to pick up sequence equality for ciphertext
// It could be avoided if the spec returned both instead of appending them
assert (
let kv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (G.reveal kv) in
let iv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv) in
// `ad` is called `auth` in Vale world; "additional data", "authenticated
// data", potato, potato
let ad_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 ad) in
let cipher_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 cipher) in
let tag_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 tag) in
let plain_nat, success =
Vale.AES.GCM_s.gcm_decrypt_LE (vale_alg_of_alg a) kv_nat iv_nat cipher_nat ad_nat tag_nat
in
Seq.equal (B.as_seq h1 dst) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 plain_nat) /\
(UInt64.v r = 0) == success);
assert (
let kv = G.reveal kv in
let cipher_tag = B.as_seq h0 cipher `S.append` B.as_seq h0 tag in
Seq.equal (Seq.slice cipher_tag (S.length cipher_tag - tag_length a) (S.length cipher_tag))
(B.as_seq h0 tag) /\
Seq.equal (Seq.slice cipher_tag 0 (S.length cipher_tag - tag_length a)) (B.as_seq h0 cipher));
pop_frame();
if r = 0uL then
Success
else
AuthenticationFailure
let decrypt_aes128_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
decrypt_st AES128_GCM =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
decrypt_aes_gcm Vale_AES128 s iv iv_len ad ad_len cipher cipher_len tag dst
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable" | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.squash EverCrypt.TargetConfig.hacl_can_compile_vale
-> EverCrypt.AEAD.decrypt_st Spec.Agile.AEAD.AES256_GCM | Prims.Tot | [
"total"
] | [] | [
"Prims.squash",
"Prims.b2t",
"EverCrypt.TargetConfig.hacl_can_compile_vale",
"LowStar.Buffer.pointer_or_null",
"EverCrypt.AEAD.state_s",
"Spec.Agile.AEAD.AES256_GCM",
"EverCrypt.AEAD.iv_p",
"FStar.UInt32.t",
"Prims.l_and",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.Integers.within_bounds",
"FStar.Integers.Unsigned",
"FStar.Integers.W32",
"FStar.Integers.v",
"LowStar.Monotonic.Buffer.length",
"EverCrypt.CTR.Keys.uint8",
"LowStar.Buffer.trivial_preorder",
"FStar.Integers.op_Greater",
"FStar.Integers.Signed",
"FStar.Integers.Winfinite",
"EverCrypt.AEAD.ad_p",
"FStar.Integers.op_Less_Equals",
"Prims.pow2",
"EverCrypt.AEAD.cipher_p",
"LowStar.Buffer.buffer",
"Spec.Agile.AEAD.tag_length",
"Prims.nat",
"EverCrypt.AEAD.decrypt_aes_gcm",
"Spec.Cipher.Expansion.Vale_AES256",
"EverCrypt.Error.error_code",
"Prims.bool",
"LowStar.Failure.failwith",
"Prims.unit",
"FStar.Pervasives.false_elim",
"EverCrypt.AEAD.decrypt_st"
] | [] | false | false | false | true | false | let decrypt_aes256_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale))
: decrypt_st AES256_GCM =
| fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale
then decrypt_aes_gcm Vale_AES256 s iv iv_len ad ad_len cipher cipher_len tag dst
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable" | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.decrypt_expand_aes256_gcm_no_check | val decrypt_expand_aes256_gcm_no_check: decrypt_expand_st false AES256_GCM | val decrypt_expand_aes256_gcm_no_check: decrypt_expand_st false AES256_GCM | let decrypt_expand_aes256_gcm_no_check : decrypt_expand_st false AES256_GCM =
fun k iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
decrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len cipher cipher_len tag dst
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale" | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 92,
"end_line": 642,
"start_col": 0,
"start_line": 637
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success
#pop-options
inline_for_extraction noextract
let create_in_aes_gcm (i: vale_impl):
create_in_st (alg_of_vale_impl i) =
fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale then (
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then (
let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success
) else
UnsupportedAlgorithm
) else
UnsupportedAlgorithm
let create_in_aes128_gcm: create_in_st AES128_GCM = create_in_aes_gcm Vale_AES128
let create_in_aes256_gcm: create_in_st AES256_GCM = create_in_aes_gcm Vale_AES256
let create_in #a r dst k =
match a with
| AES128_GCM -> create_in_aes128_gcm r dst k
| AES256_GCM -> create_in_aes256_gcm r dst k
| CHACHA20_POLY1305 -> create_in_chacha20_poly1305 r dst k
| _ -> UnsupportedAlgorithm
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
inline_for_extraction noextract
let alloca_chacha20_poly1305: alloca_st CHACHA20_POLY1305 =
fun k ->
let h0 = ST.get () in
let ek = B.alloca 0uy 32ul in
let p = B.alloca (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.loc_none h0 h3;
p
#pop-options
inline_for_extraction noextract
let alloca_aes_gcm (i: vale_impl):
alloca_st (alg_of_vale_impl i) =
fun k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
let ek = B.alloca 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.alloca (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
p
inline_for_extraction noextract
let alloca_aes128_gcm: alloca_st AES128_GCM =
alloca_aes_gcm Vale_AES128
inline_for_extraction noextract
let alloca_aes256_gcm: alloca_st AES256_GCM =
alloca_aes_gcm Vale_AES256
let alloca #a k =
match a with
| AES128_GCM -> alloca_aes128_gcm k
| AES256_GCM -> alloca_aes256_gcm k
| CHACHA20_POLY1305 -> alloca_chacha20_poly1305 k
inline_for_extraction noextract
let aes_gcm_encrypt (i: vale_impl):
Vale.Wrapper.X64.GCMencryptOpt.encrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMencryptOpt.gcm128_encrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMencryptOpt256.gcm256_encrypt_opt_stdcall
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties.slice_slice'"
inline_for_extraction noextract
let encrypt_aes_gcm (i: vale_impl): encrypt_st (alg_of_vale_impl i) =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if B.is_null s then
InvalidKey
else
let a = alg_of_vale_impl i in
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len = 0ul then
InvalidIVLength
else
let open LowStar.BufferOps in
let Ek _ kv ek = !*s in
assert (
let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.AES_s.is_aes_key_LE (vale_alg_of_alg a) k_w);
push_frame();
let scratch_b = B.sub ek (concrete_xkey_len i) 176ul in
let ek = B.sub ek 0ul (concrete_xkey_len i) in
let keys_b = B.sub ek 0ul (key_offset i) in
let hkeys_b = B.sub ek (key_offset i) 128ul in
let h0 = get() in
// The iv can be arbitrary length, hence we need to allocate a new one to perform the hashing
let tmp_iv = B.alloca 0uy 16ul in
// There is no SMTPat on le_bytes_to_seq_quad32_to_bytes and the converse,
// so we need an explicit lemma
let lemma_hkeys_reqs () : Lemma
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.OptPublic.hkeys_reqs_pub
(Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 hkeys_b)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))))
= let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
let hkeys_quad = Vale.AES.OptPublic.get_hkeys_reqs (Vale.Def.Types_s.reverse_bytes_quad32 (
Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))) in
let hkeys = Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 (Vale.Def.Types_s.le_seq_quad32_to_bytes hkeys_quad) in
assert (Seq.equal (B.as_seq h0 hkeys_b) hkeys);
calc (==) {
Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 hkeys);
(==) { Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes hkeys_quad }
hkeys_quad;
}
in lemma_hkeys_reqs ();
// We perform the hashing of the iv. The extra buffer and the hashed iv are the same
Vale.Wrapper.X64.GCM_IV.compute_iv (vale_alg_of_alg a)
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w )
iv iv_len
tmp_iv tmp_iv
hkeys_b;
let h0 = get() in
aes_gcm_encrypt i
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w)
(Ghost.hide (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv)))
plain
(uint32_to_uint64 plain_len)
ad
(uint32_to_uint64 ad_len)
tmp_iv
cipher
tag
keys_b
hkeys_b
scratch_b;
let h1 = get() in
// This assert is needed for z3 to pick up sequence equality for ciphertext
// and tag. It could be avoided if the spec returned both instead of appending them
assert (
let kv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (G.reveal kv) in
let iv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv) in
// `ad` is called `auth` in Vale world; "additional data", "authenticated
// data", potato, potato
let ad_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 ad) in
let plain_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 plain) in
let cipher_nat, tag_nat =
Vale.AES.GCM_s.gcm_encrypt_LE (vale_alg_of_alg a) kv_nat iv_nat plain_nat ad_nat
in
Seq.equal (B.as_seq h1 cipher) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 cipher_nat) /\
Seq.equal (B.as_seq h1 tag) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 tag_nat));
pop_frame();
Success
let encrypt_aes128_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES128_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES128 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt_aes256_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES256_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES256 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt #a s iv iv_len ad ad_len plain plain_len cipher tag =
if B.is_null s then
InvalidKey
else
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
match i with
| Vale_AES128 ->
encrypt_aes128_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Vale_AES256 ->
encrypt_aes256_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Hacl_CHACHA20 ->
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len <> 12ul then
InvalidIVLength
else begin
// Length restrictions
assert_norm (pow2 31 + pow2 32 / 64 <= pow2 32 - 1);
EverCrypt.Chacha20Poly1305.aead_encrypt
ek iv ad_len ad plain_len plain cipher tag;
Success
end
inline_for_extraction noextract
let encrypt_expand_aes_gcm (i: vale_impl): encrypt_expand_st false (alg_of_vale_impl i) =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s (alg_of_vale_impl i)) = alloca k in
let r = encrypt_aes_gcm i s iv iv_len ad ad_len plain plain_len cipher tag in
assert(r == Success);
pop_frame ();
Success
let encrypt_expand_aes128_gcm_no_check : encrypt_expand_st false AES128_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale"
let encrypt_expand_aes256_gcm_no_check : encrypt_expand_st false AES256_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len plain plain_len cipher tag
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale"
let encrypt_expand_aes128_gcm : encrypt_expand_st true AES128_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then
encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else
UnsupportedAlgorithm
else
UnsupportedAlgorithm
let encrypt_expand_aes256_gcm : encrypt_expand_st true AES256_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then
encrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len plain plain_len cipher tag
else
UnsupportedAlgorithm
else
UnsupportedAlgorithm
let encrypt_expand_chacha20_poly1305 : encrypt_expand_st false CHACHA20_POLY1305 =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s CHACHA20_POLY1305) = alloca k in
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
EverCrypt.Chacha20Poly1305.aead_encrypt ek iv ad_len ad plain_len plain cipher tag;
pop_frame ();
Success
let encrypt_expand #a k iv iv_len ad ad_len plain plain_len cipher tag =
match a with
| AES128_GCM ->
encrypt_expand_aes128_gcm k iv iv_len ad ad_len plain plain_len cipher tag
| AES256_GCM ->
encrypt_expand_aes256_gcm k iv iv_len ad ad_len plain plain_len cipher tag
| CHACHA20_POLY1305 ->
encrypt_expand_chacha20_poly1305 k iv iv_len ad ad_len plain plain_len cipher tag
inline_for_extraction noextract
let aes_gcm_decrypt (i: vale_impl):
Vale.Wrapper.X64.GCMdecryptOpt.decrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMdecryptOpt.gcm128_decrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMdecryptOpt256.gcm256_decrypt_opt_stdcall
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties.slice_slice'"
inline_for_extraction noextract
let decrypt_aes_gcm (i: vale_impl): decrypt_st (alg_of_vale_impl i) =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if B.is_null s then
InvalidKey
else
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len = 0ul then
InvalidIVLength
else
let a = alg_of_vale_impl i in
let open LowStar.BufferOps in
let Ek _ kv ek = !*s in
assert (
let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.AES_s.is_aes_key_LE (vale_alg_of_alg a) k_w);
push_frame();
let scratch_b = B.sub ek (concrete_xkey_len i) 176ul in
let ek = B.sub ek 0ul (concrete_xkey_len i) in
let keys_b = B.sub ek 0ul (key_offset i) in
let hkeys_b = B.sub ek (key_offset i) 128ul in
let h0 = get() in
// The iv can be arbitrary length, hence we need to allocate a new one to perform the hashing
let tmp_iv = B.alloca 0uy 16ul in
// There is no SMTPat on le_bytes_to_seq_quad32_to_bytes and the converse,
// so we need an explicit lemma
let lemma_hkeys_reqs () : Lemma
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.OptPublic.hkeys_reqs_pub
(Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 hkeys_b)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))))
= let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
let hkeys_quad = Vale.AES.OptPublic.get_hkeys_reqs (Vale.Def.Types_s.reverse_bytes_quad32 (
Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))) in
let hkeys = Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 (Vale.Def.Types_s.le_seq_quad32_to_bytes hkeys_quad) in
assert (Seq.equal (B.as_seq h0 hkeys_b) hkeys);
calc (==) {
Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 hkeys);
(==) { Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes hkeys_quad }
hkeys_quad;
}
in lemma_hkeys_reqs ();
// We perform the hashing of the iv. The extra buffer and the hashed iv are the same
Vale.Wrapper.X64.GCM_IV.compute_iv (vale_alg_of_alg a)
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w )
iv iv_len
tmp_iv tmp_iv
hkeys_b;
let r = aes_gcm_decrypt i
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w)
(Ghost.hide (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv)))
cipher
(uint32_to_uint64 cipher_len)
ad
(uint32_to_uint64 ad_len)
tmp_iv
dst
tag
keys_b
hkeys_b
scratch_b in
let h1 = get() in
// This assert is needed for z3 to pick up sequence equality for ciphertext
// It could be avoided if the spec returned both instead of appending them
assert (
let kv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (G.reveal kv) in
let iv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv) in
// `ad` is called `auth` in Vale world; "additional data", "authenticated
// data", potato, potato
let ad_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 ad) in
let cipher_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 cipher) in
let tag_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 tag) in
let plain_nat, success =
Vale.AES.GCM_s.gcm_decrypt_LE (vale_alg_of_alg a) kv_nat iv_nat cipher_nat ad_nat tag_nat
in
Seq.equal (B.as_seq h1 dst) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 plain_nat) /\
(UInt64.v r = 0) == success);
assert (
let kv = G.reveal kv in
let cipher_tag = B.as_seq h0 cipher `S.append` B.as_seq h0 tag in
Seq.equal (Seq.slice cipher_tag (S.length cipher_tag - tag_length a) (S.length cipher_tag))
(B.as_seq h0 tag) /\
Seq.equal (Seq.slice cipher_tag 0 (S.length cipher_tag - tag_length a)) (B.as_seq h0 cipher));
pop_frame();
if r = 0uL then
Success
else
AuthenticationFailure
let decrypt_aes128_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
decrypt_st AES128_GCM =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
decrypt_aes_gcm Vale_AES128 s iv iv_len ad ad_len cipher cipher_len tag dst
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let decrypt_aes256_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
decrypt_st AES256_GCM =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
decrypt_aes_gcm Vale_AES256 s iv iv_len ad ad_len cipher cipher_len tag dst
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let decrypt_chacha20_poly1305 : decrypt_st CHACHA20_POLY1305 =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if B.is_null s then
InvalidKey
else
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len <> 12ul then
InvalidIVLength
else begin
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
[@ inline_let ] let bound = pow2 32 - 1 - 16 in
assert (v cipher_len <= bound);
assert_norm (bound + 16 <= pow2 32 - 1);
assert_norm (pow2 31 + bound / 64 <= pow2 32 - 1);
let h0 = ST.get () in
let r = EverCrypt.Chacha20Poly1305.aead_decrypt
ek iv ad_len ad cipher_len dst cipher tag
in
assert (
let cipher_tag = B.as_seq h0 cipher `S.append` B.as_seq h0 tag in
let tag_s = S.slice cipher_tag (S.length cipher_tag - tag_length CHACHA20_POLY1305) (S.length cipher_tag) in
let cipher_s = S.slice cipher_tag 0 (S.length cipher_tag - tag_length CHACHA20_POLY1305) in
S.equal cipher_s (B.as_seq h0 cipher) /\ S.equal tag_s (B.as_seq h0 tag));
if r = 0ul then
Success
else
AuthenticationFailure
end
let decrypt #a s iv iv_len ad ad_len cipher cipher_len tag dst =
if B.is_null s then
InvalidKey
else
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
match i with
| Vale_AES128 ->
decrypt_aes128_gcm () s iv iv_len ad ad_len cipher cipher_len tag dst
| Vale_AES256 ->
decrypt_aes256_gcm () s iv iv_len ad ad_len cipher cipher_len tag dst
| Hacl_CHACHA20 ->
decrypt_chacha20_poly1305 s iv iv_len ad ad_len cipher cipher_len tag dst
inline_for_extraction noextract
let decrypt_expand_aes_gcm (i: vale_impl): decrypt_expand_st false (alg_of_vale_impl i) =
fun k iv iv_len ad ad_len cipher cipher_len tag dst ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s (alg_of_vale_impl i)) = alloca k in
let r = decrypt_aes_gcm i s iv iv_len ad ad_len cipher cipher_len tag dst in
pop_frame ();
r
let decrypt_expand_aes128_gcm_no_check : decrypt_expand_st false AES128_GCM =
fun k iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
decrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len cipher cipher_len tag dst
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale" | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.AEAD.decrypt_expand_st false Spec.Agile.AEAD.AES256_GCM | Prims.Tot | [
"total"
] | [] | [
"LowStar.Buffer.buffer",
"EverCrypt.CTR.Keys.uint8",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.Integers.op_Greater_Equals",
"FStar.Integers.Signed",
"FStar.Integers.Winfinite",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"Spec.Agile.AEAD.key_length",
"Spec.Agile.AEAD.AES256_GCM",
"EverCrypt.AEAD.iv_p",
"FStar.UInt32.t",
"Prims.l_and",
"FStar.Integers.within_bounds",
"FStar.Integers.Unsigned",
"FStar.Integers.W32",
"FStar.Integers.v",
"FStar.Integers.op_Greater",
"EverCrypt.AEAD.ad_p",
"FStar.Integers.op_Less_Equals",
"Prims.pow2",
"EverCrypt.AEAD.cipher_p",
"Spec.Agile.AEAD.tag_length",
"Prims.nat",
"EverCrypt.TargetConfig.hacl_can_compile_vale",
"EverCrypt.AEAD.decrypt_expand_aes_gcm",
"Spec.Cipher.Expansion.Vale_AES256",
"EverCrypt.Error.error_code",
"Prims.bool",
"LowStar.Failure.failwith",
"EverCrypt.AEAD.decrypt_expand_st"
] | [] | false | false | false | false | false | let decrypt_expand_aes256_gcm_no_check:decrypt_expand_st false AES256_GCM =
| fun k iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale
then decrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len cipher cipher_len tag dst
else LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale" | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.valid_dec | val valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
)) | val valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
)) | let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos)) | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 77,
"end_line": 47,
"start_col": 0,
"start_line": 33
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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: LowParse.Spec.Base.parser k t ->
h: FStar.Monotonic.HyperStack.mem ->
s: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> Prims.Ghost Prims.bool | Prims.Ghost | [] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.op_AmpAmp",
"Prims.op_Negation",
"FStar.UInt32.gt",
"LowParse.Slice.__proj__Mkslice__item__len",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.consumed_length",
"LowParse.Slice.bytes_of_slice_from",
"LowParse.Spec.Base.parse",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_equiv",
"Prims.bool",
"LowParse.Slice.live_slice",
"Prims.l_iff",
"Prims.eq2",
"LowParse.Low.Base.Spec.valid"
] | [] | false | false | false | false | false | let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool (requires (live_slice h s)) (ensures (fun b -> b == true <==> valid p h s pos)) =
| valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos)) | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.serialized_length | val serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
))) | val serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
))) | let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x) | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 28,
"end_line": 105,
"start_col": 0,
"start_line": 91
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: LowParse.Spec.Base.serializer p -> x: t -> Prims.Ghost Prims.nat | Prims.Ghost | [] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.serialize",
"Prims.nat",
"Prims.l_True",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high",
"Prims.logical"
] | [] | false | false | false | false | false | let serialized_length (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (x: t)
: Ghost nat
(requires True)
(ensures
(fun res ->
k.parser_kind_low <= res /\
(match k.parser_kind_high with
| None -> True
| Some max -> res <= max))) =
| Seq.length (serialize s x) | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.gaccessor_prop | val gaccessor_prop
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: GTot Type0 | val gaccessor_prop
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: GTot Type0 | let gaccessor_prop
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: GTot Type0
= gaccessor_prop' f | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 19,
"end_line": 250,
"start_col": 0,
"start_line": 240
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x))
let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos)
let get_valid_pos_post
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (
let pos' = get_valid_pos p h sl pos in
valid_pos p h sl pos pos'
))
[SMTPat (get_valid_pos p h sl pos)]
= ()
let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
= valid_exact' p h s pos pos'
let valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
= assert_norm (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
let contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost t
(requires (valid_exact p h s pos pos'))
(ensures (fun _ -> True))
= valid_exact_equiv p h s pos pos' ;
contents_exact' p h s pos pos'
let contents_exact_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_exact p h s pos pos'))
(ensures (valid_exact p h s pos pos' /\ valid_exact' p h s pos pos' /\ contents_exact p h s pos pos' == contents_exact' p h s pos pos'))
= valid_exact_equiv p h s pos pos' ;
assert_norm (contents_exact p h s pos pos' == contents_exact' p h s pos pos') | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: LowParse.Low.Base.Spec.gaccessor' p1 p2 cl -> Prims.GTot Type0 | Prims.GTot | [
"sometrivial"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.Spec.clens",
"LowParse.Low.Base.Spec.gaccessor'",
"LowParse.Low.Base.Spec.gaccessor_prop'"
] | [] | false | false | false | false | true | let gaccessor_prop
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: GTot Type0 =
| gaccessor_prop' f | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.create_in_chacha20_poly1305 | val create_in_chacha20_poly1305:create_in_st CHACHA20_POLY1305 | val create_in_chacha20_poly1305:create_in_st CHACHA20_POLY1305 | let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 9,
"end_line": 115,
"start_col": 0,
"start_line": 107
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5" | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.QI.EAGER_THRESHOLD=5"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.AEAD.create_in_st Spec.Agile.AEAD.CHACHA20_POLY1305 | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.HyperHeap.rid",
"LowStar.Buffer.pointer",
"LowStar.Buffer.pointer_or_null",
"EverCrypt.AEAD.state_s",
"Spec.Agile.AEAD.CHACHA20_POLY1305",
"LowStar.Buffer.buffer",
"EverCrypt.CTR.Keys.uint8",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.Integers.op_Greater_Equals",
"FStar.Integers.Signed",
"FStar.Integers.Winfinite",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"Spec.Agile.AEAD.key_length",
"EverCrypt.Error.Success",
"Prims.unit",
"LowStar.Monotonic.Buffer.modifies_only_not_unused_in",
"LowStar.Monotonic.Buffer.loc_buffer",
"EverCrypt.Error.error_code",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowStar.Monotonic.Buffer.upd",
"FStar.UInt32.__uint_to_t",
"LowStar.Monotonic.Buffer.blit",
"FStar.UInt8.t",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.l_and",
"Prims.eq2",
"Prims.nat",
"FStar.UInt32.v",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Prims.op_Negation",
"LowStar.Monotonic.Buffer.g_is_null",
"LowStar.Monotonic.Buffer.frameOf",
"LowStar.Monotonic.Buffer.freeable",
"LowStar.Buffer.malloc",
"EverCrypt.AEAD.Ek",
"Spec.Cipher.Expansion.Hacl_CHACHA20",
"FStar.Ghost.hide",
"Spec.Agile.AEAD.kv",
"LowStar.Monotonic.Buffer.as_seq",
"FStar.UInt8.__uint_to_t"
] | [] | false | false | false | true | false | let create_in_chacha20_poly1305:create_in_st CHACHA20_POLY1305 =
| fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.content_length | val content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True)) | val content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True)) | let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 28,
"end_line": 89,
"start_col": 0,
"start_line": 77
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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: LowParse.Spec.Base.parser k t ->
h: FStar.Monotonic.HyperStack.mem ->
sl: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> Prims.Ghost Prims.nat | Prims.Ghost | [] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.Base.Spec.content_length'",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_equiv",
"Prims.nat",
"LowParse.Low.Base.Spec.valid",
"Prims.l_True"
] | [] | false | false | false | false | false | let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat (requires (valid p h sl pos)) (ensures (fun res -> True)) =
| valid_equiv p h sl pos;
content_length' p h sl pos | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.alloca_aes_gcm | val alloca_aes_gcm (i: vale_impl) : alloca_st (alg_of_vale_impl i) | val alloca_aes_gcm (i: vale_impl) : alloca_st (alg_of_vale_impl i) | let alloca_aes_gcm (i: vale_impl):
alloca_st (alg_of_vale_impl i) =
fun k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
let ek = B.alloca 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.alloca (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
p | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 189,
"start_col": 0,
"start_line": 178
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success
#pop-options
inline_for_extraction noextract
let create_in_aes_gcm (i: vale_impl):
create_in_st (alg_of_vale_impl i) =
fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale then (
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then (
let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success
) else
UnsupportedAlgorithm
) else
UnsupportedAlgorithm
let create_in_aes128_gcm: create_in_st AES128_GCM = create_in_aes_gcm Vale_AES128
let create_in_aes256_gcm: create_in_st AES256_GCM = create_in_aes_gcm Vale_AES256
let create_in #a r dst k =
match a with
| AES128_GCM -> create_in_aes128_gcm r dst k
| AES256_GCM -> create_in_aes256_gcm r dst k
| CHACHA20_POLY1305 -> create_in_chacha20_poly1305 r dst k
| _ -> UnsupportedAlgorithm
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
inline_for_extraction noextract
let alloca_chacha20_poly1305: alloca_st CHACHA20_POLY1305 =
fun k ->
let h0 = ST.get () in
let ek = B.alloca 0uy 32ul in
let p = B.alloca (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.loc_none h0 h3;
p
#pop-options | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: EverCrypt.CTR.Keys.vale_impl -> EverCrypt.AEAD.alloca_st (EverCrypt.AEAD.alg_of_vale_impl i) | Prims.Tot | [
"total"
] | [] | [
"EverCrypt.CTR.Keys.vale_impl",
"LowStar.Buffer.buffer",
"EverCrypt.CTR.Keys.uint8",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.Integers.op_Greater_Equals",
"FStar.Integers.Signed",
"FStar.Integers.Winfinite",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"Spec.Agile.AEAD.key_length",
"EverCrypt.AEAD.alg_of_vale_impl",
"LowStar.Buffer.pointer",
"EverCrypt.AEAD.state_s",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.l_and",
"Prims.eq2",
"Prims.nat",
"FStar.UInt32.v",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Prims.op_Negation",
"LowStar.Monotonic.Buffer.g_is_null",
"LowStar.Buffer.alloca",
"EverCrypt.AEAD.Ek",
"FStar.Ghost.hide",
"Spec.Agile.AEAD.kv",
"LowStar.Monotonic.Buffer.as_seq",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"LowStar.Monotonic.Buffer.modifies_only_not_unused_in",
"LowStar.Monotonic.Buffer.loc_none",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"EverCrypt.CTR.Keys.vale_expand",
"FStar.UInt32.add",
"EverCrypt.CTR.Keys.concrete_xkey_len",
"FStar.UInt8.__uint_to_t",
"FStar.Integers.op_Plus",
"FStar.Integers.Unsigned",
"FStar.Integers.W32",
"FStar.Ghost.erased",
"Spec.Agile.AEAD.alg",
"EverCrypt.AEAD.alloca_st"
] | [] | false | false | false | false | false | let alloca_aes_gcm (i: vale_impl) : alloca_st (alg_of_vale_impl i) =
| fun k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv:G.erased (kv a) = G.hide (B.as_seq h0 k) in
let ek = B.alloca 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.alloca (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
p | false |
Vale.AES.PPC64LE.GHash.fsti | Vale.AES.PPC64LE.GHash.va_quick_Ghash_buffer | val va_quick_Ghash_buffer (hkeys_b in_b: buffer128) (h_BE y_prev: quad32)
: (va_quickCode unit (va_code_Ghash_buffer ())) | val va_quick_Ghash_buffer (hkeys_b in_b: buffer128) (h_BE y_prev: quad32)
: (va_quickCode unit (va_code_Ghash_buffer ())) | let va_quick_Ghash_buffer (hkeys_b:buffer128) (in_b:buffer128) (h_BE:quad32) (y_prev:quad32) :
(va_quickCode unit (va_code_Ghash_buffer ())) =
(va_QProc (va_code_Ghash_buffer ()) ([va_Mod_cr0; va_Mod_vec 14; va_Mod_vec 13; va_Mod_vec 12;
va_Mod_vec 11; va_Mod_vec 10; va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 7; va_Mod_vec 6;
va_Mod_vec 5; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg
10; va_Mod_reg 6; va_Mod_reg 7]) (va_wp_Ghash_buffer hkeys_b in_b h_BE y_prev)
(va_wpProof_Ghash_buffer hkeys_b in_b h_BE y_prev)) | {
"file_name": "obj/Vale.AES.PPC64LE.GHash.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 334,
"start_col": 0,
"start_line": 328
} | module Vale.AES.PPC64LE.GHash
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.AES.AES_BE_s
open Vale.PPC64LE.Machine_s
open Vale.PPC64LE.Memory
open Vale.PPC64LE.State
open Vale.PPC64LE.Decls
open Vale.PPC64LE.InsBasic
open Vale.PPC64LE.InsMem
open Vale.PPC64LE.InsVector
open Vale.PPC64LE.QuickCode
open Vale.PPC64LE.QuickCodes
open Vale.AES.AES_helpers
open Vale.Poly1305.Math // For lemma_poly_bits64()
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.Arch.TypesNative
open Vale.AES.PPC64LE.PolyOps
open Vale.AES.PPC64LE.GF128_Mul
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Bits_s
open Vale.Math.Poly2.Bits
open Vale.Math.Poly2.Lemmas
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.AES.GHash_BE
#reset-options "--z3rlimit 50"
unfold let va_subscript_FStar__Seq__Base__seq = Seq.index
let hkeys_b_powers (hkeys_b:buffer128) (heap0:vale_heap) (layout:vale_heap_layout) (ptr:int) (h:poly) =
validSrcAddrs128 heap0 ptr hkeys_b 3 layout Secret /\
of_quad32 (reverse_bytes_quad32 (buffer128_read hkeys_b 0 heap0)) == gf128_power h 1 /\
of_quad32 (reverse_bytes_quad32 (buffer128_read hkeys_b 1 heap0)) == gf128_power h 2
let in_b_blocks
(in_b:buffer128) (in_index count:int) (heap_s:vale_heap) (layout:vale_heap_layout) (ptr:int) (data:seq quad32)
=
validSrcAddrsOffset128 heap_s ptr in_b in_index count layout Secret /\
(forall (i:nat).{:pattern (index data i)}
i < count /\ i < length data ==>
reverse_bytes_quad32 (buffer128_read in_b (in_index + i) heap_s) == index data i)
//-- ReduceLast
val va_code_ReduceLast : va_dummy:unit -> Tot va_code
val va_codegen_success_ReduceLast : va_dummy:unit -> Tot va_pbool
val va_lemma_ReduceLast : va_b0:va_code -> va_s0:va_state -> h_BE:quad32 -> y_prev:quad32 ->
data:(seq quad32)
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_ReduceLast ()) va_s0 /\ va_get_ok va_s0 /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in va_get_vec 8 va_s0 ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 3254779904 0 0 /\ n > 0 /\ add (add
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 2 va_s0)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 3 va_s0)) 64)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 4 va_s0)) 128) ==
Vale.AES.GHash_BE.ghash_unroll_back h prev pdata 0 n (n - 1))))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in let xi =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_sM) in Vale.Math.Poly2.Bits_s.to_quad32 xi ==
Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data /\ xi == Vale.Math.Poly2.Bits_s.of_quad32
(Vale.Math.Poly2.Bits_s.to_quad32 xi)) /\ va_state_eq va_sM (va_update_vec 10 va_sM
(va_update_vec 9 va_sM (va_update_vec 8 va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM
(va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0 va_sM (va_update_ok va_sM
va_s0)))))))))))
[@ va_qattr]
let va_wp_ReduceLast (h_BE:quad32) (y_prev:quad32) (data:(seq quad32)) (va_s0:va_state)
(va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in
let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in va_get_vec 8 va_s0 ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 3254779904 0 0 /\ n > 0 /\ add (add
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 2 va_s0)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 3 va_s0)) 64)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 4 va_s0)) 128) ==
Vale.AES.GHash_BE.ghash_unroll_back h prev pdata 0 n (n - 1)) /\ (forall (va_x_v0:quad32)
(va_x_v1:quad32) (va_x_v2:quad32) (va_x_v3:quad32) (va_x_v4:quad32) (va_x_v8:quad32)
(va_x_v9:quad32) (va_x_v10:quad32) . let va_sM = va_upd_vec 10 va_x_v10 (va_upd_vec 9 va_x_v9
(va_upd_vec 8 va_x_v8 (va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2
(va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 va_s0))))))) in va_get_ok va_sM /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in let xi =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_sM) in Vale.Math.Poly2.Bits_s.to_quad32 xi ==
Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data /\ xi == Vale.Math.Poly2.Bits_s.of_quad32
(Vale.Math.Poly2.Bits_s.to_quad32 xi)) ==> va_k va_sM (())))
val va_wpProof_ReduceLast : h_BE:quad32 -> y_prev:quad32 -> data:(seq quad32) -> va_s0:va_state ->
va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_ReduceLast h_BE y_prev data va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_ReduceLast ()) ([va_Mod_vec 10;
va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec
0]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_ReduceLast (h_BE:quad32) (y_prev:quad32) (data:(seq quad32)) : (va_quickCode unit
(va_code_ReduceLast ())) =
(va_QProc (va_code_ReduceLast ()) ([va_Mod_vec 10; va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 4;
va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0]) (va_wp_ReduceLast h_BE y_prev data)
(va_wpProof_ReduceLast h_BE y_prev data))
//--
//-- GhashUnroll_n
val va_code_GhashUnroll_n : exactly2:bool -> Tot va_code
val va_codegen_success_GhashUnroll_n : exactly2:bool -> Tot va_pbool
val va_lemma_GhashUnroll_n : va_b0:va_code -> va_s0:va_state -> exactly2:bool -> in_b:buffer128 ->
index:nat -> h_BE:quad32 -> y_prev:quad32 -> data:(seq quad32)
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_GhashUnroll_n exactly2) va_s0 /\ va_get_ok va_s0 /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in (exactly2 ==> n == 2) /\
(~exactly2 ==> n == 1) /\ in_b_blocks in_b index n (va_get_mem_heaplet 1 va_s0)
(va_get_mem_layout va_s0) (va_get_reg 7 va_s0) data /\ Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 1 va_s0) == prev /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 5 va_s0) ==
Vale.Math.Poly2.swap (Vale.AES.GHash_BE.gf128_power h 1) 64 /\ Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 6 va_s0) == Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.div
(Vale.AES.GHash_BE.gf128_power h 1) (Vale.Math.Poly2_s.monomial 64))
(Vale.Math.Poly2_s.monomial 64) /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 7 va_s0) ==
Vale.Math.Poly2_s.mod (Vale.AES.GHash_BE.gf128_power h 1) (Vale.Math.Poly2_s.monomial 64) /\
(exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 12 va_s0) == Vale.Math.Poly2.swap
(Vale.AES.GHash_BE.gf128_power h 2) 64) /\ (exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 13 va_s0) == Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.div
(Vale.AES.GHash_BE.gf128_power h 2) (Vale.Math.Poly2_s.monomial 64))
(Vale.Math.Poly2_s.monomial 64)) /\ (exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec
14 va_s0) == Vale.Math.Poly2_s.mod (Vale.AES.GHash_BE.gf128_power h 2)
(Vale.Math.Poly2_s.monomial 64)))))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in va_get_vec 1 va_sM ==
Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data) /\ va_state_eq va_sM (va_update_vec 11
va_sM (va_update_vec 10 va_sM (va_update_vec 9 va_sM (va_update_vec 8 va_sM (va_update_vec 4
va_sM (va_update_vec 3 va_sM (va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0
va_sM (va_update_reg 10 va_sM (va_update_ok va_sM va_s0)))))))))))))
[@ va_qattr]
let va_wp_GhashUnroll_n (exactly2:bool) (in_b:buffer128) (index:nat) (h_BE:quad32) (y_prev:quad32)
(data:(seq quad32)) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in
let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in (exactly2 ==> n == 2) /\
(~exactly2 ==> n == 1) /\ in_b_blocks in_b index n (va_get_mem_heaplet 1 va_s0)
(va_get_mem_layout va_s0) (va_get_reg 7 va_s0) data /\ Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 1 va_s0) == prev /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 5 va_s0) ==
Vale.Math.Poly2.swap (Vale.AES.GHash_BE.gf128_power h 1) 64 /\ Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 6 va_s0) == Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.div
(Vale.AES.GHash_BE.gf128_power h 1) (Vale.Math.Poly2_s.monomial 64))
(Vale.Math.Poly2_s.monomial 64) /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 7 va_s0) ==
Vale.Math.Poly2_s.mod (Vale.AES.GHash_BE.gf128_power h 1) (Vale.Math.Poly2_s.monomial 64) /\
(exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 12 va_s0) == Vale.Math.Poly2.swap
(Vale.AES.GHash_BE.gf128_power h 2) 64) /\ (exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32
(va_get_vec 13 va_s0) == Vale.Math.Poly2_s.mul (Vale.Math.Poly2_s.div
(Vale.AES.GHash_BE.gf128_power h 2) (Vale.Math.Poly2_s.monomial 64))
(Vale.Math.Poly2_s.monomial 64)) /\ (exactly2 ==> Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec
14 va_s0) == Vale.Math.Poly2_s.mod (Vale.AES.GHash_BE.gf128_power h 2)
(Vale.Math.Poly2_s.monomial 64))) /\ (forall (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32)
(va_x_v2:quad32) (va_x_v3:quad32) (va_x_v4:quad32) (va_x_v8:quad32) (va_x_v9:quad32)
(va_x_v10:quad32) (va_x_v11:quad32) . let va_sM = va_upd_vec 11 va_x_v11 (va_upd_vec 10
va_x_v10 (va_upd_vec 9 va_x_v9 (va_upd_vec 8 va_x_v8 (va_upd_vec 4 va_x_v4 (va_upd_vec 3
va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 (va_upd_reg 10
va_x_r10 va_s0))))))))) in va_get_ok va_sM /\ (let (h:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let (prev:Vale.Math.Poly2_s.poly) =
Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let (pdata:(Prims.int -> Vale.AES.GHash_BE.poly128))
= Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128 data in let (n:Prims.nat) = FStar.Seq.Base.length
#quad32 data in va_get_vec 1 va_sM == Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data) ==>
va_k va_sM (())))
val va_wpProof_GhashUnroll_n : exactly2:bool -> in_b:buffer128 -> index:nat -> h_BE:quad32 ->
y_prev:quad32 -> data:(seq quad32) -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_GhashUnroll_n exactly2 in_b index h_BE y_prev data va_s0
va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_GhashUnroll_n exactly2) ([va_Mod_vec
11; va_Mod_vec 10; va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2;
va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_GhashUnroll_n (exactly2:bool) (in_b:buffer128) (index:nat) (h_BE:quad32)
(y_prev:quad32) (data:(seq quad32)) : (va_quickCode unit (va_code_GhashUnroll_n exactly2)) =
(va_QProc (va_code_GhashUnroll_n exactly2) ([va_Mod_vec 11; va_Mod_vec 10; va_Mod_vec 9;
va_Mod_vec 8; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg
10]) (va_wp_GhashUnroll_n exactly2 in_b index h_BE y_prev data) (va_wpProof_GhashUnroll_n
exactly2 in_b index h_BE y_prev data))
//--
//-- Ghash_register
val va_code_Ghash_register : va_dummy:unit -> Tot va_code
val va_codegen_success_Ghash_register : va_dummy:unit -> Tot va_pbool
val va_lemma_Ghash_register : va_b0:va_code -> va_s0:va_state -> hkeys_b:buffer128 -> h_BE:quad32
-> y_prev:quad32
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Ghash_register ()) va_s0 /\ va_get_ok va_s0 /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(data:(FStar.Seq.Base.seq quad32)) = FStar.Seq.Base.create #quad32 1 (va_get_vec 9 va_s0) in
let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in hkeys_b_powers hkeys_b (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0)
(va_get_reg 5 va_s0) h /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_s0) == prev)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(data:(FStar.Seq.Base.seq quad32)) = FStar.Seq.Base.create #quad32 1 (va_get_vec 9 va_s0) in
let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in va_get_vec 1 va_sM == Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data) /\
va_state_eq va_sM (va_update_vec 10 va_sM (va_update_vec 9 va_sM (va_update_vec 8 va_sM
(va_update_vec 7 va_sM (va_update_vec 6 va_sM (va_update_vec 5 va_sM (va_update_vec 4 va_sM
(va_update_vec 3 va_sM (va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0 va_sM
(va_update_reg 10 va_sM (va_update_ok va_sM va_s0)))))))))))))))
[@ va_qattr]
let va_wp_Ghash_register (hkeys_b:buffer128) (h_BE:quad32) (y_prev:quad32) (va_s0:va_state)
(va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in
let (data:(FStar.Seq.Base.seq quad32)) = FStar.Seq.Base.create #quad32 1 (va_get_vec 9 va_s0)
in let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in hkeys_b_powers hkeys_b (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0)
(va_get_reg 5 va_s0) h /\ Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_s0) == prev) /\
(forall (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32) (va_x_v2:quad32) (va_x_v3:quad32)
(va_x_v4:quad32) (va_x_v5:quad32) (va_x_v6:quad32) (va_x_v7:quad32) (va_x_v8:quad32)
(va_x_v9:quad32) (va_x_v10:quad32) . let va_sM = va_upd_vec 10 va_x_v10 (va_upd_vec 9 va_x_v9
(va_upd_vec 8 va_x_v8 (va_upd_vec 7 va_x_v7 (va_upd_vec 6 va_x_v6 (va_upd_vec 5 va_x_v5
(va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1
(va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 va_s0))))))))))) in va_get_ok va_sM /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(data:(FStar.Seq.Base.seq quad32)) = FStar.Seq.Base.create #quad32 1 (va_get_vec 9 va_s0) in
let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in va_get_vec 1 va_sM == Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data) ==> va_k
va_sM (())))
val va_wpProof_Ghash_register : hkeys_b:buffer128 -> h_BE:quad32 -> y_prev:quad32 -> va_s0:va_state
-> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Ghash_register hkeys_b h_BE y_prev va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Ghash_register ()) ([va_Mod_vec 10;
va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 7; va_Mod_vec 6; va_Mod_vec 5; va_Mod_vec 4; va_Mod_vec
3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_Ghash_register (hkeys_b:buffer128) (h_BE:quad32) (y_prev:quad32) : (va_quickCode unit
(va_code_Ghash_register ())) =
(va_QProc (va_code_Ghash_register ()) ([va_Mod_vec 10; va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 7;
va_Mod_vec 6; va_Mod_vec 5; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec
0; va_Mod_reg 10]) (va_wp_Ghash_register hkeys_b h_BE y_prev) (va_wpProof_Ghash_register
hkeys_b h_BE y_prev))
//--
//-- Ghash_buffer
val va_code_Ghash_buffer : va_dummy:unit -> Tot va_code
val va_codegen_success_Ghash_buffer : va_dummy:unit -> Tot va_pbool
val va_lemma_Ghash_buffer : va_b0:va_code -> va_s0:va_state -> hkeys_b:buffer128 -> in_b:buffer128
-> h_BE:quad32 -> y_prev:quad32
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Ghash_buffer ()) va_s0 /\ va_get_ok va_s0 /\ (let
(h:poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in hkeys_b_powers hkeys_b (va_get_mem_heaplet
0 va_s0) (va_get_mem_layout va_s0) (va_get_reg 5 va_s0) h /\
Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 7 va_s0) in_b
(va_get_reg 6 va_s0) (va_get_mem_layout va_s0) Secret /\ Vale.PPC64LE.Decls.buffer_length
#Vale.PPC64LE.Memory.vuint128 in_b == va_get_reg 6 va_s0 /\ va_get_reg 7 va_s0 + 16
`op_Multiply` va_get_reg 6 va_s0 < pow2_64 /\ va_get_vec 1 va_s0 == y_prev)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in va_get_vec 1 va_sM ==
Vale.AES.GHash_BE.ghash_incremental0 h_BE y_prev (Vale.Arch.Types.reverse_bytes_quad32_seq
(Vale.PPC64LE.Decls.s128 (va_get_mem_heaplet 1 va_sM) in_b)) /\ (va_get_reg 6 va_s0 == 0 ==>
va_get_vec 1 va_sM == va_get_vec 1 va_s0)) /\ va_state_eq va_sM (va_update_cr0 va_sM
(va_update_vec 14 va_sM (va_update_vec 13 va_sM (va_update_vec 12 va_sM (va_update_vec 11 va_sM
(va_update_vec 10 va_sM (va_update_vec 9 va_sM (va_update_vec 8 va_sM (va_update_vec 7 va_sM
(va_update_vec 6 va_sM (va_update_vec 5 va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM
(va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM
(va_update_reg 6 va_sM (va_update_reg 7 va_sM (va_update_ok va_sM va_s0))))))))))))))))))))))
[@ va_qattr]
let va_wp_Ghash_buffer (hkeys_b:buffer128) (in_b:buffer128) (h_BE:quad32) (y_prev:quad32)
(va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in hkeys_b_powers
hkeys_b (va_get_mem_heaplet 0 va_s0) (va_get_mem_layout va_s0) (va_get_reg 5 va_s0) h /\
Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 7 va_s0) in_b
(va_get_reg 6 va_s0) (va_get_mem_layout va_s0) Secret /\ Vale.PPC64LE.Decls.buffer_length
#Vale.PPC64LE.Memory.vuint128 in_b == va_get_reg 6 va_s0 /\ va_get_reg 7 va_s0 + 16
`op_Multiply` va_get_reg 6 va_s0 < pow2_64 /\ va_get_vec 1 va_s0 == y_prev) /\ (forall
(va_x_r7:nat64) (va_x_r6:nat64) (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32)
(va_x_v2:quad32) (va_x_v3:quad32) (va_x_v4:quad32) (va_x_v5:quad32) (va_x_v6:quad32)
(va_x_v7:quad32) (va_x_v8:quad32) (va_x_v9:quad32) (va_x_v10:quad32) (va_x_v11:quad32)
(va_x_v12:quad32) (va_x_v13:quad32) (va_x_v14:quad32) (va_x_cr0:cr0_t) . let va_sM = va_upd_cr0
va_x_cr0 (va_upd_vec 14 va_x_v14 (va_upd_vec 13 va_x_v13 (va_upd_vec 12 va_x_v12 (va_upd_vec 11
va_x_v11 (va_upd_vec 10 va_x_v10 (va_upd_vec 9 va_x_v9 (va_upd_vec 8 va_x_v8 (va_upd_vec 7
va_x_v7 (va_upd_vec 6 va_x_v6 (va_upd_vec 5 va_x_v5 (va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3
(va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10
(va_upd_reg 6 va_x_r6 (va_upd_reg 7 va_x_r7 va_s0)))))))))))))))))) in va_get_ok va_sM /\ (let
(h:poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in va_get_vec 1 va_sM ==
Vale.AES.GHash_BE.ghash_incremental0 h_BE y_prev (Vale.Arch.Types.reverse_bytes_quad32_seq
(Vale.PPC64LE.Decls.s128 (va_get_mem_heaplet 1 va_sM) in_b)) /\ (va_get_reg 6 va_s0 == 0 ==>
va_get_vec 1 va_sM == va_get_vec 1 va_s0)) ==> va_k va_sM (())))
val va_wpProof_Ghash_buffer : hkeys_b:buffer128 -> in_b:buffer128 -> h_BE:quad32 -> y_prev:quad32
-> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Ghash_buffer hkeys_b in_b h_BE y_prev va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Ghash_buffer ()) ([va_Mod_cr0;
va_Mod_vec 14; va_Mod_vec 13; va_Mod_vec 12; va_Mod_vec 11; va_Mod_vec 10; va_Mod_vec 9;
va_Mod_vec 8; va_Mod_vec 7; va_Mod_vec 6; va_Mod_vec 5; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec
2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10; va_Mod_reg 6; va_Mod_reg 7]) va_s0 va_k ((va_sM,
va_f0, va_g)))) | {
"checked_file": "/",
"dependencies": [
"Vale.PPC64LE.State.fsti.checked",
"Vale.PPC64LE.QuickCodes.fsti.checked",
"Vale.PPC64LE.QuickCode.fst.checked",
"Vale.PPC64LE.Memory.fsti.checked",
"Vale.PPC64LE.Machine_s.fst.checked",
"Vale.PPC64LE.InsVector.fsti.checked",
"Vale.PPC64LE.InsMem.fsti.checked",
"Vale.PPC64LE.InsBasic.fsti.checked",
"Vale.PPC64LE.Decls.fsti.checked",
"Vale.Poly1305.Math.fsti.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Lemmas.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Math.Poly2.Bits.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.AES.PPC64LE.PolyOps.fsti.checked",
"Vale.AES.PPC64LE.GF128_Mul.fsti.checked",
"Vale.AES.GHash_BE.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.fsti.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.AES_helpers.fsti.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.PPC64LE.GHash.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math // For lemma_poly_bits64()",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
hkeys_b: Vale.PPC64LE.Memory.buffer128 ->
in_b: Vale.PPC64LE.Memory.buffer128 ->
h_BE: Vale.PPC64LE.Memory.quad32 ->
y_prev: Vale.PPC64LE.Memory.quad32
-> Vale.PPC64LE.QuickCode.va_quickCode Prims.unit (Vale.AES.PPC64LE.GHash.va_code_Ghash_buffer ()) | Prims.Tot | [
"total"
] | [] | [
"Vale.PPC64LE.Memory.buffer128",
"Vale.PPC64LE.Memory.quad32",
"Vale.PPC64LE.QuickCode.va_QProc",
"Prims.unit",
"Vale.AES.PPC64LE.GHash.va_code_Ghash_buffer",
"Prims.Cons",
"Vale.PPC64LE.QuickCode.mod_t",
"Vale.PPC64LE.QuickCode.va_Mod_cr0",
"Vale.PPC64LE.QuickCode.va_Mod_vec",
"Vale.PPC64LE.QuickCode.va_Mod_reg",
"Prims.Nil",
"Vale.AES.PPC64LE.GHash.va_wp_Ghash_buffer",
"Vale.AES.PPC64LE.GHash.va_wpProof_Ghash_buffer",
"Vale.PPC64LE.QuickCode.va_quickCode"
] | [] | false | false | false | false | false | let va_quick_Ghash_buffer (hkeys_b in_b: buffer128) (h_BE y_prev: quad32)
: (va_quickCode unit (va_code_Ghash_buffer ())) =
| (va_QProc (va_code_Ghash_buffer ())
([
va_Mod_cr0; va_Mod_vec 14; va_Mod_vec 13; va_Mod_vec 12; va_Mod_vec 11; va_Mod_vec 10;
va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 7; va_Mod_vec 6; va_Mod_vec 5; va_Mod_vec 4;
va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10; va_Mod_reg 6;
va_Mod_reg 7
])
(va_wp_Ghash_buffer hkeys_b in_b h_BE y_prev)
(va_wpProof_Ghash_buffer hkeys_b in_b h_BE y_prev)) | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.get_valid_pos | val get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True)) | val get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True)) | let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos) | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 57,
"end_line": 166,
"start_col": 0,
"start_line": 155
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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: LowParse.Spec.Base.parser k t ->
h: FStar.Monotonic.HyperStack.mem ->
sl: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> Prims.Ghost FStar.UInt32.t | Prims.Ghost | [] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.UInt32.add",
"FStar.UInt32.uint_to_t",
"LowParse.Low.Base.Spec.content_length",
"LowParse.Low.Base.Spec.valid",
"Prims.l_True"
] | [] | false | false | false | false | false | let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t (requires (valid p h sl pos)) (ensures (fun pos' -> True)) =
| pos `U32.add` (U32.uint_to_t (content_length p h sl pos)) | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.contents_eq | val contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos)) | val contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos)) | let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos) | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 57,
"end_line": 75,
"start_col": 0,
"start_line": 63
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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: LowParse.Spec.Base.parser k t ->
h: FStar.Monotonic.HyperStack.mem ->
s: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> FStar.Pervasives.Lemma (requires LowParse.Low.Base.Spec.valid p h s pos)
(ensures
LowParse.Low.Base.Spec.valid p h s pos /\ LowParse.Low.Base.Spec.valid' p h s pos /\
LowParse.Low.Base.Spec.contents p h s pos == LowParse.Low.Base.Spec.contents' p h s pos) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"LowParse.Low.Base.Spec.contents",
"LowParse.Low.Base.Spec.contents'",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_equiv",
"LowParse.Low.Base.Spec.valid",
"Prims.squash",
"Prims.l_and",
"LowParse.Low.Base.Spec.valid'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos)) =
| valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos) | false |
Vale.AES.PPC64LE.GHash.fsti | Vale.AES.PPC64LE.GHash.va_quick_ReduceLast | val va_quick_ReduceLast (h_BE y_prev: quad32) (data: (seq quad32))
: (va_quickCode unit (va_code_ReduceLast ())) | val va_quick_ReduceLast (h_BE y_prev: quad32) (data: (seq quad32))
: (va_quickCode unit (va_code_ReduceLast ())) | let va_quick_ReduceLast (h_BE:quad32) (y_prev:quad32) (data:(seq quad32)) : (va_quickCode unit
(va_code_ReduceLast ())) =
(va_QProc (va_code_ReduceLast ()) ([va_Mod_vec 10; va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 4;
va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0]) (va_wp_ReduceLast h_BE y_prev data)
(va_wpProof_ReduceLast h_BE y_prev data)) | {
"file_name": "obj/Vale.AES.PPC64LE.GHash.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 117,
"start_col": 0,
"start_line": 113
} | module Vale.AES.PPC64LE.GHash
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.Arch.Types
open Vale.Arch.HeapImpl
open Vale.AES.AES_BE_s
open Vale.PPC64LE.Machine_s
open Vale.PPC64LE.Memory
open Vale.PPC64LE.State
open Vale.PPC64LE.Decls
open Vale.PPC64LE.InsBasic
open Vale.PPC64LE.InsMem
open Vale.PPC64LE.InsVector
open Vale.PPC64LE.QuickCode
open Vale.PPC64LE.QuickCodes
open Vale.AES.AES_helpers
open Vale.Poly1305.Math // For lemma_poly_bits64()
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.Arch.TypesNative
open Vale.AES.PPC64LE.PolyOps
open Vale.AES.PPC64LE.GF128_Mul
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Bits_s
open Vale.Math.Poly2.Bits
open Vale.Math.Poly2.Lemmas
open Vale.AES.GF128_s
open Vale.AES.GF128
open Vale.AES.GHash_BE
#reset-options "--z3rlimit 50"
unfold let va_subscript_FStar__Seq__Base__seq = Seq.index
let hkeys_b_powers (hkeys_b:buffer128) (heap0:vale_heap) (layout:vale_heap_layout) (ptr:int) (h:poly) =
validSrcAddrs128 heap0 ptr hkeys_b 3 layout Secret /\
of_quad32 (reverse_bytes_quad32 (buffer128_read hkeys_b 0 heap0)) == gf128_power h 1 /\
of_quad32 (reverse_bytes_quad32 (buffer128_read hkeys_b 1 heap0)) == gf128_power h 2
let in_b_blocks
(in_b:buffer128) (in_index count:int) (heap_s:vale_heap) (layout:vale_heap_layout) (ptr:int) (data:seq quad32)
=
validSrcAddrsOffset128 heap_s ptr in_b in_index count layout Secret /\
(forall (i:nat).{:pattern (index data i)}
i < count /\ i < length data ==>
reverse_bytes_quad32 (buffer128_read in_b (in_index + i) heap_s) == index data i)
//-- ReduceLast
val va_code_ReduceLast : va_dummy:unit -> Tot va_code
val va_codegen_success_ReduceLast : va_dummy:unit -> Tot va_pbool
val va_lemma_ReduceLast : va_b0:va_code -> va_s0:va_state -> h_BE:quad32 -> y_prev:quad32 ->
data:(seq quad32)
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_ReduceLast ()) va_s0 /\ va_get_ok va_s0 /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in va_get_vec 8 va_s0 ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 3254779904 0 0 /\ n > 0 /\ add (add
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 2 va_s0)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 3 va_s0)) 64)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 4 va_s0)) 128) ==
Vale.AES.GHash_BE.ghash_unroll_back h prev pdata 0 n (n - 1))))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in let xi =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_sM) in Vale.Math.Poly2.Bits_s.to_quad32 xi ==
Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data /\ xi == Vale.Math.Poly2.Bits_s.of_quad32
(Vale.Math.Poly2.Bits_s.to_quad32 xi)) /\ va_state_eq va_sM (va_update_vec 10 va_sM
(va_update_vec 9 va_sM (va_update_vec 8 va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM
(va_update_vec 2 va_sM (va_update_vec 1 va_sM (va_update_vec 0 va_sM (va_update_ok va_sM
va_s0)))))))))))
[@ va_qattr]
let va_wp_ReduceLast (h_BE:quad32) (y_prev:quad32) (data:(seq quad32)) (va_s0:va_state)
(va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in
let (prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in va_get_vec 8 va_s0 ==
Vale.Def.Words_s.Mkfour #Vale.Def.Types_s.nat32 0 3254779904 0 0 /\ n > 0 /\ add (add
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 2 va_s0)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 3 va_s0)) 64)) (Vale.Math.Poly2_s.shift
(Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 4 va_s0)) 128) ==
Vale.AES.GHash_BE.ghash_unroll_back h prev pdata 0 n (n - 1)) /\ (forall (va_x_v0:quad32)
(va_x_v1:quad32) (va_x_v2:quad32) (va_x_v3:quad32) (va_x_v4:quad32) (va_x_v8:quad32)
(va_x_v9:quad32) (va_x_v10:quad32) . let va_sM = va_upd_vec 10 va_x_v10 (va_upd_vec 9 va_x_v9
(va_upd_vec 8 va_x_v8 (va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2
(va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 va_s0))))))) in va_get_ok va_sM /\ (let
(h:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 h_BE in let
(prev:Vale.Math.Poly2_s.poly) = Vale.Math.Poly2.Bits_s.of_quad32 y_prev in let
(pdata:(Prims.int -> Vale.AES.GHash_BE.poly128)) = Vale.AES.GHash_BE.fun_seq_quad32_BE_poly128
data in let (n:Prims.nat) = FStar.Seq.Base.length #quad32 data in let xi =
Vale.Math.Poly2.Bits_s.of_quad32 (va_get_vec 1 va_sM) in Vale.Math.Poly2.Bits_s.to_quad32 xi ==
Vale.AES.GHash_BE.ghash_incremental h_BE y_prev data /\ xi == Vale.Math.Poly2.Bits_s.of_quad32
(Vale.Math.Poly2.Bits_s.to_quad32 xi)) ==> va_k va_sM (())))
val va_wpProof_ReduceLast : h_BE:quad32 -> y_prev:quad32 -> data:(seq quad32) -> va_s0:va_state ->
va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_ReduceLast h_BE y_prev data va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_ReduceLast ()) ([va_Mod_vec 10;
va_Mod_vec 9; va_Mod_vec 8; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec
0]) va_s0 va_k ((va_sM, va_f0, va_g)))) | {
"checked_file": "/",
"dependencies": [
"Vale.PPC64LE.State.fsti.checked",
"Vale.PPC64LE.QuickCodes.fsti.checked",
"Vale.PPC64LE.QuickCode.fst.checked",
"Vale.PPC64LE.Memory.fsti.checked",
"Vale.PPC64LE.Machine_s.fst.checked",
"Vale.PPC64LE.InsVector.fsti.checked",
"Vale.PPC64LE.InsMem.fsti.checked",
"Vale.PPC64LE.InsBasic.fsti.checked",
"Vale.PPC64LE.Decls.fsti.checked",
"Vale.Poly1305.Math.fsti.checked",
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Lemmas.fsti.checked",
"Vale.Math.Poly2.Bits_s.fsti.checked",
"Vale.Math.Poly2.Bits.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"Vale.AES.PPC64LE.PolyOps.fsti.checked",
"Vale.AES.PPC64LE.GF128_Mul.fsti.checked",
"Vale.AES.GHash_BE.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"Vale.AES.GF128.fsti.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.AES_helpers.fsti.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.PPC64LE.GHash.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math // For lemma_poly_bits64()",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Bits_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE.GF128_Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE.PolyOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h_BE: Vale.PPC64LE.Memory.quad32 ->
y_prev: Vale.PPC64LE.Memory.quad32 ->
data: FStar.Seq.Base.seq Vale.PPC64LE.Memory.quad32
-> Vale.PPC64LE.QuickCode.va_quickCode Prims.unit (Vale.AES.PPC64LE.GHash.va_code_ReduceLast ()) | Prims.Tot | [
"total"
] | [] | [
"Vale.PPC64LE.Memory.quad32",
"FStar.Seq.Base.seq",
"Vale.PPC64LE.QuickCode.va_QProc",
"Prims.unit",
"Vale.AES.PPC64LE.GHash.va_code_ReduceLast",
"Prims.Cons",
"Vale.PPC64LE.QuickCode.mod_t",
"Vale.PPC64LE.QuickCode.va_Mod_vec",
"Prims.Nil",
"Vale.AES.PPC64LE.GHash.va_wp_ReduceLast",
"Vale.AES.PPC64LE.GHash.va_wpProof_ReduceLast",
"Vale.PPC64LE.QuickCode.va_quickCode"
] | [] | false | false | false | false | false | let va_quick_ReduceLast (h_BE y_prev: quad32) (data: (seq quad32))
: (va_quickCode unit (va_code_ReduceLast ())) =
| (va_QProc (va_code_ReduceLast ())
([
va_Mod_vec 10;
va_Mod_vec 9;
va_Mod_vec 8;
va_Mod_vec 4;
va_Mod_vec 3;
va_Mod_vec 2;
va_Mod_vec 1;
va_Mod_vec 0
])
(va_wp_ReduceLast h_BE y_prev data)
(va_wpProof_ReduceLast h_BE y_prev data)) | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.contents | val contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True)) | val contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True)) | let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 21,
"end_line": 61,
"start_col": 0,
"start_line": 49
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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: LowParse.Spec.Base.parser k t ->
h: FStar.Monotonic.HyperStack.mem ->
s: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> Prims.Ghost t | Prims.Ghost | [] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.Base.Spec.contents'",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_equiv",
"LowParse.Low.Base.Spec.valid",
"Prims.l_True"
] | [] | false | false | false | false | false | let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t (requires (valid p h s pos)) (ensures (fun _ -> True)) =
| valid_equiv p h s pos;
contents' p h s pos | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.valid_equiv | val valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos) | val valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos) | let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos) | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 53,
"end_line": 31,
"start_col": 0,
"start_line": 21
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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: LowParse.Spec.Base.parser k t ->
h: FStar.Monotonic.HyperStack.mem ->
s: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> FStar.Pervasives.Lemma
(ensures LowParse.Low.Base.Spec.valid p h s pos <==> LowParse.Low.Base.Spec.valid' p h s pos) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.Pervasives.assert_norm",
"Prims.l_iff",
"LowParse.Low.Base.Spec.valid",
"LowParse.Low.Base.Spec.valid'",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma (valid p h s pos <==> valid' p h s pos) =
| assert_norm (valid p h s pos <==> valid' p h s pos) | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.content_length_eq_gen | val content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos)) | val content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos)) | let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos) | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 71,
"end_line": 129,
"start_col": 0,
"start_line": 117
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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: LowParse.Spec.Base.parser k t ->
h: FStar.Monotonic.HyperStack.mem ->
sl: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> FStar.Pervasives.Lemma (requires LowParse.Low.Base.Spec.valid p h sl pos)
(ensures
LowParse.Low.Base.Spec.valid p h sl pos /\ LowParse.Low.Base.Spec.valid' p h sl pos /\
LowParse.Low.Base.Spec.content_length p h sl pos ==
LowParse.Low.Base.Spec.content_length' p h sl pos) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.nat",
"LowParse.Low.Base.Spec.content_length",
"LowParse.Low.Base.Spec.content_length'",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_equiv",
"LowParse.Low.Base.Spec.valid",
"Prims.squash",
"Prims.l_and",
"LowParse.Low.Base.Spec.valid'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid p h sl pos))
(ensures
(valid p h sl pos /\ valid' p h sl pos /\
content_length p h sl pos == content_length' p h sl pos)) =
| valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos) | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.decrypt | val decrypt: #a:G.erased supported_alg -> decrypt_st (G.reveal a) | val decrypt: #a:G.erased supported_alg -> decrypt_st (G.reveal a) | let decrypt #a s iv iv_len ad ad_len cipher cipher_len tag dst =
if B.is_null s then
InvalidKey
else
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
match i with
| Vale_AES128 ->
decrypt_aes128_gcm () s iv iv_len ad ad_len cipher cipher_len tag dst
| Vale_AES256 ->
decrypt_aes256_gcm () s iv iv_len ad ad_len cipher cipher_len tag dst
| Hacl_CHACHA20 ->
decrypt_chacha20_poly1305 s iv iv_len ad ad_len cipher cipher_len tag dst | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 81,
"end_line": 618,
"start_col": 0,
"start_line": 606
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success
#pop-options
inline_for_extraction noextract
let create_in_aes_gcm (i: vale_impl):
create_in_st (alg_of_vale_impl i) =
fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale then (
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then (
let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success
) else
UnsupportedAlgorithm
) else
UnsupportedAlgorithm
let create_in_aes128_gcm: create_in_st AES128_GCM = create_in_aes_gcm Vale_AES128
let create_in_aes256_gcm: create_in_st AES256_GCM = create_in_aes_gcm Vale_AES256
let create_in #a r dst k =
match a with
| AES128_GCM -> create_in_aes128_gcm r dst k
| AES256_GCM -> create_in_aes256_gcm r dst k
| CHACHA20_POLY1305 -> create_in_chacha20_poly1305 r dst k
| _ -> UnsupportedAlgorithm
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
inline_for_extraction noextract
let alloca_chacha20_poly1305: alloca_st CHACHA20_POLY1305 =
fun k ->
let h0 = ST.get () in
let ek = B.alloca 0uy 32ul in
let p = B.alloca (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.loc_none h0 h3;
p
#pop-options
inline_for_extraction noextract
let alloca_aes_gcm (i: vale_impl):
alloca_st (alg_of_vale_impl i) =
fun k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
let ek = B.alloca 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.alloca (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
p
inline_for_extraction noextract
let alloca_aes128_gcm: alloca_st AES128_GCM =
alloca_aes_gcm Vale_AES128
inline_for_extraction noextract
let alloca_aes256_gcm: alloca_st AES256_GCM =
alloca_aes_gcm Vale_AES256
let alloca #a k =
match a with
| AES128_GCM -> alloca_aes128_gcm k
| AES256_GCM -> alloca_aes256_gcm k
| CHACHA20_POLY1305 -> alloca_chacha20_poly1305 k
inline_for_extraction noextract
let aes_gcm_encrypt (i: vale_impl):
Vale.Wrapper.X64.GCMencryptOpt.encrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMencryptOpt.gcm128_encrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMencryptOpt256.gcm256_encrypt_opt_stdcall
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties.slice_slice'"
inline_for_extraction noextract
let encrypt_aes_gcm (i: vale_impl): encrypt_st (alg_of_vale_impl i) =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if B.is_null s then
InvalidKey
else
let a = alg_of_vale_impl i in
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len = 0ul then
InvalidIVLength
else
let open LowStar.BufferOps in
let Ek _ kv ek = !*s in
assert (
let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.AES_s.is_aes_key_LE (vale_alg_of_alg a) k_w);
push_frame();
let scratch_b = B.sub ek (concrete_xkey_len i) 176ul in
let ek = B.sub ek 0ul (concrete_xkey_len i) in
let keys_b = B.sub ek 0ul (key_offset i) in
let hkeys_b = B.sub ek (key_offset i) 128ul in
let h0 = get() in
// The iv can be arbitrary length, hence we need to allocate a new one to perform the hashing
let tmp_iv = B.alloca 0uy 16ul in
// There is no SMTPat on le_bytes_to_seq_quad32_to_bytes and the converse,
// so we need an explicit lemma
let lemma_hkeys_reqs () : Lemma
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.OptPublic.hkeys_reqs_pub
(Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 hkeys_b)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))))
= let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
let hkeys_quad = Vale.AES.OptPublic.get_hkeys_reqs (Vale.Def.Types_s.reverse_bytes_quad32 (
Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))) in
let hkeys = Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 (Vale.Def.Types_s.le_seq_quad32_to_bytes hkeys_quad) in
assert (Seq.equal (B.as_seq h0 hkeys_b) hkeys);
calc (==) {
Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 hkeys);
(==) { Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes hkeys_quad }
hkeys_quad;
}
in lemma_hkeys_reqs ();
// We perform the hashing of the iv. The extra buffer and the hashed iv are the same
Vale.Wrapper.X64.GCM_IV.compute_iv (vale_alg_of_alg a)
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w )
iv iv_len
tmp_iv tmp_iv
hkeys_b;
let h0 = get() in
aes_gcm_encrypt i
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w)
(Ghost.hide (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv)))
plain
(uint32_to_uint64 plain_len)
ad
(uint32_to_uint64 ad_len)
tmp_iv
cipher
tag
keys_b
hkeys_b
scratch_b;
let h1 = get() in
// This assert is needed for z3 to pick up sequence equality for ciphertext
// and tag. It could be avoided if the spec returned both instead of appending them
assert (
let kv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (G.reveal kv) in
let iv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv) in
// `ad` is called `auth` in Vale world; "additional data", "authenticated
// data", potato, potato
let ad_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 ad) in
let plain_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 plain) in
let cipher_nat, tag_nat =
Vale.AES.GCM_s.gcm_encrypt_LE (vale_alg_of_alg a) kv_nat iv_nat plain_nat ad_nat
in
Seq.equal (B.as_seq h1 cipher) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 cipher_nat) /\
Seq.equal (B.as_seq h1 tag) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 tag_nat));
pop_frame();
Success
let encrypt_aes128_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES128_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES128 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt_aes256_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES256_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES256 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt #a s iv iv_len ad ad_len plain plain_len cipher tag =
if B.is_null s then
InvalidKey
else
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
match i with
| Vale_AES128 ->
encrypt_aes128_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Vale_AES256 ->
encrypt_aes256_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Hacl_CHACHA20 ->
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len <> 12ul then
InvalidIVLength
else begin
// Length restrictions
assert_norm (pow2 31 + pow2 32 / 64 <= pow2 32 - 1);
EverCrypt.Chacha20Poly1305.aead_encrypt
ek iv ad_len ad plain_len plain cipher tag;
Success
end
inline_for_extraction noextract
let encrypt_expand_aes_gcm (i: vale_impl): encrypt_expand_st false (alg_of_vale_impl i) =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s (alg_of_vale_impl i)) = alloca k in
let r = encrypt_aes_gcm i s iv iv_len ad ad_len plain plain_len cipher tag in
assert(r == Success);
pop_frame ();
Success
let encrypt_expand_aes128_gcm_no_check : encrypt_expand_st false AES128_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale"
let encrypt_expand_aes256_gcm_no_check : encrypt_expand_st false AES256_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len plain plain_len cipher tag
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale"
let encrypt_expand_aes128_gcm : encrypt_expand_st true AES128_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then
encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else
UnsupportedAlgorithm
else
UnsupportedAlgorithm
let encrypt_expand_aes256_gcm : encrypt_expand_st true AES256_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then
encrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len plain plain_len cipher tag
else
UnsupportedAlgorithm
else
UnsupportedAlgorithm
let encrypt_expand_chacha20_poly1305 : encrypt_expand_st false CHACHA20_POLY1305 =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s CHACHA20_POLY1305) = alloca k in
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
EverCrypt.Chacha20Poly1305.aead_encrypt ek iv ad_len ad plain_len plain cipher tag;
pop_frame ();
Success
let encrypt_expand #a k iv iv_len ad ad_len plain plain_len cipher tag =
match a with
| AES128_GCM ->
encrypt_expand_aes128_gcm k iv iv_len ad ad_len plain plain_len cipher tag
| AES256_GCM ->
encrypt_expand_aes256_gcm k iv iv_len ad ad_len plain plain_len cipher tag
| CHACHA20_POLY1305 ->
encrypt_expand_chacha20_poly1305 k iv iv_len ad ad_len plain plain_len cipher tag
inline_for_extraction noextract
let aes_gcm_decrypt (i: vale_impl):
Vale.Wrapper.X64.GCMdecryptOpt.decrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMdecryptOpt.gcm128_decrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMdecryptOpt256.gcm256_decrypt_opt_stdcall
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties.slice_slice'"
inline_for_extraction noextract
let decrypt_aes_gcm (i: vale_impl): decrypt_st (alg_of_vale_impl i) =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if B.is_null s then
InvalidKey
else
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len = 0ul then
InvalidIVLength
else
let a = alg_of_vale_impl i in
let open LowStar.BufferOps in
let Ek _ kv ek = !*s in
assert (
let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.AES_s.is_aes_key_LE (vale_alg_of_alg a) k_w);
push_frame();
let scratch_b = B.sub ek (concrete_xkey_len i) 176ul in
let ek = B.sub ek 0ul (concrete_xkey_len i) in
let keys_b = B.sub ek 0ul (key_offset i) in
let hkeys_b = B.sub ek (key_offset i) 128ul in
let h0 = get() in
// The iv can be arbitrary length, hence we need to allocate a new one to perform the hashing
let tmp_iv = B.alloca 0uy 16ul in
// There is no SMTPat on le_bytes_to_seq_quad32_to_bytes and the converse,
// so we need an explicit lemma
let lemma_hkeys_reqs () : Lemma
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.OptPublic.hkeys_reqs_pub
(Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 hkeys_b)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))))
= let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
let hkeys_quad = Vale.AES.OptPublic.get_hkeys_reqs (Vale.Def.Types_s.reverse_bytes_quad32 (
Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))) in
let hkeys = Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 (Vale.Def.Types_s.le_seq_quad32_to_bytes hkeys_quad) in
assert (Seq.equal (B.as_seq h0 hkeys_b) hkeys);
calc (==) {
Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 hkeys);
(==) { Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes hkeys_quad }
hkeys_quad;
}
in lemma_hkeys_reqs ();
// We perform the hashing of the iv. The extra buffer and the hashed iv are the same
Vale.Wrapper.X64.GCM_IV.compute_iv (vale_alg_of_alg a)
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w )
iv iv_len
tmp_iv tmp_iv
hkeys_b;
let r = aes_gcm_decrypt i
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w)
(Ghost.hide (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv)))
cipher
(uint32_to_uint64 cipher_len)
ad
(uint32_to_uint64 ad_len)
tmp_iv
dst
tag
keys_b
hkeys_b
scratch_b in
let h1 = get() in
// This assert is needed for z3 to pick up sequence equality for ciphertext
// It could be avoided if the spec returned both instead of appending them
assert (
let kv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (G.reveal kv) in
let iv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv) in
// `ad` is called `auth` in Vale world; "additional data", "authenticated
// data", potato, potato
let ad_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 ad) in
let cipher_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 cipher) in
let tag_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 tag) in
let plain_nat, success =
Vale.AES.GCM_s.gcm_decrypt_LE (vale_alg_of_alg a) kv_nat iv_nat cipher_nat ad_nat tag_nat
in
Seq.equal (B.as_seq h1 dst) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 plain_nat) /\
(UInt64.v r = 0) == success);
assert (
let kv = G.reveal kv in
let cipher_tag = B.as_seq h0 cipher `S.append` B.as_seq h0 tag in
Seq.equal (Seq.slice cipher_tag (S.length cipher_tag - tag_length a) (S.length cipher_tag))
(B.as_seq h0 tag) /\
Seq.equal (Seq.slice cipher_tag 0 (S.length cipher_tag - tag_length a)) (B.as_seq h0 cipher));
pop_frame();
if r = 0uL then
Success
else
AuthenticationFailure
let decrypt_aes128_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
decrypt_st AES128_GCM =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
decrypt_aes_gcm Vale_AES128 s iv iv_len ad ad_len cipher cipher_len tag dst
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let decrypt_aes256_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
decrypt_st AES256_GCM =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
decrypt_aes_gcm Vale_AES256 s iv iv_len ad ad_len cipher cipher_len tag dst
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let decrypt_chacha20_poly1305 : decrypt_st CHACHA20_POLY1305 =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if B.is_null s then
InvalidKey
else
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len <> 12ul then
InvalidIVLength
else begin
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
[@ inline_let ] let bound = pow2 32 - 1 - 16 in
assert (v cipher_len <= bound);
assert_norm (bound + 16 <= pow2 32 - 1);
assert_norm (pow2 31 + bound / 64 <= pow2 32 - 1);
let h0 = ST.get () in
let r = EverCrypt.Chacha20Poly1305.aead_decrypt
ek iv ad_len ad cipher_len dst cipher tag
in
assert (
let cipher_tag = B.as_seq h0 cipher `S.append` B.as_seq h0 tag in
let tag_s = S.slice cipher_tag (S.length cipher_tag - tag_length CHACHA20_POLY1305) (S.length cipher_tag) in
let cipher_s = S.slice cipher_tag 0 (S.length cipher_tag - tag_length CHACHA20_POLY1305) in
S.equal cipher_s (B.as_seq h0 cipher) /\ S.equal tag_s (B.as_seq h0 tag));
if r = 0ul then
Success
else
AuthenticationFailure
end | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.AEAD.decrypt_st (FStar.Ghost.reveal a) | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"Spec.Agile.AEAD.supported_alg",
"LowStar.Buffer.pointer_or_null",
"EverCrypt.AEAD.state_s",
"FStar.Ghost.reveal",
"EverCrypt.AEAD.iv_p",
"FStar.UInt32.t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.Integers.within_bounds",
"FStar.Integers.Unsigned",
"FStar.Integers.W32",
"FStar.Integers.v",
"LowStar.Monotonic.Buffer.length",
"EverCrypt.CTR.Keys.uint8",
"LowStar.Buffer.trivial_preorder",
"FStar.Integers.op_Greater",
"FStar.Integers.Signed",
"FStar.Integers.Winfinite",
"EverCrypt.AEAD.ad_p",
"FStar.Integers.op_Less_Equals",
"Prims.pow2",
"EverCrypt.AEAD.cipher_p",
"LowStar.Buffer.buffer",
"Spec.Agile.AEAD.tag_length",
"Prims.nat",
"EverCrypt.Error.InvalidKey",
"EverCrypt.Error.error_code",
"Prims.bool",
"Spec.Cipher.Expansion.impl",
"Spec.Agile.AEAD.kv",
"FStar.UInt8.t",
"EverCrypt.AEAD.decrypt_aes128_gcm",
"EverCrypt.AEAD.decrypt_aes256_gcm",
"EverCrypt.AEAD.decrypt_chacha20_poly1305",
"LowStar.BufferOps.op_Bang_Star",
"LowStar.Monotonic.Buffer.is_null"
] | [] | false | false | false | false | false | let decrypt #a s iv iv_len ad ad_len cipher cipher_len tag dst =
| if B.is_null s
then InvalidKey
else
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
match i with
| Vale_AES128 -> decrypt_aes128_gcm () s iv iv_len ad ad_len cipher cipher_len tag dst
| Vale_AES256 -> decrypt_aes256_gcm () s iv iv_len ad ad_len cipher cipher_len tag dst
| Hacl_CHACHA20 -> decrypt_chacha20_poly1305 s iv iv_len ad ad_len cipher cipher_len tag dst | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.contents_exact | val contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost t
(requires (valid_exact p h s pos pos'))
(ensures (fun _ -> True)) | val contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost t
(requires (valid_exact p h s pos pos'))
(ensures (fun _ -> True)) | let contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost t
(requires (valid_exact p h s pos pos'))
(ensures (fun _ -> True))
= valid_exact_equiv p h s pos pos' ;
contents_exact' p h s pos pos' | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 32,
"end_line": 223,
"start_col": 0,
"start_line": 210
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x))
let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos)
let get_valid_pos_post
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (
let pos' = get_valid_pos p h sl pos in
valid_pos p h sl pos pos'
))
[SMTPat (get_valid_pos p h sl pos)]
= ()
let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
= valid_exact' p h s pos pos'
let valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
= assert_norm (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos') | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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: LowParse.Spec.Base.parser k t ->
h: FStar.Monotonic.HyperStack.mem ->
s: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> Prims.Ghost t | Prims.Ghost | [] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.Base.Spec.contents_exact'",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_exact_equiv",
"LowParse.Low.Base.Spec.valid_exact",
"Prims.l_True"
] | [] | false | false | false | false | false | let contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos pos': U32.t)
: Ghost t (requires (valid_exact p h s pos pos')) (ensures (fun _ -> True)) =
| valid_exact_equiv p h s pos pos';
contents_exact' p h s pos pos' | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.free | val free:
#a:G.erased supported_alg -> (
let a = Ghost.reveal a in
s:state a -> ST unit
(requires fun h0 ->
freeable h0 s /\
invariant h0 s)
(ensures fun h0 _ h1 ->
B.(modifies (footprint h0 s) h0 h1))) | val free:
#a:G.erased supported_alg -> (
let a = Ghost.reveal a in
s:state a -> ST unit
(requires fun h0 ->
freeable h0 s /\
invariant h0 s)
(ensures fun h0 _ h1 ->
B.(modifies (footprint h0 s) h0 h1))) | let free #a s =
let open LowStar.BufferOps in
let Ek _ _ ek = !*s in
B.free ek;
B.free s | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 696,
"start_col": 0,
"start_line": 692
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success
#pop-options
inline_for_extraction noextract
let create_in_aes_gcm (i: vale_impl):
create_in_st (alg_of_vale_impl i) =
fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale then (
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then (
let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success
) else
UnsupportedAlgorithm
) else
UnsupportedAlgorithm
let create_in_aes128_gcm: create_in_st AES128_GCM = create_in_aes_gcm Vale_AES128
let create_in_aes256_gcm: create_in_st AES256_GCM = create_in_aes_gcm Vale_AES256
let create_in #a r dst k =
match a with
| AES128_GCM -> create_in_aes128_gcm r dst k
| AES256_GCM -> create_in_aes256_gcm r dst k
| CHACHA20_POLY1305 -> create_in_chacha20_poly1305 r dst k
| _ -> UnsupportedAlgorithm
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
inline_for_extraction noextract
let alloca_chacha20_poly1305: alloca_st CHACHA20_POLY1305 =
fun k ->
let h0 = ST.get () in
let ek = B.alloca 0uy 32ul in
let p = B.alloca (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.loc_none h0 h3;
p
#pop-options
inline_for_extraction noextract
let alloca_aes_gcm (i: vale_impl):
alloca_st (alg_of_vale_impl i) =
fun k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
let ek = B.alloca 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.alloca (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
p
inline_for_extraction noextract
let alloca_aes128_gcm: alloca_st AES128_GCM =
alloca_aes_gcm Vale_AES128
inline_for_extraction noextract
let alloca_aes256_gcm: alloca_st AES256_GCM =
alloca_aes_gcm Vale_AES256
let alloca #a k =
match a with
| AES128_GCM -> alloca_aes128_gcm k
| AES256_GCM -> alloca_aes256_gcm k
| CHACHA20_POLY1305 -> alloca_chacha20_poly1305 k
inline_for_extraction noextract
let aes_gcm_encrypt (i: vale_impl):
Vale.Wrapper.X64.GCMencryptOpt.encrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMencryptOpt.gcm128_encrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMencryptOpt256.gcm256_encrypt_opt_stdcall
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties.slice_slice'"
inline_for_extraction noextract
let encrypt_aes_gcm (i: vale_impl): encrypt_st (alg_of_vale_impl i) =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if B.is_null s then
InvalidKey
else
let a = alg_of_vale_impl i in
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len = 0ul then
InvalidIVLength
else
let open LowStar.BufferOps in
let Ek _ kv ek = !*s in
assert (
let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.AES_s.is_aes_key_LE (vale_alg_of_alg a) k_w);
push_frame();
let scratch_b = B.sub ek (concrete_xkey_len i) 176ul in
let ek = B.sub ek 0ul (concrete_xkey_len i) in
let keys_b = B.sub ek 0ul (key_offset i) in
let hkeys_b = B.sub ek (key_offset i) 128ul in
let h0 = get() in
// The iv can be arbitrary length, hence we need to allocate a new one to perform the hashing
let tmp_iv = B.alloca 0uy 16ul in
// There is no SMTPat on le_bytes_to_seq_quad32_to_bytes and the converse,
// so we need an explicit lemma
let lemma_hkeys_reqs () : Lemma
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.OptPublic.hkeys_reqs_pub
(Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 hkeys_b)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))))
= let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
let hkeys_quad = Vale.AES.OptPublic.get_hkeys_reqs (Vale.Def.Types_s.reverse_bytes_quad32 (
Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))) in
let hkeys = Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 (Vale.Def.Types_s.le_seq_quad32_to_bytes hkeys_quad) in
assert (Seq.equal (B.as_seq h0 hkeys_b) hkeys);
calc (==) {
Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 hkeys);
(==) { Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes hkeys_quad }
hkeys_quad;
}
in lemma_hkeys_reqs ();
// We perform the hashing of the iv. The extra buffer and the hashed iv are the same
Vale.Wrapper.X64.GCM_IV.compute_iv (vale_alg_of_alg a)
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w )
iv iv_len
tmp_iv tmp_iv
hkeys_b;
let h0 = get() in
aes_gcm_encrypt i
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w)
(Ghost.hide (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv)))
plain
(uint32_to_uint64 plain_len)
ad
(uint32_to_uint64 ad_len)
tmp_iv
cipher
tag
keys_b
hkeys_b
scratch_b;
let h1 = get() in
// This assert is needed for z3 to pick up sequence equality for ciphertext
// and tag. It could be avoided if the spec returned both instead of appending them
assert (
let kv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (G.reveal kv) in
let iv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv) in
// `ad` is called `auth` in Vale world; "additional data", "authenticated
// data", potato, potato
let ad_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 ad) in
let plain_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 plain) in
let cipher_nat, tag_nat =
Vale.AES.GCM_s.gcm_encrypt_LE (vale_alg_of_alg a) kv_nat iv_nat plain_nat ad_nat
in
Seq.equal (B.as_seq h1 cipher) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 cipher_nat) /\
Seq.equal (B.as_seq h1 tag) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 tag_nat));
pop_frame();
Success
let encrypt_aes128_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES128_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES128 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt_aes256_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES256_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES256 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt #a s iv iv_len ad ad_len plain plain_len cipher tag =
if B.is_null s then
InvalidKey
else
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
match i with
| Vale_AES128 ->
encrypt_aes128_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Vale_AES256 ->
encrypt_aes256_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Hacl_CHACHA20 ->
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len <> 12ul then
InvalidIVLength
else begin
// Length restrictions
assert_norm (pow2 31 + pow2 32 / 64 <= pow2 32 - 1);
EverCrypt.Chacha20Poly1305.aead_encrypt
ek iv ad_len ad plain_len plain cipher tag;
Success
end
inline_for_extraction noextract
let encrypt_expand_aes_gcm (i: vale_impl): encrypt_expand_st false (alg_of_vale_impl i) =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s (alg_of_vale_impl i)) = alloca k in
let r = encrypt_aes_gcm i s iv iv_len ad ad_len plain plain_len cipher tag in
assert(r == Success);
pop_frame ();
Success
let encrypt_expand_aes128_gcm_no_check : encrypt_expand_st false AES128_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale"
let encrypt_expand_aes256_gcm_no_check : encrypt_expand_st false AES256_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len plain plain_len cipher tag
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale"
let encrypt_expand_aes128_gcm : encrypt_expand_st true AES128_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then
encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else
UnsupportedAlgorithm
else
UnsupportedAlgorithm
let encrypt_expand_aes256_gcm : encrypt_expand_st true AES256_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then
encrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len plain plain_len cipher tag
else
UnsupportedAlgorithm
else
UnsupportedAlgorithm
let encrypt_expand_chacha20_poly1305 : encrypt_expand_st false CHACHA20_POLY1305 =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s CHACHA20_POLY1305) = alloca k in
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
EverCrypt.Chacha20Poly1305.aead_encrypt ek iv ad_len ad plain_len plain cipher tag;
pop_frame ();
Success
let encrypt_expand #a k iv iv_len ad ad_len plain plain_len cipher tag =
match a with
| AES128_GCM ->
encrypt_expand_aes128_gcm k iv iv_len ad ad_len plain plain_len cipher tag
| AES256_GCM ->
encrypt_expand_aes256_gcm k iv iv_len ad ad_len plain plain_len cipher tag
| CHACHA20_POLY1305 ->
encrypt_expand_chacha20_poly1305 k iv iv_len ad ad_len plain plain_len cipher tag
inline_for_extraction noextract
let aes_gcm_decrypt (i: vale_impl):
Vale.Wrapper.X64.GCMdecryptOpt.decrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMdecryptOpt.gcm128_decrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMdecryptOpt256.gcm256_decrypt_opt_stdcall
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties.slice_slice'"
inline_for_extraction noextract
let decrypt_aes_gcm (i: vale_impl): decrypt_st (alg_of_vale_impl i) =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if B.is_null s then
InvalidKey
else
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len = 0ul then
InvalidIVLength
else
let a = alg_of_vale_impl i in
let open LowStar.BufferOps in
let Ek _ kv ek = !*s in
assert (
let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.AES_s.is_aes_key_LE (vale_alg_of_alg a) k_w);
push_frame();
let scratch_b = B.sub ek (concrete_xkey_len i) 176ul in
let ek = B.sub ek 0ul (concrete_xkey_len i) in
let keys_b = B.sub ek 0ul (key_offset i) in
let hkeys_b = B.sub ek (key_offset i) 128ul in
let h0 = get() in
// The iv can be arbitrary length, hence we need to allocate a new one to perform the hashing
let tmp_iv = B.alloca 0uy 16ul in
// There is no SMTPat on le_bytes_to_seq_quad32_to_bytes and the converse,
// so we need an explicit lemma
let lemma_hkeys_reqs () : Lemma
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.OptPublic.hkeys_reqs_pub
(Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 hkeys_b)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))))
= let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
let hkeys_quad = Vale.AES.OptPublic.get_hkeys_reqs (Vale.Def.Types_s.reverse_bytes_quad32 (
Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))) in
let hkeys = Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 (Vale.Def.Types_s.le_seq_quad32_to_bytes hkeys_quad) in
assert (Seq.equal (B.as_seq h0 hkeys_b) hkeys);
calc (==) {
Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 hkeys);
(==) { Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes hkeys_quad }
hkeys_quad;
}
in lemma_hkeys_reqs ();
// We perform the hashing of the iv. The extra buffer and the hashed iv are the same
Vale.Wrapper.X64.GCM_IV.compute_iv (vale_alg_of_alg a)
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w )
iv iv_len
tmp_iv tmp_iv
hkeys_b;
let r = aes_gcm_decrypt i
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w)
(Ghost.hide (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv)))
cipher
(uint32_to_uint64 cipher_len)
ad
(uint32_to_uint64 ad_len)
tmp_iv
dst
tag
keys_b
hkeys_b
scratch_b in
let h1 = get() in
// This assert is needed for z3 to pick up sequence equality for ciphertext
// It could be avoided if the spec returned both instead of appending them
assert (
let kv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (G.reveal kv) in
let iv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv) in
// `ad` is called `auth` in Vale world; "additional data", "authenticated
// data", potato, potato
let ad_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 ad) in
let cipher_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 cipher) in
let tag_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 tag) in
let plain_nat, success =
Vale.AES.GCM_s.gcm_decrypt_LE (vale_alg_of_alg a) kv_nat iv_nat cipher_nat ad_nat tag_nat
in
Seq.equal (B.as_seq h1 dst) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 plain_nat) /\
(UInt64.v r = 0) == success);
assert (
let kv = G.reveal kv in
let cipher_tag = B.as_seq h0 cipher `S.append` B.as_seq h0 tag in
Seq.equal (Seq.slice cipher_tag (S.length cipher_tag - tag_length a) (S.length cipher_tag))
(B.as_seq h0 tag) /\
Seq.equal (Seq.slice cipher_tag 0 (S.length cipher_tag - tag_length a)) (B.as_seq h0 cipher));
pop_frame();
if r = 0uL then
Success
else
AuthenticationFailure
let decrypt_aes128_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
decrypt_st AES128_GCM =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
decrypt_aes_gcm Vale_AES128 s iv iv_len ad ad_len cipher cipher_len tag dst
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let decrypt_aes256_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
decrypt_st AES256_GCM =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
decrypt_aes_gcm Vale_AES256 s iv iv_len ad ad_len cipher cipher_len tag dst
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let decrypt_chacha20_poly1305 : decrypt_st CHACHA20_POLY1305 =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if B.is_null s then
InvalidKey
else
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len <> 12ul then
InvalidIVLength
else begin
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
[@ inline_let ] let bound = pow2 32 - 1 - 16 in
assert (v cipher_len <= bound);
assert_norm (bound + 16 <= pow2 32 - 1);
assert_norm (pow2 31 + bound / 64 <= pow2 32 - 1);
let h0 = ST.get () in
let r = EverCrypt.Chacha20Poly1305.aead_decrypt
ek iv ad_len ad cipher_len dst cipher tag
in
assert (
let cipher_tag = B.as_seq h0 cipher `S.append` B.as_seq h0 tag in
let tag_s = S.slice cipher_tag (S.length cipher_tag - tag_length CHACHA20_POLY1305) (S.length cipher_tag) in
let cipher_s = S.slice cipher_tag 0 (S.length cipher_tag - tag_length CHACHA20_POLY1305) in
S.equal cipher_s (B.as_seq h0 cipher) /\ S.equal tag_s (B.as_seq h0 tag));
if r = 0ul then
Success
else
AuthenticationFailure
end
let decrypt #a s iv iv_len ad ad_len cipher cipher_len tag dst =
if B.is_null s then
InvalidKey
else
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
match i with
| Vale_AES128 ->
decrypt_aes128_gcm () s iv iv_len ad ad_len cipher cipher_len tag dst
| Vale_AES256 ->
decrypt_aes256_gcm () s iv iv_len ad ad_len cipher cipher_len tag dst
| Hacl_CHACHA20 ->
decrypt_chacha20_poly1305 s iv iv_len ad ad_len cipher cipher_len tag dst
inline_for_extraction noextract
let decrypt_expand_aes_gcm (i: vale_impl): decrypt_expand_st false (alg_of_vale_impl i) =
fun k iv iv_len ad ad_len cipher cipher_len tag dst ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s (alg_of_vale_impl i)) = alloca k in
let r = decrypt_aes_gcm i s iv iv_len ad ad_len cipher cipher_len tag dst in
pop_frame ();
r
let decrypt_expand_aes128_gcm_no_check : decrypt_expand_st false AES128_GCM =
fun k iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
decrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len cipher cipher_len tag dst
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale"
let decrypt_expand_aes256_gcm_no_check : decrypt_expand_st false AES256_GCM =
fun k iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
decrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len cipher cipher_len tag dst
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale"
let decrypt_expand_aes128_gcm : decrypt_expand_st true AES128_GCM =
fun k iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then
decrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len cipher cipher_len tag dst
else
UnsupportedAlgorithm
else
UnsupportedAlgorithm
let decrypt_expand_aes256_gcm : decrypt_expand_st true AES256_GCM =
fun k iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then
decrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len cipher cipher_len tag dst
else
UnsupportedAlgorithm
else
UnsupportedAlgorithm
let decrypt_expand_chacha20_poly1305 : decrypt_expand_st false CHACHA20_POLY1305 =
fun k iv iv_len ad ad_len cipher cipher_len tag dst ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s CHACHA20_POLY1305) = alloca k in
let r = decrypt_chacha20_poly1305 s iv iv_len ad ad_len cipher cipher_len tag dst in
pop_frame ();
r
let decrypt_expand #a k iv iv_len ad ad_len cipher cipher_len tag dst =
match a with
| AES128_GCM ->
decrypt_expand_aes128_gcm k iv iv_len ad ad_len cipher cipher_len tag dst
| AES256_GCM ->
decrypt_expand_aes256_gcm k iv iv_len ad ad_len cipher cipher_len tag dst
| CHACHA20_POLY1305 ->
decrypt_expand_chacha20_poly1305 k iv iv_len ad ad_len cipher cipher_len tag dst | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | let a = FStar.Ghost.reveal a in
s: EverCrypt.AEAD.state a -> FStar.HyperStack.ST.ST Prims.unit | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"Spec.Agile.AEAD.supported_alg",
"EverCrypt.AEAD.state",
"FStar.Ghost.reveal",
"Spec.Cipher.Expansion.impl",
"Spec.Agile.AEAD.kv",
"LowStar.Buffer.buffer",
"FStar.UInt8.t",
"LowStar.Monotonic.Buffer.free",
"EverCrypt.AEAD.state_s",
"LowStar.Buffer.trivial_preorder",
"Prims.unit",
"LowStar.BufferOps.op_Bang_Star"
] | [] | false | false | false | false | false | let free #a s =
| let open LowStar.BufferOps in
let Ek _ _ ek = !*s in
B.free ek;
B.free s | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.contents_exact_eq | val contents_exact_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_exact p h s pos pos'))
(ensures (valid_exact p h s pos pos' /\ valid_exact' p h s pos pos' /\ contents_exact p h s pos pos' == contents_exact' p h s pos pos')) | val contents_exact_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_exact p h s pos pos'))
(ensures (valid_exact p h s pos pos' /\ valid_exact' p h s pos pos' /\ contents_exact p h s pos pos' == contents_exact' p h s pos pos')) | let contents_exact_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_exact p h s pos pos'))
(ensures (valid_exact p h s pos pos' /\ valid_exact' p h s pos pos' /\ contents_exact p h s pos pos' == contents_exact' p h s pos pos'))
= valid_exact_equiv p h s pos pos' ;
assert_norm (contents_exact p h s pos pos' == contents_exact' p h s pos pos') | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 79,
"end_line": 238,
"start_col": 0,
"start_line": 225
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x))
let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos)
let get_valid_pos_post
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (
let pos' = get_valid_pos p h sl pos in
valid_pos p h sl pos pos'
))
[SMTPat (get_valid_pos p h sl pos)]
= ()
let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
= valid_exact' p h s pos pos'
let valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
= assert_norm (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
let contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost t
(requires (valid_exact p h s pos pos'))
(ensures (fun _ -> True))
= valid_exact_equiv p h s pos pos' ;
contents_exact' p h s pos pos' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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: LowParse.Spec.Base.parser k t ->
h: FStar.Monotonic.HyperStack.mem ->
s: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> FStar.Pervasives.Lemma (requires LowParse.Low.Base.Spec.valid_exact p h s pos pos')
(ensures
LowParse.Low.Base.Spec.valid_exact p h s pos pos' /\
LowParse.Low.Base.Spec.valid_exact' p h s pos pos' /\
LowParse.Low.Base.Spec.contents_exact p h s pos pos' ==
LowParse.Low.Base.Spec.contents_exact' p h s pos pos') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"LowParse.Low.Base.Spec.contents_exact",
"LowParse.Low.Base.Spec.contents_exact'",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_exact_equiv",
"LowParse.Low.Base.Spec.valid_exact",
"Prims.squash",
"Prims.l_and",
"LowParse.Low.Base.Spec.valid_exact'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let contents_exact_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos pos': U32.t)
: Lemma (requires (valid_exact p h s pos pos'))
(ensures
(valid_exact p h s pos pos' /\ valid_exact' p h s pos pos' /\
contents_exact p h s pos pos' == contents_exact' p h s pos pos')) =
| valid_exact_equiv p h s pos pos';
assert_norm (contents_exact p h s pos pos' == contents_exact' p h s pos pos') | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.valid_exact_equiv | val valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos') | val valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos') | let valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
= assert_norm (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos') | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 75,
"end_line": 208,
"start_col": 0,
"start_line": 197
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x))
let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos)
let get_valid_pos_post
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (
let pos' = get_valid_pos p h sl pos in
valid_pos p h sl pos pos'
))
[SMTPat (get_valid_pos p h sl pos)]
= ()
let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
= valid_exact' p h s pos pos' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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: LowParse.Spec.Base.parser k t ->
h: FStar.Monotonic.HyperStack.mem ->
s: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> FStar.Pervasives.Lemma
(ensures
LowParse.Low.Base.Spec.valid_exact p h s pos pos' <==>
LowParse.Low.Base.Spec.valid_exact' p h s pos pos') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.Pervasives.assert_norm",
"Prims.l_iff",
"LowParse.Low.Base.Spec.valid_exact",
"LowParse.Low.Base.Spec.valid_exact'",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos pos': U32.t)
: Lemma (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos') =
| assert_norm (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos') | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.encrypt | val encrypt: #a:G.erased (supported_alg) -> encrypt_st (G.reveal a) | val encrypt: #a:G.erased (supported_alg) -> encrypt_st (G.reveal a) | let encrypt #a s iv iv_len ad ad_len plain plain_len cipher tag =
if B.is_null s then
InvalidKey
else
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
match i with
| Vale_AES128 ->
encrypt_aes128_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Vale_AES256 ->
encrypt_aes256_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Hacl_CHACHA20 ->
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len <> 12ul then
InvalidIVLength
else begin
// Length restrictions
assert_norm (pow2 31 + pow2 32 / 64 <= pow2 32 - 1);
EverCrypt.Chacha20Poly1305.aead_encrypt
ek iv ad_len ad plain_len plain cipher tag;
Success
end | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 357,
"start_col": 0,
"start_line": 335
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success
#pop-options
inline_for_extraction noextract
let create_in_aes_gcm (i: vale_impl):
create_in_st (alg_of_vale_impl i) =
fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale then (
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then (
let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success
) else
UnsupportedAlgorithm
) else
UnsupportedAlgorithm
let create_in_aes128_gcm: create_in_st AES128_GCM = create_in_aes_gcm Vale_AES128
let create_in_aes256_gcm: create_in_st AES256_GCM = create_in_aes_gcm Vale_AES256
let create_in #a r dst k =
match a with
| AES128_GCM -> create_in_aes128_gcm r dst k
| AES256_GCM -> create_in_aes256_gcm r dst k
| CHACHA20_POLY1305 -> create_in_chacha20_poly1305 r dst k
| _ -> UnsupportedAlgorithm
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
inline_for_extraction noextract
let alloca_chacha20_poly1305: alloca_st CHACHA20_POLY1305 =
fun k ->
let h0 = ST.get () in
let ek = B.alloca 0uy 32ul in
let p = B.alloca (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.loc_none h0 h3;
p
#pop-options
inline_for_extraction noextract
let alloca_aes_gcm (i: vale_impl):
alloca_st (alg_of_vale_impl i) =
fun k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
let ek = B.alloca 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.alloca (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
p
inline_for_extraction noextract
let alloca_aes128_gcm: alloca_st AES128_GCM =
alloca_aes_gcm Vale_AES128
inline_for_extraction noextract
let alloca_aes256_gcm: alloca_st AES256_GCM =
alloca_aes_gcm Vale_AES256
let alloca #a k =
match a with
| AES128_GCM -> alloca_aes128_gcm k
| AES256_GCM -> alloca_aes256_gcm k
| CHACHA20_POLY1305 -> alloca_chacha20_poly1305 k
inline_for_extraction noextract
let aes_gcm_encrypt (i: vale_impl):
Vale.Wrapper.X64.GCMencryptOpt.encrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMencryptOpt.gcm128_encrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMencryptOpt256.gcm256_encrypt_opt_stdcall
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties.slice_slice'"
inline_for_extraction noextract
let encrypt_aes_gcm (i: vale_impl): encrypt_st (alg_of_vale_impl i) =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if B.is_null s then
InvalidKey
else
let a = alg_of_vale_impl i in
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len = 0ul then
InvalidIVLength
else
let open LowStar.BufferOps in
let Ek _ kv ek = !*s in
assert (
let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.AES_s.is_aes_key_LE (vale_alg_of_alg a) k_w);
push_frame();
let scratch_b = B.sub ek (concrete_xkey_len i) 176ul in
let ek = B.sub ek 0ul (concrete_xkey_len i) in
let keys_b = B.sub ek 0ul (key_offset i) in
let hkeys_b = B.sub ek (key_offset i) 128ul in
let h0 = get() in
// The iv can be arbitrary length, hence we need to allocate a new one to perform the hashing
let tmp_iv = B.alloca 0uy 16ul in
// There is no SMTPat on le_bytes_to_seq_quad32_to_bytes and the converse,
// so we need an explicit lemma
let lemma_hkeys_reqs () : Lemma
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.OptPublic.hkeys_reqs_pub
(Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 hkeys_b)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))))
= let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
let hkeys_quad = Vale.AES.OptPublic.get_hkeys_reqs (Vale.Def.Types_s.reverse_bytes_quad32 (
Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))) in
let hkeys = Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 (Vale.Def.Types_s.le_seq_quad32_to_bytes hkeys_quad) in
assert (Seq.equal (B.as_seq h0 hkeys_b) hkeys);
calc (==) {
Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 hkeys);
(==) { Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes hkeys_quad }
hkeys_quad;
}
in lemma_hkeys_reqs ();
// We perform the hashing of the iv. The extra buffer and the hashed iv are the same
Vale.Wrapper.X64.GCM_IV.compute_iv (vale_alg_of_alg a)
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w )
iv iv_len
tmp_iv tmp_iv
hkeys_b;
let h0 = get() in
aes_gcm_encrypt i
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w)
(Ghost.hide (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv)))
plain
(uint32_to_uint64 plain_len)
ad
(uint32_to_uint64 ad_len)
tmp_iv
cipher
tag
keys_b
hkeys_b
scratch_b;
let h1 = get() in
// This assert is needed for z3 to pick up sequence equality for ciphertext
// and tag. It could be avoided if the spec returned both instead of appending them
assert (
let kv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (G.reveal kv) in
let iv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv) in
// `ad` is called `auth` in Vale world; "additional data", "authenticated
// data", potato, potato
let ad_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 ad) in
let plain_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 plain) in
let cipher_nat, tag_nat =
Vale.AES.GCM_s.gcm_encrypt_LE (vale_alg_of_alg a) kv_nat iv_nat plain_nat ad_nat
in
Seq.equal (B.as_seq h1 cipher) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 cipher_nat) /\
Seq.equal (B.as_seq h1 tag) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 tag_nat));
pop_frame();
Success
let encrypt_aes128_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES128_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES128 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt_aes256_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES256_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES256 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable" | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.AEAD.encrypt_st (FStar.Ghost.reveal a) | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"Spec.Agile.AEAD.supported_alg",
"LowStar.Buffer.pointer_or_null",
"EverCrypt.AEAD.state_s",
"FStar.Ghost.reveal",
"EverCrypt.AEAD.iv_p",
"FStar.UInt32.t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.Integers.within_bounds",
"FStar.Integers.Unsigned",
"FStar.Integers.W32",
"FStar.Integers.v",
"LowStar.Monotonic.Buffer.length",
"EverCrypt.CTR.Keys.uint8",
"LowStar.Buffer.trivial_preorder",
"FStar.Integers.op_Greater",
"FStar.Integers.Signed",
"FStar.Integers.Winfinite",
"EverCrypt.AEAD.ad_p",
"FStar.Integers.op_Less_Equals",
"Prims.pow2",
"EverCrypt.AEAD.plain_p",
"Spec.Agile.AEAD.max_length",
"LowStar.Buffer.buffer",
"Prims.nat",
"Spec.Agile.AEAD.tag_length",
"EverCrypt.Error.InvalidKey",
"EverCrypt.Error.error_code",
"Prims.bool",
"Spec.Cipher.Expansion.impl",
"Spec.Agile.AEAD.kv",
"FStar.UInt8.t",
"EverCrypt.AEAD.encrypt_aes128_gcm",
"EverCrypt.AEAD.encrypt_aes256_gcm",
"Prims.op_disEquality",
"FStar.UInt32.__uint_to_t",
"EverCrypt.Error.InvalidIVLength",
"EverCrypt.Error.Success",
"Prims.unit",
"EverCrypt.Chacha20Poly1305.aead_encrypt",
"FStar.Pervasives.assert_norm",
"FStar.Integers.op_Plus",
"FStar.Integers.op_Slash",
"FStar.Integers.op_Subtraction",
"LowStar.BufferOps.op_Bang_Star",
"LowStar.Monotonic.Buffer.is_null"
] | [] | false | false | false | false | false | let encrypt #a s iv iv_len ad ad_len plain plain_len cipher tag =
| if B.is_null s
then InvalidKey
else
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
match i with
| Vale_AES128 -> encrypt_aes128_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Vale_AES256 -> encrypt_aes256_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Hacl_CHACHA20 ->
if iv_len <> 12ul
then InvalidIVLength
else
(assert_norm (pow2 31 + pow2 32 / 64 <= pow2 32 - 1);
EverCrypt.Chacha20Poly1305.aead_encrypt ek iv ad_len ad plain_len plain cipher tag;
Success) | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.content_length_eq | val content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))] | val content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))] | let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x)) | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 48,
"end_line": 153,
"start_col": 0,
"start_line": 131
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: LowParse.Spec.Base.serializer p ->
h: FStar.Monotonic.HyperStack.mem ->
sl: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> FStar.Pervasives.Lemma (requires LowParse.Low.Base.Spec.valid p h sl pos)
(ensures
LowParse.Low.Base.Spec.content_length p h sl pos ==
LowParse.Low.Base.Spec.serialized_length s (LowParse.Low.Base.Spec.contents p h sl pos))
[
SMTPat (LowParse.Low.Base.Spec.serialized_length s
(LowParse.Low.Base.Spec.contents p h sl pos))
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Spec.Base.consumed_length",
"Prims._assert",
"LowParse.Spec.Base.injective_precond",
"LowParse.Spec.Base.serialize",
"Prims.unit",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.serializer_correct",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parse",
"Prims.eq2",
"LowParse.Low.Base.Spec.contents",
"LowParse.Bytes.bytes",
"LowParse.Slice.bytes_of_slice_from",
"LowParse.Low.Base.Spec.contents_eq",
"LowParse.Low.Base.Spec.content_length_eq_gen",
"LowParse.Spec.Base.parser_kind_prop_equiv",
"LowParse.Low.Base.Spec.valid",
"Prims.squash",
"Prims.nat",
"LowParse.Low.Base.Spec.content_length",
"LowParse.Low.Base.Spec.serialized_length",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | false | false | true | false | false | let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))] =
| parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x)) | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.gaccessor_id | val gaccessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (gaccessor p p (clens_id _)) | val gaccessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (gaccessor p p (clens_id _)) | let gaccessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (gaccessor p p (clens_id _))
= gaccessor_id' p | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 17,
"end_line": 270,
"start_col": 0,
"start_line": 265
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x))
let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos)
let get_valid_pos_post
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (
let pos' = get_valid_pos p h sl pos in
valid_pos p h sl pos pos'
))
[SMTPat (get_valid_pos p h sl pos)]
= ()
let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
= valid_exact' p h s pos pos'
let valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
= assert_norm (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
let contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost t
(requires (valid_exact p h s pos pos'))
(ensures (fun _ -> True))
= valid_exact_equiv p h s pos pos' ;
contents_exact' p h s pos pos'
let contents_exact_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_exact p h s pos pos'))
(ensures (valid_exact p h s pos pos' /\ valid_exact' p h s pos pos' /\ contents_exact p h s pos pos' == contents_exact' p h s pos pos'))
= valid_exact_equiv p h s pos pos' ;
assert_norm (contents_exact p h s pos pos' == contents_exact' p h s pos pos')
let gaccessor_prop
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: GTot Type0
= gaccessor_prop' f
let gaccessor_prop_equiv
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: Lemma
(gaccessor_prop f <==> gaccessor_prop' f)
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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: LowParse.Spec.Base.parser k t
-> LowParse.Low.Base.Spec.gaccessor p p (LowParse.Low.Base.Spec.clens_id t) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.Spec.gaccessor_id'",
"LowParse.Low.Base.Spec.gaccessor",
"LowParse.Low.Base.Spec.clens_id"
] | [] | false | false | false | false | false | let gaccessor_id (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (gaccessor p p (clens_id _)) =
| gaccessor_id' p | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.encrypt_expand_aes256_gcm | val encrypt_expand_aes256_gcm: encrypt_expand_st true AES256_GCM | val encrypt_expand_aes256_gcm: encrypt_expand_st true AES256_GCM | let encrypt_expand_aes256_gcm : encrypt_expand_st true AES256_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then
encrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len plain plain_len cipher tag
else
UnsupportedAlgorithm
else
UnsupportedAlgorithm | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 24,
"end_line": 412,
"start_col": 0,
"start_line": 399
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success
#pop-options
inline_for_extraction noextract
let create_in_aes_gcm (i: vale_impl):
create_in_st (alg_of_vale_impl i) =
fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale then (
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then (
let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success
) else
UnsupportedAlgorithm
) else
UnsupportedAlgorithm
let create_in_aes128_gcm: create_in_st AES128_GCM = create_in_aes_gcm Vale_AES128
let create_in_aes256_gcm: create_in_st AES256_GCM = create_in_aes_gcm Vale_AES256
let create_in #a r dst k =
match a with
| AES128_GCM -> create_in_aes128_gcm r dst k
| AES256_GCM -> create_in_aes256_gcm r dst k
| CHACHA20_POLY1305 -> create_in_chacha20_poly1305 r dst k
| _ -> UnsupportedAlgorithm
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
inline_for_extraction noextract
let alloca_chacha20_poly1305: alloca_st CHACHA20_POLY1305 =
fun k ->
let h0 = ST.get () in
let ek = B.alloca 0uy 32ul in
let p = B.alloca (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.loc_none h0 h3;
p
#pop-options
inline_for_extraction noextract
let alloca_aes_gcm (i: vale_impl):
alloca_st (alg_of_vale_impl i) =
fun k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
let ek = B.alloca 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.alloca (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
p
inline_for_extraction noextract
let alloca_aes128_gcm: alloca_st AES128_GCM =
alloca_aes_gcm Vale_AES128
inline_for_extraction noextract
let alloca_aes256_gcm: alloca_st AES256_GCM =
alloca_aes_gcm Vale_AES256
let alloca #a k =
match a with
| AES128_GCM -> alloca_aes128_gcm k
| AES256_GCM -> alloca_aes256_gcm k
| CHACHA20_POLY1305 -> alloca_chacha20_poly1305 k
inline_for_extraction noextract
let aes_gcm_encrypt (i: vale_impl):
Vale.Wrapper.X64.GCMencryptOpt.encrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMencryptOpt.gcm128_encrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMencryptOpt256.gcm256_encrypt_opt_stdcall
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties.slice_slice'"
inline_for_extraction noextract
let encrypt_aes_gcm (i: vale_impl): encrypt_st (alg_of_vale_impl i) =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if B.is_null s then
InvalidKey
else
let a = alg_of_vale_impl i in
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len = 0ul then
InvalidIVLength
else
let open LowStar.BufferOps in
let Ek _ kv ek = !*s in
assert (
let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.AES_s.is_aes_key_LE (vale_alg_of_alg a) k_w);
push_frame();
let scratch_b = B.sub ek (concrete_xkey_len i) 176ul in
let ek = B.sub ek 0ul (concrete_xkey_len i) in
let keys_b = B.sub ek 0ul (key_offset i) in
let hkeys_b = B.sub ek (key_offset i) 128ul in
let h0 = get() in
// The iv can be arbitrary length, hence we need to allocate a new one to perform the hashing
let tmp_iv = B.alloca 0uy 16ul in
// There is no SMTPat on le_bytes_to_seq_quad32_to_bytes and the converse,
// so we need an explicit lemma
let lemma_hkeys_reqs () : Lemma
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.OptPublic.hkeys_reqs_pub
(Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 hkeys_b)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))))
= let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
let hkeys_quad = Vale.AES.OptPublic.get_hkeys_reqs (Vale.Def.Types_s.reverse_bytes_quad32 (
Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))) in
let hkeys = Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 (Vale.Def.Types_s.le_seq_quad32_to_bytes hkeys_quad) in
assert (Seq.equal (B.as_seq h0 hkeys_b) hkeys);
calc (==) {
Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 hkeys);
(==) { Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes hkeys_quad }
hkeys_quad;
}
in lemma_hkeys_reqs ();
// We perform the hashing of the iv. The extra buffer and the hashed iv are the same
Vale.Wrapper.X64.GCM_IV.compute_iv (vale_alg_of_alg a)
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w )
iv iv_len
tmp_iv tmp_iv
hkeys_b;
let h0 = get() in
aes_gcm_encrypt i
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w)
(Ghost.hide (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv)))
plain
(uint32_to_uint64 plain_len)
ad
(uint32_to_uint64 ad_len)
tmp_iv
cipher
tag
keys_b
hkeys_b
scratch_b;
let h1 = get() in
// This assert is needed for z3 to pick up sequence equality for ciphertext
// and tag. It could be avoided if the spec returned both instead of appending them
assert (
let kv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (G.reveal kv) in
let iv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv) in
// `ad` is called `auth` in Vale world; "additional data", "authenticated
// data", potato, potato
let ad_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 ad) in
let plain_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 plain) in
let cipher_nat, tag_nat =
Vale.AES.GCM_s.gcm_encrypt_LE (vale_alg_of_alg a) kv_nat iv_nat plain_nat ad_nat
in
Seq.equal (B.as_seq h1 cipher) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 cipher_nat) /\
Seq.equal (B.as_seq h1 tag) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 tag_nat));
pop_frame();
Success
let encrypt_aes128_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES128_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES128 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt_aes256_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES256_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES256 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt #a s iv iv_len ad ad_len plain plain_len cipher tag =
if B.is_null s then
InvalidKey
else
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
match i with
| Vale_AES128 ->
encrypt_aes128_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Vale_AES256 ->
encrypt_aes256_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Hacl_CHACHA20 ->
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len <> 12ul then
InvalidIVLength
else begin
// Length restrictions
assert_norm (pow2 31 + pow2 32 / 64 <= pow2 32 - 1);
EverCrypt.Chacha20Poly1305.aead_encrypt
ek iv ad_len ad plain_len plain cipher tag;
Success
end
inline_for_extraction noextract
let encrypt_expand_aes_gcm (i: vale_impl): encrypt_expand_st false (alg_of_vale_impl i) =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s (alg_of_vale_impl i)) = alloca k in
let r = encrypt_aes_gcm i s iv iv_len ad ad_len plain plain_len cipher tag in
assert(r == Success);
pop_frame ();
Success
let encrypt_expand_aes128_gcm_no_check : encrypt_expand_st false AES128_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale"
let encrypt_expand_aes256_gcm_no_check : encrypt_expand_st false AES256_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len plain plain_len cipher tag
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale"
let encrypt_expand_aes128_gcm : encrypt_expand_st true AES128_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then
encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else
UnsupportedAlgorithm
else
UnsupportedAlgorithm | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.AEAD.encrypt_expand_st true Spec.Agile.AEAD.AES256_GCM | Prims.Tot | [
"total"
] | [] | [
"LowStar.Buffer.buffer",
"EverCrypt.CTR.Keys.uint8",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.Integers.op_Greater_Equals",
"FStar.Integers.Signed",
"FStar.Integers.Winfinite",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"Spec.Agile.AEAD.key_length",
"Spec.Agile.AEAD.AES256_GCM",
"EverCrypt.AEAD.iv_p",
"FStar.UInt32.t",
"Prims.l_and",
"FStar.Integers.within_bounds",
"FStar.Integers.Unsigned",
"FStar.Integers.W32",
"FStar.Integers.v",
"FStar.Integers.op_Greater",
"EverCrypt.AEAD.ad_p",
"FStar.Integers.op_Less_Equals",
"Prims.pow2",
"EverCrypt.AEAD.plain_p",
"Spec.Agile.AEAD.max_length",
"Prims.nat",
"Spec.Agile.AEAD.tag_length",
"EverCrypt.TargetConfig.hacl_can_compile_vale",
"Prims.op_AmpAmp",
"EverCrypt.AEAD.encrypt_expand_aes_gcm",
"Spec.Cipher.Expansion.Vale_AES256",
"EverCrypt.Error.error_code",
"Prims.bool",
"EverCrypt.Error.UnsupportedAlgorithm",
"EverCrypt.AutoConfig2.has_aesni",
"EverCrypt.AutoConfig2.has_movbe",
"EverCrypt.AutoConfig2.has_sse",
"EverCrypt.AutoConfig2.has_avx",
"EverCrypt.AutoConfig2.has_pclmulqdq",
"EverCrypt.AEAD.encrypt_expand_st"
] | [] | false | false | false | false | false | let encrypt_expand_aes256_gcm:encrypt_expand_st true AES256_GCM =
| fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale
then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx () in
let has_sse = EverCrypt.AutoConfig2.has_sse () in
let has_movbe = EverCrypt.AutoConfig2.has_movbe () in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe)
then encrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len plain plain_len cipher tag
else UnsupportedAlgorithm
else UnsupportedAlgorithm | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.encrypt_expand_aes128_gcm | val encrypt_expand_aes128_gcm: encrypt_expand_st true AES128_GCM | val encrypt_expand_aes128_gcm: encrypt_expand_st true AES128_GCM | let encrypt_expand_aes128_gcm : encrypt_expand_st true AES128_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then
encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else
UnsupportedAlgorithm
else
UnsupportedAlgorithm | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 24,
"end_line": 397,
"start_col": 0,
"start_line": 384
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success
#pop-options
inline_for_extraction noextract
let create_in_aes_gcm (i: vale_impl):
create_in_st (alg_of_vale_impl i) =
fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale then (
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then (
let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success
) else
UnsupportedAlgorithm
) else
UnsupportedAlgorithm
let create_in_aes128_gcm: create_in_st AES128_GCM = create_in_aes_gcm Vale_AES128
let create_in_aes256_gcm: create_in_st AES256_GCM = create_in_aes_gcm Vale_AES256
let create_in #a r dst k =
match a with
| AES128_GCM -> create_in_aes128_gcm r dst k
| AES256_GCM -> create_in_aes256_gcm r dst k
| CHACHA20_POLY1305 -> create_in_chacha20_poly1305 r dst k
| _ -> UnsupportedAlgorithm
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
inline_for_extraction noextract
let alloca_chacha20_poly1305: alloca_st CHACHA20_POLY1305 =
fun k ->
let h0 = ST.get () in
let ek = B.alloca 0uy 32ul in
let p = B.alloca (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.loc_none h0 h3;
p
#pop-options
inline_for_extraction noextract
let alloca_aes_gcm (i: vale_impl):
alloca_st (alg_of_vale_impl i) =
fun k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
let ek = B.alloca 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.alloca (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
p
inline_for_extraction noextract
let alloca_aes128_gcm: alloca_st AES128_GCM =
alloca_aes_gcm Vale_AES128
inline_for_extraction noextract
let alloca_aes256_gcm: alloca_st AES256_GCM =
alloca_aes_gcm Vale_AES256
let alloca #a k =
match a with
| AES128_GCM -> alloca_aes128_gcm k
| AES256_GCM -> alloca_aes256_gcm k
| CHACHA20_POLY1305 -> alloca_chacha20_poly1305 k
inline_for_extraction noextract
let aes_gcm_encrypt (i: vale_impl):
Vale.Wrapper.X64.GCMencryptOpt.encrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMencryptOpt.gcm128_encrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMencryptOpt256.gcm256_encrypt_opt_stdcall
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties.slice_slice'"
inline_for_extraction noextract
let encrypt_aes_gcm (i: vale_impl): encrypt_st (alg_of_vale_impl i) =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if B.is_null s then
InvalidKey
else
let a = alg_of_vale_impl i in
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len = 0ul then
InvalidIVLength
else
let open LowStar.BufferOps in
let Ek _ kv ek = !*s in
assert (
let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.AES_s.is_aes_key_LE (vale_alg_of_alg a) k_w);
push_frame();
let scratch_b = B.sub ek (concrete_xkey_len i) 176ul in
let ek = B.sub ek 0ul (concrete_xkey_len i) in
let keys_b = B.sub ek 0ul (key_offset i) in
let hkeys_b = B.sub ek (key_offset i) 128ul in
let h0 = get() in
// The iv can be arbitrary length, hence we need to allocate a new one to perform the hashing
let tmp_iv = B.alloca 0uy 16ul in
// There is no SMTPat on le_bytes_to_seq_quad32_to_bytes and the converse,
// so we need an explicit lemma
let lemma_hkeys_reqs () : Lemma
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.OptPublic.hkeys_reqs_pub
(Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 hkeys_b)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))))
= let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
let hkeys_quad = Vale.AES.OptPublic.get_hkeys_reqs (Vale.Def.Types_s.reverse_bytes_quad32 (
Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))) in
let hkeys = Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 (Vale.Def.Types_s.le_seq_quad32_to_bytes hkeys_quad) in
assert (Seq.equal (B.as_seq h0 hkeys_b) hkeys);
calc (==) {
Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 hkeys);
(==) { Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes hkeys_quad }
hkeys_quad;
}
in lemma_hkeys_reqs ();
// We perform the hashing of the iv. The extra buffer and the hashed iv are the same
Vale.Wrapper.X64.GCM_IV.compute_iv (vale_alg_of_alg a)
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w )
iv iv_len
tmp_iv tmp_iv
hkeys_b;
let h0 = get() in
aes_gcm_encrypt i
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w)
(Ghost.hide (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv)))
plain
(uint32_to_uint64 plain_len)
ad
(uint32_to_uint64 ad_len)
tmp_iv
cipher
tag
keys_b
hkeys_b
scratch_b;
let h1 = get() in
// This assert is needed for z3 to pick up sequence equality for ciphertext
// and tag. It could be avoided if the spec returned both instead of appending them
assert (
let kv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (G.reveal kv) in
let iv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv) in
// `ad` is called `auth` in Vale world; "additional data", "authenticated
// data", potato, potato
let ad_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 ad) in
let plain_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 plain) in
let cipher_nat, tag_nat =
Vale.AES.GCM_s.gcm_encrypt_LE (vale_alg_of_alg a) kv_nat iv_nat plain_nat ad_nat
in
Seq.equal (B.as_seq h1 cipher) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 cipher_nat) /\
Seq.equal (B.as_seq h1 tag) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 tag_nat));
pop_frame();
Success
let encrypt_aes128_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES128_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES128 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt_aes256_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES256_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES256 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt #a s iv iv_len ad ad_len plain plain_len cipher tag =
if B.is_null s then
InvalidKey
else
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
match i with
| Vale_AES128 ->
encrypt_aes128_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Vale_AES256 ->
encrypt_aes256_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Hacl_CHACHA20 ->
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len <> 12ul then
InvalidIVLength
else begin
// Length restrictions
assert_norm (pow2 31 + pow2 32 / 64 <= pow2 32 - 1);
EverCrypt.Chacha20Poly1305.aead_encrypt
ek iv ad_len ad plain_len plain cipher tag;
Success
end
inline_for_extraction noextract
let encrypt_expand_aes_gcm (i: vale_impl): encrypt_expand_st false (alg_of_vale_impl i) =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s (alg_of_vale_impl i)) = alloca k in
let r = encrypt_aes_gcm i s iv iv_len ad ad_len plain plain_len cipher tag in
assert(r == Success);
pop_frame ();
Success
let encrypt_expand_aes128_gcm_no_check : encrypt_expand_st false AES128_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale"
let encrypt_expand_aes256_gcm_no_check : encrypt_expand_st false AES256_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len plain plain_len cipher tag
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale" | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.AEAD.encrypt_expand_st true Spec.Agile.AEAD.AES128_GCM | Prims.Tot | [
"total"
] | [] | [
"LowStar.Buffer.buffer",
"EverCrypt.CTR.Keys.uint8",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.Integers.op_Greater_Equals",
"FStar.Integers.Signed",
"FStar.Integers.Winfinite",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"Spec.Agile.AEAD.key_length",
"Spec.Agile.AEAD.AES128_GCM",
"EverCrypt.AEAD.iv_p",
"FStar.UInt32.t",
"Prims.l_and",
"FStar.Integers.within_bounds",
"FStar.Integers.Unsigned",
"FStar.Integers.W32",
"FStar.Integers.v",
"FStar.Integers.op_Greater",
"EverCrypt.AEAD.ad_p",
"FStar.Integers.op_Less_Equals",
"Prims.pow2",
"EverCrypt.AEAD.plain_p",
"Spec.Agile.AEAD.max_length",
"Prims.nat",
"Spec.Agile.AEAD.tag_length",
"EverCrypt.TargetConfig.hacl_can_compile_vale",
"Prims.op_AmpAmp",
"EverCrypt.AEAD.encrypt_expand_aes_gcm",
"Spec.Cipher.Expansion.Vale_AES128",
"EverCrypt.Error.error_code",
"Prims.bool",
"EverCrypt.Error.UnsupportedAlgorithm",
"EverCrypt.AutoConfig2.has_aesni",
"EverCrypt.AutoConfig2.has_movbe",
"EverCrypt.AutoConfig2.has_sse",
"EverCrypt.AutoConfig2.has_avx",
"EverCrypt.AutoConfig2.has_pclmulqdq",
"EverCrypt.AEAD.encrypt_expand_st"
] | [] | false | false | false | false | false | let encrypt_expand_aes128_gcm:encrypt_expand_st true AES128_GCM =
| fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale
then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx () in
let has_sse = EverCrypt.AutoConfig2.has_sse () in
let has_movbe = EverCrypt.AutoConfig2.has_movbe () in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe)
then encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else UnsupportedAlgorithm
else UnsupportedAlgorithm | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.contents_list | val contents_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost (list t)
(requires (valid_list p h sl pos pos'))
(ensures (fun _ -> True))
(decreases (U32.v pos' - U32.v pos)) | val contents_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost (list t)
(requires (valid_list p h sl pos pos'))
(ensures (fun _ -> True))
(decreases (U32.v pos' - U32.v pos)) | let rec contents_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost (list t)
(requires (valid_list p h sl pos pos'))
(ensures (fun _ -> True))
(decreases (U32.v pos' - U32.v pos))
= valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos' | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 79,
"end_line": 565,
"start_col": 0,
"start_line": 548
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x))
let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos)
let get_valid_pos_post
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (
let pos' = get_valid_pos p h sl pos in
valid_pos p h sl pos pos'
))
[SMTPat (get_valid_pos p h sl pos)]
= ()
let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
= valid_exact' p h s pos pos'
let valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
= assert_norm (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
let contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost t
(requires (valid_exact p h s pos pos'))
(ensures (fun _ -> True))
= valid_exact_equiv p h s pos pos' ;
contents_exact' p h s pos pos'
let contents_exact_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_exact p h s pos pos'))
(ensures (valid_exact p h s pos pos' /\ valid_exact' p h s pos pos' /\ contents_exact p h s pos pos' == contents_exact' p h s pos pos'))
= valid_exact_equiv p h s pos pos' ;
assert_norm (contents_exact p h s pos pos' == contents_exact' p h s pos pos')
let gaccessor_prop
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: GTot Type0
= gaccessor_prop' f
let gaccessor_prop_equiv
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: Lemma
(gaccessor_prop f <==> gaccessor_prop' f)
= ()
let gaccessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (gaccessor p p (clens_id _))
= gaccessor_id' p
let gaccessor_id_eq
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(gaccessor_id p input == gaccessor_id' p input)
= ()
let gaccessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (gaccessor p1 p2 cl')
= gaccessor_ext' g cl' sq
let gaccessor_ext_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
(input: bytes)
: Lemma
(gaccessor_ext g cl sq input == gaccessor_ext' g cl sq input)
= ()
let gaccessor_compose_injective
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ injective_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
assert (injective_precond p2 sl_ sl'_)
let gaccessor_compose_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (k1.parser_kind_subkind == Some ParserStrong /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ no_lookahead_on_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
parse_strong_prefix p1 sl sl';
assert (injective_precond p1 sl sl');
assert (injective_precond p2 sl_ sl'_)
[@"opaque_to_smt"]
let gaccessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
: Tot (gaccessor p1 p3 (clens_compose cl12 cl23))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_injective a12 a23 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_no_lookahead a12 a23 x));
gaccessor_compose' a12 a23
let gaccessor_compose_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(input: bytes)
: Lemma
(gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
= assert_norm (gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
[@"opaque_to_smt"]
let slice_access
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun pos' -> True))
= valid_facts p1 h sl pos;
slice_access' h g sl pos
let slice_access_eq
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (
valid' p1 h sl pos /\
cl.clens_cond (contents' p1 h sl pos) /\
slice_access h g sl pos == slice_access' h g sl pos
))
= valid_facts p1 h sl pos;
assert_norm (slice_access h g sl pos == slice_access' h g sl pos)
let slice_access_frame_strong
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
k1.parser_kind_subkind == Some ParserStrong /\
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos) /\
B.modifies l h h' /\
B.loc_disjoint l (loc_slice_from_to sl pos (get_valid_pos p1 h sl pos))
))
(ensures (
valid p1 h' sl pos /\
cl.clens_cond (contents p1 h' sl pos) /\
slice_access h' g sl pos == slice_access h g sl pos
))
[SMTPatOr [
[SMTPat (slice_access h g sl pos); SMTPat (B.modifies l h h')];
[SMTPat (slice_access h' g sl pos); SMTPat (B.modifies l h h')];
]]
= valid_facts p1 h sl pos;
valid_facts p1 h' sl pos;
slice_access_eq h g sl pos;
slice_access_eq h' g sl pos;
let pos2 = get_valid_pos p1 h sl pos in
parse_strong_prefix p1 (bytes_of_slice_from h sl pos) (bytes_of_slice_from_to h sl pos pos2);
B.modifies_buffer_from_to_elim sl.base pos (get_valid_pos p1 h sl pos) l h h' ;
parse_strong_prefix p1 (bytes_of_slice_from_to h' sl pos pos2) (bytes_of_slice_from h' sl pos)
let rec valid_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
(decreases (U32.v pos' - U32.v pos))
= k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))
let rec valid_list_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_list p h sl pos pos' <==> (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))))
= assert_norm (valid_list p h sl pos pos' <==> (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
)))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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: LowParse.Spec.Base.parser k t ->
h: FStar.Monotonic.HyperStack.mem ->
sl: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> Prims.Ghost (Prims.list t) | Prims.Ghost | [
""
] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.op_Equality",
"Prims.Nil",
"Prims.bool",
"Prims.Cons",
"LowParse.Low.Base.Spec.contents",
"LowParse.Low.Base.Spec.contents_list",
"LowParse.Low.Base.Spec.get_valid_pos",
"Prims.list",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_list_equiv",
"LowParse.Low.Base.Spec.valid_list",
"Prims.l_True"
] | [
"recursion"
] | false | false | false | false | false | let rec contents_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos pos': U32.t)
: Ghost (list t)
(requires (valid_list p h sl pos pos'))
(ensures (fun _ -> True))
(decreases (U32.v pos' - U32.v pos)) =
| valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos' | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.gaccessor_ext | val gaccessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (gaccessor p1 p2 cl') | val gaccessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (gaccessor p1 p2 cl') | let gaccessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (gaccessor p1 p2 cl')
= gaccessor_ext' g cl' sq | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 25,
"end_line": 294,
"start_col": 0,
"start_line": 282
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x))
let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos)
let get_valid_pos_post
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (
let pos' = get_valid_pos p h sl pos in
valid_pos p h sl pos pos'
))
[SMTPat (get_valid_pos p h sl pos)]
= ()
let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
= valid_exact' p h s pos pos'
let valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
= assert_norm (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
let contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost t
(requires (valid_exact p h s pos pos'))
(ensures (fun _ -> True))
= valid_exact_equiv p h s pos pos' ;
contents_exact' p h s pos pos'
let contents_exact_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_exact p h s pos pos'))
(ensures (valid_exact p h s pos pos' /\ valid_exact' p h s pos pos' /\ contents_exact p h s pos pos' == contents_exact' p h s pos pos'))
= valid_exact_equiv p h s pos pos' ;
assert_norm (contents_exact p h s pos pos' == contents_exact' p h s pos pos')
let gaccessor_prop
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: GTot Type0
= gaccessor_prop' f
let gaccessor_prop_equiv
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: Lemma
(gaccessor_prop f <==> gaccessor_prop' f)
= ()
let gaccessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (gaccessor p p (clens_id _))
= gaccessor_id' p
let gaccessor_id_eq
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(gaccessor_id p input == gaccessor_id' p input)
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
g: LowParse.Low.Base.Spec.gaccessor p1 p2 cl ->
cl': LowParse.Low.Base.Spec.clens t1 t2 ->
sq: Prims.squash (LowParse.Low.Base.Spec.clens_eq cl cl')
-> LowParse.Low.Base.Spec.gaccessor p1 p2 cl' | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.Spec.clens",
"LowParse.Low.Base.Spec.gaccessor",
"Prims.squash",
"LowParse.Low.Base.Spec.clens_eq",
"LowParse.Low.Base.Spec.gaccessor_ext'"
] | [] | false | false | false | false | false | let gaccessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (gaccessor p1 p2 cl') =
| gaccessor_ext' g cl' sq | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.slice_access | val slice_access
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun pos' -> True)) | val slice_access
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun pos' -> True)) | let slice_access
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun pos' -> True))
= valid_facts p1 h sl pos;
slice_access' h g sl pos | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 26,
"end_line": 418,
"start_col": 0,
"start_line": 398
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x))
let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos)
let get_valid_pos_post
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (
let pos' = get_valid_pos p h sl pos in
valid_pos p h sl pos pos'
))
[SMTPat (get_valid_pos p h sl pos)]
= ()
let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
= valid_exact' p h s pos pos'
let valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
= assert_norm (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
let contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost t
(requires (valid_exact p h s pos pos'))
(ensures (fun _ -> True))
= valid_exact_equiv p h s pos pos' ;
contents_exact' p h s pos pos'
let contents_exact_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_exact p h s pos pos'))
(ensures (valid_exact p h s pos pos' /\ valid_exact' p h s pos pos' /\ contents_exact p h s pos pos' == contents_exact' p h s pos pos'))
= valid_exact_equiv p h s pos pos' ;
assert_norm (contents_exact p h s pos pos' == contents_exact' p h s pos pos')
let gaccessor_prop
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: GTot Type0
= gaccessor_prop' f
let gaccessor_prop_equiv
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: Lemma
(gaccessor_prop f <==> gaccessor_prop' f)
= ()
let gaccessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (gaccessor p p (clens_id _))
= gaccessor_id' p
let gaccessor_id_eq
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(gaccessor_id p input == gaccessor_id' p input)
= ()
let gaccessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (gaccessor p1 p2 cl')
= gaccessor_ext' g cl' sq
let gaccessor_ext_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
(input: bytes)
: Lemma
(gaccessor_ext g cl sq input == gaccessor_ext' g cl sq input)
= ()
let gaccessor_compose_injective
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ injective_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
assert (injective_precond p2 sl_ sl'_)
let gaccessor_compose_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (k1.parser_kind_subkind == Some ParserStrong /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ no_lookahead_on_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
parse_strong_prefix p1 sl sl';
assert (injective_precond p1 sl sl');
assert (injective_precond p2 sl_ sl'_)
[@"opaque_to_smt"]
let gaccessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
: Tot (gaccessor p1 p3 (clens_compose cl12 cl23))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_injective a12 a23 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_no_lookahead a12 a23 x));
gaccessor_compose' a12 a23
let gaccessor_compose_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(input: bytes)
: Lemma
(gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
= assert_norm (gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h: FStar.Monotonic.HyperStack.mem ->
g: LowParse.Low.Base.Spec.gaccessor p1 p2 cl ->
sl: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> Prims.Ghost FStar.UInt32.t | Prims.Ghost | [] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.Spec.clens",
"LowParse.Low.Base.Spec.gaccessor",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.Base.Spec.slice_access'",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"Prims.l_and",
"LowParse.Low.Base.Spec.valid",
"LowParse.Low.Base.Spec.__proj__Mkclens__item__clens_cond",
"LowParse.Low.Base.Spec.contents",
"Prims.l_True"
] | [] | false | false | false | false | false | let slice_access
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p1 h sl pos /\ cl.clens_cond (contents p1 h sl pos)))
(ensures (fun pos' -> True)) =
| valid_facts p1 h sl pos;
slice_access' h g sl pos | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.gaccessor_compose_no_lookahead | val gaccessor_compose_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (k1.parser_kind_subkind == Some ParserStrong /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ no_lookahead_on_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl')) | val gaccessor_compose_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (k1.parser_kind_subkind == Some ParserStrong /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ no_lookahead_on_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl')) | let gaccessor_compose_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (k1.parser_kind_subkind == Some ParserStrong /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ no_lookahead_on_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
parse_strong_prefix p1 sl sl';
assert (injective_precond p1 sl sl');
assert (injective_precond p2 sl_ sl'_) | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 40,
"end_line": 356,
"start_col": 0,
"start_line": 334
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x))
let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos)
let get_valid_pos_post
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (
let pos' = get_valid_pos p h sl pos in
valid_pos p h sl pos pos'
))
[SMTPat (get_valid_pos p h sl pos)]
= ()
let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
= valid_exact' p h s pos pos'
let valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
= assert_norm (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
let contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost t
(requires (valid_exact p h s pos pos'))
(ensures (fun _ -> True))
= valid_exact_equiv p h s pos pos' ;
contents_exact' p h s pos pos'
let contents_exact_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_exact p h s pos pos'))
(ensures (valid_exact p h s pos pos' /\ valid_exact' p h s pos pos' /\ contents_exact p h s pos pos' == contents_exact' p h s pos pos'))
= valid_exact_equiv p h s pos pos' ;
assert_norm (contents_exact p h s pos pos' == contents_exact' p h s pos pos')
let gaccessor_prop
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: GTot Type0
= gaccessor_prop' f
let gaccessor_prop_equiv
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: Lemma
(gaccessor_prop f <==> gaccessor_prop' f)
= ()
let gaccessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (gaccessor p p (clens_id _))
= gaccessor_id' p
let gaccessor_id_eq
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(gaccessor_id p input == gaccessor_id' p input)
= ()
let gaccessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (gaccessor p1 p2 cl')
= gaccessor_ext' g cl' sq
let gaccessor_ext_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
(input: bytes)
: Lemma
(gaccessor_ext g cl sq input == gaccessor_ext' g cl sq input)
= ()
let gaccessor_compose_injective
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ injective_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
assert (injective_precond p2 sl_ sl'_) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 |
a12: LowParse.Low.Base.Spec.gaccessor p1 p2 cl12 ->
a23: LowParse.Low.Base.Spec.gaccessor p2 p3 cl23 ->
sl: LowParse.Bytes.bytes ->
sl': LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(requires
Mkparser_kind'?.parser_kind_subkind k1 ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
LowParse.Low.Base.Spec.gaccessor_pre p1
p3
(LowParse.Low.Base.Spec.clens_compose cl12 cl23)
sl /\
LowParse.Low.Base.Spec.gaccessor_pre p1
p3
(LowParse.Low.Base.Spec.clens_compose cl12 cl23)
sl' /\ LowParse.Spec.Base.no_lookahead_on_precond p1 sl sl')
(ensures
LowParse.Low.Base.Spec.gaccessor_compose' a12 a23 sl ==
LowParse.Low.Base.Spec.gaccessor_compose' a12 a23 sl') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.Spec.clens",
"LowParse.Low.Base.Spec.gaccessor",
"LowParse.Bytes.bytes",
"Prims._assert",
"LowParse.Spec.Base.injective_precond",
"Prims.unit",
"LowParse.Spec.Base.parse_strong_prefix",
"FStar.Seq.Base.seq",
"LowParse.Bytes.byte",
"FStar.Seq.Base.slice",
"FStar.Seq.Base.length",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Low.Base.Spec.gaccessor_pre",
"LowParse.Low.Base.Spec.clens_compose",
"LowParse.Spec.Base.no_lookahead_on_precond",
"Prims.squash",
"Prims.nat",
"LowParse.Low.Base.Spec.gaccessor_compose'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let gaccessor_compose_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires
(k1.parser_kind_subkind == Some ParserStrong /\
gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\
gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ no_lookahead_on_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl')) =
| let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
parse_strong_prefix p1 sl sl';
assert (injective_precond p1 sl sl');
assert (injective_precond p2 sl_ sl'_) | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.gaccessor_compose_injective | val gaccessor_compose_injective
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ injective_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl')) | val gaccessor_compose_injective
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ injective_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl')) | let gaccessor_compose_injective
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ injective_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
assert (injective_precond p2 sl_ sl'_) | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 40,
"end_line": 332,
"start_col": 0,
"start_line": 312
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x))
let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos)
let get_valid_pos_post
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (
let pos' = get_valid_pos p h sl pos in
valid_pos p h sl pos pos'
))
[SMTPat (get_valid_pos p h sl pos)]
= ()
let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
= valid_exact' p h s pos pos'
let valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
= assert_norm (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
let contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost t
(requires (valid_exact p h s pos pos'))
(ensures (fun _ -> True))
= valid_exact_equiv p h s pos pos' ;
contents_exact' p h s pos pos'
let contents_exact_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_exact p h s pos pos'))
(ensures (valid_exact p h s pos pos' /\ valid_exact' p h s pos pos' /\ contents_exact p h s pos pos' == contents_exact' p h s pos pos'))
= valid_exact_equiv p h s pos pos' ;
assert_norm (contents_exact p h s pos pos' == contents_exact' p h s pos pos')
let gaccessor_prop
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: GTot Type0
= gaccessor_prop' f
let gaccessor_prop_equiv
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: Lemma
(gaccessor_prop f <==> gaccessor_prop' f)
= ()
let gaccessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (gaccessor p p (clens_id _))
= gaccessor_id' p
let gaccessor_id_eq
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(gaccessor_id p input == gaccessor_id' p input)
= ()
let gaccessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (gaccessor p1 p2 cl')
= gaccessor_ext' g cl' sq
let gaccessor_ext_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
(input: bytes)
: Lemma
(gaccessor_ext g cl sq input == gaccessor_ext' g cl sq input)
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 |
a12: LowParse.Low.Base.Spec.gaccessor p1 p2 cl12 ->
a23: LowParse.Low.Base.Spec.gaccessor p2 p3 cl23 ->
sl: LowParse.Bytes.bytes ->
sl': LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.Spec.gaccessor_pre p1
p3
(LowParse.Low.Base.Spec.clens_compose cl12 cl23)
sl /\
LowParse.Low.Base.Spec.gaccessor_pre p1
p3
(LowParse.Low.Base.Spec.clens_compose cl12 cl23)
sl' /\ LowParse.Spec.Base.injective_precond p1 sl sl')
(ensures
LowParse.Low.Base.Spec.gaccessor_compose' a12 a23 sl ==
LowParse.Low.Base.Spec.gaccessor_compose' a12 a23 sl') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.Spec.clens",
"LowParse.Low.Base.Spec.gaccessor",
"LowParse.Bytes.bytes",
"Prims._assert",
"LowParse.Spec.Base.injective_precond",
"FStar.Seq.Base.seq",
"LowParse.Bytes.byte",
"FStar.Seq.Base.slice",
"FStar.Seq.Base.length",
"Prims.unit",
"Prims.l_and",
"LowParse.Low.Base.Spec.gaccessor_pre",
"LowParse.Low.Base.Spec.clens_compose",
"Prims.squash",
"Prims.eq2",
"Prims.nat",
"LowParse.Low.Base.Spec.gaccessor_compose'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let gaccessor_compose_injective
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires
(gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\
gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ injective_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl')) =
| let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
assert (injective_precond p2 sl_ sl'_) | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.valid_list | val valid_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
(decreases (U32.v pos' - U32.v pos)) | val valid_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
(decreases (U32.v pos' - U32.v pos)) | let rec valid_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
(decreases (U32.v pos' - U32.v pos))
= k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
)) | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 4,
"end_line": 509,
"start_col": 0,
"start_line": 487
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x))
let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos)
let get_valid_pos_post
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (
let pos' = get_valid_pos p h sl pos in
valid_pos p h sl pos pos'
))
[SMTPat (get_valid_pos p h sl pos)]
= ()
let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
= valid_exact' p h s pos pos'
let valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
= assert_norm (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
let contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost t
(requires (valid_exact p h s pos pos'))
(ensures (fun _ -> True))
= valid_exact_equiv p h s pos pos' ;
contents_exact' p h s pos pos'
let contents_exact_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_exact p h s pos pos'))
(ensures (valid_exact p h s pos pos' /\ valid_exact' p h s pos pos' /\ contents_exact p h s pos pos' == contents_exact' p h s pos pos'))
= valid_exact_equiv p h s pos pos' ;
assert_norm (contents_exact p h s pos pos' == contents_exact' p h s pos pos')
let gaccessor_prop
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: GTot Type0
= gaccessor_prop' f
let gaccessor_prop_equiv
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: Lemma
(gaccessor_prop f <==> gaccessor_prop' f)
= ()
let gaccessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (gaccessor p p (clens_id _))
= gaccessor_id' p
let gaccessor_id_eq
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(gaccessor_id p input == gaccessor_id' p input)
= ()
let gaccessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (gaccessor p1 p2 cl')
= gaccessor_ext' g cl' sq
let gaccessor_ext_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
(input: bytes)
: Lemma
(gaccessor_ext g cl sq input == gaccessor_ext' g cl sq input)
= ()
let gaccessor_compose_injective
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ injective_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
assert (injective_precond p2 sl_ sl'_)
let gaccessor_compose_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (k1.parser_kind_subkind == Some ParserStrong /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ no_lookahead_on_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
parse_strong_prefix p1 sl sl';
assert (injective_precond p1 sl sl');
assert (injective_precond p2 sl_ sl'_)
[@"opaque_to_smt"]
let gaccessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
: Tot (gaccessor p1 p3 (clens_compose cl12 cl23))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_injective a12 a23 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_no_lookahead a12 a23 x));
gaccessor_compose' a12 a23
let gaccessor_compose_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(input: bytes)
: Lemma
(gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
= assert_norm (gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
[@"opaque_to_smt"]
let slice_access
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun pos' -> True))
= valid_facts p1 h sl pos;
slice_access' h g sl pos
let slice_access_eq
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (
valid' p1 h sl pos /\
cl.clens_cond (contents' p1 h sl pos) /\
slice_access h g sl pos == slice_access' h g sl pos
))
= valid_facts p1 h sl pos;
assert_norm (slice_access h g sl pos == slice_access' h g sl pos)
let slice_access_frame_strong
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
k1.parser_kind_subkind == Some ParserStrong /\
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos) /\
B.modifies l h h' /\
B.loc_disjoint l (loc_slice_from_to sl pos (get_valid_pos p1 h sl pos))
))
(ensures (
valid p1 h' sl pos /\
cl.clens_cond (contents p1 h' sl pos) /\
slice_access h' g sl pos == slice_access h g sl pos
))
[SMTPatOr [
[SMTPat (slice_access h g sl pos); SMTPat (B.modifies l h h')];
[SMTPat (slice_access h' g sl pos); SMTPat (B.modifies l h h')];
]]
= valid_facts p1 h sl pos;
valid_facts p1 h' sl pos;
slice_access_eq h g sl pos;
slice_access_eq h' g sl pos;
let pos2 = get_valid_pos p1 h sl pos in
parse_strong_prefix p1 (bytes_of_slice_from h sl pos) (bytes_of_slice_from_to h sl pos pos2);
B.modifies_buffer_from_to_elim sl.base pos (get_valid_pos p1 h sl pos) l h h' ;
parse_strong_prefix p1 (bytes_of_slice_from_to h' sl pos pos2) (bytes_of_slice_from h' sl pos) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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: LowParse.Spec.Base.parser k t ->
h: FStar.Monotonic.HyperStack.mem ->
sl: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> Prims.GTot Type0 | Prims.GTot | [
"",
"sometrivial"
] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"Prims.b2t",
"Prims.op_GreaterThan",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"LowParse.Slice.live_slice",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"LowParse.Slice.__proj__Mkslice__item__len",
"Prims.op_Equality",
"Prims.l_True",
"Prims.bool",
"LowParse.Low.Base.Spec.valid",
"LowParse.Low.Base.Spec.valid_list",
"LowParse.Low.Base.Spec.get_valid_pos",
"Prims.logical"
] | [
"recursion"
] | false | false | false | false | true | let rec valid_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos pos': U32.t)
: GTot Type0 (decreases (U32.v pos' - U32.v pos)) =
| k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_low > 0 /\ live_slice h sl /\
U32.v pos' <= U32.v sl.len /\
(if pos = pos'
then True
else
valid p h sl pos /\
(let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\ valid_list p h sl pos1 pos')) | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.gaccessor_compose_eq | val gaccessor_compose_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(input: bytes)
: Lemma
(gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input) | val gaccessor_compose_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(input: bytes)
: Lemma
(gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input) | let gaccessor_compose_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(input: bytes)
: Lemma
(gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
= assert_norm (gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input) | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 83,
"end_line": 395,
"start_col": 0,
"start_line": 378
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x))
let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos)
let get_valid_pos_post
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (
let pos' = get_valid_pos p h sl pos in
valid_pos p h sl pos pos'
))
[SMTPat (get_valid_pos p h sl pos)]
= ()
let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
= valid_exact' p h s pos pos'
let valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
= assert_norm (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
let contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost t
(requires (valid_exact p h s pos pos'))
(ensures (fun _ -> True))
= valid_exact_equiv p h s pos pos' ;
contents_exact' p h s pos pos'
let contents_exact_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_exact p h s pos pos'))
(ensures (valid_exact p h s pos pos' /\ valid_exact' p h s pos pos' /\ contents_exact p h s pos pos' == contents_exact' p h s pos pos'))
= valid_exact_equiv p h s pos pos' ;
assert_norm (contents_exact p h s pos pos' == contents_exact' p h s pos pos')
let gaccessor_prop
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: GTot Type0
= gaccessor_prop' f
let gaccessor_prop_equiv
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: Lemma
(gaccessor_prop f <==> gaccessor_prop' f)
= ()
let gaccessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (gaccessor p p (clens_id _))
= gaccessor_id' p
let gaccessor_id_eq
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(gaccessor_id p input == gaccessor_id' p input)
= ()
let gaccessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (gaccessor p1 p2 cl')
= gaccessor_ext' g cl' sq
let gaccessor_ext_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
(input: bytes)
: Lemma
(gaccessor_ext g cl sq input == gaccessor_ext' g cl sq input)
= ()
let gaccessor_compose_injective
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ injective_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
assert (injective_precond p2 sl_ sl'_)
let gaccessor_compose_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (k1.parser_kind_subkind == Some ParserStrong /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ no_lookahead_on_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
parse_strong_prefix p1 sl sl';
assert (injective_precond p1 sl sl');
assert (injective_precond p2 sl_ sl'_)
[@"opaque_to_smt"]
let gaccessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
: Tot (gaccessor p1 p3 (clens_compose cl12 cl23))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_injective a12 a23 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_no_lookahead a12 a23 x));
gaccessor_compose' a12 a23 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 |
a12: LowParse.Low.Base.Spec.gaccessor p1 p2 cl12 ->
a23: LowParse.Low.Base.Spec.gaccessor p2 p3 cl23 ->
input: LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(ensures
LowParse.Low.Base.Spec.gaccessor_compose a12 a23 input ==
LowParse.Low.Base.Spec.gaccessor_compose' a12 a23 input) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.Spec.clens",
"LowParse.Low.Base.Spec.gaccessor",
"LowParse.Bytes.bytes",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.nat",
"LowParse.Low.Base.Spec.gaccessor_compose",
"LowParse.Low.Base.Spec.gaccessor_compose'",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let gaccessor_compose_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(input: bytes)
: Lemma (gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input) =
| assert_norm (gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input) | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.serialized_list_length | val serialized_list_length (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (l: list t) : GTot nat | val serialized_list_length (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (l: list t) : GTot nat | let rec serialized_list_length (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (l: list t) : GTot nat =
match l with
| [] -> 0
| x :: q -> serialized_length s x + serialized_list_length s q | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 64,
"end_line": 596,
"start_col": 0,
"start_line": 593
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x))
let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos)
let get_valid_pos_post
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (
let pos' = get_valid_pos p h sl pos in
valid_pos p h sl pos pos'
))
[SMTPat (get_valid_pos p h sl pos)]
= ()
let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
= valid_exact' p h s pos pos'
let valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
= assert_norm (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
let contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost t
(requires (valid_exact p h s pos pos'))
(ensures (fun _ -> True))
= valid_exact_equiv p h s pos pos' ;
contents_exact' p h s pos pos'
let contents_exact_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_exact p h s pos pos'))
(ensures (valid_exact p h s pos pos' /\ valid_exact' p h s pos pos' /\ contents_exact p h s pos pos' == contents_exact' p h s pos pos'))
= valid_exact_equiv p h s pos pos' ;
assert_norm (contents_exact p h s pos pos' == contents_exact' p h s pos pos')
let gaccessor_prop
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: GTot Type0
= gaccessor_prop' f
let gaccessor_prop_equiv
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: Lemma
(gaccessor_prop f <==> gaccessor_prop' f)
= ()
let gaccessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (gaccessor p p (clens_id _))
= gaccessor_id' p
let gaccessor_id_eq
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(gaccessor_id p input == gaccessor_id' p input)
= ()
let gaccessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (gaccessor p1 p2 cl')
= gaccessor_ext' g cl' sq
let gaccessor_ext_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
(input: bytes)
: Lemma
(gaccessor_ext g cl sq input == gaccessor_ext' g cl sq input)
= ()
let gaccessor_compose_injective
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ injective_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
assert (injective_precond p2 sl_ sl'_)
let gaccessor_compose_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (k1.parser_kind_subkind == Some ParserStrong /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ no_lookahead_on_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
parse_strong_prefix p1 sl sl';
assert (injective_precond p1 sl sl');
assert (injective_precond p2 sl_ sl'_)
[@"opaque_to_smt"]
let gaccessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
: Tot (gaccessor p1 p3 (clens_compose cl12 cl23))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_injective a12 a23 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_no_lookahead a12 a23 x));
gaccessor_compose' a12 a23
let gaccessor_compose_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(input: bytes)
: Lemma
(gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
= assert_norm (gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
[@"opaque_to_smt"]
let slice_access
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun pos' -> True))
= valid_facts p1 h sl pos;
slice_access' h g sl pos
let slice_access_eq
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (
valid' p1 h sl pos /\
cl.clens_cond (contents' p1 h sl pos) /\
slice_access h g sl pos == slice_access' h g sl pos
))
= valid_facts p1 h sl pos;
assert_norm (slice_access h g sl pos == slice_access' h g sl pos)
let slice_access_frame_strong
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
k1.parser_kind_subkind == Some ParserStrong /\
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos) /\
B.modifies l h h' /\
B.loc_disjoint l (loc_slice_from_to sl pos (get_valid_pos p1 h sl pos))
))
(ensures (
valid p1 h' sl pos /\
cl.clens_cond (contents p1 h' sl pos) /\
slice_access h' g sl pos == slice_access h g sl pos
))
[SMTPatOr [
[SMTPat (slice_access h g sl pos); SMTPat (B.modifies l h h')];
[SMTPat (slice_access h' g sl pos); SMTPat (B.modifies l h h')];
]]
= valid_facts p1 h sl pos;
valid_facts p1 h' sl pos;
slice_access_eq h g sl pos;
slice_access_eq h' g sl pos;
let pos2 = get_valid_pos p1 h sl pos in
parse_strong_prefix p1 (bytes_of_slice_from h sl pos) (bytes_of_slice_from_to h sl pos pos2);
B.modifies_buffer_from_to_elim sl.base pos (get_valid_pos p1 h sl pos) l h h' ;
parse_strong_prefix p1 (bytes_of_slice_from_to h' sl pos pos2) (bytes_of_slice_from h' sl pos)
let rec valid_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
(decreases (U32.v pos' - U32.v pos))
= k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))
let rec valid_list_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_list p h sl pos pos' <==> (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))))
= assert_norm (valid_list p h sl pos pos' <==> (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))))
let rec contents_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost (list t)
(requires (valid_list p h sl pos pos'))
(ensures (fun _ -> True))
(decreases (U32.v pos' - U32.v pos))
= valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
let contents_list_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h sl pos pos'))
(ensures (contents_list p h sl pos pos' == (
valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
)))
= assert_norm (contents_list p h sl pos pos' == (
valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: LowParse.Spec.Base.serializer p -> l: Prims.list t -> Prims.GTot Prims.nat | Prims.GTot | [
"sometrivial"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.list",
"Prims.op_Addition",
"LowParse.Low.Base.Spec.serialized_length",
"LowParse.Low.Base.Spec.serialized_list_length",
"Prims.nat"
] | [
"recursion"
] | false | false | false | false | false | let rec serialized_list_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(l: list t)
: GTot nat =
| match l with
| [] -> 0
| x :: q -> serialized_length s x + serialized_list_length s q | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.slice_access_eq | val slice_access_eq
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (
valid' p1 h sl pos /\
cl.clens_cond (contents' p1 h sl pos) /\
slice_access h g sl pos == slice_access' h g sl pos
)) | val slice_access_eq
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (
valid' p1 h sl pos /\
cl.clens_cond (contents' p1 h sl pos) /\
slice_access h g sl pos == slice_access' h g sl pos
)) | let slice_access_eq
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (
valid' p1 h sl pos /\
cl.clens_cond (contents' p1 h sl pos) /\
slice_access h g sl pos == slice_access' h g sl pos
))
= valid_facts p1 h sl pos;
assert_norm (slice_access h g sl pos == slice_access' h g sl pos) | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 67,
"end_line": 444,
"start_col": 0,
"start_line": 420
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x))
let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos)
let get_valid_pos_post
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (
let pos' = get_valid_pos p h sl pos in
valid_pos p h sl pos pos'
))
[SMTPat (get_valid_pos p h sl pos)]
= ()
let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
= valid_exact' p h s pos pos'
let valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
= assert_norm (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
let contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost t
(requires (valid_exact p h s pos pos'))
(ensures (fun _ -> True))
= valid_exact_equiv p h s pos pos' ;
contents_exact' p h s pos pos'
let contents_exact_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_exact p h s pos pos'))
(ensures (valid_exact p h s pos pos' /\ valid_exact' p h s pos pos' /\ contents_exact p h s pos pos' == contents_exact' p h s pos pos'))
= valid_exact_equiv p h s pos pos' ;
assert_norm (contents_exact p h s pos pos' == contents_exact' p h s pos pos')
let gaccessor_prop
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: GTot Type0
= gaccessor_prop' f
let gaccessor_prop_equiv
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: Lemma
(gaccessor_prop f <==> gaccessor_prop' f)
= ()
let gaccessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (gaccessor p p (clens_id _))
= gaccessor_id' p
let gaccessor_id_eq
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(gaccessor_id p input == gaccessor_id' p input)
= ()
let gaccessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (gaccessor p1 p2 cl')
= gaccessor_ext' g cl' sq
let gaccessor_ext_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
(input: bytes)
: Lemma
(gaccessor_ext g cl sq input == gaccessor_ext' g cl sq input)
= ()
let gaccessor_compose_injective
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ injective_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
assert (injective_precond p2 sl_ sl'_)
let gaccessor_compose_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (k1.parser_kind_subkind == Some ParserStrong /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ no_lookahead_on_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
parse_strong_prefix p1 sl sl';
assert (injective_precond p1 sl sl');
assert (injective_precond p2 sl_ sl'_)
[@"opaque_to_smt"]
let gaccessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
: Tot (gaccessor p1 p3 (clens_compose cl12 cl23))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_injective a12 a23 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_no_lookahead a12 a23 x));
gaccessor_compose' a12 a23
let gaccessor_compose_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(input: bytes)
: Lemma
(gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
= assert_norm (gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
[@"opaque_to_smt"]
let slice_access
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun pos' -> True))
= valid_facts p1 h sl pos;
slice_access' h g sl pos | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h: FStar.Monotonic.HyperStack.mem ->
g: LowParse.Low.Base.Spec.gaccessor p1 p2 cl ->
sl: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.Spec.valid p1 h sl pos /\
Mkclens?.clens_cond cl (LowParse.Low.Base.Spec.contents p1 h sl pos))
(ensures
LowParse.Low.Base.Spec.valid' p1 h sl pos /\
Mkclens?.clens_cond cl (LowParse.Low.Base.Spec.contents' p1 h sl pos) /\
LowParse.Low.Base.Spec.slice_access h g sl pos ==
LowParse.Low.Base.Spec.slice_access' h g sl pos) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.Spec.clens",
"LowParse.Low.Base.Spec.gaccessor",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"LowParse.Low.Base.Spec.slice_access",
"LowParse.Low.Base.Spec.slice_access'",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"Prims.l_and",
"LowParse.Low.Base.Spec.valid",
"LowParse.Low.Base.Spec.__proj__Mkclens__item__clens_cond",
"LowParse.Low.Base.Spec.contents",
"Prims.squash",
"LowParse.Low.Base.Spec.valid'",
"LowParse.Low.Base.Spec.contents'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let slice_access_eq
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma (requires (valid p1 h sl pos /\ cl.clens_cond (contents p1 h sl pos)))
(ensures
(valid' p1 h sl pos /\ cl.clens_cond (contents' p1 h sl pos) /\
slice_access h g sl pos == slice_access' h g sl pos)) =
| valid_facts p1 h sl pos;
assert_norm (slice_access h g sl pos == slice_access' h g sl pos) | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.contents_list_eq | val contents_list_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h sl pos pos'))
(ensures (contents_list p h sl pos pos' == (
valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
))) | val contents_list_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h sl pos pos'))
(ensures (contents_list p h sl pos pos' == (
valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
))) | let contents_list_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h sl pos pos'))
(ensures (contents_list p h sl pos pos' == (
valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
)))
= assert_norm (contents_list p h sl pos pos' == (
valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
)) | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 4,
"end_line": 591,
"start_col": 0,
"start_line": 567
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x))
let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos)
let get_valid_pos_post
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (
let pos' = get_valid_pos p h sl pos in
valid_pos p h sl pos pos'
))
[SMTPat (get_valid_pos p h sl pos)]
= ()
let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
= valid_exact' p h s pos pos'
let valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
= assert_norm (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
let contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost t
(requires (valid_exact p h s pos pos'))
(ensures (fun _ -> True))
= valid_exact_equiv p h s pos pos' ;
contents_exact' p h s pos pos'
let contents_exact_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_exact p h s pos pos'))
(ensures (valid_exact p h s pos pos' /\ valid_exact' p h s pos pos' /\ contents_exact p h s pos pos' == contents_exact' p h s pos pos'))
= valid_exact_equiv p h s pos pos' ;
assert_norm (contents_exact p h s pos pos' == contents_exact' p h s pos pos')
let gaccessor_prop
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: GTot Type0
= gaccessor_prop' f
let gaccessor_prop_equiv
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: Lemma
(gaccessor_prop f <==> gaccessor_prop' f)
= ()
let gaccessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (gaccessor p p (clens_id _))
= gaccessor_id' p
let gaccessor_id_eq
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(gaccessor_id p input == gaccessor_id' p input)
= ()
let gaccessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (gaccessor p1 p2 cl')
= gaccessor_ext' g cl' sq
let gaccessor_ext_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
(input: bytes)
: Lemma
(gaccessor_ext g cl sq input == gaccessor_ext' g cl sq input)
= ()
let gaccessor_compose_injective
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ injective_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
assert (injective_precond p2 sl_ sl'_)
let gaccessor_compose_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (k1.parser_kind_subkind == Some ParserStrong /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ no_lookahead_on_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
parse_strong_prefix p1 sl sl';
assert (injective_precond p1 sl sl');
assert (injective_precond p2 sl_ sl'_)
[@"opaque_to_smt"]
let gaccessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
: Tot (gaccessor p1 p3 (clens_compose cl12 cl23))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_injective a12 a23 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_no_lookahead a12 a23 x));
gaccessor_compose' a12 a23
let gaccessor_compose_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(input: bytes)
: Lemma
(gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
= assert_norm (gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
[@"opaque_to_smt"]
let slice_access
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun pos' -> True))
= valid_facts p1 h sl pos;
slice_access' h g sl pos
let slice_access_eq
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (
valid' p1 h sl pos /\
cl.clens_cond (contents' p1 h sl pos) /\
slice_access h g sl pos == slice_access' h g sl pos
))
= valid_facts p1 h sl pos;
assert_norm (slice_access h g sl pos == slice_access' h g sl pos)
let slice_access_frame_strong
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
k1.parser_kind_subkind == Some ParserStrong /\
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos) /\
B.modifies l h h' /\
B.loc_disjoint l (loc_slice_from_to sl pos (get_valid_pos p1 h sl pos))
))
(ensures (
valid p1 h' sl pos /\
cl.clens_cond (contents p1 h' sl pos) /\
slice_access h' g sl pos == slice_access h g sl pos
))
[SMTPatOr [
[SMTPat (slice_access h g sl pos); SMTPat (B.modifies l h h')];
[SMTPat (slice_access h' g sl pos); SMTPat (B.modifies l h h')];
]]
= valid_facts p1 h sl pos;
valid_facts p1 h' sl pos;
slice_access_eq h g sl pos;
slice_access_eq h' g sl pos;
let pos2 = get_valid_pos p1 h sl pos in
parse_strong_prefix p1 (bytes_of_slice_from h sl pos) (bytes_of_slice_from_to h sl pos pos2);
B.modifies_buffer_from_to_elim sl.base pos (get_valid_pos p1 h sl pos) l h h' ;
parse_strong_prefix p1 (bytes_of_slice_from_to h' sl pos pos2) (bytes_of_slice_from h' sl pos)
let rec valid_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
(decreases (U32.v pos' - U32.v pos))
= k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))
let rec valid_list_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_list p h sl pos pos' <==> (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))))
= assert_norm (valid_list p h sl pos pos' <==> (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))))
let rec contents_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost (list t)
(requires (valid_list p h sl pos pos'))
(ensures (fun _ -> True))
(decreases (U32.v pos' - U32.v pos))
= valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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: LowParse.Spec.Base.parser k t ->
h: FStar.Monotonic.HyperStack.mem ->
sl: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> FStar.Pervasives.Lemma (requires LowParse.Low.Base.Spec.valid_list p h sl pos pos')
(ensures
LowParse.Low.Base.Spec.contents_list p h sl pos pos' ==
(LowParse.Low.Base.Spec.valid_list_equiv p h sl pos pos';
(match pos = pos' with
| true -> []
| _ ->
LowParse.Low.Base.Spec.contents p h sl pos ::
LowParse.Low.Base.Spec.contents_list p
h
sl
(LowParse.Low.Base.Spec.get_valid_pos p h sl pos)
pos')
<:
Prims.list t)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.list",
"LowParse.Low.Base.Spec.contents_list",
"Prims.op_Equality",
"Prims.Nil",
"Prims.bool",
"Prims.Cons",
"LowParse.Low.Base.Spec.contents",
"LowParse.Low.Base.Spec.get_valid_pos",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_list_equiv",
"LowParse.Low.Base.Spec.valid_list",
"Prims.squash",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let contents_list_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos pos': U32.t)
: Lemma (requires (valid_list p h sl pos pos'))
(ensures
(contents_list p h sl pos pos' ==
(valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'))) =
| assert_norm (contents_list p h sl pos pos' ==
(valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos')) | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.serialized_list_length_constant_size | val serialized_list_length_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_high == Some k.parser_kind_low})
(l: list t)
: Lemma
(ensures (
serialized_list_length s l == L.length l `Prims.op_Multiply` k.parser_kind_low
)) | val serialized_list_length_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_high == Some k.parser_kind_low})
(l: list t)
: Lemma
(ensures (
serialized_list_length s l == L.length l `Prims.op_Multiply` k.parser_kind_low
)) | let rec serialized_list_length_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_high == Some k.parser_kind_low})
(l: list t)
: Lemma
(ensures (
serialized_list_length s l == L.length l `Prims.op_Multiply` k.parser_kind_low
))
= match l with
| [] ->
assert (serialized_list_length s l == 0);
assert (L.length l == 0)
| a :: q ->
serialized_list_length_constant_size s q;
serialized_length_eq s a;
assert (serialized_length s a == k.parser_kind_low);
M.distributivity_add_left 1 (L.length q) k.parser_kind_low | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 62,
"end_line": 649,
"start_col": 0,
"start_line": 631
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x))
let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos)
let get_valid_pos_post
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (
let pos' = get_valid_pos p h sl pos in
valid_pos p h sl pos pos'
))
[SMTPat (get_valid_pos p h sl pos)]
= ()
let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
= valid_exact' p h s pos pos'
let valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
= assert_norm (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
let contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost t
(requires (valid_exact p h s pos pos'))
(ensures (fun _ -> True))
= valid_exact_equiv p h s pos pos' ;
contents_exact' p h s pos pos'
let contents_exact_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_exact p h s pos pos'))
(ensures (valid_exact p h s pos pos' /\ valid_exact' p h s pos pos' /\ contents_exact p h s pos pos' == contents_exact' p h s pos pos'))
= valid_exact_equiv p h s pos pos' ;
assert_norm (contents_exact p h s pos pos' == contents_exact' p h s pos pos')
let gaccessor_prop
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: GTot Type0
= gaccessor_prop' f
let gaccessor_prop_equiv
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: Lemma
(gaccessor_prop f <==> gaccessor_prop' f)
= ()
let gaccessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (gaccessor p p (clens_id _))
= gaccessor_id' p
let gaccessor_id_eq
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(gaccessor_id p input == gaccessor_id' p input)
= ()
let gaccessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (gaccessor p1 p2 cl')
= gaccessor_ext' g cl' sq
let gaccessor_ext_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
(input: bytes)
: Lemma
(gaccessor_ext g cl sq input == gaccessor_ext' g cl sq input)
= ()
let gaccessor_compose_injective
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ injective_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
assert (injective_precond p2 sl_ sl'_)
let gaccessor_compose_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (k1.parser_kind_subkind == Some ParserStrong /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ no_lookahead_on_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
parse_strong_prefix p1 sl sl';
assert (injective_precond p1 sl sl');
assert (injective_precond p2 sl_ sl'_)
[@"opaque_to_smt"]
let gaccessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
: Tot (gaccessor p1 p3 (clens_compose cl12 cl23))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_injective a12 a23 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_no_lookahead a12 a23 x));
gaccessor_compose' a12 a23
let gaccessor_compose_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(input: bytes)
: Lemma
(gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
= assert_norm (gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
[@"opaque_to_smt"]
let slice_access
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun pos' -> True))
= valid_facts p1 h sl pos;
slice_access' h g sl pos
let slice_access_eq
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (
valid' p1 h sl pos /\
cl.clens_cond (contents' p1 h sl pos) /\
slice_access h g sl pos == slice_access' h g sl pos
))
= valid_facts p1 h sl pos;
assert_norm (slice_access h g sl pos == slice_access' h g sl pos)
let slice_access_frame_strong
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
k1.parser_kind_subkind == Some ParserStrong /\
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos) /\
B.modifies l h h' /\
B.loc_disjoint l (loc_slice_from_to sl pos (get_valid_pos p1 h sl pos))
))
(ensures (
valid p1 h' sl pos /\
cl.clens_cond (contents p1 h' sl pos) /\
slice_access h' g sl pos == slice_access h g sl pos
))
[SMTPatOr [
[SMTPat (slice_access h g sl pos); SMTPat (B.modifies l h h')];
[SMTPat (slice_access h' g sl pos); SMTPat (B.modifies l h h')];
]]
= valid_facts p1 h sl pos;
valid_facts p1 h' sl pos;
slice_access_eq h g sl pos;
slice_access_eq h' g sl pos;
let pos2 = get_valid_pos p1 h sl pos in
parse_strong_prefix p1 (bytes_of_slice_from h sl pos) (bytes_of_slice_from_to h sl pos pos2);
B.modifies_buffer_from_to_elim sl.base pos (get_valid_pos p1 h sl pos) l h h' ;
parse_strong_prefix p1 (bytes_of_slice_from_to h' sl pos pos2) (bytes_of_slice_from h' sl pos)
let rec valid_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
(decreases (U32.v pos' - U32.v pos))
= k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))
let rec valid_list_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_list p h sl pos pos' <==> (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))))
= assert_norm (valid_list p h sl pos pos' <==> (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))))
let rec contents_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost (list t)
(requires (valid_list p h sl pos pos'))
(ensures (fun _ -> True))
(decreases (U32.v pos' - U32.v pos))
= valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
let contents_list_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h sl pos pos'))
(ensures (contents_list p h sl pos pos' == (
valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
)))
= assert_norm (contents_list p h sl pos pos' == (
valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
))
let rec serialized_list_length (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (l: list t) : GTot nat =
match l with
| [] -> 0
| x :: q -> serialized_length s x + serialized_list_length s q
let serialized_list_length_nil (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Lemma
(serialized_list_length s [] == 0)
= ()
let serialized_list_length_cons (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (x: t) (q: list t) : Lemma
(serialized_list_length s (x :: q) == serialized_length s x + serialized_list_length s q)
= ()
let rec serialized_list_length_append (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (l1 l2: list t) : Lemma
(serialized_list_length s (List.Tot.append l1 l2) == serialized_list_length s l1 + serialized_list_length s l2)
= match l1 with
| [] -> ()
| _ :: q -> serialized_list_length_append s q l2
let rec valid_list_serialized_list_length (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma
(requires (
valid_list p h input pos pos'
))
(ensures (
serialized_list_length s (contents_list p h input pos pos') == U32.v pos' - U32.v pos
))
(decreases (U32.v pos' - U32.v pos))
= if pos = pos'
then valid_list_nil p h input pos
else begin
valid_list_cons_recip p h input pos pos' ;
let pos1 = get_valid_pos p h input pos in
valid_list_serialized_list_length s h input pos1 pos'
end
#restart-solver
#set-options "--fuel 2 --ifuel 2 --z3rlimit 100" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 2,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s:
LowParse.Spec.Base.serializer p
{ Mkparser_kind'?.parser_kind_high k ==
FStar.Pervasives.Native.Some (Mkparser_kind'?.parser_kind_low k) } ->
l: Prims.list t
-> FStar.Pervasives.Lemma
(ensures
LowParse.Low.Base.Spec.serialized_list_length s l ==
FStar.List.Tot.Base.length l * Mkparser_kind'?.parser_kind_low k) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"Prims.nat",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"Prims.list",
"Prims._assert",
"Prims.int",
"FStar.List.Tot.Base.length",
"Prims.unit",
"LowParse.Low.Base.Spec.serialized_list_length",
"FStar.Math.Lemmas.distributivity_add_left",
"LowParse.Low.Base.Spec.serialized_length",
"LowParse.Low.Base.Spec.serialized_length_eq",
"LowParse.Low.Base.Spec.serialized_list_length_constant_size",
"Prims.l_True",
"Prims.squash",
"Prims.op_Multiply",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec serialized_list_length_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_high == Some k.parser_kind_low})
(l: list t)
: Lemma
(ensures (serialized_list_length s l == (L.length l) `Prims.op_Multiply` k.parser_kind_low)) =
| match l with
| [] ->
assert (serialized_list_length s l == 0);
assert (L.length l == 0)
| a :: q ->
serialized_list_length_constant_size s q;
serialized_length_eq s a;
assert (serialized_length s a == k.parser_kind_low);
M.distributivity_add_left 1 (L.length q) k.parser_kind_low | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.gaccessor_compose | val gaccessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
: Tot (gaccessor p1 p3 (clens_compose cl12 cl23)) | val gaccessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
: Tot (gaccessor p1 p3 (clens_compose cl12 cl23)) | let gaccessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
: Tot (gaccessor p1 p3 (clens_compose cl12 cl23))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_injective a12 a23 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_no_lookahead a12 a23 x));
gaccessor_compose' a12 a23 | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 28,
"end_line": 376,
"start_col": 0,
"start_line": 359
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x))
let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos)
let get_valid_pos_post
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (
let pos' = get_valid_pos p h sl pos in
valid_pos p h sl pos pos'
))
[SMTPat (get_valid_pos p h sl pos)]
= ()
let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
= valid_exact' p h s pos pos'
let valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
= assert_norm (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
let contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost t
(requires (valid_exact p h s pos pos'))
(ensures (fun _ -> True))
= valid_exact_equiv p h s pos pos' ;
contents_exact' p h s pos pos'
let contents_exact_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_exact p h s pos pos'))
(ensures (valid_exact p h s pos pos' /\ valid_exact' p h s pos pos' /\ contents_exact p h s pos pos' == contents_exact' p h s pos pos'))
= valid_exact_equiv p h s pos pos' ;
assert_norm (contents_exact p h s pos pos' == contents_exact' p h s pos pos')
let gaccessor_prop
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: GTot Type0
= gaccessor_prop' f
let gaccessor_prop_equiv
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: Lemma
(gaccessor_prop f <==> gaccessor_prop' f)
= ()
let gaccessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (gaccessor p p (clens_id _))
= gaccessor_id' p
let gaccessor_id_eq
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(gaccessor_id p input == gaccessor_id' p input)
= ()
let gaccessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (gaccessor p1 p2 cl')
= gaccessor_ext' g cl' sq
let gaccessor_ext_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
(input: bytes)
: Lemma
(gaccessor_ext g cl sq input == gaccessor_ext' g cl sq input)
= ()
let gaccessor_compose_injective
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ injective_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
assert (injective_precond p2 sl_ sl'_)
let gaccessor_compose_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (k1.parser_kind_subkind == Some ParserStrong /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ no_lookahead_on_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
parse_strong_prefix p1 sl sl';
assert (injective_precond p1 sl sl');
assert (injective_precond p2 sl_ sl'_) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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 | a12: LowParse.Low.Base.Spec.gaccessor p1 p2 cl12 -> a23: LowParse.Low.Base.Spec.gaccessor p2 p3 cl23
-> LowParse.Low.Base.Spec.gaccessor p1 p3 (LowParse.Low.Base.Spec.clens_compose cl12 cl23) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.Spec.clens",
"LowParse.Low.Base.Spec.gaccessor",
"LowParse.Low.Base.Spec.gaccessor_compose'",
"Prims.unit",
"FStar.Classical.forall_intro_2",
"LowParse.Bytes.bytes",
"Prims.l_imp",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Low.Base.Spec.gaccessor_pre",
"LowParse.Low.Base.Spec.clens_compose",
"LowParse.Spec.Base.no_lookahead_on_precond",
"Prims.nat",
"FStar.Classical.move_requires",
"LowParse.Low.Base.Spec.gaccessor_compose_no_lookahead",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"LowParse.Spec.Base.injective_precond",
"LowParse.Low.Base.Spec.gaccessor_compose_injective"
] | [] | false | false | false | false | false | let gaccessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
: Tot (gaccessor p1 p3 (clens_compose cl12 cl23)) =
| Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_injective a12 a23 x));
Classical.forall_intro_2 (fun x ->
Classical.move_requires (gaccessor_compose_no_lookahead a12 a23 x));
gaccessor_compose' a12 a23 | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.list_filter_append | val list_filter_append
(#t: Type)
(f: (t -> Tot bool))
(l1 l2: list t)
: Lemma
(L.filter f (l1 `L.append` l2) == L.filter f l1 `L.append` L.filter f l2) | val list_filter_append
(#t: Type)
(f: (t -> Tot bool))
(l1 l2: list t)
: Lemma
(L.filter f (l1 `L.append` l2) == L.filter f l1 `L.append` L.filter f l2) | let rec list_filter_append
(#t: Type)
(f: (t -> Tot bool))
(l1 l2: list t)
: Lemma
(L.filter f (l1 `L.append` l2) == L.filter f l1 `L.append` L.filter f l2)
= match l1 with
| [] -> ()
| a :: q ->
list_filter_append f q l2 | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 29,
"end_line": 673,
"start_col": 0,
"start_line": 664
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x))
let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos)
let get_valid_pos_post
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (
let pos' = get_valid_pos p h sl pos in
valid_pos p h sl pos pos'
))
[SMTPat (get_valid_pos p h sl pos)]
= ()
let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
= valid_exact' p h s pos pos'
let valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
= assert_norm (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
let contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost t
(requires (valid_exact p h s pos pos'))
(ensures (fun _ -> True))
= valid_exact_equiv p h s pos pos' ;
contents_exact' p h s pos pos'
let contents_exact_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_exact p h s pos pos'))
(ensures (valid_exact p h s pos pos' /\ valid_exact' p h s pos pos' /\ contents_exact p h s pos pos' == contents_exact' p h s pos pos'))
= valid_exact_equiv p h s pos pos' ;
assert_norm (contents_exact p h s pos pos' == contents_exact' p h s pos pos')
let gaccessor_prop
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: GTot Type0
= gaccessor_prop' f
let gaccessor_prop_equiv
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: Lemma
(gaccessor_prop f <==> gaccessor_prop' f)
= ()
let gaccessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (gaccessor p p (clens_id _))
= gaccessor_id' p
let gaccessor_id_eq
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(gaccessor_id p input == gaccessor_id' p input)
= ()
let gaccessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (gaccessor p1 p2 cl')
= gaccessor_ext' g cl' sq
let gaccessor_ext_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
(input: bytes)
: Lemma
(gaccessor_ext g cl sq input == gaccessor_ext' g cl sq input)
= ()
let gaccessor_compose_injective
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ injective_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
assert (injective_precond p2 sl_ sl'_)
let gaccessor_compose_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (k1.parser_kind_subkind == Some ParserStrong /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ no_lookahead_on_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
parse_strong_prefix p1 sl sl';
assert (injective_precond p1 sl sl');
assert (injective_precond p2 sl_ sl'_)
[@"opaque_to_smt"]
let gaccessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
: Tot (gaccessor p1 p3 (clens_compose cl12 cl23))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_injective a12 a23 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_no_lookahead a12 a23 x));
gaccessor_compose' a12 a23
let gaccessor_compose_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(input: bytes)
: Lemma
(gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
= assert_norm (gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
[@"opaque_to_smt"]
let slice_access
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun pos' -> True))
= valid_facts p1 h sl pos;
slice_access' h g sl pos
let slice_access_eq
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (
valid' p1 h sl pos /\
cl.clens_cond (contents' p1 h sl pos) /\
slice_access h g sl pos == slice_access' h g sl pos
))
= valid_facts p1 h sl pos;
assert_norm (slice_access h g sl pos == slice_access' h g sl pos)
let slice_access_frame_strong
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
k1.parser_kind_subkind == Some ParserStrong /\
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos) /\
B.modifies l h h' /\
B.loc_disjoint l (loc_slice_from_to sl pos (get_valid_pos p1 h sl pos))
))
(ensures (
valid p1 h' sl pos /\
cl.clens_cond (contents p1 h' sl pos) /\
slice_access h' g sl pos == slice_access h g sl pos
))
[SMTPatOr [
[SMTPat (slice_access h g sl pos); SMTPat (B.modifies l h h')];
[SMTPat (slice_access h' g sl pos); SMTPat (B.modifies l h h')];
]]
= valid_facts p1 h sl pos;
valid_facts p1 h' sl pos;
slice_access_eq h g sl pos;
slice_access_eq h' g sl pos;
let pos2 = get_valid_pos p1 h sl pos in
parse_strong_prefix p1 (bytes_of_slice_from h sl pos) (bytes_of_slice_from_to h sl pos pos2);
B.modifies_buffer_from_to_elim sl.base pos (get_valid_pos p1 h sl pos) l h h' ;
parse_strong_prefix p1 (bytes_of_slice_from_to h' sl pos pos2) (bytes_of_slice_from h' sl pos)
let rec valid_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
(decreases (U32.v pos' - U32.v pos))
= k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))
let rec valid_list_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_list p h sl pos pos' <==> (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))))
= assert_norm (valid_list p h sl pos pos' <==> (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))))
let rec contents_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost (list t)
(requires (valid_list p h sl pos pos'))
(ensures (fun _ -> True))
(decreases (U32.v pos' - U32.v pos))
= valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
let contents_list_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h sl pos pos'))
(ensures (contents_list p h sl pos pos' == (
valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
)))
= assert_norm (contents_list p h sl pos pos' == (
valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
))
let rec serialized_list_length (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (l: list t) : GTot nat =
match l with
| [] -> 0
| x :: q -> serialized_length s x + serialized_list_length s q
let serialized_list_length_nil (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Lemma
(serialized_list_length s [] == 0)
= ()
let serialized_list_length_cons (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (x: t) (q: list t) : Lemma
(serialized_list_length s (x :: q) == serialized_length s x + serialized_list_length s q)
= ()
let rec serialized_list_length_append (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (l1 l2: list t) : Lemma
(serialized_list_length s (List.Tot.append l1 l2) == serialized_list_length s l1 + serialized_list_length s l2)
= match l1 with
| [] -> ()
| _ :: q -> serialized_list_length_append s q l2
let rec valid_list_serialized_list_length (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma
(requires (
valid_list p h input pos pos'
))
(ensures (
serialized_list_length s (contents_list p h input pos pos') == U32.v pos' - U32.v pos
))
(decreases (U32.v pos' - U32.v pos))
= if pos = pos'
then valid_list_nil p h input pos
else begin
valid_list_cons_recip p h input pos pos' ;
let pos1 = get_valid_pos p h input pos in
valid_list_serialized_list_length s h input pos1 pos'
end
#restart-solver
#set-options "--fuel 2 --ifuel 2 --z3rlimit 100"
let rec serialized_list_length_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_high == Some k.parser_kind_low})
(l: list t)
: Lemma
(ensures (
serialized_list_length s l == L.length l `Prims.op_Multiply` k.parser_kind_low
))
= match l with
| [] ->
assert (serialized_list_length s l == 0);
assert (L.length l == 0)
| a :: q ->
serialized_list_length_constant_size s q;
serialized_length_eq s a;
assert (serialized_length s a == k.parser_kind_low);
M.distributivity_add_left 1 (L.length q) k.parser_kind_low
#set-options "--fuel 2 --ifuel 1 --z3rlimit 100"
let rec list_flatten_append
(#a: Type)
(l1 l2: list (list a))
: Lemma
(L.flatten (l1 `L.append` l2) == L.flatten l1 `L.append` L.flatten l2)
= match l1 with
| [] -> ()
| a :: q ->
list_flatten_append q l2;
L.append_assoc a (L.flatten q) (L.flatten l2) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: (_: t -> Prims.bool) -> l1: Prims.list t -> l2: Prims.list t
-> FStar.Pervasives.Lemma
(ensures
FStar.List.Tot.Base.filter f (l1 @ l2) ==
FStar.List.Tot.Base.filter f l1 @ FStar.List.Tot.Base.filter f l2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.bool",
"Prims.list",
"LowParse.Low.Base.Spec.list_filter_append",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.List.Tot.Base.filter",
"FStar.List.Tot.Base.append",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec list_filter_append (#t: Type) (f: (t -> Tot bool)) (l1 l2: list t)
: Lemma (L.filter f (l1 `L.append` l2) == (L.filter f l1) `L.append` (L.filter f l2)) =
| match l1 with
| [] -> ()
| a :: q -> list_filter_append f q l2 | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.list_flatten_map_append | val list_flatten_map_append
(#a #b: Type)
(f: a -> Tot (list b))
(l1 l2: list a)
: Lemma
(L.flatten (L.map f (l1 `L.append` l2)) == L.flatten (L.map f l1) `L.append` L.flatten (L.map f l2)) | val list_flatten_map_append
(#a #b: Type)
(f: a -> Tot (list b))
(l1 l2: list a)
: Lemma
(L.flatten (L.map f (l1 `L.append` l2)) == L.flatten (L.map f l1) `L.append` L.flatten (L.map f l2)) | let list_flatten_map_append
(#a #b: Type)
(f: a -> Tot (list b))
(l1 l2: list a)
: Lemma
(L.flatten (L.map f (l1 `L.append` l2)) == L.flatten (L.map f l1) `L.append` L.flatten (L.map f l2))
= L.map_append f l1 l2;
list_flatten_append (L.map f l1) (L.map f l2) | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 47,
"end_line": 696,
"start_col": 0,
"start_line": 689
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x))
let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos)
let get_valid_pos_post
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (
let pos' = get_valid_pos p h sl pos in
valid_pos p h sl pos pos'
))
[SMTPat (get_valid_pos p h sl pos)]
= ()
let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
= valid_exact' p h s pos pos'
let valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
= assert_norm (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
let contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost t
(requires (valid_exact p h s pos pos'))
(ensures (fun _ -> True))
= valid_exact_equiv p h s pos pos' ;
contents_exact' p h s pos pos'
let contents_exact_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_exact p h s pos pos'))
(ensures (valid_exact p h s pos pos' /\ valid_exact' p h s pos pos' /\ contents_exact p h s pos pos' == contents_exact' p h s pos pos'))
= valid_exact_equiv p h s pos pos' ;
assert_norm (contents_exact p h s pos pos' == contents_exact' p h s pos pos')
let gaccessor_prop
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: GTot Type0
= gaccessor_prop' f
let gaccessor_prop_equiv
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: Lemma
(gaccessor_prop f <==> gaccessor_prop' f)
= ()
let gaccessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (gaccessor p p (clens_id _))
= gaccessor_id' p
let gaccessor_id_eq
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(gaccessor_id p input == gaccessor_id' p input)
= ()
let gaccessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (gaccessor p1 p2 cl')
= gaccessor_ext' g cl' sq
let gaccessor_ext_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
(input: bytes)
: Lemma
(gaccessor_ext g cl sq input == gaccessor_ext' g cl sq input)
= ()
let gaccessor_compose_injective
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ injective_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
assert (injective_precond p2 sl_ sl'_)
let gaccessor_compose_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (k1.parser_kind_subkind == Some ParserStrong /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ no_lookahead_on_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
parse_strong_prefix p1 sl sl';
assert (injective_precond p1 sl sl');
assert (injective_precond p2 sl_ sl'_)
[@"opaque_to_smt"]
let gaccessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
: Tot (gaccessor p1 p3 (clens_compose cl12 cl23))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_injective a12 a23 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_no_lookahead a12 a23 x));
gaccessor_compose' a12 a23
let gaccessor_compose_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(input: bytes)
: Lemma
(gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
= assert_norm (gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
[@"opaque_to_smt"]
let slice_access
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun pos' -> True))
= valid_facts p1 h sl pos;
slice_access' h g sl pos
let slice_access_eq
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (
valid' p1 h sl pos /\
cl.clens_cond (contents' p1 h sl pos) /\
slice_access h g sl pos == slice_access' h g sl pos
))
= valid_facts p1 h sl pos;
assert_norm (slice_access h g sl pos == slice_access' h g sl pos)
let slice_access_frame_strong
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
k1.parser_kind_subkind == Some ParserStrong /\
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos) /\
B.modifies l h h' /\
B.loc_disjoint l (loc_slice_from_to sl pos (get_valid_pos p1 h sl pos))
))
(ensures (
valid p1 h' sl pos /\
cl.clens_cond (contents p1 h' sl pos) /\
slice_access h' g sl pos == slice_access h g sl pos
))
[SMTPatOr [
[SMTPat (slice_access h g sl pos); SMTPat (B.modifies l h h')];
[SMTPat (slice_access h' g sl pos); SMTPat (B.modifies l h h')];
]]
= valid_facts p1 h sl pos;
valid_facts p1 h' sl pos;
slice_access_eq h g sl pos;
slice_access_eq h' g sl pos;
let pos2 = get_valid_pos p1 h sl pos in
parse_strong_prefix p1 (bytes_of_slice_from h sl pos) (bytes_of_slice_from_to h sl pos pos2);
B.modifies_buffer_from_to_elim sl.base pos (get_valid_pos p1 h sl pos) l h h' ;
parse_strong_prefix p1 (bytes_of_slice_from_to h' sl pos pos2) (bytes_of_slice_from h' sl pos)
let rec valid_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
(decreases (U32.v pos' - U32.v pos))
= k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))
let rec valid_list_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_list p h sl pos pos' <==> (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))))
= assert_norm (valid_list p h sl pos pos' <==> (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))))
let rec contents_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost (list t)
(requires (valid_list p h sl pos pos'))
(ensures (fun _ -> True))
(decreases (U32.v pos' - U32.v pos))
= valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
let contents_list_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h sl pos pos'))
(ensures (contents_list p h sl pos pos' == (
valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
)))
= assert_norm (contents_list p h sl pos pos' == (
valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
))
let rec serialized_list_length (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (l: list t) : GTot nat =
match l with
| [] -> 0
| x :: q -> serialized_length s x + serialized_list_length s q
let serialized_list_length_nil (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Lemma
(serialized_list_length s [] == 0)
= ()
let serialized_list_length_cons (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (x: t) (q: list t) : Lemma
(serialized_list_length s (x :: q) == serialized_length s x + serialized_list_length s q)
= ()
let rec serialized_list_length_append (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (l1 l2: list t) : Lemma
(serialized_list_length s (List.Tot.append l1 l2) == serialized_list_length s l1 + serialized_list_length s l2)
= match l1 with
| [] -> ()
| _ :: q -> serialized_list_length_append s q l2
let rec valid_list_serialized_list_length (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma
(requires (
valid_list p h input pos pos'
))
(ensures (
serialized_list_length s (contents_list p h input pos pos') == U32.v pos' - U32.v pos
))
(decreases (U32.v pos' - U32.v pos))
= if pos = pos'
then valid_list_nil p h input pos
else begin
valid_list_cons_recip p h input pos pos' ;
let pos1 = get_valid_pos p h input pos in
valid_list_serialized_list_length s h input pos1 pos'
end
#restart-solver
#set-options "--fuel 2 --ifuel 2 --z3rlimit 100"
let rec serialized_list_length_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_high == Some k.parser_kind_low})
(l: list t)
: Lemma
(ensures (
serialized_list_length s l == L.length l `Prims.op_Multiply` k.parser_kind_low
))
= match l with
| [] ->
assert (serialized_list_length s l == 0);
assert (L.length l == 0)
| a :: q ->
serialized_list_length_constant_size s q;
serialized_length_eq s a;
assert (serialized_length s a == k.parser_kind_low);
M.distributivity_add_left 1 (L.length q) k.parser_kind_low
#set-options "--fuel 2 --ifuel 1 --z3rlimit 100"
let rec list_flatten_append
(#a: Type)
(l1 l2: list (list a))
: Lemma
(L.flatten (l1 `L.append` l2) == L.flatten l1 `L.append` L.flatten l2)
= match l1 with
| [] -> ()
| a :: q ->
list_flatten_append q l2;
L.append_assoc a (L.flatten q) (L.flatten l2)
let rec list_filter_append
(#t: Type)
(f: (t -> Tot bool))
(l1 l2: list t)
: Lemma
(L.filter f (l1 `L.append` l2) == L.filter f l1 `L.append` L.filter f l2)
= match l1 with
| [] -> ()
| a :: q ->
list_filter_append f q l2
let rec list_index_append (#t: Type) (l1 l2: list t) (i: int) : Lemma
(requires (L.length l1 <= i /\ i < L.length l1 + L.length l2))
(ensures (
L.length (L.append l1 l2) == L.length l1 + L.length l2 /\
L.index (L.append l1 l2) i == L.index l2 (i - L.length l1)
))
= list_length_append l1 l2;
match l1 with
| [] -> ()
| a :: q -> list_index_append q l2 (i - 1)
#set-options "--fuel 2 --ifuel 0 --z3rlimit 500"
#restart-solver | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 2,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_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": 500,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: (_: a -> Prims.list b) -> l1: Prims.list a -> l2: Prims.list a
-> FStar.Pervasives.Lemma
(ensures
FStar.List.Tot.Base.flatten (FStar.List.Tot.Base.map f (l1 @ l2)) ==
FStar.List.Tot.Base.flatten (FStar.List.Tot.Base.map f l1) @
FStar.List.Tot.Base.flatten (FStar.List.Tot.Base.map f l2)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.list",
"LowParse.Low.Base.Spec.list_flatten_append",
"FStar.List.Tot.Base.map",
"Prims.unit",
"FStar.List.Tot.Properties.map_append",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.List.Tot.Base.flatten",
"FStar.List.Tot.Base.append",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let list_flatten_map_append (#a #b: Type) (f: (a -> Tot (list b))) (l1 l2: list a)
: Lemma
(L.flatten (L.map f (l1 `L.append` l2)) ==
(L.flatten (L.map f l1))
`L.append`
(L.flatten (L.map f l2))) =
| L.map_append f l1 l2;
list_flatten_append (L.map f l1) (L.map f l2) | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.serialized_list_length_append | val serialized_list_length_append (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (l1 l2: list t) : Lemma
(serialized_list_length s (List.Tot.append l1 l2) == serialized_list_length s l1 + serialized_list_length s l2) | val serialized_list_length_append (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (l1 l2: list t) : Lemma
(serialized_list_length s (List.Tot.append l1 l2) == serialized_list_length s l1 + serialized_list_length s l2) | let rec serialized_list_length_append (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (l1 l2: list t) : Lemma
(serialized_list_length s (List.Tot.append l1 l2) == serialized_list_length s l1 + serialized_list_length s l2)
= match l1 with
| [] -> ()
| _ :: q -> serialized_list_length_append s q l2 | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 50,
"end_line": 610,
"start_col": 0,
"start_line": 606
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x))
let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos)
let get_valid_pos_post
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (
let pos' = get_valid_pos p h sl pos in
valid_pos p h sl pos pos'
))
[SMTPat (get_valid_pos p h sl pos)]
= ()
let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
= valid_exact' p h s pos pos'
let valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
= assert_norm (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
let contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost t
(requires (valid_exact p h s pos pos'))
(ensures (fun _ -> True))
= valid_exact_equiv p h s pos pos' ;
contents_exact' p h s pos pos'
let contents_exact_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_exact p h s pos pos'))
(ensures (valid_exact p h s pos pos' /\ valid_exact' p h s pos pos' /\ contents_exact p h s pos pos' == contents_exact' p h s pos pos'))
= valid_exact_equiv p h s pos pos' ;
assert_norm (contents_exact p h s pos pos' == contents_exact' p h s pos pos')
let gaccessor_prop
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: GTot Type0
= gaccessor_prop' f
let gaccessor_prop_equiv
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: Lemma
(gaccessor_prop f <==> gaccessor_prop' f)
= ()
let gaccessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (gaccessor p p (clens_id _))
= gaccessor_id' p
let gaccessor_id_eq
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(gaccessor_id p input == gaccessor_id' p input)
= ()
let gaccessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (gaccessor p1 p2 cl')
= gaccessor_ext' g cl' sq
let gaccessor_ext_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
(input: bytes)
: Lemma
(gaccessor_ext g cl sq input == gaccessor_ext' g cl sq input)
= ()
let gaccessor_compose_injective
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ injective_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
assert (injective_precond p2 sl_ sl'_)
let gaccessor_compose_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (k1.parser_kind_subkind == Some ParserStrong /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ no_lookahead_on_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
parse_strong_prefix p1 sl sl';
assert (injective_precond p1 sl sl');
assert (injective_precond p2 sl_ sl'_)
[@"opaque_to_smt"]
let gaccessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
: Tot (gaccessor p1 p3 (clens_compose cl12 cl23))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_injective a12 a23 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_no_lookahead a12 a23 x));
gaccessor_compose' a12 a23
let gaccessor_compose_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(input: bytes)
: Lemma
(gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
= assert_norm (gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
[@"opaque_to_smt"]
let slice_access
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun pos' -> True))
= valid_facts p1 h sl pos;
slice_access' h g sl pos
let slice_access_eq
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (
valid' p1 h sl pos /\
cl.clens_cond (contents' p1 h sl pos) /\
slice_access h g sl pos == slice_access' h g sl pos
))
= valid_facts p1 h sl pos;
assert_norm (slice_access h g sl pos == slice_access' h g sl pos)
let slice_access_frame_strong
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
k1.parser_kind_subkind == Some ParserStrong /\
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos) /\
B.modifies l h h' /\
B.loc_disjoint l (loc_slice_from_to sl pos (get_valid_pos p1 h sl pos))
))
(ensures (
valid p1 h' sl pos /\
cl.clens_cond (contents p1 h' sl pos) /\
slice_access h' g sl pos == slice_access h g sl pos
))
[SMTPatOr [
[SMTPat (slice_access h g sl pos); SMTPat (B.modifies l h h')];
[SMTPat (slice_access h' g sl pos); SMTPat (B.modifies l h h')];
]]
= valid_facts p1 h sl pos;
valid_facts p1 h' sl pos;
slice_access_eq h g sl pos;
slice_access_eq h' g sl pos;
let pos2 = get_valid_pos p1 h sl pos in
parse_strong_prefix p1 (bytes_of_slice_from h sl pos) (bytes_of_slice_from_to h sl pos pos2);
B.modifies_buffer_from_to_elim sl.base pos (get_valid_pos p1 h sl pos) l h h' ;
parse_strong_prefix p1 (bytes_of_slice_from_to h' sl pos pos2) (bytes_of_slice_from h' sl pos)
let rec valid_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
(decreases (U32.v pos' - U32.v pos))
= k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))
let rec valid_list_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_list p h sl pos pos' <==> (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))))
= assert_norm (valid_list p h sl pos pos' <==> (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))))
let rec contents_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost (list t)
(requires (valid_list p h sl pos pos'))
(ensures (fun _ -> True))
(decreases (U32.v pos' - U32.v pos))
= valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
let contents_list_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h sl pos pos'))
(ensures (contents_list p h sl pos pos' == (
valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
)))
= assert_norm (contents_list p h sl pos pos' == (
valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
))
let rec serialized_list_length (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (l: list t) : GTot nat =
match l with
| [] -> 0
| x :: q -> serialized_length s x + serialized_list_length s q
let serialized_list_length_nil (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Lemma
(serialized_list_length s [] == 0)
= ()
let serialized_list_length_cons (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (x: t) (q: list t) : Lemma
(serialized_list_length s (x :: q) == serialized_length s x + serialized_list_length s q)
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: LowParse.Spec.Base.serializer p -> l1: Prims.list t -> l2: Prims.list t
-> FStar.Pervasives.Lemma
(ensures
LowParse.Low.Base.Spec.serialized_list_length s (l1 @ l2) ==
LowParse.Low.Base.Spec.serialized_list_length s l1 +
LowParse.Low.Base.Spec.serialized_list_length s l2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.list",
"LowParse.Low.Base.Spec.serialized_list_length_append",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"LowParse.Low.Base.Spec.serialized_list_length",
"FStar.List.Tot.Base.append",
"Prims.op_Addition",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec serialized_list_length_append
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(l1 l2: list t)
: Lemma
(serialized_list_length s (List.Tot.append l1 l2) ==
serialized_list_length s l1 + serialized_list_length s l2) =
| match l1 with
| [] -> ()
| _ :: q -> serialized_list_length_append s q l2 | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.valid_list_equiv | val valid_list_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_list p h sl pos pos' <==> (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
)))) | val valid_list_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_list p h sl pos pos' <==> (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
)))) | let rec valid_list_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_list p h sl pos pos' <==> (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))))
= assert_norm (valid_list p h sl pos pos' <==> (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
)))) | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 6,
"end_line": 546,
"start_col": 0,
"start_line": 511
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x))
let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos)
let get_valid_pos_post
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (
let pos' = get_valid_pos p h sl pos in
valid_pos p h sl pos pos'
))
[SMTPat (get_valid_pos p h sl pos)]
= ()
let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
= valid_exact' p h s pos pos'
let valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
= assert_norm (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
let contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost t
(requires (valid_exact p h s pos pos'))
(ensures (fun _ -> True))
= valid_exact_equiv p h s pos pos' ;
contents_exact' p h s pos pos'
let contents_exact_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_exact p h s pos pos'))
(ensures (valid_exact p h s pos pos' /\ valid_exact' p h s pos pos' /\ contents_exact p h s pos pos' == contents_exact' p h s pos pos'))
= valid_exact_equiv p h s pos pos' ;
assert_norm (contents_exact p h s pos pos' == contents_exact' p h s pos pos')
let gaccessor_prop
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: GTot Type0
= gaccessor_prop' f
let gaccessor_prop_equiv
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: Lemma
(gaccessor_prop f <==> gaccessor_prop' f)
= ()
let gaccessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (gaccessor p p (clens_id _))
= gaccessor_id' p
let gaccessor_id_eq
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(gaccessor_id p input == gaccessor_id' p input)
= ()
let gaccessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (gaccessor p1 p2 cl')
= gaccessor_ext' g cl' sq
let gaccessor_ext_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
(input: bytes)
: Lemma
(gaccessor_ext g cl sq input == gaccessor_ext' g cl sq input)
= ()
let gaccessor_compose_injective
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ injective_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
assert (injective_precond p2 sl_ sl'_)
let gaccessor_compose_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (k1.parser_kind_subkind == Some ParserStrong /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ no_lookahead_on_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
parse_strong_prefix p1 sl sl';
assert (injective_precond p1 sl sl');
assert (injective_precond p2 sl_ sl'_)
[@"opaque_to_smt"]
let gaccessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
: Tot (gaccessor p1 p3 (clens_compose cl12 cl23))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_injective a12 a23 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_no_lookahead a12 a23 x));
gaccessor_compose' a12 a23
let gaccessor_compose_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(input: bytes)
: Lemma
(gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
= assert_norm (gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
[@"opaque_to_smt"]
let slice_access
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun pos' -> True))
= valid_facts p1 h sl pos;
slice_access' h g sl pos
let slice_access_eq
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (
valid' p1 h sl pos /\
cl.clens_cond (contents' p1 h sl pos) /\
slice_access h g sl pos == slice_access' h g sl pos
))
= valid_facts p1 h sl pos;
assert_norm (slice_access h g sl pos == slice_access' h g sl pos)
let slice_access_frame_strong
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
k1.parser_kind_subkind == Some ParserStrong /\
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos) /\
B.modifies l h h' /\
B.loc_disjoint l (loc_slice_from_to sl pos (get_valid_pos p1 h sl pos))
))
(ensures (
valid p1 h' sl pos /\
cl.clens_cond (contents p1 h' sl pos) /\
slice_access h' g sl pos == slice_access h g sl pos
))
[SMTPatOr [
[SMTPat (slice_access h g sl pos); SMTPat (B.modifies l h h')];
[SMTPat (slice_access h' g sl pos); SMTPat (B.modifies l h h')];
]]
= valid_facts p1 h sl pos;
valid_facts p1 h' sl pos;
slice_access_eq h g sl pos;
slice_access_eq h' g sl pos;
let pos2 = get_valid_pos p1 h sl pos in
parse_strong_prefix p1 (bytes_of_slice_from h sl pos) (bytes_of_slice_from_to h sl pos pos2);
B.modifies_buffer_from_to_elim sl.base pos (get_valid_pos p1 h sl pos) l h h' ;
parse_strong_prefix p1 (bytes_of_slice_from_to h' sl pos pos2) (bytes_of_slice_from h' sl pos)
let rec valid_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
(decreases (U32.v pos' - U32.v pos))
= k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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: LowParse.Spec.Base.parser k t ->
h: FStar.Monotonic.HyperStack.mem ->
sl: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> FStar.Pervasives.Lemma
(ensures
LowParse.Low.Base.Spec.valid_list p h sl pos pos' <==>
Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
Mkparser_kind'?.parser_kind_low k > 0 /\ LowParse.Slice.live_slice h sl /\
FStar.UInt32.v pos' <= FStar.UInt32.v (Mkslice?.len sl) /\
((match pos = pos' with
| true -> Prims.l_True
| _ ->
LowParse.Low.Base.Spec.valid p h sl pos /\
(let pos1 = LowParse.Low.Base.Spec.get_valid_pos p h sl pos in
FStar.UInt32.v pos1 <= FStar.UInt32.v pos' /\
LowParse.Low.Base.Spec.valid_list p h sl pos1 pos'))
<:
Prims.logical)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.Pervasives.assert_norm",
"Prims.l_iff",
"LowParse.Low.Base.Spec.valid_list",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"Prims.b2t",
"Prims.op_GreaterThan",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"LowParse.Slice.live_slice",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"LowParse.Slice.__proj__Mkslice__item__len",
"Prims.op_Equality",
"Prims.l_True",
"Prims.bool",
"LowParse.Low.Base.Spec.valid",
"LowParse.Low.Base.Spec.get_valid_pos",
"Prims.logical",
"Prims.unit",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec valid_list_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos pos': U32.t)
: Lemma
(valid_list p h sl pos pos' <==>
(k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_low > 0 /\ live_slice h sl /\
U32.v pos' <= U32.v sl.len /\
(if pos = pos'
then True
else
valid p h sl pos /\
(let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\ valid_list p h sl pos1 pos')))) =
| assert_norm (valid_list p h sl pos pos' <==>
(k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_low > 0 /\ live_slice h sl /\
U32.v pos' <= U32.v sl.len /\
(if pos = pos'
then True
else
valid p h sl pos /\
(let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\ valid_list p h sl pos1 pos')))) | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.decrypt_chacha20_poly1305 | val decrypt_chacha20_poly1305:decrypt_st CHACHA20_POLY1305 | val decrypt_chacha20_poly1305:decrypt_st CHACHA20_POLY1305 | let decrypt_chacha20_poly1305 : decrypt_st CHACHA20_POLY1305 =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if B.is_null s then
InvalidKey
else
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len <> 12ul then
InvalidIVLength
else begin
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
[@ inline_let ] let bound = pow2 32 - 1 - 16 in
assert (v cipher_len <= bound);
assert_norm (bound + 16 <= pow2 32 - 1);
assert_norm (pow2 31 + bound / 64 <= pow2 32 - 1);
let h0 = ST.get () in
let r = EverCrypt.Chacha20Poly1305.aead_decrypt
ek iv ad_len ad cipher_len dst cipher tag
in
assert (
let cipher_tag = B.as_seq h0 cipher `S.append` B.as_seq h0 tag in
let tag_s = S.slice cipher_tag (S.length cipher_tag - tag_length CHACHA20_POLY1305) (S.length cipher_tag) in
let cipher_s = S.slice cipher_tag 0 (S.length cipher_tag - tag_length CHACHA20_POLY1305) in
S.equal cipher_s (B.as_seq h0 cipher) /\ S.equal tag_s (B.as_seq h0 tag));
if r = 0ul then
Success
else
AuthenticationFailure
end | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 7,
"end_line": 604,
"start_col": 0,
"start_line": 573
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success
#pop-options
inline_for_extraction noextract
let create_in_aes_gcm (i: vale_impl):
create_in_st (alg_of_vale_impl i) =
fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale then (
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then (
let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success
) else
UnsupportedAlgorithm
) else
UnsupportedAlgorithm
let create_in_aes128_gcm: create_in_st AES128_GCM = create_in_aes_gcm Vale_AES128
let create_in_aes256_gcm: create_in_st AES256_GCM = create_in_aes_gcm Vale_AES256
let create_in #a r dst k =
match a with
| AES128_GCM -> create_in_aes128_gcm r dst k
| AES256_GCM -> create_in_aes256_gcm r dst k
| CHACHA20_POLY1305 -> create_in_chacha20_poly1305 r dst k
| _ -> UnsupportedAlgorithm
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
inline_for_extraction noextract
let alloca_chacha20_poly1305: alloca_st CHACHA20_POLY1305 =
fun k ->
let h0 = ST.get () in
let ek = B.alloca 0uy 32ul in
let p = B.alloca (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.loc_none h0 h3;
p
#pop-options
inline_for_extraction noextract
let alloca_aes_gcm (i: vale_impl):
alloca_st (alg_of_vale_impl i) =
fun k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
let ek = B.alloca 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.alloca (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
p
inline_for_extraction noextract
let alloca_aes128_gcm: alloca_st AES128_GCM =
alloca_aes_gcm Vale_AES128
inline_for_extraction noextract
let alloca_aes256_gcm: alloca_st AES256_GCM =
alloca_aes_gcm Vale_AES256
let alloca #a k =
match a with
| AES128_GCM -> alloca_aes128_gcm k
| AES256_GCM -> alloca_aes256_gcm k
| CHACHA20_POLY1305 -> alloca_chacha20_poly1305 k
inline_for_extraction noextract
let aes_gcm_encrypt (i: vale_impl):
Vale.Wrapper.X64.GCMencryptOpt.encrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMencryptOpt.gcm128_encrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMencryptOpt256.gcm256_encrypt_opt_stdcall
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties.slice_slice'"
inline_for_extraction noextract
let encrypt_aes_gcm (i: vale_impl): encrypt_st (alg_of_vale_impl i) =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if B.is_null s then
InvalidKey
else
let a = alg_of_vale_impl i in
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len = 0ul then
InvalidIVLength
else
let open LowStar.BufferOps in
let Ek _ kv ek = !*s in
assert (
let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.AES_s.is_aes_key_LE (vale_alg_of_alg a) k_w);
push_frame();
let scratch_b = B.sub ek (concrete_xkey_len i) 176ul in
let ek = B.sub ek 0ul (concrete_xkey_len i) in
let keys_b = B.sub ek 0ul (key_offset i) in
let hkeys_b = B.sub ek (key_offset i) 128ul in
let h0 = get() in
// The iv can be arbitrary length, hence we need to allocate a new one to perform the hashing
let tmp_iv = B.alloca 0uy 16ul in
// There is no SMTPat on le_bytes_to_seq_quad32_to_bytes and the converse,
// so we need an explicit lemma
let lemma_hkeys_reqs () : Lemma
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.OptPublic.hkeys_reqs_pub
(Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 hkeys_b)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))))
= let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
let hkeys_quad = Vale.AES.OptPublic.get_hkeys_reqs (Vale.Def.Types_s.reverse_bytes_quad32 (
Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))) in
let hkeys = Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 (Vale.Def.Types_s.le_seq_quad32_to_bytes hkeys_quad) in
assert (Seq.equal (B.as_seq h0 hkeys_b) hkeys);
calc (==) {
Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 hkeys);
(==) { Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes hkeys_quad }
hkeys_quad;
}
in lemma_hkeys_reqs ();
// We perform the hashing of the iv. The extra buffer and the hashed iv are the same
Vale.Wrapper.X64.GCM_IV.compute_iv (vale_alg_of_alg a)
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w )
iv iv_len
tmp_iv tmp_iv
hkeys_b;
let h0 = get() in
aes_gcm_encrypt i
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w)
(Ghost.hide (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv)))
plain
(uint32_to_uint64 plain_len)
ad
(uint32_to_uint64 ad_len)
tmp_iv
cipher
tag
keys_b
hkeys_b
scratch_b;
let h1 = get() in
// This assert is needed for z3 to pick up sequence equality for ciphertext
// and tag. It could be avoided if the spec returned both instead of appending them
assert (
let kv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (G.reveal kv) in
let iv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv) in
// `ad` is called `auth` in Vale world; "additional data", "authenticated
// data", potato, potato
let ad_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 ad) in
let plain_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 plain) in
let cipher_nat, tag_nat =
Vale.AES.GCM_s.gcm_encrypt_LE (vale_alg_of_alg a) kv_nat iv_nat plain_nat ad_nat
in
Seq.equal (B.as_seq h1 cipher) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 cipher_nat) /\
Seq.equal (B.as_seq h1 tag) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 tag_nat));
pop_frame();
Success
let encrypt_aes128_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES128_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES128 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt_aes256_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
encrypt_st AES256_GCM =
fun s iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_aes_gcm Vale_AES256 s iv iv_len ad ad_len plain plain_len cipher tag
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let encrypt #a s iv iv_len ad ad_len plain plain_len cipher tag =
if B.is_null s then
InvalidKey
else
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
match i with
| Vale_AES128 ->
encrypt_aes128_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Vale_AES256 ->
encrypt_aes256_gcm () s iv iv_len ad ad_len plain plain_len cipher tag
| Hacl_CHACHA20 ->
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len <> 12ul then
InvalidIVLength
else begin
// Length restrictions
assert_norm (pow2 31 + pow2 32 / 64 <= pow2 32 - 1);
EverCrypt.Chacha20Poly1305.aead_encrypt
ek iv ad_len ad plain_len plain cipher tag;
Success
end
inline_for_extraction noextract
let encrypt_expand_aes_gcm (i: vale_impl): encrypt_expand_st false (alg_of_vale_impl i) =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s (alg_of_vale_impl i)) = alloca k in
let r = encrypt_aes_gcm i s iv iv_len ad ad_len plain plain_len cipher tag in
assert(r == Success);
pop_frame ();
Success
let encrypt_expand_aes128_gcm_no_check : encrypt_expand_st false AES128_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale"
let encrypt_expand_aes256_gcm_no_check : encrypt_expand_st false AES256_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
encrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len plain plain_len cipher tag
else
LowStar.Failure.failwith "EverCrypt was compiled on a system which doesn't support Vale"
let encrypt_expand_aes128_gcm : encrypt_expand_st true AES128_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then
encrypt_expand_aes_gcm Vale_AES128 k iv iv_len ad ad_len plain plain_len cipher tag
else
UnsupportedAlgorithm
else
UnsupportedAlgorithm
let encrypt_expand_aes256_gcm : encrypt_expand_st true AES256_GCM =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then
encrypt_expand_aes_gcm Vale_AES256 k iv iv_len ad ad_len plain plain_len cipher tag
else
UnsupportedAlgorithm
else
UnsupportedAlgorithm
let encrypt_expand_chacha20_poly1305 : encrypt_expand_st false CHACHA20_POLY1305 =
fun k iv iv_len ad ad_len plain plain_len cipher tag ->
push_frame ();
(* Allocate the state *)
let s : B.pointer_or_null (state_s CHACHA20_POLY1305) = alloca k in
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
EverCrypt.Chacha20Poly1305.aead_encrypt ek iv ad_len ad plain_len plain cipher tag;
pop_frame ();
Success
let encrypt_expand #a k iv iv_len ad ad_len plain plain_len cipher tag =
match a with
| AES128_GCM ->
encrypt_expand_aes128_gcm k iv iv_len ad ad_len plain plain_len cipher tag
| AES256_GCM ->
encrypt_expand_aes256_gcm k iv iv_len ad ad_len plain plain_len cipher tag
| CHACHA20_POLY1305 ->
encrypt_expand_chacha20_poly1305 k iv iv_len ad ad_len plain plain_len cipher tag
inline_for_extraction noextract
let aes_gcm_decrypt (i: vale_impl):
Vale.Wrapper.X64.GCMdecryptOpt.decrypt_opt_stdcall_st (vale_alg_of_vale_impl i) =
match i with
| Vale_AES128 -> Vale.Wrapper.X64.GCMdecryptOpt.gcm128_decrypt_opt_stdcall
| Vale_AES256 -> Vale.Wrapper.X64.GCMdecryptOpt256.gcm256_decrypt_opt_stdcall
#reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties.slice_slice'"
inline_for_extraction noextract
let decrypt_aes_gcm (i: vale_impl): decrypt_st (alg_of_vale_impl i) =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if B.is_null s then
InvalidKey
else
// This condition is never satisfied in F* because of the iv_length precondition on iv.
// We keep it here to be defensive when extracting to C
if iv_len = 0ul then
InvalidIVLength
else
let a = alg_of_vale_impl i in
let open LowStar.BufferOps in
let Ek _ kv ek = !*s in
assert (
let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.AES_s.is_aes_key_LE (vale_alg_of_alg a) k_w);
push_frame();
let scratch_b = B.sub ek (concrete_xkey_len i) 176ul in
let ek = B.sub ek 0ul (concrete_xkey_len i) in
let keys_b = B.sub ek 0ul (key_offset i) in
let hkeys_b = B.sub ek (key_offset i) 128ul in
let h0 = get() in
// The iv can be arbitrary length, hence we need to allocate a new one to perform the hashing
let tmp_iv = B.alloca 0uy 16ul in
// There is no SMTPat on le_bytes_to_seq_quad32_to_bytes and the converse,
// so we need an explicit lemma
let lemma_hkeys_reqs () : Lemma
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
Vale.AES.OptPublic.hkeys_reqs_pub
(Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 hkeys_b)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))))
= let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in
let hkeys_quad = Vale.AES.OptPublic.get_hkeys_reqs (Vale.Def.Types_s.reverse_bytes_quad32 (
Vale.AES.AES_s.aes_encrypt_LE (vale_alg_of_alg a) k_w (Vale.Def.Words_s.Mkfour 0 0 0 0))) in
let hkeys = Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 (Vale.Def.Types_s.le_seq_quad32_to_bytes hkeys_quad) in
assert (Seq.equal (B.as_seq h0 hkeys_b) hkeys);
calc (==) {
Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 hkeys);
(==) { Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes hkeys_quad }
hkeys_quad;
}
in lemma_hkeys_reqs ();
// We perform the hashing of the iv. The extra buffer and the hashed iv are the same
Vale.Wrapper.X64.GCM_IV.compute_iv (vale_alg_of_alg a)
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w )
iv iv_len
tmp_iv tmp_iv
hkeys_b;
let r = aes_gcm_decrypt i
(let k = G.reveal kv in
let k_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 k in
let k_w = Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE k_nat in G.hide k_w)
(Ghost.hide (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv)))
cipher
(uint32_to_uint64 cipher_len)
ad
(uint32_to_uint64 ad_len)
tmp_iv
dst
tag
keys_b
hkeys_b
scratch_b in
let h1 = get() in
// This assert is needed for z3 to pick up sequence equality for ciphertext
// It could be avoided if the spec returned both instead of appending them
assert (
let kv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (G.reveal kv) in
let iv_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 iv) in
// `ad` is called `auth` in Vale world; "additional data", "authenticated
// data", potato, potato
let ad_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 ad) in
let cipher_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 cipher) in
let tag_nat = Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (B.as_seq h0 tag) in
let plain_nat, success =
Vale.AES.GCM_s.gcm_decrypt_LE (vale_alg_of_alg a) kv_nat iv_nat cipher_nat ad_nat tag_nat
in
Seq.equal (B.as_seq h1 dst) (Vale.Def.Words.Seq_s.seq_nat8_to_seq_uint8 plain_nat) /\
(UInt64.v r = 0) == success);
assert (
let kv = G.reveal kv in
let cipher_tag = B.as_seq h0 cipher `S.append` B.as_seq h0 tag in
Seq.equal (Seq.slice cipher_tag (S.length cipher_tag - tag_length a) (S.length cipher_tag))
(B.as_seq h0 tag) /\
Seq.equal (Seq.slice cipher_tag 0 (S.length cipher_tag - tag_length a)) (B.as_seq h0 cipher));
pop_frame();
if r = 0uL then
Success
else
AuthenticationFailure
let decrypt_aes128_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
decrypt_st AES128_GCM =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
decrypt_aes_gcm Vale_AES128 s iv iv_len ad ad_len cipher cipher_len tag dst
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable"
let decrypt_aes256_gcm (_: squash (EverCrypt.TargetConfig.hacl_can_compile_vale)):
decrypt_st AES256_GCM =
fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if EverCrypt.TargetConfig.hacl_can_compile_vale then
decrypt_aes_gcm Vale_AES256 s iv iv_len ad ad_len cipher cipher_len tag dst
else
let () = false_elim () in
LowStar.Failure.failwith "statically unreachable" | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.AEAD.decrypt_st Spec.Agile.AEAD.CHACHA20_POLY1305 | Prims.Tot | [
"total"
] | [] | [
"LowStar.Buffer.pointer_or_null",
"EverCrypt.AEAD.state_s",
"Spec.Agile.AEAD.CHACHA20_POLY1305",
"EverCrypt.AEAD.iv_p",
"FStar.UInt32.t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.Integers.within_bounds",
"FStar.Integers.Unsigned",
"FStar.Integers.W32",
"FStar.Integers.v",
"LowStar.Monotonic.Buffer.length",
"EverCrypt.CTR.Keys.uint8",
"LowStar.Buffer.trivial_preorder",
"FStar.Integers.op_Greater",
"FStar.Integers.Signed",
"FStar.Integers.Winfinite",
"EverCrypt.AEAD.ad_p",
"FStar.Integers.op_Less_Equals",
"Prims.pow2",
"EverCrypt.AEAD.cipher_p",
"LowStar.Buffer.buffer",
"Spec.Agile.AEAD.tag_length",
"Prims.nat",
"EverCrypt.Error.InvalidKey",
"EverCrypt.Error.error_code",
"Prims.bool",
"Prims.op_disEquality",
"FStar.UInt32.__uint_to_t",
"EverCrypt.Error.InvalidIVLength",
"Spec.Cipher.Expansion.impl",
"FStar.Ghost.erased",
"Spec.Agile.AEAD.kv",
"FStar.UInt8.t",
"EverCrypt.Error.Success",
"EverCrypt.Error.AuthenticationFailure",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"LowStar.Monotonic.Buffer.as_seq",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.slice",
"FStar.Integers.op_Subtraction",
"FStar.Seq.Base.length",
"FStar.Seq.Base.append",
"EverCrypt.Chacha20Poly1305.aead_decrypt",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"FStar.Pervasives.assert_norm",
"FStar.Integers.op_Plus",
"FStar.Integers.op_Slash",
"FStar.Integers.int_t",
"LowStar.BufferOps.op_Bang_Star",
"LowStar.Monotonic.Buffer.is_null"
] | [] | false | false | false | true | false | let decrypt_chacha20_poly1305:decrypt_st CHACHA20_POLY1305 =
| fun s iv iv_len ad ad_len cipher cipher_len tag dst ->
if B.is_null s
then InvalidKey
else
if iv_len <> 12ul
then InvalidIVLength
else
let open LowStar.BufferOps in
let Ek i kv ek = !*s in
[@@ inline_let ]let bound = pow2 32 - 1 - 16 in
assert (v cipher_len <= bound);
assert_norm (bound + 16 <= pow2 32 - 1);
assert_norm (pow2 31 + bound / 64 <= pow2 32 - 1);
let h0 = ST.get () in
let r = EverCrypt.Chacha20Poly1305.aead_decrypt ek iv ad_len ad cipher_len dst cipher tag in
assert (let cipher_tag = (B.as_seq h0 cipher) `S.append` (B.as_seq h0 tag) in
let tag_s =
S.slice cipher_tag
(S.length cipher_tag - tag_length CHACHA20_POLY1305)
(S.length cipher_tag)
in
let cipher_s =
S.slice cipher_tag 0 (S.length cipher_tag - tag_length CHACHA20_POLY1305)
in
S.equal cipher_s (B.as_seq h0 cipher) /\ S.equal tag_s (B.as_seq h0 tag));
if r = 0ul then Success else AuthenticationFailure | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.valid_list_serialized_list_length | val valid_list_serialized_list_length (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma
(requires (
valid_list p h input pos pos'
))
(ensures (
serialized_list_length s (contents_list p h input pos pos') == U32.v pos' - U32.v pos
))
(decreases (U32.v pos' - U32.v pos)) | val valid_list_serialized_list_length (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma
(requires (
valid_list p h input pos pos'
))
(ensures (
serialized_list_length s (contents_list p h input pos pos') == U32.v pos' - U32.v pos
))
(decreases (U32.v pos' - U32.v pos)) | let rec valid_list_serialized_list_length (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma
(requires (
valid_list p h input pos pos'
))
(ensures (
serialized_list_length s (contents_list p h input pos pos') == U32.v pos' - U32.v pos
))
(decreases (U32.v pos' - U32.v pos))
= if pos = pos'
then valid_list_nil p h input pos
else begin
valid_list_cons_recip p h input pos pos' ;
let pos1 = get_valid_pos p h input pos in
valid_list_serialized_list_length s h input pos1 pos'
end | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 626,
"start_col": 0,
"start_line": 612
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x))
let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos)
let get_valid_pos_post
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (
let pos' = get_valid_pos p h sl pos in
valid_pos p h sl pos pos'
))
[SMTPat (get_valid_pos p h sl pos)]
= ()
let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
= valid_exact' p h s pos pos'
let valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
= assert_norm (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
let contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost t
(requires (valid_exact p h s pos pos'))
(ensures (fun _ -> True))
= valid_exact_equiv p h s pos pos' ;
contents_exact' p h s pos pos'
let contents_exact_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_exact p h s pos pos'))
(ensures (valid_exact p h s pos pos' /\ valid_exact' p h s pos pos' /\ contents_exact p h s pos pos' == contents_exact' p h s pos pos'))
= valid_exact_equiv p h s pos pos' ;
assert_norm (contents_exact p h s pos pos' == contents_exact' p h s pos pos')
let gaccessor_prop
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: GTot Type0
= gaccessor_prop' f
let gaccessor_prop_equiv
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: Lemma
(gaccessor_prop f <==> gaccessor_prop' f)
= ()
let gaccessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (gaccessor p p (clens_id _))
= gaccessor_id' p
let gaccessor_id_eq
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(gaccessor_id p input == gaccessor_id' p input)
= ()
let gaccessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (gaccessor p1 p2 cl')
= gaccessor_ext' g cl' sq
let gaccessor_ext_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
(input: bytes)
: Lemma
(gaccessor_ext g cl sq input == gaccessor_ext' g cl sq input)
= ()
let gaccessor_compose_injective
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ injective_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
assert (injective_precond p2 sl_ sl'_)
let gaccessor_compose_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (k1.parser_kind_subkind == Some ParserStrong /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ no_lookahead_on_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
parse_strong_prefix p1 sl sl';
assert (injective_precond p1 sl sl');
assert (injective_precond p2 sl_ sl'_)
[@"opaque_to_smt"]
let gaccessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
: Tot (gaccessor p1 p3 (clens_compose cl12 cl23))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_injective a12 a23 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_no_lookahead a12 a23 x));
gaccessor_compose' a12 a23
let gaccessor_compose_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(input: bytes)
: Lemma
(gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
= assert_norm (gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
[@"opaque_to_smt"]
let slice_access
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun pos' -> True))
= valid_facts p1 h sl pos;
slice_access' h g sl pos
let slice_access_eq
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (
valid' p1 h sl pos /\
cl.clens_cond (contents' p1 h sl pos) /\
slice_access h g sl pos == slice_access' h g sl pos
))
= valid_facts p1 h sl pos;
assert_norm (slice_access h g sl pos == slice_access' h g sl pos)
let slice_access_frame_strong
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
k1.parser_kind_subkind == Some ParserStrong /\
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos) /\
B.modifies l h h' /\
B.loc_disjoint l (loc_slice_from_to sl pos (get_valid_pos p1 h sl pos))
))
(ensures (
valid p1 h' sl pos /\
cl.clens_cond (contents p1 h' sl pos) /\
slice_access h' g sl pos == slice_access h g sl pos
))
[SMTPatOr [
[SMTPat (slice_access h g sl pos); SMTPat (B.modifies l h h')];
[SMTPat (slice_access h' g sl pos); SMTPat (B.modifies l h h')];
]]
= valid_facts p1 h sl pos;
valid_facts p1 h' sl pos;
slice_access_eq h g sl pos;
slice_access_eq h' g sl pos;
let pos2 = get_valid_pos p1 h sl pos in
parse_strong_prefix p1 (bytes_of_slice_from h sl pos) (bytes_of_slice_from_to h sl pos pos2);
B.modifies_buffer_from_to_elim sl.base pos (get_valid_pos p1 h sl pos) l h h' ;
parse_strong_prefix p1 (bytes_of_slice_from_to h' sl pos pos2) (bytes_of_slice_from h' sl pos)
let rec valid_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
(decreases (U32.v pos' - U32.v pos))
= k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))
let rec valid_list_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_list p h sl pos pos' <==> (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))))
= assert_norm (valid_list p h sl pos pos' <==> (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))))
let rec contents_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost (list t)
(requires (valid_list p h sl pos pos'))
(ensures (fun _ -> True))
(decreases (U32.v pos' - U32.v pos))
= valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
let contents_list_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h sl pos pos'))
(ensures (contents_list p h sl pos pos' == (
valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
)))
= assert_norm (contents_list p h sl pos pos' == (
valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
))
let rec serialized_list_length (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (l: list t) : GTot nat =
match l with
| [] -> 0
| x :: q -> serialized_length s x + serialized_list_length s q
let serialized_list_length_nil (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Lemma
(serialized_list_length s [] == 0)
= ()
let serialized_list_length_cons (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (x: t) (q: list t) : Lemma
(serialized_list_length s (x :: q) == serialized_length s x + serialized_list_length s q)
= ()
let rec serialized_list_length_append (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (l1 l2: list t) : Lemma
(serialized_list_length s (List.Tot.append l1 l2) == serialized_list_length s l1 + serialized_list_length s l2)
= match l1 with
| [] -> ()
| _ :: q -> serialized_list_length_append s q l2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: LowParse.Spec.Base.serializer p ->
h: FStar.Monotonic.HyperStack.mem ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> FStar.Pervasives.Lemma (requires LowParse.Low.Base.Spec.valid_list p h input pos pos')
(ensures
LowParse.Low.Base.Spec.serialized_list_length s
(LowParse.Low.Base.Spec.contents_list p h input pos pos') ==
FStar.UInt32.v pos' - FStar.UInt32.v pos)
(decreases FStar.UInt32.v pos' - FStar.UInt32.v pos) | FStar.Pervasives.Lemma | [
"",
"lemma"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.op_Equality",
"LowParse.Low.Base.Spec.valid_list_nil",
"Prims.bool",
"LowParse.Low.Base.Spec.valid_list_serialized_list_length",
"LowParse.Low.Base.Spec.get_valid_pos",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_list_cons_recip",
"LowParse.Low.Base.Spec.valid_list",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"LowParse.Low.Base.Spec.serialized_list_length",
"LowParse.Low.Base.Spec.contents_list",
"Prims.op_Subtraction",
"FStar.UInt32.v",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec valid_list_serialized_list_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(#rrel #rel: _)
(input: slice rrel rel)
(pos pos': U32.t)
: Lemma (requires (valid_list p h input pos pos'))
(ensures
(serialized_list_length s (contents_list p h input pos pos') == U32.v pos' - U32.v pos))
(decreases (U32.v pos' - U32.v pos)) =
| if pos = pos'
then valid_list_nil p h input pos
else
(valid_list_cons_recip p h input pos pos';
let pos1 = get_valid_pos p h input pos in
valid_list_serialized_list_length s h input pos1 pos') | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.list_map_list_flatten_map | val list_map_list_flatten_map
(#a #b: Type)
(f: a -> Tot b)
(l: list a)
: Lemma
(L.map f l == L.flatten (L.map (fun x -> [f x]) l)) | val list_map_list_flatten_map
(#a #b: Type)
(f: a -> Tot b)
(l: list a)
: Lemma
(L.map f l == L.flatten (L.map (fun x -> [f x]) l)) | let rec list_map_list_flatten_map
(#a #b: Type)
(f: a -> Tot b)
(l: list a)
: Lemma
(L.map f l == L.flatten (L.map (fun x -> [f x]) l))
= match l with
| [] -> ()
| a :: q -> list_map_list_flatten_map f q | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 43,
"end_line": 708,
"start_col": 0,
"start_line": 700
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x))
let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos)
let get_valid_pos_post
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (
let pos' = get_valid_pos p h sl pos in
valid_pos p h sl pos pos'
))
[SMTPat (get_valid_pos p h sl pos)]
= ()
let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
= valid_exact' p h s pos pos'
let valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
= assert_norm (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
let contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost t
(requires (valid_exact p h s pos pos'))
(ensures (fun _ -> True))
= valid_exact_equiv p h s pos pos' ;
contents_exact' p h s pos pos'
let contents_exact_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_exact p h s pos pos'))
(ensures (valid_exact p h s pos pos' /\ valid_exact' p h s pos pos' /\ contents_exact p h s pos pos' == contents_exact' p h s pos pos'))
= valid_exact_equiv p h s pos pos' ;
assert_norm (contents_exact p h s pos pos' == contents_exact' p h s pos pos')
let gaccessor_prop
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: GTot Type0
= gaccessor_prop' f
let gaccessor_prop_equiv
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: Lemma
(gaccessor_prop f <==> gaccessor_prop' f)
= ()
let gaccessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (gaccessor p p (clens_id _))
= gaccessor_id' p
let gaccessor_id_eq
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(gaccessor_id p input == gaccessor_id' p input)
= ()
let gaccessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (gaccessor p1 p2 cl')
= gaccessor_ext' g cl' sq
let gaccessor_ext_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
(input: bytes)
: Lemma
(gaccessor_ext g cl sq input == gaccessor_ext' g cl sq input)
= ()
let gaccessor_compose_injective
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ injective_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
assert (injective_precond p2 sl_ sl'_)
let gaccessor_compose_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (k1.parser_kind_subkind == Some ParserStrong /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ no_lookahead_on_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
parse_strong_prefix p1 sl sl';
assert (injective_precond p1 sl sl');
assert (injective_precond p2 sl_ sl'_)
[@"opaque_to_smt"]
let gaccessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
: Tot (gaccessor p1 p3 (clens_compose cl12 cl23))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_injective a12 a23 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_no_lookahead a12 a23 x));
gaccessor_compose' a12 a23
let gaccessor_compose_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(input: bytes)
: Lemma
(gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
= assert_norm (gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
[@"opaque_to_smt"]
let slice_access
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun pos' -> True))
= valid_facts p1 h sl pos;
slice_access' h g sl pos
let slice_access_eq
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (
valid' p1 h sl pos /\
cl.clens_cond (contents' p1 h sl pos) /\
slice_access h g sl pos == slice_access' h g sl pos
))
= valid_facts p1 h sl pos;
assert_norm (slice_access h g sl pos == slice_access' h g sl pos)
let slice_access_frame_strong
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
k1.parser_kind_subkind == Some ParserStrong /\
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos) /\
B.modifies l h h' /\
B.loc_disjoint l (loc_slice_from_to sl pos (get_valid_pos p1 h sl pos))
))
(ensures (
valid p1 h' sl pos /\
cl.clens_cond (contents p1 h' sl pos) /\
slice_access h' g sl pos == slice_access h g sl pos
))
[SMTPatOr [
[SMTPat (slice_access h g sl pos); SMTPat (B.modifies l h h')];
[SMTPat (slice_access h' g sl pos); SMTPat (B.modifies l h h')];
]]
= valid_facts p1 h sl pos;
valid_facts p1 h' sl pos;
slice_access_eq h g sl pos;
slice_access_eq h' g sl pos;
let pos2 = get_valid_pos p1 h sl pos in
parse_strong_prefix p1 (bytes_of_slice_from h sl pos) (bytes_of_slice_from_to h sl pos pos2);
B.modifies_buffer_from_to_elim sl.base pos (get_valid_pos p1 h sl pos) l h h' ;
parse_strong_prefix p1 (bytes_of_slice_from_to h' sl pos pos2) (bytes_of_slice_from h' sl pos)
let rec valid_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
(decreases (U32.v pos' - U32.v pos))
= k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))
let rec valid_list_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_list p h sl pos pos' <==> (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))))
= assert_norm (valid_list p h sl pos pos' <==> (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))))
let rec contents_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost (list t)
(requires (valid_list p h sl pos pos'))
(ensures (fun _ -> True))
(decreases (U32.v pos' - U32.v pos))
= valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
let contents_list_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h sl pos pos'))
(ensures (contents_list p h sl pos pos' == (
valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
)))
= assert_norm (contents_list p h sl pos pos' == (
valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
))
let rec serialized_list_length (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (l: list t) : GTot nat =
match l with
| [] -> 0
| x :: q -> serialized_length s x + serialized_list_length s q
let serialized_list_length_nil (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Lemma
(serialized_list_length s [] == 0)
= ()
let serialized_list_length_cons (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (x: t) (q: list t) : Lemma
(serialized_list_length s (x :: q) == serialized_length s x + serialized_list_length s q)
= ()
let rec serialized_list_length_append (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (l1 l2: list t) : Lemma
(serialized_list_length s (List.Tot.append l1 l2) == serialized_list_length s l1 + serialized_list_length s l2)
= match l1 with
| [] -> ()
| _ :: q -> serialized_list_length_append s q l2
let rec valid_list_serialized_list_length (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma
(requires (
valid_list p h input pos pos'
))
(ensures (
serialized_list_length s (contents_list p h input pos pos') == U32.v pos' - U32.v pos
))
(decreases (U32.v pos' - U32.v pos))
= if pos = pos'
then valid_list_nil p h input pos
else begin
valid_list_cons_recip p h input pos pos' ;
let pos1 = get_valid_pos p h input pos in
valid_list_serialized_list_length s h input pos1 pos'
end
#restart-solver
#set-options "--fuel 2 --ifuel 2 --z3rlimit 100"
let rec serialized_list_length_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_high == Some k.parser_kind_low})
(l: list t)
: Lemma
(ensures (
serialized_list_length s l == L.length l `Prims.op_Multiply` k.parser_kind_low
))
= match l with
| [] ->
assert (serialized_list_length s l == 0);
assert (L.length l == 0)
| a :: q ->
serialized_list_length_constant_size s q;
serialized_length_eq s a;
assert (serialized_length s a == k.parser_kind_low);
M.distributivity_add_left 1 (L.length q) k.parser_kind_low
#set-options "--fuel 2 --ifuel 1 --z3rlimit 100"
let rec list_flatten_append
(#a: Type)
(l1 l2: list (list a))
: Lemma
(L.flatten (l1 `L.append` l2) == L.flatten l1 `L.append` L.flatten l2)
= match l1 with
| [] -> ()
| a :: q ->
list_flatten_append q l2;
L.append_assoc a (L.flatten q) (L.flatten l2)
let rec list_filter_append
(#t: Type)
(f: (t -> Tot bool))
(l1 l2: list t)
: Lemma
(L.filter f (l1 `L.append` l2) == L.filter f l1 `L.append` L.filter f l2)
= match l1 with
| [] -> ()
| a :: q ->
list_filter_append f q l2
let rec list_index_append (#t: Type) (l1 l2: list t) (i: int) : Lemma
(requires (L.length l1 <= i /\ i < L.length l1 + L.length l2))
(ensures (
L.length (L.append l1 l2) == L.length l1 + L.length l2 /\
L.index (L.append l1 l2) i == L.index l2 (i - L.length l1)
))
= list_length_append l1 l2;
match l1 with
| [] -> ()
| a :: q -> list_index_append q l2 (i - 1)
#set-options "--fuel 2 --ifuel 0 --z3rlimit 500"
#restart-solver
let list_flatten_map_append
(#a #b: Type)
(f: a -> Tot (list b))
(l1 l2: list a)
: Lemma
(L.flatten (L.map f (l1 `L.append` l2)) == L.flatten (L.map f l1) `L.append` L.flatten (L.map f l2))
= L.map_append f l1 l2;
list_flatten_append (L.map f l1) (L.map f l2)
#set-options "--fuel 2 --ifuel 1 --z3rlimit 100" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: (_: a -> b) -> l: Prims.list a
-> FStar.Pervasives.Lemma
(ensures
FStar.List.Tot.Base.map f l ==
FStar.List.Tot.Base.flatten (FStar.List.Tot.Base.map (fun x -> [f x]) l)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.list",
"LowParse.Low.Base.Spec.list_map_list_flatten_map",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.List.Tot.Base.map",
"FStar.List.Tot.Base.flatten",
"Prims.Cons",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec list_map_list_flatten_map (#a #b: Type) (f: (a -> Tot b)) (l: list a)
: Lemma (L.map f l == L.flatten (L.map (fun x -> [f x]) l)) =
| match l with
| [] -> ()
| a :: q -> list_map_list_flatten_map f q | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.slice_access_frame_strong | val slice_access_frame_strong
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
k1.parser_kind_subkind == Some ParserStrong /\
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos) /\
B.modifies l h h' /\
B.loc_disjoint l (loc_slice_from_to sl pos (get_valid_pos p1 h sl pos))
))
(ensures (
valid p1 h' sl pos /\
cl.clens_cond (contents p1 h' sl pos) /\
slice_access h' g sl pos == slice_access h g sl pos
))
[SMTPatOr [
[SMTPat (slice_access h g sl pos); SMTPat (B.modifies l h h')];
[SMTPat (slice_access h' g sl pos); SMTPat (B.modifies l h h')];
]] | val slice_access_frame_strong
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
k1.parser_kind_subkind == Some ParserStrong /\
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos) /\
B.modifies l h h' /\
B.loc_disjoint l (loc_slice_from_to sl pos (get_valid_pos p1 h sl pos))
))
(ensures (
valid p1 h' sl pos /\
cl.clens_cond (contents p1 h' sl pos) /\
slice_access h' g sl pos == slice_access h g sl pos
))
[SMTPatOr [
[SMTPat (slice_access h g sl pos); SMTPat (B.modifies l h h')];
[SMTPat (slice_access h' g sl pos); SMTPat (B.modifies l h h')];
]] | let slice_access_frame_strong
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
k1.parser_kind_subkind == Some ParserStrong /\
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos) /\
B.modifies l h h' /\
B.loc_disjoint l (loc_slice_from_to sl pos (get_valid_pos p1 h sl pos))
))
(ensures (
valid p1 h' sl pos /\
cl.clens_cond (contents p1 h' sl pos) /\
slice_access h' g sl pos == slice_access h g sl pos
))
[SMTPatOr [
[SMTPat (slice_access h g sl pos); SMTPat (B.modifies l h h')];
[SMTPat (slice_access h' g sl pos); SMTPat (B.modifies l h h')];
]]
= valid_facts p1 h sl pos;
valid_facts p1 h' sl pos;
slice_access_eq h g sl pos;
slice_access_eq h' g sl pos;
let pos2 = get_valid_pos p1 h sl pos in
parse_strong_prefix p1 (bytes_of_slice_from h sl pos) (bytes_of_slice_from_to h sl pos pos2);
B.modifies_buffer_from_to_elim sl.base pos (get_valid_pos p1 h sl pos) l h h' ;
parse_strong_prefix p1 (bytes_of_slice_from_to h' sl pos pos2) (bytes_of_slice_from h' sl pos) | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 96,
"end_line": 485,
"start_col": 0,
"start_line": 446
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x))
let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos)
let get_valid_pos_post
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (
let pos' = get_valid_pos p h sl pos in
valid_pos p h sl pos pos'
))
[SMTPat (get_valid_pos p h sl pos)]
= ()
let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
= valid_exact' p h s pos pos'
let valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
= assert_norm (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
let contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost t
(requires (valid_exact p h s pos pos'))
(ensures (fun _ -> True))
= valid_exact_equiv p h s pos pos' ;
contents_exact' p h s pos pos'
let contents_exact_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_exact p h s pos pos'))
(ensures (valid_exact p h s pos pos' /\ valid_exact' p h s pos pos' /\ contents_exact p h s pos pos' == contents_exact' p h s pos pos'))
= valid_exact_equiv p h s pos pos' ;
assert_norm (contents_exact p h s pos pos' == contents_exact' p h s pos pos')
let gaccessor_prop
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: GTot Type0
= gaccessor_prop' f
let gaccessor_prop_equiv
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: Lemma
(gaccessor_prop f <==> gaccessor_prop' f)
= ()
let gaccessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (gaccessor p p (clens_id _))
= gaccessor_id' p
let gaccessor_id_eq
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(gaccessor_id p input == gaccessor_id' p input)
= ()
let gaccessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (gaccessor p1 p2 cl')
= gaccessor_ext' g cl' sq
let gaccessor_ext_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
(input: bytes)
: Lemma
(gaccessor_ext g cl sq input == gaccessor_ext' g cl sq input)
= ()
let gaccessor_compose_injective
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ injective_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
assert (injective_precond p2 sl_ sl'_)
let gaccessor_compose_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (k1.parser_kind_subkind == Some ParserStrong /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ no_lookahead_on_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
parse_strong_prefix p1 sl sl';
assert (injective_precond p1 sl sl');
assert (injective_precond p2 sl_ sl'_)
[@"opaque_to_smt"]
let gaccessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
: Tot (gaccessor p1 p3 (clens_compose cl12 cl23))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_injective a12 a23 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_no_lookahead a12 a23 x));
gaccessor_compose' a12 a23
let gaccessor_compose_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(input: bytes)
: Lemma
(gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
= assert_norm (gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
[@"opaque_to_smt"]
let slice_access
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun pos' -> True))
= valid_facts p1 h sl pos;
slice_access' h g sl pos
let slice_access_eq
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (
valid' p1 h sl pos /\
cl.clens_cond (contents' p1 h sl pos) /\
slice_access h g sl pos == slice_access' h g sl pos
))
= valid_facts p1 h sl pos;
assert_norm (slice_access h g sl pos == slice_access' h g sl pos) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h: FStar.Monotonic.HyperStack.mem ->
g: LowParse.Low.Base.Spec.gaccessor p1 p2 cl ->
sl: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
l: LowStar.Monotonic.Buffer.loc ->
h': FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires
Mkparser_kind'?.parser_kind_subkind k1 ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
LowParse.Low.Base.Spec.valid p1 h sl pos /\
Mkclens?.clens_cond cl (LowParse.Low.Base.Spec.contents p1 h sl pos) /\
LowStar.Monotonic.Buffer.modifies l h h' /\
LowStar.Monotonic.Buffer.loc_disjoint l
(LowParse.Slice.loc_slice_from_to sl
pos
(LowParse.Low.Base.Spec.get_valid_pos p1 h sl pos)))
(ensures
LowParse.Low.Base.Spec.valid p1 h' sl pos /\
Mkclens?.clens_cond cl (LowParse.Low.Base.Spec.contents p1 h' sl pos) /\
LowParse.Low.Base.Spec.slice_access h' g sl pos ==
LowParse.Low.Base.Spec.slice_access h g sl pos)
[
SMTPatOr [
[
SMTPat (LowParse.Low.Base.Spec.slice_access h g sl pos);
SMTPat (LowStar.Monotonic.Buffer.modifies l h h')
];
[
SMTPat (LowParse.Low.Base.Spec.slice_access h' g sl pos);
SMTPat (LowStar.Monotonic.Buffer.modifies l h h')
]
]
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.Spec.clens",
"LowParse.Low.Base.Spec.gaccessor",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.loc",
"LowParse.Spec.Base.parse_strong_prefix",
"LowParse.Low.Base.Spec.bytes_of_slice_from_to",
"LowParse.Slice.bytes_of_slice_from",
"Prims.unit",
"LowStar.Monotonic.Buffer.modifies_buffer_from_to_elim",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"LowParse.Low.Base.Spec.get_valid_pos",
"LowParse.Low.Base.Spec.slice_access_eq",
"LowParse.Low.Base.Spec.valid_facts",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Low.Base.Spec.valid",
"LowParse.Low.Base.Spec.__proj__Mkclens__item__clens_cond",
"LowParse.Low.Base.Spec.contents",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_disjoint",
"LowParse.Slice.loc_slice_from_to",
"Prims.squash",
"LowParse.Low.Base.Spec.slice_access",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat_or",
"Prims.list",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let slice_access_frame_strong
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
(l: B.loc)
(h': HS.mem)
: Lemma
(requires
(k1.parser_kind_subkind == Some ParserStrong /\ valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos) /\ B.modifies l h h' /\
B.loc_disjoint l (loc_slice_from_to sl pos (get_valid_pos p1 h sl pos))))
(ensures
(valid p1 h' sl pos /\ cl.clens_cond (contents p1 h' sl pos) /\
slice_access h' g sl pos == slice_access h g sl pos))
[
SMTPatOr
[
[SMTPat (slice_access h g sl pos); SMTPat (B.modifies l h h')];
[SMTPat (slice_access h' g sl pos); SMTPat (B.modifies l h h')]
]
] =
| valid_facts p1 h sl pos;
valid_facts p1 h' sl pos;
slice_access_eq h g sl pos;
slice_access_eq h' g sl pos;
let pos2 = get_valid_pos p1 h sl pos in
parse_strong_prefix p1 (bytes_of_slice_from h sl pos) (bytes_of_slice_from_to h sl pos pos2);
B.modifies_buffer_from_to_elim sl.base pos (get_valid_pos p1 h sl pos) l h h';
parse_strong_prefix p1 (bytes_of_slice_from_to h' sl pos pos2) (bytes_of_slice_from h' sl pos) | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.list_index_append | val list_index_append (#t: Type) (l1 l2: list t) (i: int) : Lemma
(requires (L.length l1 <= i /\ i < L.length l1 + L.length l2))
(ensures (
L.length (L.append l1 l2) == L.length l1 + L.length l2 /\
L.index (L.append l1 l2) i == L.index l2 (i - L.length l1)
)) | val list_index_append (#t: Type) (l1 l2: list t) (i: int) : Lemma
(requires (L.length l1 <= i /\ i < L.length l1 + L.length l2))
(ensures (
L.length (L.append l1 l2) == L.length l1 + L.length l2 /\
L.index (L.append l1 l2) i == L.index l2 (i - L.length l1)
)) | let rec list_index_append (#t: Type) (l1 l2: list t) (i: int) : Lemma
(requires (L.length l1 <= i /\ i < L.length l1 + L.length l2))
(ensures (
L.length (L.append l1 l2) == L.length l1 + L.length l2 /\
L.index (L.append l1 l2) i == L.index l2 (i - L.length l1)
))
= list_length_append l1 l2;
match l1 with
| [] -> ()
| a :: q -> list_index_append q l2 (i - 1) | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 44,
"end_line": 684,
"start_col": 0,
"start_line": 675
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x))
let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos)
let get_valid_pos_post
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (
let pos' = get_valid_pos p h sl pos in
valid_pos p h sl pos pos'
))
[SMTPat (get_valid_pos p h sl pos)]
= ()
let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
= valid_exact' p h s pos pos'
let valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
= assert_norm (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
let contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost t
(requires (valid_exact p h s pos pos'))
(ensures (fun _ -> True))
= valid_exact_equiv p h s pos pos' ;
contents_exact' p h s pos pos'
let contents_exact_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_exact p h s pos pos'))
(ensures (valid_exact p h s pos pos' /\ valid_exact' p h s pos pos' /\ contents_exact p h s pos pos' == contents_exact' p h s pos pos'))
= valid_exact_equiv p h s pos pos' ;
assert_norm (contents_exact p h s pos pos' == contents_exact' p h s pos pos')
let gaccessor_prop
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: GTot Type0
= gaccessor_prop' f
let gaccessor_prop_equiv
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: Lemma
(gaccessor_prop f <==> gaccessor_prop' f)
= ()
let gaccessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (gaccessor p p (clens_id _))
= gaccessor_id' p
let gaccessor_id_eq
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(gaccessor_id p input == gaccessor_id' p input)
= ()
let gaccessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (gaccessor p1 p2 cl')
= gaccessor_ext' g cl' sq
let gaccessor_ext_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
(input: bytes)
: Lemma
(gaccessor_ext g cl sq input == gaccessor_ext' g cl sq input)
= ()
let gaccessor_compose_injective
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ injective_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
assert (injective_precond p2 sl_ sl'_)
let gaccessor_compose_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (k1.parser_kind_subkind == Some ParserStrong /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ no_lookahead_on_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
parse_strong_prefix p1 sl sl';
assert (injective_precond p1 sl sl');
assert (injective_precond p2 sl_ sl'_)
[@"opaque_to_smt"]
let gaccessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
: Tot (gaccessor p1 p3 (clens_compose cl12 cl23))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_injective a12 a23 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_no_lookahead a12 a23 x));
gaccessor_compose' a12 a23
let gaccessor_compose_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(input: bytes)
: Lemma
(gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
= assert_norm (gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
[@"opaque_to_smt"]
let slice_access
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun pos' -> True))
= valid_facts p1 h sl pos;
slice_access' h g sl pos
let slice_access_eq
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (
valid' p1 h sl pos /\
cl.clens_cond (contents' p1 h sl pos) /\
slice_access h g sl pos == slice_access' h g sl pos
))
= valid_facts p1 h sl pos;
assert_norm (slice_access h g sl pos == slice_access' h g sl pos)
let slice_access_frame_strong
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
k1.parser_kind_subkind == Some ParserStrong /\
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos) /\
B.modifies l h h' /\
B.loc_disjoint l (loc_slice_from_to sl pos (get_valid_pos p1 h sl pos))
))
(ensures (
valid p1 h' sl pos /\
cl.clens_cond (contents p1 h' sl pos) /\
slice_access h' g sl pos == slice_access h g sl pos
))
[SMTPatOr [
[SMTPat (slice_access h g sl pos); SMTPat (B.modifies l h h')];
[SMTPat (slice_access h' g sl pos); SMTPat (B.modifies l h h')];
]]
= valid_facts p1 h sl pos;
valid_facts p1 h' sl pos;
slice_access_eq h g sl pos;
slice_access_eq h' g sl pos;
let pos2 = get_valid_pos p1 h sl pos in
parse_strong_prefix p1 (bytes_of_slice_from h sl pos) (bytes_of_slice_from_to h sl pos pos2);
B.modifies_buffer_from_to_elim sl.base pos (get_valid_pos p1 h sl pos) l h h' ;
parse_strong_prefix p1 (bytes_of_slice_from_to h' sl pos pos2) (bytes_of_slice_from h' sl pos)
let rec valid_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
(decreases (U32.v pos' - U32.v pos))
= k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))
let rec valid_list_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_list p h sl pos pos' <==> (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))))
= assert_norm (valid_list p h sl pos pos' <==> (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))))
let rec contents_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost (list t)
(requires (valid_list p h sl pos pos'))
(ensures (fun _ -> True))
(decreases (U32.v pos' - U32.v pos))
= valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
let contents_list_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h sl pos pos'))
(ensures (contents_list p h sl pos pos' == (
valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
)))
= assert_norm (contents_list p h sl pos pos' == (
valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
))
let rec serialized_list_length (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (l: list t) : GTot nat =
match l with
| [] -> 0
| x :: q -> serialized_length s x + serialized_list_length s q
let serialized_list_length_nil (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Lemma
(serialized_list_length s [] == 0)
= ()
let serialized_list_length_cons (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (x: t) (q: list t) : Lemma
(serialized_list_length s (x :: q) == serialized_length s x + serialized_list_length s q)
= ()
let rec serialized_list_length_append (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (l1 l2: list t) : Lemma
(serialized_list_length s (List.Tot.append l1 l2) == serialized_list_length s l1 + serialized_list_length s l2)
= match l1 with
| [] -> ()
| _ :: q -> serialized_list_length_append s q l2
let rec valid_list_serialized_list_length (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma
(requires (
valid_list p h input pos pos'
))
(ensures (
serialized_list_length s (contents_list p h input pos pos') == U32.v pos' - U32.v pos
))
(decreases (U32.v pos' - U32.v pos))
= if pos = pos'
then valid_list_nil p h input pos
else begin
valid_list_cons_recip p h input pos pos' ;
let pos1 = get_valid_pos p h input pos in
valid_list_serialized_list_length s h input pos1 pos'
end
#restart-solver
#set-options "--fuel 2 --ifuel 2 --z3rlimit 100"
let rec serialized_list_length_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_high == Some k.parser_kind_low})
(l: list t)
: Lemma
(ensures (
serialized_list_length s l == L.length l `Prims.op_Multiply` k.parser_kind_low
))
= match l with
| [] ->
assert (serialized_list_length s l == 0);
assert (L.length l == 0)
| a :: q ->
serialized_list_length_constant_size s q;
serialized_length_eq s a;
assert (serialized_length s a == k.parser_kind_low);
M.distributivity_add_left 1 (L.length q) k.parser_kind_low
#set-options "--fuel 2 --ifuel 1 --z3rlimit 100"
let rec list_flatten_append
(#a: Type)
(l1 l2: list (list a))
: Lemma
(L.flatten (l1 `L.append` l2) == L.flatten l1 `L.append` L.flatten l2)
= match l1 with
| [] -> ()
| a :: q ->
list_flatten_append q l2;
L.append_assoc a (L.flatten q) (L.flatten l2)
let rec list_filter_append
(#t: Type)
(f: (t -> Tot bool))
(l1 l2: list t)
: Lemma
(L.filter f (l1 `L.append` l2) == L.filter f l1 `L.append` L.filter f l2)
= match l1 with
| [] -> ()
| a :: q ->
list_filter_append f q l2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | l1: Prims.list t -> l2: Prims.list t -> i: Prims.int
-> FStar.Pervasives.Lemma
(requires
FStar.List.Tot.Base.length l1 <= i /\
i < FStar.List.Tot.Base.length l1 + FStar.List.Tot.Base.length l2)
(ensures
FStar.List.Tot.Base.length (l1 @ l2) ==
FStar.List.Tot.Base.length l1 + FStar.List.Tot.Base.length l2 /\
FStar.List.Tot.Base.index (l1 @ l2) i ==
FStar.List.Tot.Base.index l2 (i - FStar.List.Tot.Base.length l1)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.list",
"Prims.int",
"LowParse.Low.Base.Spec.list_index_append",
"Prims.op_Subtraction",
"Prims.unit",
"LowParse.Low.Base.Spec.list_length_append",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.List.Tot.Base.length",
"Prims.op_LessThan",
"Prims.op_Addition",
"Prims.squash",
"Prims.eq2",
"FStar.List.Tot.Base.append",
"FStar.List.Tot.Base.index",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec list_index_append (#t: Type) (l1 l2: list t) (i: int)
: Lemma (requires (L.length l1 <= i /\ i < L.length l1 + L.length l2))
(ensures
(L.length (L.append l1 l2) == L.length l1 + L.length l2 /\
L.index (L.append l1 l2) i == L.index l2 (i - L.length l1))) =
| list_length_append l1 l2;
match l1 with
| [] -> ()
| a :: q -> list_index_append q l2 (i - 1) | false |
LowParse.Low.Base.Spec.fst | LowParse.Low.Base.Spec.list_flatten_append | val list_flatten_append
(#a: Type)
(l1 l2: list (list a))
: Lemma
(L.flatten (l1 `L.append` l2) == L.flatten l1 `L.append` L.flatten l2) | val list_flatten_append
(#a: Type)
(l1 l2: list (list a))
: Lemma
(L.flatten (l1 `L.append` l2) == L.flatten l1 `L.append` L.flatten l2) | let rec list_flatten_append
(#a: Type)
(l1 l2: list (list a))
: Lemma
(L.flatten (l1 `L.append` l2) == L.flatten l1 `L.append` L.flatten l2)
= match l1 with
| [] -> ()
| a :: q ->
list_flatten_append q l2;
L.append_assoc a (L.flatten q) (L.flatten l2) | {
"file_name": "src/lowparse/LowParse.Low.Base.Spec.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 49,
"end_line": 662,
"start_col": 0,
"start_line": 653
} | module LowParse.Low.Base.Spec
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
let valid
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: GTot Type0
= valid' p h s pos
let valid_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(valid p h s pos <==> valid' p h s pos)
= assert_norm (valid p h s pos <==> valid' p h s pos)
let valid_dec
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost bool
(requires (live_slice h s))
(ensures (fun b ->
b == true <==> valid p h s pos
))
= valid_equiv p h s pos;
(not (pos `U32.gt` s.len)) && Some? (parse p (bytes_of_slice_from h s pos))
let contents
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Ghost t
(requires (valid p h s pos))
(ensures (fun _ -> True))
= valid_equiv p h s pos;
contents' p h s pos
let contents_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h s pos))
(ensures (valid p h s pos /\ valid' p h s pos /\ contents p h s pos == contents' p h s pos))
= valid_equiv p h s pos;
assert_norm (contents p h s pos == contents' p h s pos)
let content_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost nat
(requires (valid p h sl pos))
(ensures (fun res -> True))
= valid_equiv p h sl pos;
content_length' p h sl pos
let serialized_length
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Ghost nat
(requires True)
(ensures (fun res ->
k.parser_kind_low <= res /\ (
match k.parser_kind_high with
| None -> True
| Some max -> res <= max
)))
= Seq.length (serialize s x)
let serialized_length_eq
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: Lemma
(serialized_length s x == Seq.length (serialize s x))
= ()
let content_length_eq_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (valid p h sl pos /\ valid' p h sl pos /\ content_length p h sl pos == content_length' p h sl pos))
= valid_equiv p h sl pos;
assert_norm (content_length p h sl pos == content_length' p h sl pos)
let content_length_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (content_length p h sl pos == serialized_length s (contents p h sl pos)))
[SMTPat (serialized_length s (contents p h sl pos))]
= parser_kind_prop_equiv k p;
content_length_eq_gen p h sl pos;
contents_eq p h sl pos;
let b = bytes_of_slice_from h sl pos in
let Some (x, consumed) = parse p b in
assert (x == contents p h sl pos);
let ps' = parse p (serialize s x) in
assert (serializer_correct p s);
assert (Some? ps');
assert (injective_precond p b (serialize s x))
let get_valid_pos
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (valid p h sl pos))
(ensures (fun pos' -> True))
= pos `U32.add` U32.uint_to_t (content_length p h sl pos)
let get_valid_pos_post
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p h sl pos))
(ensures (
let pos' = get_valid_pos p h sl pos in
valid_pos p h sl pos pos'
))
[SMTPat (get_valid_pos p h sl pos)]
= ()
let valid_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
= valid_exact' p h s pos pos'
let valid_exact_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
= assert_norm (valid_exact p h s pos pos' <==> valid_exact' p h s pos pos')
let contents_exact
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost t
(requires (valid_exact p h s pos pos'))
(ensures (fun _ -> True))
= valid_exact_equiv p h s pos pos' ;
contents_exact' p h s pos pos'
let contents_exact_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(s: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_exact p h s pos pos'))
(ensures (valid_exact p h s pos pos' /\ valid_exact' p h s pos pos' /\ contents_exact p h s pos pos' == contents_exact' p h s pos pos'))
= valid_exact_equiv p h s pos pos' ;
assert_norm (contents_exact p h s pos pos' == contents_exact' p h s pos pos')
let gaccessor_prop
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: GTot Type0
= gaccessor_prop' f
let gaccessor_prop_equiv
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(cl: clens t1 t2)
(f: gaccessor' p1 p2 cl)
: Lemma
(gaccessor_prop f <==> gaccessor_prop' f)
= ()
let gaccessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (gaccessor p p (clens_id _))
= gaccessor_id' p
let gaccessor_id_eq
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(gaccessor_id p input == gaccessor_id' p input)
= ()
let gaccessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (gaccessor p1 p2 cl')
= gaccessor_ext' g cl' sq
let gaccessor_ext_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
(input: bytes)
: Lemma
(gaccessor_ext g cl sq input == gaccessor_ext' g cl sq input)
= ()
let gaccessor_compose_injective
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ injective_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
assert (injective_precond p2 sl_ sl'_)
let gaccessor_compose_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(sl sl': bytes)
: Lemma
(requires (k1.parser_kind_subkind == Some ParserStrong /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl /\ gaccessor_pre p1 p3 (clens_compose cl12 cl23) sl' /\ no_lookahead_on_precond p1 sl sl'))
(ensures (gaccessor_compose' a12 a23 sl == gaccessor_compose' a12 a23 sl'))
= let sl_ = Seq.slice sl (a12 sl) (Seq.length sl) in
let sl'_ = Seq.slice sl' (a12 sl') (Seq.length sl') in
parse_strong_prefix p1 sl sl';
assert (injective_precond p1 sl sl');
assert (injective_precond p2 sl_ sl'_)
[@"opaque_to_smt"]
let gaccessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
: Tot (gaccessor p1 p3 (clens_compose cl12 cl23))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_injective a12 a23 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_compose_no_lookahead a12 a23 x));
gaccessor_compose' a12 a23
let gaccessor_compose_eq
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(a12: gaccessor p1 p2 cl12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(a23: gaccessor p2 p3 cl23)
(input: bytes)
: Lemma
(gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
= assert_norm (gaccessor_compose a12 a23 input == gaccessor_compose' a12 a23 input)
[@"opaque_to_smt"]
let slice_access
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Ghost U32.t
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun pos' -> True))
= valid_facts p1 h sl pos;
slice_access' h g sl pos
let slice_access_eq
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (
valid' p1 h sl pos /\
cl.clens_cond (contents' p1 h sl pos) /\
slice_access h g sl pos == slice_access' h g sl pos
))
= valid_facts p1 h sl pos;
assert_norm (slice_access h g sl pos == slice_access' h g sl pos)
let slice_access_frame_strong
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
(sl: slice rrel rel)
(pos: U32.t)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
k1.parser_kind_subkind == Some ParserStrong /\
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos) /\
B.modifies l h h' /\
B.loc_disjoint l (loc_slice_from_to sl pos (get_valid_pos p1 h sl pos))
))
(ensures (
valid p1 h' sl pos /\
cl.clens_cond (contents p1 h' sl pos) /\
slice_access h' g sl pos == slice_access h g sl pos
))
[SMTPatOr [
[SMTPat (slice_access h g sl pos); SMTPat (B.modifies l h h')];
[SMTPat (slice_access h' g sl pos); SMTPat (B.modifies l h h')];
]]
= valid_facts p1 h sl pos;
valid_facts p1 h' sl pos;
slice_access_eq h g sl pos;
slice_access_eq h' g sl pos;
let pos2 = get_valid_pos p1 h sl pos in
parse_strong_prefix p1 (bytes_of_slice_from h sl pos) (bytes_of_slice_from_to h sl pos pos2);
B.modifies_buffer_from_to_elim sl.base pos (get_valid_pos p1 h sl pos) l h h' ;
parse_strong_prefix p1 (bytes_of_slice_from_to h' sl pos pos2) (bytes_of_slice_from h' sl pos)
let rec valid_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: GTot Type0
(decreases (U32.v pos' - U32.v pos))
= k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))
let rec valid_list_equiv
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(valid_list p h sl pos pos' <==> (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))))
= assert_norm (valid_list p h sl pos pos' <==> (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_low > 0 /\
live_slice h sl /\
U32.v pos' <= U32.v sl.len /\ (
if pos = pos'
then True
else
valid p h sl pos /\ (
let pos1 = get_valid_pos p h sl pos in
U32.v pos1 <= U32.v pos' /\
valid_list p h sl pos1 pos'
))))
let rec contents_list
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Ghost (list t)
(requires (valid_list p h sl pos pos'))
(ensures (fun _ -> True))
(decreases (U32.v pos' - U32.v pos))
= valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
let contents_list_eq
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(h: HS.mem)
(sl: slice rrel rel)
(pos: U32.t)
(pos' : U32.t)
: Lemma
(requires (valid_list p h sl pos pos'))
(ensures (contents_list p h sl pos pos' == (
valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
)))
= assert_norm (contents_list p h sl pos pos' == (
valid_list_equiv p h sl pos pos';
if pos = pos'
then []
else
contents p h sl pos :: contents_list p h sl (get_valid_pos p h sl pos) pos'
))
let rec serialized_list_length (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (l: list t) : GTot nat =
match l with
| [] -> 0
| x :: q -> serialized_length s x + serialized_list_length s q
let serialized_list_length_nil (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) : Lemma
(serialized_list_length s [] == 0)
= ()
let serialized_list_length_cons (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (x: t) (q: list t) : Lemma
(serialized_list_length s (x :: q) == serialized_length s x + serialized_list_length s q)
= ()
let rec serialized_list_length_append (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (l1 l2: list t) : Lemma
(serialized_list_length s (List.Tot.append l1 l2) == serialized_list_length s l1 + serialized_list_length s l2)
= match l1 with
| [] -> ()
| _ :: q -> serialized_list_length_append s q l2
let rec valid_list_serialized_list_length (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma
(requires (
valid_list p h input pos pos'
))
(ensures (
serialized_list_length s (contents_list p h input pos pos') == U32.v pos' - U32.v pos
))
(decreases (U32.v pos' - U32.v pos))
= if pos = pos'
then valid_list_nil p h input pos
else begin
valid_list_cons_recip p h input pos pos' ;
let pos1 = get_valid_pos p h input pos in
valid_list_serialized_list_length s h input pos1 pos'
end
#restart-solver
#set-options "--fuel 2 --ifuel 2 --z3rlimit 100"
let rec serialized_list_length_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {k.parser_kind_high == Some k.parser_kind_low})
(l: list t)
: Lemma
(ensures (
serialized_list_length s l == L.length l `Prims.op_Multiply` k.parser_kind_low
))
= match l with
| [] ->
assert (serialized_list_length s l == 0);
assert (L.length l == 0)
| a :: q ->
serialized_list_length_constant_size s q;
serialized_length_eq s a;
assert (serialized_length s a == k.parser_kind_low);
M.distributivity_add_left 1 (L.length q) k.parser_kind_low
#set-options "--fuel 2 --ifuel 1 --z3rlimit 100" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "LowParse.Low.Base.Spec.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Slice",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": 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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | l1: Prims.list (Prims.list a) -> l2: Prims.list (Prims.list a)
-> FStar.Pervasives.Lemma
(ensures
FStar.List.Tot.Base.flatten (l1 @ l2) ==
FStar.List.Tot.Base.flatten l1 @ FStar.List.Tot.Base.flatten l2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.list",
"FStar.List.Tot.Properties.append_assoc",
"FStar.List.Tot.Base.flatten",
"Prims.unit",
"LowParse.Low.Base.Spec.list_flatten_append",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.List.Tot.Base.append",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec list_flatten_append (#a: Type) (l1 l2: list (list a))
: Lemma (L.flatten (l1 `L.append` l2) == (L.flatten l1) `L.append` (L.flatten l2)) =
| match l1 with
| [] -> ()
| a :: q ->
list_flatten_append q l2;
L.append_assoc a (L.flatten q) (L.flatten l2) | false |
EverCrypt.AEAD.fst | EverCrypt.AEAD.create_in_aes_gcm | val create_in_aes_gcm (i: vale_impl) : create_in_st (alg_of_vale_impl i) | val create_in_aes_gcm (i: vale_impl) : create_in_st (alg_of_vale_impl i) | let create_in_aes_gcm (i: vale_impl):
create_in_st (alg_of_vale_impl i) =
fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv: G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale then (
let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx() in
let has_sse = EverCrypt.AutoConfig2.has_sse() in
let has_movbe = EverCrypt.AutoConfig2.has_movbe() in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe) then (
let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success
) else
UnsupportedAlgorithm
) else
UnsupportedAlgorithm | {
"file_name": "providers/evercrypt/fst/EverCrypt.AEAD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 149,
"start_col": 0,
"start_line": 120
} | module EverCrypt.AEAD
module S = FStar.Seq
module G = FStar.Ghost
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module MB = LowStar.Monotonic.Buffer
module B = LowStar.Buffer
open FStar.HyperStack.ST
open FStar.Integers
open FStar.Int.Cast
open Spec.Agile.AEAD
open Spec.Cipher.Expansion
open EverCrypt.CTR.Keys
friend Spec.Agile.AEAD
friend Spec.Cipher.Expansion
friend EverCrypt.CTR.Keys
#set-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
/// Defining abstract predicates, invariants, footprint, etc.
/// ---------------------------------------------------------
let _: squash (inversion impl) = allow_inversion impl
/// We now distinguish between an expanded key (as mandated by NIST spec) and a
/// **concrete** expanded key, which may contain implementation-specific details
/// and extra precomputations. In the rest of this module, we rely on concrete
/// expanded keys, which are parameterized over an implementation, instead of
/// regular expanded keys, which are parameterized over an algorithm. Helpers
/// allow us to move from one notion to the other.
let supported_alg_of_impl (i: impl): supported_alg =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
| Hacl_CHACHA20 -> CHACHA20_POLY1305
inline_for_extraction noextract
let alg_of_vale_impl (i: vale_impl) =
match i with
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
noeq
type state_s a =
| Ek: impl:impl ->
kv:G.erased (kv a) ->
ek:B.buffer UInt8.t -> // concrete expanded key
state_s a
let invert_state_s (a: alg): Lemma
(requires True)
(ensures (inversion (state_s a)))
[ SMTPat (state_s a) ]
=
allow_inversion (state_s a)
let freeable_s #a (Ek _ _ ek) = B.freeable ek
let footprint_s #a (Ek _ _ ek) = B.loc_addr_of_buffer ek
let invariant_s #a h (Ek i kv ek) =
is_supported_alg a /\
a = supported_alg_of_impl i /\
B.live h ek /\
B.length ek >= concrete_xkey_length i /\
B.as_seq h (B.gsub ek 0ul (UInt32.uint_to_t (concrete_xkey_length i)))
`S.equal` concrete_expand i (G.reveal kv) /\
config_pre a /\ (
match i with
| Vale_AES128
| Vale_AES256 ->
// Expanded key length + precomputed stuff + scratch space (AES-GCM specific)
B.length ek =
vale_xkey_length (cipher_alg_of_supported_alg a) + 176
| Hacl_CHACHA20 ->
B.length ek = concrete_xkey_length i)
let invariant_loc_in_footprint #a s m =
()
let frame_invariant #a l s h0 h1 =
()
/// Actual stateful API
/// -------------------
let alg_of_state a s =
let open LowStar.BufferOps in
let Ek impl _ _ = !*s in
match impl with
| Hacl_CHACHA20 -> CHACHA20_POLY1305
| Vale_AES128 -> AES128_GCM
| Vale_AES256 -> AES256_GCM
let as_kv #a (Ek _ kv _) =
G.reveal kv
#push-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --z3cliopt smt.QI.EAGER_THRESHOLD=5"
let create_in_chacha20_poly1305: create_in_st CHACHA20_POLY1305 = fun r dst k ->
let h0 = ST.get () in
let ek = B.malloc r 0uy 32ul in
let p = B.malloc r (Ek Hacl_CHACHA20 (G.hide (B.as_seq h0 k)) ek) 1ul in
B.blit k 0ul ek 0ul 32ul;
B.upd dst 0ul p;
let h2 = ST.get() in
B.modifies_only_not_unused_in B.(loc_buffer dst) h0 h2;
Success
#pop-options | {
"checked_file": "/",
"dependencies": [
"Vale.Wrapper.X64.GCMencryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Wrapper.X64.GCM_IV.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Cipher.Expansion.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"Spec.Agile.AEAD.fst.checked",
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Calc.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.CTR.Keys.fst.checked",
"EverCrypt.Chacha20Poly1305.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": true,
"source_file": "EverCrypt.AEAD.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.CTR.Keys",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Cipher.Expansion",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt.Error",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "Spec"
},
{
"abbrev": false,
"full_module": "Spec.Agile.AEAD",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "MB"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: EverCrypt.CTR.Keys.vale_impl -> EverCrypt.AEAD.create_in_st (EverCrypt.AEAD.alg_of_vale_impl i) | Prims.Tot | [
"total"
] | [] | [
"EverCrypt.CTR.Keys.vale_impl",
"FStar.Monotonic.HyperHeap.rid",
"LowStar.Buffer.pointer",
"LowStar.Buffer.pointer_or_null",
"EverCrypt.AEAD.state_s",
"EverCrypt.AEAD.alg_of_vale_impl",
"LowStar.Buffer.buffer",
"EverCrypt.CTR.Keys.uint8",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.Integers.op_Greater_Equals",
"FStar.Integers.Signed",
"FStar.Integers.Winfinite",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"Spec.Agile.AEAD.key_length",
"EverCrypt.TargetConfig.hacl_can_compile_vale",
"Prims.op_AmpAmp",
"EverCrypt.Error.Success",
"Prims.unit",
"LowStar.Monotonic.Buffer.modifies_only_not_unused_in",
"LowStar.Monotonic.Buffer.loc_buffer",
"EverCrypt.Error.error_code",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowStar.BufferOps.op_Star_Equals",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.l_and",
"Prims.eq2",
"Prims.nat",
"FStar.UInt32.v",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Prims.op_Negation",
"LowStar.Monotonic.Buffer.g_is_null",
"LowStar.Monotonic.Buffer.frameOf",
"LowStar.Monotonic.Buffer.freeable",
"LowStar.Buffer.malloc",
"EverCrypt.AEAD.Ek",
"FStar.Ghost.hide",
"Spec.Agile.AEAD.kv",
"LowStar.Monotonic.Buffer.as_seq",
"FStar.UInt32.__uint_to_t",
"LowStar.Monotonic.Buffer.loc_none",
"EverCrypt.CTR.Keys.vale_expand",
"FStar.UInt32.add",
"EverCrypt.CTR.Keys.concrete_xkey_len",
"FStar.UInt8.__uint_to_t",
"FStar.Integers.op_Plus",
"FStar.Integers.Unsigned",
"FStar.Integers.W32",
"Prims.bool",
"EverCrypt.Error.UnsupportedAlgorithm",
"EverCrypt.AutoConfig2.has_movbe",
"EverCrypt.AutoConfig2.has_sse",
"EverCrypt.AutoConfig2.has_avx",
"EverCrypt.AutoConfig2.has_pclmulqdq",
"EverCrypt.AutoConfig2.has_aesni",
"FStar.Ghost.erased",
"Spec.Agile.AEAD.alg",
"EverCrypt.AEAD.create_in_st"
] | [] | false | false | false | false | false | let create_in_aes_gcm (i: vale_impl) : create_in_st (alg_of_vale_impl i) =
| fun r dst k ->
let a = alg_of_vale_impl i in
let h0 = ST.get () in
let kv:G.erased (kv a) = G.hide (B.as_seq h0 k) in
if EverCrypt.TargetConfig.hacl_can_compile_vale
then
(let has_aesni = EverCrypt.AutoConfig2.has_aesni () in
let has_pclmulqdq = EverCrypt.AutoConfig2.has_pclmulqdq () in
let has_avx = EverCrypt.AutoConfig2.has_avx () in
let has_sse = EverCrypt.AutoConfig2.has_sse () in
let has_movbe = EverCrypt.AutoConfig2.has_movbe () in
if (has_aesni && has_pclmulqdq && has_avx && has_sse && has_movbe)
then
(let ek = B.malloc r 0uy (concrete_xkey_len i + 176ul) in
vale_expand i k ek;
let h2 = ST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h2;
let p = B.malloc r (Ek i (G.hide (B.as_seq h0 k)) ek) 1ul in
let open LowStar.BufferOps in
dst *= p;
let h3 = ST.get () in
B.modifies_only_not_unused_in B.(loc_buffer dst) h2 h3;
Success)
else UnsupportedAlgorithm)
else UnsupportedAlgorithm | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.