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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
MSort.SeqLemmas.fst | MSort.SeqLemmas.append_slice | val append_slice #a (s : S.seq a)
(l1:nat) (l2 : nat{S.length s == l2 /\ l1 <= l2})
: Lemma (S.append (S.slice s 0 l1) (S.slice s l1 l2) == s)
[SMTPat (S.append (S.slice s 0 l1) (S.slice s l1 l2))] | val append_slice #a (s : S.seq a)
(l1:nat) (l2 : nat{S.length s == l2 /\ l1 <= l2})
: Lemma (S.append (S.slice s 0 l1) (S.slice s l1 l2) == s)
[SMTPat (S.append (S.slice s 0 l1) (S.slice s l1 l2))] | let append_slice s l1 l2 =
assert (S.equal (S.append (S.slice s 0 l1) (S.slice s l1 l2)) s);
() | {
"file_name": "share/steel/examples/pulse/MSort.SeqLemmas.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 4,
"end_line": 52,
"start_col": 0,
"start_line": 50
} | module MSort.SeqLemmas
open FStar.Ghost
module S = FStar.Seq
assume val sort : Seq.seq int -> Seq.seq int
assume val sorted : Seq.seq int -> bool
assume val sort_is_sorted (s:Seq.seq int) : Lemma (sorted (sort s))
assume val sort_len (s:Seq.seq int)
: Lemma (S.length (sort s) == S.length s)
[SMTPat (S.length (sort s))]
assume val singl_is_sorted (s : S.seq int)
: Lemma (requires S.length s < 2)
(ensures s == sort s)
type seq_view a =
| Nil
| Cons : a -> S.seq a -> seq_view a
let view #a (s : S.seq a) : seq_view a =
if S.length s = 0 then Nil else Cons (S.head s) (S.tail s)
val merge : Seq.seq int -> Seq.seq int -> Seq.seq int
let rec merge s1 s2 : Tot (S.seq int) (decreases S.length s1 + S.length s2) =
match view s1, view s2 with
| Nil, Nil -> S.empty
| Nil, Cons h t -> S.cons h t
| Cons h t, Nil -> S.cons h t
| Cons h1 t1, Cons h2 t2 ->
if h1 <= h2 then S.cons h1 (merge t1 s2) else S.cons h2 (merge s1 t2)
assume val merge_len (s1 s2 : S.seq int)
: Lemma (ensures S.length (merge s1 s2) == S.length s1 + S.length s2)
[SMTPat (merge s1 s2)]
assume val merge_sorted' (s1 s2 : S.seq int)
: Lemma (ensures merge (sort s1) (sort s2) == sort (s1 `S.append` s2))
[SMTPat (merge (sort s1) (sort s2))]
assume val merge_sorted (s1 s2 : S.seq int)
: Lemma (requires sorted s1 /\ sorted s2)
(ensures sorted (merge s1 s2))
[SMTPat (sorted (merge s1 s2))]
val append_slice #a (s : S.seq a)
(l1:nat) (l2 : nat{S.length s == l2 /\ l1 <= l2})
: Lemma (S.append (S.slice s 0 l1) (S.slice s l1 l2) == s) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "MSort.SeqLemmas.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MSort",
"short_module": null
},
{
"abbrev": false,
"full_module": "MSort",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: FStar.Seq.Base.seq a -> l1: Prims.nat -> l2: Prims.nat{FStar.Seq.Base.length s == l2 /\ l1 <= l2}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.append (FStar.Seq.Base.slice s 0 l1) (FStar.Seq.Base.slice s l1 l2) == s)
[SMTPat (FStar.Seq.Base.append (FStar.Seq.Base.slice s 0 l1) (FStar.Seq.Base.slice s l1 l2))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.length",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.append",
"FStar.Seq.Base.slice"
] | [] | true | false | true | false | false | let append_slice s l1 l2 =
| assert (S.equal (S.append (S.slice s 0 l1) (S.slice s l1 l2)) s);
() | false |
Vale.Transformers.InstructionReorderSanityChecks.fst | Vale.Transformers.InstructionReorderSanityChecks.ins_exchange_sanity_check1 | val ins_exchange_sanity_check1 : Prims.unit | let ins_exchange_sanity_check1 =
assert_norm !!(ins_exchange_sanity_check1_1);
assert_norm !!(ins_exchange_sanity_check1_2) | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.InstructionReorderSanityChecks.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 46,
"end_line": 39,
"start_col": 0,
"start_line": 37
} | module Vale.Transformers.InstructionReorderSanityChecks
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.X64.InsLemmas // this one is from [code]; is that ok?; we use it primarily for the sanity checks
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
open Vale.Transformers.BoundedInstructionEffects
friend Vale.Transformers.BoundedInstructionEffects
open Vale.Transformers.InstructionReorder
#push-options "--lax" (* XXX: This part of the file causes an F* SMTEncoding bug. I've reported it, and once it is fixed, we should remove this --lax *)
let ins_exchange_sanity_check1_1 : pbool =
normalize_term (
ins_exchange_allowed
(make_instr ins_IMul64 (OReg rRax) (OReg rRbx))
(make_instr ins_IMul64 (OReg rRcx) (OReg rRdx))
)
let ins_exchange_sanity_check1_2 : pbool =
normalize_term (
ins_exchange_allowed
(make_instr ins_Mov64 (OReg rRax) (OConst 100))
(make_instr ins_Add64 (OReg rRbx) (OConst 299))
) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.InsLemmas.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.InstructionReorder.fst.checked",
"Vale.Transformers.BoundedInstructionEffects.fst.checked",
"Vale.Transformers.BoundedInstructionEffects.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.InstructionReorderSanityChecks.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.InsLemmas // this one is from [code]; is that ok?; we use it primarily for the sanity checks",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers.InstructionReorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers.BoundedInstructionEffects",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.unit | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Vale.Def.PossiblyMonad.op_Bang_Bang",
"Vale.Transformers.InstructionReorderSanityChecks.ins_exchange_sanity_check1_2",
"Prims.unit",
"Vale.Transformers.InstructionReorderSanityChecks.ins_exchange_sanity_check1_1"
] | [] | false | false | false | true | false | let ins_exchange_sanity_check1 =
| assert_norm !!(ins_exchange_sanity_check1_1);
assert_norm !!(ins_exchange_sanity_check1_2) | false |
|
CDDL.Pulse.fst | CDDL.Pulse.impl_matches_map_entry_zero_or_more | val impl_matches_map_entry_zero_or_more : g: CDDL.Spec.map_group (FStar.Ghost.reveal b) -> Type0 | let impl_matches_map_entry_zero_or_more
(#b: Ghost.erased (option raw_data_item))
(g: map_group b)
=
c: cbor_map_entry ->
(#p: perm) ->
(#v: Ghost.erased (raw_data_item & raw_data_item)) ->
stt bool
(
raw_data_item_map_entry_match p c v **
pure (opt_precedes (Ghost.reveal v) b)
)
(fun res ->
raw_data_item_map_entry_match p c v **
pure (opt_precedes (Ghost.reveal v) b /\
res == List.Tot.existsb (pull_rel matches_map_group_entry' (Ghost.reveal v)) g.zero_or_more)
) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Pulse.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 9,
"end_line": 802,
"start_col": 0,
"start_line": 786
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module CDDL.Pulse
open Pulse.Lib.Pervasives
open Pulse.Lib.Stick
open CBOR.Spec
open CBOR.Pulse
open CDDL.Spec
module R = Pulse.Lib.Reference
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_typ
(#b: option raw_data_item)
(t: bounded_typ_gen b)
=
(c: cbor) ->
(#p: perm) ->
(#v: Ghost.erased raw_data_item) ->
stt bool
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) b
))
(fun res -> raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) b /\
res == t v
))
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_coerce_to_bounded_typ
(b: Ghost.erased (option raw_data_item))
(#t: typ)
(f: impl_typ t)
: impl_typ #b (coerce_to_bounded_typ b t) // FIXME: WHY WHY WHY do I need to provide the implicit argument
= (c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
f c;
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_t_choice
(#b: Ghost.erased (option raw_data_item))
(#t1 #t2: bounded_typ_gen b)
(f1: impl_typ t1)
(f2: impl_typ t2)
: impl_typ #b (t_choice t1 t2)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let test = f1 c;
if (test)
{
true
} else {
f2 c
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_t_choice_none // FIXME: WHY WHY WHY can F* not automatically infer t1 and t2 by reducing (reveal (hide None)) to None?
(#t1 #t2: bounded_typ_gen None)
(f1: impl_typ t1)
(f2: impl_typ t2)
: Tot (impl_typ (t_choice t1 t2))
= impl_t_choice #None #t1 #t2 f1 f2
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_any
(_: unit)
: impl_typ #None any
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
true
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint
(_: unit)
: impl_typ #None uint
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
(mt = cbor_major_type_uint64)
}
```
module U64 = FStar.UInt64
(* FIXME: WHY WHY WHY does this one not work?
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint_literal
(n: U64.t)
: impl_typ #None (t_uint_literal n)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
if (mt = major_type_uint64) {
let i = cbor_destr_int64 c;
(i.cbor_int_value = n)
} else {
false
}
}
```
*)
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint_literal'
(n: U64.t)
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
requires
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) (None #raw_data_item)
))
returns res: bool
ensures
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) (None #raw_data_item) /\
res == t_uint_literal n v
))
{
let mt = cbor_get_major_type c;
if (mt = cbor_major_type_uint64) {
let i = cbor_destr_int64 c;
(i.cbor_int_value = n)
} else {
false
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_uint_literal
(n: U64.t)
: impl_typ (t_uint_literal n)
= impl_uint_literal' n
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_bytes
(_: unit)
: impl_typ #None bytes
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
(mt = cbor_major_type_byte_string)
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_array_group3
(#b: Ghost.erased (option raw_data_item))
(g: array_group3 b)
=
(pi: R.ref cbor_array_iterator_t) ->
(#p: perm) ->
(#i: Ghost.erased cbor_array_iterator_t) ->
(#l: Ghost.erased (list raw_data_item)) ->
stt bool
(R.pts_to pi i **
cbor_array_iterator_match p i l **
pure (opt_precedes (Ghost.reveal l) b)
)
(fun res -> exists* i' l'.
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
```pulse
ghost
fn intro_impl_array_group3_post
(#b: option raw_data_item)
(g: array_group3 b)
(pi: R.ref cbor_array_iterator_t)
(p: perm)
(i: cbor_array_iterator_t)
(l: list raw_data_item)
(res: bool)
(i': cbor_array_iterator_t)
(l': list raw_data_item)
requires
(
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
ensures
(exists* i' l'.
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
{
()
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_array_group3_concat
(#b: Ghost.erased (option raw_data_item))
(#g1: array_group3 b)
(f1: impl_array_group3 g1)
(#g2: array_group3 b)
(f2: impl_array_group3 g2)
: impl_array_group3 #b (array_group3_concat g1 g2)
=
(pi: R.ref cbor_array_iterator_t)
(#p: perm)
(#gi: Ghost.erased cbor_array_iterator_t)
(#l: Ghost.erased (list raw_data_item))
{
let test1 = f1 pi;
if (test1) {
let test2 = f2 pi;
stick_trans ();
test2
} else {
false
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_array_group3_item
(#b: Ghost.erased (option raw_data_item))
(#ty: bounded_typ_gen b)
(fty: impl_typ ty)
: impl_array_group3 #b (array_group3_item ty)
=
(pi: R.ref cbor_array_iterator_t)
(#p: perm)
(#gi: Ghost.erased cbor_array_iterator_t)
(#l: Ghost.erased (list raw_data_item))
{
let i = !pi;
rewrite (cbor_array_iterator_match p gi l) as (cbor_array_iterator_match p i l);
let is_done = cbor_array_iterator_is_done i;
rewrite (cbor_array_iterator_match p i l) as (cbor_array_iterator_match p gi l);
if (is_done) {
stick_refl0 (cbor_array_iterator_match p gi l);
intro_impl_array_group3_post (array_group3_item ty) pi p gi l false gi l; // FIXME: WHY WHY WHY? and also WHY WHY WHY here and not in the other "false" case below?
false
} else {
let c = cbor_array_iterator_next pi #p #l #gi; // FIXME: WHY WHY WHY those explicit arguments?
with gc i' l' . assert (
raw_data_item_match p c gc **
cbor_array_iterator_match p i' l' **
((raw_data_item_match p c gc ** cbor_array_iterator_match p i' l') @==> cbor_array_iterator_match p gi l)
); // this is needed for the explicit arguments to split_consume_l below
let test = fty c;
if (test) {
stick_consume_l ()
#(raw_data_item_match p c gc)
#(cbor_array_iterator_match p i' l')
#(cbor_array_iterator_match p gi l) // FIXME: WHY WHY WHY those explicit arguments? (for which the with above is needed)
;
true
} else {
elim_stick0 ()
#(raw_data_item_match p c gc ** cbor_array_iterator_match p i' l')
#(cbor_array_iterator_match p gi l); // FIXME: WHY WHY WHY those explicit arguments?
pi := i;
rewrite (R.pts_to pi i) as (R.pts_to pi gi);
stick_refl0 (cbor_array_iterator_match p gi l);
false
}
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_t_array
(#b: Ghost.erased (option raw_data_item))
(#g: (array_group3 b))
(ig: (impl_array_group3 (g)))
: impl_typ #b (t_array3 g)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let ty = cbor_get_major_type c;
if (ty = cbor_major_type_array) {
let i = cbor_array_iterator_init c;
with l . assert (cbor_array_iterator_match p i l);
rewrite (cbor_array_iterator_match p i l) as (cbor_array_iterator_match p (Ghost.reveal (Ghost.hide i)) l);
let mut pi = i;
let b_success = ig pi;
with gi' l' . assert (cbor_array_iterator_match p gi' l');
let i' = ! pi;
rewrite (cbor_array_iterator_match p gi' l') as (cbor_array_iterator_match p i' l');
let b_end = cbor_array_iterator_is_done i';
rewrite (cbor_array_iterator_match p i' l') as (cbor_array_iterator_match p gi' l');
elim_stick0 ();
rewrite (cbor_array_iterator_match p (Ghost.reveal (Ghost.hide i)) l) as (cbor_array_iterator_match p i l);
elim_stick0 ();
(b_success && b_end)
} else {
false
}
}
```
module U8 = FStar.UInt8
noextract [@@noextract_to "krml"]
let cbor_read_with_typ_success_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Tot prop
=
cbor_read_success_postcond va c v rem /\
t v == true
module A = Pulse.Lib.Array
let cbor_read_with_typ_success_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
: Tot vprop
= exists* v rem.
raw_data_item_match full_perm c.cbor_read_payload v **
A.pts_to c.cbor_read_remainder #p rem **
((raw_data_item_match full_perm c.cbor_read_payload v ** A.pts_to c.cbor_read_remainder #p rem) @==>
A.pts_to a #p va) **
pure (cbor_read_with_typ_success_postcond t va c v rem)
noextract [@@noextract_to "krml"]
let cbor_read_with_typ_error_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
: Tot prop
= forall v suff .
Ghost.reveal va == serialize_cbor v `Seq.append` suff ==>
t v == false
let cbor_read_with_typ_error_postcond_intro_typ_fail
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Lemma
(requires (
cbor_read_success_postcond va c v rem /\
t v == false
))
(ensures (
cbor_read_with_typ_error_postcond t va
))
= serialize_cbor_with_test_correct v rem (fun v' rem' -> t v' == true)
let cbor_read_with_typ_error_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
: Tot vprop
= A.pts_to a #p va ** pure (cbor_read_with_typ_error_postcond t va)
let cbor_read_with_typ_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(res: cbor_read_t)
: Tot vprop
= if res.cbor_read_is_success
then cbor_read_with_typ_success_post t a p va res
else cbor_read_with_typ_error_post t a p va
module SZ = FStar.SizeT
inline_for_extraction noextract
let mk_cbor_read_error
(res: cbor_read_t)
: Tot cbor_read_t
= {res with cbor_read_is_success = false}
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn cbor_read_with_typ
(#t: typ)
(ft: impl_typ t)
(a: A.array U8.t)
(sz: SZ.t)
(#va: Ghost.erased (Seq.seq U8.t))
(#p: perm)
requires
(A.pts_to a #p va ** pure (
(SZ.v sz == Seq.length va \/ SZ.v sz == A.length a)
))
returns res: cbor_read_t
ensures cbor_read_with_typ_post t a p va res
{
let res = cbor_read a sz;
if (res.cbor_read_is_success) {
rewrite (cbor_read_post a p va res) as (cbor_read_success_post a p va res);
unfold (cbor_read_success_post a p va res);
let test = ft res.cbor_read_payload;
if (test) {
fold (cbor_read_with_typ_success_post t a p va res);
rewrite (cbor_read_with_typ_success_post t a p va res) as (cbor_read_with_typ_post t a p va res);
res
} else {
with v . assert (raw_data_item_match full_perm res.cbor_read_payload v);
with vrem . assert (A.pts_to res.cbor_read_remainder #p vrem);
cbor_read_with_typ_error_postcond_intro_typ_fail t va res v vrem;
elim_stick0 ()
#(raw_data_item_match full_perm res.cbor_read_payload v ** A.pts_to res.cbor_read_remainder #p vrem);
fold (cbor_read_with_typ_error_post t a p va);
let res = mk_cbor_read_error res;
rewrite (cbor_read_with_typ_error_post t a p va) as (cbor_read_with_typ_post t a p va res);
res
}
} else {
rewrite (cbor_read_post a p va res) as (cbor_read_error_post a p va);
unfold (cbor_read_error_post a p va);
fold (cbor_read_with_typ_error_post t a p va);
rewrite (cbor_read_with_typ_error_post t a p va) as (cbor_read_with_typ_post t a p va res);
res
}
}
```
noextract [@@noextract_to "krml"]
let cbor_read_deterministically_encoded_with_typ_success_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Tot prop
=
cbor_read_deterministically_encoded_success_postcond va c v rem /\
t v == true
noextract [@@noextract_to "krml"]
let cbor_read_deterministically_encoded_with_typ_error_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
: Tot prop
= forall v suff .
(Ghost.reveal va == serialize_cbor v `Seq.append` suff /\
data_item_wf deterministically_encoded_cbor_map_key_order v == true
) ==>
t v == false
let cbor_read_deterministically_encoded_with_typ_error_postcond_intro_typ_fail
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Lemma
(requires (
cbor_read_deterministically_encoded_success_postcond va c v rem /\
t v == false
))
(ensures (
cbor_read_deterministically_encoded_with_typ_error_postcond t va
))
= serialize_cbor_with_test_correct v rem (fun v' rem' -> data_item_wf deterministically_encoded_cbor_map_key_order v' == true /\ t v' == true)
let cbor_read_deterministically_encoded_with_typ_success_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(res: cbor_read_t)
: Tot vprop
= exists* v rem.
raw_data_item_match full_perm res.cbor_read_payload v **
A.pts_to res.cbor_read_remainder #p rem **
((raw_data_item_match full_perm res.cbor_read_payload v ** A.pts_to res.cbor_read_remainder #p rem) @==>
A.pts_to a #p va) **
pure (cbor_read_deterministically_encoded_with_typ_success_postcond t va res v rem)
let cbor_read_deterministically_encoded_with_typ_error_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
: Tot vprop
= A.pts_to a #p va ** pure (cbor_read_deterministically_encoded_with_typ_error_postcond t va)
let cbor_read_deterministically_encoded_with_typ_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(res: cbor_read_t)
: Tot vprop
= if res.cbor_read_is_success
then cbor_read_deterministically_encoded_with_typ_success_post t a p va res
else cbor_read_deterministically_encoded_with_typ_error_post t a p va
module SZ = FStar.SizeT
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn cbor_read_deterministically_encoded_with_typ
(#t: typ)
(ft: impl_typ t)
(a: A.array U8.t)
(sz: SZ.t)
(#va: Ghost.erased (Seq.seq U8.t))
(#p: perm)
requires
(A.pts_to a #p va ** pure (
(SZ.v sz == Seq.length va \/ SZ.v sz == A.length a)
))
returns res: cbor_read_t
ensures cbor_read_deterministically_encoded_with_typ_post t a p va res
{
let res = cbor_read_deterministically_encoded a sz;
if (res.cbor_read_is_success) {
rewrite (cbor_read_deterministically_encoded_post a p va res) as (cbor_read_deterministically_encoded_success_post a p va res);
unfold (cbor_read_deterministically_encoded_success_post a p va res);
let test = ft res.cbor_read_payload;
if (test) {
fold (cbor_read_deterministically_encoded_with_typ_success_post t a p va res);
fold (cbor_read_deterministically_encoded_with_typ_post t a p va res);
res
} else {
with v . assert (raw_data_item_match full_perm res.cbor_read_payload v);
with vrem . assert (A.pts_to res.cbor_read_remainder #p vrem);
cbor_read_deterministically_encoded_with_typ_error_postcond_intro_typ_fail t va res v vrem;
elim_stick0 ()
#(raw_data_item_match full_perm res.cbor_read_payload v ** A.pts_to res.cbor_read_remainder #p vrem);
let res = mk_cbor_read_error res;
fold (cbor_read_deterministically_encoded_with_typ_error_post t a p va);
fold (cbor_read_deterministically_encoded_with_typ_post t a p va res);
res
}
} else {
rewrite (cbor_read_deterministically_encoded_post a p va res) as (cbor_read_deterministically_encoded_error_post a p va);
unfold (cbor_read_deterministically_encoded_error_post a p va);
fold (cbor_read_deterministically_encoded_with_typ_error_post t a p va);
fold (cbor_read_deterministically_encoded_with_typ_post t a p va res);
res
}
}
```
noextract
let cbor_map_get_with_typ_post_found
(t: typ)
(vkey: raw_data_item)
(vmap: raw_data_item)
(vvalue: raw_data_item)
: Tot prop
= Map? vmap /\
list_ghost_assoc vkey (Map?.v vmap) == Some vvalue /\
t vvalue == true
let cbor_map_get_with_typ_post
(t: typ)
(p: perm)
(vkey: raw_data_item)
(vmap: raw_data_item)
(map: cbor)
(res: cbor_map_get_t)
: Tot vprop
= match res with
| NotFound ->
raw_data_item_match p map vmap ** pure (
Map? vmap /\
begin match list_ghost_assoc vkey (Map?.v vmap) with
| None -> True
| Some v -> t v == false
end
)
| Found value ->
exists* vvalue.
raw_data_item_match p value vvalue **
(raw_data_item_match p value vvalue @==> raw_data_item_match p map vmap) **
pure (cbor_map_get_with_typ_post_found t vkey vmap vvalue)
let cbor_map_get_post_eq_found
(p: perm)
(vkey: raw_data_item)
(vmap: raw_data_item)
(map: cbor)
(res: cbor_map_get_t)
(fres: cbor)
: Lemma
(requires (res == Found fres))
(ensures (
cbor_map_get_post p vkey vmap map res ==
cbor_map_get_post_found p vkey vmap map fres
))
= ()
```pulse
ghost
fn manurewrite
(pre post: vprop)
requires
pre ** pure (pre == post)
ensures
post
{
rewrite pre as post
}
```
```pulse
ghost
fn cbor_map_get_found_elim
(p: perm)
(vkey: Ghost.erased raw_data_item)
(vmap: Ghost.erased raw_data_item)
(map: cbor)
(res: cbor_map_get_t)
(fres: cbor)
requires
cbor_map_get_post p vkey vmap map res **
pure (res == Found fres)
ensures
cbor_map_get_post_found p vkey vmap map fres
{
manurewrite (cbor_map_get_post p vkey vmap map res) (cbor_map_get_post_found p vkey vmap map fres)
// rewrite ... as ... fails: WHY WHY WHY??
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn cbor_map_get_with_typ
(#t: typ)
(ft: impl_typ t)
(key: cbor)
(map: cbor)
(#pkey: perm)
(#vkey: Ghost.erased raw_data_item)
(#pmap: perm)
(#vmap: Ghost.erased raw_data_item)
requires
(raw_data_item_match pkey key vkey ** raw_data_item_match pmap map vmap ** pure (
Map? vmap /\
(~ (Tagged? vkey \/ Array? vkey \/ Map? vkey))
))
returns res: cbor_map_get_t
ensures
(raw_data_item_match pkey key vkey ** cbor_map_get_with_typ_post t pmap vkey vmap map res ** pure (
Map? vmap /\
Found? res == begin match list_ghost_assoc (Ghost.reveal vkey) (Map?.v vmap) with
| None -> false
| Some v -> t v
end
))
{
let res = cbor_map_get key map;
if (Found? res) {
let fres = Found?._0 res;
manurewrite (cbor_map_get_post pmap vkey vmap map res) (cbor_map_get_post_found pmap vkey vmap map fres);
unfold (cbor_map_get_post_found pmap vkey vmap map fres);
let test = ft fres;
if (test) {
fold (cbor_map_get_with_typ_post t pmap vkey vmap map (Found fres));
res
} else {
elim_stick0 ();
fold (cbor_map_get_with_typ_post t pmap vkey vmap map NotFound);
NotFound
}
} else {
rewrite (cbor_map_get_post pmap vkey vmap map res) as (cbor_map_get_post_not_found pmap vkey vmap map);
unfold (cbor_map_get_post_not_found pmap vkey vmap map);
fold (cbor_map_get_with_typ_post t pmap vkey vmap map NotFound);
res
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_matches_map_group
(#b: Ghost.erased (option raw_data_item))
(g: map_group b)
=
c: cbor ->
(#p: perm) ->
(#v: Ghost.erased raw_data_item) ->
stt bool
(
raw_data_item_match p c v **
pure (opt_precedes (Ghost.reveal v) b /\ Map? v)
)
(fun res ->
raw_data_item_match p c v **
pure (opt_precedes (Ghost.reveal v) b /\ Map? v /\ res == matches_map_group g (Map?.v v))
)
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_t_map
(#b: Ghost.erased (option raw_data_item))
(#g: map_group b)
(ig: (impl_matches_map_group (g)))
: impl_typ #b (t_map g)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let ty = cbor_get_major_type c;
if (ty = cbor_major_type_map) {
ig c;
} else {
false
}
}
``` | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Stick.fsti.checked",
"Pulse.Lib.Reference.fsti.checked",
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"CDDL.Spec.fsti.checked",
"CBOR.Spec.fsti.checked",
"CBOR.Pulse.fst.checked"
],
"interface_file": false,
"source_file": "CDDL.Pulse.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Reference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "CDDL.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Stick",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: CDDL.Spec.map_group (FStar.Ghost.reveal b) -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.map_group",
"FStar.Ghost.reveal",
"CBOR.Pulse.Type.cbor_map_entry",
"PulseCore.FractionalPermission.perm",
"FStar.Pervasives.Native.tuple2",
"Pulse.Lib.Core.stt",
"Prims.bool",
"Pulse.Lib.Core.op_Star_Star",
"CBOR.Pulse.Extern.raw_data_item_map_entry_match",
"Pulse.Lib.Core.pure",
"CDDL.Spec.opt_precedes",
"Prims.l_and",
"Prims.eq2",
"FStar.List.Tot.Base.existsb",
"CDDL.Spec.map_group_entry",
"CDDL.Spec.pull_rel",
"CDDL.Spec.matches_map_group_entry'",
"CDDL.Spec.__proj__Mkmap_group__item__zero_or_more",
"Pulse.Lib.Core.vprop"
] | [] | false | false | false | false | true | let impl_matches_map_entry_zero_or_more (#b: Ghost.erased (option raw_data_item)) (g: map_group b) =
| c: cbor_map_entry -> #p: perm -> #v: Ghost.erased (raw_data_item & raw_data_item)
-> stt bool
(raw_data_item_map_entry_match p c v ** pure (opt_precedes (Ghost.reveal v) b))
(fun res ->
raw_data_item_map_entry_match p c v **
pure (opt_precedes (Ghost.reveal v) b /\
res ==
List.Tot.existsb (pull_rel matches_map_group_entry' (Ghost.reveal v)) g.zero_or_more)) | false |
|
MSort.SeqLemmas.fst | MSort.SeqLemmas.partial_merge | val partial_merge
(s1 s2: S.seq int)
(s3: S.seq int {S.length s3 == S.length s1 + S.length s2})
(i: nat{i <= S.length s1})
(j: nat{j <= S.length s2})
: Seq.lseq int (S.length s1 + S.length s2) | val partial_merge
(s1 s2: S.seq int)
(s3: S.seq int {S.length s3 == S.length s1 + S.length s2})
(i: nat{i <= S.length s1})
(j: nat{j <= S.length s2})
: Seq.lseq int (S.length s1 + S.length s2) | let partial_merge
(s1 s2 : S.seq int)
(s3 : S.seq int {S.length s3 == S.length s1 + S.length s2})
(i:nat{i <= S.length s1}) (j : nat{j <= S.length s2})
: Seq.lseq int (S.length s1 + S.length s2) =
S.append (merge (stake i s1) (stake j s2)) (sdrop (i+j) s3) | {
"file_name": "share/steel/examples/pulse/MSort.SeqLemmas.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 61,
"end_line": 113,
"start_col": 0,
"start_line": 108
} | module MSort.SeqLemmas
open FStar.Ghost
module S = FStar.Seq
assume val sort : Seq.seq int -> Seq.seq int
assume val sorted : Seq.seq int -> bool
assume val sort_is_sorted (s:Seq.seq int) : Lemma (sorted (sort s))
assume val sort_len (s:Seq.seq int)
: Lemma (S.length (sort s) == S.length s)
[SMTPat (S.length (sort s))]
assume val singl_is_sorted (s : S.seq int)
: Lemma (requires S.length s < 2)
(ensures s == sort s)
type seq_view a =
| Nil
| Cons : a -> S.seq a -> seq_view a
let view #a (s : S.seq a) : seq_view a =
if S.length s = 0 then Nil else Cons (S.head s) (S.tail s)
val merge : Seq.seq int -> Seq.seq int -> Seq.seq int
let rec merge s1 s2 : Tot (S.seq int) (decreases S.length s1 + S.length s2) =
match view s1, view s2 with
| Nil, Nil -> S.empty
| Nil, Cons h t -> S.cons h t
| Cons h t, Nil -> S.cons h t
| Cons h1 t1, Cons h2 t2 ->
if h1 <= h2 then S.cons h1 (merge t1 s2) else S.cons h2 (merge s1 t2)
assume val merge_len (s1 s2 : S.seq int)
: Lemma (ensures S.length (merge s1 s2) == S.length s1 + S.length s2)
[SMTPat (merge s1 s2)]
assume val merge_sorted' (s1 s2 : S.seq int)
: Lemma (ensures merge (sort s1) (sort s2) == sort (s1 `S.append` s2))
[SMTPat (merge (sort s1) (sort s2))]
assume val merge_sorted (s1 s2 : S.seq int)
: Lemma (requires sorted s1 /\ sorted s2)
(ensures sorted (merge s1 s2))
[SMTPat (sorted (merge s1 s2))]
val append_slice #a (s : S.seq a)
(l1:nat) (l2 : nat{S.length s == l2 /\ l1 <= l2})
: Lemma (S.append (S.slice s 0 l1) (S.slice s l1 l2) == s)
[SMTPat (S.append (S.slice s 0 l1) (S.slice s l1 l2))]
let append_slice s l1 l2 =
assert (S.equal (S.append (S.slice s 0 l1) (S.slice s l1 l2)) s);
()
(* These two must be total or the invariant of the loop fails to typecheck.
I think the problem is that the pure assertions within the invariant are not
used to typecheck the other components of the invariant. *)
let stake #a (i:nat) (s : S.seq a)
: Tot (S.seq a)
= if i <= S.length s
then S.slice s 0 i
else s
let sdrop #a (i:nat) (s : S.seq a)
: Tot (S.seq a)
= if i <= S.length s
then S.slice s i (S.length s)
else S.empty
let take_0_lem #a (s : S.seq a)
: Lemma (stake 0 s == S.empty)
[SMTPat (stake 0 s)]
= ()
let drop_0_lem #a (s : S.seq a)
: Lemma (sdrop 0 s == s)
[SMTPat (sdrop 0 s)]
= ()
let take_len_lem #a (s : S.seq a)
: Lemma (stake (S.length s) s == s)
[SMTPat (stake (S.length s) s)]
= ()
let drop_len_lem #a (s : S.seq a)
: Lemma (sdrop (S.length s) s == S.empty)
[SMTPat (sdrop (S.length s) s)]
= ()
//
let nil_app_l #a (s : S.seq a)
: Lemma (S.append S.empty s == s)
[SMTPat (S.append S.empty s)]
= S.append_empty_l s
let nil_app_r #a (s : S.seq a)
: Lemma (S.append s S.empty == s)
[SMTPat (S.append s S.empty)]
= S.append_empty_r s
let lem_upd_spliced #a (l:nat) (s1 s2 : S.seq a) (i : nat)
: Lemma
(requires S.length s1 == l /\ S.length s2 == l /\ 0 <= i /\ i < l )
(ensures
S.upd (stake i s1 `S.append` sdrop i s2) i (S.index s1 i) ==
(stake (i+1) s1 `S.append` sdrop (i+1) s2))
= assert (S.equal (S.upd (stake i s1 `S.append` sdrop i s2) i (S.index s1 i))
(stake (i+1) s1 `S.append` sdrop (i+1) s2));
() | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "MSort.SeqLemmas.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MSort",
"short_module": null
},
{
"abbrev": false,
"full_module": "MSort",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
s1: FStar.Seq.Base.seq Prims.int ->
s2: FStar.Seq.Base.seq Prims.int ->
s3:
FStar.Seq.Base.seq Prims.int
{FStar.Seq.Base.length s3 == FStar.Seq.Base.length s1 + FStar.Seq.Base.length s2} ->
i: Prims.nat{i <= FStar.Seq.Base.length s1} ->
j: Prims.nat{j <= FStar.Seq.Base.length s2}
-> FStar.Seq.Properties.lseq Prims.int (FStar.Seq.Base.length s1 + FStar.Seq.Base.length s2) | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.seq",
"Prims.int",
"Prims.eq2",
"FStar.Seq.Base.length",
"Prims.op_Addition",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.append",
"MSort.SeqLemmas.merge",
"MSort.SeqLemmas.stake",
"MSort.SeqLemmas.sdrop",
"FStar.Seq.Properties.lseq"
] | [] | false | false | false | false | false | let partial_merge
(s1 s2: S.seq int)
(s3: S.seq int {S.length s3 == S.length s1 + S.length s2})
(i: nat{i <= S.length s1})
(j: nat{j <= S.length s2})
: Seq.lseq int (S.length s1 + S.length s2) =
| S.append (merge (stake i s1) (stake j s2)) (sdrop (i + j) s3) | false |
MSort.SeqLemmas.fst | MSort.SeqLemmas.lem_upd_spliced | val lem_upd_spliced (#a: _) (l: nat) (s1 s2: S.seq a) (i: nat)
: Lemma (requires S.length s1 == l /\ S.length s2 == l /\ 0 <= i /\ i < l)
(ensures
S.upd ((stake i s1) `S.append` (sdrop i s2)) i (S.index s1 i) ==
((stake (i + 1) s1) `S.append` (sdrop (i + 1) s2))) | val lem_upd_spliced (#a: _) (l: nat) (s1 s2: S.seq a) (i: nat)
: Lemma (requires S.length s1 == l /\ S.length s2 == l /\ 0 <= i /\ i < l)
(ensures
S.upd ((stake i s1) `S.append` (sdrop i s2)) i (S.index s1 i) ==
((stake (i + 1) s1) `S.append` (sdrop (i + 1) s2))) | let lem_upd_spliced #a (l:nat) (s1 s2 : S.seq a) (i : nat)
: Lemma
(requires S.length s1 == l /\ S.length s2 == l /\ 0 <= i /\ i < l )
(ensures
S.upd (stake i s1 `S.append` sdrop i s2) i (S.index s1 i) ==
(stake (i+1) s1 `S.append` sdrop (i+1) s2))
= assert (S.equal (S.upd (stake i s1 `S.append` sdrop i s2) i (S.index s1 i))
(stake (i+1) s1 `S.append` sdrop (i+1) s2));
() | {
"file_name": "share/steel/examples/pulse/MSort.SeqLemmas.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 6,
"end_line": 106,
"start_col": 0,
"start_line": 98
} | module MSort.SeqLemmas
open FStar.Ghost
module S = FStar.Seq
assume val sort : Seq.seq int -> Seq.seq int
assume val sorted : Seq.seq int -> bool
assume val sort_is_sorted (s:Seq.seq int) : Lemma (sorted (sort s))
assume val sort_len (s:Seq.seq int)
: Lemma (S.length (sort s) == S.length s)
[SMTPat (S.length (sort s))]
assume val singl_is_sorted (s : S.seq int)
: Lemma (requires S.length s < 2)
(ensures s == sort s)
type seq_view a =
| Nil
| Cons : a -> S.seq a -> seq_view a
let view #a (s : S.seq a) : seq_view a =
if S.length s = 0 then Nil else Cons (S.head s) (S.tail s)
val merge : Seq.seq int -> Seq.seq int -> Seq.seq int
let rec merge s1 s2 : Tot (S.seq int) (decreases S.length s1 + S.length s2) =
match view s1, view s2 with
| Nil, Nil -> S.empty
| Nil, Cons h t -> S.cons h t
| Cons h t, Nil -> S.cons h t
| Cons h1 t1, Cons h2 t2 ->
if h1 <= h2 then S.cons h1 (merge t1 s2) else S.cons h2 (merge s1 t2)
assume val merge_len (s1 s2 : S.seq int)
: Lemma (ensures S.length (merge s1 s2) == S.length s1 + S.length s2)
[SMTPat (merge s1 s2)]
assume val merge_sorted' (s1 s2 : S.seq int)
: Lemma (ensures merge (sort s1) (sort s2) == sort (s1 `S.append` s2))
[SMTPat (merge (sort s1) (sort s2))]
assume val merge_sorted (s1 s2 : S.seq int)
: Lemma (requires sorted s1 /\ sorted s2)
(ensures sorted (merge s1 s2))
[SMTPat (sorted (merge s1 s2))]
val append_slice #a (s : S.seq a)
(l1:nat) (l2 : nat{S.length s == l2 /\ l1 <= l2})
: Lemma (S.append (S.slice s 0 l1) (S.slice s l1 l2) == s)
[SMTPat (S.append (S.slice s 0 l1) (S.slice s l1 l2))]
let append_slice s l1 l2 =
assert (S.equal (S.append (S.slice s 0 l1) (S.slice s l1 l2)) s);
()
(* These two must be total or the invariant of the loop fails to typecheck.
I think the problem is that the pure assertions within the invariant are not
used to typecheck the other components of the invariant. *)
let stake #a (i:nat) (s : S.seq a)
: Tot (S.seq a)
= if i <= S.length s
then S.slice s 0 i
else s
let sdrop #a (i:nat) (s : S.seq a)
: Tot (S.seq a)
= if i <= S.length s
then S.slice s i (S.length s)
else S.empty
let take_0_lem #a (s : S.seq a)
: Lemma (stake 0 s == S.empty)
[SMTPat (stake 0 s)]
= ()
let drop_0_lem #a (s : S.seq a)
: Lemma (sdrop 0 s == s)
[SMTPat (sdrop 0 s)]
= ()
let take_len_lem #a (s : S.seq a)
: Lemma (stake (S.length s) s == s)
[SMTPat (stake (S.length s) s)]
= ()
let drop_len_lem #a (s : S.seq a)
: Lemma (sdrop (S.length s) s == S.empty)
[SMTPat (sdrop (S.length s) s)]
= ()
//
let nil_app_l #a (s : S.seq a)
: Lemma (S.append S.empty s == s)
[SMTPat (S.append S.empty s)]
= S.append_empty_l s
let nil_app_r #a (s : S.seq a)
: Lemma (S.append s S.empty == s)
[SMTPat (S.append s S.empty)]
= S.append_empty_r s | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "MSort.SeqLemmas.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MSort",
"short_module": null
},
{
"abbrev": false,
"full_module": "MSort",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | l: Prims.nat -> s1: FStar.Seq.Base.seq a -> s2: FStar.Seq.Base.seq a -> i: Prims.nat
-> FStar.Pervasives.Lemma
(requires FStar.Seq.Base.length s1 == l /\ FStar.Seq.Base.length s2 == l /\ 0 <= i /\ i < l)
(ensures
FStar.Seq.Base.upd (FStar.Seq.Base.append (MSort.SeqLemmas.stake i s1)
(MSort.SeqLemmas.sdrop i s2))
i
(FStar.Seq.Base.index s1 i) ==
FStar.Seq.Base.append (MSort.SeqLemmas.stake (i + 1) s1) (MSort.SeqLemmas.sdrop (i + 1) s2)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"FStar.Seq.Base.seq",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.upd",
"FStar.Seq.Base.append",
"MSort.SeqLemmas.stake",
"MSort.SeqLemmas.sdrop",
"FStar.Seq.Base.index",
"Prims.op_Addition",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.length",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lem_upd_spliced #a (l: nat) (s1: S.seq a) (s2: S.seq a) (i: nat)
: Lemma (requires S.length s1 == l /\ S.length s2 == l /\ 0 <= i /\ i < l)
(ensures
S.upd ((stake i s1) `S.append` (sdrop i s2)) i (S.index s1 i) ==
((stake (i + 1) s1) `S.append` (sdrop (i + 1) s2))) =
| assert (S.equal (S.upd ((stake i s1) `S.append` (sdrop i s2)) i (S.index s1 i))
((stake (i + 1) s1) `S.append` (sdrop (i + 1) s2)));
() | false |
CDDL.Pulse.fst | CDDL.Pulse.impl_matches_map_entry_zero_or_more_nil | val impl_matches_map_entry_zero_or_more_nil (b: Ghost.erased (option raw_data_item))
: Tot (impl_matches_map_entry_zero_or_more (map_group_empty #b)) | val impl_matches_map_entry_zero_or_more_nil (b: Ghost.erased (option raw_data_item))
: Tot (impl_matches_map_entry_zero_or_more (map_group_empty #b)) | let impl_matches_map_entry_zero_or_more_nil
(b: Ghost.erased (option raw_data_item))
: Tot (impl_matches_map_entry_zero_or_more (map_group_empty #b))
= impl_matches_map_entry_zero_or_more_nil' b | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Pulse.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 44,
"end_line": 849,
"start_col": 0,
"start_line": 846
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module CDDL.Pulse
open Pulse.Lib.Pervasives
open Pulse.Lib.Stick
open CBOR.Spec
open CBOR.Pulse
open CDDL.Spec
module R = Pulse.Lib.Reference
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_typ
(#b: option raw_data_item)
(t: bounded_typ_gen b)
=
(c: cbor) ->
(#p: perm) ->
(#v: Ghost.erased raw_data_item) ->
stt bool
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) b
))
(fun res -> raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) b /\
res == t v
))
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_coerce_to_bounded_typ
(b: Ghost.erased (option raw_data_item))
(#t: typ)
(f: impl_typ t)
: impl_typ #b (coerce_to_bounded_typ b t) // FIXME: WHY WHY WHY do I need to provide the implicit argument
= (c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
f c;
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_t_choice
(#b: Ghost.erased (option raw_data_item))
(#t1 #t2: bounded_typ_gen b)
(f1: impl_typ t1)
(f2: impl_typ t2)
: impl_typ #b (t_choice t1 t2)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let test = f1 c;
if (test)
{
true
} else {
f2 c
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_t_choice_none // FIXME: WHY WHY WHY can F* not automatically infer t1 and t2 by reducing (reveal (hide None)) to None?
(#t1 #t2: bounded_typ_gen None)
(f1: impl_typ t1)
(f2: impl_typ t2)
: Tot (impl_typ (t_choice t1 t2))
= impl_t_choice #None #t1 #t2 f1 f2
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_any
(_: unit)
: impl_typ #None any
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
true
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint
(_: unit)
: impl_typ #None uint
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
(mt = cbor_major_type_uint64)
}
```
module U64 = FStar.UInt64
(* FIXME: WHY WHY WHY does this one not work?
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint_literal
(n: U64.t)
: impl_typ #None (t_uint_literal n)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
if (mt = major_type_uint64) {
let i = cbor_destr_int64 c;
(i.cbor_int_value = n)
} else {
false
}
}
```
*)
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint_literal'
(n: U64.t)
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
requires
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) (None #raw_data_item)
))
returns res: bool
ensures
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) (None #raw_data_item) /\
res == t_uint_literal n v
))
{
let mt = cbor_get_major_type c;
if (mt = cbor_major_type_uint64) {
let i = cbor_destr_int64 c;
(i.cbor_int_value = n)
} else {
false
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_uint_literal
(n: U64.t)
: impl_typ (t_uint_literal n)
= impl_uint_literal' n
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_bytes
(_: unit)
: impl_typ #None bytes
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
(mt = cbor_major_type_byte_string)
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_array_group3
(#b: Ghost.erased (option raw_data_item))
(g: array_group3 b)
=
(pi: R.ref cbor_array_iterator_t) ->
(#p: perm) ->
(#i: Ghost.erased cbor_array_iterator_t) ->
(#l: Ghost.erased (list raw_data_item)) ->
stt bool
(R.pts_to pi i **
cbor_array_iterator_match p i l **
pure (opt_precedes (Ghost.reveal l) b)
)
(fun res -> exists* i' l'.
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
```pulse
ghost
fn intro_impl_array_group3_post
(#b: option raw_data_item)
(g: array_group3 b)
(pi: R.ref cbor_array_iterator_t)
(p: perm)
(i: cbor_array_iterator_t)
(l: list raw_data_item)
(res: bool)
(i': cbor_array_iterator_t)
(l': list raw_data_item)
requires
(
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
ensures
(exists* i' l'.
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
{
()
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_array_group3_concat
(#b: Ghost.erased (option raw_data_item))
(#g1: array_group3 b)
(f1: impl_array_group3 g1)
(#g2: array_group3 b)
(f2: impl_array_group3 g2)
: impl_array_group3 #b (array_group3_concat g1 g2)
=
(pi: R.ref cbor_array_iterator_t)
(#p: perm)
(#gi: Ghost.erased cbor_array_iterator_t)
(#l: Ghost.erased (list raw_data_item))
{
let test1 = f1 pi;
if (test1) {
let test2 = f2 pi;
stick_trans ();
test2
} else {
false
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_array_group3_item
(#b: Ghost.erased (option raw_data_item))
(#ty: bounded_typ_gen b)
(fty: impl_typ ty)
: impl_array_group3 #b (array_group3_item ty)
=
(pi: R.ref cbor_array_iterator_t)
(#p: perm)
(#gi: Ghost.erased cbor_array_iterator_t)
(#l: Ghost.erased (list raw_data_item))
{
let i = !pi;
rewrite (cbor_array_iterator_match p gi l) as (cbor_array_iterator_match p i l);
let is_done = cbor_array_iterator_is_done i;
rewrite (cbor_array_iterator_match p i l) as (cbor_array_iterator_match p gi l);
if (is_done) {
stick_refl0 (cbor_array_iterator_match p gi l);
intro_impl_array_group3_post (array_group3_item ty) pi p gi l false gi l; // FIXME: WHY WHY WHY? and also WHY WHY WHY here and not in the other "false" case below?
false
} else {
let c = cbor_array_iterator_next pi #p #l #gi; // FIXME: WHY WHY WHY those explicit arguments?
with gc i' l' . assert (
raw_data_item_match p c gc **
cbor_array_iterator_match p i' l' **
((raw_data_item_match p c gc ** cbor_array_iterator_match p i' l') @==> cbor_array_iterator_match p gi l)
); // this is needed for the explicit arguments to split_consume_l below
let test = fty c;
if (test) {
stick_consume_l ()
#(raw_data_item_match p c gc)
#(cbor_array_iterator_match p i' l')
#(cbor_array_iterator_match p gi l) // FIXME: WHY WHY WHY those explicit arguments? (for which the with above is needed)
;
true
} else {
elim_stick0 ()
#(raw_data_item_match p c gc ** cbor_array_iterator_match p i' l')
#(cbor_array_iterator_match p gi l); // FIXME: WHY WHY WHY those explicit arguments?
pi := i;
rewrite (R.pts_to pi i) as (R.pts_to pi gi);
stick_refl0 (cbor_array_iterator_match p gi l);
false
}
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_t_array
(#b: Ghost.erased (option raw_data_item))
(#g: (array_group3 b))
(ig: (impl_array_group3 (g)))
: impl_typ #b (t_array3 g)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let ty = cbor_get_major_type c;
if (ty = cbor_major_type_array) {
let i = cbor_array_iterator_init c;
with l . assert (cbor_array_iterator_match p i l);
rewrite (cbor_array_iterator_match p i l) as (cbor_array_iterator_match p (Ghost.reveal (Ghost.hide i)) l);
let mut pi = i;
let b_success = ig pi;
with gi' l' . assert (cbor_array_iterator_match p gi' l');
let i' = ! pi;
rewrite (cbor_array_iterator_match p gi' l') as (cbor_array_iterator_match p i' l');
let b_end = cbor_array_iterator_is_done i';
rewrite (cbor_array_iterator_match p i' l') as (cbor_array_iterator_match p gi' l');
elim_stick0 ();
rewrite (cbor_array_iterator_match p (Ghost.reveal (Ghost.hide i)) l) as (cbor_array_iterator_match p i l);
elim_stick0 ();
(b_success && b_end)
} else {
false
}
}
```
module U8 = FStar.UInt8
noextract [@@noextract_to "krml"]
let cbor_read_with_typ_success_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Tot prop
=
cbor_read_success_postcond va c v rem /\
t v == true
module A = Pulse.Lib.Array
let cbor_read_with_typ_success_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
: Tot vprop
= exists* v rem.
raw_data_item_match full_perm c.cbor_read_payload v **
A.pts_to c.cbor_read_remainder #p rem **
((raw_data_item_match full_perm c.cbor_read_payload v ** A.pts_to c.cbor_read_remainder #p rem) @==>
A.pts_to a #p va) **
pure (cbor_read_with_typ_success_postcond t va c v rem)
noextract [@@noextract_to "krml"]
let cbor_read_with_typ_error_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
: Tot prop
= forall v suff .
Ghost.reveal va == serialize_cbor v `Seq.append` suff ==>
t v == false
let cbor_read_with_typ_error_postcond_intro_typ_fail
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Lemma
(requires (
cbor_read_success_postcond va c v rem /\
t v == false
))
(ensures (
cbor_read_with_typ_error_postcond t va
))
= serialize_cbor_with_test_correct v rem (fun v' rem' -> t v' == true)
let cbor_read_with_typ_error_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
: Tot vprop
= A.pts_to a #p va ** pure (cbor_read_with_typ_error_postcond t va)
let cbor_read_with_typ_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(res: cbor_read_t)
: Tot vprop
= if res.cbor_read_is_success
then cbor_read_with_typ_success_post t a p va res
else cbor_read_with_typ_error_post t a p va
module SZ = FStar.SizeT
inline_for_extraction noextract
let mk_cbor_read_error
(res: cbor_read_t)
: Tot cbor_read_t
= {res with cbor_read_is_success = false}
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn cbor_read_with_typ
(#t: typ)
(ft: impl_typ t)
(a: A.array U8.t)
(sz: SZ.t)
(#va: Ghost.erased (Seq.seq U8.t))
(#p: perm)
requires
(A.pts_to a #p va ** pure (
(SZ.v sz == Seq.length va \/ SZ.v sz == A.length a)
))
returns res: cbor_read_t
ensures cbor_read_with_typ_post t a p va res
{
let res = cbor_read a sz;
if (res.cbor_read_is_success) {
rewrite (cbor_read_post a p va res) as (cbor_read_success_post a p va res);
unfold (cbor_read_success_post a p va res);
let test = ft res.cbor_read_payload;
if (test) {
fold (cbor_read_with_typ_success_post t a p va res);
rewrite (cbor_read_with_typ_success_post t a p va res) as (cbor_read_with_typ_post t a p va res);
res
} else {
with v . assert (raw_data_item_match full_perm res.cbor_read_payload v);
with vrem . assert (A.pts_to res.cbor_read_remainder #p vrem);
cbor_read_with_typ_error_postcond_intro_typ_fail t va res v vrem;
elim_stick0 ()
#(raw_data_item_match full_perm res.cbor_read_payload v ** A.pts_to res.cbor_read_remainder #p vrem);
fold (cbor_read_with_typ_error_post t a p va);
let res = mk_cbor_read_error res;
rewrite (cbor_read_with_typ_error_post t a p va) as (cbor_read_with_typ_post t a p va res);
res
}
} else {
rewrite (cbor_read_post a p va res) as (cbor_read_error_post a p va);
unfold (cbor_read_error_post a p va);
fold (cbor_read_with_typ_error_post t a p va);
rewrite (cbor_read_with_typ_error_post t a p va) as (cbor_read_with_typ_post t a p va res);
res
}
}
```
noextract [@@noextract_to "krml"]
let cbor_read_deterministically_encoded_with_typ_success_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Tot prop
=
cbor_read_deterministically_encoded_success_postcond va c v rem /\
t v == true
noextract [@@noextract_to "krml"]
let cbor_read_deterministically_encoded_with_typ_error_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
: Tot prop
= forall v suff .
(Ghost.reveal va == serialize_cbor v `Seq.append` suff /\
data_item_wf deterministically_encoded_cbor_map_key_order v == true
) ==>
t v == false
let cbor_read_deterministically_encoded_with_typ_error_postcond_intro_typ_fail
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Lemma
(requires (
cbor_read_deterministically_encoded_success_postcond va c v rem /\
t v == false
))
(ensures (
cbor_read_deterministically_encoded_with_typ_error_postcond t va
))
= serialize_cbor_with_test_correct v rem (fun v' rem' -> data_item_wf deterministically_encoded_cbor_map_key_order v' == true /\ t v' == true)
let cbor_read_deterministically_encoded_with_typ_success_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(res: cbor_read_t)
: Tot vprop
= exists* v rem.
raw_data_item_match full_perm res.cbor_read_payload v **
A.pts_to res.cbor_read_remainder #p rem **
((raw_data_item_match full_perm res.cbor_read_payload v ** A.pts_to res.cbor_read_remainder #p rem) @==>
A.pts_to a #p va) **
pure (cbor_read_deterministically_encoded_with_typ_success_postcond t va res v rem)
let cbor_read_deterministically_encoded_with_typ_error_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
: Tot vprop
= A.pts_to a #p va ** pure (cbor_read_deterministically_encoded_with_typ_error_postcond t va)
let cbor_read_deterministically_encoded_with_typ_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(res: cbor_read_t)
: Tot vprop
= if res.cbor_read_is_success
then cbor_read_deterministically_encoded_with_typ_success_post t a p va res
else cbor_read_deterministically_encoded_with_typ_error_post t a p va
module SZ = FStar.SizeT
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn cbor_read_deterministically_encoded_with_typ
(#t: typ)
(ft: impl_typ t)
(a: A.array U8.t)
(sz: SZ.t)
(#va: Ghost.erased (Seq.seq U8.t))
(#p: perm)
requires
(A.pts_to a #p va ** pure (
(SZ.v sz == Seq.length va \/ SZ.v sz == A.length a)
))
returns res: cbor_read_t
ensures cbor_read_deterministically_encoded_with_typ_post t a p va res
{
let res = cbor_read_deterministically_encoded a sz;
if (res.cbor_read_is_success) {
rewrite (cbor_read_deterministically_encoded_post a p va res) as (cbor_read_deterministically_encoded_success_post a p va res);
unfold (cbor_read_deterministically_encoded_success_post a p va res);
let test = ft res.cbor_read_payload;
if (test) {
fold (cbor_read_deterministically_encoded_with_typ_success_post t a p va res);
fold (cbor_read_deterministically_encoded_with_typ_post t a p va res);
res
} else {
with v . assert (raw_data_item_match full_perm res.cbor_read_payload v);
with vrem . assert (A.pts_to res.cbor_read_remainder #p vrem);
cbor_read_deterministically_encoded_with_typ_error_postcond_intro_typ_fail t va res v vrem;
elim_stick0 ()
#(raw_data_item_match full_perm res.cbor_read_payload v ** A.pts_to res.cbor_read_remainder #p vrem);
let res = mk_cbor_read_error res;
fold (cbor_read_deterministically_encoded_with_typ_error_post t a p va);
fold (cbor_read_deterministically_encoded_with_typ_post t a p va res);
res
}
} else {
rewrite (cbor_read_deterministically_encoded_post a p va res) as (cbor_read_deterministically_encoded_error_post a p va);
unfold (cbor_read_deterministically_encoded_error_post a p va);
fold (cbor_read_deterministically_encoded_with_typ_error_post t a p va);
fold (cbor_read_deterministically_encoded_with_typ_post t a p va res);
res
}
}
```
noextract
let cbor_map_get_with_typ_post_found
(t: typ)
(vkey: raw_data_item)
(vmap: raw_data_item)
(vvalue: raw_data_item)
: Tot prop
= Map? vmap /\
list_ghost_assoc vkey (Map?.v vmap) == Some vvalue /\
t vvalue == true
let cbor_map_get_with_typ_post
(t: typ)
(p: perm)
(vkey: raw_data_item)
(vmap: raw_data_item)
(map: cbor)
(res: cbor_map_get_t)
: Tot vprop
= match res with
| NotFound ->
raw_data_item_match p map vmap ** pure (
Map? vmap /\
begin match list_ghost_assoc vkey (Map?.v vmap) with
| None -> True
| Some v -> t v == false
end
)
| Found value ->
exists* vvalue.
raw_data_item_match p value vvalue **
(raw_data_item_match p value vvalue @==> raw_data_item_match p map vmap) **
pure (cbor_map_get_with_typ_post_found t vkey vmap vvalue)
let cbor_map_get_post_eq_found
(p: perm)
(vkey: raw_data_item)
(vmap: raw_data_item)
(map: cbor)
(res: cbor_map_get_t)
(fres: cbor)
: Lemma
(requires (res == Found fres))
(ensures (
cbor_map_get_post p vkey vmap map res ==
cbor_map_get_post_found p vkey vmap map fres
))
= ()
```pulse
ghost
fn manurewrite
(pre post: vprop)
requires
pre ** pure (pre == post)
ensures
post
{
rewrite pre as post
}
```
```pulse
ghost
fn cbor_map_get_found_elim
(p: perm)
(vkey: Ghost.erased raw_data_item)
(vmap: Ghost.erased raw_data_item)
(map: cbor)
(res: cbor_map_get_t)
(fres: cbor)
requires
cbor_map_get_post p vkey vmap map res **
pure (res == Found fres)
ensures
cbor_map_get_post_found p vkey vmap map fres
{
manurewrite (cbor_map_get_post p vkey vmap map res) (cbor_map_get_post_found p vkey vmap map fres)
// rewrite ... as ... fails: WHY WHY WHY??
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn cbor_map_get_with_typ
(#t: typ)
(ft: impl_typ t)
(key: cbor)
(map: cbor)
(#pkey: perm)
(#vkey: Ghost.erased raw_data_item)
(#pmap: perm)
(#vmap: Ghost.erased raw_data_item)
requires
(raw_data_item_match pkey key vkey ** raw_data_item_match pmap map vmap ** pure (
Map? vmap /\
(~ (Tagged? vkey \/ Array? vkey \/ Map? vkey))
))
returns res: cbor_map_get_t
ensures
(raw_data_item_match pkey key vkey ** cbor_map_get_with_typ_post t pmap vkey vmap map res ** pure (
Map? vmap /\
Found? res == begin match list_ghost_assoc (Ghost.reveal vkey) (Map?.v vmap) with
| None -> false
| Some v -> t v
end
))
{
let res = cbor_map_get key map;
if (Found? res) {
let fres = Found?._0 res;
manurewrite (cbor_map_get_post pmap vkey vmap map res) (cbor_map_get_post_found pmap vkey vmap map fres);
unfold (cbor_map_get_post_found pmap vkey vmap map fres);
let test = ft fres;
if (test) {
fold (cbor_map_get_with_typ_post t pmap vkey vmap map (Found fres));
res
} else {
elim_stick0 ();
fold (cbor_map_get_with_typ_post t pmap vkey vmap map NotFound);
NotFound
}
} else {
rewrite (cbor_map_get_post pmap vkey vmap map res) as (cbor_map_get_post_not_found pmap vkey vmap map);
unfold (cbor_map_get_post_not_found pmap vkey vmap map);
fold (cbor_map_get_with_typ_post t pmap vkey vmap map NotFound);
res
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_matches_map_group
(#b: Ghost.erased (option raw_data_item))
(g: map_group b)
=
c: cbor ->
(#p: perm) ->
(#v: Ghost.erased raw_data_item) ->
stt bool
(
raw_data_item_match p c v **
pure (opt_precedes (Ghost.reveal v) b /\ Map? v)
)
(fun res ->
raw_data_item_match p c v **
pure (opt_precedes (Ghost.reveal v) b /\ Map? v /\ res == matches_map_group g (Map?.v v))
)
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_t_map
(#b: Ghost.erased (option raw_data_item))
(#g: map_group b)
(ig: (impl_matches_map_group (g)))
: impl_typ #b (t_map g)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let ty = cbor_get_major_type c;
if (ty = cbor_major_type_map) {
ig c;
} else {
false
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_matches_map_entry_zero_or_more
(#b: Ghost.erased (option raw_data_item))
(g: map_group b)
=
c: cbor_map_entry ->
(#p: perm) ->
(#v: Ghost.erased (raw_data_item & raw_data_item)) ->
stt bool
(
raw_data_item_map_entry_match p c v **
pure (opt_precedes (Ghost.reveal v) b)
)
(fun res ->
raw_data_item_map_entry_match p c v **
pure (opt_precedes (Ghost.reveal v) b /\
res == List.Tot.existsb (pull_rel matches_map_group_entry' (Ghost.reveal v)) g.zero_or_more)
)
(* FIXME: WHY WHY WHY does this one not work?
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_matches_map_entry_zero_or_more_nil
(b: Ghost.erased (option raw_data_item))
: impl_matches_map_entry_zero_or_more #b map_group_empty
=
(c: cbor_map_entry)
(#p: perm)
(#v: Ghost.erased (raw_data_item & raw_data_item))
{
false
}
```
*)
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_matches_map_entry_zero_or_more_nil'
(b: Ghost.erased (option raw_data_item))
(c: cbor_map_entry)
(#p: perm)
(#v: Ghost.erased (raw_data_item & raw_data_item))
requires
(
raw_data_item_map_entry_match p c v **
pure (opt_precedes (Ghost.reveal v) b)
)
returns res: bool
ensures
(
raw_data_item_map_entry_match p c v **
pure (opt_precedes (Ghost.reveal v) b /\
res == List.Tot.existsb (pull_rel matches_map_group_entry' (Ghost.reveal v)) (map_group_empty #b).zero_or_more)
)
{
false
}
``` | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Stick.fsti.checked",
"Pulse.Lib.Reference.fsti.checked",
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"CDDL.Spec.fsti.checked",
"CBOR.Spec.fsti.checked",
"CBOR.Pulse.fst.checked"
],
"interface_file": false,
"source_file": "CDDL.Pulse.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Reference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "CDDL.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Stick",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: FStar.Ghost.erased (FStar.Pervasives.Native.option CBOR.Spec.Type.raw_data_item)
-> CDDL.Pulse.impl_matches_map_entry_zero_or_more CDDL.Spec.map_group_empty | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Pulse.impl_matches_map_entry_zero_or_more_nil'",
"CDDL.Pulse.impl_matches_map_entry_zero_or_more",
"CDDL.Spec.map_group_empty",
"FStar.Ghost.reveal"
] | [] | false | false | false | false | false | let impl_matches_map_entry_zero_or_more_nil (b: Ghost.erased (option raw_data_item))
: Tot (impl_matches_map_entry_zero_or_more (map_group_empty #b)) =
| impl_matches_map_entry_zero_or_more_nil' b | false |
MSort.SeqLemmas.fst | MSort.SeqLemmas.lemma_eq_intro_explicit | val lemma_eq_intro_explicit
(#a: Type)
(s1: S.seq a)
(s2: S.seq a {S.length s2 == S.length s1})
(pf: (i: nat{i < S.length s1} -> Lemma (S.index s1 i == S.index s2 i)))
: Lemma (S.equal s1 s2) | val lemma_eq_intro_explicit
(#a: Type)
(s1: S.seq a)
(s2: S.seq a {S.length s2 == S.length s1})
(pf: (i: nat{i < S.length s1} -> Lemma (S.index s1 i == S.index s2 i)))
: Lemma (S.equal s1 s2) | let lemma_eq_intro_explicit (#a : Type) (s1 : S.seq a) (s2 : S.seq a{S.length s2 == S.length s1})
(pf : ((i:nat{i < S.length s1}) -> Lemma (S.index s1 i == S.index s2 i)))
: Lemma (S.equal s1 s2)
= Classical.forall_intro pf;
S.lemma_eq_intro s1 s2 | {
"file_name": "share/steel/examples/pulse/MSort.SeqLemmas.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 26,
"end_line": 121,
"start_col": 0,
"start_line": 117
} | module MSort.SeqLemmas
open FStar.Ghost
module S = FStar.Seq
assume val sort : Seq.seq int -> Seq.seq int
assume val sorted : Seq.seq int -> bool
assume val sort_is_sorted (s:Seq.seq int) : Lemma (sorted (sort s))
assume val sort_len (s:Seq.seq int)
: Lemma (S.length (sort s) == S.length s)
[SMTPat (S.length (sort s))]
assume val singl_is_sorted (s : S.seq int)
: Lemma (requires S.length s < 2)
(ensures s == sort s)
type seq_view a =
| Nil
| Cons : a -> S.seq a -> seq_view a
let view #a (s : S.seq a) : seq_view a =
if S.length s = 0 then Nil else Cons (S.head s) (S.tail s)
val merge : Seq.seq int -> Seq.seq int -> Seq.seq int
let rec merge s1 s2 : Tot (S.seq int) (decreases S.length s1 + S.length s2) =
match view s1, view s2 with
| Nil, Nil -> S.empty
| Nil, Cons h t -> S.cons h t
| Cons h t, Nil -> S.cons h t
| Cons h1 t1, Cons h2 t2 ->
if h1 <= h2 then S.cons h1 (merge t1 s2) else S.cons h2 (merge s1 t2)
assume val merge_len (s1 s2 : S.seq int)
: Lemma (ensures S.length (merge s1 s2) == S.length s1 + S.length s2)
[SMTPat (merge s1 s2)]
assume val merge_sorted' (s1 s2 : S.seq int)
: Lemma (ensures merge (sort s1) (sort s2) == sort (s1 `S.append` s2))
[SMTPat (merge (sort s1) (sort s2))]
assume val merge_sorted (s1 s2 : S.seq int)
: Lemma (requires sorted s1 /\ sorted s2)
(ensures sorted (merge s1 s2))
[SMTPat (sorted (merge s1 s2))]
val append_slice #a (s : S.seq a)
(l1:nat) (l2 : nat{S.length s == l2 /\ l1 <= l2})
: Lemma (S.append (S.slice s 0 l1) (S.slice s l1 l2) == s)
[SMTPat (S.append (S.slice s 0 l1) (S.slice s l1 l2))]
let append_slice s l1 l2 =
assert (S.equal (S.append (S.slice s 0 l1) (S.slice s l1 l2)) s);
()
(* These two must be total or the invariant of the loop fails to typecheck.
I think the problem is that the pure assertions within the invariant are not
used to typecheck the other components of the invariant. *)
let stake #a (i:nat) (s : S.seq a)
: Tot (S.seq a)
= if i <= S.length s
then S.slice s 0 i
else s
let sdrop #a (i:nat) (s : S.seq a)
: Tot (S.seq a)
= if i <= S.length s
then S.slice s i (S.length s)
else S.empty
let take_0_lem #a (s : S.seq a)
: Lemma (stake 0 s == S.empty)
[SMTPat (stake 0 s)]
= ()
let drop_0_lem #a (s : S.seq a)
: Lemma (sdrop 0 s == s)
[SMTPat (sdrop 0 s)]
= ()
let take_len_lem #a (s : S.seq a)
: Lemma (stake (S.length s) s == s)
[SMTPat (stake (S.length s) s)]
= ()
let drop_len_lem #a (s : S.seq a)
: Lemma (sdrop (S.length s) s == S.empty)
[SMTPat (sdrop (S.length s) s)]
= ()
//
let nil_app_l #a (s : S.seq a)
: Lemma (S.append S.empty s == s)
[SMTPat (S.append S.empty s)]
= S.append_empty_l s
let nil_app_r #a (s : S.seq a)
: Lemma (S.append s S.empty == s)
[SMTPat (S.append s S.empty)]
= S.append_empty_r s
let lem_upd_spliced #a (l:nat) (s1 s2 : S.seq a) (i : nat)
: Lemma
(requires S.length s1 == l /\ S.length s2 == l /\ 0 <= i /\ i < l )
(ensures
S.upd (stake i s1 `S.append` sdrop i s2) i (S.index s1 i) ==
(stake (i+1) s1 `S.append` sdrop (i+1) s2))
= assert (S.equal (S.upd (stake i s1 `S.append` sdrop i s2) i (S.index s1 i))
(stake (i+1) s1 `S.append` sdrop (i+1) s2));
()
let partial_merge
(s1 s2 : S.seq int)
(s3 : S.seq int {S.length s3 == S.length s1 + S.length s2})
(i:nat{i <= S.length s1}) (j : nat{j <= S.length s2})
: Seq.lseq int (S.length s1 + S.length s2) =
S.append (merge (stake i s1) (stake j s2)) (sdrop (i+j) s3)
#set-options "--z3rlimit 20" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "MSort.SeqLemmas.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "MSort",
"short_module": null
},
{
"abbrev": false,
"full_module": "MSort",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s1: FStar.Seq.Base.seq a ->
s2: FStar.Seq.Base.seq a {FStar.Seq.Base.length s2 == FStar.Seq.Base.length s1} ->
pf:
(i: Prims.nat{i < FStar.Seq.Base.length s1}
-> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.index s1 i == FStar.Seq.Base.index s2 i)
)
-> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.equal s1 s2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Prims.eq2",
"Prims.nat",
"FStar.Seq.Base.length",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"FStar.Seq.Base.index",
"Prims.Nil",
"FStar.Pervasives.pattern",
"FStar.Seq.Base.lemma_eq_intro",
"FStar.Classical.forall_intro",
"FStar.Seq.Base.equal"
] | [] | false | false | true | false | false | let lemma_eq_intro_explicit
(#a: Type)
(s1: S.seq a)
(s2: S.seq a {S.length s2 == S.length s1})
(pf: (i: nat{i < S.length s1} -> Lemma (S.index s1 i == S.index s2 i)))
: Lemma (S.equal s1 s2) =
| Classical.forall_intro pf;
S.lemma_eq_intro s1 s2 | false |
CDDL.Pulse.fst | CDDL.Pulse.impl_str_size | val impl_str_size (ty: major_type_byte_string_or_text_string) (sz: SZ.t{SZ.fits_u64})
: impl_typ (str_size ty (SZ.v sz)) | val impl_str_size (ty: major_type_byte_string_or_text_string) (sz: SZ.t{SZ.fits_u64})
: impl_typ (str_size ty (SZ.v sz)) | let impl_str_size
(ty: major_type_byte_string_or_text_string)
(sz: SZ.t {SZ.fits_u64})
: impl_typ (str_size ty (SZ.v sz))
= impl_str_size' ty sz | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Pulse.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 22,
"end_line": 1005,
"start_col": 0,
"start_line": 1001
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module CDDL.Pulse
open Pulse.Lib.Pervasives
open Pulse.Lib.Stick
open CBOR.Spec
open CBOR.Pulse
open CDDL.Spec
module R = Pulse.Lib.Reference
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_typ
(#b: option raw_data_item)
(t: bounded_typ_gen b)
=
(c: cbor) ->
(#p: perm) ->
(#v: Ghost.erased raw_data_item) ->
stt bool
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) b
))
(fun res -> raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) b /\
res == t v
))
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_coerce_to_bounded_typ
(b: Ghost.erased (option raw_data_item))
(#t: typ)
(f: impl_typ t)
: impl_typ #b (coerce_to_bounded_typ b t) // FIXME: WHY WHY WHY do I need to provide the implicit argument
= (c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
f c;
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_t_choice
(#b: Ghost.erased (option raw_data_item))
(#t1 #t2: bounded_typ_gen b)
(f1: impl_typ t1)
(f2: impl_typ t2)
: impl_typ #b (t_choice t1 t2)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let test = f1 c;
if (test)
{
true
} else {
f2 c
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_t_choice_none // FIXME: WHY WHY WHY can F* not automatically infer t1 and t2 by reducing (reveal (hide None)) to None?
(#t1 #t2: bounded_typ_gen None)
(f1: impl_typ t1)
(f2: impl_typ t2)
: Tot (impl_typ (t_choice t1 t2))
= impl_t_choice #None #t1 #t2 f1 f2
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_any
(_: unit)
: impl_typ #None any
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
true
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint
(_: unit)
: impl_typ #None uint
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
(mt = cbor_major_type_uint64)
}
```
module U64 = FStar.UInt64
(* FIXME: WHY WHY WHY does this one not work?
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint_literal
(n: U64.t)
: impl_typ #None (t_uint_literal n)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
if (mt = major_type_uint64) {
let i = cbor_destr_int64 c;
(i.cbor_int_value = n)
} else {
false
}
}
```
*)
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint_literal'
(n: U64.t)
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
requires
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) (None #raw_data_item)
))
returns res: bool
ensures
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) (None #raw_data_item) /\
res == t_uint_literal n v
))
{
let mt = cbor_get_major_type c;
if (mt = cbor_major_type_uint64) {
let i = cbor_destr_int64 c;
(i.cbor_int_value = n)
} else {
false
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_uint_literal
(n: U64.t)
: impl_typ (t_uint_literal n)
= impl_uint_literal' n
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_bytes
(_: unit)
: impl_typ #None bytes
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
(mt = cbor_major_type_byte_string)
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_array_group3
(#b: Ghost.erased (option raw_data_item))
(g: array_group3 b)
=
(pi: R.ref cbor_array_iterator_t) ->
(#p: perm) ->
(#i: Ghost.erased cbor_array_iterator_t) ->
(#l: Ghost.erased (list raw_data_item)) ->
stt bool
(R.pts_to pi i **
cbor_array_iterator_match p i l **
pure (opt_precedes (Ghost.reveal l) b)
)
(fun res -> exists* i' l'.
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
```pulse
ghost
fn intro_impl_array_group3_post
(#b: option raw_data_item)
(g: array_group3 b)
(pi: R.ref cbor_array_iterator_t)
(p: perm)
(i: cbor_array_iterator_t)
(l: list raw_data_item)
(res: bool)
(i': cbor_array_iterator_t)
(l': list raw_data_item)
requires
(
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
ensures
(exists* i' l'.
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
{
()
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_array_group3_concat
(#b: Ghost.erased (option raw_data_item))
(#g1: array_group3 b)
(f1: impl_array_group3 g1)
(#g2: array_group3 b)
(f2: impl_array_group3 g2)
: impl_array_group3 #b (array_group3_concat g1 g2)
=
(pi: R.ref cbor_array_iterator_t)
(#p: perm)
(#gi: Ghost.erased cbor_array_iterator_t)
(#l: Ghost.erased (list raw_data_item))
{
let test1 = f1 pi;
if (test1) {
let test2 = f2 pi;
stick_trans ();
test2
} else {
false
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_array_group3_item
(#b: Ghost.erased (option raw_data_item))
(#ty: bounded_typ_gen b)
(fty: impl_typ ty)
: impl_array_group3 #b (array_group3_item ty)
=
(pi: R.ref cbor_array_iterator_t)
(#p: perm)
(#gi: Ghost.erased cbor_array_iterator_t)
(#l: Ghost.erased (list raw_data_item))
{
let i = !pi;
rewrite (cbor_array_iterator_match p gi l) as (cbor_array_iterator_match p i l);
let is_done = cbor_array_iterator_is_done i;
rewrite (cbor_array_iterator_match p i l) as (cbor_array_iterator_match p gi l);
if (is_done) {
stick_refl0 (cbor_array_iterator_match p gi l);
intro_impl_array_group3_post (array_group3_item ty) pi p gi l false gi l; // FIXME: WHY WHY WHY? and also WHY WHY WHY here and not in the other "false" case below?
false
} else {
let c = cbor_array_iterator_next pi #p #l #gi; // FIXME: WHY WHY WHY those explicit arguments?
with gc i' l' . assert (
raw_data_item_match p c gc **
cbor_array_iterator_match p i' l' **
((raw_data_item_match p c gc ** cbor_array_iterator_match p i' l') @==> cbor_array_iterator_match p gi l)
); // this is needed for the explicit arguments to split_consume_l below
let test = fty c;
if (test) {
stick_consume_l ()
#(raw_data_item_match p c gc)
#(cbor_array_iterator_match p i' l')
#(cbor_array_iterator_match p gi l) // FIXME: WHY WHY WHY those explicit arguments? (for which the with above is needed)
;
true
} else {
elim_stick0 ()
#(raw_data_item_match p c gc ** cbor_array_iterator_match p i' l')
#(cbor_array_iterator_match p gi l); // FIXME: WHY WHY WHY those explicit arguments?
pi := i;
rewrite (R.pts_to pi i) as (R.pts_to pi gi);
stick_refl0 (cbor_array_iterator_match p gi l);
false
}
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_t_array
(#b: Ghost.erased (option raw_data_item))
(#g: (array_group3 b))
(ig: (impl_array_group3 (g)))
: impl_typ #b (t_array3 g)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let ty = cbor_get_major_type c;
if (ty = cbor_major_type_array) {
let i = cbor_array_iterator_init c;
with l . assert (cbor_array_iterator_match p i l);
rewrite (cbor_array_iterator_match p i l) as (cbor_array_iterator_match p (Ghost.reveal (Ghost.hide i)) l);
let mut pi = i;
let b_success = ig pi;
with gi' l' . assert (cbor_array_iterator_match p gi' l');
let i' = ! pi;
rewrite (cbor_array_iterator_match p gi' l') as (cbor_array_iterator_match p i' l');
let b_end = cbor_array_iterator_is_done i';
rewrite (cbor_array_iterator_match p i' l') as (cbor_array_iterator_match p gi' l');
elim_stick0 ();
rewrite (cbor_array_iterator_match p (Ghost.reveal (Ghost.hide i)) l) as (cbor_array_iterator_match p i l);
elim_stick0 ();
(b_success && b_end)
} else {
false
}
}
```
module U8 = FStar.UInt8
noextract [@@noextract_to "krml"]
let cbor_read_with_typ_success_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Tot prop
=
cbor_read_success_postcond va c v rem /\
t v == true
module A = Pulse.Lib.Array
let cbor_read_with_typ_success_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
: Tot vprop
= exists* v rem.
raw_data_item_match full_perm c.cbor_read_payload v **
A.pts_to c.cbor_read_remainder #p rem **
((raw_data_item_match full_perm c.cbor_read_payload v ** A.pts_to c.cbor_read_remainder #p rem) @==>
A.pts_to a #p va) **
pure (cbor_read_with_typ_success_postcond t va c v rem)
noextract [@@noextract_to "krml"]
let cbor_read_with_typ_error_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
: Tot prop
= forall v suff .
Ghost.reveal va == serialize_cbor v `Seq.append` suff ==>
t v == false
let cbor_read_with_typ_error_postcond_intro_typ_fail
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Lemma
(requires (
cbor_read_success_postcond va c v rem /\
t v == false
))
(ensures (
cbor_read_with_typ_error_postcond t va
))
= serialize_cbor_with_test_correct v rem (fun v' rem' -> t v' == true)
let cbor_read_with_typ_error_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
: Tot vprop
= A.pts_to a #p va ** pure (cbor_read_with_typ_error_postcond t va)
let cbor_read_with_typ_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(res: cbor_read_t)
: Tot vprop
= if res.cbor_read_is_success
then cbor_read_with_typ_success_post t a p va res
else cbor_read_with_typ_error_post t a p va
module SZ = FStar.SizeT
inline_for_extraction noextract
let mk_cbor_read_error
(res: cbor_read_t)
: Tot cbor_read_t
= {res with cbor_read_is_success = false}
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn cbor_read_with_typ
(#t: typ)
(ft: impl_typ t)
(a: A.array U8.t)
(sz: SZ.t)
(#va: Ghost.erased (Seq.seq U8.t))
(#p: perm)
requires
(A.pts_to a #p va ** pure (
(SZ.v sz == Seq.length va \/ SZ.v sz == A.length a)
))
returns res: cbor_read_t
ensures cbor_read_with_typ_post t a p va res
{
let res = cbor_read a sz;
if (res.cbor_read_is_success) {
rewrite (cbor_read_post a p va res) as (cbor_read_success_post a p va res);
unfold (cbor_read_success_post a p va res);
let test = ft res.cbor_read_payload;
if (test) {
fold (cbor_read_with_typ_success_post t a p va res);
rewrite (cbor_read_with_typ_success_post t a p va res) as (cbor_read_with_typ_post t a p va res);
res
} else {
with v . assert (raw_data_item_match full_perm res.cbor_read_payload v);
with vrem . assert (A.pts_to res.cbor_read_remainder #p vrem);
cbor_read_with_typ_error_postcond_intro_typ_fail t va res v vrem;
elim_stick0 ()
#(raw_data_item_match full_perm res.cbor_read_payload v ** A.pts_to res.cbor_read_remainder #p vrem);
fold (cbor_read_with_typ_error_post t a p va);
let res = mk_cbor_read_error res;
rewrite (cbor_read_with_typ_error_post t a p va) as (cbor_read_with_typ_post t a p va res);
res
}
} else {
rewrite (cbor_read_post a p va res) as (cbor_read_error_post a p va);
unfold (cbor_read_error_post a p va);
fold (cbor_read_with_typ_error_post t a p va);
rewrite (cbor_read_with_typ_error_post t a p va) as (cbor_read_with_typ_post t a p va res);
res
}
}
```
noextract [@@noextract_to "krml"]
let cbor_read_deterministically_encoded_with_typ_success_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Tot prop
=
cbor_read_deterministically_encoded_success_postcond va c v rem /\
t v == true
noextract [@@noextract_to "krml"]
let cbor_read_deterministically_encoded_with_typ_error_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
: Tot prop
= forall v suff .
(Ghost.reveal va == serialize_cbor v `Seq.append` suff /\
data_item_wf deterministically_encoded_cbor_map_key_order v == true
) ==>
t v == false
let cbor_read_deterministically_encoded_with_typ_error_postcond_intro_typ_fail
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Lemma
(requires (
cbor_read_deterministically_encoded_success_postcond va c v rem /\
t v == false
))
(ensures (
cbor_read_deterministically_encoded_with_typ_error_postcond t va
))
= serialize_cbor_with_test_correct v rem (fun v' rem' -> data_item_wf deterministically_encoded_cbor_map_key_order v' == true /\ t v' == true)
let cbor_read_deterministically_encoded_with_typ_success_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(res: cbor_read_t)
: Tot vprop
= exists* v rem.
raw_data_item_match full_perm res.cbor_read_payload v **
A.pts_to res.cbor_read_remainder #p rem **
((raw_data_item_match full_perm res.cbor_read_payload v ** A.pts_to res.cbor_read_remainder #p rem) @==>
A.pts_to a #p va) **
pure (cbor_read_deterministically_encoded_with_typ_success_postcond t va res v rem)
let cbor_read_deterministically_encoded_with_typ_error_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
: Tot vprop
= A.pts_to a #p va ** pure (cbor_read_deterministically_encoded_with_typ_error_postcond t va)
let cbor_read_deterministically_encoded_with_typ_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(res: cbor_read_t)
: Tot vprop
= if res.cbor_read_is_success
then cbor_read_deterministically_encoded_with_typ_success_post t a p va res
else cbor_read_deterministically_encoded_with_typ_error_post t a p va
module SZ = FStar.SizeT
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn cbor_read_deterministically_encoded_with_typ
(#t: typ)
(ft: impl_typ t)
(a: A.array U8.t)
(sz: SZ.t)
(#va: Ghost.erased (Seq.seq U8.t))
(#p: perm)
requires
(A.pts_to a #p va ** pure (
(SZ.v sz == Seq.length va \/ SZ.v sz == A.length a)
))
returns res: cbor_read_t
ensures cbor_read_deterministically_encoded_with_typ_post t a p va res
{
let res = cbor_read_deterministically_encoded a sz;
if (res.cbor_read_is_success) {
rewrite (cbor_read_deterministically_encoded_post a p va res) as (cbor_read_deterministically_encoded_success_post a p va res);
unfold (cbor_read_deterministically_encoded_success_post a p va res);
let test = ft res.cbor_read_payload;
if (test) {
fold (cbor_read_deterministically_encoded_with_typ_success_post t a p va res);
fold (cbor_read_deterministically_encoded_with_typ_post t a p va res);
res
} else {
with v . assert (raw_data_item_match full_perm res.cbor_read_payload v);
with vrem . assert (A.pts_to res.cbor_read_remainder #p vrem);
cbor_read_deterministically_encoded_with_typ_error_postcond_intro_typ_fail t va res v vrem;
elim_stick0 ()
#(raw_data_item_match full_perm res.cbor_read_payload v ** A.pts_to res.cbor_read_remainder #p vrem);
let res = mk_cbor_read_error res;
fold (cbor_read_deterministically_encoded_with_typ_error_post t a p va);
fold (cbor_read_deterministically_encoded_with_typ_post t a p va res);
res
}
} else {
rewrite (cbor_read_deterministically_encoded_post a p va res) as (cbor_read_deterministically_encoded_error_post a p va);
unfold (cbor_read_deterministically_encoded_error_post a p va);
fold (cbor_read_deterministically_encoded_with_typ_error_post t a p va);
fold (cbor_read_deterministically_encoded_with_typ_post t a p va res);
res
}
}
```
noextract
let cbor_map_get_with_typ_post_found
(t: typ)
(vkey: raw_data_item)
(vmap: raw_data_item)
(vvalue: raw_data_item)
: Tot prop
= Map? vmap /\
list_ghost_assoc vkey (Map?.v vmap) == Some vvalue /\
t vvalue == true
let cbor_map_get_with_typ_post
(t: typ)
(p: perm)
(vkey: raw_data_item)
(vmap: raw_data_item)
(map: cbor)
(res: cbor_map_get_t)
: Tot vprop
= match res with
| NotFound ->
raw_data_item_match p map vmap ** pure (
Map? vmap /\
begin match list_ghost_assoc vkey (Map?.v vmap) with
| None -> True
| Some v -> t v == false
end
)
| Found value ->
exists* vvalue.
raw_data_item_match p value vvalue **
(raw_data_item_match p value vvalue @==> raw_data_item_match p map vmap) **
pure (cbor_map_get_with_typ_post_found t vkey vmap vvalue)
let cbor_map_get_post_eq_found
(p: perm)
(vkey: raw_data_item)
(vmap: raw_data_item)
(map: cbor)
(res: cbor_map_get_t)
(fres: cbor)
: Lemma
(requires (res == Found fres))
(ensures (
cbor_map_get_post p vkey vmap map res ==
cbor_map_get_post_found p vkey vmap map fres
))
= ()
```pulse
ghost
fn manurewrite
(pre post: vprop)
requires
pre ** pure (pre == post)
ensures
post
{
rewrite pre as post
}
```
```pulse
ghost
fn cbor_map_get_found_elim
(p: perm)
(vkey: Ghost.erased raw_data_item)
(vmap: Ghost.erased raw_data_item)
(map: cbor)
(res: cbor_map_get_t)
(fres: cbor)
requires
cbor_map_get_post p vkey vmap map res **
pure (res == Found fres)
ensures
cbor_map_get_post_found p vkey vmap map fres
{
manurewrite (cbor_map_get_post p vkey vmap map res) (cbor_map_get_post_found p vkey vmap map fres)
// rewrite ... as ... fails: WHY WHY WHY??
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn cbor_map_get_with_typ
(#t: typ)
(ft: impl_typ t)
(key: cbor)
(map: cbor)
(#pkey: perm)
(#vkey: Ghost.erased raw_data_item)
(#pmap: perm)
(#vmap: Ghost.erased raw_data_item)
requires
(raw_data_item_match pkey key vkey ** raw_data_item_match pmap map vmap ** pure (
Map? vmap /\
(~ (Tagged? vkey \/ Array? vkey \/ Map? vkey))
))
returns res: cbor_map_get_t
ensures
(raw_data_item_match pkey key vkey ** cbor_map_get_with_typ_post t pmap vkey vmap map res ** pure (
Map? vmap /\
Found? res == begin match list_ghost_assoc (Ghost.reveal vkey) (Map?.v vmap) with
| None -> false
| Some v -> t v
end
))
{
let res = cbor_map_get key map;
if (Found? res) {
let fres = Found?._0 res;
manurewrite (cbor_map_get_post pmap vkey vmap map res) (cbor_map_get_post_found pmap vkey vmap map fres);
unfold (cbor_map_get_post_found pmap vkey vmap map fres);
let test = ft fres;
if (test) {
fold (cbor_map_get_with_typ_post t pmap vkey vmap map (Found fres));
res
} else {
elim_stick0 ();
fold (cbor_map_get_with_typ_post t pmap vkey vmap map NotFound);
NotFound
}
} else {
rewrite (cbor_map_get_post pmap vkey vmap map res) as (cbor_map_get_post_not_found pmap vkey vmap map);
unfold (cbor_map_get_post_not_found pmap vkey vmap map);
fold (cbor_map_get_with_typ_post t pmap vkey vmap map NotFound);
res
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_matches_map_group
(#b: Ghost.erased (option raw_data_item))
(g: map_group b)
=
c: cbor ->
(#p: perm) ->
(#v: Ghost.erased raw_data_item) ->
stt bool
(
raw_data_item_match p c v **
pure (opt_precedes (Ghost.reveal v) b /\ Map? v)
)
(fun res ->
raw_data_item_match p c v **
pure (opt_precedes (Ghost.reveal v) b /\ Map? v /\ res == matches_map_group g (Map?.v v))
)
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_t_map
(#b: Ghost.erased (option raw_data_item))
(#g: map_group b)
(ig: (impl_matches_map_group (g)))
: impl_typ #b (t_map g)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let ty = cbor_get_major_type c;
if (ty = cbor_major_type_map) {
ig c;
} else {
false
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_matches_map_entry_zero_or_more
(#b: Ghost.erased (option raw_data_item))
(g: map_group b)
=
c: cbor_map_entry ->
(#p: perm) ->
(#v: Ghost.erased (raw_data_item & raw_data_item)) ->
stt bool
(
raw_data_item_map_entry_match p c v **
pure (opt_precedes (Ghost.reveal v) b)
)
(fun res ->
raw_data_item_map_entry_match p c v **
pure (opt_precedes (Ghost.reveal v) b /\
res == List.Tot.existsb (pull_rel matches_map_group_entry' (Ghost.reveal v)) g.zero_or_more)
)
(* FIXME: WHY WHY WHY does this one not work?
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_matches_map_entry_zero_or_more_nil
(b: Ghost.erased (option raw_data_item))
: impl_matches_map_entry_zero_or_more #b map_group_empty
=
(c: cbor_map_entry)
(#p: perm)
(#v: Ghost.erased (raw_data_item & raw_data_item))
{
false
}
```
*)
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_matches_map_entry_zero_or_more_nil'
(b: Ghost.erased (option raw_data_item))
(c: cbor_map_entry)
(#p: perm)
(#v: Ghost.erased (raw_data_item & raw_data_item))
requires
(
raw_data_item_map_entry_match p c v **
pure (opt_precedes (Ghost.reveal v) b)
)
returns res: bool
ensures
(
raw_data_item_map_entry_match p c v **
pure (opt_precedes (Ghost.reveal v) b /\
res == List.Tot.existsb (pull_rel matches_map_group_entry' (Ghost.reveal v)) (map_group_empty #b).zero_or_more)
)
{
false
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_matches_map_entry_zero_or_more_nil
(b: Ghost.erased (option raw_data_item))
: Tot (impl_matches_map_entry_zero_or_more (map_group_empty #b))
= impl_matches_map_entry_zero_or_more_nil' b
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_matches_map_entry_zero_or_more_cons
(#b: Ghost.erased (option raw_data_item))
(e: map_group_entry b)
(f_fst: impl_typ e.fst)
(f_snd: impl_typ e.snd)
(#g: map_group b)
(f_g: impl_matches_map_entry_zero_or_more g)
: impl_matches_map_entry_zero_or_more #b (map_group_cons_zero_or_more e false g)
=
(c: cbor_map_entry)
(#p: perm)
(#v: Ghost.erased (raw_data_item & raw_data_item))
{
assert (pure (
List.Tot.existsb (pull_rel matches_map_group_entry' (Ghost.reveal v)) (map_group_cons_zero_or_more e false g).zero_or_more == (
matches_map_group_entry e (Ghost.reveal v) ||
List.Tot.existsb (pull_rel matches_map_group_entry' (Ghost.reveal v)) g.zero_or_more
)));
unfold (raw_data_item_map_entry_match p c v);
let test_fst = f_fst (cbor_map_entry_key c);
if (test_fst) {
let test_snd = f_snd (cbor_map_entry_value c);
fold (raw_data_item_map_entry_match p c v);
if (test_snd) {
true
} else {
f_g c;
}
} else {
fold (raw_data_item_map_entry_match p c v);
f_g c;
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_matches_map_group_no_restricted
(#b: Ghost.erased (option raw_data_item))
(#g: map_group b)
(ig: (impl_matches_map_entry_zero_or_more (g)))
(h_ig: squash (
(Nil? g.one /\ Nil? g.zero_or_one)
))
: impl_matches_map_group #b g
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let i0 = cbor_map_iterator_init c;
let mut pi = i0;
let mut pres = true;
let done0 = cbor_map_iterator_is_done i0;
let mut pcont = not done0;
while (let cont = !pcont ; cont)
invariant cont . exists* (i: cbor_map_iterator_t) (l: list (raw_data_item & raw_data_item)) (res: bool) . (
pts_to pcont cont **
pts_to pres res **
pts_to pi i **
cbor_map_iterator_match p i l **
(cbor_map_iterator_match p i l @==> raw_data_item_match p c v) **
pure (
list_ghost_forall_exists matches_map_group_entry' (Map?.v v) g.zero_or_more ==
(res && list_ghost_forall_exists matches_map_group_entry' l g.zero_or_more) /\
opt_precedes l (Ghost.reveal b) /\
cont == (res && Cons? l)
)
)
{
let x = cbor_map_iterator_next pi;
stick_trans ();
let res = ig x;
with vx gi l . assert (pts_to pi gi ** raw_data_item_map_entry_match p x vx ** cbor_map_iterator_match p gi l ** ((raw_data_item_map_entry_match p x vx ** cbor_map_iterator_match p gi l) @==> raw_data_item_match p c v)) ;
stick_consume_l ()
#(raw_data_item_map_entry_match p x vx)
#(cbor_map_iterator_match p gi l);
pres := res;
if (res) {
let i = !pi;
rewrite each gi as i; // FIXME: HOW HOW HOW to do that once the issue with the use of stick_consume_l above is solved and the `with` above is removed?
let done = cbor_map_iterator_is_done i;
pcont := not done;
} else {
pcont := false;
}
};
elim_stick0 ();
!pres
}
```
(* FIXME: WHY WHY WHY does this one not work?
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_str_size
(ty: major_type_byte_string_or_text_string)
(sz: (sz: SZ.t { SZ.fits_u64 }))
: impl_typ #None (str_size ty (SZ.v sz))
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
if (mt = ty) {
let str = cbor_destr_string c;
elim_stick0 ();
(SZ.uint64_to_sizet str.cbor_string_length = sz)
} else {
false
}
}
```
*)
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_str_size'
(ty: major_type_byte_string_or_text_string)
(sz: (sz: SZ.t { SZ.fits_u64 }))
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
requires
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) (None #raw_data_item)
))
returns res: bool
ensures
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) (None #raw_data_item) /\
res == str_size ty (SZ.v sz) v
))
{
let mt = cbor_get_major_type c;
if (mt = ty) {
let str = cbor_destr_string c;
elim_stick0 ();
(SZ.uint64_to_sizet str.cbor_string_length = sz)
} else {
false
}
}
``` | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Stick.fsti.checked",
"Pulse.Lib.Reference.fsti.checked",
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"CDDL.Spec.fsti.checked",
"CBOR.Spec.fsti.checked",
"CBOR.Pulse.fst.checked"
],
"interface_file": false,
"source_file": "CDDL.Pulse.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Reference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "CDDL.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Stick",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ty: CBOR.Spec.Constants.major_type_byte_string_or_text_string ->
sz: FStar.SizeT.t{FStar.SizeT.fits_u64}
-> CDDL.Pulse.impl_typ (CDDL.Spec.str_size ty (FStar.SizeT.v sz)) | Prims.Tot | [
"total"
] | [] | [
"CBOR.Spec.Constants.major_type_byte_string_or_text_string",
"FStar.SizeT.t",
"FStar.SizeT.fits_u64",
"CDDL.Pulse.impl_str_size'",
"CDDL.Pulse.impl_typ",
"FStar.Pervasives.Native.None",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.str_size",
"FStar.SizeT.v"
] | [] | false | false | false | false | false | let impl_str_size (ty: major_type_byte_string_or_text_string) (sz: SZ.t{SZ.fits_u64})
: impl_typ (str_size ty (SZ.v sz)) =
| impl_str_size' ty sz | false |
CDDL.Pulse.fst | CDDL.Pulse.impl_typ | val impl_typ : t: CDDL.Spec.bounded_typ_gen b -> Type0 | let impl_typ
(#b: option raw_data_item)
(t: bounded_typ_gen b)
=
(c: cbor) ->
(#p: perm) ->
(#v: Ghost.erased raw_data_item) ->
stt bool
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) b
))
(fun res -> raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) b /\
res == t v
)) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Pulse.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 10,
"end_line": 41,
"start_col": 0,
"start_line": 27
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module CDDL.Pulse
open Pulse.Lib.Pervasives
open Pulse.Lib.Stick
open CBOR.Spec
open CBOR.Pulse
open CDDL.Spec
module R = Pulse.Lib.Reference | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Stick.fsti.checked",
"Pulse.Lib.Reference.fsti.checked",
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"CDDL.Spec.fsti.checked",
"CBOR.Spec.fsti.checked",
"CBOR.Pulse.fst.checked"
],
"interface_file": false,
"source_file": "CDDL.Pulse.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Lib.Reference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "CDDL.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Stick",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: CDDL.Spec.bounded_typ_gen b -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.bounded_typ_gen",
"CBOR.Pulse.Type.cbor",
"PulseCore.FractionalPermission.perm",
"FStar.Ghost.erased",
"Pulse.Lib.Core.stt",
"Prims.bool",
"Pulse.Lib.Core.op_Star_Star",
"CBOR.Pulse.Extern.raw_data_item_match",
"FStar.Ghost.reveal",
"Pulse.Lib.Core.pure",
"CDDL.Spec.opt_precedes",
"Prims.l_and",
"Prims.eq2",
"Pulse.Lib.Core.vprop"
] | [] | false | false | false | false | true | let impl_typ (#b: option raw_data_item) (t: bounded_typ_gen b) =
| c: cbor -> #p: perm -> #v: Ghost.erased raw_data_item
-> stt bool
(raw_data_item_match p c v ** pure (opt_precedes (Ghost.reveal v) b))
(fun res -> raw_data_item_match p c v ** pure (opt_precedes (Ghost.reveal v) b /\ res == t v)) | false |
|
CDDL.Pulse.fst | CDDL.Pulse.impl_array_group3 | val impl_array_group3 : g: CDDL.Spec.array_group3 (FStar.Ghost.reveal b) -> Type0 | let impl_array_group3
(#b: Ghost.erased (option raw_data_item))
(g: array_group3 b)
=
(pi: R.ref cbor_array_iterator_t) ->
(#p: perm) ->
(#i: Ghost.erased cbor_array_iterator_t) ->
(#l: Ghost.erased (list raw_data_item)) ->
stt bool
(R.pts_to pi i **
cbor_array_iterator_match p i l **
pure (opt_precedes (Ghost.reveal l) b)
)
(fun res -> exists* i' l'.
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Pulse.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 9,
"end_line": 215,
"start_col": 0,
"start_line": 193
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module CDDL.Pulse
open Pulse.Lib.Pervasives
open Pulse.Lib.Stick
open CBOR.Spec
open CBOR.Pulse
open CDDL.Spec
module R = Pulse.Lib.Reference
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_typ
(#b: option raw_data_item)
(t: bounded_typ_gen b)
=
(c: cbor) ->
(#p: perm) ->
(#v: Ghost.erased raw_data_item) ->
stt bool
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) b
))
(fun res -> raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) b /\
res == t v
))
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_coerce_to_bounded_typ
(b: Ghost.erased (option raw_data_item))
(#t: typ)
(f: impl_typ t)
: impl_typ #b (coerce_to_bounded_typ b t) // FIXME: WHY WHY WHY do I need to provide the implicit argument
= (c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
f c;
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_t_choice
(#b: Ghost.erased (option raw_data_item))
(#t1 #t2: bounded_typ_gen b)
(f1: impl_typ t1)
(f2: impl_typ t2)
: impl_typ #b (t_choice t1 t2)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let test = f1 c;
if (test)
{
true
} else {
f2 c
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_t_choice_none // FIXME: WHY WHY WHY can F* not automatically infer t1 and t2 by reducing (reveal (hide None)) to None?
(#t1 #t2: bounded_typ_gen None)
(f1: impl_typ t1)
(f2: impl_typ t2)
: Tot (impl_typ (t_choice t1 t2))
= impl_t_choice #None #t1 #t2 f1 f2
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_any
(_: unit)
: impl_typ #None any
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
true
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint
(_: unit)
: impl_typ #None uint
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
(mt = cbor_major_type_uint64)
}
```
module U64 = FStar.UInt64
(* FIXME: WHY WHY WHY does this one not work?
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint_literal
(n: U64.t)
: impl_typ #None (t_uint_literal n)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
if (mt = major_type_uint64) {
let i = cbor_destr_int64 c;
(i.cbor_int_value = n)
} else {
false
}
}
```
*)
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint_literal'
(n: U64.t)
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
requires
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) (None #raw_data_item)
))
returns res: bool
ensures
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) (None #raw_data_item) /\
res == t_uint_literal n v
))
{
let mt = cbor_get_major_type c;
if (mt = cbor_major_type_uint64) {
let i = cbor_destr_int64 c;
(i.cbor_int_value = n)
} else {
false
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_uint_literal
(n: U64.t)
: impl_typ (t_uint_literal n)
= impl_uint_literal' n
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_bytes
(_: unit)
: impl_typ #None bytes
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
(mt = cbor_major_type_byte_string)
}
``` | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Stick.fsti.checked",
"Pulse.Lib.Reference.fsti.checked",
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"CDDL.Spec.fsti.checked",
"CBOR.Spec.fsti.checked",
"CBOR.Pulse.fst.checked"
],
"interface_file": false,
"source_file": "CDDL.Pulse.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Reference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "CDDL.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Stick",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: CDDL.Spec.array_group3 (FStar.Ghost.reveal b) -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.array_group3",
"FStar.Ghost.reveal",
"Pulse.Lib.Reference.ref",
"CBOR.Pulse.Type.cbor_array_iterator_t",
"PulseCore.FractionalPermission.perm",
"Prims.list",
"Pulse.Lib.Core.stt",
"Prims.bool",
"Pulse.Lib.Core.op_Star_Star",
"Pulse.Lib.Reference.pts_to",
"PulseCore.FractionalPermission.full_perm",
"CBOR.Pulse.Extern.cbor_array_iterator_match",
"Pulse.Lib.Core.pure",
"CDDL.Spec.opt_precedes",
"Pulse.Lib.Core.op_exists_Star",
"Pulse.Lib.Stick.op_At_Equals_Equals_Greater",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.uu___is_Some",
"Prims.l_imp",
"FStar.Pervasives.Native.__proj__Some__item__v",
"Pulse.Lib.Core.vprop"
] | [] | false | false | false | false | true | let impl_array_group3 (#b: Ghost.erased (option raw_data_item)) (g: array_group3 b) =
|
pi: R.ref cbor_array_iterator_t ->
#p: perm ->
#i: Ghost.erased cbor_array_iterator_t ->
#l: Ghost.erased (list raw_data_item)
-> stt bool
((R.pts_to pi i ** cbor_array_iterator_match p i l) ** pure (opt_precedes (Ghost.reveal l) b))
(fun res ->
exists* i' l'.
((R.pts_to pi i' ** cbor_array_iterator_match p i' l') **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l)) **
pure (opt_precedes (Ghost.reveal l) b /\ res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l'))) | false |
|
Steel.ST.SeqMatch.fst | Steel.ST.SeqMatch.seq_seq_match_seq_list_match | val seq_seq_match_seq_list_match
(#opened: _)
(#t1 #t2: Type)
(p: (t1 -> t2 -> vprop))
(c: Seq.seq t1)
(l: list t2)
: STGhost unit
opened
(seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l))
(fun _ -> seq_list_match c l p)
(Seq.length c == List.Tot.length l)
(fun _ -> True)
(decreases l) | val seq_seq_match_seq_list_match
(#opened: _)
(#t1 #t2: Type)
(p: (t1 -> t2 -> vprop))
(c: Seq.seq t1)
(l: list t2)
: STGhost unit
opened
(seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l))
(fun _ -> seq_list_match c l p)
(Seq.length c == List.Tot.length l)
(fun _ -> True)
(decreases l) | let rec seq_seq_match_seq_list_match
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: list t2)
: STGhost unit opened
(seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l))
(fun _ -> seq_list_match c l p)
(Seq.length c == List.Tot.length l)
(fun _ -> True)
(decreases l)
= match l with
| [] ->
drop (seq_seq_match p _ _ _ _);
rewrite
(seq_list_match_nil0 c)
(seq_list_match c l p)
| a :: q ->
Seq.lemma_seq_of_list_induction (a :: q);
seq_list_match_cons_eq c l p;
on_range_uncons
(seq_seq_match_item p _ _)
_ 1 _;
rewrite
(seq_seq_match_item p _ _ _)
(p (Seq.head c) (List.Tot.hd l));
let _ = seq_seq_match_tail_intro
p _ _ 1 _ _
in
rewrite
(seq_seq_match p _ _ _ _)
(seq_seq_match p (Seq.tail c) (Seq.seq_of_list (List.Tot.tl l)) 0 (List.Tot.length (List.Tot.tl l)));
seq_seq_match_seq_list_match p _ (List.Tot.tl l);
rewrite
(seq_list_match_cons0 c l p seq_list_match)
(seq_list_match c l p) | {
"file_name": "lib/steel/Steel.ST.SeqMatch.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 28,
"end_line": 447,
"start_col": 0,
"start_line": 411
} | module Steel.ST.SeqMatch
include Steel.ST.OnRange
open Steel.ST.GenElim
module Seq = FStar.Seq
module SZ = FStar.SizeT
(* `seq_list_match` describes how to match a sequence of low-level
values (the low-level contents of an array) with a list of high-level
values. `seq_list_match` is carefully designed to be usable within
(mutually) recursive definitions of matching functions on the type of
high-level values. *)
[@@__reduce__]
let seq_list_match_nil0
(#t: Type)
(c: Seq.seq t)
: Tot vprop
= pure (c `Seq.equal` Seq.empty)
[@@__reduce__]
let seq_list_match_cons0
(#t #t': Type)
(c: Seq.seq t)
(l: list t' { Cons? l })
(item_match: (t -> (v': t' { v' << l }) -> vprop))
(seq_list_match: (Seq.seq t -> (v': list t') -> (raw_data_item_match: (t -> (v'': t' { v'' << v' }) -> vprop) { v' << l }) ->
vprop))
: Tot vprop
= exists_ (fun (c1: t) -> exists_ (fun (c2: Seq.seq t) ->
item_match c1 (List.Tot.hd l) `star`
seq_list_match c2 (List.Tot.tl l) item_match `star`
pure (c `Seq.equal` Seq.cons c1 c2)
))
let rec seq_list_match
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match: (t -> (v': t' { v' << v }) -> vprop))
: Tot vprop
(decreases v)
= if Nil? v
then seq_list_match_nil0 c
else seq_list_match_cons0 c v item_match seq_list_match
let seq_list_match_cons_eq
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match: (t -> (v': t' { v' << v }) -> vprop))
: Lemma
(requires (Cons? v))
(ensures (
seq_list_match c v item_match ==
seq_list_match_cons0 c v item_match seq_list_match
))
= let a :: q = v in
assert_norm (seq_list_match c (a :: q) item_match ==
seq_list_match_cons0 c (a :: q) item_match seq_list_match
)
let seq_list_match_nil
(#opened: _)
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match: (t -> (v': t' { v' << v }) -> vprop))
: STGhost unit opened
emp
(fun _ -> seq_list_match c v item_match)
(c `Seq.equal` Seq.empty /\
Nil? v)
(fun _ -> True)
= noop ();
rewrite
(seq_list_match_nil0 c)
(seq_list_match c v item_match)
let list_cons_precedes
(#t: Type)
(a: t)
(q: list t)
: Lemma
((a << a :: q) /\ (q << a :: q))
[SMTPat (a :: q)]
= assert (List.Tot.hd (a :: q) << (a :: q));
assert (List.Tot.tl (a :: q) << (a :: q))
let seq_list_match_cons_intro
(#opened: _)
(#t #t': Type)
(a: t)
(a' : t')
(c: Seq.seq t)
(v: list t')
(item_match: (t -> (v': t' { v' << a' :: v }) -> vprop))
: STGhostT unit opened
(item_match a a' `star` seq_list_match c v item_match)
(fun _ -> seq_list_match (Seq.cons a c) (a' :: v) item_match)
= seq_list_match_cons_eq (Seq.cons a c) (a' :: v) item_match;
noop ();
rewrite
(seq_list_match_cons0 (Seq.cons a c) (a' :: v) item_match seq_list_match)
(seq_list_match (Seq.cons a c) (a' :: v) item_match)
let seq_list_match_cons_elim
(#opened: _)
(#t #t': Type)
(c: Seq.seq t)
(v: list t' { Cons? v \/ Seq.length c > 0 })
(item_match: (t -> (v': t' { v' << v }) -> vprop))
: STGhostT (squash (Cons? v /\ Seq.length c > 0)) opened
(seq_list_match c v item_match)
(fun _ -> item_match (Seq.head c) (List.Tot.hd v) `star`
seq_list_match (Seq.tail c) (List.Tot.tl v) item_match)
= if Nil? v
then begin
rewrite
(seq_list_match c v item_match)
(seq_list_match_nil0 c);
let _ = gen_elim () in
assert False;
rewrite // by contradiction
emp
(item_match (Seq.head c) (List.Tot.hd v) `star`
seq_list_match (Seq.tail c) (List.Tot.tl v) item_match)
end else begin
seq_list_match_cons_eq c v item_match;
noop ();
rewrite
(seq_list_match c v item_match)
(seq_list_match_cons0 c v item_match seq_list_match);
let _ = gen_elim () in
let prf : squash (Cons? v /\ Seq.length c > 0) = () in
let c1 = vpattern (fun c1 -> item_match c1 (List.Tot.hd v)) in
let c2 = vpattern (fun c2 -> seq_list_match c2 (List.Tot.tl v) item_match) in
Seq.lemma_cons_inj c1 (Seq.head c) c2 (Seq.tail c);
vpattern_rewrite (fun c1 -> item_match c1 (List.Tot.hd v)) (Seq.head c);
vpattern_rewrite (fun c2 -> seq_list_match c2 (List.Tot.tl v) item_match) (Seq.tail c);
prf
end
// this one cannot be proven with seq_seq_match because of the << refinement in the type of item_match
let rec seq_list_match_weaken
(#opened: _)
(#t #t': Type)
(c: Seq.seq t)
(v: list t')
(item_match1 item_match2: (t -> (v': t' { v' << v }) -> vprop))
(prf: (
(#opened: _) ->
(c': t) ->
(v': t' { v' << v }) ->
STGhostT unit opened
(item_match1 c' v')
(fun _ -> item_match2 c' v')
))
: STGhostT unit opened
(seq_list_match c v item_match1)
(fun _ -> seq_list_match c v item_match2)
(decreases v)
= if Nil? v
then
rewrite (seq_list_match c v item_match1) (seq_list_match c v item_match2)
else begin
let _ : squash (Cons? v) = () in
seq_list_match_cons_eq c v item_match1;
seq_list_match_cons_eq c v item_match2;
rewrite
(seq_list_match c v item_match1)
(seq_list_match_cons0 c v item_match1 seq_list_match);
let _ = gen_elim () in
prf _ _;
seq_list_match_weaken _ (List.Tot.tl v) item_match1 item_match2 prf;
rewrite
(seq_list_match_cons0 c v item_match2 seq_list_match)
(seq_list_match c v item_match2)
end
(* `seq_seq_match` describes how to match a sequence of low-level
values (the low-level contents of an array) with a sequence of high-level
values. Contrary to `seq_list_match`, `seq_seq_match` is not meant to be usable within
(mutually) recursive definitions of matching functions on the type of
high-level values, because no lemma ensures that `Seq.index s i << s` *)
let seq_seq_match_item
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: Seq.seq t2)
(i: nat)
: Tot vprop
= if i < Seq.length c && i < Seq.length l
then
p (Seq.index c i) (Seq.index l i)
else
pure (squash False)
let seq_seq_match_item_tail
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: Seq.seq t2)
(delta: nat)
(i: nat)
: Lemma
(requires (
i + delta <= Seq.length c /\
i + delta <= Seq.length l
))
(ensures (
seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) i ==
seq_seq_match_item p c l (i + delta)
))
= ()
[@@__reduce__]
let seq_seq_match
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: Seq.seq t2)
(i j: nat)
: Tot vprop
= on_range (seq_seq_match_item p c l) i j
let seq_seq_match_length
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(s1: Seq.seq t1)
(s2: Seq.seq t2)
(i j: nat)
: STGhost unit opened
(seq_seq_match p s1 s2 i j)
(fun _ -> seq_seq_match p s1 s2 i j)
True
(fun _ -> i <= j /\ (i == j \/ (j <= Seq.length s1 /\ j <= Seq.length s2)))
= on_range_le (seq_seq_match_item p s1 s2) i j;
if i = j
then noop ()
else begin
let j' = j - 1 in
if j' < Seq.length s1 && j' < Seq.length s2
then noop ()
else begin
on_range_unsnoc
(seq_seq_match_item p s1 s2)
i j' j;
rewrite
(seq_seq_match_item p _ _ _)
(pure (squash False));
let _ = gen_elim () in
rewrite
(seq_seq_match p s1 s2 i j')
(seq_seq_match p s1 s2 i j) // by contradiction
end
end
let seq_seq_match_weaken
(#opened: _)
(#t1 #t2: Type)
(p p': t1 -> t2 -> vprop)
(w: ((x1: t1) -> (x2: t2) -> STGhostT unit opened
(p x1 x2) (fun _ -> p' x1 x2)
))
(c1 c1': Seq.seq t1)
(c2 c2': Seq.seq t2)
(i j: nat)
: STGhost unit opened
(seq_seq_match p c1 c2 i j)
(fun _ -> seq_seq_match p' c1' c2' i j)
(i <= j /\ (i == j \/ (
j <= Seq.length c1 /\ j <= Seq.length c2 /\
j <= Seq.length c1' /\ j <= Seq.length c2' /\
Seq.slice c1 i j `Seq.equal` Seq.slice c1' i j /\
Seq.slice c2 i j `Seq.equal` Seq.slice c2' i j
)))
(fun _ -> True)
=
on_range_weaken
(seq_seq_match_item p c1 c2)
(seq_seq_match_item p' c1' c2')
i j
(fun k ->
rewrite (seq_seq_match_item p c1 c2 k) (p (Seq.index (Seq.slice c1 i j) (k - i)) (Seq.index (Seq.slice c2 i j) (k - i)));
w _ _;
rewrite (p' _ _) (seq_seq_match_item p' c1' c2' k)
)
let seq_seq_match_weaken_with_implies
(#opened: _)
(#t1 #t2: Type)
(p: t1 -> t2 -> vprop)
(c1 c1': Seq.seq t1)
(c2 c2': Seq.seq t2)
(i j: nat)
: STGhost unit opened
(seq_seq_match p c1 c2 i j)
(fun _ -> seq_seq_match p c1' c2' i j `star`
(seq_seq_match p c1' c2' i j `implies_` seq_seq_match p c1 c2 i j)
)
(i <= j /\ (i == j \/ (
j <= Seq.length c1 /\ j <= Seq.length c2 /\
j <= Seq.length c1' /\ j <= Seq.length c2' /\
Seq.slice c1 i j `Seq.equal` Seq.slice c1' i j /\
Seq.slice c2 i j `Seq.equal` Seq.slice c2' i j
)))
(fun _ -> True)
= seq_seq_match_weaken
p p (fun _ _ -> noop ())
c1 c1'
c2 c2'
i j;
intro_implies
(seq_seq_match p c1' c2' i j)
(seq_seq_match p c1 c2 i j)
emp
(fun _ ->
seq_seq_match_weaken
p p (fun _ _ -> noop ())
c1' c1
c2' c2
i j
)
(* Going between `seq_list_match` and `seq_seq_match` *)
let seq_seq_match_tail_elim
(#t1 #t2: Type)
(#opened: _)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: Seq.seq (t2))
(delta: nat {
delta <= Seq.length c /\
delta <= Seq.length l
})
(i j: nat)
: STGhostT unit opened
(seq_seq_match p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) i j)
(fun _ -> seq_seq_match p c l (i + delta) (j + delta))
= on_range_le (seq_seq_match_item p _ _) _ _;
on_range_weaken_and_shift
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)))
(seq_seq_match_item p c l)
delta
i j
(fun k ->
if k < Seq.length c - delta && k < Seq.length l - delta
then begin
seq_seq_match_item_tail p c l delta k;
rewrite
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) k)
(seq_seq_match_item p c l (k + delta))
end else begin
rewrite
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) k)
(pure (squash False));
let _ = gen_elim () in
rewrite
emp
(seq_seq_match_item p c l (k + delta)) // by contradiction
end
)
(i + delta) (j + delta)
let seq_seq_match_tail_intro
(#t1 #t2: Type)
(#opened: _)
(p: t1 -> t2 -> vprop)
(c: Seq.seq t1)
(l: Seq.seq t2)
(delta: nat {
delta <= Seq.length c /\
delta <= Seq.length l
})
(i: nat {
delta <= i
})
(j: nat)
: STGhostT (squash (i <= j)) opened
(seq_seq_match p c l i j)
(fun _ -> seq_seq_match p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) (i - delta) (j - delta))
= on_range_le (seq_seq_match_item p _ _) _ _;
on_range_weaken_and_shift
(seq_seq_match_item p c l)
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)))
(0 - delta)
i j
(fun k ->
if k < Seq.length c && k < Seq.length l
then begin
seq_seq_match_item_tail p c l delta (k - delta);
rewrite
(seq_seq_match_item p c l k)
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) (k + (0 - delta)))
end else begin
rewrite
(seq_seq_match_item p c l k)
(pure (squash False));
let _ = gen_elim () in
rewrite
emp
(seq_seq_match_item p (Seq.slice c delta (Seq.length c)) (Seq.slice l delta (Seq.length l)) (k + (0 - delta))) // by contradiction
end
)
(i - delta) (j - delta) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.OnRange.fsti.checked",
"Steel.ST.GenElim.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Steel.ST.SeqMatch.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.OnRange",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: (_: t1 -> _: t2 -> Steel.Effect.Common.vprop) -> c: FStar.Seq.Base.seq t1 -> l: Prims.list t2
-> Steel.ST.Effect.Ghost.STGhost Prims.unit | Steel.ST.Effect.Ghost.STGhost | [
""
] | [] | [
"Steel.Memory.inames",
"Steel.Effect.Common.vprop",
"FStar.Seq.Base.seq",
"Prims.list",
"Steel.ST.Util.rewrite",
"Steel.ST.SeqMatch.seq_list_match_nil0",
"Steel.ST.SeqMatch.seq_list_match",
"Prims.unit",
"Steel.ST.Util.drop",
"Steel.ST.SeqMatch.seq_seq_match",
"FStar.Seq.Base.seq_of_list",
"FStar.List.Tot.Base.length",
"Steel.ST.SeqMatch.seq_list_match_cons0",
"Steel.ST.SeqMatch.seq_seq_match_seq_list_match",
"FStar.Seq.Properties.tail",
"FStar.List.Tot.Base.tl",
"FStar.Seq.Base.slice",
"FStar.Seq.Base.length",
"Prims.op_Subtraction",
"Prims.squash",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Steel.ST.SeqMatch.seq_seq_match_tail_intro",
"Steel.ST.SeqMatch.seq_seq_match_item",
"FStar.Seq.Properties.head",
"FStar.List.Tot.Base.hd",
"Steel.ST.OnRange.on_range_uncons",
"Steel.ST.SeqMatch.seq_list_match_cons_eq",
"FStar.Seq.Properties.lemma_seq_of_list_induction",
"Prims.Cons",
"Prims.eq2",
"Prims.nat",
"Prims.l_True"
] | [
"recursion"
] | false | true | false | false | false | let rec seq_seq_match_seq_list_match
(#opened: _)
(#t1 #t2: Type)
(p: (t1 -> t2 -> vprop))
(c: Seq.seq t1)
(l: list t2)
: STGhost unit
opened
(seq_seq_match p c (Seq.seq_of_list l) 0 (List.Tot.length l))
(fun _ -> seq_list_match c l p)
(Seq.length c == List.Tot.length l)
(fun _ -> True)
(decreases l) =
| match l with
| [] ->
drop (seq_seq_match p _ _ _ _);
rewrite (seq_list_match_nil0 c) (seq_list_match c l p)
| a :: q ->
Seq.lemma_seq_of_list_induction (a :: q);
seq_list_match_cons_eq c l p;
on_range_uncons (seq_seq_match_item p _ _) _ 1 _;
rewrite (seq_seq_match_item p _ _ _) (p (Seq.head c) (List.Tot.hd l));
let _ = seq_seq_match_tail_intro p _ _ 1 _ _ in
rewrite (seq_seq_match p _ _ _ _)
(seq_seq_match p
(Seq.tail c)
(Seq.seq_of_list (List.Tot.tl l))
0
(List.Tot.length (List.Tot.tl l)));
seq_seq_match_seq_list_match p _ (List.Tot.tl l);
rewrite (seq_list_match_cons0 c l p seq_list_match) (seq_list_match c l p) | false |
Vale.AES.GCM_BE.fst | Vale.AES.GCM_BE.upper3_equal | val upper3_equal (q0 q1: quad32) : bool | val upper3_equal (q0 q1: quad32) : bool | let upper3_equal (q0 q1:quad32) : bool =
q0.lo1 = q1.lo1 &&
q0.hi2 = q1.hi2 &&
q0.hi3 = q1.hi3 | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_BE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 17,
"end_line": 21,
"start_col": 0,
"start_line": 18
} | module Vale.AES.GCM_BE
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.AES.GCM_BE_s
open Vale.AES.AES_BE_s
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.AES.GHash_BE_s
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open FStar.Calc | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.GHash_BE_s.fst.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.GCM_BE_s.fst.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_BE.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | q0: Vale.Def.Types_s.quad32 -> q1: Vale.Def.Types_s.quad32 -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Vale.Def.Types_s.quad32",
"Prims.op_AmpAmp",
"Prims.op_Equality",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3",
"Prims.bool"
] | [] | false | false | false | true | false | let upper3_equal (q0 q1: quad32) : bool =
| q0.lo1 = q1.lo1 && q0.hi2 = q1.hi2 && q0.hi3 = q1.hi3 | false |
Steel.ST.HigherReference.fst | Steel.ST.HigherReference.with_named_local | val with_named_local
(#t: Type)
(init: t)
(#pre: vprop)
(#ret_t: Type)
(#post: ret_t -> vprop)
(name: string)
(body: (r: ref t) ->
STT ret_t
(pts_to r full_perm init `star` pre)
(fun v -> exists_ (pts_to r full_perm) `star` post v)
)
: STF ret_t pre post True (fun _ -> True) | val with_named_local
(#t: Type)
(init: t)
(#pre: vprop)
(#ret_t: Type)
(#post: ret_t -> vprop)
(name: string)
(body: (r: ref t) ->
STT ret_t
(pts_to r full_perm init `star` pre)
(fun v -> exists_ (pts_to r full_perm) `star` post v)
)
: STF ret_t pre post True (fun _ -> True) | let with_named_local
(#t: Type)
(init: t)
(#pre: vprop)
(#ret_t: Type)
(#post: ret_t -> vprop)
(name: string)
(body: (r: ref t) ->
STT ret_t
(pts_to r full_perm init `star` pre)
(fun v -> exists_ (pts_to r full_perm) `star` post v)
)
: STF ret_t pre post True (fun _ -> True)
= _push_frame ();
[@(rename_let name)]
let r = _alloca init in
let v = body r in
let _ = elim_exists () in
_free_and_pop_frame r;
return v | {
"file_name": "lib/steel/Steel.ST.HigherReference.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 10,
"end_line": 166,
"start_col": 0,
"start_line": 147
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.HigherReference
open FStar.Ghost
open Steel.ST.Util
open Steel.ST.Coercions
module R = Steel.HigherReference
let ref (a:Type u#1)
: Type0
= R.ref a
let null (#a:Type)
: ref a
= R.null #a
let is_null (#a:Type) (r:ref a)
: b:bool{b <==> r == null}
= R.is_null r
let pts_to (#a:Type)
(r:ref a)
([@@@smt_fallback] p:perm)
([@@@smt_fallback] v:a)
: vprop
= R.pts_to r p v
let pts_to_injective_eq
(#a: Type)
(#opened:inames)
(#p0 #p1:perm)
(#v0 #v1:a)
(r: ref a)
: STGhost unit opened
(pts_to r p0 v0 `star` pts_to r p1 v1)
(fun _ -> pts_to r p0 v0 `star` pts_to r p1 v0)
(requires True)
(ensures fun _ -> v0 == v1)
= coerce_ghost
(fun _ -> R.higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #(hide v0) #(hide v1) r)
let pts_to_not_null #a #opened #p #v r
= extract_fact #opened (pts_to r p v) (r =!= null) (R.pts_to_not_null r p v);
()
let alloc (#a:Type) (x:a)
: ST (ref a)
emp
(fun r -> pts_to r full_perm x)
(requires True)
(ensures fun r -> not (is_null r))
= let r = coerce_steel (fun _ -> R.alloc x) in
r
let read (#a:Type)
(#p:perm)
(#v:erased a)
(r:ref a)
: ST a
(pts_to r p v)
(fun _ -> pts_to r p v)
(requires True)
(ensures fun x -> x == Ghost.reveal v)
= let u = coerce_steel (fun _ -> R.read r) in
return u
let write (#a:Type)
(#v:erased a)
(r:ref a)
(x:a)
: STT unit
(pts_to r full_perm v)
(fun _ -> pts_to r full_perm x)
= coerce_steel (fun _ -> R.write r x);
return ()
let free (#a:Type)
(#v:erased a)
(r:ref a)
: STT unit
(pts_to r full_perm v)
(fun _ -> emp)
= coerce_steel(fun _ -> R.free r);
return ()
/// Local primitive, to be extracted to Low* EPushFrame. To remember
/// that we need to call some pop_frame later, we insert some dummy
/// vprop into the context.
let _stack_frame : vprop = pure True
let _push_frame () : STT unit emp (fun _ -> _stack_frame) =
rewrite (pure True) _stack_frame
/// Local primitive, to be extracted to Low* EBufCreate
let _alloca (#a:Type) (x:a)
: ST (ref a)
emp
(fun r -> pts_to r full_perm x)
(requires True)
(ensures fun r -> not (is_null r))
= alloc x
/// Local primitive, to be extracted to Low* EPopFrame
let _free_and_pop_frame
(#a:Type)
(#v:erased a)
(r:ref a)
: STT unit
(pts_to r full_perm v `star` _stack_frame)
(fun _ -> emp)
= free r;
rewrite _stack_frame (pure True);
elim_pure _
let with_local
(#t: Type)
(init: t)
(#pre: vprop)
(#ret_t: Type)
(#post: ret_t -> vprop)
(body: (r: ref t) ->
STT ret_t
(pts_to r full_perm init `star` pre)
(fun v -> exists_ (pts_to r full_perm) `star` post v)
)
: STF ret_t pre post True (fun _ -> True)
= _push_frame ();
let r = _alloca init in
let v = body r in
let _ = elim_exists () in
_free_and_pop_frame r;
return v | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Coercions.fsti.checked",
"Steel.HigherReference.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.HigherReference.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Steel.ST.Coercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
init: t ->
name: Prims.string ->
body: (r: Steel.ST.HigherReference.ref t -> Steel.ST.Effect.STT ret_t)
-> Steel.ST.Effect.STF ret_t | Steel.ST.Effect.STF | [] | [] | [
"Steel.Effect.Common.vprop",
"Prims.string",
"Steel.ST.HigherReference.ref",
"Steel.Effect.Common.star",
"Steel.ST.HigherReference.pts_to",
"Steel.FractionalPermission.full_perm",
"Steel.ST.Util.exists_",
"Steel.ST.Util.return",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Prims.unit",
"Steel.ST.HigherReference._free_and_pop_frame",
"FStar.Ghost.erased",
"Steel.ST.Util.elim_exists",
"Steel.ST.HigherReference._alloca",
"Steel.ST.HigherReference._push_frame",
"Prims.l_True"
] | [] | false | true | false | false | false | let with_named_local
(#t: Type)
(init: t)
(#pre: vprop)
(#ret_t: Type)
(#post: (ret_t -> vprop))
(name: string)
(body:
(r: ref t
-> STT ret_t
((pts_to r full_perm init) `star` pre)
(fun v -> (exists_ (pts_to r full_perm)) `star` (post v))))
: STF ret_t pre post True (fun _ -> True) =
| _push_frame ();
[@@ (rename_let name) ]let r = _alloca init in
let v = body r in
let _ = elim_exists () in
_free_and_pop_frame r;
return v | false |
CDDL.Pulse.fst | CDDL.Pulse.cbor_read_with_typ_success_postcond | val cbor_read_with_typ_success_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Tot prop | val cbor_read_with_typ_success_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Tot prop | let cbor_read_with_typ_success_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Tot prop
=
cbor_read_success_postcond va c v rem /\
t v == true | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Pulse.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 15,
"end_line": 378,
"start_col": 0,
"start_line": 369
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module CDDL.Pulse
open Pulse.Lib.Pervasives
open Pulse.Lib.Stick
open CBOR.Spec
open CBOR.Pulse
open CDDL.Spec
module R = Pulse.Lib.Reference
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_typ
(#b: option raw_data_item)
(t: bounded_typ_gen b)
=
(c: cbor) ->
(#p: perm) ->
(#v: Ghost.erased raw_data_item) ->
stt bool
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) b
))
(fun res -> raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) b /\
res == t v
))
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_coerce_to_bounded_typ
(b: Ghost.erased (option raw_data_item))
(#t: typ)
(f: impl_typ t)
: impl_typ #b (coerce_to_bounded_typ b t) // FIXME: WHY WHY WHY do I need to provide the implicit argument
= (c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
f c;
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_t_choice
(#b: Ghost.erased (option raw_data_item))
(#t1 #t2: bounded_typ_gen b)
(f1: impl_typ t1)
(f2: impl_typ t2)
: impl_typ #b (t_choice t1 t2)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let test = f1 c;
if (test)
{
true
} else {
f2 c
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_t_choice_none // FIXME: WHY WHY WHY can F* not automatically infer t1 and t2 by reducing (reveal (hide None)) to None?
(#t1 #t2: bounded_typ_gen None)
(f1: impl_typ t1)
(f2: impl_typ t2)
: Tot (impl_typ (t_choice t1 t2))
= impl_t_choice #None #t1 #t2 f1 f2
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_any
(_: unit)
: impl_typ #None any
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
true
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint
(_: unit)
: impl_typ #None uint
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
(mt = cbor_major_type_uint64)
}
```
module U64 = FStar.UInt64
(* FIXME: WHY WHY WHY does this one not work?
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint_literal
(n: U64.t)
: impl_typ #None (t_uint_literal n)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
if (mt = major_type_uint64) {
let i = cbor_destr_int64 c;
(i.cbor_int_value = n)
} else {
false
}
}
```
*)
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint_literal'
(n: U64.t)
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
requires
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) (None #raw_data_item)
))
returns res: bool
ensures
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) (None #raw_data_item) /\
res == t_uint_literal n v
))
{
let mt = cbor_get_major_type c;
if (mt = cbor_major_type_uint64) {
let i = cbor_destr_int64 c;
(i.cbor_int_value = n)
} else {
false
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_uint_literal
(n: U64.t)
: impl_typ (t_uint_literal n)
= impl_uint_literal' n
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_bytes
(_: unit)
: impl_typ #None bytes
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
(mt = cbor_major_type_byte_string)
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_array_group3
(#b: Ghost.erased (option raw_data_item))
(g: array_group3 b)
=
(pi: R.ref cbor_array_iterator_t) ->
(#p: perm) ->
(#i: Ghost.erased cbor_array_iterator_t) ->
(#l: Ghost.erased (list raw_data_item)) ->
stt bool
(R.pts_to pi i **
cbor_array_iterator_match p i l **
pure (opt_precedes (Ghost.reveal l) b)
)
(fun res -> exists* i' l'.
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
```pulse
ghost
fn intro_impl_array_group3_post
(#b: option raw_data_item)
(g: array_group3 b)
(pi: R.ref cbor_array_iterator_t)
(p: perm)
(i: cbor_array_iterator_t)
(l: list raw_data_item)
(res: bool)
(i': cbor_array_iterator_t)
(l': list raw_data_item)
requires
(
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
ensures
(exists* i' l'.
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
{
()
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_array_group3_concat
(#b: Ghost.erased (option raw_data_item))
(#g1: array_group3 b)
(f1: impl_array_group3 g1)
(#g2: array_group3 b)
(f2: impl_array_group3 g2)
: impl_array_group3 #b (array_group3_concat g1 g2)
=
(pi: R.ref cbor_array_iterator_t)
(#p: perm)
(#gi: Ghost.erased cbor_array_iterator_t)
(#l: Ghost.erased (list raw_data_item))
{
let test1 = f1 pi;
if (test1) {
let test2 = f2 pi;
stick_trans ();
test2
} else {
false
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_array_group3_item
(#b: Ghost.erased (option raw_data_item))
(#ty: bounded_typ_gen b)
(fty: impl_typ ty)
: impl_array_group3 #b (array_group3_item ty)
=
(pi: R.ref cbor_array_iterator_t)
(#p: perm)
(#gi: Ghost.erased cbor_array_iterator_t)
(#l: Ghost.erased (list raw_data_item))
{
let i = !pi;
rewrite (cbor_array_iterator_match p gi l) as (cbor_array_iterator_match p i l);
let is_done = cbor_array_iterator_is_done i;
rewrite (cbor_array_iterator_match p i l) as (cbor_array_iterator_match p gi l);
if (is_done) {
stick_refl0 (cbor_array_iterator_match p gi l);
intro_impl_array_group3_post (array_group3_item ty) pi p gi l false gi l; // FIXME: WHY WHY WHY? and also WHY WHY WHY here and not in the other "false" case below?
false
} else {
let c = cbor_array_iterator_next pi #p #l #gi; // FIXME: WHY WHY WHY those explicit arguments?
with gc i' l' . assert (
raw_data_item_match p c gc **
cbor_array_iterator_match p i' l' **
((raw_data_item_match p c gc ** cbor_array_iterator_match p i' l') @==> cbor_array_iterator_match p gi l)
); // this is needed for the explicit arguments to split_consume_l below
let test = fty c;
if (test) {
stick_consume_l ()
#(raw_data_item_match p c gc)
#(cbor_array_iterator_match p i' l')
#(cbor_array_iterator_match p gi l) // FIXME: WHY WHY WHY those explicit arguments? (for which the with above is needed)
;
true
} else {
elim_stick0 ()
#(raw_data_item_match p c gc ** cbor_array_iterator_match p i' l')
#(cbor_array_iterator_match p gi l); // FIXME: WHY WHY WHY those explicit arguments?
pi := i;
rewrite (R.pts_to pi i) as (R.pts_to pi gi);
stick_refl0 (cbor_array_iterator_match p gi l);
false
}
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_t_array
(#b: Ghost.erased (option raw_data_item))
(#g: (array_group3 b))
(ig: (impl_array_group3 (g)))
: impl_typ #b (t_array3 g)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let ty = cbor_get_major_type c;
if (ty = cbor_major_type_array) {
let i = cbor_array_iterator_init c;
with l . assert (cbor_array_iterator_match p i l);
rewrite (cbor_array_iterator_match p i l) as (cbor_array_iterator_match p (Ghost.reveal (Ghost.hide i)) l);
let mut pi = i;
let b_success = ig pi;
with gi' l' . assert (cbor_array_iterator_match p gi' l');
let i' = ! pi;
rewrite (cbor_array_iterator_match p gi' l') as (cbor_array_iterator_match p i' l');
let b_end = cbor_array_iterator_is_done i';
rewrite (cbor_array_iterator_match p i' l') as (cbor_array_iterator_match p gi' l');
elim_stick0 ();
rewrite (cbor_array_iterator_match p (Ghost.reveal (Ghost.hide i)) l) as (cbor_array_iterator_match p i l);
elim_stick0 ();
(b_success && b_end)
} else {
false
}
}
```
module U8 = FStar.UInt8 | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Stick.fsti.checked",
"Pulse.Lib.Reference.fsti.checked",
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"CDDL.Spec.fsti.checked",
"CBOR.Spec.fsti.checked",
"CBOR.Pulse.fst.checked"
],
"interface_file": false,
"source_file": "CDDL.Pulse.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Reference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "CDDL.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Stick",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t: CDDL.Spec.typ ->
va: FStar.Ghost.erased (FStar.Seq.Base.seq FStar.UInt8.t) ->
c: CBOR.Pulse.Extern.cbor_read_t ->
v: CBOR.Spec.Type.raw_data_item ->
rem: FStar.Seq.Base.seq FStar.UInt8.t
-> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"CDDL.Spec.typ",
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"FStar.UInt8.t",
"CBOR.Pulse.Extern.cbor_read_t",
"CBOR.Spec.Type.raw_data_item",
"Prims.l_and",
"CBOR.Pulse.Extern.cbor_read_success_postcond",
"Prims.eq2",
"Prims.bool",
"Prims.prop"
] | [] | false | false | false | true | true | let cbor_read_with_typ_success_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Tot prop =
| cbor_read_success_postcond va c v rem /\ t v == true | false |
Vale.AES.GCM_BE.fst | Vale.AES.GCM_BE.append_distributes_be_seq_quad32_to_bytes | val append_distributes_be_seq_quad32_to_bytes (x y: seq quad32)
: Lemma
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append x y)) ==
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE x))
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE y))) | val append_distributes_be_seq_quad32_to_bytes (x y: seq quad32)
: Lemma
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append x y)) ==
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE x))
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE y))) | let append_distributes_be_seq_quad32_to_bytes (x y:seq quad32) :
Lemma (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append x y)) == append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE x)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE y)))
=
append_distributes_be_seq_quad32_to_bytes x y | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_BE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 263,
"start_col": 0,
"start_line": 260
} | module Vale.AES.GCM_BE
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.AES.GCM_BE_s
open Vale.AES.AES_BE_s
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.AES.GHash_BE_s
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open FStar.Calc
let upper3_equal (q0 q1:quad32) : bool =
q0.lo1 = q1.lo1 &&
q0.hi2 = q1.hi2 &&
q0.hi3 = q1.hi3
let lemma_be_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma
(requires slice b0 0 12 == slice b1 0 12)
(ensures upper3_equal (be_bytes_to_quad32 b0) (be_bytes_to_quad32 b1))
=
let q0 = be_bytes_to_quad32 b0 in
let q1 = be_bytes_to_quad32 b1 in
be_bytes_to_quad32_reveal ();
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #nat8);
assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\
index b1 i == index (slice b1 0 12) i))
let lemma_be_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma
(slice (be_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
=
assert (equal (slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
(slice (be_quad32_to_bytes q) 0 12));
()
let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_BE) (num_bytes:nat64) (h_BE j0:quad32) : Lemma
(requires
length iv_extra_b == 1 /\
length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\
num_bytes == 96/8 /\
(let iv_BE = index iv_extra_b 0 in
j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\
(let raw_quads = append iv_b iv_extra_b in
let iv_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 num_bytes in
iv_bytes == iv))
(ensures j0 == compute_iv_BE h_BE iv)
=
assert (length iv == 12);
assert (length iv_b == 0);
lemma_empty iv_b;
append_empty_l iv_extra_b;
assert (append iv_b iv_extra_b == iv_extra_b);
let q = index iv_extra_b 0 in
be_seq_quad32_to_bytes_of_singleton q;
assert (equal iv_extra_b (create 1 q));
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b) == be_quad32_to_bytes q);
calc (==) {
slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12;
== {}
slice (pad_to_128_bits iv) 0 12;
};
calc (==) {
be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b)) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits iv);
};
calc (==) {
j0;
== {}
set_to_one q;
== { be_bytes_to_quad32_to_bytes q }
set_to_one (be_bytes_to_quad32 (be_quad32_to_bytes q));
== {
lemma_be_seq_quad32_to_bytes_prefix_equality q;
lemma_be_bytes_to_quad32_prefix_equality
(be_quad32_to_bytes q)
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
}
set_to_one (be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)));
== { lemma_be_bytes_to_quad32_prefix_equality
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
(pad_to_128_bits iv) }
set_to_one (be_bytes_to_quad32 (pad_to_128_bits iv));
== {compute_iv_BE_reveal ()}
compute_iv_BE h_BE iv;
};
()
let lemma_compute_iv_hard (iv:supported_iv_BE) (quads:seq quad32) (length_quad h_BE j0:quad32) : Lemma
(requires
~(length iv == 96/8) /\
quads == be_bytes_to_seq_quad32 (pad_to_128_bits iv) /\
j0 == ghash_incremental h_BE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 0)
(nat_to_two 32 (8 * length iv))))
(ensures j0 == compute_iv_BE h_BE iv)
=
ghash_incremental_to_ghash h_BE (append quads (create 1 length_quad));
compute_iv_BE_reveal ();
()
let gcm_encrypt_BE_fst_helper (iv:supported_iv_BE) (iv_enc iv_BE:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma
(requires
is_aes_key_word alg key /\
length plain < pow2_32 /\
length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
iv_enc == inc32 (compute_iv_BE h_BE iv) 1 /\
cipher == gctr_encrypt iv_enc plain alg key
))
(ensures cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth))
=
gcm_encrypt_BE_reveal ()
let gcm_encrypt_BE_snd_helper (iv:supported_iv_BE) (j0_BE length_quad32 hash mac:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma
(requires
is_aes_key_word alg key /\
length plain < pow2_32 /\
length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth) /\
length_quad32 == two_two_to_four (Mktwo (nat_to_two 32 (8 * length auth)) (nat_to_two 32 (8 * length plain))) /\
(let auth_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits auth) in
let cipher_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits cipher) in
hash == ghash_BE h_BE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\
be_quad32_to_bytes mac == gctr_encrypt j0_BE (be_quad32_to_bytes hash) alg key)
))
(ensures be_quad32_to_bytes mac == snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth))
=
gcm_encrypt_BE_reveal ()
#reset-options "--z3rlimit 10"
let gcm_blocks_helper_enc (alg:algorithm) (key:seq nat32)
(p128 p_bytes c128 c_bytes:seq quad32)
(auth_bytes:seq nat8)
(p_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
(length auth_bytes) < pow2_32 /\
is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\
(let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2
)))
(ensures (let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
//cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key))
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes)))
=
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
gctr_partial_opaque_completed alg plain cipher key ctr_BE_2;
if p_num_bytes > length p128 * 16 then (
gctr_partial_reveal ();
assert (gctr_partial alg (length p128) plain cipher key ctr_BE_2);
assert (equal (slice plain 0 (length p128))
(slice p128 0 (length p128)));
assert (equal (slice cipher 0 (length p128))
(slice c128 0 (length p128)));
gctr_partial_opaque_ignores_postfix
alg (length p128)
plain p128
cipher c128
key ctr_BE_2;
assert (gctr_partial alg (length p128) p128 c128 key ctr_BE_2);
gctr_partial_opaque_completed alg p128 c128 key ctr_BE_2;
let num_blocks = p_num_bytes / 16 in
assert(index cipher num_blocks == quad32_xor (index plain num_blocks) (aes_encrypt_word alg key (inc32 ctr_BE_2 num_blocks)));
gctr_encrypt_block_offset ctr_BE_2 (index plain num_blocks) alg key num_blocks;
assert( gctr_encrypt_block ctr_BE_2 (index plain num_blocks) alg key num_blocks ==
gctr_encrypt_block (inc32 ctr_BE_2 num_blocks) (index plain num_blocks) alg key 0);
aes_encrypt_word_reveal ();
gctr_partial_to_full_advanced ctr_BE_2 plain cipher alg key p_num_bytes;
assert (cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key)
) else (
gctr_partial_to_full_basic ctr_BE_2 plain alg key cipher;
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher) == gctr_encrypt ctr_BE_2 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) alg key);
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
assert (equal plain_bytes (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)));
assert (equal cipher_bytes (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)));
assert (cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key)
);
gcm_encrypt_BE_fst_helper iv ctr_BE_2 j0_BE plain_bytes auth_bytes cipher_bytes alg key;
()
let slice_append_back (#a:Type) (x y:seq a) (i:nat) : Lemma
(requires length x <= i /\ i <= length x + length y)
(ensures slice (append x y) 0 i == append x (slice y 0 (i - length x)))
=
assert (equal (slice (append x y) 0 i) (append x (slice y 0 (i - length x))));
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.GHash_BE_s.fst.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.GCM_BE_s.fst.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_BE.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> y: FStar.Seq.Base.seq Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(ensures
Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE (FStar.Seq.Base.append
x
y)) ==
FStar.Seq.Base.append (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
x))
(Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE y))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.quad32",
"Vale.Arch.Types.append_distributes_be_seq_quad32_to_bytes",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Vale.Def.Words_s.nat8",
"Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE",
"Vale.Def.Words.Seq_s.seq_four_to_seq_BE",
"Vale.Def.Types_s.nat32",
"FStar.Seq.Base.append",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let append_distributes_be_seq_quad32_to_bytes (x y: seq quad32)
: Lemma
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append x y)) ==
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE x))
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE y))) =
| append_distributes_be_seq_quad32_to_bytes x y | false |
CDDL.Pulse.fst | CDDL.Pulse.cbor_map_get_with_typ_post_found | val cbor_map_get_with_typ_post_found (t: typ) (vkey vmap vvalue: raw_data_item) : Tot prop | val cbor_map_get_with_typ_post_found (t: typ) (vkey vmap vvalue: raw_data_item) : Tot prop | let cbor_map_get_with_typ_post_found
(t: typ)
(vkey: raw_data_item)
(vmap: raw_data_item)
(vvalue: raw_data_item)
: Tot prop
= Map? vmap /\
list_ghost_assoc vkey (Map?.v vmap) == Some vvalue /\
t vvalue == true | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Pulse.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 18,
"end_line": 622,
"start_col": 0,
"start_line": 614
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module CDDL.Pulse
open Pulse.Lib.Pervasives
open Pulse.Lib.Stick
open CBOR.Spec
open CBOR.Pulse
open CDDL.Spec
module R = Pulse.Lib.Reference
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_typ
(#b: option raw_data_item)
(t: bounded_typ_gen b)
=
(c: cbor) ->
(#p: perm) ->
(#v: Ghost.erased raw_data_item) ->
stt bool
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) b
))
(fun res -> raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) b /\
res == t v
))
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_coerce_to_bounded_typ
(b: Ghost.erased (option raw_data_item))
(#t: typ)
(f: impl_typ t)
: impl_typ #b (coerce_to_bounded_typ b t) // FIXME: WHY WHY WHY do I need to provide the implicit argument
= (c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
f c;
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_t_choice
(#b: Ghost.erased (option raw_data_item))
(#t1 #t2: bounded_typ_gen b)
(f1: impl_typ t1)
(f2: impl_typ t2)
: impl_typ #b (t_choice t1 t2)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let test = f1 c;
if (test)
{
true
} else {
f2 c
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_t_choice_none // FIXME: WHY WHY WHY can F* not automatically infer t1 and t2 by reducing (reveal (hide None)) to None?
(#t1 #t2: bounded_typ_gen None)
(f1: impl_typ t1)
(f2: impl_typ t2)
: Tot (impl_typ (t_choice t1 t2))
= impl_t_choice #None #t1 #t2 f1 f2
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_any
(_: unit)
: impl_typ #None any
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
true
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint
(_: unit)
: impl_typ #None uint
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
(mt = cbor_major_type_uint64)
}
```
module U64 = FStar.UInt64
(* FIXME: WHY WHY WHY does this one not work?
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint_literal
(n: U64.t)
: impl_typ #None (t_uint_literal n)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
if (mt = major_type_uint64) {
let i = cbor_destr_int64 c;
(i.cbor_int_value = n)
} else {
false
}
}
```
*)
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint_literal'
(n: U64.t)
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
requires
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) (None #raw_data_item)
))
returns res: bool
ensures
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) (None #raw_data_item) /\
res == t_uint_literal n v
))
{
let mt = cbor_get_major_type c;
if (mt = cbor_major_type_uint64) {
let i = cbor_destr_int64 c;
(i.cbor_int_value = n)
} else {
false
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_uint_literal
(n: U64.t)
: impl_typ (t_uint_literal n)
= impl_uint_literal' n
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_bytes
(_: unit)
: impl_typ #None bytes
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
(mt = cbor_major_type_byte_string)
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_array_group3
(#b: Ghost.erased (option raw_data_item))
(g: array_group3 b)
=
(pi: R.ref cbor_array_iterator_t) ->
(#p: perm) ->
(#i: Ghost.erased cbor_array_iterator_t) ->
(#l: Ghost.erased (list raw_data_item)) ->
stt bool
(R.pts_to pi i **
cbor_array_iterator_match p i l **
pure (opt_precedes (Ghost.reveal l) b)
)
(fun res -> exists* i' l'.
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
```pulse
ghost
fn intro_impl_array_group3_post
(#b: option raw_data_item)
(g: array_group3 b)
(pi: R.ref cbor_array_iterator_t)
(p: perm)
(i: cbor_array_iterator_t)
(l: list raw_data_item)
(res: bool)
(i': cbor_array_iterator_t)
(l': list raw_data_item)
requires
(
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
ensures
(exists* i' l'.
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
{
()
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_array_group3_concat
(#b: Ghost.erased (option raw_data_item))
(#g1: array_group3 b)
(f1: impl_array_group3 g1)
(#g2: array_group3 b)
(f2: impl_array_group3 g2)
: impl_array_group3 #b (array_group3_concat g1 g2)
=
(pi: R.ref cbor_array_iterator_t)
(#p: perm)
(#gi: Ghost.erased cbor_array_iterator_t)
(#l: Ghost.erased (list raw_data_item))
{
let test1 = f1 pi;
if (test1) {
let test2 = f2 pi;
stick_trans ();
test2
} else {
false
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_array_group3_item
(#b: Ghost.erased (option raw_data_item))
(#ty: bounded_typ_gen b)
(fty: impl_typ ty)
: impl_array_group3 #b (array_group3_item ty)
=
(pi: R.ref cbor_array_iterator_t)
(#p: perm)
(#gi: Ghost.erased cbor_array_iterator_t)
(#l: Ghost.erased (list raw_data_item))
{
let i = !pi;
rewrite (cbor_array_iterator_match p gi l) as (cbor_array_iterator_match p i l);
let is_done = cbor_array_iterator_is_done i;
rewrite (cbor_array_iterator_match p i l) as (cbor_array_iterator_match p gi l);
if (is_done) {
stick_refl0 (cbor_array_iterator_match p gi l);
intro_impl_array_group3_post (array_group3_item ty) pi p gi l false gi l; // FIXME: WHY WHY WHY? and also WHY WHY WHY here and not in the other "false" case below?
false
} else {
let c = cbor_array_iterator_next pi #p #l #gi; // FIXME: WHY WHY WHY those explicit arguments?
with gc i' l' . assert (
raw_data_item_match p c gc **
cbor_array_iterator_match p i' l' **
((raw_data_item_match p c gc ** cbor_array_iterator_match p i' l') @==> cbor_array_iterator_match p gi l)
); // this is needed for the explicit arguments to split_consume_l below
let test = fty c;
if (test) {
stick_consume_l ()
#(raw_data_item_match p c gc)
#(cbor_array_iterator_match p i' l')
#(cbor_array_iterator_match p gi l) // FIXME: WHY WHY WHY those explicit arguments? (for which the with above is needed)
;
true
} else {
elim_stick0 ()
#(raw_data_item_match p c gc ** cbor_array_iterator_match p i' l')
#(cbor_array_iterator_match p gi l); // FIXME: WHY WHY WHY those explicit arguments?
pi := i;
rewrite (R.pts_to pi i) as (R.pts_to pi gi);
stick_refl0 (cbor_array_iterator_match p gi l);
false
}
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_t_array
(#b: Ghost.erased (option raw_data_item))
(#g: (array_group3 b))
(ig: (impl_array_group3 (g)))
: impl_typ #b (t_array3 g)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let ty = cbor_get_major_type c;
if (ty = cbor_major_type_array) {
let i = cbor_array_iterator_init c;
with l . assert (cbor_array_iterator_match p i l);
rewrite (cbor_array_iterator_match p i l) as (cbor_array_iterator_match p (Ghost.reveal (Ghost.hide i)) l);
let mut pi = i;
let b_success = ig pi;
with gi' l' . assert (cbor_array_iterator_match p gi' l');
let i' = ! pi;
rewrite (cbor_array_iterator_match p gi' l') as (cbor_array_iterator_match p i' l');
let b_end = cbor_array_iterator_is_done i';
rewrite (cbor_array_iterator_match p i' l') as (cbor_array_iterator_match p gi' l');
elim_stick0 ();
rewrite (cbor_array_iterator_match p (Ghost.reveal (Ghost.hide i)) l) as (cbor_array_iterator_match p i l);
elim_stick0 ();
(b_success && b_end)
} else {
false
}
}
```
module U8 = FStar.UInt8
noextract [@@noextract_to "krml"]
let cbor_read_with_typ_success_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Tot prop
=
cbor_read_success_postcond va c v rem /\
t v == true
module A = Pulse.Lib.Array
let cbor_read_with_typ_success_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
: Tot vprop
= exists* v rem.
raw_data_item_match full_perm c.cbor_read_payload v **
A.pts_to c.cbor_read_remainder #p rem **
((raw_data_item_match full_perm c.cbor_read_payload v ** A.pts_to c.cbor_read_remainder #p rem) @==>
A.pts_to a #p va) **
pure (cbor_read_with_typ_success_postcond t va c v rem)
noextract [@@noextract_to "krml"]
let cbor_read_with_typ_error_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
: Tot prop
= forall v suff .
Ghost.reveal va == serialize_cbor v `Seq.append` suff ==>
t v == false
let cbor_read_with_typ_error_postcond_intro_typ_fail
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Lemma
(requires (
cbor_read_success_postcond va c v rem /\
t v == false
))
(ensures (
cbor_read_with_typ_error_postcond t va
))
= serialize_cbor_with_test_correct v rem (fun v' rem' -> t v' == true)
let cbor_read_with_typ_error_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
: Tot vprop
= A.pts_to a #p va ** pure (cbor_read_with_typ_error_postcond t va)
let cbor_read_with_typ_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(res: cbor_read_t)
: Tot vprop
= if res.cbor_read_is_success
then cbor_read_with_typ_success_post t a p va res
else cbor_read_with_typ_error_post t a p va
module SZ = FStar.SizeT
inline_for_extraction noextract
let mk_cbor_read_error
(res: cbor_read_t)
: Tot cbor_read_t
= {res with cbor_read_is_success = false}
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn cbor_read_with_typ
(#t: typ)
(ft: impl_typ t)
(a: A.array U8.t)
(sz: SZ.t)
(#va: Ghost.erased (Seq.seq U8.t))
(#p: perm)
requires
(A.pts_to a #p va ** pure (
(SZ.v sz == Seq.length va \/ SZ.v sz == A.length a)
))
returns res: cbor_read_t
ensures cbor_read_with_typ_post t a p va res
{
let res = cbor_read a sz;
if (res.cbor_read_is_success) {
rewrite (cbor_read_post a p va res) as (cbor_read_success_post a p va res);
unfold (cbor_read_success_post a p va res);
let test = ft res.cbor_read_payload;
if (test) {
fold (cbor_read_with_typ_success_post t a p va res);
rewrite (cbor_read_with_typ_success_post t a p va res) as (cbor_read_with_typ_post t a p va res);
res
} else {
with v . assert (raw_data_item_match full_perm res.cbor_read_payload v);
with vrem . assert (A.pts_to res.cbor_read_remainder #p vrem);
cbor_read_with_typ_error_postcond_intro_typ_fail t va res v vrem;
elim_stick0 ()
#(raw_data_item_match full_perm res.cbor_read_payload v ** A.pts_to res.cbor_read_remainder #p vrem);
fold (cbor_read_with_typ_error_post t a p va);
let res = mk_cbor_read_error res;
rewrite (cbor_read_with_typ_error_post t a p va) as (cbor_read_with_typ_post t a p va res);
res
}
} else {
rewrite (cbor_read_post a p va res) as (cbor_read_error_post a p va);
unfold (cbor_read_error_post a p va);
fold (cbor_read_with_typ_error_post t a p va);
rewrite (cbor_read_with_typ_error_post t a p va) as (cbor_read_with_typ_post t a p va res);
res
}
}
```
noextract [@@noextract_to "krml"]
let cbor_read_deterministically_encoded_with_typ_success_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Tot prop
=
cbor_read_deterministically_encoded_success_postcond va c v rem /\
t v == true
noextract [@@noextract_to "krml"]
let cbor_read_deterministically_encoded_with_typ_error_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
: Tot prop
= forall v suff .
(Ghost.reveal va == serialize_cbor v `Seq.append` suff /\
data_item_wf deterministically_encoded_cbor_map_key_order v == true
) ==>
t v == false
let cbor_read_deterministically_encoded_with_typ_error_postcond_intro_typ_fail
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Lemma
(requires (
cbor_read_deterministically_encoded_success_postcond va c v rem /\
t v == false
))
(ensures (
cbor_read_deterministically_encoded_with_typ_error_postcond t va
))
= serialize_cbor_with_test_correct v rem (fun v' rem' -> data_item_wf deterministically_encoded_cbor_map_key_order v' == true /\ t v' == true)
let cbor_read_deterministically_encoded_with_typ_success_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(res: cbor_read_t)
: Tot vprop
= exists* v rem.
raw_data_item_match full_perm res.cbor_read_payload v **
A.pts_to res.cbor_read_remainder #p rem **
((raw_data_item_match full_perm res.cbor_read_payload v ** A.pts_to res.cbor_read_remainder #p rem) @==>
A.pts_to a #p va) **
pure (cbor_read_deterministically_encoded_with_typ_success_postcond t va res v rem)
let cbor_read_deterministically_encoded_with_typ_error_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
: Tot vprop
= A.pts_to a #p va ** pure (cbor_read_deterministically_encoded_with_typ_error_postcond t va)
let cbor_read_deterministically_encoded_with_typ_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(res: cbor_read_t)
: Tot vprop
= if res.cbor_read_is_success
then cbor_read_deterministically_encoded_with_typ_success_post t a p va res
else cbor_read_deterministically_encoded_with_typ_error_post t a p va
module SZ = FStar.SizeT
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn cbor_read_deterministically_encoded_with_typ
(#t: typ)
(ft: impl_typ t)
(a: A.array U8.t)
(sz: SZ.t)
(#va: Ghost.erased (Seq.seq U8.t))
(#p: perm)
requires
(A.pts_to a #p va ** pure (
(SZ.v sz == Seq.length va \/ SZ.v sz == A.length a)
))
returns res: cbor_read_t
ensures cbor_read_deterministically_encoded_with_typ_post t a p va res
{
let res = cbor_read_deterministically_encoded a sz;
if (res.cbor_read_is_success) {
rewrite (cbor_read_deterministically_encoded_post a p va res) as (cbor_read_deterministically_encoded_success_post a p va res);
unfold (cbor_read_deterministically_encoded_success_post a p va res);
let test = ft res.cbor_read_payload;
if (test) {
fold (cbor_read_deterministically_encoded_with_typ_success_post t a p va res);
fold (cbor_read_deterministically_encoded_with_typ_post t a p va res);
res
} else {
with v . assert (raw_data_item_match full_perm res.cbor_read_payload v);
with vrem . assert (A.pts_to res.cbor_read_remainder #p vrem);
cbor_read_deterministically_encoded_with_typ_error_postcond_intro_typ_fail t va res v vrem;
elim_stick0 ()
#(raw_data_item_match full_perm res.cbor_read_payload v ** A.pts_to res.cbor_read_remainder #p vrem);
let res = mk_cbor_read_error res;
fold (cbor_read_deterministically_encoded_with_typ_error_post t a p va);
fold (cbor_read_deterministically_encoded_with_typ_post t a p va res);
res
}
} else {
rewrite (cbor_read_deterministically_encoded_post a p va res) as (cbor_read_deterministically_encoded_error_post a p va);
unfold (cbor_read_deterministically_encoded_error_post a p va);
fold (cbor_read_deterministically_encoded_with_typ_error_post t a p va);
fold (cbor_read_deterministically_encoded_with_typ_post t a p va res);
res
}
}
``` | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Stick.fsti.checked",
"Pulse.Lib.Reference.fsti.checked",
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"CDDL.Spec.fsti.checked",
"CBOR.Spec.fsti.checked",
"CBOR.Pulse.fst.checked"
],
"interface_file": false,
"source_file": "CDDL.Pulse.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Reference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "CDDL.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Stick",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t: CDDL.Spec.typ ->
vkey: CBOR.Spec.Type.raw_data_item ->
vmap: CBOR.Spec.Type.raw_data_item ->
vvalue: CBOR.Spec.Type.raw_data_item
-> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"CDDL.Spec.typ",
"CBOR.Spec.Type.raw_data_item",
"Prims.l_and",
"Prims.b2t",
"CBOR.Spec.Type.uu___is_Map",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"CBOR.Pulse.list_ghost_assoc",
"CBOR.Spec.Type.__proj__Map__item__v",
"FStar.Pervasives.Native.Some",
"Prims.bool",
"Prims.prop"
] | [] | false | false | false | true | true | let cbor_map_get_with_typ_post_found (t: typ) (vkey vmap vvalue: raw_data_item) : Tot prop =
| Map? vmap /\ list_ghost_assoc vkey (Map?.v vmap) == Some vvalue /\ t vvalue == true | false |
Vale.AES.GCM_BE.fst | Vale.AES.GCM_BE.lemma_be_bytes_to_quad32_prefix_equality | val lemma_be_bytes_to_quad32_prefix_equality
(b0: seq nat8 {length b0 == 16})
(b1: seq nat8 {length b1 == 16})
: Lemma (requires slice b0 0 12 == slice b1 0 12)
(ensures upper3_equal (be_bytes_to_quad32 b0) (be_bytes_to_quad32 b1)) | val lemma_be_bytes_to_quad32_prefix_equality
(b0: seq nat8 {length b0 == 16})
(b1: seq nat8 {length b1 == 16})
: Lemma (requires slice b0 0 12 == slice b1 0 12)
(ensures upper3_equal (be_bytes_to_quad32 b0) (be_bytes_to_quad32 b1)) | let lemma_be_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma
(requires slice b0 0 12 == slice b1 0 12)
(ensures upper3_equal (be_bytes_to_quad32 b0) (be_bytes_to_quad32 b1))
=
let q0 = be_bytes_to_quad32 b0 in
let q1 = be_bytes_to_quad32 b1 in
be_bytes_to_quad32_reveal ();
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #nat8);
assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\
index b1 i == index (slice b1 0 12) i)) | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_BE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 80,
"end_line": 34,
"start_col": 0,
"start_line": 23
} | module Vale.AES.GCM_BE
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.AES.GCM_BE_s
open Vale.AES.AES_BE_s
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.AES.GHash_BE_s
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open FStar.Calc
let upper3_equal (q0 q1:quad32) : bool =
q0.lo1 = q1.lo1 &&
q0.hi2 = q1.hi2 &&
q0.hi3 = q1.hi3 | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.GHash_BE_s.fst.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.GCM_BE_s.fst.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_BE.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b0: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 {FStar.Seq.Base.length b0 == 16} ->
b1: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 {FStar.Seq.Base.length b1 == 16}
-> FStar.Pervasives.Lemma (requires FStar.Seq.Base.slice b0 0 12 == FStar.Seq.Base.slice b1 0 12)
(ensures
Vale.AES.GCM_BE.upper3_equal (Vale.Def.Types_s.be_bytes_to_quad32 b0)
(Vale.Def.Types_s.be_bytes_to_quad32 b1)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat8",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"Prims._assert",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"FStar.Seq.Base.index",
"FStar.Seq.Base.slice",
"Prims.unit",
"FStar.Pervasives.reveal_opaque",
"Prims.op_Modulus",
"Vale.Def.Words_s.four",
"Prims.op_Division",
"Vale.Def.Words.Seq_s.seq_to_seq_four_BE",
"Vale.Def.Types_s.be_bytes_to_quad32_reveal",
"Vale.Def.Types_s.quad32",
"Vale.Def.Types_s.be_bytes_to_quad32",
"Prims.squash",
"Vale.AES.GCM_BE.upper3_equal",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_be_bytes_to_quad32_prefix_equality
(b0: seq nat8 {length b0 == 16})
(b1: seq nat8 {length b1 == 16})
: Lemma (requires slice b0 0 12 == slice b1 0 12)
(ensures upper3_equal (be_bytes_to_quad32 b0) (be_bytes_to_quad32 b1)) =
| let q0 = be_bytes_to_quad32 b0 in
let q1 = be_bytes_to_quad32 b1 in
be_bytes_to_quad32_reveal ();
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #nat8);
assert (forall (i: int).
(0 <= i /\ i < 12) ==>
(index b0 i == index (slice b0 0 12) i /\ index b1 i == index (slice b1 0 12) i)) | false |
Vale.AES.GCM_BE.fst | Vale.AES.GCM_BE.gcm_encrypt_BE_fst_helper | val gcm_encrypt_BE_fst_helper
(iv: supported_iv_BE)
(iv_enc iv_BE: quad32)
(plain auth cipher: seq nat8)
(alg: algorithm)
(key: seq nat32)
: Lemma
(requires
is_aes_key_word alg key /\ length plain < pow2_32 /\ length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
iv_enc == inc32 (compute_iv_BE h_BE iv) 1 /\ cipher == gctr_encrypt iv_enc plain alg key))
(ensures cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth)) | val gcm_encrypt_BE_fst_helper
(iv: supported_iv_BE)
(iv_enc iv_BE: quad32)
(plain auth cipher: seq nat8)
(alg: algorithm)
(key: seq nat32)
: Lemma
(requires
is_aes_key_word alg key /\ length plain < pow2_32 /\ length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
iv_enc == inc32 (compute_iv_BE h_BE iv) 1 /\ cipher == gctr_encrypt iv_enc plain alg key))
(ensures cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth)) | let gcm_encrypt_BE_fst_helper (iv:supported_iv_BE) (iv_enc iv_BE:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma
(requires
is_aes_key_word alg key /\
length plain < pow2_32 /\
length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
iv_enc == inc32 (compute_iv_BE h_BE iv) 1 /\
cipher == gctr_encrypt iv_enc plain alg key
))
(ensures cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth))
=
gcm_encrypt_BE_reveal () | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_BE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 125,
"start_col": 0,
"start_line": 114
} | module Vale.AES.GCM_BE
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.AES.GCM_BE_s
open Vale.AES.AES_BE_s
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.AES.GHash_BE_s
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open FStar.Calc
let upper3_equal (q0 q1:quad32) : bool =
q0.lo1 = q1.lo1 &&
q0.hi2 = q1.hi2 &&
q0.hi3 = q1.hi3
let lemma_be_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma
(requires slice b0 0 12 == slice b1 0 12)
(ensures upper3_equal (be_bytes_to_quad32 b0) (be_bytes_to_quad32 b1))
=
let q0 = be_bytes_to_quad32 b0 in
let q1 = be_bytes_to_quad32 b1 in
be_bytes_to_quad32_reveal ();
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #nat8);
assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\
index b1 i == index (slice b1 0 12) i))
let lemma_be_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma
(slice (be_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
=
assert (equal (slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
(slice (be_quad32_to_bytes q) 0 12));
()
let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_BE) (num_bytes:nat64) (h_BE j0:quad32) : Lemma
(requires
length iv_extra_b == 1 /\
length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\
num_bytes == 96/8 /\
(let iv_BE = index iv_extra_b 0 in
j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\
(let raw_quads = append iv_b iv_extra_b in
let iv_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 num_bytes in
iv_bytes == iv))
(ensures j0 == compute_iv_BE h_BE iv)
=
assert (length iv == 12);
assert (length iv_b == 0);
lemma_empty iv_b;
append_empty_l iv_extra_b;
assert (append iv_b iv_extra_b == iv_extra_b);
let q = index iv_extra_b 0 in
be_seq_quad32_to_bytes_of_singleton q;
assert (equal iv_extra_b (create 1 q));
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b) == be_quad32_to_bytes q);
calc (==) {
slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12;
== {}
slice (pad_to_128_bits iv) 0 12;
};
calc (==) {
be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b)) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits iv);
};
calc (==) {
j0;
== {}
set_to_one q;
== { be_bytes_to_quad32_to_bytes q }
set_to_one (be_bytes_to_quad32 (be_quad32_to_bytes q));
== {
lemma_be_seq_quad32_to_bytes_prefix_equality q;
lemma_be_bytes_to_quad32_prefix_equality
(be_quad32_to_bytes q)
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
}
set_to_one (be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)));
== { lemma_be_bytes_to_quad32_prefix_equality
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
(pad_to_128_bits iv) }
set_to_one (be_bytes_to_quad32 (pad_to_128_bits iv));
== {compute_iv_BE_reveal ()}
compute_iv_BE h_BE iv;
};
()
let lemma_compute_iv_hard (iv:supported_iv_BE) (quads:seq quad32) (length_quad h_BE j0:quad32) : Lemma
(requires
~(length iv == 96/8) /\
quads == be_bytes_to_seq_quad32 (pad_to_128_bits iv) /\
j0 == ghash_incremental h_BE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 0)
(nat_to_two 32 (8 * length iv))))
(ensures j0 == compute_iv_BE h_BE iv)
=
ghash_incremental_to_ghash h_BE (append quads (create 1 length_quad));
compute_iv_BE_reveal ();
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.GHash_BE_s.fst.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.GCM_BE_s.fst.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_BE.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
iv: Vale.AES.GCM_BE_s.supported_iv_BE ->
iv_enc: Vale.Def.Types_s.quad32 ->
iv_BE: Vale.Def.Types_s.quad32 ->
plain: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 ->
auth: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 ->
cipher: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 ->
alg: Vale.AES.AES_common_s.algorithm ->
key: FStar.Seq.Base.seq Vale.Def.Words_s.nat32
-> FStar.Pervasives.Lemma
(requires
Vale.AES.AES_BE_s.is_aes_key_word alg key /\
FStar.Seq.Base.length plain < Vale.Def.Words_s.pow2_32 /\
FStar.Seq.Base.length auth < Vale.Def.Words_s.pow2_32 /\
(let h_BE = Vale.AES.AES_BE_s.aes_encrypt_word alg key (Vale.Def.Words_s.Mkfour 0 0 0 0) in
iv_enc == Vale.AES.GCTR_BE_s.inc32 (Vale.AES.GCM_BE_s.compute_iv_BE h_BE iv) 1 /\
cipher == Vale.AES.GCTR_BE_s.gctr_encrypt iv_enc plain alg key))
(ensures
cipher ==
FStar.Pervasives.Native.fst (Vale.AES.GCM_BE_s.gcm_encrypt_BE alg
(Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE key)
iv
plain
auth)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.AES.GCM_BE_s.supported_iv_BE",
"Vale.Def.Types_s.quad32",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat8",
"Vale.AES.AES_common_s.algorithm",
"Vale.Def.Words_s.nat32",
"Vale.AES.GCM_BE_s.gcm_encrypt_BE_reveal",
"Prims.unit",
"Prims.l_and",
"Vale.AES.AES_BE_s.is_aes_key_word",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Vale.Def.Words_s.pow2_32",
"Prims.eq2",
"Vale.AES.GCTR_BE_s.inc32",
"Vale.AES.GCM_BE_s.compute_iv_BE",
"Vale.Def.Types_s.nat8",
"Vale.AES.GCTR_BE_s.gctr_encrypt",
"Vale.AES.AES_BE_s.aes_encrypt_word",
"Vale.Def.Words_s.Mkfour",
"Vale.Def.Types_s.nat32",
"Prims.squash",
"FStar.Pervasives.Native.fst",
"Vale.AES.GCM_BE_s.gcm_encrypt_BE",
"Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let gcm_encrypt_BE_fst_helper
(iv: supported_iv_BE)
(iv_enc iv_BE: quad32)
(plain auth cipher: seq nat8)
(alg: algorithm)
(key: seq nat32)
: Lemma
(requires
is_aes_key_word alg key /\ length plain < pow2_32 /\ length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
iv_enc == inc32 (compute_iv_BE h_BE iv) 1 /\ cipher == gctr_encrypt iv_enc plain alg key))
(ensures cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth)) =
| gcm_encrypt_BE_reveal () | false |
Vale.AES.GCM_BE.fst | Vale.AES.GCM_BE.slice_append_back | val slice_append_back (#a: Type) (x y: seq a) (i: nat)
: Lemma (requires length x <= i /\ i <= length x + length y)
(ensures slice (append x y) 0 i == append x (slice y 0 (i - length x))) | val slice_append_back (#a: Type) (x y: seq a) (i: nat)
: Lemma (requires length x <= i /\ i <= length x + length y)
(ensures slice (append x y) 0 i == append x (slice y 0 (i - length x))) | let slice_append_back (#a:Type) (x y:seq a) (i:nat) : Lemma
(requires length x <= i /\ i <= length x + length y)
(ensures slice (append x y) 0 i == append x (slice y 0 (i - length x)))
=
assert (equal (slice (append x y) 0 i) (append x (slice y 0 (i - length x))));
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_BE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 258,
"start_col": 0,
"start_line": 253
} | module Vale.AES.GCM_BE
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.AES.GCM_BE_s
open Vale.AES.AES_BE_s
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.AES.GHash_BE_s
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open FStar.Calc
let upper3_equal (q0 q1:quad32) : bool =
q0.lo1 = q1.lo1 &&
q0.hi2 = q1.hi2 &&
q0.hi3 = q1.hi3
let lemma_be_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma
(requires slice b0 0 12 == slice b1 0 12)
(ensures upper3_equal (be_bytes_to_quad32 b0) (be_bytes_to_quad32 b1))
=
let q0 = be_bytes_to_quad32 b0 in
let q1 = be_bytes_to_quad32 b1 in
be_bytes_to_quad32_reveal ();
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #nat8);
assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\
index b1 i == index (slice b1 0 12) i))
let lemma_be_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma
(slice (be_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
=
assert (equal (slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
(slice (be_quad32_to_bytes q) 0 12));
()
let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_BE) (num_bytes:nat64) (h_BE j0:quad32) : Lemma
(requires
length iv_extra_b == 1 /\
length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\
num_bytes == 96/8 /\
(let iv_BE = index iv_extra_b 0 in
j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\
(let raw_quads = append iv_b iv_extra_b in
let iv_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 num_bytes in
iv_bytes == iv))
(ensures j0 == compute_iv_BE h_BE iv)
=
assert (length iv == 12);
assert (length iv_b == 0);
lemma_empty iv_b;
append_empty_l iv_extra_b;
assert (append iv_b iv_extra_b == iv_extra_b);
let q = index iv_extra_b 0 in
be_seq_quad32_to_bytes_of_singleton q;
assert (equal iv_extra_b (create 1 q));
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b) == be_quad32_to_bytes q);
calc (==) {
slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12;
== {}
slice (pad_to_128_bits iv) 0 12;
};
calc (==) {
be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b)) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits iv);
};
calc (==) {
j0;
== {}
set_to_one q;
== { be_bytes_to_quad32_to_bytes q }
set_to_one (be_bytes_to_quad32 (be_quad32_to_bytes q));
== {
lemma_be_seq_quad32_to_bytes_prefix_equality q;
lemma_be_bytes_to_quad32_prefix_equality
(be_quad32_to_bytes q)
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
}
set_to_one (be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)));
== { lemma_be_bytes_to_quad32_prefix_equality
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
(pad_to_128_bits iv) }
set_to_one (be_bytes_to_quad32 (pad_to_128_bits iv));
== {compute_iv_BE_reveal ()}
compute_iv_BE h_BE iv;
};
()
let lemma_compute_iv_hard (iv:supported_iv_BE) (quads:seq quad32) (length_quad h_BE j0:quad32) : Lemma
(requires
~(length iv == 96/8) /\
quads == be_bytes_to_seq_quad32 (pad_to_128_bits iv) /\
j0 == ghash_incremental h_BE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 0)
(nat_to_two 32 (8 * length iv))))
(ensures j0 == compute_iv_BE h_BE iv)
=
ghash_incremental_to_ghash h_BE (append quads (create 1 length_quad));
compute_iv_BE_reveal ();
()
let gcm_encrypt_BE_fst_helper (iv:supported_iv_BE) (iv_enc iv_BE:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma
(requires
is_aes_key_word alg key /\
length plain < pow2_32 /\
length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
iv_enc == inc32 (compute_iv_BE h_BE iv) 1 /\
cipher == gctr_encrypt iv_enc plain alg key
))
(ensures cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth))
=
gcm_encrypt_BE_reveal ()
let gcm_encrypt_BE_snd_helper (iv:supported_iv_BE) (j0_BE length_quad32 hash mac:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma
(requires
is_aes_key_word alg key /\
length plain < pow2_32 /\
length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth) /\
length_quad32 == two_two_to_four (Mktwo (nat_to_two 32 (8 * length auth)) (nat_to_two 32 (8 * length plain))) /\
(let auth_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits auth) in
let cipher_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits cipher) in
hash == ghash_BE h_BE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\
be_quad32_to_bytes mac == gctr_encrypt j0_BE (be_quad32_to_bytes hash) alg key)
))
(ensures be_quad32_to_bytes mac == snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth))
=
gcm_encrypt_BE_reveal ()
#reset-options "--z3rlimit 10"
let gcm_blocks_helper_enc (alg:algorithm) (key:seq nat32)
(p128 p_bytes c128 c_bytes:seq quad32)
(auth_bytes:seq nat8)
(p_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
(length auth_bytes) < pow2_32 /\
is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\
(let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2
)))
(ensures (let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
//cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key))
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes)))
=
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
gctr_partial_opaque_completed alg plain cipher key ctr_BE_2;
if p_num_bytes > length p128 * 16 then (
gctr_partial_reveal ();
assert (gctr_partial alg (length p128) plain cipher key ctr_BE_2);
assert (equal (slice plain 0 (length p128))
(slice p128 0 (length p128)));
assert (equal (slice cipher 0 (length p128))
(slice c128 0 (length p128)));
gctr_partial_opaque_ignores_postfix
alg (length p128)
plain p128
cipher c128
key ctr_BE_2;
assert (gctr_partial alg (length p128) p128 c128 key ctr_BE_2);
gctr_partial_opaque_completed alg p128 c128 key ctr_BE_2;
let num_blocks = p_num_bytes / 16 in
assert(index cipher num_blocks == quad32_xor (index plain num_blocks) (aes_encrypt_word alg key (inc32 ctr_BE_2 num_blocks)));
gctr_encrypt_block_offset ctr_BE_2 (index plain num_blocks) alg key num_blocks;
assert( gctr_encrypt_block ctr_BE_2 (index plain num_blocks) alg key num_blocks ==
gctr_encrypt_block (inc32 ctr_BE_2 num_blocks) (index plain num_blocks) alg key 0);
aes_encrypt_word_reveal ();
gctr_partial_to_full_advanced ctr_BE_2 plain cipher alg key p_num_bytes;
assert (cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key)
) else (
gctr_partial_to_full_basic ctr_BE_2 plain alg key cipher;
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher) == gctr_encrypt ctr_BE_2 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) alg key);
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
assert (equal plain_bytes (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)));
assert (equal cipher_bytes (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)));
assert (cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key)
);
gcm_encrypt_BE_fst_helper iv ctr_BE_2 j0_BE plain_bytes auth_bytes cipher_bytes alg key;
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.GHash_BE_s.fst.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.GCM_BE_s.fst.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_BE.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.Seq.Base.seq a -> y: FStar.Seq.Base.seq a -> i: Prims.nat
-> FStar.Pervasives.Lemma
(requires
FStar.Seq.Base.length x <= i /\ i <= FStar.Seq.Base.length x + FStar.Seq.Base.length y)
(ensures
FStar.Seq.Base.slice (FStar.Seq.Base.append x y) 0 i ==
FStar.Seq.Base.append x (FStar.Seq.Base.slice y 0 (i - FStar.Seq.Base.length x))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.slice",
"FStar.Seq.Base.append",
"Prims.op_Subtraction",
"FStar.Seq.Base.length",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Prims.squash",
"Prims.eq2",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let slice_append_back (#a: Type) (x y: seq a) (i: nat)
: Lemma (requires length x <= i /\ i <= length x + length y)
(ensures slice (append x y) 0 i == append x (slice y 0 (i - length x))) =
| assert (equal (slice (append x y) 0 i) (append x (slice y 0 (i - length x))));
() | false |
Vale.AES.GCM_BE.fst | Vale.AES.GCM_BE.lemma_be_seq_quad32_to_bytes_prefix_equality | val lemma_be_seq_quad32_to_bytes_prefix_equality (q: quad32)
: Lemma
(slice (be_quad32_to_bytes q) 0 12 ==
slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12) | val lemma_be_seq_quad32_to_bytes_prefix_equality (q: quad32)
: Lemma
(slice (be_quad32_to_bytes q) 0 12 ==
slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12) | let lemma_be_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma
(slice (be_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
=
assert (equal (slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
(slice (be_quad32_to_bytes q) 0 12));
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_BE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 41,
"start_col": 0,
"start_line": 36
} | module Vale.AES.GCM_BE
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.AES.GCM_BE_s
open Vale.AES.AES_BE_s
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.AES.GHash_BE_s
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open FStar.Calc
let upper3_equal (q0 q1:quad32) : bool =
q0.lo1 = q1.lo1 &&
q0.hi2 = q1.hi2 &&
q0.hi3 = q1.hi3
let lemma_be_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma
(requires slice b0 0 12 == slice b1 0 12)
(ensures upper3_equal (be_bytes_to_quad32 b0) (be_bytes_to_quad32 b1))
=
let q0 = be_bytes_to_quad32 b0 in
let q1 = be_bytes_to_quad32 b1 in
be_bytes_to_quad32_reveal ();
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #nat8);
assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\
index b1 i == index (slice b1 0 12) i)) | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.GHash_BE_s.fst.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.GCM_BE_s.fst.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_BE.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | q: Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.slice (Vale.Arch.Types.be_quad32_to_bytes q) 0 12 ==
FStar.Seq.Base.slice (Vale.AES.GCTR_BE_s.pad_to_128_bits (FStar.Seq.Base.slice (Vale.Arch.Types.be_quad32_to_bytes
q)
0
12))
0
12) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"Vale.Def.Types_s.nat8",
"FStar.Seq.Base.slice",
"Vale.AES.GCTR_BE_s.pad_to_128_bits",
"Vale.Def.Words_s.nat8",
"Vale.Arch.Types.be_quad32_to_bytes",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_be_seq_quad32_to_bytes_prefix_equality (q: quad32)
: Lemma
(slice (be_quad32_to_bytes q) 0 12 ==
slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12) =
| assert (equal (slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
(slice (be_quad32_to_bytes q) 0 12));
() | false |
CDDL.Pulse.fst | CDDL.Pulse.cbor_read_deterministically_encoded_with_typ_error_postcond_intro_typ_fail | val cbor_read_deterministically_encoded_with_typ_error_postcond_intro_typ_fail
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Lemma
(requires (cbor_read_deterministically_encoded_success_postcond va c v rem /\ t v == false))
(ensures (cbor_read_deterministically_encoded_with_typ_error_postcond t va)) | val cbor_read_deterministically_encoded_with_typ_error_postcond_intro_typ_fail
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Lemma
(requires (cbor_read_deterministically_encoded_success_postcond va c v rem /\ t v == false))
(ensures (cbor_read_deterministically_encoded_with_typ_error_postcond t va)) | let cbor_read_deterministically_encoded_with_typ_error_postcond_intro_typ_fail
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Lemma
(requires (
cbor_read_deterministically_encoded_success_postcond va c v rem /\
t v == false
))
(ensures (
cbor_read_deterministically_encoded_with_typ_error_postcond t va
))
= serialize_cbor_with_test_correct v rem (fun v' rem' -> data_item_wf deterministically_encoded_cbor_map_key_order v' == true /\ t v' == true) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Pulse.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 142,
"end_line": 530,
"start_col": 0,
"start_line": 516
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module CDDL.Pulse
open Pulse.Lib.Pervasives
open Pulse.Lib.Stick
open CBOR.Spec
open CBOR.Pulse
open CDDL.Spec
module R = Pulse.Lib.Reference
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_typ
(#b: option raw_data_item)
(t: bounded_typ_gen b)
=
(c: cbor) ->
(#p: perm) ->
(#v: Ghost.erased raw_data_item) ->
stt bool
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) b
))
(fun res -> raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) b /\
res == t v
))
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_coerce_to_bounded_typ
(b: Ghost.erased (option raw_data_item))
(#t: typ)
(f: impl_typ t)
: impl_typ #b (coerce_to_bounded_typ b t) // FIXME: WHY WHY WHY do I need to provide the implicit argument
= (c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
f c;
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_t_choice
(#b: Ghost.erased (option raw_data_item))
(#t1 #t2: bounded_typ_gen b)
(f1: impl_typ t1)
(f2: impl_typ t2)
: impl_typ #b (t_choice t1 t2)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let test = f1 c;
if (test)
{
true
} else {
f2 c
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_t_choice_none // FIXME: WHY WHY WHY can F* not automatically infer t1 and t2 by reducing (reveal (hide None)) to None?
(#t1 #t2: bounded_typ_gen None)
(f1: impl_typ t1)
(f2: impl_typ t2)
: Tot (impl_typ (t_choice t1 t2))
= impl_t_choice #None #t1 #t2 f1 f2
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_any
(_: unit)
: impl_typ #None any
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
true
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint
(_: unit)
: impl_typ #None uint
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
(mt = cbor_major_type_uint64)
}
```
module U64 = FStar.UInt64
(* FIXME: WHY WHY WHY does this one not work?
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint_literal
(n: U64.t)
: impl_typ #None (t_uint_literal n)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
if (mt = major_type_uint64) {
let i = cbor_destr_int64 c;
(i.cbor_int_value = n)
} else {
false
}
}
```
*)
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint_literal'
(n: U64.t)
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
requires
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) (None #raw_data_item)
))
returns res: bool
ensures
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) (None #raw_data_item) /\
res == t_uint_literal n v
))
{
let mt = cbor_get_major_type c;
if (mt = cbor_major_type_uint64) {
let i = cbor_destr_int64 c;
(i.cbor_int_value = n)
} else {
false
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_uint_literal
(n: U64.t)
: impl_typ (t_uint_literal n)
= impl_uint_literal' n
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_bytes
(_: unit)
: impl_typ #None bytes
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
(mt = cbor_major_type_byte_string)
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_array_group3
(#b: Ghost.erased (option raw_data_item))
(g: array_group3 b)
=
(pi: R.ref cbor_array_iterator_t) ->
(#p: perm) ->
(#i: Ghost.erased cbor_array_iterator_t) ->
(#l: Ghost.erased (list raw_data_item)) ->
stt bool
(R.pts_to pi i **
cbor_array_iterator_match p i l **
pure (opt_precedes (Ghost.reveal l) b)
)
(fun res -> exists* i' l'.
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
```pulse
ghost
fn intro_impl_array_group3_post
(#b: option raw_data_item)
(g: array_group3 b)
(pi: R.ref cbor_array_iterator_t)
(p: perm)
(i: cbor_array_iterator_t)
(l: list raw_data_item)
(res: bool)
(i': cbor_array_iterator_t)
(l': list raw_data_item)
requires
(
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
ensures
(exists* i' l'.
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
{
()
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_array_group3_concat
(#b: Ghost.erased (option raw_data_item))
(#g1: array_group3 b)
(f1: impl_array_group3 g1)
(#g2: array_group3 b)
(f2: impl_array_group3 g2)
: impl_array_group3 #b (array_group3_concat g1 g2)
=
(pi: R.ref cbor_array_iterator_t)
(#p: perm)
(#gi: Ghost.erased cbor_array_iterator_t)
(#l: Ghost.erased (list raw_data_item))
{
let test1 = f1 pi;
if (test1) {
let test2 = f2 pi;
stick_trans ();
test2
} else {
false
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_array_group3_item
(#b: Ghost.erased (option raw_data_item))
(#ty: bounded_typ_gen b)
(fty: impl_typ ty)
: impl_array_group3 #b (array_group3_item ty)
=
(pi: R.ref cbor_array_iterator_t)
(#p: perm)
(#gi: Ghost.erased cbor_array_iterator_t)
(#l: Ghost.erased (list raw_data_item))
{
let i = !pi;
rewrite (cbor_array_iterator_match p gi l) as (cbor_array_iterator_match p i l);
let is_done = cbor_array_iterator_is_done i;
rewrite (cbor_array_iterator_match p i l) as (cbor_array_iterator_match p gi l);
if (is_done) {
stick_refl0 (cbor_array_iterator_match p gi l);
intro_impl_array_group3_post (array_group3_item ty) pi p gi l false gi l; // FIXME: WHY WHY WHY? and also WHY WHY WHY here and not in the other "false" case below?
false
} else {
let c = cbor_array_iterator_next pi #p #l #gi; // FIXME: WHY WHY WHY those explicit arguments?
with gc i' l' . assert (
raw_data_item_match p c gc **
cbor_array_iterator_match p i' l' **
((raw_data_item_match p c gc ** cbor_array_iterator_match p i' l') @==> cbor_array_iterator_match p gi l)
); // this is needed for the explicit arguments to split_consume_l below
let test = fty c;
if (test) {
stick_consume_l ()
#(raw_data_item_match p c gc)
#(cbor_array_iterator_match p i' l')
#(cbor_array_iterator_match p gi l) // FIXME: WHY WHY WHY those explicit arguments? (for which the with above is needed)
;
true
} else {
elim_stick0 ()
#(raw_data_item_match p c gc ** cbor_array_iterator_match p i' l')
#(cbor_array_iterator_match p gi l); // FIXME: WHY WHY WHY those explicit arguments?
pi := i;
rewrite (R.pts_to pi i) as (R.pts_to pi gi);
stick_refl0 (cbor_array_iterator_match p gi l);
false
}
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_t_array
(#b: Ghost.erased (option raw_data_item))
(#g: (array_group3 b))
(ig: (impl_array_group3 (g)))
: impl_typ #b (t_array3 g)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let ty = cbor_get_major_type c;
if (ty = cbor_major_type_array) {
let i = cbor_array_iterator_init c;
with l . assert (cbor_array_iterator_match p i l);
rewrite (cbor_array_iterator_match p i l) as (cbor_array_iterator_match p (Ghost.reveal (Ghost.hide i)) l);
let mut pi = i;
let b_success = ig pi;
with gi' l' . assert (cbor_array_iterator_match p gi' l');
let i' = ! pi;
rewrite (cbor_array_iterator_match p gi' l') as (cbor_array_iterator_match p i' l');
let b_end = cbor_array_iterator_is_done i';
rewrite (cbor_array_iterator_match p i' l') as (cbor_array_iterator_match p gi' l');
elim_stick0 ();
rewrite (cbor_array_iterator_match p (Ghost.reveal (Ghost.hide i)) l) as (cbor_array_iterator_match p i l);
elim_stick0 ();
(b_success && b_end)
} else {
false
}
}
```
module U8 = FStar.UInt8
noextract [@@noextract_to "krml"]
let cbor_read_with_typ_success_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Tot prop
=
cbor_read_success_postcond va c v rem /\
t v == true
module A = Pulse.Lib.Array
let cbor_read_with_typ_success_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
: Tot vprop
= exists* v rem.
raw_data_item_match full_perm c.cbor_read_payload v **
A.pts_to c.cbor_read_remainder #p rem **
((raw_data_item_match full_perm c.cbor_read_payload v ** A.pts_to c.cbor_read_remainder #p rem) @==>
A.pts_to a #p va) **
pure (cbor_read_with_typ_success_postcond t va c v rem)
noextract [@@noextract_to "krml"]
let cbor_read_with_typ_error_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
: Tot prop
= forall v suff .
Ghost.reveal va == serialize_cbor v `Seq.append` suff ==>
t v == false
let cbor_read_with_typ_error_postcond_intro_typ_fail
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Lemma
(requires (
cbor_read_success_postcond va c v rem /\
t v == false
))
(ensures (
cbor_read_with_typ_error_postcond t va
))
= serialize_cbor_with_test_correct v rem (fun v' rem' -> t v' == true)
let cbor_read_with_typ_error_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
: Tot vprop
= A.pts_to a #p va ** pure (cbor_read_with_typ_error_postcond t va)
let cbor_read_with_typ_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(res: cbor_read_t)
: Tot vprop
= if res.cbor_read_is_success
then cbor_read_with_typ_success_post t a p va res
else cbor_read_with_typ_error_post t a p va
module SZ = FStar.SizeT
inline_for_extraction noextract
let mk_cbor_read_error
(res: cbor_read_t)
: Tot cbor_read_t
= {res with cbor_read_is_success = false}
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn cbor_read_with_typ
(#t: typ)
(ft: impl_typ t)
(a: A.array U8.t)
(sz: SZ.t)
(#va: Ghost.erased (Seq.seq U8.t))
(#p: perm)
requires
(A.pts_to a #p va ** pure (
(SZ.v sz == Seq.length va \/ SZ.v sz == A.length a)
))
returns res: cbor_read_t
ensures cbor_read_with_typ_post t a p va res
{
let res = cbor_read a sz;
if (res.cbor_read_is_success) {
rewrite (cbor_read_post a p va res) as (cbor_read_success_post a p va res);
unfold (cbor_read_success_post a p va res);
let test = ft res.cbor_read_payload;
if (test) {
fold (cbor_read_with_typ_success_post t a p va res);
rewrite (cbor_read_with_typ_success_post t a p va res) as (cbor_read_with_typ_post t a p va res);
res
} else {
with v . assert (raw_data_item_match full_perm res.cbor_read_payload v);
with vrem . assert (A.pts_to res.cbor_read_remainder #p vrem);
cbor_read_with_typ_error_postcond_intro_typ_fail t va res v vrem;
elim_stick0 ()
#(raw_data_item_match full_perm res.cbor_read_payload v ** A.pts_to res.cbor_read_remainder #p vrem);
fold (cbor_read_with_typ_error_post t a p va);
let res = mk_cbor_read_error res;
rewrite (cbor_read_with_typ_error_post t a p va) as (cbor_read_with_typ_post t a p va res);
res
}
} else {
rewrite (cbor_read_post a p va res) as (cbor_read_error_post a p va);
unfold (cbor_read_error_post a p va);
fold (cbor_read_with_typ_error_post t a p va);
rewrite (cbor_read_with_typ_error_post t a p va) as (cbor_read_with_typ_post t a p va res);
res
}
}
```
noextract [@@noextract_to "krml"]
let cbor_read_deterministically_encoded_with_typ_success_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Tot prop
=
cbor_read_deterministically_encoded_success_postcond va c v rem /\
t v == true
noextract [@@noextract_to "krml"]
let cbor_read_deterministically_encoded_with_typ_error_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
: Tot prop
= forall v suff .
(Ghost.reveal va == serialize_cbor v `Seq.append` suff /\
data_item_wf deterministically_encoded_cbor_map_key_order v == true
) ==>
t v == false | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Stick.fsti.checked",
"Pulse.Lib.Reference.fsti.checked",
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"CDDL.Spec.fsti.checked",
"CBOR.Spec.fsti.checked",
"CBOR.Pulse.fst.checked"
],
"interface_file": false,
"source_file": "CDDL.Pulse.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Reference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "CDDL.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Stick",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t: CDDL.Spec.typ ->
va: FStar.Ghost.erased (FStar.Seq.Base.seq FStar.UInt8.t) ->
c: CBOR.Pulse.Extern.cbor_read_t ->
v: CBOR.Spec.Type.raw_data_item ->
rem: FStar.Seq.Base.seq FStar.UInt8.t
-> FStar.Pervasives.Lemma
(requires
CBOR.Pulse.Extern.cbor_read_deterministically_encoded_success_postcond va c v rem /\
t v == false)
(ensures CDDL.Pulse.cbor_read_deterministically_encoded_with_typ_error_postcond t va) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"CDDL.Spec.typ",
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"FStar.UInt8.t",
"CBOR.Pulse.Extern.cbor_read_t",
"CBOR.Spec.Type.raw_data_item",
"CBOR.Spec.serialize_cbor_with_test_correct",
"Prims.l_and",
"Prims.eq2",
"Prims.bool",
"CBOR.Spec.Type.data_item_wf",
"FStar.Ghost.reveal",
"CBOR.Spec.deterministically_encoded_cbor_map_key_order",
"Prims.prop",
"Prims.unit",
"CBOR.Pulse.Extern.cbor_read_deterministically_encoded_success_postcond",
"Prims.squash",
"CDDL.Pulse.cbor_read_deterministically_encoded_with_typ_error_postcond",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let cbor_read_deterministically_encoded_with_typ_error_postcond_intro_typ_fail
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Lemma
(requires (cbor_read_deterministically_encoded_success_postcond va c v rem /\ t v == false))
(ensures (cbor_read_deterministically_encoded_with_typ_error_postcond t va)) =
| serialize_cbor_with_test_correct v
rem
(fun v' rem' ->
data_item_wf deterministically_encoded_cbor_map_key_order v' == true /\ t v' == true) | false |
CDDL.Pulse.fst | CDDL.Pulse.cbor_read_deterministically_encoded_with_typ_success_postcond | val cbor_read_deterministically_encoded_with_typ_success_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Tot prop | val cbor_read_deterministically_encoded_with_typ_success_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Tot prop | let cbor_read_deterministically_encoded_with_typ_success_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Tot prop
=
cbor_read_deterministically_encoded_success_postcond va c v rem /\
t v == true | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Pulse.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 15,
"end_line": 503,
"start_col": 0,
"start_line": 494
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module CDDL.Pulse
open Pulse.Lib.Pervasives
open Pulse.Lib.Stick
open CBOR.Spec
open CBOR.Pulse
open CDDL.Spec
module R = Pulse.Lib.Reference
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_typ
(#b: option raw_data_item)
(t: bounded_typ_gen b)
=
(c: cbor) ->
(#p: perm) ->
(#v: Ghost.erased raw_data_item) ->
stt bool
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) b
))
(fun res -> raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) b /\
res == t v
))
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_coerce_to_bounded_typ
(b: Ghost.erased (option raw_data_item))
(#t: typ)
(f: impl_typ t)
: impl_typ #b (coerce_to_bounded_typ b t) // FIXME: WHY WHY WHY do I need to provide the implicit argument
= (c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
f c;
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_t_choice
(#b: Ghost.erased (option raw_data_item))
(#t1 #t2: bounded_typ_gen b)
(f1: impl_typ t1)
(f2: impl_typ t2)
: impl_typ #b (t_choice t1 t2)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let test = f1 c;
if (test)
{
true
} else {
f2 c
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_t_choice_none // FIXME: WHY WHY WHY can F* not automatically infer t1 and t2 by reducing (reveal (hide None)) to None?
(#t1 #t2: bounded_typ_gen None)
(f1: impl_typ t1)
(f2: impl_typ t2)
: Tot (impl_typ (t_choice t1 t2))
= impl_t_choice #None #t1 #t2 f1 f2
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_any
(_: unit)
: impl_typ #None any
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
true
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint
(_: unit)
: impl_typ #None uint
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
(mt = cbor_major_type_uint64)
}
```
module U64 = FStar.UInt64
(* FIXME: WHY WHY WHY does this one not work?
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint_literal
(n: U64.t)
: impl_typ #None (t_uint_literal n)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
if (mt = major_type_uint64) {
let i = cbor_destr_int64 c;
(i.cbor_int_value = n)
} else {
false
}
}
```
*)
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint_literal'
(n: U64.t)
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
requires
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) (None #raw_data_item)
))
returns res: bool
ensures
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) (None #raw_data_item) /\
res == t_uint_literal n v
))
{
let mt = cbor_get_major_type c;
if (mt = cbor_major_type_uint64) {
let i = cbor_destr_int64 c;
(i.cbor_int_value = n)
} else {
false
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_uint_literal
(n: U64.t)
: impl_typ (t_uint_literal n)
= impl_uint_literal' n
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_bytes
(_: unit)
: impl_typ #None bytes
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
(mt = cbor_major_type_byte_string)
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_array_group3
(#b: Ghost.erased (option raw_data_item))
(g: array_group3 b)
=
(pi: R.ref cbor_array_iterator_t) ->
(#p: perm) ->
(#i: Ghost.erased cbor_array_iterator_t) ->
(#l: Ghost.erased (list raw_data_item)) ->
stt bool
(R.pts_to pi i **
cbor_array_iterator_match p i l **
pure (opt_precedes (Ghost.reveal l) b)
)
(fun res -> exists* i' l'.
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
```pulse
ghost
fn intro_impl_array_group3_post
(#b: option raw_data_item)
(g: array_group3 b)
(pi: R.ref cbor_array_iterator_t)
(p: perm)
(i: cbor_array_iterator_t)
(l: list raw_data_item)
(res: bool)
(i': cbor_array_iterator_t)
(l': list raw_data_item)
requires
(
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
ensures
(exists* i' l'.
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
{
()
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_array_group3_concat
(#b: Ghost.erased (option raw_data_item))
(#g1: array_group3 b)
(f1: impl_array_group3 g1)
(#g2: array_group3 b)
(f2: impl_array_group3 g2)
: impl_array_group3 #b (array_group3_concat g1 g2)
=
(pi: R.ref cbor_array_iterator_t)
(#p: perm)
(#gi: Ghost.erased cbor_array_iterator_t)
(#l: Ghost.erased (list raw_data_item))
{
let test1 = f1 pi;
if (test1) {
let test2 = f2 pi;
stick_trans ();
test2
} else {
false
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_array_group3_item
(#b: Ghost.erased (option raw_data_item))
(#ty: bounded_typ_gen b)
(fty: impl_typ ty)
: impl_array_group3 #b (array_group3_item ty)
=
(pi: R.ref cbor_array_iterator_t)
(#p: perm)
(#gi: Ghost.erased cbor_array_iterator_t)
(#l: Ghost.erased (list raw_data_item))
{
let i = !pi;
rewrite (cbor_array_iterator_match p gi l) as (cbor_array_iterator_match p i l);
let is_done = cbor_array_iterator_is_done i;
rewrite (cbor_array_iterator_match p i l) as (cbor_array_iterator_match p gi l);
if (is_done) {
stick_refl0 (cbor_array_iterator_match p gi l);
intro_impl_array_group3_post (array_group3_item ty) pi p gi l false gi l; // FIXME: WHY WHY WHY? and also WHY WHY WHY here and not in the other "false" case below?
false
} else {
let c = cbor_array_iterator_next pi #p #l #gi; // FIXME: WHY WHY WHY those explicit arguments?
with gc i' l' . assert (
raw_data_item_match p c gc **
cbor_array_iterator_match p i' l' **
((raw_data_item_match p c gc ** cbor_array_iterator_match p i' l') @==> cbor_array_iterator_match p gi l)
); // this is needed for the explicit arguments to split_consume_l below
let test = fty c;
if (test) {
stick_consume_l ()
#(raw_data_item_match p c gc)
#(cbor_array_iterator_match p i' l')
#(cbor_array_iterator_match p gi l) // FIXME: WHY WHY WHY those explicit arguments? (for which the with above is needed)
;
true
} else {
elim_stick0 ()
#(raw_data_item_match p c gc ** cbor_array_iterator_match p i' l')
#(cbor_array_iterator_match p gi l); // FIXME: WHY WHY WHY those explicit arguments?
pi := i;
rewrite (R.pts_to pi i) as (R.pts_to pi gi);
stick_refl0 (cbor_array_iterator_match p gi l);
false
}
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_t_array
(#b: Ghost.erased (option raw_data_item))
(#g: (array_group3 b))
(ig: (impl_array_group3 (g)))
: impl_typ #b (t_array3 g)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let ty = cbor_get_major_type c;
if (ty = cbor_major_type_array) {
let i = cbor_array_iterator_init c;
with l . assert (cbor_array_iterator_match p i l);
rewrite (cbor_array_iterator_match p i l) as (cbor_array_iterator_match p (Ghost.reveal (Ghost.hide i)) l);
let mut pi = i;
let b_success = ig pi;
with gi' l' . assert (cbor_array_iterator_match p gi' l');
let i' = ! pi;
rewrite (cbor_array_iterator_match p gi' l') as (cbor_array_iterator_match p i' l');
let b_end = cbor_array_iterator_is_done i';
rewrite (cbor_array_iterator_match p i' l') as (cbor_array_iterator_match p gi' l');
elim_stick0 ();
rewrite (cbor_array_iterator_match p (Ghost.reveal (Ghost.hide i)) l) as (cbor_array_iterator_match p i l);
elim_stick0 ();
(b_success && b_end)
} else {
false
}
}
```
module U8 = FStar.UInt8
noextract [@@noextract_to "krml"]
let cbor_read_with_typ_success_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Tot prop
=
cbor_read_success_postcond va c v rem /\
t v == true
module A = Pulse.Lib.Array
let cbor_read_with_typ_success_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
: Tot vprop
= exists* v rem.
raw_data_item_match full_perm c.cbor_read_payload v **
A.pts_to c.cbor_read_remainder #p rem **
((raw_data_item_match full_perm c.cbor_read_payload v ** A.pts_to c.cbor_read_remainder #p rem) @==>
A.pts_to a #p va) **
pure (cbor_read_with_typ_success_postcond t va c v rem)
noextract [@@noextract_to "krml"]
let cbor_read_with_typ_error_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
: Tot prop
= forall v suff .
Ghost.reveal va == serialize_cbor v `Seq.append` suff ==>
t v == false
let cbor_read_with_typ_error_postcond_intro_typ_fail
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Lemma
(requires (
cbor_read_success_postcond va c v rem /\
t v == false
))
(ensures (
cbor_read_with_typ_error_postcond t va
))
= serialize_cbor_with_test_correct v rem (fun v' rem' -> t v' == true)
let cbor_read_with_typ_error_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
: Tot vprop
= A.pts_to a #p va ** pure (cbor_read_with_typ_error_postcond t va)
let cbor_read_with_typ_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(res: cbor_read_t)
: Tot vprop
= if res.cbor_read_is_success
then cbor_read_with_typ_success_post t a p va res
else cbor_read_with_typ_error_post t a p va
module SZ = FStar.SizeT
inline_for_extraction noextract
let mk_cbor_read_error
(res: cbor_read_t)
: Tot cbor_read_t
= {res with cbor_read_is_success = false}
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn cbor_read_with_typ
(#t: typ)
(ft: impl_typ t)
(a: A.array U8.t)
(sz: SZ.t)
(#va: Ghost.erased (Seq.seq U8.t))
(#p: perm)
requires
(A.pts_to a #p va ** pure (
(SZ.v sz == Seq.length va \/ SZ.v sz == A.length a)
))
returns res: cbor_read_t
ensures cbor_read_with_typ_post t a p va res
{
let res = cbor_read a sz;
if (res.cbor_read_is_success) {
rewrite (cbor_read_post a p va res) as (cbor_read_success_post a p va res);
unfold (cbor_read_success_post a p va res);
let test = ft res.cbor_read_payload;
if (test) {
fold (cbor_read_with_typ_success_post t a p va res);
rewrite (cbor_read_with_typ_success_post t a p va res) as (cbor_read_with_typ_post t a p va res);
res
} else {
with v . assert (raw_data_item_match full_perm res.cbor_read_payload v);
with vrem . assert (A.pts_to res.cbor_read_remainder #p vrem);
cbor_read_with_typ_error_postcond_intro_typ_fail t va res v vrem;
elim_stick0 ()
#(raw_data_item_match full_perm res.cbor_read_payload v ** A.pts_to res.cbor_read_remainder #p vrem);
fold (cbor_read_with_typ_error_post t a p va);
let res = mk_cbor_read_error res;
rewrite (cbor_read_with_typ_error_post t a p va) as (cbor_read_with_typ_post t a p va res);
res
}
} else {
rewrite (cbor_read_post a p va res) as (cbor_read_error_post a p va);
unfold (cbor_read_error_post a p va);
fold (cbor_read_with_typ_error_post t a p va);
rewrite (cbor_read_with_typ_error_post t a p va) as (cbor_read_with_typ_post t a p va res);
res
}
}
``` | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Stick.fsti.checked",
"Pulse.Lib.Reference.fsti.checked",
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"CDDL.Spec.fsti.checked",
"CBOR.Spec.fsti.checked",
"CBOR.Pulse.fst.checked"
],
"interface_file": false,
"source_file": "CDDL.Pulse.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Reference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "CDDL.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Stick",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t: CDDL.Spec.typ ->
va: FStar.Ghost.erased (FStar.Seq.Base.seq FStar.UInt8.t) ->
c: CBOR.Pulse.Extern.cbor_read_t ->
v: CBOR.Spec.Type.raw_data_item ->
rem: FStar.Seq.Base.seq FStar.UInt8.t
-> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"CDDL.Spec.typ",
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"FStar.UInt8.t",
"CBOR.Pulse.Extern.cbor_read_t",
"CBOR.Spec.Type.raw_data_item",
"Prims.l_and",
"CBOR.Pulse.Extern.cbor_read_deterministically_encoded_success_postcond",
"Prims.eq2",
"Prims.bool",
"Prims.prop"
] | [] | false | false | false | true | true | let cbor_read_deterministically_encoded_with_typ_success_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Tot prop =
| cbor_read_deterministically_encoded_success_postcond va c v rem /\ t v == true | false |
Vale.Transformers.MovMovElim.fst | Vale.Transformers.MovMovElim.mov_mov_elim_ph | val mov_mov_elim_ph : Vale.Transformers.PeepHole.pre_peephole | let mov_mov_elim_ph = {
ph = (fun is ->
if safe_mov_mov_elim is then (
let [i1; i2] = is in
Some [i2]
) else None);
input_hint = 2;
} | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.MovMovElim.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 1,
"end_line": 54,
"start_col": 0,
"start_line": 47
} | module Vale.Transformers.MovMovElim
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.InstructionReorder
open Vale.X64.InsLemmas
open Vale.Transformers.PeepHole
(*
* AR: this proof relies on multiple inductive type inversions to know that
* oprs1 is a Mov64 (resp. for oprs2)
*
* this used to go through earlier with just ifuel 1, because F* was weakening
* the branch VCs with discriminator expressions, thereby unintentionally
* triggering the inversions, this is no longer true in F*, and hence more ifuel
*)
#push-options "--ifuel 4"
let safe_mov_mov_elim (is:list ins) : Tot bool =
match is with
| [Instr i1 oprs1 (AnnotateMov64 ()); Instr i2 oprs2 (AnnotateMov64 ())] ->
let oprs1:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs1 in
let oprs2:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs2 in
let (dst1, (src1, ())) = oprs1 in
let (dst2, (src2, ())) = oprs2 in
dst1 = dst2 && OReg? dst1 && (
let OReg rd = dst1 in
match src2 with
| OConst _ -> true
| OReg rs2 -> not (rs2 = rd)
| OStack (m, _) | OMem (m, _) ->
match m with
| MConst _ -> true
| _ -> false // TODO: Can we relax this restriction?
)
| _ -> false
#pop-options | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.InsLemmas.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.PeepHole.fsti.checked",
"Vale.Transformers.InstructionReorder.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Transformers.MovMovElim.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Transformers.PeepHole",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers.InstructionReorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Vale.Transformers.PeepHole.pre_peephole | Prims.Tot | [
"total"
] | [] | [
"Vale.Transformers.PeepHole.Mkpre_peephole",
"Prims.list",
"Vale.X64.Machine_Semantics_s.ins",
"Vale.Transformers.MovMovElim.safe_mov_mov_elim",
"FStar.Pervasives.Native.Some",
"Prims.Cons",
"Prims.Nil",
"FStar.Pervasives.Native.option",
"Prims.bool",
"FStar.Pervasives.Native.None"
] | [] | false | false | false | true | false | let mov_mov_elim_ph =
| {
ph
=
(fun is ->
if safe_mov_mov_elim is
then
(let [i1 ; i2] = is in
Some [i2])
else None);
input_hint = 2
} | false |
|
CDDL.Pulse.fst | CDDL.Pulse.cbor_read_with_typ_error_postcond_intro_typ_fail | val cbor_read_with_typ_error_postcond_intro_typ_fail
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Lemma (requires (cbor_read_success_postcond va c v rem /\ t v == false))
(ensures (cbor_read_with_typ_error_postcond t va)) | val cbor_read_with_typ_error_postcond_intro_typ_fail
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Lemma (requires (cbor_read_success_postcond va c v rem /\ t v == false))
(ensures (cbor_read_with_typ_error_postcond t va)) | let cbor_read_with_typ_error_postcond_intro_typ_fail
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Lemma
(requires (
cbor_read_success_postcond va c v rem /\
t v == false
))
(ensures (
cbor_read_with_typ_error_postcond t va
))
= serialize_cbor_with_test_correct v rem (fun v' rem' -> t v' == true) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Pulse.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 70,
"end_line": 419,
"start_col": 0,
"start_line": 405
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module CDDL.Pulse
open Pulse.Lib.Pervasives
open Pulse.Lib.Stick
open CBOR.Spec
open CBOR.Pulse
open CDDL.Spec
module R = Pulse.Lib.Reference
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_typ
(#b: option raw_data_item)
(t: bounded_typ_gen b)
=
(c: cbor) ->
(#p: perm) ->
(#v: Ghost.erased raw_data_item) ->
stt bool
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) b
))
(fun res -> raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) b /\
res == t v
))
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_coerce_to_bounded_typ
(b: Ghost.erased (option raw_data_item))
(#t: typ)
(f: impl_typ t)
: impl_typ #b (coerce_to_bounded_typ b t) // FIXME: WHY WHY WHY do I need to provide the implicit argument
= (c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
f c;
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_t_choice
(#b: Ghost.erased (option raw_data_item))
(#t1 #t2: bounded_typ_gen b)
(f1: impl_typ t1)
(f2: impl_typ t2)
: impl_typ #b (t_choice t1 t2)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let test = f1 c;
if (test)
{
true
} else {
f2 c
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_t_choice_none // FIXME: WHY WHY WHY can F* not automatically infer t1 and t2 by reducing (reveal (hide None)) to None?
(#t1 #t2: bounded_typ_gen None)
(f1: impl_typ t1)
(f2: impl_typ t2)
: Tot (impl_typ (t_choice t1 t2))
= impl_t_choice #None #t1 #t2 f1 f2
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_any
(_: unit)
: impl_typ #None any
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
true
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint
(_: unit)
: impl_typ #None uint
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
(mt = cbor_major_type_uint64)
}
```
module U64 = FStar.UInt64
(* FIXME: WHY WHY WHY does this one not work?
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint_literal
(n: U64.t)
: impl_typ #None (t_uint_literal n)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
if (mt = major_type_uint64) {
let i = cbor_destr_int64 c;
(i.cbor_int_value = n)
} else {
false
}
}
```
*)
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint_literal'
(n: U64.t)
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
requires
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) (None #raw_data_item)
))
returns res: bool
ensures
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) (None #raw_data_item) /\
res == t_uint_literal n v
))
{
let mt = cbor_get_major_type c;
if (mt = cbor_major_type_uint64) {
let i = cbor_destr_int64 c;
(i.cbor_int_value = n)
} else {
false
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_uint_literal
(n: U64.t)
: impl_typ (t_uint_literal n)
= impl_uint_literal' n
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_bytes
(_: unit)
: impl_typ #None bytes
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
(mt = cbor_major_type_byte_string)
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_array_group3
(#b: Ghost.erased (option raw_data_item))
(g: array_group3 b)
=
(pi: R.ref cbor_array_iterator_t) ->
(#p: perm) ->
(#i: Ghost.erased cbor_array_iterator_t) ->
(#l: Ghost.erased (list raw_data_item)) ->
stt bool
(R.pts_to pi i **
cbor_array_iterator_match p i l **
pure (opt_precedes (Ghost.reveal l) b)
)
(fun res -> exists* i' l'.
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
```pulse
ghost
fn intro_impl_array_group3_post
(#b: option raw_data_item)
(g: array_group3 b)
(pi: R.ref cbor_array_iterator_t)
(p: perm)
(i: cbor_array_iterator_t)
(l: list raw_data_item)
(res: bool)
(i': cbor_array_iterator_t)
(l': list raw_data_item)
requires
(
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
ensures
(exists* i' l'.
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
{
()
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_array_group3_concat
(#b: Ghost.erased (option raw_data_item))
(#g1: array_group3 b)
(f1: impl_array_group3 g1)
(#g2: array_group3 b)
(f2: impl_array_group3 g2)
: impl_array_group3 #b (array_group3_concat g1 g2)
=
(pi: R.ref cbor_array_iterator_t)
(#p: perm)
(#gi: Ghost.erased cbor_array_iterator_t)
(#l: Ghost.erased (list raw_data_item))
{
let test1 = f1 pi;
if (test1) {
let test2 = f2 pi;
stick_trans ();
test2
} else {
false
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_array_group3_item
(#b: Ghost.erased (option raw_data_item))
(#ty: bounded_typ_gen b)
(fty: impl_typ ty)
: impl_array_group3 #b (array_group3_item ty)
=
(pi: R.ref cbor_array_iterator_t)
(#p: perm)
(#gi: Ghost.erased cbor_array_iterator_t)
(#l: Ghost.erased (list raw_data_item))
{
let i = !pi;
rewrite (cbor_array_iterator_match p gi l) as (cbor_array_iterator_match p i l);
let is_done = cbor_array_iterator_is_done i;
rewrite (cbor_array_iterator_match p i l) as (cbor_array_iterator_match p gi l);
if (is_done) {
stick_refl0 (cbor_array_iterator_match p gi l);
intro_impl_array_group3_post (array_group3_item ty) pi p gi l false gi l; // FIXME: WHY WHY WHY? and also WHY WHY WHY here and not in the other "false" case below?
false
} else {
let c = cbor_array_iterator_next pi #p #l #gi; // FIXME: WHY WHY WHY those explicit arguments?
with gc i' l' . assert (
raw_data_item_match p c gc **
cbor_array_iterator_match p i' l' **
((raw_data_item_match p c gc ** cbor_array_iterator_match p i' l') @==> cbor_array_iterator_match p gi l)
); // this is needed for the explicit arguments to split_consume_l below
let test = fty c;
if (test) {
stick_consume_l ()
#(raw_data_item_match p c gc)
#(cbor_array_iterator_match p i' l')
#(cbor_array_iterator_match p gi l) // FIXME: WHY WHY WHY those explicit arguments? (for which the with above is needed)
;
true
} else {
elim_stick0 ()
#(raw_data_item_match p c gc ** cbor_array_iterator_match p i' l')
#(cbor_array_iterator_match p gi l); // FIXME: WHY WHY WHY those explicit arguments?
pi := i;
rewrite (R.pts_to pi i) as (R.pts_to pi gi);
stick_refl0 (cbor_array_iterator_match p gi l);
false
}
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_t_array
(#b: Ghost.erased (option raw_data_item))
(#g: (array_group3 b))
(ig: (impl_array_group3 (g)))
: impl_typ #b (t_array3 g)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let ty = cbor_get_major_type c;
if (ty = cbor_major_type_array) {
let i = cbor_array_iterator_init c;
with l . assert (cbor_array_iterator_match p i l);
rewrite (cbor_array_iterator_match p i l) as (cbor_array_iterator_match p (Ghost.reveal (Ghost.hide i)) l);
let mut pi = i;
let b_success = ig pi;
with gi' l' . assert (cbor_array_iterator_match p gi' l');
let i' = ! pi;
rewrite (cbor_array_iterator_match p gi' l') as (cbor_array_iterator_match p i' l');
let b_end = cbor_array_iterator_is_done i';
rewrite (cbor_array_iterator_match p i' l') as (cbor_array_iterator_match p gi' l');
elim_stick0 ();
rewrite (cbor_array_iterator_match p (Ghost.reveal (Ghost.hide i)) l) as (cbor_array_iterator_match p i l);
elim_stick0 ();
(b_success && b_end)
} else {
false
}
}
```
module U8 = FStar.UInt8
noextract [@@noextract_to "krml"]
let cbor_read_with_typ_success_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Tot prop
=
cbor_read_success_postcond va c v rem /\
t v == true
module A = Pulse.Lib.Array
let cbor_read_with_typ_success_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
: Tot vprop
= exists* v rem.
raw_data_item_match full_perm c.cbor_read_payload v **
A.pts_to c.cbor_read_remainder #p rem **
((raw_data_item_match full_perm c.cbor_read_payload v ** A.pts_to c.cbor_read_remainder #p rem) @==>
A.pts_to a #p va) **
pure (cbor_read_with_typ_success_postcond t va c v rem)
noextract [@@noextract_to "krml"]
let cbor_read_with_typ_error_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
: Tot prop
= forall v suff .
Ghost.reveal va == serialize_cbor v `Seq.append` suff ==>
t v == false | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Stick.fsti.checked",
"Pulse.Lib.Reference.fsti.checked",
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"CDDL.Spec.fsti.checked",
"CBOR.Spec.fsti.checked",
"CBOR.Pulse.fst.checked"
],
"interface_file": false,
"source_file": "CDDL.Pulse.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Lib.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Reference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "CDDL.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Stick",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t: CDDL.Spec.typ ->
va: FStar.Ghost.erased (FStar.Seq.Base.seq FStar.UInt8.t) ->
c: CBOR.Pulse.Extern.cbor_read_t ->
v: CBOR.Spec.Type.raw_data_item ->
rem: FStar.Seq.Base.seq FStar.UInt8.t
-> FStar.Pervasives.Lemma
(requires CBOR.Pulse.Extern.cbor_read_success_postcond va c v rem /\ t v == false)
(ensures CDDL.Pulse.cbor_read_with_typ_error_postcond t va) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"CDDL.Spec.typ",
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"FStar.UInt8.t",
"CBOR.Pulse.Extern.cbor_read_t",
"CBOR.Spec.Type.raw_data_item",
"CBOR.Spec.serialize_cbor_with_test_correct",
"Prims.eq2",
"Prims.bool",
"Prims.prop",
"Prims.unit",
"Prims.l_and",
"CBOR.Pulse.Extern.cbor_read_success_postcond",
"Prims.squash",
"CDDL.Pulse.cbor_read_with_typ_error_postcond",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let cbor_read_with_typ_error_postcond_intro_typ_fail
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Lemma (requires (cbor_read_success_postcond va c v rem /\ t v == false))
(ensures (cbor_read_with_typ_error_postcond t va)) =
| serialize_cbor_with_test_correct v rem (fun v' rem' -> t v' == true) | false |
Vale.AES.GCM_BE.fst | Vale.AES.GCM_BE.gcm_encrypt_BE_snd_helper | val gcm_encrypt_BE_snd_helper
(iv: supported_iv_BE)
(j0_BE length_quad32 hash mac: quad32)
(plain auth cipher: seq nat8)
(alg: algorithm)
(key: seq nat32)
: Lemma
(requires
is_aes_key_word alg key /\ length plain < pow2_32 /\ length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth) /\
length_quad32 ==
two_two_to_four (Mktwo (nat_to_two 32 (8 * length auth))
(nat_to_two 32 (8 * length plain))) /\
(let auth_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits auth) in
let cipher_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits cipher) in
hash ==
ghash_BE h_BE
(append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\
be_quad32_to_bytes mac == gctr_encrypt j0_BE (be_quad32_to_bytes hash) alg key)))
(ensures
be_quad32_to_bytes mac ==
snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth)) | val gcm_encrypt_BE_snd_helper
(iv: supported_iv_BE)
(j0_BE length_quad32 hash mac: quad32)
(plain auth cipher: seq nat8)
(alg: algorithm)
(key: seq nat32)
: Lemma
(requires
is_aes_key_word alg key /\ length plain < pow2_32 /\ length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth) /\
length_quad32 ==
two_two_to_four (Mktwo (nat_to_two 32 (8 * length auth))
(nat_to_two 32 (8 * length plain))) /\
(let auth_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits auth) in
let cipher_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits cipher) in
hash ==
ghash_BE h_BE
(append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\
be_quad32_to_bytes mac == gctr_encrypt j0_BE (be_quad32_to_bytes hash) alg key)))
(ensures
be_quad32_to_bytes mac ==
snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth)) | let gcm_encrypt_BE_snd_helper (iv:supported_iv_BE) (j0_BE length_quad32 hash mac:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma
(requires
is_aes_key_word alg key /\
length plain < pow2_32 /\
length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth) /\
length_quad32 == two_two_to_four (Mktwo (nat_to_two 32 (8 * length auth)) (nat_to_two 32 (8 * length plain))) /\
(let auth_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits auth) in
let cipher_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits cipher) in
hash == ghash_BE h_BE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\
be_quad32_to_bytes mac == gctr_encrypt j0_BE (be_quad32_to_bytes hash) alg key)
))
(ensures be_quad32_to_bytes mac == snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth))
=
gcm_encrypt_BE_reveal () | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_BE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 143,
"start_col": 0,
"start_line": 127
} | module Vale.AES.GCM_BE
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.AES.GCM_BE_s
open Vale.AES.AES_BE_s
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.AES.GHash_BE_s
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open FStar.Calc
let upper3_equal (q0 q1:quad32) : bool =
q0.lo1 = q1.lo1 &&
q0.hi2 = q1.hi2 &&
q0.hi3 = q1.hi3
let lemma_be_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma
(requires slice b0 0 12 == slice b1 0 12)
(ensures upper3_equal (be_bytes_to_quad32 b0) (be_bytes_to_quad32 b1))
=
let q0 = be_bytes_to_quad32 b0 in
let q1 = be_bytes_to_quad32 b1 in
be_bytes_to_quad32_reveal ();
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #nat8);
assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\
index b1 i == index (slice b1 0 12) i))
let lemma_be_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma
(slice (be_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
=
assert (equal (slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
(slice (be_quad32_to_bytes q) 0 12));
()
let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_BE) (num_bytes:nat64) (h_BE j0:quad32) : Lemma
(requires
length iv_extra_b == 1 /\
length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\
num_bytes == 96/8 /\
(let iv_BE = index iv_extra_b 0 in
j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\
(let raw_quads = append iv_b iv_extra_b in
let iv_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 num_bytes in
iv_bytes == iv))
(ensures j0 == compute_iv_BE h_BE iv)
=
assert (length iv == 12);
assert (length iv_b == 0);
lemma_empty iv_b;
append_empty_l iv_extra_b;
assert (append iv_b iv_extra_b == iv_extra_b);
let q = index iv_extra_b 0 in
be_seq_quad32_to_bytes_of_singleton q;
assert (equal iv_extra_b (create 1 q));
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b) == be_quad32_to_bytes q);
calc (==) {
slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12;
== {}
slice (pad_to_128_bits iv) 0 12;
};
calc (==) {
be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b)) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits iv);
};
calc (==) {
j0;
== {}
set_to_one q;
== { be_bytes_to_quad32_to_bytes q }
set_to_one (be_bytes_to_quad32 (be_quad32_to_bytes q));
== {
lemma_be_seq_quad32_to_bytes_prefix_equality q;
lemma_be_bytes_to_quad32_prefix_equality
(be_quad32_to_bytes q)
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
}
set_to_one (be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)));
== { lemma_be_bytes_to_quad32_prefix_equality
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
(pad_to_128_bits iv) }
set_to_one (be_bytes_to_quad32 (pad_to_128_bits iv));
== {compute_iv_BE_reveal ()}
compute_iv_BE h_BE iv;
};
()
let lemma_compute_iv_hard (iv:supported_iv_BE) (quads:seq quad32) (length_quad h_BE j0:quad32) : Lemma
(requires
~(length iv == 96/8) /\
quads == be_bytes_to_seq_quad32 (pad_to_128_bits iv) /\
j0 == ghash_incremental h_BE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 0)
(nat_to_two 32 (8 * length iv))))
(ensures j0 == compute_iv_BE h_BE iv)
=
ghash_incremental_to_ghash h_BE (append quads (create 1 length_quad));
compute_iv_BE_reveal ();
()
let gcm_encrypt_BE_fst_helper (iv:supported_iv_BE) (iv_enc iv_BE:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma
(requires
is_aes_key_word alg key /\
length plain < pow2_32 /\
length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
iv_enc == inc32 (compute_iv_BE h_BE iv) 1 /\
cipher == gctr_encrypt iv_enc plain alg key
))
(ensures cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth))
=
gcm_encrypt_BE_reveal () | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.GHash_BE_s.fst.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.GCM_BE_s.fst.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_BE.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
iv: Vale.AES.GCM_BE_s.supported_iv_BE ->
j0_BE: Vale.Def.Types_s.quad32 ->
length_quad32: Vale.Def.Types_s.quad32 ->
hash: Vale.Def.Types_s.quad32 ->
mac: Vale.Def.Types_s.quad32 ->
plain: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 ->
auth: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 ->
cipher: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 ->
alg: Vale.AES.AES_common_s.algorithm ->
key: FStar.Seq.Base.seq Vale.Def.Words_s.nat32
-> FStar.Pervasives.Lemma
(requires
Vale.AES.AES_BE_s.is_aes_key_word alg key /\
FStar.Seq.Base.length plain < Vale.Def.Words_s.pow2_32 /\
FStar.Seq.Base.length auth < Vale.Def.Words_s.pow2_32 /\
(let h_BE = Vale.AES.AES_BE_s.aes_encrypt_word alg key (Vale.Def.Words_s.Mkfour 0 0 0 0) in
j0_BE = Vale.AES.GCM_BE_s.compute_iv_BE h_BE iv /\
cipher ==
FStar.Pervasives.Native.fst (Vale.AES.GCM_BE_s.gcm_encrypt_BE alg
(Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE key)
iv
plain
auth) /\
length_quad32 ==
Vale.Def.Words.Four_s.two_two_to_four (Vale.Def.Words_s.Mktwo
(Vale.Def.Words.Two_s.nat_to_two 32 (8 * FStar.Seq.Base.length auth))
(Vale.Def.Words.Two_s.nat_to_two 32 (8 * FStar.Seq.Base.length plain))) /\
(let auth_padded_quads =
Vale.Def.Types_s.be_bytes_to_seq_quad32 (Vale.AES.GCTR_BE_s.pad_to_128_bits auth)
in
let cipher_padded_quads =
Vale.Def.Types_s.be_bytes_to_seq_quad32 (Vale.AES.GCTR_BE_s.pad_to_128_bits cipher)
in
hash ==
Vale.AES.GHash_BE_s.ghash_BE h_BE
(FStar.Seq.Base.append auth_padded_quads
(FStar.Seq.Base.append cipher_padded_quads (FStar.Seq.Base.create 1 length_quad32)
)) /\
Vale.Arch.Types.be_quad32_to_bytes mac ==
Vale.AES.GCTR_BE_s.gctr_encrypt j0_BE (Vale.Arch.Types.be_quad32_to_bytes hash) alg key)
))
(ensures
Vale.Arch.Types.be_quad32_to_bytes mac ==
FStar.Pervasives.Native.snd (Vale.AES.GCM_BE_s.gcm_encrypt_BE alg
(Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE key)
iv
plain
auth)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.AES.GCM_BE_s.supported_iv_BE",
"Vale.Def.Types_s.quad32",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat8",
"Vale.AES.AES_common_s.algorithm",
"Vale.Def.Words_s.nat32",
"Vale.AES.GCM_BE_s.gcm_encrypt_BE_reveal",
"Prims.unit",
"Prims.l_and",
"Vale.AES.AES_BE_s.is_aes_key_word",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Vale.Def.Words_s.pow2_32",
"Prims.op_Equality",
"Vale.AES.GCM_BE_s.compute_iv_BE",
"Prims.eq2",
"Vale.Def.Types_s.nat8",
"FStar.Pervasives.Native.fst",
"Vale.AES.GCM_BE_s.gcm_encrypt_BE",
"Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE",
"Vale.Def.Words_s.four",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Def.Words.Four_s.two_two_to_four",
"Vale.Def.Words_s.Mktwo",
"Vale.Def.Words_s.two",
"Vale.Def.Words.Two_s.nat_to_two",
"FStar.Mul.op_Star",
"Vale.AES.GHash_BE_s.ghash_BE",
"FStar.Seq.Base.append",
"FStar.Seq.Base.create",
"Vale.Arch.Types.be_quad32_to_bytes",
"Vale.AES.GCTR_BE_s.gctr_encrypt",
"Vale.Def.Types_s.be_bytes_to_seq_quad32",
"Vale.AES.GCTR_BE_s.pad_to_128_bits",
"Vale.AES.AES_BE_s.aes_encrypt_word",
"Vale.Def.Words_s.Mkfour",
"Vale.Def.Types_s.nat32",
"Prims.squash",
"FStar.Pervasives.Native.snd",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let gcm_encrypt_BE_snd_helper
(iv: supported_iv_BE)
(j0_BE length_quad32 hash mac: quad32)
(plain auth cipher: seq nat8)
(alg: algorithm)
(key: seq nat32)
: Lemma
(requires
is_aes_key_word alg key /\ length plain < pow2_32 /\ length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth) /\
length_quad32 ==
two_two_to_four (Mktwo (nat_to_two 32 (8 * length auth))
(nat_to_two 32 (8 * length plain))) /\
(let auth_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits auth) in
let cipher_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits cipher) in
hash ==
ghash_BE h_BE
(append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\
be_quad32_to_bytes mac == gctr_encrypt j0_BE (be_quad32_to_bytes hash) alg key)))
(ensures
be_quad32_to_bytes mac ==
snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth)) =
| gcm_encrypt_BE_reveal () | false |
Vale.Transformers.MovMovElim.fst | Vale.Transformers.MovMovElim.safe_mov_mov_elim | val safe_mov_mov_elim (is: list ins) : Tot bool | val safe_mov_mov_elim (is: list ins) : Tot bool | let safe_mov_mov_elim (is:list ins) : Tot bool =
match is with
| [Instr i1 oprs1 (AnnotateMov64 ()); Instr i2 oprs2 (AnnotateMov64 ())] ->
let oprs1:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs1 in
let oprs2:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs2 in
let (dst1, (src1, ())) = oprs1 in
let (dst2, (src2, ())) = oprs2 in
dst1 = dst2 && OReg? dst1 && (
let OReg rd = dst1 in
match src2 with
| OConst _ -> true
| OReg rs2 -> not (rs2 = rd)
| OStack (m, _) | OMem (m, _) ->
match m with
| MConst _ -> true
| _ -> false // TODO: Can we relax this restriction?
)
| _ -> false | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.MovMovElim.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 14,
"end_line": 44,
"start_col": 0,
"start_line": 25
} | module Vale.Transformers.MovMovElim
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.InstructionReorder
open Vale.X64.InsLemmas
open Vale.Transformers.PeepHole
(*
* AR: this proof relies on multiple inductive type inversions to know that
* oprs1 is a Mov64 (resp. for oprs2)
*
* this used to go through earlier with just ifuel 1, because F* was weakening
* the branch VCs with discriminator expressions, thereby unintentionally
* triggering the inversions, this is no longer true in F*, and hence more ifuel
*) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.InsLemmas.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.PeepHole.fsti.checked",
"Vale.Transformers.InstructionReorder.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Transformers.MovMovElim.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Transformers.PeepHole",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers.InstructionReorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 4,
"max_fuel": 1,
"max_ifuel": 4,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | is: Prims.list Vale.X64.Machine_Semantics_s.ins -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Instruction_s.instr_t_record",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args",
"Vale.X64.Machine_s.operand64",
"Prims.op_AmpAmp",
"Prims.op_Equality",
"Vale.X64.Machine_s.uu___is_OReg",
"Vale.X64.Machine_s.nat64",
"Vale.X64.Machine_s.reg_64",
"Prims.op_Negation",
"Vale.X64.Machine_s.maddr",
"Vale.Arch.HeapTypes_s.taint",
"Prims.int",
"Prims.bool",
"FStar.Pervasives.norm",
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.zeta",
"FStar.Pervasives.iota",
"FStar.Pervasives.delta_attr",
"Prims.string",
"Prims.Nil",
"Vale.X64.Instruction_s.instr_out",
"FStar.Pervasives.Native.Mktuple2",
"Vale.X64.Instruction_s.instr_operand_inout",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.Out",
"Vale.X64.Instruction_s.IOpEx",
"Vale.X64.Instruction_s.IOp64",
"Vale.Transformers.PeepHole.coerce_to_normal",
"Vale.X64.Instruction_s.out",
"Vale.X64.Instruction_s.op64"
] | [] | false | false | false | true | false | let safe_mov_mov_elim (is: list ins) : Tot bool =
| match is with
| [Instr i1 oprs1 (AnnotateMov64 ()) ; Instr i2 oprs2 (AnnotateMov64 ())] ->
let oprs1:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs1
in
let oprs2:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs2
in
let dst1, (src1, ()) = oprs1 in
let dst2, (src2, ()) = oprs2 in
dst1 = dst2 && OReg? dst1 &&
(let OReg rd = dst1 in
match src2 with
| OConst _ -> true
| OReg rs2 -> not (rs2 = rd)
| OStack (m, _)
| OMem (m, _) ->
match m with
| MConst _ -> true
| _ -> false)
| _ -> false | false |
Vale.AES.GCM_BE.fst | Vale.AES.GCM_BE.lemma_compute_iv_hard | val lemma_compute_iv_hard (iv:supported_iv_BE) (quads:seq quad32) (length_quad h_BE j0:quad32) : Lemma
(requires
~(length iv == 96/8) /\
quads == be_bytes_to_seq_quad32 (pad_to_128_bits iv) /\
j0 == ghash_incremental h_BE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 0)
(nat_to_two 32 (8 * length iv))))
(ensures j0 == compute_iv_BE h_BE iv) | val lemma_compute_iv_hard (iv:supported_iv_BE) (quads:seq quad32) (length_quad h_BE j0:quad32) : Lemma
(requires
~(length iv == 96/8) /\
quads == be_bytes_to_seq_quad32 (pad_to_128_bits iv) /\
j0 == ghash_incremental h_BE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 0)
(nat_to_two 32 (8 * length iv))))
(ensures j0 == compute_iv_BE h_BE iv) | let lemma_compute_iv_hard (iv:supported_iv_BE) (quads:seq quad32) (length_quad h_BE j0:quad32) : Lemma
(requires
~(length iv == 96/8) /\
quads == be_bytes_to_seq_quad32 (pad_to_128_bits iv) /\
j0 == ghash_incremental h_BE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 0)
(nat_to_two 32 (8 * length iv))))
(ensures j0 == compute_iv_BE h_BE iv)
=
ghash_incremental_to_ghash h_BE (append quads (create 1 length_quad));
compute_iv_BE_reveal ();
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_BE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 112,
"start_col": 0,
"start_line": 101
} | module Vale.AES.GCM_BE
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.AES.GCM_BE_s
open Vale.AES.AES_BE_s
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.AES.GHash_BE_s
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open FStar.Calc
let upper3_equal (q0 q1:quad32) : bool =
q0.lo1 = q1.lo1 &&
q0.hi2 = q1.hi2 &&
q0.hi3 = q1.hi3
let lemma_be_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma
(requires slice b0 0 12 == slice b1 0 12)
(ensures upper3_equal (be_bytes_to_quad32 b0) (be_bytes_to_quad32 b1))
=
let q0 = be_bytes_to_quad32 b0 in
let q1 = be_bytes_to_quad32 b1 in
be_bytes_to_quad32_reveal ();
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #nat8);
assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\
index b1 i == index (slice b1 0 12) i))
let lemma_be_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma
(slice (be_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
=
assert (equal (slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
(slice (be_quad32_to_bytes q) 0 12));
()
let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_BE) (num_bytes:nat64) (h_BE j0:quad32) : Lemma
(requires
length iv_extra_b == 1 /\
length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\
num_bytes == 96/8 /\
(let iv_BE = index iv_extra_b 0 in
j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\
(let raw_quads = append iv_b iv_extra_b in
let iv_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 num_bytes in
iv_bytes == iv))
(ensures j0 == compute_iv_BE h_BE iv)
=
assert (length iv == 12);
assert (length iv_b == 0);
lemma_empty iv_b;
append_empty_l iv_extra_b;
assert (append iv_b iv_extra_b == iv_extra_b);
let q = index iv_extra_b 0 in
be_seq_quad32_to_bytes_of_singleton q;
assert (equal iv_extra_b (create 1 q));
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b) == be_quad32_to_bytes q);
calc (==) {
slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12;
== {}
slice (pad_to_128_bits iv) 0 12;
};
calc (==) {
be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b)) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits iv);
};
calc (==) {
j0;
== {}
set_to_one q;
== { be_bytes_to_quad32_to_bytes q }
set_to_one (be_bytes_to_quad32 (be_quad32_to_bytes q));
== {
lemma_be_seq_quad32_to_bytes_prefix_equality q;
lemma_be_bytes_to_quad32_prefix_equality
(be_quad32_to_bytes q)
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
}
set_to_one (be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)));
== { lemma_be_bytes_to_quad32_prefix_equality
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
(pad_to_128_bits iv) }
set_to_one (be_bytes_to_quad32 (pad_to_128_bits iv));
== {compute_iv_BE_reveal ()}
compute_iv_BE h_BE iv;
};
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.GHash_BE_s.fst.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.GCM_BE_s.fst.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_BE.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
iv: Vale.AES.GCM_BE_s.supported_iv_BE ->
quads: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
length_quad: Vale.Def.Types_s.quad32 ->
h_BE: Vale.Def.Types_s.quad32 ->
j0: Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(requires
~(FStar.Seq.Base.length iv == 96 / 8) /\
quads == Vale.Def.Types_s.be_bytes_to_seq_quad32 (Vale.AES.GCTR_BE_s.pad_to_128_bits iv) /\
j0 ==
Vale.AES.GHash_BE.ghash_incremental h_BE
(Vale.Def.Words_s.Mkfour 0 0 0 0)
(FStar.Seq.Base.append quads (FStar.Seq.Base.create 1 length_quad)) /\
length_quad ==
Vale.Def.Words.Four_s.two_two_to_four (Vale.Def.Words_s.Mktwo
(Vale.Def.Words.Two_s.nat_to_two 32 0)
(Vale.Def.Words.Two_s.nat_to_two 32 (8 * FStar.Seq.Base.length iv))))
(ensures j0 == Vale.AES.GCM_BE_s.compute_iv_BE h_BE iv) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.AES.GCM_BE_s.supported_iv_BE",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.quad32",
"Prims.unit",
"Vale.AES.GCM_BE_s.compute_iv_BE_reveal",
"Vale.AES.GHash_BE.ghash_incremental_to_ghash",
"FStar.Seq.Base.append",
"FStar.Seq.Base.create",
"Prims.l_and",
"Prims.l_not",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"Vale.Def.Types_s.nat8",
"Prims.op_Division",
"Vale.Def.Types_s.be_bytes_to_seq_quad32",
"Vale.AES.GCTR_BE_s.pad_to_128_bits",
"Vale.AES.GHash_BE.ghash_incremental",
"Vale.Def.Words_s.Mkfour",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words_s.four",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Def.Words.Four_s.two_two_to_four",
"Vale.Def.Words_s.Mktwo",
"Vale.Def.Words_s.two",
"Vale.Def.Words.Two_s.nat_to_two",
"FStar.Mul.op_Star",
"Prims.squash",
"Vale.AES.GCM_BE_s.compute_iv_BE",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_compute_iv_hard (iv: supported_iv_BE) (quads: seq quad32) (length_quad h_BE j0: quad32)
: Lemma
(requires
~(length iv == 96 / 8) /\ quads == be_bytes_to_seq_quad32 (pad_to_128_bits iv) /\
j0 == ghash_incremental h_BE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 0) (nat_to_two 32 (8 * length iv))))
(ensures j0 == compute_iv_BE h_BE iv) =
| ghash_incremental_to_ghash h_BE (append quads (create 1 length_quad));
compute_iv_BE_reveal ();
() | false |
Vale.AES.GCM_BE.fst | Vale.AES.GCM_BE.pad_to_128_bits_multiple_append | val pad_to_128_bits_multiple_append (x y: seq nat8)
: Lemma (requires length x % 16 == 0)
(ensures pad_to_128_bits (append x y) == append x (pad_to_128_bits y)) | val pad_to_128_bits_multiple_append (x y: seq nat8)
: Lemma (requires length x % 16 == 0)
(ensures pad_to_128_bits (append x y) == append x (pad_to_128_bits y)) | let pad_to_128_bits_multiple_append (x y:seq nat8) : Lemma
(requires length x % 16 == 0)
(ensures pad_to_128_bits (append x y) == append x (pad_to_128_bits y))
=
assert (equal (pad_to_128_bits (append x y)) (append x (pad_to_128_bits y))) | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_BE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 78,
"end_line": 269,
"start_col": 0,
"start_line": 265
} | module Vale.AES.GCM_BE
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.AES.GCM_BE_s
open Vale.AES.AES_BE_s
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.AES.GHash_BE_s
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open FStar.Calc
let upper3_equal (q0 q1:quad32) : bool =
q0.lo1 = q1.lo1 &&
q0.hi2 = q1.hi2 &&
q0.hi3 = q1.hi3
let lemma_be_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma
(requires slice b0 0 12 == slice b1 0 12)
(ensures upper3_equal (be_bytes_to_quad32 b0) (be_bytes_to_quad32 b1))
=
let q0 = be_bytes_to_quad32 b0 in
let q1 = be_bytes_to_quad32 b1 in
be_bytes_to_quad32_reveal ();
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #nat8);
assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\
index b1 i == index (slice b1 0 12) i))
let lemma_be_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma
(slice (be_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
=
assert (equal (slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
(slice (be_quad32_to_bytes q) 0 12));
()
let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_BE) (num_bytes:nat64) (h_BE j0:quad32) : Lemma
(requires
length iv_extra_b == 1 /\
length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\
num_bytes == 96/8 /\
(let iv_BE = index iv_extra_b 0 in
j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\
(let raw_quads = append iv_b iv_extra_b in
let iv_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 num_bytes in
iv_bytes == iv))
(ensures j0 == compute_iv_BE h_BE iv)
=
assert (length iv == 12);
assert (length iv_b == 0);
lemma_empty iv_b;
append_empty_l iv_extra_b;
assert (append iv_b iv_extra_b == iv_extra_b);
let q = index iv_extra_b 0 in
be_seq_quad32_to_bytes_of_singleton q;
assert (equal iv_extra_b (create 1 q));
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b) == be_quad32_to_bytes q);
calc (==) {
slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12;
== {}
slice (pad_to_128_bits iv) 0 12;
};
calc (==) {
be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b)) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits iv);
};
calc (==) {
j0;
== {}
set_to_one q;
== { be_bytes_to_quad32_to_bytes q }
set_to_one (be_bytes_to_quad32 (be_quad32_to_bytes q));
== {
lemma_be_seq_quad32_to_bytes_prefix_equality q;
lemma_be_bytes_to_quad32_prefix_equality
(be_quad32_to_bytes q)
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
}
set_to_one (be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)));
== { lemma_be_bytes_to_quad32_prefix_equality
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
(pad_to_128_bits iv) }
set_to_one (be_bytes_to_quad32 (pad_to_128_bits iv));
== {compute_iv_BE_reveal ()}
compute_iv_BE h_BE iv;
};
()
let lemma_compute_iv_hard (iv:supported_iv_BE) (quads:seq quad32) (length_quad h_BE j0:quad32) : Lemma
(requires
~(length iv == 96/8) /\
quads == be_bytes_to_seq_quad32 (pad_to_128_bits iv) /\
j0 == ghash_incremental h_BE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 0)
(nat_to_two 32 (8 * length iv))))
(ensures j0 == compute_iv_BE h_BE iv)
=
ghash_incremental_to_ghash h_BE (append quads (create 1 length_quad));
compute_iv_BE_reveal ();
()
let gcm_encrypt_BE_fst_helper (iv:supported_iv_BE) (iv_enc iv_BE:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma
(requires
is_aes_key_word alg key /\
length plain < pow2_32 /\
length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
iv_enc == inc32 (compute_iv_BE h_BE iv) 1 /\
cipher == gctr_encrypt iv_enc plain alg key
))
(ensures cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth))
=
gcm_encrypt_BE_reveal ()
let gcm_encrypt_BE_snd_helper (iv:supported_iv_BE) (j0_BE length_quad32 hash mac:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma
(requires
is_aes_key_word alg key /\
length plain < pow2_32 /\
length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth) /\
length_quad32 == two_two_to_four (Mktwo (nat_to_two 32 (8 * length auth)) (nat_to_two 32 (8 * length plain))) /\
(let auth_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits auth) in
let cipher_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits cipher) in
hash == ghash_BE h_BE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\
be_quad32_to_bytes mac == gctr_encrypt j0_BE (be_quad32_to_bytes hash) alg key)
))
(ensures be_quad32_to_bytes mac == snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth))
=
gcm_encrypt_BE_reveal ()
#reset-options "--z3rlimit 10"
let gcm_blocks_helper_enc (alg:algorithm) (key:seq nat32)
(p128 p_bytes c128 c_bytes:seq quad32)
(auth_bytes:seq nat8)
(p_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
(length auth_bytes) < pow2_32 /\
is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\
(let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2
)))
(ensures (let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
//cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key))
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes)))
=
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
gctr_partial_opaque_completed alg plain cipher key ctr_BE_2;
if p_num_bytes > length p128 * 16 then (
gctr_partial_reveal ();
assert (gctr_partial alg (length p128) plain cipher key ctr_BE_2);
assert (equal (slice plain 0 (length p128))
(slice p128 0 (length p128)));
assert (equal (slice cipher 0 (length p128))
(slice c128 0 (length p128)));
gctr_partial_opaque_ignores_postfix
alg (length p128)
plain p128
cipher c128
key ctr_BE_2;
assert (gctr_partial alg (length p128) p128 c128 key ctr_BE_2);
gctr_partial_opaque_completed alg p128 c128 key ctr_BE_2;
let num_blocks = p_num_bytes / 16 in
assert(index cipher num_blocks == quad32_xor (index plain num_blocks) (aes_encrypt_word alg key (inc32 ctr_BE_2 num_blocks)));
gctr_encrypt_block_offset ctr_BE_2 (index plain num_blocks) alg key num_blocks;
assert( gctr_encrypt_block ctr_BE_2 (index plain num_blocks) alg key num_blocks ==
gctr_encrypt_block (inc32 ctr_BE_2 num_blocks) (index plain num_blocks) alg key 0);
aes_encrypt_word_reveal ();
gctr_partial_to_full_advanced ctr_BE_2 plain cipher alg key p_num_bytes;
assert (cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key)
) else (
gctr_partial_to_full_basic ctr_BE_2 plain alg key cipher;
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher) == gctr_encrypt ctr_BE_2 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) alg key);
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
assert (equal plain_bytes (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)));
assert (equal cipher_bytes (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)));
assert (cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key)
);
gcm_encrypt_BE_fst_helper iv ctr_BE_2 j0_BE plain_bytes auth_bytes cipher_bytes alg key;
()
let slice_append_back (#a:Type) (x y:seq a) (i:nat) : Lemma
(requires length x <= i /\ i <= length x + length y)
(ensures slice (append x y) 0 i == append x (slice y 0 (i - length x)))
=
assert (equal (slice (append x y) 0 i) (append x (slice y 0 (i - length x))));
()
let append_distributes_be_seq_quad32_to_bytes (x y:seq quad32) :
Lemma (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append x y)) == append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE x)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE y)))
=
append_distributes_be_seq_quad32_to_bytes x y | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.GHash_BE_s.fst.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.GCM_BE_s.fst.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_BE.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 -> y: FStar.Seq.Base.seq Vale.Def.Words_s.nat8
-> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length x % 16 == 0)
(ensures
Vale.AES.GCTR_BE_s.pad_to_128_bits (FStar.Seq.Base.append x y) ==
FStar.Seq.Base.append x (Vale.AES.GCTR_BE_s.pad_to_128_bits y)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat8",
"Prims._assert",
"FStar.Seq.Base.equal",
"Vale.Def.Types_s.nat8",
"Vale.AES.GCTR_BE_s.pad_to_128_bits",
"FStar.Seq.Base.append",
"Prims.unit",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"FStar.Seq.Base.length",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let pad_to_128_bits_multiple_append (x y: seq nat8)
: Lemma (requires length x % 16 == 0)
(ensures pad_to_128_bits (append x y) == append x (pad_to_128_bits y)) =
| assert (equal (pad_to_128_bits (append x y)) (append x (pad_to_128_bits y))) | false |
Vale.AES.GCM_BE.fst | Vale.AES.GCM_BE.lemma_gcm_encrypt_decrypt_equiv | val lemma_gcm_encrypt_decrypt_equiv
(alg: algorithm)
(key: seq nat32)
(iv: supported_iv_BE)
(j0_BE: quad32)
(plain cipher auth alleged_tag: seq nat8)
: Lemma
(requires
is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv) /\ length cipher < pow2_32 /\ length auth < pow2_32 /\
plain == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv cipher auth))
(ensures
plain == fst (gcm_decrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv cipher auth alleged_tag)) | val lemma_gcm_encrypt_decrypt_equiv
(alg: algorithm)
(key: seq nat32)
(iv: supported_iv_BE)
(j0_BE: quad32)
(plain cipher auth alleged_tag: seq nat8)
: Lemma
(requires
is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv) /\ length cipher < pow2_32 /\ length auth < pow2_32 /\
plain == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv cipher auth))
(ensures
plain == fst (gcm_decrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv cipher auth alleged_tag)) | let lemma_gcm_encrypt_decrypt_equiv (alg:algorithm) (key:seq nat32) (iv:supported_iv_BE) (j0_BE:quad32) (plain cipher auth alleged_tag:seq nat8) : Lemma
(requires
is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv) /\
length cipher < pow2_32 /\
length auth < pow2_32 /\
plain == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv cipher auth)
)
(ensures plain == fst (gcm_decrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv cipher auth alleged_tag))
=
gcm_encrypt_BE_reveal ();
gcm_decrypt_BE_reveal ();
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_BE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 650,
"start_col": 0,
"start_line": 637
} | module Vale.AES.GCM_BE
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.AES.GCM_BE_s
open Vale.AES.AES_BE_s
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.AES.GHash_BE_s
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open FStar.Calc
let upper3_equal (q0 q1:quad32) : bool =
q0.lo1 = q1.lo1 &&
q0.hi2 = q1.hi2 &&
q0.hi3 = q1.hi3
let lemma_be_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma
(requires slice b0 0 12 == slice b1 0 12)
(ensures upper3_equal (be_bytes_to_quad32 b0) (be_bytes_to_quad32 b1))
=
let q0 = be_bytes_to_quad32 b0 in
let q1 = be_bytes_to_quad32 b1 in
be_bytes_to_quad32_reveal ();
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #nat8);
assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\
index b1 i == index (slice b1 0 12) i))
let lemma_be_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma
(slice (be_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
=
assert (equal (slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
(slice (be_quad32_to_bytes q) 0 12));
()
let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_BE) (num_bytes:nat64) (h_BE j0:quad32) : Lemma
(requires
length iv_extra_b == 1 /\
length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\
num_bytes == 96/8 /\
(let iv_BE = index iv_extra_b 0 in
j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\
(let raw_quads = append iv_b iv_extra_b in
let iv_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 num_bytes in
iv_bytes == iv))
(ensures j0 == compute_iv_BE h_BE iv)
=
assert (length iv == 12);
assert (length iv_b == 0);
lemma_empty iv_b;
append_empty_l iv_extra_b;
assert (append iv_b iv_extra_b == iv_extra_b);
let q = index iv_extra_b 0 in
be_seq_quad32_to_bytes_of_singleton q;
assert (equal iv_extra_b (create 1 q));
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b) == be_quad32_to_bytes q);
calc (==) {
slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12;
== {}
slice (pad_to_128_bits iv) 0 12;
};
calc (==) {
be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b)) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits iv);
};
calc (==) {
j0;
== {}
set_to_one q;
== { be_bytes_to_quad32_to_bytes q }
set_to_one (be_bytes_to_quad32 (be_quad32_to_bytes q));
== {
lemma_be_seq_quad32_to_bytes_prefix_equality q;
lemma_be_bytes_to_quad32_prefix_equality
(be_quad32_to_bytes q)
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
}
set_to_one (be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)));
== { lemma_be_bytes_to_quad32_prefix_equality
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
(pad_to_128_bits iv) }
set_to_one (be_bytes_to_quad32 (pad_to_128_bits iv));
== {compute_iv_BE_reveal ()}
compute_iv_BE h_BE iv;
};
()
let lemma_compute_iv_hard (iv:supported_iv_BE) (quads:seq quad32) (length_quad h_BE j0:quad32) : Lemma
(requires
~(length iv == 96/8) /\
quads == be_bytes_to_seq_quad32 (pad_to_128_bits iv) /\
j0 == ghash_incremental h_BE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 0)
(nat_to_two 32 (8 * length iv))))
(ensures j0 == compute_iv_BE h_BE iv)
=
ghash_incremental_to_ghash h_BE (append quads (create 1 length_quad));
compute_iv_BE_reveal ();
()
let gcm_encrypt_BE_fst_helper (iv:supported_iv_BE) (iv_enc iv_BE:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma
(requires
is_aes_key_word alg key /\
length plain < pow2_32 /\
length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
iv_enc == inc32 (compute_iv_BE h_BE iv) 1 /\
cipher == gctr_encrypt iv_enc plain alg key
))
(ensures cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth))
=
gcm_encrypt_BE_reveal ()
let gcm_encrypt_BE_snd_helper (iv:supported_iv_BE) (j0_BE length_quad32 hash mac:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma
(requires
is_aes_key_word alg key /\
length plain < pow2_32 /\
length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth) /\
length_quad32 == two_two_to_four (Mktwo (nat_to_two 32 (8 * length auth)) (nat_to_two 32 (8 * length plain))) /\
(let auth_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits auth) in
let cipher_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits cipher) in
hash == ghash_BE h_BE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\
be_quad32_to_bytes mac == gctr_encrypt j0_BE (be_quad32_to_bytes hash) alg key)
))
(ensures be_quad32_to_bytes mac == snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth))
=
gcm_encrypt_BE_reveal ()
#reset-options "--z3rlimit 10"
let gcm_blocks_helper_enc (alg:algorithm) (key:seq nat32)
(p128 p_bytes c128 c_bytes:seq quad32)
(auth_bytes:seq nat8)
(p_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
(length auth_bytes) < pow2_32 /\
is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\
(let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2
)))
(ensures (let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
//cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key))
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes)))
=
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
gctr_partial_opaque_completed alg plain cipher key ctr_BE_2;
if p_num_bytes > length p128 * 16 then (
gctr_partial_reveal ();
assert (gctr_partial alg (length p128) plain cipher key ctr_BE_2);
assert (equal (slice plain 0 (length p128))
(slice p128 0 (length p128)));
assert (equal (slice cipher 0 (length p128))
(slice c128 0 (length p128)));
gctr_partial_opaque_ignores_postfix
alg (length p128)
plain p128
cipher c128
key ctr_BE_2;
assert (gctr_partial alg (length p128) p128 c128 key ctr_BE_2);
gctr_partial_opaque_completed alg p128 c128 key ctr_BE_2;
let num_blocks = p_num_bytes / 16 in
assert(index cipher num_blocks == quad32_xor (index plain num_blocks) (aes_encrypt_word alg key (inc32 ctr_BE_2 num_blocks)));
gctr_encrypt_block_offset ctr_BE_2 (index plain num_blocks) alg key num_blocks;
assert( gctr_encrypt_block ctr_BE_2 (index plain num_blocks) alg key num_blocks ==
gctr_encrypt_block (inc32 ctr_BE_2 num_blocks) (index plain num_blocks) alg key 0);
aes_encrypt_word_reveal ();
gctr_partial_to_full_advanced ctr_BE_2 plain cipher alg key p_num_bytes;
assert (cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key)
) else (
gctr_partial_to_full_basic ctr_BE_2 plain alg key cipher;
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher) == gctr_encrypt ctr_BE_2 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) alg key);
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
assert (equal plain_bytes (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)));
assert (equal cipher_bytes (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)));
assert (cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key)
);
gcm_encrypt_BE_fst_helper iv ctr_BE_2 j0_BE plain_bytes auth_bytes cipher_bytes alg key;
()
let slice_append_back (#a:Type) (x y:seq a) (i:nat) : Lemma
(requires length x <= i /\ i <= length x + length y)
(ensures slice (append x y) 0 i == append x (slice y 0 (i - length x)))
=
assert (equal (slice (append x y) 0 i) (append x (slice y 0 (i - length x))));
()
let append_distributes_be_seq_quad32_to_bytes (x y:seq quad32) :
Lemma (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append x y)) == append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE x)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE y)))
=
append_distributes_be_seq_quad32_to_bytes x y
let pad_to_128_bits_multiple_append (x y:seq nat8) : Lemma
(requires length x % 16 == 0)
(ensures pad_to_128_bits (append x y) == append x (pad_to_128_bits y))
=
assert (equal (pad_to_128_bits (append x y)) (append x (pad_to_128_bits y)))
#reset-options "--z3rlimit 100"
let gcm_blocks_helper (alg:algorithm) (key:seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes:seq quad32)
(p_num_bytes a_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE h enc_hash length_quad:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\
a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
length a_bytes == 1 /\
is_aes_key_word alg key /\
j0_BE = compute_iv_BE h iv /\
h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads c_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0
)))
(ensures (let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let plain_raw_quads =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else p128
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes) /\
be_quad32_to_bytes enc_hash ==
snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key)
iv plain_bytes auth_bytes)))
=
let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads c_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
let hash = ghash_BE h final_quads in
gcm_blocks_helper_enc alg key p128 p_bytes c128 c_bytes auth_input_bytes p_num_bytes iv j0_BE;
calc (==) {
enc_hash;
== {}
gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0;
== {}
gctr_encrypt_block ctr_BE_1 hash alg key 0;
== {}
quad32_xor hash (aes_encrypt_word alg key ctr_BE_1);
};
calc (==) {
gctr_encrypt ctr_BE_1 (be_quad32_to_bytes hash) alg key;
== { gctr_encrypt_one_block ctr_BE_1 hash alg key }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 (quad32_xor hash (aes_encrypt_word alg key ctr_BE_1))));
== {}
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 enc_hash));
== { be_seq_quad32_to_bytes_of_singleton enc_hash }
be_quad32_to_bytes enc_hash;
};
if p_num_bytes > length p128 * 16 then (
let c = append c128 c_bytes in
calc (==) {
append (append auth_quads c128) c_bytes;
== { append_assoc auth_quads c128 c_bytes }
append auth_quads (append c128 c_bytes);
== {}
append auth_quads c;
};
calc (==) {
append (append (append auth_quads c128) c_bytes) (create 1 length_quad);
= {} // See previous calc
append (append auth_quads (append c128 c_bytes)) (create 1 length_quad);
== { append_assoc auth_quads c (create 1 length_quad) }
append auth_quads (append c (create 1 length_quad));
};
let raw_quads_old = append auth_quads c in
calc (==) {
raw_quads;
== {}
be_bytes_to_seq_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes));
== {
calc (==) {
pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes);
== {
calc (==) {
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes;
== { append_distributes_be_seq_quad32_to_bytes auth_quads c }
slice (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))) 0 total_bytes;
== { slice_append_back (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))
total_bytes }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes);
== {}
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) cipher_bytes;
}
}
pad_to_128_bits (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) cipher_bytes);
== { pad_to_128_bits_multiple_append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) cipher_bytes }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (pad_to_128_bits cipher_bytes);
}
}
be_bytes_to_seq_quad32 (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (pad_to_128_bits cipher_bytes));
== { append_distributes_be_bytes_to_seq_quad32
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(pad_to_128_bits cipher_bytes) }
append (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))) (be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes));
== { be_bytes_to_seq_quad32_to_bytes auth_quads }
append auth_quads (be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes));
};
let auth_padded_quads' = be_bytes_to_seq_quad32 (pad_to_128_bits auth_input_bytes) in
let cipher_padded_quads' = be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes) in
calc (==) {
append raw_quads (create 1 length_quad);
== {}
append (append auth_quads (be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes))) (create 1 length_quad);
== { assert (equal auth_quads auth_padded_quads') }
append (append auth_padded_quads' cipher_padded_quads') (create 1 length_quad);
== { append_assoc auth_padded_quads' cipher_padded_quads' (create 1 length_quad) }
append auth_padded_quads' (append cipher_padded_quads' (create 1 length_quad));
};
gcm_encrypt_BE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key;
()
) else (
calc (==) {
append (append auth_quads c128) (create 1 length_quad);
== { append_assoc auth_quads c128 (create 1 length_quad) }
append auth_quads (append c128 (create 1 length_quad));
};
let c = c128 in
calc (==) {
be_bytes_to_seq_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes));
== { assert (equal (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes)) }
be_bytes_to_seq_quad32 (pad_to_128_bits (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)));
== { assert (pad_to_128_bits (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) == (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))) }
be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c));
== { be_bytes_to_seq_quad32_to_bytes c }
c;
};
gcm_encrypt_BE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key;
()
);
()
let lemma_length_simplifier (s bytes t:seq quad32) (num_bytes:nat) : Lemma
(requires t == (if num_bytes > (length s) * 16 then append s bytes else s) /\
(num_bytes <= (length s) * 16 ==> num_bytes == (length s * 16)) /\
length s * 16 <= num_bytes /\
num_bytes < length s * 16 + 16 /\
length bytes == 1
)
(ensures slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE t)) 0 num_bytes ==
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append s bytes))) 0 num_bytes)
=
if num_bytes > (length s) * 16 then (
()
) else (
calc (==) {
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append s bytes))) 0 num_bytes;
== { append_distributes_be_seq_quad32_to_bytes s bytes }
slice (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE bytes))) 0 num_bytes;
== { Vale.Lib.Seqs.lemma_slice_first_exactly_in_append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE bytes)) }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s);
== { assert (length (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == num_bytes) }
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes;
};
()
)
#reset-options "--z3rlimit 10"
let gcm_blocks_helper_simplified (alg:algorithm) (key:seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes:seq quad32)
(p_num_bytes a_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE h enc_hash length_quad:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\
a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
length a_bytes == 1 /\
is_aes_key_word alg key /\
j0_BE == compute_iv_BE h iv /\
h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > length a128 * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads c_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0
)))
(ensures (let auth_raw_quads = append a128 a_bytes in
let auth_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let plain_raw_quads = append p128 p_bytes in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher_raw_quads = append c128 c_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_raw_quads)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes) /\
be_quad32_to_bytes enc_hash ==
snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key)
iv plain_bytes auth_bytes))
)
=
gcm_blocks_helper alg key a128 a_bytes p128 p_bytes c128 c_bytes p_num_bytes a_num_bytes iv j0_BE h enc_hash length_quad;
let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in
let plain_raw_quads =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else p128
in
let cipher_raw_quads:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
lemma_length_simplifier a128 a_bytes auth_raw_quads a_num_bytes;
lemma_length_simplifier p128 p_bytes plain_raw_quads p_num_bytes;
lemma_length_simplifier c128 c_bytes cipher_raw_quads p_num_bytes;
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.GHash_BE_s.fst.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.GCM_BE_s.fst.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_BE.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
alg: Vale.AES.AES_common_s.algorithm ->
key: FStar.Seq.Base.seq Vale.Def.Words_s.nat32 ->
iv: Vale.AES.GCM_BE_s.supported_iv_BE ->
j0_BE: Vale.Def.Types_s.quad32 ->
plain: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 ->
cipher: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 ->
auth: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 ->
alleged_tag: FStar.Seq.Base.seq Vale.Def.Words_s.nat8
-> FStar.Pervasives.Lemma
(requires
Vale.AES.AES_BE_s.is_aes_key_word alg key /\
(let h_BE = Vale.AES.AES_BE_s.aes_encrypt_word alg key (Vale.Def.Words_s.Mkfour 0 0 0 0) in
j0_BE = Vale.AES.GCM_BE_s.compute_iv_BE h_BE iv) /\
FStar.Seq.Base.length cipher < Vale.Def.Words_s.pow2_32 /\
FStar.Seq.Base.length auth < Vale.Def.Words_s.pow2_32 /\
plain ==
FStar.Pervasives.Native.fst (Vale.AES.GCM_BE_s.gcm_encrypt_BE alg
(Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE key)
iv
cipher
auth))
(ensures
plain ==
FStar.Pervasives.Native.fst (Vale.AES.GCM_BE_s.gcm_decrypt_BE alg
(Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE key)
iv
cipher
auth
alleged_tag)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.AES.AES_common_s.algorithm",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat32",
"Vale.AES.GCM_BE_s.supported_iv_BE",
"Vale.Def.Types_s.quad32",
"Vale.Def.Words_s.nat8",
"Prims.unit",
"Vale.AES.GCM_BE_s.gcm_decrypt_BE_reveal",
"Vale.AES.GCM_BE_s.gcm_encrypt_BE_reveal",
"Prims.l_and",
"Vale.AES.AES_BE_s.is_aes_key_word",
"Prims.b2t",
"Prims.op_Equality",
"Vale.AES.GCM_BE_s.compute_iv_BE",
"Vale.AES.AES_BE_s.aes_encrypt_word",
"Vale.Def.Words_s.Mkfour",
"Vale.Def.Types_s.nat32",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Vale.Def.Words_s.pow2_32",
"Prims.eq2",
"Vale.Def.Types_s.nat8",
"FStar.Pervasives.Native.fst",
"Vale.AES.GCM_BE_s.gcm_encrypt_BE",
"Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE",
"Prims.squash",
"Prims.bool",
"Vale.AES.GCM_BE_s.gcm_decrypt_BE",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_gcm_encrypt_decrypt_equiv
(alg: algorithm)
(key: seq nat32)
(iv: supported_iv_BE)
(j0_BE: quad32)
(plain cipher auth alleged_tag: seq nat8)
: Lemma
(requires
is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv) /\ length cipher < pow2_32 /\ length auth < pow2_32 /\
plain == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv cipher auth))
(ensures
plain == fst (gcm_decrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv cipher auth alleged_tag)) =
| gcm_encrypt_BE_reveal ();
gcm_decrypt_BE_reveal ();
() | false |
Vale.AES.GCM_BE.fst | Vale.AES.GCM_BE.decrypt_helper | val decrypt_helper
(alg:algorithm) (key:seq nat8) (iv:supported_iv_BE) (cipher:seq nat8) (auth:seq nat8)
(r3:nat64) (alleged_tag_quad computed_tag:quad32) : Lemma
(requires
is_aes_key alg key /\
length cipher < pow2_32 /\
length auth < pow2_32 /\
(if alleged_tag_quad = computed_tag then r3 = 0 else r3 > 0) /\
be_quad32_to_bytes computed_tag == gcm_decrypt_BE_tag alg key iv cipher auth
)
(ensures (r3 = 0) == snd (gcm_decrypt_BE alg key iv cipher auth (be_quad32_to_bytes alleged_tag_quad))) | val decrypt_helper
(alg:algorithm) (key:seq nat8) (iv:supported_iv_BE) (cipher:seq nat8) (auth:seq nat8)
(r3:nat64) (alleged_tag_quad computed_tag:quad32) : Lemma
(requires
is_aes_key alg key /\
length cipher < pow2_32 /\
length auth < pow2_32 /\
(if alleged_tag_quad = computed_tag then r3 = 0 else r3 > 0) /\
be_quad32_to_bytes computed_tag == gcm_decrypt_BE_tag alg key iv cipher auth
)
(ensures (r3 = 0) == snd (gcm_decrypt_BE alg key iv cipher auth (be_quad32_to_bytes alleged_tag_quad))) | let decrypt_helper
(alg:algorithm) (key:seq nat8) (iv:supported_iv_BE) (cipher:seq nat8) (auth:seq nat8)
(r3:nat64) (alleged_tag_quad computed_tag:quad32) : Lemma
(requires
is_aes_key alg key /\
length cipher < pow2_32 /\
length auth < pow2_32 /\
(if alleged_tag_quad = computed_tag then r3 = 0 else r3 > 0) /\
be_quad32_to_bytes computed_tag == gcm_decrypt_BE_tag alg key iv cipher auth
)
(ensures (r3 = 0) == snd (gcm_decrypt_BE alg key iv cipher auth (be_quad32_to_bytes alleged_tag_quad)))
=
gcm_decrypt_BE_reveal ();
be_quad32_to_bytes_injective_specific alleged_tag_quad computed_tag;
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_BE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 1065,
"start_col": 0,
"start_line": 1051
} | module Vale.AES.GCM_BE
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.AES.GCM_BE_s
open Vale.AES.AES_BE_s
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.AES.GHash_BE_s
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open FStar.Calc
let upper3_equal (q0 q1:quad32) : bool =
q0.lo1 = q1.lo1 &&
q0.hi2 = q1.hi2 &&
q0.hi3 = q1.hi3
let lemma_be_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma
(requires slice b0 0 12 == slice b1 0 12)
(ensures upper3_equal (be_bytes_to_quad32 b0) (be_bytes_to_quad32 b1))
=
let q0 = be_bytes_to_quad32 b0 in
let q1 = be_bytes_to_quad32 b1 in
be_bytes_to_quad32_reveal ();
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #nat8);
assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\
index b1 i == index (slice b1 0 12) i))
let lemma_be_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma
(slice (be_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
=
assert (equal (slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
(slice (be_quad32_to_bytes q) 0 12));
()
let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_BE) (num_bytes:nat64) (h_BE j0:quad32) : Lemma
(requires
length iv_extra_b == 1 /\
length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\
num_bytes == 96/8 /\
(let iv_BE = index iv_extra_b 0 in
j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\
(let raw_quads = append iv_b iv_extra_b in
let iv_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 num_bytes in
iv_bytes == iv))
(ensures j0 == compute_iv_BE h_BE iv)
=
assert (length iv == 12);
assert (length iv_b == 0);
lemma_empty iv_b;
append_empty_l iv_extra_b;
assert (append iv_b iv_extra_b == iv_extra_b);
let q = index iv_extra_b 0 in
be_seq_quad32_to_bytes_of_singleton q;
assert (equal iv_extra_b (create 1 q));
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b) == be_quad32_to_bytes q);
calc (==) {
slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12;
== {}
slice (pad_to_128_bits iv) 0 12;
};
calc (==) {
be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b)) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits iv);
};
calc (==) {
j0;
== {}
set_to_one q;
== { be_bytes_to_quad32_to_bytes q }
set_to_one (be_bytes_to_quad32 (be_quad32_to_bytes q));
== {
lemma_be_seq_quad32_to_bytes_prefix_equality q;
lemma_be_bytes_to_quad32_prefix_equality
(be_quad32_to_bytes q)
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
}
set_to_one (be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)));
== { lemma_be_bytes_to_quad32_prefix_equality
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
(pad_to_128_bits iv) }
set_to_one (be_bytes_to_quad32 (pad_to_128_bits iv));
== {compute_iv_BE_reveal ()}
compute_iv_BE h_BE iv;
};
()
let lemma_compute_iv_hard (iv:supported_iv_BE) (quads:seq quad32) (length_quad h_BE j0:quad32) : Lemma
(requires
~(length iv == 96/8) /\
quads == be_bytes_to_seq_quad32 (pad_to_128_bits iv) /\
j0 == ghash_incremental h_BE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 0)
(nat_to_two 32 (8 * length iv))))
(ensures j0 == compute_iv_BE h_BE iv)
=
ghash_incremental_to_ghash h_BE (append quads (create 1 length_quad));
compute_iv_BE_reveal ();
()
let gcm_encrypt_BE_fst_helper (iv:supported_iv_BE) (iv_enc iv_BE:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma
(requires
is_aes_key_word alg key /\
length plain < pow2_32 /\
length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
iv_enc == inc32 (compute_iv_BE h_BE iv) 1 /\
cipher == gctr_encrypt iv_enc plain alg key
))
(ensures cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth))
=
gcm_encrypt_BE_reveal ()
let gcm_encrypt_BE_snd_helper (iv:supported_iv_BE) (j0_BE length_quad32 hash mac:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma
(requires
is_aes_key_word alg key /\
length plain < pow2_32 /\
length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth) /\
length_quad32 == two_two_to_four (Mktwo (nat_to_two 32 (8 * length auth)) (nat_to_two 32 (8 * length plain))) /\
(let auth_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits auth) in
let cipher_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits cipher) in
hash == ghash_BE h_BE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\
be_quad32_to_bytes mac == gctr_encrypt j0_BE (be_quad32_to_bytes hash) alg key)
))
(ensures be_quad32_to_bytes mac == snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth))
=
gcm_encrypt_BE_reveal ()
#reset-options "--z3rlimit 10"
let gcm_blocks_helper_enc (alg:algorithm) (key:seq nat32)
(p128 p_bytes c128 c_bytes:seq quad32)
(auth_bytes:seq nat8)
(p_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
(length auth_bytes) < pow2_32 /\
is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\
(let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2
)))
(ensures (let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
//cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key))
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes)))
=
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
gctr_partial_opaque_completed alg plain cipher key ctr_BE_2;
if p_num_bytes > length p128 * 16 then (
gctr_partial_reveal ();
assert (gctr_partial alg (length p128) plain cipher key ctr_BE_2);
assert (equal (slice plain 0 (length p128))
(slice p128 0 (length p128)));
assert (equal (slice cipher 0 (length p128))
(slice c128 0 (length p128)));
gctr_partial_opaque_ignores_postfix
alg (length p128)
plain p128
cipher c128
key ctr_BE_2;
assert (gctr_partial alg (length p128) p128 c128 key ctr_BE_2);
gctr_partial_opaque_completed alg p128 c128 key ctr_BE_2;
let num_blocks = p_num_bytes / 16 in
assert(index cipher num_blocks == quad32_xor (index plain num_blocks) (aes_encrypt_word alg key (inc32 ctr_BE_2 num_blocks)));
gctr_encrypt_block_offset ctr_BE_2 (index plain num_blocks) alg key num_blocks;
assert( gctr_encrypt_block ctr_BE_2 (index plain num_blocks) alg key num_blocks ==
gctr_encrypt_block (inc32 ctr_BE_2 num_blocks) (index plain num_blocks) alg key 0);
aes_encrypt_word_reveal ();
gctr_partial_to_full_advanced ctr_BE_2 plain cipher alg key p_num_bytes;
assert (cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key)
) else (
gctr_partial_to_full_basic ctr_BE_2 plain alg key cipher;
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher) == gctr_encrypt ctr_BE_2 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) alg key);
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
assert (equal plain_bytes (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)));
assert (equal cipher_bytes (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)));
assert (cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key)
);
gcm_encrypt_BE_fst_helper iv ctr_BE_2 j0_BE plain_bytes auth_bytes cipher_bytes alg key;
()
let slice_append_back (#a:Type) (x y:seq a) (i:nat) : Lemma
(requires length x <= i /\ i <= length x + length y)
(ensures slice (append x y) 0 i == append x (slice y 0 (i - length x)))
=
assert (equal (slice (append x y) 0 i) (append x (slice y 0 (i - length x))));
()
let append_distributes_be_seq_quad32_to_bytes (x y:seq quad32) :
Lemma (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append x y)) == append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE x)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE y)))
=
append_distributes_be_seq_quad32_to_bytes x y
let pad_to_128_bits_multiple_append (x y:seq nat8) : Lemma
(requires length x % 16 == 0)
(ensures pad_to_128_bits (append x y) == append x (pad_to_128_bits y))
=
assert (equal (pad_to_128_bits (append x y)) (append x (pad_to_128_bits y)))
#reset-options "--z3rlimit 100"
let gcm_blocks_helper (alg:algorithm) (key:seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes:seq quad32)
(p_num_bytes a_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE h enc_hash length_quad:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\
a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
length a_bytes == 1 /\
is_aes_key_word alg key /\
j0_BE = compute_iv_BE h iv /\
h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads c_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0
)))
(ensures (let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let plain_raw_quads =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else p128
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes) /\
be_quad32_to_bytes enc_hash ==
snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key)
iv plain_bytes auth_bytes)))
=
let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads c_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
let hash = ghash_BE h final_quads in
gcm_blocks_helper_enc alg key p128 p_bytes c128 c_bytes auth_input_bytes p_num_bytes iv j0_BE;
calc (==) {
enc_hash;
== {}
gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0;
== {}
gctr_encrypt_block ctr_BE_1 hash alg key 0;
== {}
quad32_xor hash (aes_encrypt_word alg key ctr_BE_1);
};
calc (==) {
gctr_encrypt ctr_BE_1 (be_quad32_to_bytes hash) alg key;
== { gctr_encrypt_one_block ctr_BE_1 hash alg key }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 (quad32_xor hash (aes_encrypt_word alg key ctr_BE_1))));
== {}
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 enc_hash));
== { be_seq_quad32_to_bytes_of_singleton enc_hash }
be_quad32_to_bytes enc_hash;
};
if p_num_bytes > length p128 * 16 then (
let c = append c128 c_bytes in
calc (==) {
append (append auth_quads c128) c_bytes;
== { append_assoc auth_quads c128 c_bytes }
append auth_quads (append c128 c_bytes);
== {}
append auth_quads c;
};
calc (==) {
append (append (append auth_quads c128) c_bytes) (create 1 length_quad);
= {} // See previous calc
append (append auth_quads (append c128 c_bytes)) (create 1 length_quad);
== { append_assoc auth_quads c (create 1 length_quad) }
append auth_quads (append c (create 1 length_quad));
};
let raw_quads_old = append auth_quads c in
calc (==) {
raw_quads;
== {}
be_bytes_to_seq_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes));
== {
calc (==) {
pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes);
== {
calc (==) {
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes;
== { append_distributes_be_seq_quad32_to_bytes auth_quads c }
slice (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))) 0 total_bytes;
== { slice_append_back (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))
total_bytes }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes);
== {}
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) cipher_bytes;
}
}
pad_to_128_bits (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) cipher_bytes);
== { pad_to_128_bits_multiple_append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) cipher_bytes }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (pad_to_128_bits cipher_bytes);
}
}
be_bytes_to_seq_quad32 (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (pad_to_128_bits cipher_bytes));
== { append_distributes_be_bytes_to_seq_quad32
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(pad_to_128_bits cipher_bytes) }
append (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))) (be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes));
== { be_bytes_to_seq_quad32_to_bytes auth_quads }
append auth_quads (be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes));
};
let auth_padded_quads' = be_bytes_to_seq_quad32 (pad_to_128_bits auth_input_bytes) in
let cipher_padded_quads' = be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes) in
calc (==) {
append raw_quads (create 1 length_quad);
== {}
append (append auth_quads (be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes))) (create 1 length_quad);
== { assert (equal auth_quads auth_padded_quads') }
append (append auth_padded_quads' cipher_padded_quads') (create 1 length_quad);
== { append_assoc auth_padded_quads' cipher_padded_quads' (create 1 length_quad) }
append auth_padded_quads' (append cipher_padded_quads' (create 1 length_quad));
};
gcm_encrypt_BE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key;
()
) else (
calc (==) {
append (append auth_quads c128) (create 1 length_quad);
== { append_assoc auth_quads c128 (create 1 length_quad) }
append auth_quads (append c128 (create 1 length_quad));
};
let c = c128 in
calc (==) {
be_bytes_to_seq_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes));
== { assert (equal (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes)) }
be_bytes_to_seq_quad32 (pad_to_128_bits (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)));
== { assert (pad_to_128_bits (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) == (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))) }
be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c));
== { be_bytes_to_seq_quad32_to_bytes c }
c;
};
gcm_encrypt_BE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key;
()
);
()
let lemma_length_simplifier (s bytes t:seq quad32) (num_bytes:nat) : Lemma
(requires t == (if num_bytes > (length s) * 16 then append s bytes else s) /\
(num_bytes <= (length s) * 16 ==> num_bytes == (length s * 16)) /\
length s * 16 <= num_bytes /\
num_bytes < length s * 16 + 16 /\
length bytes == 1
)
(ensures slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE t)) 0 num_bytes ==
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append s bytes))) 0 num_bytes)
=
if num_bytes > (length s) * 16 then (
()
) else (
calc (==) {
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append s bytes))) 0 num_bytes;
== { append_distributes_be_seq_quad32_to_bytes s bytes }
slice (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE bytes))) 0 num_bytes;
== { Vale.Lib.Seqs.lemma_slice_first_exactly_in_append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE bytes)) }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s);
== { assert (length (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == num_bytes) }
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes;
};
()
)
#reset-options "--z3rlimit 10"
let gcm_blocks_helper_simplified (alg:algorithm) (key:seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes:seq quad32)
(p_num_bytes a_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE h enc_hash length_quad:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\
a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
length a_bytes == 1 /\
is_aes_key_word alg key /\
j0_BE == compute_iv_BE h iv /\
h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > length a128 * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads c_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0
)))
(ensures (let auth_raw_quads = append a128 a_bytes in
let auth_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let plain_raw_quads = append p128 p_bytes in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher_raw_quads = append c128 c_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_raw_quads)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes) /\
be_quad32_to_bytes enc_hash ==
snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key)
iv plain_bytes auth_bytes))
)
=
gcm_blocks_helper alg key a128 a_bytes p128 p_bytes c128 c_bytes p_num_bytes a_num_bytes iv j0_BE h enc_hash length_quad;
let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in
let plain_raw_quads =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else p128
in
let cipher_raw_quads:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
lemma_length_simplifier a128 a_bytes auth_raw_quads a_num_bytes;
lemma_length_simplifier p128 p_bytes plain_raw_quads p_num_bytes;
lemma_length_simplifier c128 c_bytes cipher_raw_quads p_num_bytes;
()
let lemma_gcm_encrypt_decrypt_equiv (alg:algorithm) (key:seq nat32) (iv:supported_iv_BE) (j0_BE:quad32) (plain cipher auth alleged_tag:seq nat8) : Lemma
(requires
is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv) /\
length cipher < pow2_32 /\
length auth < pow2_32 /\
plain == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv cipher auth)
)
(ensures plain == fst (gcm_decrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv cipher auth alleged_tag))
=
gcm_encrypt_BE_reveal ();
gcm_decrypt_BE_reveal ();
()
let gcm_blocks_helper_dec_simplified (alg:algorithm) (key:seq nat32)
(p128 p_bytes c128 c_bytes:seq quad32)
(auth_bytes alleged_tag:seq nat8)
(p_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
(length auth_bytes) < pow2_32 /\
is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\
(let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2
))
(ensures (let plain_raw_quads = append p128 p_bytes in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher_raw_quads = append c128 c_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_raw_quads)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
cipher_bytes == fst (gcm_decrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes alleged_tag)))
=
gcm_blocks_helper_enc alg key p128 p_bytes c128 c_bytes auth_bytes p_num_bytes iv j0_BE;
let plain_raw_quads =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else p128
in
let cipher_raw_quads:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
lemma_length_simplifier p128 p_bytes plain_raw_quads p_num_bytes;
lemma_length_simplifier c128 c_bytes cipher_raw_quads p_num_bytes;
let plain_raw_quads = append p128 p_bytes in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher_raw_quads = append c128 c_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_raw_quads)) 0 p_num_bytes in
assert (cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes));
lemma_gcm_encrypt_decrypt_equiv alg key iv j0_BE cipher_bytes plain_bytes auth_bytes alleged_tag;
()
#reset-options "--z3rlimit 60"
let gcm_blocks_dec_helper (alg:algorithm) (key:seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes:seq quad32)
(p_num_bytes a_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE h enc_hash length_quad:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\
a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
length a_bytes == 1 /\
is_aes_key_word alg key /\
j0_BE = compute_iv_BE h iv /\
h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads p128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads p_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0
)))
(ensures (let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let plain_raw_quads =
if p_num_bytes >length p128 * 16 then
append p128 p_bytes
else p128
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
be_quad32_to_bytes enc_hash == gcm_decrypt_BE_tag alg (seq_nat32_to_seq_nat8_BE key)
iv plain_bytes auth_bytes))
=
let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
let auth_raw_quads =
if a_num_bytes > length a128 * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads p128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads p_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
let hash = ghash_BE h final_quads in
calc (==) {
enc_hash;
== {}
gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0;
== {}
gctr_encrypt_block ctr_BE_1 hash alg key 0;
== {}
quad32_xor hash (aes_encrypt_word alg key ctr_BE_1);
};
calc (==) {
gctr_encrypt ctr_BE_1 (be_quad32_to_bytes hash) alg key;
== { gctr_encrypt_one_block ctr_BE_1 hash alg key }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 (quad32_xor hash (aes_encrypt_word alg key ctr_BE_1))));
== {}
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 enc_hash));
== { be_seq_quad32_to_bytes_of_singleton enc_hash }
be_quad32_to_bytes enc_hash;
};
if p_num_bytes > length p128 * 16 then (
let c = append p128 p_bytes in
calc (==) {
append (append auth_quads p128) p_bytes;
== { append_assoc auth_quads p128 p_bytes }
append auth_quads (append p128 p_bytes);
== {}
append auth_quads c;
};
calc (==) {
append (append (append auth_quads p128) p_bytes) (create 1 length_quad);
= {} // See previous calc
append (append auth_quads (append p128 p_bytes)) (create 1 length_quad);
== { append_assoc auth_quads c (create 1 length_quad) }
append auth_quads (append c (create 1 length_quad));
};
let raw_quads_old = append auth_quads c in
calc (==) {
raw_quads;
== {}
be_bytes_to_seq_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes));
== {
calc (==) {
pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes);
== {
calc (==) {
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes;
== { append_distributes_be_seq_quad32_to_bytes auth_quads c }
slice (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))) 0 total_bytes;
== { slice_append_back (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))
total_bytes }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes);
== { assert(equal (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes) plain_bytes) }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) plain_bytes;
}
}
pad_to_128_bits (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) plain_bytes);
== { pad_to_128_bits_multiple_append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) plain_bytes }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (pad_to_128_bits plain_bytes);
}
}
be_bytes_to_seq_quad32 (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (pad_to_128_bits plain_bytes));
== { append_distributes_be_bytes_to_seq_quad32
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(pad_to_128_bits plain_bytes) }
append (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))) (be_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes));
== { be_bytes_to_seq_quad32_to_bytes auth_quads }
append auth_quads (be_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes));
};
let auth_padded_quads' = be_bytes_to_seq_quad32 (pad_to_128_bits auth_input_bytes) in
let cipher_padded_quads' = be_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes) in
calc (==) {
append raw_quads (create 1 length_quad);
== {}
append (append auth_quads (be_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes))) (create 1 length_quad);
== { assert (equal auth_quads auth_padded_quads') }
append (append auth_padded_quads' cipher_padded_quads') (create 1 length_quad);
== { append_assoc auth_padded_quads' cipher_padded_quads' (create 1 length_quad) }
append auth_padded_quads' (append cipher_padded_quads' (create 1 length_quad));
};
()
) else (
calc (==) {
append (append auth_quads p128) (create 1 length_quad);
== { append_assoc auth_quads p128 (create 1 length_quad) }
append auth_quads (append p128 (create 1 length_quad));
};
let c = p128 in
calc (==) {
be_bytes_to_seq_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes));
== { assert (equal (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes)) }
be_bytes_to_seq_quad32 (pad_to_128_bits (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)));
== { assert (pad_to_128_bits (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) == (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))) }
be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c));
== { be_bytes_to_seq_quad32_to_bytes c }
c;
};
()
);
()
#reset-options ""
let gcm_blocks_dec_helper_simplified (alg:algorithm) (key:seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes:seq quad32)
(p_num_bytes a_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE h enc_hash length_quad:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\
a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
length a_bytes == 1 /\
is_aes_key_word alg key /\
j0_BE == compute_iv_BE h iv /\
h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads p128 in
let total_bytes = (length auth_quads) * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads p_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0
)))
(ensures(let auth_raw_quads = append a128 a_bytes in
let auth_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let plain_raw_quads = append p128 p_bytes in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher_raw_quads = append c128 c_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_raw_quads)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
be_quad32_to_bytes enc_hash == gcm_decrypt_BE_tag alg (seq_nat32_to_seq_nat8_BE key)
iv plain_bytes auth_bytes))
=
gcm_blocks_dec_helper alg key a128 a_bytes p128 p_bytes c128 c_bytes p_num_bytes a_num_bytes iv j0_BE h enc_hash length_quad;
let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in
let plain_raw_quads =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else p128
in
let cipher_raw_quads:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
lemma_length_simplifier a128 a_bytes auth_raw_quads a_num_bytes;
lemma_length_simplifier p128 p_bytes plain_raw_quads p_num_bytes;
lemma_length_simplifier c128 c_bytes cipher_raw_quads p_num_bytes;
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.GHash_BE_s.fst.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.GCM_BE_s.fst.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_BE.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
alg: Vale.AES.AES_common_s.algorithm ->
key: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 ->
iv: Vale.AES.GCM_BE_s.supported_iv_BE ->
cipher: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 ->
auth: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 ->
r3: Vale.Def.Words_s.nat64 ->
alleged_tag_quad: Vale.Def.Types_s.quad32 ->
computed_tag: Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(requires
Vale.AES.AES_common_s.is_aes_key alg key /\
FStar.Seq.Base.length cipher < Vale.Def.Words_s.pow2_32 /\
FStar.Seq.Base.length auth < Vale.Def.Words_s.pow2_32 /\
(match alleged_tag_quad = computed_tag with
| true -> r3 = 0
| _ -> r3 > 0) /\
Vale.Arch.Types.be_quad32_to_bytes computed_tag ==
Vale.AES.GCM_BE.gcm_decrypt_BE_tag alg key iv cipher auth)
(ensures
r3 = 0 ==
FStar.Pervasives.Native.snd (Vale.AES.GCM_BE_s.gcm_decrypt_BE alg
key
iv
cipher
auth
(Vale.Arch.Types.be_quad32_to_bytes alleged_tag_quad))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.AES.AES_common_s.algorithm",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat8",
"Vale.AES.GCM_BE_s.supported_iv_BE",
"Vale.Def.Words_s.nat64",
"Vale.Def.Types_s.quad32",
"Prims.unit",
"Vale.Arch.Types.be_quad32_to_bytes_injective_specific",
"Vale.AES.GCM_BE_s.gcm_decrypt_BE_reveal",
"Prims.l_and",
"Vale.AES.AES_common_s.is_aes_key",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Vale.Def.Words_s.pow2_32",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"Prims.op_GreaterThan",
"Prims.logical",
"Prims.eq2",
"Vale.Arch.Types.be_quad32_to_bytes",
"Vale.AES.GCM_BE.gcm_decrypt_BE_tag",
"Prims.squash",
"FStar.Pervasives.Native.snd",
"Vale.Def.Types_s.nat8",
"Vale.AES.GCM_BE_s.gcm_decrypt_BE",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let decrypt_helper
(alg: algorithm)
(key: seq nat8)
(iv: supported_iv_BE)
(cipher auth: seq nat8)
(r3: nat64)
(alleged_tag_quad computed_tag: quad32)
: Lemma
(requires
is_aes_key alg key /\ length cipher < pow2_32 /\ length auth < pow2_32 /\
(if alleged_tag_quad = computed_tag then r3 = 0 else r3 > 0) /\
be_quad32_to_bytes computed_tag == gcm_decrypt_BE_tag alg key iv cipher auth)
(ensures
(r3 = 0) ==
snd (gcm_decrypt_BE alg key iv cipher auth (be_quad32_to_bytes alleged_tag_quad))) =
| gcm_decrypt_BE_reveal ();
be_quad32_to_bytes_injective_specific alleged_tag_quad computed_tag;
() | false |
Vale.Transformers.MovMovElim.fst | Vale.Transformers.MovMovElim.mov_mov_elim_correct | val mov_mov_elim_correct (is: list ins) (s: machine_state)
: Lemma (peephole_correct mov_mov_elim_ph is s) [SMTPat (peephole_correct mov_mov_elim_ph is s)] | val mov_mov_elim_correct (is: list ins) (s: machine_state)
: Lemma (peephole_correct mov_mov_elim_ph is s) [SMTPat (peephole_correct mov_mov_elim_ph is s)] | let mov_mov_elim_correct (is:list ins) (s:machine_state) :
Lemma (peephole_correct mov_mov_elim_ph is s)
[SMTPat (peephole_correct mov_mov_elim_ph is s)] =
if safe_mov_mov_elim is then (
let [i1; i2] = is in
lemma_mov_mov_is_mov i1 i2 s
) else () | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.MovMovElim.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 97,
"start_col": 0,
"start_line": 91
} | module Vale.Transformers.MovMovElim
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.InstructionReorder
open Vale.X64.InsLemmas
open Vale.Transformers.PeepHole
(*
* AR: this proof relies on multiple inductive type inversions to know that
* oprs1 is a Mov64 (resp. for oprs2)
*
* this used to go through earlier with just ifuel 1, because F* was weakening
* the branch VCs with discriminator expressions, thereby unintentionally
* triggering the inversions, this is no longer true in F*, and hence more ifuel
*)
#push-options "--ifuel 4"
let safe_mov_mov_elim (is:list ins) : Tot bool =
match is with
| [Instr i1 oprs1 (AnnotateMov64 ()); Instr i2 oprs2 (AnnotateMov64 ())] ->
let oprs1:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs1 in
let oprs2:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs2 in
let (dst1, (src1, ())) = oprs1 in
let (dst2, (src2, ())) = oprs2 in
dst1 = dst2 && OReg? dst1 && (
let OReg rd = dst1 in
match src2 with
| OConst _ -> true
| OReg rs2 -> not (rs2 = rd)
| OStack (m, _) | OMem (m, _) ->
match m with
| MConst _ -> true
| _ -> false // TODO: Can we relax this restriction?
)
| _ -> false
#pop-options
let mov_mov_elim_ph = {
ph = (fun is ->
if safe_mov_mov_elim is then (
let [i1; i2] = is in
Some [i2]
) else None);
input_hint = 2;
}
module T = Vale.Def.Types_s
module H = Vale.Arch.Heap
#push-options "--initial_fuel 2 --max_fuel 8 --initial_ifuel 1 --max_ifuel 2 --query_stats"
let lemma_mov_mov_is_mov (i1 i2:ins) (s:machine_state) :
Lemma
(requires (safe_mov_mov_elim [i1; i2]))
(ensures (
let s1 = machine_eval_ins i2 (machine_eval_ins i1 s) in
let s2 = machine_eval_ins i2 s in
s1.ms_ok ==> equiv_states s1 s2)) =
let Instr ii1 oprs1 (AnnotateMov64 ()) = i1 in
let Instr ii2 oprs2 (AnnotateMov64 ()) = i2 in
let oprs1:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs1 in
let oprs2:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs2 in
let (dst1, (src1, ())) = oprs1 in
let (dst2, (src2, ())) = oprs2 in
let dst = assert (dst1 == dst2); dst1 in
let pre_s1 = machine_eval_ins i1 s in
let s1 = machine_eval_ins i2 pre_s1 in
let s2 = machine_eval_ins i2 s in
if s1.ms_ok then (
assert (pre_s1.ms_ok);
let v1 = eval_operand src1 s in
let v2' = eval_operand src2 s in
let v2 = eval_operand src2 pre_s1 in
assert (v2 == v2');
lemma_double_update_reg dst s pre_s1 s1 s2 v1 v2
) else ()
#pop-options | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.InsLemmas.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.PeepHole.fsti.checked",
"Vale.Transformers.InstructionReorder.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Transformers.MovMovElim.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Arch.Heap",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Vale.Def.Types_s",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.PeepHole",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers.InstructionReorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 3,
"initial_ifuel": 0,
"max_fuel": 3,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | is: Prims.list Vale.X64.Machine_Semantics_s.ins -> s: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(ensures
Vale.Transformers.PeepHole.peephole_correct Vale.Transformers.MovMovElim.mov_mov_elim_ph
is
s)
[
SMTPat (Vale.Transformers.PeepHole.peephole_correct Vale.Transformers.MovMovElim.mov_mov_elim_ph
is
s)
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.list",
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Transformers.MovMovElim.safe_mov_mov_elim",
"Vale.Transformers.MovMovElim.lemma_mov_mov_is_mov",
"Prims.unit",
"Prims.bool",
"Prims.l_True",
"Prims.squash",
"Vale.Transformers.PeepHole.peephole_correct",
"Vale.Transformers.MovMovElim.mov_mov_elim_ph",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | false | false | true | false | false | let mov_mov_elim_correct (is: list ins) (s: machine_state)
: Lemma (peephole_correct mov_mov_elim_ph is s) [SMTPat (peephole_correct mov_mov_elim_ph is s)] =
| if safe_mov_mov_elim is
then
(let [i1 ; i2] = is in
lemma_mov_mov_is_mov i1 i2 s) | false |
Vale.AES.GCM_BE.fst | Vale.AES.GCM_BE.lemma_length_simplifier | val lemma_length_simplifier (s bytes t:seq quad32) (num_bytes:nat) : Lemma
(requires t == (if num_bytes > (length s) * 16 then append s bytes else s) /\
(num_bytes <= (length s) * 16 ==> num_bytes == (length s * 16)) /\
length s * 16 <= num_bytes /\
num_bytes < length s * 16 + 16 /\
length bytes == 1
)
(ensures slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE t)) 0 num_bytes ==
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append s bytes))) 0 num_bytes) | val lemma_length_simplifier (s bytes t:seq quad32) (num_bytes:nat) : Lemma
(requires t == (if num_bytes > (length s) * 16 then append s bytes else s) /\
(num_bytes <= (length s) * 16 ==> num_bytes == (length s * 16)) /\
length s * 16 <= num_bytes /\
num_bytes < length s * 16 + 16 /\
length bytes == 1
)
(ensures slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE t)) 0 num_bytes ==
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append s bytes))) 0 num_bytes) | let lemma_length_simplifier (s bytes t:seq quad32) (num_bytes:nat) : Lemma
(requires t == (if num_bytes > (length s) * 16 then append s bytes else s) /\
(num_bytes <= (length s) * 16 ==> num_bytes == (length s * 16)) /\
length s * 16 <= num_bytes /\
num_bytes < length s * 16 + 16 /\
length bytes == 1
)
(ensures slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE t)) 0 num_bytes ==
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append s bytes))) 0 num_bytes)
=
if num_bytes > (length s) * 16 then (
()
) else (
calc (==) {
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append s bytes))) 0 num_bytes;
== { append_distributes_be_seq_quad32_to_bytes s bytes }
slice (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE bytes))) 0 num_bytes;
== { Vale.Lib.Seqs.lemma_slice_first_exactly_in_append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE bytes)) }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s);
== { assert (length (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == num_bytes) }
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes;
};
()
) | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_BE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 536,
"start_col": 0,
"start_line": 513
} | module Vale.AES.GCM_BE
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.AES.GCM_BE_s
open Vale.AES.AES_BE_s
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.AES.GHash_BE_s
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open FStar.Calc
let upper3_equal (q0 q1:quad32) : bool =
q0.lo1 = q1.lo1 &&
q0.hi2 = q1.hi2 &&
q0.hi3 = q1.hi3
let lemma_be_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma
(requires slice b0 0 12 == slice b1 0 12)
(ensures upper3_equal (be_bytes_to_quad32 b0) (be_bytes_to_quad32 b1))
=
let q0 = be_bytes_to_quad32 b0 in
let q1 = be_bytes_to_quad32 b1 in
be_bytes_to_quad32_reveal ();
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #nat8);
assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\
index b1 i == index (slice b1 0 12) i))
let lemma_be_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma
(slice (be_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
=
assert (equal (slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
(slice (be_quad32_to_bytes q) 0 12));
()
let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_BE) (num_bytes:nat64) (h_BE j0:quad32) : Lemma
(requires
length iv_extra_b == 1 /\
length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\
num_bytes == 96/8 /\
(let iv_BE = index iv_extra_b 0 in
j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\
(let raw_quads = append iv_b iv_extra_b in
let iv_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 num_bytes in
iv_bytes == iv))
(ensures j0 == compute_iv_BE h_BE iv)
=
assert (length iv == 12);
assert (length iv_b == 0);
lemma_empty iv_b;
append_empty_l iv_extra_b;
assert (append iv_b iv_extra_b == iv_extra_b);
let q = index iv_extra_b 0 in
be_seq_quad32_to_bytes_of_singleton q;
assert (equal iv_extra_b (create 1 q));
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b) == be_quad32_to_bytes q);
calc (==) {
slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12;
== {}
slice (pad_to_128_bits iv) 0 12;
};
calc (==) {
be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b)) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits iv);
};
calc (==) {
j0;
== {}
set_to_one q;
== { be_bytes_to_quad32_to_bytes q }
set_to_one (be_bytes_to_quad32 (be_quad32_to_bytes q));
== {
lemma_be_seq_quad32_to_bytes_prefix_equality q;
lemma_be_bytes_to_quad32_prefix_equality
(be_quad32_to_bytes q)
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
}
set_to_one (be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)));
== { lemma_be_bytes_to_quad32_prefix_equality
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
(pad_to_128_bits iv) }
set_to_one (be_bytes_to_quad32 (pad_to_128_bits iv));
== {compute_iv_BE_reveal ()}
compute_iv_BE h_BE iv;
};
()
let lemma_compute_iv_hard (iv:supported_iv_BE) (quads:seq quad32) (length_quad h_BE j0:quad32) : Lemma
(requires
~(length iv == 96/8) /\
quads == be_bytes_to_seq_quad32 (pad_to_128_bits iv) /\
j0 == ghash_incremental h_BE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 0)
(nat_to_two 32 (8 * length iv))))
(ensures j0 == compute_iv_BE h_BE iv)
=
ghash_incremental_to_ghash h_BE (append quads (create 1 length_quad));
compute_iv_BE_reveal ();
()
let gcm_encrypt_BE_fst_helper (iv:supported_iv_BE) (iv_enc iv_BE:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma
(requires
is_aes_key_word alg key /\
length plain < pow2_32 /\
length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
iv_enc == inc32 (compute_iv_BE h_BE iv) 1 /\
cipher == gctr_encrypt iv_enc plain alg key
))
(ensures cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth))
=
gcm_encrypt_BE_reveal ()
let gcm_encrypt_BE_snd_helper (iv:supported_iv_BE) (j0_BE length_quad32 hash mac:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma
(requires
is_aes_key_word alg key /\
length plain < pow2_32 /\
length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth) /\
length_quad32 == two_two_to_four (Mktwo (nat_to_two 32 (8 * length auth)) (nat_to_two 32 (8 * length plain))) /\
(let auth_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits auth) in
let cipher_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits cipher) in
hash == ghash_BE h_BE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\
be_quad32_to_bytes mac == gctr_encrypt j0_BE (be_quad32_to_bytes hash) alg key)
))
(ensures be_quad32_to_bytes mac == snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth))
=
gcm_encrypt_BE_reveal ()
#reset-options "--z3rlimit 10"
let gcm_blocks_helper_enc (alg:algorithm) (key:seq nat32)
(p128 p_bytes c128 c_bytes:seq quad32)
(auth_bytes:seq nat8)
(p_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
(length auth_bytes) < pow2_32 /\
is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\
(let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2
)))
(ensures (let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
//cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key))
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes)))
=
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
gctr_partial_opaque_completed alg plain cipher key ctr_BE_2;
if p_num_bytes > length p128 * 16 then (
gctr_partial_reveal ();
assert (gctr_partial alg (length p128) plain cipher key ctr_BE_2);
assert (equal (slice plain 0 (length p128))
(slice p128 0 (length p128)));
assert (equal (slice cipher 0 (length p128))
(slice c128 0 (length p128)));
gctr_partial_opaque_ignores_postfix
alg (length p128)
plain p128
cipher c128
key ctr_BE_2;
assert (gctr_partial alg (length p128) p128 c128 key ctr_BE_2);
gctr_partial_opaque_completed alg p128 c128 key ctr_BE_2;
let num_blocks = p_num_bytes / 16 in
assert(index cipher num_blocks == quad32_xor (index plain num_blocks) (aes_encrypt_word alg key (inc32 ctr_BE_2 num_blocks)));
gctr_encrypt_block_offset ctr_BE_2 (index plain num_blocks) alg key num_blocks;
assert( gctr_encrypt_block ctr_BE_2 (index plain num_blocks) alg key num_blocks ==
gctr_encrypt_block (inc32 ctr_BE_2 num_blocks) (index plain num_blocks) alg key 0);
aes_encrypt_word_reveal ();
gctr_partial_to_full_advanced ctr_BE_2 plain cipher alg key p_num_bytes;
assert (cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key)
) else (
gctr_partial_to_full_basic ctr_BE_2 plain alg key cipher;
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher) == gctr_encrypt ctr_BE_2 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) alg key);
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
assert (equal plain_bytes (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)));
assert (equal cipher_bytes (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)));
assert (cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key)
);
gcm_encrypt_BE_fst_helper iv ctr_BE_2 j0_BE plain_bytes auth_bytes cipher_bytes alg key;
()
let slice_append_back (#a:Type) (x y:seq a) (i:nat) : Lemma
(requires length x <= i /\ i <= length x + length y)
(ensures slice (append x y) 0 i == append x (slice y 0 (i - length x)))
=
assert (equal (slice (append x y) 0 i) (append x (slice y 0 (i - length x))));
()
let append_distributes_be_seq_quad32_to_bytes (x y:seq quad32) :
Lemma (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append x y)) == append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE x)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE y)))
=
append_distributes_be_seq_quad32_to_bytes x y
let pad_to_128_bits_multiple_append (x y:seq nat8) : Lemma
(requires length x % 16 == 0)
(ensures pad_to_128_bits (append x y) == append x (pad_to_128_bits y))
=
assert (equal (pad_to_128_bits (append x y)) (append x (pad_to_128_bits y)))
#reset-options "--z3rlimit 100"
let gcm_blocks_helper (alg:algorithm) (key:seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes:seq quad32)
(p_num_bytes a_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE h enc_hash length_quad:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\
a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
length a_bytes == 1 /\
is_aes_key_word alg key /\
j0_BE = compute_iv_BE h iv /\
h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads c_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0
)))
(ensures (let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let plain_raw_quads =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else p128
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes) /\
be_quad32_to_bytes enc_hash ==
snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key)
iv plain_bytes auth_bytes)))
=
let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads c_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
let hash = ghash_BE h final_quads in
gcm_blocks_helper_enc alg key p128 p_bytes c128 c_bytes auth_input_bytes p_num_bytes iv j0_BE;
calc (==) {
enc_hash;
== {}
gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0;
== {}
gctr_encrypt_block ctr_BE_1 hash alg key 0;
== {}
quad32_xor hash (aes_encrypt_word alg key ctr_BE_1);
};
calc (==) {
gctr_encrypt ctr_BE_1 (be_quad32_to_bytes hash) alg key;
== { gctr_encrypt_one_block ctr_BE_1 hash alg key }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 (quad32_xor hash (aes_encrypt_word alg key ctr_BE_1))));
== {}
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 enc_hash));
== { be_seq_quad32_to_bytes_of_singleton enc_hash }
be_quad32_to_bytes enc_hash;
};
if p_num_bytes > length p128 * 16 then (
let c = append c128 c_bytes in
calc (==) {
append (append auth_quads c128) c_bytes;
== { append_assoc auth_quads c128 c_bytes }
append auth_quads (append c128 c_bytes);
== {}
append auth_quads c;
};
calc (==) {
append (append (append auth_quads c128) c_bytes) (create 1 length_quad);
= {} // See previous calc
append (append auth_quads (append c128 c_bytes)) (create 1 length_quad);
== { append_assoc auth_quads c (create 1 length_quad) }
append auth_quads (append c (create 1 length_quad));
};
let raw_quads_old = append auth_quads c in
calc (==) {
raw_quads;
== {}
be_bytes_to_seq_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes));
== {
calc (==) {
pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes);
== {
calc (==) {
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes;
== { append_distributes_be_seq_quad32_to_bytes auth_quads c }
slice (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))) 0 total_bytes;
== { slice_append_back (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))
total_bytes }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes);
== {}
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) cipher_bytes;
}
}
pad_to_128_bits (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) cipher_bytes);
== { pad_to_128_bits_multiple_append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) cipher_bytes }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (pad_to_128_bits cipher_bytes);
}
}
be_bytes_to_seq_quad32 (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (pad_to_128_bits cipher_bytes));
== { append_distributes_be_bytes_to_seq_quad32
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(pad_to_128_bits cipher_bytes) }
append (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))) (be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes));
== { be_bytes_to_seq_quad32_to_bytes auth_quads }
append auth_quads (be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes));
};
let auth_padded_quads' = be_bytes_to_seq_quad32 (pad_to_128_bits auth_input_bytes) in
let cipher_padded_quads' = be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes) in
calc (==) {
append raw_quads (create 1 length_quad);
== {}
append (append auth_quads (be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes))) (create 1 length_quad);
== { assert (equal auth_quads auth_padded_quads') }
append (append auth_padded_quads' cipher_padded_quads') (create 1 length_quad);
== { append_assoc auth_padded_quads' cipher_padded_quads' (create 1 length_quad) }
append auth_padded_quads' (append cipher_padded_quads' (create 1 length_quad));
};
gcm_encrypt_BE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key;
()
) else (
calc (==) {
append (append auth_quads c128) (create 1 length_quad);
== { append_assoc auth_quads c128 (create 1 length_quad) }
append auth_quads (append c128 (create 1 length_quad));
};
let c = c128 in
calc (==) {
be_bytes_to_seq_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes));
== { assert (equal (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes)) }
be_bytes_to_seq_quad32 (pad_to_128_bits (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)));
== { assert (pad_to_128_bits (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) == (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))) }
be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c));
== { be_bytes_to_seq_quad32_to_bytes c }
c;
};
gcm_encrypt_BE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key;
()
);
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.GHash_BE_s.fst.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.GCM_BE_s.fst.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_BE.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
t: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
num_bytes: Prims.nat
-> FStar.Pervasives.Lemma
(requires
t ==
(match num_bytes > FStar.Seq.Base.length s * 16 with
| true -> FStar.Seq.Base.append s bytes
| _ -> s) /\
(num_bytes <= FStar.Seq.Base.length s * 16 ==> num_bytes == FStar.Seq.Base.length s * 16) /\
FStar.Seq.Base.length s * 16 <= num_bytes /\ num_bytes < FStar.Seq.Base.length s * 16 + 16 /\
FStar.Seq.Base.length bytes == 1)
(ensures
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
t))
0
num_bytes ==
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
(FStar.Seq.Base.append s bytes)))
0
num_bytes) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.quad32",
"Prims.nat",
"Prims.op_GreaterThan",
"FStar.Mul.op_Star",
"FStar.Seq.Base.length",
"Prims.bool",
"Prims.unit",
"FStar.Calc.calc_finish",
"Vale.Def.Words_s.nat8",
"Prims.eq2",
"FStar.Seq.Base.slice",
"Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE",
"Vale.Def.Words.Seq_s.seq_four_to_seq_BE",
"Vale.Def.Types_s.nat32",
"FStar.Seq.Base.append",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Vale.AES.GCM_BE.append_distributes_be_seq_quad32_to_bytes",
"Prims.squash",
"Vale.Lib.Seqs.lemma_slice_first_exactly_in_append",
"Prims._assert",
"Prims.l_and",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.int",
"Prims.op_LessThan",
"Prims.op_Addition",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_length_simplifier (s bytes t: seq quad32) (num_bytes: nat)
: Lemma
(requires
t == (if num_bytes > (length s) * 16 then append s bytes else s) /\
(num_bytes <= (length s) * 16 ==> num_bytes == (length s * 16)) /\
length s * 16 <= num_bytes /\ num_bytes < length s * 16 + 16 /\ length bytes == 1)
(ensures
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE t)) 0 num_bytes ==
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append s bytes))) 0 num_bytes) =
| if num_bytes > (length s) * 16
then (())
else
(calc ( == ) {
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append s bytes))) 0 num_bytes;
( == ) { append_distributes_be_seq_quad32_to_bytes s bytes }
slice (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s))
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE bytes)))
0
num_bytes;
( == ) { Vale.Lib.Seqs.lemma_slice_first_exactly_in_append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE
s))
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE bytes)) }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s);
( == ) { assert (length (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == num_bytes) }
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes;
};
()) | false |
CDDL.Pulse.fst | CDDL.Pulse.impl_matches_map_group | val impl_matches_map_group : g: CDDL.Spec.map_group (FStar.Ghost.reveal b) -> Type0 | let impl_matches_map_group
(#b: Ghost.erased (option raw_data_item))
(g: map_group b)
=
c: cbor ->
(#p: perm) ->
(#v: Ghost.erased raw_data_item) ->
stt bool
(
raw_data_item_match p c v **
pure (opt_precedes (Ghost.reveal v) b /\ Map? v)
)
(fun res ->
raw_data_item_match p c v **
pure (opt_precedes (Ghost.reveal v) b /\ Map? v /\ res == matches_map_group g (Map?.v v))
) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Pulse.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 9,
"end_line": 762,
"start_col": 0,
"start_line": 747
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module CDDL.Pulse
open Pulse.Lib.Pervasives
open Pulse.Lib.Stick
open CBOR.Spec
open CBOR.Pulse
open CDDL.Spec
module R = Pulse.Lib.Reference
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_typ
(#b: option raw_data_item)
(t: bounded_typ_gen b)
=
(c: cbor) ->
(#p: perm) ->
(#v: Ghost.erased raw_data_item) ->
stt bool
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) b
))
(fun res -> raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) b /\
res == t v
))
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_coerce_to_bounded_typ
(b: Ghost.erased (option raw_data_item))
(#t: typ)
(f: impl_typ t)
: impl_typ #b (coerce_to_bounded_typ b t) // FIXME: WHY WHY WHY do I need to provide the implicit argument
= (c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
f c;
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_t_choice
(#b: Ghost.erased (option raw_data_item))
(#t1 #t2: bounded_typ_gen b)
(f1: impl_typ t1)
(f2: impl_typ t2)
: impl_typ #b (t_choice t1 t2)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let test = f1 c;
if (test)
{
true
} else {
f2 c
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_t_choice_none // FIXME: WHY WHY WHY can F* not automatically infer t1 and t2 by reducing (reveal (hide None)) to None?
(#t1 #t2: bounded_typ_gen None)
(f1: impl_typ t1)
(f2: impl_typ t2)
: Tot (impl_typ (t_choice t1 t2))
= impl_t_choice #None #t1 #t2 f1 f2
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_any
(_: unit)
: impl_typ #None any
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
true
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint
(_: unit)
: impl_typ #None uint
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
(mt = cbor_major_type_uint64)
}
```
module U64 = FStar.UInt64
(* FIXME: WHY WHY WHY does this one not work?
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint_literal
(n: U64.t)
: impl_typ #None (t_uint_literal n)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
if (mt = major_type_uint64) {
let i = cbor_destr_int64 c;
(i.cbor_int_value = n)
} else {
false
}
}
```
*)
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint_literal'
(n: U64.t)
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
requires
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) (None #raw_data_item)
))
returns res: bool
ensures
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) (None #raw_data_item) /\
res == t_uint_literal n v
))
{
let mt = cbor_get_major_type c;
if (mt = cbor_major_type_uint64) {
let i = cbor_destr_int64 c;
(i.cbor_int_value = n)
} else {
false
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_uint_literal
(n: U64.t)
: impl_typ (t_uint_literal n)
= impl_uint_literal' n
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_bytes
(_: unit)
: impl_typ #None bytes
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
(mt = cbor_major_type_byte_string)
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_array_group3
(#b: Ghost.erased (option raw_data_item))
(g: array_group3 b)
=
(pi: R.ref cbor_array_iterator_t) ->
(#p: perm) ->
(#i: Ghost.erased cbor_array_iterator_t) ->
(#l: Ghost.erased (list raw_data_item)) ->
stt bool
(R.pts_to pi i **
cbor_array_iterator_match p i l **
pure (opt_precedes (Ghost.reveal l) b)
)
(fun res -> exists* i' l'.
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
```pulse
ghost
fn intro_impl_array_group3_post
(#b: option raw_data_item)
(g: array_group3 b)
(pi: R.ref cbor_array_iterator_t)
(p: perm)
(i: cbor_array_iterator_t)
(l: list raw_data_item)
(res: bool)
(i': cbor_array_iterator_t)
(l': list raw_data_item)
requires
(
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
ensures
(exists* i' l'.
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
{
()
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_array_group3_concat
(#b: Ghost.erased (option raw_data_item))
(#g1: array_group3 b)
(f1: impl_array_group3 g1)
(#g2: array_group3 b)
(f2: impl_array_group3 g2)
: impl_array_group3 #b (array_group3_concat g1 g2)
=
(pi: R.ref cbor_array_iterator_t)
(#p: perm)
(#gi: Ghost.erased cbor_array_iterator_t)
(#l: Ghost.erased (list raw_data_item))
{
let test1 = f1 pi;
if (test1) {
let test2 = f2 pi;
stick_trans ();
test2
} else {
false
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_array_group3_item
(#b: Ghost.erased (option raw_data_item))
(#ty: bounded_typ_gen b)
(fty: impl_typ ty)
: impl_array_group3 #b (array_group3_item ty)
=
(pi: R.ref cbor_array_iterator_t)
(#p: perm)
(#gi: Ghost.erased cbor_array_iterator_t)
(#l: Ghost.erased (list raw_data_item))
{
let i = !pi;
rewrite (cbor_array_iterator_match p gi l) as (cbor_array_iterator_match p i l);
let is_done = cbor_array_iterator_is_done i;
rewrite (cbor_array_iterator_match p i l) as (cbor_array_iterator_match p gi l);
if (is_done) {
stick_refl0 (cbor_array_iterator_match p gi l);
intro_impl_array_group3_post (array_group3_item ty) pi p gi l false gi l; // FIXME: WHY WHY WHY? and also WHY WHY WHY here and not in the other "false" case below?
false
} else {
let c = cbor_array_iterator_next pi #p #l #gi; // FIXME: WHY WHY WHY those explicit arguments?
with gc i' l' . assert (
raw_data_item_match p c gc **
cbor_array_iterator_match p i' l' **
((raw_data_item_match p c gc ** cbor_array_iterator_match p i' l') @==> cbor_array_iterator_match p gi l)
); // this is needed for the explicit arguments to split_consume_l below
let test = fty c;
if (test) {
stick_consume_l ()
#(raw_data_item_match p c gc)
#(cbor_array_iterator_match p i' l')
#(cbor_array_iterator_match p gi l) // FIXME: WHY WHY WHY those explicit arguments? (for which the with above is needed)
;
true
} else {
elim_stick0 ()
#(raw_data_item_match p c gc ** cbor_array_iterator_match p i' l')
#(cbor_array_iterator_match p gi l); // FIXME: WHY WHY WHY those explicit arguments?
pi := i;
rewrite (R.pts_to pi i) as (R.pts_to pi gi);
stick_refl0 (cbor_array_iterator_match p gi l);
false
}
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_t_array
(#b: Ghost.erased (option raw_data_item))
(#g: (array_group3 b))
(ig: (impl_array_group3 (g)))
: impl_typ #b (t_array3 g)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let ty = cbor_get_major_type c;
if (ty = cbor_major_type_array) {
let i = cbor_array_iterator_init c;
with l . assert (cbor_array_iterator_match p i l);
rewrite (cbor_array_iterator_match p i l) as (cbor_array_iterator_match p (Ghost.reveal (Ghost.hide i)) l);
let mut pi = i;
let b_success = ig pi;
with gi' l' . assert (cbor_array_iterator_match p gi' l');
let i' = ! pi;
rewrite (cbor_array_iterator_match p gi' l') as (cbor_array_iterator_match p i' l');
let b_end = cbor_array_iterator_is_done i';
rewrite (cbor_array_iterator_match p i' l') as (cbor_array_iterator_match p gi' l');
elim_stick0 ();
rewrite (cbor_array_iterator_match p (Ghost.reveal (Ghost.hide i)) l) as (cbor_array_iterator_match p i l);
elim_stick0 ();
(b_success && b_end)
} else {
false
}
}
```
module U8 = FStar.UInt8
noextract [@@noextract_to "krml"]
let cbor_read_with_typ_success_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Tot prop
=
cbor_read_success_postcond va c v rem /\
t v == true
module A = Pulse.Lib.Array
let cbor_read_with_typ_success_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
: Tot vprop
= exists* v rem.
raw_data_item_match full_perm c.cbor_read_payload v **
A.pts_to c.cbor_read_remainder #p rem **
((raw_data_item_match full_perm c.cbor_read_payload v ** A.pts_to c.cbor_read_remainder #p rem) @==>
A.pts_to a #p va) **
pure (cbor_read_with_typ_success_postcond t va c v rem)
noextract [@@noextract_to "krml"]
let cbor_read_with_typ_error_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
: Tot prop
= forall v suff .
Ghost.reveal va == serialize_cbor v `Seq.append` suff ==>
t v == false
let cbor_read_with_typ_error_postcond_intro_typ_fail
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Lemma
(requires (
cbor_read_success_postcond va c v rem /\
t v == false
))
(ensures (
cbor_read_with_typ_error_postcond t va
))
= serialize_cbor_with_test_correct v rem (fun v' rem' -> t v' == true)
let cbor_read_with_typ_error_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
: Tot vprop
= A.pts_to a #p va ** pure (cbor_read_with_typ_error_postcond t va)
let cbor_read_with_typ_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(res: cbor_read_t)
: Tot vprop
= if res.cbor_read_is_success
then cbor_read_with_typ_success_post t a p va res
else cbor_read_with_typ_error_post t a p va
module SZ = FStar.SizeT
inline_for_extraction noextract
let mk_cbor_read_error
(res: cbor_read_t)
: Tot cbor_read_t
= {res with cbor_read_is_success = false}
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn cbor_read_with_typ
(#t: typ)
(ft: impl_typ t)
(a: A.array U8.t)
(sz: SZ.t)
(#va: Ghost.erased (Seq.seq U8.t))
(#p: perm)
requires
(A.pts_to a #p va ** pure (
(SZ.v sz == Seq.length va \/ SZ.v sz == A.length a)
))
returns res: cbor_read_t
ensures cbor_read_with_typ_post t a p va res
{
let res = cbor_read a sz;
if (res.cbor_read_is_success) {
rewrite (cbor_read_post a p va res) as (cbor_read_success_post a p va res);
unfold (cbor_read_success_post a p va res);
let test = ft res.cbor_read_payload;
if (test) {
fold (cbor_read_with_typ_success_post t a p va res);
rewrite (cbor_read_with_typ_success_post t a p va res) as (cbor_read_with_typ_post t a p va res);
res
} else {
with v . assert (raw_data_item_match full_perm res.cbor_read_payload v);
with vrem . assert (A.pts_to res.cbor_read_remainder #p vrem);
cbor_read_with_typ_error_postcond_intro_typ_fail t va res v vrem;
elim_stick0 ()
#(raw_data_item_match full_perm res.cbor_read_payload v ** A.pts_to res.cbor_read_remainder #p vrem);
fold (cbor_read_with_typ_error_post t a p va);
let res = mk_cbor_read_error res;
rewrite (cbor_read_with_typ_error_post t a p va) as (cbor_read_with_typ_post t a p va res);
res
}
} else {
rewrite (cbor_read_post a p va res) as (cbor_read_error_post a p va);
unfold (cbor_read_error_post a p va);
fold (cbor_read_with_typ_error_post t a p va);
rewrite (cbor_read_with_typ_error_post t a p va) as (cbor_read_with_typ_post t a p va res);
res
}
}
```
noextract [@@noextract_to "krml"]
let cbor_read_deterministically_encoded_with_typ_success_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Tot prop
=
cbor_read_deterministically_encoded_success_postcond va c v rem /\
t v == true
noextract [@@noextract_to "krml"]
let cbor_read_deterministically_encoded_with_typ_error_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
: Tot prop
= forall v suff .
(Ghost.reveal va == serialize_cbor v `Seq.append` suff /\
data_item_wf deterministically_encoded_cbor_map_key_order v == true
) ==>
t v == false
let cbor_read_deterministically_encoded_with_typ_error_postcond_intro_typ_fail
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Lemma
(requires (
cbor_read_deterministically_encoded_success_postcond va c v rem /\
t v == false
))
(ensures (
cbor_read_deterministically_encoded_with_typ_error_postcond t va
))
= serialize_cbor_with_test_correct v rem (fun v' rem' -> data_item_wf deterministically_encoded_cbor_map_key_order v' == true /\ t v' == true)
let cbor_read_deterministically_encoded_with_typ_success_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(res: cbor_read_t)
: Tot vprop
= exists* v rem.
raw_data_item_match full_perm res.cbor_read_payload v **
A.pts_to res.cbor_read_remainder #p rem **
((raw_data_item_match full_perm res.cbor_read_payload v ** A.pts_to res.cbor_read_remainder #p rem) @==>
A.pts_to a #p va) **
pure (cbor_read_deterministically_encoded_with_typ_success_postcond t va res v rem)
let cbor_read_deterministically_encoded_with_typ_error_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
: Tot vprop
= A.pts_to a #p va ** pure (cbor_read_deterministically_encoded_with_typ_error_postcond t va)
let cbor_read_deterministically_encoded_with_typ_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(res: cbor_read_t)
: Tot vprop
= if res.cbor_read_is_success
then cbor_read_deterministically_encoded_with_typ_success_post t a p va res
else cbor_read_deterministically_encoded_with_typ_error_post t a p va
module SZ = FStar.SizeT
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn cbor_read_deterministically_encoded_with_typ
(#t: typ)
(ft: impl_typ t)
(a: A.array U8.t)
(sz: SZ.t)
(#va: Ghost.erased (Seq.seq U8.t))
(#p: perm)
requires
(A.pts_to a #p va ** pure (
(SZ.v sz == Seq.length va \/ SZ.v sz == A.length a)
))
returns res: cbor_read_t
ensures cbor_read_deterministically_encoded_with_typ_post t a p va res
{
let res = cbor_read_deterministically_encoded a sz;
if (res.cbor_read_is_success) {
rewrite (cbor_read_deterministically_encoded_post a p va res) as (cbor_read_deterministically_encoded_success_post a p va res);
unfold (cbor_read_deterministically_encoded_success_post a p va res);
let test = ft res.cbor_read_payload;
if (test) {
fold (cbor_read_deterministically_encoded_with_typ_success_post t a p va res);
fold (cbor_read_deterministically_encoded_with_typ_post t a p va res);
res
} else {
with v . assert (raw_data_item_match full_perm res.cbor_read_payload v);
with vrem . assert (A.pts_to res.cbor_read_remainder #p vrem);
cbor_read_deterministically_encoded_with_typ_error_postcond_intro_typ_fail t va res v vrem;
elim_stick0 ()
#(raw_data_item_match full_perm res.cbor_read_payload v ** A.pts_to res.cbor_read_remainder #p vrem);
let res = mk_cbor_read_error res;
fold (cbor_read_deterministically_encoded_with_typ_error_post t a p va);
fold (cbor_read_deterministically_encoded_with_typ_post t a p va res);
res
}
} else {
rewrite (cbor_read_deterministically_encoded_post a p va res) as (cbor_read_deterministically_encoded_error_post a p va);
unfold (cbor_read_deterministically_encoded_error_post a p va);
fold (cbor_read_deterministically_encoded_with_typ_error_post t a p va);
fold (cbor_read_deterministically_encoded_with_typ_post t a p va res);
res
}
}
```
noextract
let cbor_map_get_with_typ_post_found
(t: typ)
(vkey: raw_data_item)
(vmap: raw_data_item)
(vvalue: raw_data_item)
: Tot prop
= Map? vmap /\
list_ghost_assoc vkey (Map?.v vmap) == Some vvalue /\
t vvalue == true
let cbor_map_get_with_typ_post
(t: typ)
(p: perm)
(vkey: raw_data_item)
(vmap: raw_data_item)
(map: cbor)
(res: cbor_map_get_t)
: Tot vprop
= match res with
| NotFound ->
raw_data_item_match p map vmap ** pure (
Map? vmap /\
begin match list_ghost_assoc vkey (Map?.v vmap) with
| None -> True
| Some v -> t v == false
end
)
| Found value ->
exists* vvalue.
raw_data_item_match p value vvalue **
(raw_data_item_match p value vvalue @==> raw_data_item_match p map vmap) **
pure (cbor_map_get_with_typ_post_found t vkey vmap vvalue)
let cbor_map_get_post_eq_found
(p: perm)
(vkey: raw_data_item)
(vmap: raw_data_item)
(map: cbor)
(res: cbor_map_get_t)
(fres: cbor)
: Lemma
(requires (res == Found fres))
(ensures (
cbor_map_get_post p vkey vmap map res ==
cbor_map_get_post_found p vkey vmap map fres
))
= ()
```pulse
ghost
fn manurewrite
(pre post: vprop)
requires
pre ** pure (pre == post)
ensures
post
{
rewrite pre as post
}
```
```pulse
ghost
fn cbor_map_get_found_elim
(p: perm)
(vkey: Ghost.erased raw_data_item)
(vmap: Ghost.erased raw_data_item)
(map: cbor)
(res: cbor_map_get_t)
(fres: cbor)
requires
cbor_map_get_post p vkey vmap map res **
pure (res == Found fres)
ensures
cbor_map_get_post_found p vkey vmap map fres
{
manurewrite (cbor_map_get_post p vkey vmap map res) (cbor_map_get_post_found p vkey vmap map fres)
// rewrite ... as ... fails: WHY WHY WHY??
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn cbor_map_get_with_typ
(#t: typ)
(ft: impl_typ t)
(key: cbor)
(map: cbor)
(#pkey: perm)
(#vkey: Ghost.erased raw_data_item)
(#pmap: perm)
(#vmap: Ghost.erased raw_data_item)
requires
(raw_data_item_match pkey key vkey ** raw_data_item_match pmap map vmap ** pure (
Map? vmap /\
(~ (Tagged? vkey \/ Array? vkey \/ Map? vkey))
))
returns res: cbor_map_get_t
ensures
(raw_data_item_match pkey key vkey ** cbor_map_get_with_typ_post t pmap vkey vmap map res ** pure (
Map? vmap /\
Found? res == begin match list_ghost_assoc (Ghost.reveal vkey) (Map?.v vmap) with
| None -> false
| Some v -> t v
end
))
{
let res = cbor_map_get key map;
if (Found? res) {
let fres = Found?._0 res;
manurewrite (cbor_map_get_post pmap vkey vmap map res) (cbor_map_get_post_found pmap vkey vmap map fres);
unfold (cbor_map_get_post_found pmap vkey vmap map fres);
let test = ft fres;
if (test) {
fold (cbor_map_get_with_typ_post t pmap vkey vmap map (Found fres));
res
} else {
elim_stick0 ();
fold (cbor_map_get_with_typ_post t pmap vkey vmap map NotFound);
NotFound
}
} else {
rewrite (cbor_map_get_post pmap vkey vmap map res) as (cbor_map_get_post_not_found pmap vkey vmap map);
unfold (cbor_map_get_post_not_found pmap vkey vmap map);
fold (cbor_map_get_with_typ_post t pmap vkey vmap map NotFound);
res
}
}
``` | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Stick.fsti.checked",
"Pulse.Lib.Reference.fsti.checked",
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"CDDL.Spec.fsti.checked",
"CBOR.Spec.fsti.checked",
"CBOR.Pulse.fst.checked"
],
"interface_file": false,
"source_file": "CDDL.Pulse.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Reference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "CDDL.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Stick",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: CDDL.Spec.map_group (FStar.Ghost.reveal b) -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.map_group",
"FStar.Ghost.reveal",
"CBOR.Pulse.Type.cbor",
"PulseCore.FractionalPermission.perm",
"Pulse.Lib.Core.stt",
"Prims.bool",
"Pulse.Lib.Core.op_Star_Star",
"CBOR.Pulse.Extern.raw_data_item_match",
"Pulse.Lib.Core.pure",
"Prims.l_and",
"CDDL.Spec.opt_precedes",
"Prims.b2t",
"CBOR.Spec.Type.uu___is_Map",
"Prims.eq2",
"CDDL.Spec.matches_map_group",
"CBOR.Spec.Type.__proj__Map__item__v",
"Pulse.Lib.Core.vprop"
] | [] | false | false | false | false | true | let impl_matches_map_group (#b: Ghost.erased (option raw_data_item)) (g: map_group b) =
| c: cbor -> #p: perm -> #v: Ghost.erased raw_data_item
-> stt bool
(raw_data_item_match p c v ** pure (opt_precedes (Ghost.reveal v) b /\ Map? v))
(fun res ->
raw_data_item_match p c v **
pure (opt_precedes (Ghost.reveal v) b /\ Map? v /\ res == matches_map_group g (Map?.v v))) | false |
|
CDDL.Pulse.fst | CDDL.Pulse.cbor_map_get_with_typ_post | val cbor_map_get_with_typ_post
(t: typ)
(p: perm)
(vkey vmap: raw_data_item)
(map: cbor)
(res: cbor_map_get_t)
: Tot vprop | val cbor_map_get_with_typ_post
(t: typ)
(p: perm)
(vkey vmap: raw_data_item)
(map: cbor)
(res: cbor_map_get_t)
: Tot vprop | let cbor_map_get_with_typ_post
(t: typ)
(p: perm)
(vkey: raw_data_item)
(vmap: raw_data_item)
(map: cbor)
(res: cbor_map_get_t)
: Tot vprop
= match res with
| NotFound ->
raw_data_item_match p map vmap ** pure (
Map? vmap /\
begin match list_ghost_assoc vkey (Map?.v vmap) with
| None -> True
| Some v -> t v == false
end
)
| Found value ->
exists* vvalue.
raw_data_item_match p value vvalue **
(raw_data_item_match p value vvalue @==> raw_data_item_match p map vmap) **
pure (cbor_map_get_with_typ_post_found t vkey vmap vvalue) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Pulse.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 66,
"end_line": 646,
"start_col": 0,
"start_line": 625
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module CDDL.Pulse
open Pulse.Lib.Pervasives
open Pulse.Lib.Stick
open CBOR.Spec
open CBOR.Pulse
open CDDL.Spec
module R = Pulse.Lib.Reference
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_typ
(#b: option raw_data_item)
(t: bounded_typ_gen b)
=
(c: cbor) ->
(#p: perm) ->
(#v: Ghost.erased raw_data_item) ->
stt bool
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) b
))
(fun res -> raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) b /\
res == t v
))
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_coerce_to_bounded_typ
(b: Ghost.erased (option raw_data_item))
(#t: typ)
(f: impl_typ t)
: impl_typ #b (coerce_to_bounded_typ b t) // FIXME: WHY WHY WHY do I need to provide the implicit argument
= (c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
f c;
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_t_choice
(#b: Ghost.erased (option raw_data_item))
(#t1 #t2: bounded_typ_gen b)
(f1: impl_typ t1)
(f2: impl_typ t2)
: impl_typ #b (t_choice t1 t2)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let test = f1 c;
if (test)
{
true
} else {
f2 c
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_t_choice_none // FIXME: WHY WHY WHY can F* not automatically infer t1 and t2 by reducing (reveal (hide None)) to None?
(#t1 #t2: bounded_typ_gen None)
(f1: impl_typ t1)
(f2: impl_typ t2)
: Tot (impl_typ (t_choice t1 t2))
= impl_t_choice #None #t1 #t2 f1 f2
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_any
(_: unit)
: impl_typ #None any
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
true
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint
(_: unit)
: impl_typ #None uint
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
(mt = cbor_major_type_uint64)
}
```
module U64 = FStar.UInt64
(* FIXME: WHY WHY WHY does this one not work?
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint_literal
(n: U64.t)
: impl_typ #None (t_uint_literal n)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
if (mt = major_type_uint64) {
let i = cbor_destr_int64 c;
(i.cbor_int_value = n)
} else {
false
}
}
```
*)
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_uint_literal'
(n: U64.t)
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
requires
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) (None #raw_data_item)
))
returns res: bool
ensures
(raw_data_item_match p c v ** pure (
opt_precedes (Ghost.reveal v) (None #raw_data_item) /\
res == t_uint_literal n v
))
{
let mt = cbor_get_major_type c;
if (mt = cbor_major_type_uint64) {
let i = cbor_destr_int64 c;
(i.cbor_int_value = n)
} else {
false
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_uint_literal
(n: U64.t)
: impl_typ (t_uint_literal n)
= impl_uint_literal' n
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_bytes
(_: unit)
: impl_typ #None bytes
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let mt = cbor_get_major_type c;
(mt = cbor_major_type_byte_string)
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
let impl_array_group3
(#b: Ghost.erased (option raw_data_item))
(g: array_group3 b)
=
(pi: R.ref cbor_array_iterator_t) ->
(#p: perm) ->
(#i: Ghost.erased cbor_array_iterator_t) ->
(#l: Ghost.erased (list raw_data_item)) ->
stt bool
(R.pts_to pi i **
cbor_array_iterator_match p i l **
pure (opt_precedes (Ghost.reveal l) b)
)
(fun res -> exists* i' l'.
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
```pulse
ghost
fn intro_impl_array_group3_post
(#b: option raw_data_item)
(g: array_group3 b)
(pi: R.ref cbor_array_iterator_t)
(p: perm)
(i: cbor_array_iterator_t)
(l: list raw_data_item)
(res: bool)
(i': cbor_array_iterator_t)
(l': list raw_data_item)
requires
(
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
ensures
(exists* i' l'.
R.pts_to pi i' **
cbor_array_iterator_match p i' l' **
(cbor_array_iterator_match p i' l' @==> cbor_array_iterator_match p i l) **
pure (
opt_precedes (Ghost.reveal l) b /\
res == Some? (g l) /\
(res == true ==> Some?.v (g l) == l')
)
)
{
()
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_array_group3_concat
(#b: Ghost.erased (option raw_data_item))
(#g1: array_group3 b)
(f1: impl_array_group3 g1)
(#g2: array_group3 b)
(f2: impl_array_group3 g2)
: impl_array_group3 #b (array_group3_concat g1 g2)
=
(pi: R.ref cbor_array_iterator_t)
(#p: perm)
(#gi: Ghost.erased cbor_array_iterator_t)
(#l: Ghost.erased (list raw_data_item))
{
let test1 = f1 pi;
if (test1) {
let test2 = f2 pi;
stick_trans ();
test2
} else {
false
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_array_group3_item
(#b: Ghost.erased (option raw_data_item))
(#ty: bounded_typ_gen b)
(fty: impl_typ ty)
: impl_array_group3 #b (array_group3_item ty)
=
(pi: R.ref cbor_array_iterator_t)
(#p: perm)
(#gi: Ghost.erased cbor_array_iterator_t)
(#l: Ghost.erased (list raw_data_item))
{
let i = !pi;
rewrite (cbor_array_iterator_match p gi l) as (cbor_array_iterator_match p i l);
let is_done = cbor_array_iterator_is_done i;
rewrite (cbor_array_iterator_match p i l) as (cbor_array_iterator_match p gi l);
if (is_done) {
stick_refl0 (cbor_array_iterator_match p gi l);
intro_impl_array_group3_post (array_group3_item ty) pi p gi l false gi l; // FIXME: WHY WHY WHY? and also WHY WHY WHY here and not in the other "false" case below?
false
} else {
let c = cbor_array_iterator_next pi #p #l #gi; // FIXME: WHY WHY WHY those explicit arguments?
with gc i' l' . assert (
raw_data_item_match p c gc **
cbor_array_iterator_match p i' l' **
((raw_data_item_match p c gc ** cbor_array_iterator_match p i' l') @==> cbor_array_iterator_match p gi l)
); // this is needed for the explicit arguments to split_consume_l below
let test = fty c;
if (test) {
stick_consume_l ()
#(raw_data_item_match p c gc)
#(cbor_array_iterator_match p i' l')
#(cbor_array_iterator_match p gi l) // FIXME: WHY WHY WHY those explicit arguments? (for which the with above is needed)
;
true
} else {
elim_stick0 ()
#(raw_data_item_match p c gc ** cbor_array_iterator_match p i' l')
#(cbor_array_iterator_match p gi l); // FIXME: WHY WHY WHY those explicit arguments?
pi := i;
rewrite (R.pts_to pi i) as (R.pts_to pi gi);
stick_refl0 (cbor_array_iterator_match p gi l);
false
}
}
}
```
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn impl_t_array
(#b: Ghost.erased (option raw_data_item))
(#g: (array_group3 b))
(ig: (impl_array_group3 (g)))
: impl_typ #b (t_array3 g)
=
(c: cbor)
(#p: perm)
(#v: Ghost.erased raw_data_item)
{
let ty = cbor_get_major_type c;
if (ty = cbor_major_type_array) {
let i = cbor_array_iterator_init c;
with l . assert (cbor_array_iterator_match p i l);
rewrite (cbor_array_iterator_match p i l) as (cbor_array_iterator_match p (Ghost.reveal (Ghost.hide i)) l);
let mut pi = i;
let b_success = ig pi;
with gi' l' . assert (cbor_array_iterator_match p gi' l');
let i' = ! pi;
rewrite (cbor_array_iterator_match p gi' l') as (cbor_array_iterator_match p i' l');
let b_end = cbor_array_iterator_is_done i';
rewrite (cbor_array_iterator_match p i' l') as (cbor_array_iterator_match p gi' l');
elim_stick0 ();
rewrite (cbor_array_iterator_match p (Ghost.reveal (Ghost.hide i)) l) as (cbor_array_iterator_match p i l);
elim_stick0 ();
(b_success && b_end)
} else {
false
}
}
```
module U8 = FStar.UInt8
noextract [@@noextract_to "krml"]
let cbor_read_with_typ_success_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Tot prop
=
cbor_read_success_postcond va c v rem /\
t v == true
module A = Pulse.Lib.Array
let cbor_read_with_typ_success_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
: Tot vprop
= exists* v rem.
raw_data_item_match full_perm c.cbor_read_payload v **
A.pts_to c.cbor_read_remainder #p rem **
((raw_data_item_match full_perm c.cbor_read_payload v ** A.pts_to c.cbor_read_remainder #p rem) @==>
A.pts_to a #p va) **
pure (cbor_read_with_typ_success_postcond t va c v rem)
noextract [@@noextract_to "krml"]
let cbor_read_with_typ_error_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
: Tot prop
= forall v suff .
Ghost.reveal va == serialize_cbor v `Seq.append` suff ==>
t v == false
let cbor_read_with_typ_error_postcond_intro_typ_fail
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Lemma
(requires (
cbor_read_success_postcond va c v rem /\
t v == false
))
(ensures (
cbor_read_with_typ_error_postcond t va
))
= serialize_cbor_with_test_correct v rem (fun v' rem' -> t v' == true)
let cbor_read_with_typ_error_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
: Tot vprop
= A.pts_to a #p va ** pure (cbor_read_with_typ_error_postcond t va)
let cbor_read_with_typ_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(res: cbor_read_t)
: Tot vprop
= if res.cbor_read_is_success
then cbor_read_with_typ_success_post t a p va res
else cbor_read_with_typ_error_post t a p va
module SZ = FStar.SizeT
inline_for_extraction noextract
let mk_cbor_read_error
(res: cbor_read_t)
: Tot cbor_read_t
= {res with cbor_read_is_success = false}
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn cbor_read_with_typ
(#t: typ)
(ft: impl_typ t)
(a: A.array U8.t)
(sz: SZ.t)
(#va: Ghost.erased (Seq.seq U8.t))
(#p: perm)
requires
(A.pts_to a #p va ** pure (
(SZ.v sz == Seq.length va \/ SZ.v sz == A.length a)
))
returns res: cbor_read_t
ensures cbor_read_with_typ_post t a p va res
{
let res = cbor_read a sz;
if (res.cbor_read_is_success) {
rewrite (cbor_read_post a p va res) as (cbor_read_success_post a p va res);
unfold (cbor_read_success_post a p va res);
let test = ft res.cbor_read_payload;
if (test) {
fold (cbor_read_with_typ_success_post t a p va res);
rewrite (cbor_read_with_typ_success_post t a p va res) as (cbor_read_with_typ_post t a p va res);
res
} else {
with v . assert (raw_data_item_match full_perm res.cbor_read_payload v);
with vrem . assert (A.pts_to res.cbor_read_remainder #p vrem);
cbor_read_with_typ_error_postcond_intro_typ_fail t va res v vrem;
elim_stick0 ()
#(raw_data_item_match full_perm res.cbor_read_payload v ** A.pts_to res.cbor_read_remainder #p vrem);
fold (cbor_read_with_typ_error_post t a p va);
let res = mk_cbor_read_error res;
rewrite (cbor_read_with_typ_error_post t a p va) as (cbor_read_with_typ_post t a p va res);
res
}
} else {
rewrite (cbor_read_post a p va res) as (cbor_read_error_post a p va);
unfold (cbor_read_error_post a p va);
fold (cbor_read_with_typ_error_post t a p va);
rewrite (cbor_read_with_typ_error_post t a p va) as (cbor_read_with_typ_post t a p va res);
res
}
}
```
noextract [@@noextract_to "krml"]
let cbor_read_deterministically_encoded_with_typ_success_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Tot prop
=
cbor_read_deterministically_encoded_success_postcond va c v rem /\
t v == true
noextract [@@noextract_to "krml"]
let cbor_read_deterministically_encoded_with_typ_error_postcond
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
: Tot prop
= forall v suff .
(Ghost.reveal va == serialize_cbor v `Seq.append` suff /\
data_item_wf deterministically_encoded_cbor_map_key_order v == true
) ==>
t v == false
let cbor_read_deterministically_encoded_with_typ_error_postcond_intro_typ_fail
(t: typ)
(va: Ghost.erased (Seq.seq U8.t))
(c: cbor_read_t)
(v: raw_data_item)
(rem: Seq.seq U8.t)
: Lemma
(requires (
cbor_read_deterministically_encoded_success_postcond va c v rem /\
t v == false
))
(ensures (
cbor_read_deterministically_encoded_with_typ_error_postcond t va
))
= serialize_cbor_with_test_correct v rem (fun v' rem' -> data_item_wf deterministically_encoded_cbor_map_key_order v' == true /\ t v' == true)
let cbor_read_deterministically_encoded_with_typ_success_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(res: cbor_read_t)
: Tot vprop
= exists* v rem.
raw_data_item_match full_perm res.cbor_read_payload v **
A.pts_to res.cbor_read_remainder #p rem **
((raw_data_item_match full_perm res.cbor_read_payload v ** A.pts_to res.cbor_read_remainder #p rem) @==>
A.pts_to a #p va) **
pure (cbor_read_deterministically_encoded_with_typ_success_postcond t va res v rem)
let cbor_read_deterministically_encoded_with_typ_error_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
: Tot vprop
= A.pts_to a #p va ** pure (cbor_read_deterministically_encoded_with_typ_error_postcond t va)
let cbor_read_deterministically_encoded_with_typ_post
(t: typ)
(a: A.array U8.t)
(p: perm)
(va: Ghost.erased (Seq.seq U8.t))
(res: cbor_read_t)
: Tot vprop
= if res.cbor_read_is_success
then cbor_read_deterministically_encoded_with_typ_success_post t a p va res
else cbor_read_deterministically_encoded_with_typ_error_post t a p va
module SZ = FStar.SizeT
inline_for_extraction noextract [@@noextract_to "krml"]
```pulse
fn cbor_read_deterministically_encoded_with_typ
(#t: typ)
(ft: impl_typ t)
(a: A.array U8.t)
(sz: SZ.t)
(#va: Ghost.erased (Seq.seq U8.t))
(#p: perm)
requires
(A.pts_to a #p va ** pure (
(SZ.v sz == Seq.length va \/ SZ.v sz == A.length a)
))
returns res: cbor_read_t
ensures cbor_read_deterministically_encoded_with_typ_post t a p va res
{
let res = cbor_read_deterministically_encoded a sz;
if (res.cbor_read_is_success) {
rewrite (cbor_read_deterministically_encoded_post a p va res) as (cbor_read_deterministically_encoded_success_post a p va res);
unfold (cbor_read_deterministically_encoded_success_post a p va res);
let test = ft res.cbor_read_payload;
if (test) {
fold (cbor_read_deterministically_encoded_with_typ_success_post t a p va res);
fold (cbor_read_deterministically_encoded_with_typ_post t a p va res);
res
} else {
with v . assert (raw_data_item_match full_perm res.cbor_read_payload v);
with vrem . assert (A.pts_to res.cbor_read_remainder #p vrem);
cbor_read_deterministically_encoded_with_typ_error_postcond_intro_typ_fail t va res v vrem;
elim_stick0 ()
#(raw_data_item_match full_perm res.cbor_read_payload v ** A.pts_to res.cbor_read_remainder #p vrem);
let res = mk_cbor_read_error res;
fold (cbor_read_deterministically_encoded_with_typ_error_post t a p va);
fold (cbor_read_deterministically_encoded_with_typ_post t a p va res);
res
}
} else {
rewrite (cbor_read_deterministically_encoded_post a p va res) as (cbor_read_deterministically_encoded_error_post a p va);
unfold (cbor_read_deterministically_encoded_error_post a p va);
fold (cbor_read_deterministically_encoded_with_typ_error_post t a p va);
fold (cbor_read_deterministically_encoded_with_typ_post t a p va res);
res
}
}
```
noextract
let cbor_map_get_with_typ_post_found
(t: typ)
(vkey: raw_data_item)
(vmap: raw_data_item)
(vvalue: raw_data_item)
: Tot prop
= Map? vmap /\
list_ghost_assoc vkey (Map?.v vmap) == Some vvalue /\
t vvalue == true | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Stick.fsti.checked",
"Pulse.Lib.Reference.fsti.checked",
"Pulse.Lib.Pervasives.fst.checked",
"Pulse.Lib.Array.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Ghost.fsti.checked",
"CDDL.Spec.fsti.checked",
"CBOR.Spec.fsti.checked",
"CBOR.Pulse.fst.checked"
],
"interface_file": false,
"source_file": "CDDL.Pulse.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "Pulse.Lib.Reference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "CDDL.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Stick",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t: CDDL.Spec.typ ->
p: PulseCore.FractionalPermission.perm ->
vkey: CBOR.Spec.Type.raw_data_item ->
vmap: CBOR.Spec.Type.raw_data_item ->
map: CBOR.Pulse.Type.cbor ->
res: CBOR.Pulse.cbor_map_get_t
-> Pulse.Lib.Core.vprop | Prims.Tot | [
"total"
] | [] | [
"CDDL.Spec.typ",
"PulseCore.FractionalPermission.perm",
"CBOR.Spec.Type.raw_data_item",
"CBOR.Pulse.Type.cbor",
"CBOR.Pulse.cbor_map_get_t",
"Pulse.Lib.Core.op_Star_Star",
"CBOR.Pulse.Extern.raw_data_item_match",
"Pulse.Lib.Core.pure",
"Prims.l_and",
"Prims.b2t",
"CBOR.Spec.Type.uu___is_Map",
"CBOR.Pulse.list_ghost_assoc",
"CBOR.Spec.Type.__proj__Map__item__v",
"Prims.l_True",
"Prims.eq2",
"Prims.bool",
"Prims.logical",
"Pulse.Lib.Core.op_exists_Star",
"Pulse.Lib.Stick.op_At_Equals_Equals_Greater",
"CDDL.Pulse.cbor_map_get_with_typ_post_found",
"Pulse.Lib.Core.vprop"
] | [] | false | false | false | true | false | let cbor_map_get_with_typ_post
(t: typ)
(p: perm)
(vkey vmap: raw_data_item)
(map: cbor)
(res: cbor_map_get_t)
: Tot vprop =
| match res with
| NotFound ->
raw_data_item_match p map vmap **
pure (Map? vmap /\
(match list_ghost_assoc vkey (Map?.v vmap) with
| None -> True
| Some v -> t v == false))
| Found value ->
exists* vvalue.
(raw_data_item_match p value vvalue **
(raw_data_item_match p value vvalue @==> raw_data_item_match p map vmap)) **
pure (cbor_map_get_with_typ_post_found t vkey vmap vvalue) | false |
Pulse.C.Types.Base.fsti | Pulse.C.Types.Base.ref | val ref (#t: Type) (td: typedef t) : Tot Type0 | val ref (#t: Type) (td: typedef t) : Tot Type0 | let ref (#t: Type) (td: typedef t) : Tot Type0 = (p: ptr td { ~ (p == null td) }) | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Base.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 81,
"end_line": 99,
"start_col": 0,
"start_line": 99
} | module Pulse.C.Types.Base
open Pulse.Lib.Pervasives
/// Helper to compose two permissions into one
val prod_perm (p1 p2: perm) : Pure perm
(requires True)
(ensures (fun p ->
((p1 `lesser_equal_perm` full_perm /\ p2 `lesser_equal_perm` full_perm) ==>
p `lesser_equal_perm` full_perm) /\
p.v == (let open FStar.Real in p1.v *. p2.v)
))
[@@noextract_to "krml"] // proof-only
val typedef (t: Type0) : Type0
inline_for_extraction [@@noextract_to "krml"]
let typeof (#t: Type0) (td: typedef t) : Tot Type0 = t
val fractionable (#t: Type0) (td: typedef t) (x: t) : GTot prop
val mk_fraction (#t: Type0) (td: typedef t) (x: t) (p: perm) : Ghost t
(requires (fractionable td x))
(ensures (fun y -> p `lesser_equal_perm` full_perm ==> fractionable td y))
val mk_fraction_full (#t: Type0) (td: typedef t) (x: t) : Lemma
(requires (fractionable td x))
(ensures (mk_fraction td x full_perm == x))
[SMTPat (mk_fraction td x full_perm)]
val mk_fraction_compose (#t: Type0) (td: typedef t) (x: t) (p1 p2: perm) : Lemma
(requires (fractionable td x /\ p1 `lesser_equal_perm` full_perm /\ p2 `lesser_equal_perm` full_perm))
(ensures (mk_fraction td (mk_fraction td x p1) p2 == mk_fraction td x (p1 `prod_perm` p2)))
val full (#t: Type0) (td: typedef t) (v: t) : GTot prop
val uninitialized (#t: Type0) (td: typedef t) : Ghost t
(requires True)
(ensures (fun y -> full td y /\ fractionable td y))
val unknown (#t: Type0) (td: typedef t) : Ghost t
(requires True)
(ensures (fun y -> fractionable td y))
val full_not_unknown
(#t: Type)
(td: typedef t)
(v: t)
: Lemma
(requires (full td v))
(ensures (~ (v == unknown td)))
[SMTPat (full td v)]
val mk_fraction_unknown (#t: Type0) (td: typedef t) (p: perm) : Lemma
(ensures (mk_fraction td (unknown td) p == unknown td))
val mk_fraction_eq_unknown (#t: Type0) (td: typedef t) (v: t) (p: perm) : Lemma
(requires (fractionable td v /\ mk_fraction td v p == unknown td))
(ensures (v == unknown td))
// To be extracted as: void*
[@@noextract_to "krml"] // primitive
val void_ptr : Type0
// To be extracted as: NULL
[@@noextract_to "krml"] // primitive
val void_null: void_ptr
// To be extracted as: *t
[@@noextract_to "krml"] // primitive
val ptr_gen ([@@@unused] t: Type) : Type0
[@@noextract_to "krml"] // primitive
val null_gen (t: Type) : Tot (ptr_gen t)
val ghost_void_ptr_of_ptr_gen (#[@@@unused] t: Type) (x: ptr_gen t) : GTot void_ptr
val ghost_ptr_gen_of_void_ptr (x: void_ptr) ([@@@unused] t: Type) : GTot (ptr_gen t)
val ghost_void_ptr_of_ptr_gen_of_void_ptr
(x: void_ptr)
(t: Type)
: Lemma
(ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t) == x)
[SMTPat (ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t))]
val ghost_ptr_gen_of_void_ptr_of_ptr_gen
(#t: Type)
(x: ptr_gen t)
: Lemma
(ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t == x)
[SMTPat (ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t)]
inline_for_extraction [@@noextract_to "krml"] // primitive
let ptr (#t: Type) (td: typedef t) : Tot Type0 = ptr_gen t
inline_for_extraction [@@noextract_to "krml"] // primitive
let null (#t: Type) (td: typedef t) : Tot (ptr td) = null_gen t | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Base.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | td: Pulse.C.Types.Base.typedef t -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Pulse.C.Types.Base.typedef",
"Pulse.C.Types.Base.ptr",
"Prims.l_not",
"Prims.eq2",
"Pulse.C.Types.Base.null"
] | [] | false | false | false | true | true | let ref (#t: Type) (td: typedef t) : Tot Type0 =
| (p: ptr td {~(p == null td)}) | false |
Hacl.Impl.P256.Scalar.fsti | Hacl.Impl.P256.Scalar.qmont_as_nat | val qmont_as_nat : h: FStar.Monotonic.HyperStack.mem -> a: Hacl.Impl.P256.Bignum.felem
-> Prims.GTot Spec.P256.PointOps.qelem | let qmont_as_nat (h:mem) (a:felem) = SM.from_qmont (as_nat h a) | {
"file_name": "code/ecdsap256/Hacl.Impl.P256.Scalar.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 63,
"end_line": 19,
"start_col": 0,
"start_line": 19
} | module Hacl.Impl.P256.Scalar
open FStar.Mul
open FStar.HyperStack.All
open FStar.HyperStack
module ST = FStar.HyperStack.ST
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.P256.Bignum
module S = Spec.P256
module SM = Hacl.Spec.P256.Montgomery
module BSeq = Lib.ByteSequence
#set-options "--z3rlimit 30 --fuel 0 --ifuel 0" | {
"checked_file": "/",
"dependencies": [
"Spec.P256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.P256.Montgomery.fsti.checked",
"Hacl.Impl.P256.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.P256.Scalar.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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": 30,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | h: FStar.Monotonic.HyperStack.mem -> a: Hacl.Impl.P256.Bignum.felem
-> Prims.GTot Spec.P256.PointOps.qelem | Prims.GTot | [
"sometrivial"
] | [] | [
"FStar.Monotonic.HyperStack.mem",
"Hacl.Impl.P256.Bignum.felem",
"Hacl.Spec.P256.Montgomery.from_qmont",
"Hacl.Impl.P256.Bignum.as_nat",
"Spec.P256.PointOps.qelem"
] | [] | false | false | false | false | false | let qmont_as_nat (h: mem) (a: felem) =
| SM.from_qmont (as_nat h a) | false |
|
Vale.AES.GCM_BE.fst | Vale.AES.GCM_BE.gcm_blocks_helper_dec_simplified | val gcm_blocks_helper_dec_simplified (alg:algorithm) (key:seq nat32)
(p128 p_bytes c128 c_bytes:seq quad32)
(auth_bytes alleged_tag:seq nat8)
(p_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
(length auth_bytes) < pow2_32 /\
is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\
(let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2
))
(ensures (let plain_raw_quads = append p128 p_bytes in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher_raw_quads = append c128 c_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_raw_quads)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
cipher_bytes == fst (gcm_decrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes alleged_tag))) | val gcm_blocks_helper_dec_simplified (alg:algorithm) (key:seq nat32)
(p128 p_bytes c128 c_bytes:seq quad32)
(auth_bytes alleged_tag:seq nat8)
(p_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
(length auth_bytes) < pow2_32 /\
is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\
(let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2
))
(ensures (let plain_raw_quads = append p128 p_bytes in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher_raw_quads = append c128 c_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_raw_quads)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
cipher_bytes == fst (gcm_decrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes alleged_tag))) | let gcm_blocks_helper_dec_simplified (alg:algorithm) (key:seq nat32)
(p128 p_bytes c128 c_bytes:seq quad32)
(auth_bytes alleged_tag:seq nat8)
(p_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
(length auth_bytes) < pow2_32 /\
is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\
(let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2
))
(ensures (let plain_raw_quads = append p128 p_bytes in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher_raw_quads = append c128 c_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_raw_quads)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
cipher_bytes == fst (gcm_decrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes alleged_tag)))
=
gcm_blocks_helper_enc alg key p128 p_bytes c128 c_bytes auth_bytes p_num_bytes iv j0_BE;
let plain_raw_quads =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else p128
in
let cipher_raw_quads:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
lemma_length_simplifier p128 p_bytes plain_raw_quads p_num_bytes;
lemma_length_simplifier c128 c_bytes cipher_raw_quads p_num_bytes;
let plain_raw_quads = append p128 p_bytes in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher_raw_quads = append c128 c_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_raw_quads)) 0 p_num_bytes in
assert (cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes));
lemma_gcm_encrypt_decrypt_equiv alg key iv j0_BE cipher_bytes plain_bytes auth_bytes alleged_tag;
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_BE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 718,
"start_col": 0,
"start_line": 652
} | module Vale.AES.GCM_BE
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.AES.GCM_BE_s
open Vale.AES.AES_BE_s
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.AES.GHash_BE_s
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open FStar.Calc
let upper3_equal (q0 q1:quad32) : bool =
q0.lo1 = q1.lo1 &&
q0.hi2 = q1.hi2 &&
q0.hi3 = q1.hi3
let lemma_be_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma
(requires slice b0 0 12 == slice b1 0 12)
(ensures upper3_equal (be_bytes_to_quad32 b0) (be_bytes_to_quad32 b1))
=
let q0 = be_bytes_to_quad32 b0 in
let q1 = be_bytes_to_quad32 b1 in
be_bytes_to_quad32_reveal ();
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #nat8);
assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\
index b1 i == index (slice b1 0 12) i))
let lemma_be_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma
(slice (be_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
=
assert (equal (slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
(slice (be_quad32_to_bytes q) 0 12));
()
let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_BE) (num_bytes:nat64) (h_BE j0:quad32) : Lemma
(requires
length iv_extra_b == 1 /\
length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\
num_bytes == 96/8 /\
(let iv_BE = index iv_extra_b 0 in
j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\
(let raw_quads = append iv_b iv_extra_b in
let iv_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 num_bytes in
iv_bytes == iv))
(ensures j0 == compute_iv_BE h_BE iv)
=
assert (length iv == 12);
assert (length iv_b == 0);
lemma_empty iv_b;
append_empty_l iv_extra_b;
assert (append iv_b iv_extra_b == iv_extra_b);
let q = index iv_extra_b 0 in
be_seq_quad32_to_bytes_of_singleton q;
assert (equal iv_extra_b (create 1 q));
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b) == be_quad32_to_bytes q);
calc (==) {
slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12;
== {}
slice (pad_to_128_bits iv) 0 12;
};
calc (==) {
be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b)) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits iv);
};
calc (==) {
j0;
== {}
set_to_one q;
== { be_bytes_to_quad32_to_bytes q }
set_to_one (be_bytes_to_quad32 (be_quad32_to_bytes q));
== {
lemma_be_seq_quad32_to_bytes_prefix_equality q;
lemma_be_bytes_to_quad32_prefix_equality
(be_quad32_to_bytes q)
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
}
set_to_one (be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)));
== { lemma_be_bytes_to_quad32_prefix_equality
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
(pad_to_128_bits iv) }
set_to_one (be_bytes_to_quad32 (pad_to_128_bits iv));
== {compute_iv_BE_reveal ()}
compute_iv_BE h_BE iv;
};
()
let lemma_compute_iv_hard (iv:supported_iv_BE) (quads:seq quad32) (length_quad h_BE j0:quad32) : Lemma
(requires
~(length iv == 96/8) /\
quads == be_bytes_to_seq_quad32 (pad_to_128_bits iv) /\
j0 == ghash_incremental h_BE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 0)
(nat_to_two 32 (8 * length iv))))
(ensures j0 == compute_iv_BE h_BE iv)
=
ghash_incremental_to_ghash h_BE (append quads (create 1 length_quad));
compute_iv_BE_reveal ();
()
let gcm_encrypt_BE_fst_helper (iv:supported_iv_BE) (iv_enc iv_BE:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma
(requires
is_aes_key_word alg key /\
length plain < pow2_32 /\
length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
iv_enc == inc32 (compute_iv_BE h_BE iv) 1 /\
cipher == gctr_encrypt iv_enc plain alg key
))
(ensures cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth))
=
gcm_encrypt_BE_reveal ()
let gcm_encrypt_BE_snd_helper (iv:supported_iv_BE) (j0_BE length_quad32 hash mac:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma
(requires
is_aes_key_word alg key /\
length plain < pow2_32 /\
length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth) /\
length_quad32 == two_two_to_four (Mktwo (nat_to_two 32 (8 * length auth)) (nat_to_two 32 (8 * length plain))) /\
(let auth_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits auth) in
let cipher_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits cipher) in
hash == ghash_BE h_BE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\
be_quad32_to_bytes mac == gctr_encrypt j0_BE (be_quad32_to_bytes hash) alg key)
))
(ensures be_quad32_to_bytes mac == snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth))
=
gcm_encrypt_BE_reveal ()
#reset-options "--z3rlimit 10"
let gcm_blocks_helper_enc (alg:algorithm) (key:seq nat32)
(p128 p_bytes c128 c_bytes:seq quad32)
(auth_bytes:seq nat8)
(p_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
(length auth_bytes) < pow2_32 /\
is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\
(let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2
)))
(ensures (let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
//cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key))
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes)))
=
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
gctr_partial_opaque_completed alg plain cipher key ctr_BE_2;
if p_num_bytes > length p128 * 16 then (
gctr_partial_reveal ();
assert (gctr_partial alg (length p128) plain cipher key ctr_BE_2);
assert (equal (slice plain 0 (length p128))
(slice p128 0 (length p128)));
assert (equal (slice cipher 0 (length p128))
(slice c128 0 (length p128)));
gctr_partial_opaque_ignores_postfix
alg (length p128)
plain p128
cipher c128
key ctr_BE_2;
assert (gctr_partial alg (length p128) p128 c128 key ctr_BE_2);
gctr_partial_opaque_completed alg p128 c128 key ctr_BE_2;
let num_blocks = p_num_bytes / 16 in
assert(index cipher num_blocks == quad32_xor (index plain num_blocks) (aes_encrypt_word alg key (inc32 ctr_BE_2 num_blocks)));
gctr_encrypt_block_offset ctr_BE_2 (index plain num_blocks) alg key num_blocks;
assert( gctr_encrypt_block ctr_BE_2 (index plain num_blocks) alg key num_blocks ==
gctr_encrypt_block (inc32 ctr_BE_2 num_blocks) (index plain num_blocks) alg key 0);
aes_encrypt_word_reveal ();
gctr_partial_to_full_advanced ctr_BE_2 plain cipher alg key p_num_bytes;
assert (cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key)
) else (
gctr_partial_to_full_basic ctr_BE_2 plain alg key cipher;
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher) == gctr_encrypt ctr_BE_2 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) alg key);
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
assert (equal plain_bytes (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)));
assert (equal cipher_bytes (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)));
assert (cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key)
);
gcm_encrypt_BE_fst_helper iv ctr_BE_2 j0_BE plain_bytes auth_bytes cipher_bytes alg key;
()
let slice_append_back (#a:Type) (x y:seq a) (i:nat) : Lemma
(requires length x <= i /\ i <= length x + length y)
(ensures slice (append x y) 0 i == append x (slice y 0 (i - length x)))
=
assert (equal (slice (append x y) 0 i) (append x (slice y 0 (i - length x))));
()
let append_distributes_be_seq_quad32_to_bytes (x y:seq quad32) :
Lemma (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append x y)) == append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE x)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE y)))
=
append_distributes_be_seq_quad32_to_bytes x y
let pad_to_128_bits_multiple_append (x y:seq nat8) : Lemma
(requires length x % 16 == 0)
(ensures pad_to_128_bits (append x y) == append x (pad_to_128_bits y))
=
assert (equal (pad_to_128_bits (append x y)) (append x (pad_to_128_bits y)))
#reset-options "--z3rlimit 100"
let gcm_blocks_helper (alg:algorithm) (key:seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes:seq quad32)
(p_num_bytes a_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE h enc_hash length_quad:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\
a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
length a_bytes == 1 /\
is_aes_key_word alg key /\
j0_BE = compute_iv_BE h iv /\
h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads c_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0
)))
(ensures (let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let plain_raw_quads =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else p128
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes) /\
be_quad32_to_bytes enc_hash ==
snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key)
iv plain_bytes auth_bytes)))
=
let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads c_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
let hash = ghash_BE h final_quads in
gcm_blocks_helper_enc alg key p128 p_bytes c128 c_bytes auth_input_bytes p_num_bytes iv j0_BE;
calc (==) {
enc_hash;
== {}
gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0;
== {}
gctr_encrypt_block ctr_BE_1 hash alg key 0;
== {}
quad32_xor hash (aes_encrypt_word alg key ctr_BE_1);
};
calc (==) {
gctr_encrypt ctr_BE_1 (be_quad32_to_bytes hash) alg key;
== { gctr_encrypt_one_block ctr_BE_1 hash alg key }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 (quad32_xor hash (aes_encrypt_word alg key ctr_BE_1))));
== {}
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 enc_hash));
== { be_seq_quad32_to_bytes_of_singleton enc_hash }
be_quad32_to_bytes enc_hash;
};
if p_num_bytes > length p128 * 16 then (
let c = append c128 c_bytes in
calc (==) {
append (append auth_quads c128) c_bytes;
== { append_assoc auth_quads c128 c_bytes }
append auth_quads (append c128 c_bytes);
== {}
append auth_quads c;
};
calc (==) {
append (append (append auth_quads c128) c_bytes) (create 1 length_quad);
= {} // See previous calc
append (append auth_quads (append c128 c_bytes)) (create 1 length_quad);
== { append_assoc auth_quads c (create 1 length_quad) }
append auth_quads (append c (create 1 length_quad));
};
let raw_quads_old = append auth_quads c in
calc (==) {
raw_quads;
== {}
be_bytes_to_seq_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes));
== {
calc (==) {
pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes);
== {
calc (==) {
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes;
== { append_distributes_be_seq_quad32_to_bytes auth_quads c }
slice (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))) 0 total_bytes;
== { slice_append_back (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))
total_bytes }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes);
== {}
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) cipher_bytes;
}
}
pad_to_128_bits (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) cipher_bytes);
== { pad_to_128_bits_multiple_append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) cipher_bytes }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (pad_to_128_bits cipher_bytes);
}
}
be_bytes_to_seq_quad32 (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (pad_to_128_bits cipher_bytes));
== { append_distributes_be_bytes_to_seq_quad32
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(pad_to_128_bits cipher_bytes) }
append (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))) (be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes));
== { be_bytes_to_seq_quad32_to_bytes auth_quads }
append auth_quads (be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes));
};
let auth_padded_quads' = be_bytes_to_seq_quad32 (pad_to_128_bits auth_input_bytes) in
let cipher_padded_quads' = be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes) in
calc (==) {
append raw_quads (create 1 length_quad);
== {}
append (append auth_quads (be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes))) (create 1 length_quad);
== { assert (equal auth_quads auth_padded_quads') }
append (append auth_padded_quads' cipher_padded_quads') (create 1 length_quad);
== { append_assoc auth_padded_quads' cipher_padded_quads' (create 1 length_quad) }
append auth_padded_quads' (append cipher_padded_quads' (create 1 length_quad));
};
gcm_encrypt_BE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key;
()
) else (
calc (==) {
append (append auth_quads c128) (create 1 length_quad);
== { append_assoc auth_quads c128 (create 1 length_quad) }
append auth_quads (append c128 (create 1 length_quad));
};
let c = c128 in
calc (==) {
be_bytes_to_seq_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes));
== { assert (equal (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes)) }
be_bytes_to_seq_quad32 (pad_to_128_bits (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)));
== { assert (pad_to_128_bits (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) == (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))) }
be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c));
== { be_bytes_to_seq_quad32_to_bytes c }
c;
};
gcm_encrypt_BE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key;
()
);
()
let lemma_length_simplifier (s bytes t:seq quad32) (num_bytes:nat) : Lemma
(requires t == (if num_bytes > (length s) * 16 then append s bytes else s) /\
(num_bytes <= (length s) * 16 ==> num_bytes == (length s * 16)) /\
length s * 16 <= num_bytes /\
num_bytes < length s * 16 + 16 /\
length bytes == 1
)
(ensures slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE t)) 0 num_bytes ==
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append s bytes))) 0 num_bytes)
=
if num_bytes > (length s) * 16 then (
()
) else (
calc (==) {
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append s bytes))) 0 num_bytes;
== { append_distributes_be_seq_quad32_to_bytes s bytes }
slice (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE bytes))) 0 num_bytes;
== { Vale.Lib.Seqs.lemma_slice_first_exactly_in_append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE bytes)) }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s);
== { assert (length (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == num_bytes) }
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes;
};
()
)
#reset-options "--z3rlimit 10"
let gcm_blocks_helper_simplified (alg:algorithm) (key:seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes:seq quad32)
(p_num_bytes a_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE h enc_hash length_quad:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\
a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
length a_bytes == 1 /\
is_aes_key_word alg key /\
j0_BE == compute_iv_BE h iv /\
h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > length a128 * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads c_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0
)))
(ensures (let auth_raw_quads = append a128 a_bytes in
let auth_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let plain_raw_quads = append p128 p_bytes in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher_raw_quads = append c128 c_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_raw_quads)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes) /\
be_quad32_to_bytes enc_hash ==
snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key)
iv plain_bytes auth_bytes))
)
=
gcm_blocks_helper alg key a128 a_bytes p128 p_bytes c128 c_bytes p_num_bytes a_num_bytes iv j0_BE h enc_hash length_quad;
let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in
let plain_raw_quads =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else p128
in
let cipher_raw_quads:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
lemma_length_simplifier a128 a_bytes auth_raw_quads a_num_bytes;
lemma_length_simplifier p128 p_bytes plain_raw_quads p_num_bytes;
lemma_length_simplifier c128 c_bytes cipher_raw_quads p_num_bytes;
()
let lemma_gcm_encrypt_decrypt_equiv (alg:algorithm) (key:seq nat32) (iv:supported_iv_BE) (j0_BE:quad32) (plain cipher auth alleged_tag:seq nat8) : Lemma
(requires
is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv) /\
length cipher < pow2_32 /\
length auth < pow2_32 /\
plain == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv cipher auth)
)
(ensures plain == fst (gcm_decrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv cipher auth alleged_tag))
=
gcm_encrypt_BE_reveal ();
gcm_decrypt_BE_reveal ();
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.GHash_BE_s.fst.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.GCM_BE_s.fst.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_BE.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
alg: Vale.AES.AES_common_s.algorithm ->
key: FStar.Seq.Base.seq Vale.Def.Words_s.nat32 ->
p128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
p_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
c128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
c_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
auth_bytes: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 ->
alleged_tag: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 ->
p_num_bytes: Prims.nat ->
iv: Vale.AES.GCM_BE_s.supported_iv_BE ->
j0_BE: Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(requires
FStar.Seq.Base.length p128 * 16 <= p_num_bytes /\
p_num_bytes < FStar.Seq.Base.length p128 * 16 + 16 /\
FStar.Seq.Base.length p128 == FStar.Seq.Base.length c128 /\
FStar.Seq.Base.length p_bytes == 1 /\ FStar.Seq.Base.length c_bytes == 1 /\
FStar.Seq.Base.length auth_bytes < Vale.Def.Words_s.pow2_32 /\
Vale.AES.AES_BE_s.is_aes_key_word alg key /\
(let h_BE = Vale.AES.AES_BE_s.aes_encrypt_word alg key (Vale.Def.Words_s.Mkfour 0 0 0 0) in
j0_BE = Vale.AES.GCM_BE_s.compute_iv_BE h_BE iv) /\ p_num_bytes < Vale.Def.Words_s.pow2_32 /\
(let ctr_BE_2 = Vale.AES.GCTR_BE_s.inc32 j0_BE 1 in
let plain =
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true -> FStar.Seq.Base.append p128 p_bytes
| _ -> p128)
<:
FStar.Seq.Base.seq Vale.Def.Types_s.quad32
in
let cipher =
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true -> FStar.Seq.Base.append c128 c_bytes
| _ -> c128)
<:
FStar.Seq.Base.seq Vale.Def.Types_s.quad32
in
let cipher_bound =
FStar.Seq.Base.length p128 +
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true -> 1
| _ -> 0)
in
Vale.AES.GCTR_BE.gctr_partial alg cipher_bound plain cipher key ctr_BE_2))
(ensures
(let plain_raw_quads = FStar.Seq.Base.append p128 p_bytes in
let plain_bytes =
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
plain_raw_quads))
0
p_num_bytes
in
let cipher_raw_quads = FStar.Seq.Base.append c128 c_bytes in
let cipher_bytes =
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
cipher_raw_quads))
0
p_num_bytes
in
FStar.Seq.Base.length auth_bytes < Vale.Def.Words_s.pow2_32 /\
FStar.Seq.Base.length plain_bytes < Vale.Def.Words_s.pow2_32 /\
cipher_bytes ==
FStar.Pervasives.Native.fst (Vale.AES.GCM_BE_s.gcm_decrypt_BE alg
(Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE key)
iv
plain_bytes
auth_bytes
alleged_tag))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.AES.AES_common_s.algorithm",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat32",
"Vale.Def.Types_s.quad32",
"Vale.Def.Words_s.nat8",
"Prims.nat",
"Vale.AES.GCM_BE_s.supported_iv_BE",
"Prims.unit",
"Vale.AES.GCM_BE.lemma_gcm_encrypt_decrypt_equiv",
"Prims._assert",
"Prims.eq2",
"Vale.Def.Types_s.nat8",
"FStar.Pervasives.Native.fst",
"Vale.AES.GCM_BE_s.gcm_encrypt_BE",
"Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE",
"FStar.Seq.Base.slice",
"Vale.Def.Words.Seq_s.seq_four_to_seq_BE",
"Vale.Def.Types_s.nat32",
"FStar.Seq.Base.append",
"Vale.AES.GCM_BE.lemma_length_simplifier",
"Prims.op_GreaterThan",
"FStar.Mul.op_Star",
"FStar.Seq.Base.length",
"Prims.bool",
"Vale.AES.GCM_BE.gcm_blocks_helper_enc",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Addition",
"Prims.int",
"Vale.Def.Words_s.pow2_32",
"Vale.AES.AES_BE_s.is_aes_key_word",
"Prims.op_Equality",
"Vale.AES.GCM_BE_s.compute_iv_BE",
"Vale.AES.AES_BE_s.aes_encrypt_word",
"Vale.Def.Words_s.Mkfour",
"Vale.AES.GCTR_BE.gctr_partial",
"Vale.AES.GCTR_BE_s.inc32",
"Prims.squash",
"Vale.AES.GCM_BE_s.gcm_decrypt_BE",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let gcm_blocks_helper_dec_simplified
(alg: algorithm)
(key: seq nat32)
(p128 p_bytes c128 c_bytes: seq quad32)
(auth_bytes alleged_tag: seq nat8)
(p_num_bytes: nat)
(iv: supported_iv_BE)
(j0_BE: quad32)
: Lemma
(requires
length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128 * 16 + 16 /\
length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\
(length auth_bytes) < pow2_32 /\ is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv) /\ p_num_bytes < pow2_32 /\
(let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then append c128 c_bytes else c128
in
let cipher_bound:nat = length p128 + (if p_num_bytes > length p128 * 16 then 1 else 0) in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2))
(ensures
(let plain_raw_quads = append p128 p_bytes in
let plain_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes
in
let cipher_raw_quads = append c128 c_bytes in
let cipher_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_raw_quads)) 0 p_num_bytes
in
length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\
cipher_bytes ==
fst (gcm_decrypt_BE alg
(seq_nat32_to_seq_nat8_BE key)
iv
plain_bytes
auth_bytes
alleged_tag))) =
| gcm_blocks_helper_enc alg key p128 p_bytes c128 c_bytes auth_bytes p_num_bytes iv j0_BE;
let plain_raw_quads = if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128 in
let cipher_raw_quads:seq quad32 =
if p_num_bytes > length p128 * 16 then append c128 c_bytes else c128
in
lemma_length_simplifier p128 p_bytes plain_raw_quads p_num_bytes;
lemma_length_simplifier c128 c_bytes cipher_raw_quads p_num_bytes;
let plain_raw_quads = append p128 p_bytes in
let plain_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes
in
let cipher_raw_quads = append c128 c_bytes in
let cipher_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_raw_quads)) 0 p_num_bytes
in
assert (cipher_bytes ==
fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes));
lemma_gcm_encrypt_decrypt_equiv alg key iv j0_BE cipher_bytes plain_bytes auth_bytes alleged_tag;
() | false |
Pulse.C.Types.Base.fsti | Pulse.C.Types.Base.ptr | val ptr (#t: Type) (td: typedef t) : Tot Type0 | val ptr (#t: Type) (td: typedef t) : Tot Type0 | let ptr (#t: Type) (td: typedef t) : Tot Type0 = ptr_gen t | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Base.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 58,
"end_line": 94,
"start_col": 0,
"start_line": 94
} | module Pulse.C.Types.Base
open Pulse.Lib.Pervasives
/// Helper to compose two permissions into one
val prod_perm (p1 p2: perm) : Pure perm
(requires True)
(ensures (fun p ->
((p1 `lesser_equal_perm` full_perm /\ p2 `lesser_equal_perm` full_perm) ==>
p `lesser_equal_perm` full_perm) /\
p.v == (let open FStar.Real in p1.v *. p2.v)
))
[@@noextract_to "krml"] // proof-only
val typedef (t: Type0) : Type0
inline_for_extraction [@@noextract_to "krml"]
let typeof (#t: Type0) (td: typedef t) : Tot Type0 = t
val fractionable (#t: Type0) (td: typedef t) (x: t) : GTot prop
val mk_fraction (#t: Type0) (td: typedef t) (x: t) (p: perm) : Ghost t
(requires (fractionable td x))
(ensures (fun y -> p `lesser_equal_perm` full_perm ==> fractionable td y))
val mk_fraction_full (#t: Type0) (td: typedef t) (x: t) : Lemma
(requires (fractionable td x))
(ensures (mk_fraction td x full_perm == x))
[SMTPat (mk_fraction td x full_perm)]
val mk_fraction_compose (#t: Type0) (td: typedef t) (x: t) (p1 p2: perm) : Lemma
(requires (fractionable td x /\ p1 `lesser_equal_perm` full_perm /\ p2 `lesser_equal_perm` full_perm))
(ensures (mk_fraction td (mk_fraction td x p1) p2 == mk_fraction td x (p1 `prod_perm` p2)))
val full (#t: Type0) (td: typedef t) (v: t) : GTot prop
val uninitialized (#t: Type0) (td: typedef t) : Ghost t
(requires True)
(ensures (fun y -> full td y /\ fractionable td y))
val unknown (#t: Type0) (td: typedef t) : Ghost t
(requires True)
(ensures (fun y -> fractionable td y))
val full_not_unknown
(#t: Type)
(td: typedef t)
(v: t)
: Lemma
(requires (full td v))
(ensures (~ (v == unknown td)))
[SMTPat (full td v)]
val mk_fraction_unknown (#t: Type0) (td: typedef t) (p: perm) : Lemma
(ensures (mk_fraction td (unknown td) p == unknown td))
val mk_fraction_eq_unknown (#t: Type0) (td: typedef t) (v: t) (p: perm) : Lemma
(requires (fractionable td v /\ mk_fraction td v p == unknown td))
(ensures (v == unknown td))
// To be extracted as: void*
[@@noextract_to "krml"] // primitive
val void_ptr : Type0
// To be extracted as: NULL
[@@noextract_to "krml"] // primitive
val void_null: void_ptr
// To be extracted as: *t
[@@noextract_to "krml"] // primitive
val ptr_gen ([@@@unused] t: Type) : Type0
[@@noextract_to "krml"] // primitive
val null_gen (t: Type) : Tot (ptr_gen t)
val ghost_void_ptr_of_ptr_gen (#[@@@unused] t: Type) (x: ptr_gen t) : GTot void_ptr
val ghost_ptr_gen_of_void_ptr (x: void_ptr) ([@@@unused] t: Type) : GTot (ptr_gen t)
val ghost_void_ptr_of_ptr_gen_of_void_ptr
(x: void_ptr)
(t: Type)
: Lemma
(ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t) == x)
[SMTPat (ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t))]
val ghost_ptr_gen_of_void_ptr_of_ptr_gen
(#t: Type)
(x: ptr_gen t)
: Lemma
(ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t == x)
[SMTPat (ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t)] | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Base.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | td: Pulse.C.Types.Base.typedef t -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Pulse.C.Types.Base.typedef",
"Pulse.C.Types.Base.ptr_gen"
] | [] | false | false | false | true | true | let ptr (#t: Type) (td: typedef t) : Tot Type0 =
| ptr_gen t | false |
Vale.AES.GCM_BE.fst | Vale.AES.GCM_BE.gcm_blocks_helper_enc | val gcm_blocks_helper_enc
(alg: algorithm)
(key: seq nat32)
(p128 p_bytes c128 c_bytes: seq quad32)
(auth_bytes: seq nat8)
(p_num_bytes: nat)
(iv: supported_iv_BE)
(j0_BE: quad32)
: Lemma
(requires
length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128 * 16 + 16 /\
length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\
(length auth_bytes) < pow2_32 /\ is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\ p_num_bytes < pow2_32 /\
(let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then append c128 c_bytes else c128
in
let cipher_bound:nat =
length p128 + (if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2)))
(ensures
(let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then append c128 c_bytes else c128
in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes
in
let cipher_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes
in
cipher_bytes ==
fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes))) | val gcm_blocks_helper_enc
(alg: algorithm)
(key: seq nat32)
(p128 p_bytes c128 c_bytes: seq quad32)
(auth_bytes: seq nat8)
(p_num_bytes: nat)
(iv: supported_iv_BE)
(j0_BE: quad32)
: Lemma
(requires
length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128 * 16 + 16 /\
length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\
(length auth_bytes) < pow2_32 /\ is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\ p_num_bytes < pow2_32 /\
(let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then append c128 c_bytes else c128
in
let cipher_bound:nat =
length p128 + (if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2)))
(ensures
(let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then append c128 c_bytes else c128
in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes
in
let cipher_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes
in
cipher_bytes ==
fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes))) | let gcm_blocks_helper_enc (alg:algorithm) (key:seq nat32)
(p128 p_bytes c128 c_bytes:seq quad32)
(auth_bytes:seq nat8)
(p_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
(length auth_bytes) < pow2_32 /\
is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\
(let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2
)))
(ensures (let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
//cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key))
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes)))
=
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
gctr_partial_opaque_completed alg plain cipher key ctr_BE_2;
if p_num_bytes > length p128 * 16 then (
gctr_partial_reveal ();
assert (gctr_partial alg (length p128) plain cipher key ctr_BE_2);
assert (equal (slice plain 0 (length p128))
(slice p128 0 (length p128)));
assert (equal (slice cipher 0 (length p128))
(slice c128 0 (length p128)));
gctr_partial_opaque_ignores_postfix
alg (length p128)
plain p128
cipher c128
key ctr_BE_2;
assert (gctr_partial alg (length p128) p128 c128 key ctr_BE_2);
gctr_partial_opaque_completed alg p128 c128 key ctr_BE_2;
let num_blocks = p_num_bytes / 16 in
assert(index cipher num_blocks == quad32_xor (index plain num_blocks) (aes_encrypt_word alg key (inc32 ctr_BE_2 num_blocks)));
gctr_encrypt_block_offset ctr_BE_2 (index plain num_blocks) alg key num_blocks;
assert( gctr_encrypt_block ctr_BE_2 (index plain num_blocks) alg key num_blocks ==
gctr_encrypt_block (inc32 ctr_BE_2 num_blocks) (index plain num_blocks) alg key 0);
aes_encrypt_word_reveal ();
gctr_partial_to_full_advanced ctr_BE_2 plain cipher alg key p_num_bytes;
assert (cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key)
) else (
gctr_partial_to_full_basic ctr_BE_2 plain alg key cipher;
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher) == gctr_encrypt ctr_BE_2 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) alg key);
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
assert (equal plain_bytes (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)));
assert (equal cipher_bytes (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)));
assert (cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key)
);
gcm_encrypt_BE_fst_helper iv ctr_BE_2 j0_BE plain_bytes auth_bytes cipher_bytes alg key;
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_BE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 251,
"start_col": 0,
"start_line": 146
} | module Vale.AES.GCM_BE
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.AES.GCM_BE_s
open Vale.AES.AES_BE_s
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.AES.GHash_BE_s
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open FStar.Calc
let upper3_equal (q0 q1:quad32) : bool =
q0.lo1 = q1.lo1 &&
q0.hi2 = q1.hi2 &&
q0.hi3 = q1.hi3
let lemma_be_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma
(requires slice b0 0 12 == slice b1 0 12)
(ensures upper3_equal (be_bytes_to_quad32 b0) (be_bytes_to_quad32 b1))
=
let q0 = be_bytes_to_quad32 b0 in
let q1 = be_bytes_to_quad32 b1 in
be_bytes_to_quad32_reveal ();
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #nat8);
assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\
index b1 i == index (slice b1 0 12) i))
let lemma_be_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma
(slice (be_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
=
assert (equal (slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
(slice (be_quad32_to_bytes q) 0 12));
()
let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_BE) (num_bytes:nat64) (h_BE j0:quad32) : Lemma
(requires
length iv_extra_b == 1 /\
length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\
num_bytes == 96/8 /\
(let iv_BE = index iv_extra_b 0 in
j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\
(let raw_quads = append iv_b iv_extra_b in
let iv_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 num_bytes in
iv_bytes == iv))
(ensures j0 == compute_iv_BE h_BE iv)
=
assert (length iv == 12);
assert (length iv_b == 0);
lemma_empty iv_b;
append_empty_l iv_extra_b;
assert (append iv_b iv_extra_b == iv_extra_b);
let q = index iv_extra_b 0 in
be_seq_quad32_to_bytes_of_singleton q;
assert (equal iv_extra_b (create 1 q));
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b) == be_quad32_to_bytes q);
calc (==) {
slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12;
== {}
slice (pad_to_128_bits iv) 0 12;
};
calc (==) {
be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b)) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits iv);
};
calc (==) {
j0;
== {}
set_to_one q;
== { be_bytes_to_quad32_to_bytes q }
set_to_one (be_bytes_to_quad32 (be_quad32_to_bytes q));
== {
lemma_be_seq_quad32_to_bytes_prefix_equality q;
lemma_be_bytes_to_quad32_prefix_equality
(be_quad32_to_bytes q)
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
}
set_to_one (be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)));
== { lemma_be_bytes_to_quad32_prefix_equality
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
(pad_to_128_bits iv) }
set_to_one (be_bytes_to_quad32 (pad_to_128_bits iv));
== {compute_iv_BE_reveal ()}
compute_iv_BE h_BE iv;
};
()
let lemma_compute_iv_hard (iv:supported_iv_BE) (quads:seq quad32) (length_quad h_BE j0:quad32) : Lemma
(requires
~(length iv == 96/8) /\
quads == be_bytes_to_seq_quad32 (pad_to_128_bits iv) /\
j0 == ghash_incremental h_BE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 0)
(nat_to_two 32 (8 * length iv))))
(ensures j0 == compute_iv_BE h_BE iv)
=
ghash_incremental_to_ghash h_BE (append quads (create 1 length_quad));
compute_iv_BE_reveal ();
()
let gcm_encrypt_BE_fst_helper (iv:supported_iv_BE) (iv_enc iv_BE:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma
(requires
is_aes_key_word alg key /\
length plain < pow2_32 /\
length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
iv_enc == inc32 (compute_iv_BE h_BE iv) 1 /\
cipher == gctr_encrypt iv_enc plain alg key
))
(ensures cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth))
=
gcm_encrypt_BE_reveal ()
let gcm_encrypt_BE_snd_helper (iv:supported_iv_BE) (j0_BE length_quad32 hash mac:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma
(requires
is_aes_key_word alg key /\
length plain < pow2_32 /\
length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth) /\
length_quad32 == two_two_to_four (Mktwo (nat_to_two 32 (8 * length auth)) (nat_to_two 32 (8 * length plain))) /\
(let auth_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits auth) in
let cipher_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits cipher) in
hash == ghash_BE h_BE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\
be_quad32_to_bytes mac == gctr_encrypt j0_BE (be_quad32_to_bytes hash) alg key)
))
(ensures be_quad32_to_bytes mac == snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth))
=
gcm_encrypt_BE_reveal () | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.GHash_BE_s.fst.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.GCM_BE_s.fst.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_BE.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
alg: Vale.AES.AES_common_s.algorithm ->
key: FStar.Seq.Base.seq Vale.Def.Words_s.nat32 ->
p128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
p_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
c128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
c_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
auth_bytes: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 ->
p_num_bytes: Prims.nat ->
iv: Vale.AES.GCM_BE_s.supported_iv_BE ->
j0_BE: Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(requires
FStar.Seq.Base.length p128 * 16 <= p_num_bytes /\
p_num_bytes < FStar.Seq.Base.length p128 * 16 + 16 /\
FStar.Seq.Base.length p128 == FStar.Seq.Base.length c128 /\
FStar.Seq.Base.length p_bytes == 1 /\ FStar.Seq.Base.length c_bytes == 1 /\
FStar.Seq.Base.length auth_bytes < Vale.Def.Words_s.pow2_32 /\
Vale.AES.AES_BE_s.is_aes_key_word alg key /\
(let h_BE = Vale.AES.AES_BE_s.aes_encrypt_word alg key (Vale.Def.Words_s.Mkfour 0 0 0 0) in
j0_BE = Vale.AES.GCM_BE_s.compute_iv_BE h_BE iv /\ p_num_bytes < Vale.Def.Words_s.pow2_32 /\
(let ctr_BE_2 = Vale.AES.GCTR_BE_s.inc32 j0_BE 1 in
let plain =
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true -> FStar.Seq.Base.append p128 p_bytes
| _ -> p128)
<:
FStar.Seq.Base.seq Vale.Def.Types_s.quad32
in
let cipher =
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true -> FStar.Seq.Base.append c128 c_bytes
| _ -> c128)
<:
FStar.Seq.Base.seq Vale.Def.Types_s.quad32
in
let cipher_bound =
FStar.Seq.Base.length p128 +
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true -> 1
| _ -> 0)
in
Vale.AES.GCTR_BE.gctr_partial alg cipher_bound plain cipher key ctr_BE_2)))
(ensures
(let plain =
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true -> FStar.Seq.Base.append p128 p_bytes
| _ -> p128)
<:
FStar.Seq.Base.seq Vale.Def.Types_s.quad32
in
let cipher =
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true -> FStar.Seq.Base.append c128 c_bytes
| _ -> c128)
<:
FStar.Seq.Base.seq Vale.Def.Types_s.quad32
in
let ctr_BE_2 = Vale.AES.GCTR_BE_s.inc32 j0_BE 1 in
let plain_bytes =
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
plain))
0
p_num_bytes
in
let cipher_bytes =
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
cipher))
0
p_num_bytes
in
cipher_bytes ==
FStar.Pervasives.Native.fst (Vale.AES.GCM_BE_s.gcm_encrypt_BE alg
(Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE key)
iv
plain_bytes
auth_bytes))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.AES.AES_common_s.algorithm",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat32",
"Vale.Def.Types_s.quad32",
"Vale.Def.Words_s.nat8",
"Prims.nat",
"Vale.AES.GCM_BE_s.supported_iv_BE",
"Prims.unit",
"Vale.AES.GCM_BE.gcm_encrypt_BE_fst_helper",
"Prims.op_GreaterThan",
"FStar.Mul.op_Star",
"FStar.Seq.Base.length",
"Prims._assert",
"Prims.eq2",
"Vale.AES.GCTR_BE_s.gctr_encrypt",
"Vale.AES.GCTR_BE.gctr_partial_to_full_advanced",
"Vale.AES.AES_BE_s.aes_encrypt_word_reveal",
"Vale.AES.GCTR_BE_s.gctr_encrypt_block",
"FStar.Seq.Base.index",
"Vale.AES.GCTR_BE_s.inc32",
"Vale.AES.GCTR_BE.gctr_encrypt_block_offset",
"Vale.Def.Types_s.quad32_xor",
"Vale.AES.AES_BE_s.aes_encrypt_word",
"Prims.int",
"Prims.op_Division",
"Vale.AES.GCTR_BE.gctr_partial_opaque_completed",
"Vale.AES.GCTR_BE.gctr_partial",
"Vale.AES.GCTR_BE.gctr_partial_opaque_ignores_postfix",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.slice",
"Vale.AES.GCTR_BE.gctr_partial_reveal",
"Prims.bool",
"Vale.Def.Types_s.nat8",
"Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE",
"Vale.Def.Words.Seq_s.seq_four_to_seq_BE",
"Vale.Def.Types_s.nat32",
"Vale.AES.GCTR_BE.gctr_partial_to_full_basic",
"Prims.op_Addition",
"FStar.Seq.Base.append",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Vale.Def.Words_s.pow2_32",
"Vale.AES.AES_BE_s.is_aes_key_word",
"Prims.op_Equality",
"Vale.AES.GCM_BE_s.compute_iv_BE",
"Vale.Def.Words_s.Mkfour",
"Prims.squash",
"FStar.Pervasives.Native.fst",
"Vale.AES.GCM_BE_s.gcm_encrypt_BE",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let gcm_blocks_helper_enc
(alg: algorithm)
(key: seq nat32)
(p128 p_bytes c128 c_bytes: seq quad32)
(auth_bytes: seq nat8)
(p_num_bytes: nat)
(iv: supported_iv_BE)
(j0_BE: quad32)
: Lemma
(requires
length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128 * 16 + 16 /\
length p128 == length c128 /\ length p_bytes == 1 /\ length c_bytes == 1 /\
(length auth_bytes) < pow2_32 /\ is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\ p_num_bytes < pow2_32 /\
(let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then append c128 c_bytes else c128
in
let cipher_bound:nat =
length p128 + (if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2)))
(ensures
(let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then append c128 c_bytes else c128
in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes
in
let cipher_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes
in
cipher_bytes ==
fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes))) =
| let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 = if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128 in
let cipher:seq quad32 = if p_num_bytes > length p128 * 16 then append c128 c_bytes else c128 in
let cipher_bound:nat = length p128 + (if p_num_bytes > length p128 * 16 then 1 else 0) in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
gctr_partial_opaque_completed alg plain cipher key ctr_BE_2;
if p_num_bytes > length p128 * 16
then
(gctr_partial_reveal ();
assert (gctr_partial alg (length p128) plain cipher key ctr_BE_2);
assert (equal (slice plain 0 (length p128)) (slice p128 0 (length p128)));
assert (equal (slice cipher 0 (length p128)) (slice c128 0 (length p128)));
gctr_partial_opaque_ignores_postfix alg (length p128) plain p128 cipher c128 key ctr_BE_2;
assert (gctr_partial alg (length p128) p128 c128 key ctr_BE_2);
gctr_partial_opaque_completed alg p128 c128 key ctr_BE_2;
let num_blocks = p_num_bytes / 16 in
assert (index cipher num_blocks ==
quad32_xor (index plain num_blocks) (aes_encrypt_word alg key (inc32 ctr_BE_2 num_blocks)));
gctr_encrypt_block_offset ctr_BE_2 (index plain num_blocks) alg key num_blocks;
assert (gctr_encrypt_block ctr_BE_2 (index plain num_blocks) alg key num_blocks ==
gctr_encrypt_block (inc32 ctr_BE_2 num_blocks) (index plain num_blocks) alg key 0);
aes_encrypt_word_reveal ();
gctr_partial_to_full_advanced ctr_BE_2 plain cipher alg key p_num_bytes;
assert (cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key))
else
(gctr_partial_to_full_basic ctr_BE_2 plain alg key cipher;
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher) ==
gctr_encrypt ctr_BE_2 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) alg key);
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
assert (equal plain_bytes (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)));
assert (equal cipher_bytes (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)));
assert (cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key));
gcm_encrypt_BE_fst_helper iv ctr_BE_2 j0_BE plain_bytes auth_bytes cipher_bytes alg key;
() | false |
Pulse.C.Types.Base.fsti | Pulse.C.Types.Base.typeof | val typeof (#t: Type0) (td: typedef t) : Tot Type0 | val typeof (#t: Type0) (td: typedef t) : Tot Type0 | let typeof (#t: Type0) (td: typedef t) : Tot Type0 = t | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Base.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 54,
"end_line": 17,
"start_col": 0,
"start_line": 17
} | module Pulse.C.Types.Base
open Pulse.Lib.Pervasives
/// Helper to compose two permissions into one
val prod_perm (p1 p2: perm) : Pure perm
(requires True)
(ensures (fun p ->
((p1 `lesser_equal_perm` full_perm /\ p2 `lesser_equal_perm` full_perm) ==>
p `lesser_equal_perm` full_perm) /\
p.v == (let open FStar.Real in p1.v *. p2.v)
))
[@@noextract_to "krml"] // proof-only
val typedef (t: Type0) : Type0 | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Base.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | td: Pulse.C.Types.Base.typedef t -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Pulse.C.Types.Base.typedef"
] | [] | false | false | false | true | true | let typeof (#t: Type0) (td: typedef t) : Tot Type0 =
| t | false |
Vale.AES.GCM_BE.fst | Vale.AES.GCM_BE.lemma_compute_iv_easy | val lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_BE) (num_bytes:nat64) (h_BE j0:quad32) : Lemma
(requires
length iv_extra_b == 1 /\
length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\
num_bytes == 96/8 /\
(let iv_BE = index iv_extra_b 0 in
j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\
(let raw_quads = append iv_b iv_extra_b in
let iv_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 num_bytes in
iv_bytes == iv))
(ensures j0 == compute_iv_BE h_BE iv) | val lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_BE) (num_bytes:nat64) (h_BE j0:quad32) : Lemma
(requires
length iv_extra_b == 1 /\
length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\
num_bytes == 96/8 /\
(let iv_BE = index iv_extra_b 0 in
j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\
(let raw_quads = append iv_b iv_extra_b in
let iv_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 num_bytes in
iv_bytes == iv))
(ensures j0 == compute_iv_BE h_BE iv) | let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_BE) (num_bytes:nat64) (h_BE j0:quad32) : Lemma
(requires
length iv_extra_b == 1 /\
length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\
num_bytes == 96/8 /\
(let iv_BE = index iv_extra_b 0 in
j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\
(let raw_quads = append iv_b iv_extra_b in
let iv_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 num_bytes in
iv_bytes == iv))
(ensures j0 == compute_iv_BE h_BE iv)
=
assert (length iv == 12);
assert (length iv_b == 0);
lemma_empty iv_b;
append_empty_l iv_extra_b;
assert (append iv_b iv_extra_b == iv_extra_b);
let q = index iv_extra_b 0 in
be_seq_quad32_to_bytes_of_singleton q;
assert (equal iv_extra_b (create 1 q));
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b) == be_quad32_to_bytes q);
calc (==) {
slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12;
== {}
slice (pad_to_128_bits iv) 0 12;
};
calc (==) {
be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b)) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits iv);
};
calc (==) {
j0;
== {}
set_to_one q;
== { be_bytes_to_quad32_to_bytes q }
set_to_one (be_bytes_to_quad32 (be_quad32_to_bytes q));
== {
lemma_be_seq_quad32_to_bytes_prefix_equality q;
lemma_be_bytes_to_quad32_prefix_equality
(be_quad32_to_bytes q)
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
}
set_to_one (be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)));
== { lemma_be_bytes_to_quad32_prefix_equality
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
(pad_to_128_bits iv) }
set_to_one (be_bytes_to_quad32 (pad_to_128_bits iv));
== {compute_iv_BE_reveal ()}
compute_iv_BE h_BE iv;
};
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_BE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 99,
"start_col": 0,
"start_line": 43
} | module Vale.AES.GCM_BE
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.AES.GCM_BE_s
open Vale.AES.AES_BE_s
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.AES.GHash_BE_s
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open FStar.Calc
let upper3_equal (q0 q1:quad32) : bool =
q0.lo1 = q1.lo1 &&
q0.hi2 = q1.hi2 &&
q0.hi3 = q1.hi3
let lemma_be_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma
(requires slice b0 0 12 == slice b1 0 12)
(ensures upper3_equal (be_bytes_to_quad32 b0) (be_bytes_to_quad32 b1))
=
let q0 = be_bytes_to_quad32 b0 in
let q1 = be_bytes_to_quad32 b1 in
be_bytes_to_quad32_reveal ();
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #nat8);
assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\
index b1 i == index (slice b1 0 12) i))
let lemma_be_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma
(slice (be_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
=
assert (equal (slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
(slice (be_quad32_to_bytes q) 0 12));
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.GHash_BE_s.fst.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.GCM_BE_s.fst.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_BE.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
iv_b: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
iv_extra_b: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
iv: Vale.AES.GCM_BE_s.supported_iv_BE ->
num_bytes: Vale.Def.Words_s.nat64 ->
h_BE: Vale.Def.Types_s.quad32 ->
j0: Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(requires
FStar.Seq.Base.length iv_extra_b == 1 /\ FStar.Seq.Base.length iv_b * (128 / 8) <= num_bytes /\
num_bytes < FStar.Seq.Base.length iv_b * (128 / 8) + 128 / 8 /\ num_bytes == 96 / 8 /\
(let iv_BE = FStar.Seq.Base.index iv_extra_b 0 in
j0 ==
Vale.Def.Words_s.Mkfour 1 (Mkfour?.lo1 iv_BE) (Mkfour?.hi2 iv_BE) (Mkfour?.hi3 iv_BE)) /\
(let raw_quads = FStar.Seq.Base.append iv_b iv_extra_b in
let iv_bytes =
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
raw_quads))
0
num_bytes
in
iv_bytes == iv)) (ensures j0 == Vale.AES.GCM_BE_s.compute_iv_BE h_BE iv) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.quad32",
"Vale.AES.GCM_BE_s.supported_iv_BE",
"Vale.Def.Words_s.nat64",
"Prims.unit",
"FStar.Calc.calc_finish",
"Prims.eq2",
"Vale.AES.GCM_BE_s.compute_iv_BE",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"Vale.AES.GCM_BE.set_to_one",
"Vale.Def.Types_s.be_bytes_to_quad32",
"Vale.AES.GCTR_BE_s.pad_to_128_bits",
"FStar.Seq.Base.slice",
"Vale.Def.Words_s.nat8",
"Vale.Arch.Types.be_quad32_to_bytes",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"Vale.Arch.Types.be_bytes_to_quad32_to_bytes",
"Vale.AES.GCM_BE.lemma_be_bytes_to_quad32_prefix_equality",
"Vale.AES.GCM_BE.lemma_be_seq_quad32_to_bytes_prefix_equality",
"Vale.AES.GCM_BE_s.compute_iv_BE_reveal",
"Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE",
"Vale.Def.Words.Seq_s.seq_four_to_seq_BE",
"Vale.Def.Types_s.nat32",
"Vale.Def.Types_s.nat8",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.create",
"Vale.Arch.Types.be_seq_quad32_to_bytes_of_singleton",
"FStar.Seq.Base.index",
"FStar.Seq.Base.append",
"FStar.Seq.Base.append_empty_l",
"FStar.Seq.Base.lemma_empty",
"Prims.int",
"FStar.Seq.Base.length",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Prims.op_Division",
"Prims.op_LessThan",
"Prims.op_Addition",
"Vale.Def.Words_s.four",
"Vale.Def.Words_s.Mkfour",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_compute_iv_easy
(iv_b iv_extra_b: seq quad32)
(iv: supported_iv_BE)
(num_bytes: nat64)
(h_BE j0: quad32)
: Lemma
(requires
length iv_extra_b == 1 /\ length iv_b * (128 / 8) <= num_bytes /\
num_bytes < length iv_b * (128 / 8) + 128 / 8 /\ num_bytes == 96 / 8 /\
(let iv_BE = index iv_extra_b 0 in
j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\
(let raw_quads = append iv_b iv_extra_b in
let iv_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 num_bytes
in
iv_bytes == iv)) (ensures j0 == compute_iv_BE h_BE iv) =
| assert (length iv == 12);
assert (length iv_b == 0);
lemma_empty iv_b;
append_empty_l iv_extra_b;
assert (append iv_b iv_extra_b == iv_extra_b);
let q = index iv_extra_b 0 in
be_seq_quad32_to_bytes_of_singleton q;
assert (equal iv_extra_b (create 1 q));
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b) == be_quad32_to_bytes q);
calc ( == ) {
slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12;
( == ) { () }
slice (pad_to_128_bits iv) 0 12;
};
calc ( == ) {
be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 num_bytes));
( == ) { () }
be_bytes_to_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b
))
0
num_bytes));
( == ) { () }
be_bytes_to_quad32 (pad_to_128_bits iv);
};
calc ( == ) {
j0;
( == ) { () }
set_to_one q;
( == ) { be_bytes_to_quad32_to_bytes q }
set_to_one (be_bytes_to_quad32 (be_quad32_to_bytes q));
( == ) { (lemma_be_seq_quad32_to_bytes_prefix_equality q;
lemma_be_bytes_to_quad32_prefix_equality (be_quad32_to_bytes q)
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))) }
set_to_one (be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)));
( == ) { lemma_be_bytes_to_quad32_prefix_equality (pad_to_128_bits (slice (be_quad32_to_bytes q)
0
12))
(pad_to_128_bits iv) }
set_to_one (be_bytes_to_quad32 (pad_to_128_bits iv));
( == ) { compute_iv_BE_reveal () }
compute_iv_BE h_BE iv;
};
() | false |
Pulse.C.Types.Base.fsti | Pulse.C.Types.Base.null | val null (#t: Type) (td: typedef t) : Tot (ptr td) | val null (#t: Type) (td: typedef t) : Tot (ptr td) | let null (#t: Type) (td: typedef t) : Tot (ptr td) = null_gen t | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Base.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 63,
"end_line": 96,
"start_col": 0,
"start_line": 96
} | module Pulse.C.Types.Base
open Pulse.Lib.Pervasives
/// Helper to compose two permissions into one
val prod_perm (p1 p2: perm) : Pure perm
(requires True)
(ensures (fun p ->
((p1 `lesser_equal_perm` full_perm /\ p2 `lesser_equal_perm` full_perm) ==>
p `lesser_equal_perm` full_perm) /\
p.v == (let open FStar.Real in p1.v *. p2.v)
))
[@@noextract_to "krml"] // proof-only
val typedef (t: Type0) : Type0
inline_for_extraction [@@noextract_to "krml"]
let typeof (#t: Type0) (td: typedef t) : Tot Type0 = t
val fractionable (#t: Type0) (td: typedef t) (x: t) : GTot prop
val mk_fraction (#t: Type0) (td: typedef t) (x: t) (p: perm) : Ghost t
(requires (fractionable td x))
(ensures (fun y -> p `lesser_equal_perm` full_perm ==> fractionable td y))
val mk_fraction_full (#t: Type0) (td: typedef t) (x: t) : Lemma
(requires (fractionable td x))
(ensures (mk_fraction td x full_perm == x))
[SMTPat (mk_fraction td x full_perm)]
val mk_fraction_compose (#t: Type0) (td: typedef t) (x: t) (p1 p2: perm) : Lemma
(requires (fractionable td x /\ p1 `lesser_equal_perm` full_perm /\ p2 `lesser_equal_perm` full_perm))
(ensures (mk_fraction td (mk_fraction td x p1) p2 == mk_fraction td x (p1 `prod_perm` p2)))
val full (#t: Type0) (td: typedef t) (v: t) : GTot prop
val uninitialized (#t: Type0) (td: typedef t) : Ghost t
(requires True)
(ensures (fun y -> full td y /\ fractionable td y))
val unknown (#t: Type0) (td: typedef t) : Ghost t
(requires True)
(ensures (fun y -> fractionable td y))
val full_not_unknown
(#t: Type)
(td: typedef t)
(v: t)
: Lemma
(requires (full td v))
(ensures (~ (v == unknown td)))
[SMTPat (full td v)]
val mk_fraction_unknown (#t: Type0) (td: typedef t) (p: perm) : Lemma
(ensures (mk_fraction td (unknown td) p == unknown td))
val mk_fraction_eq_unknown (#t: Type0) (td: typedef t) (v: t) (p: perm) : Lemma
(requires (fractionable td v /\ mk_fraction td v p == unknown td))
(ensures (v == unknown td))
// To be extracted as: void*
[@@noextract_to "krml"] // primitive
val void_ptr : Type0
// To be extracted as: NULL
[@@noextract_to "krml"] // primitive
val void_null: void_ptr
// To be extracted as: *t
[@@noextract_to "krml"] // primitive
val ptr_gen ([@@@unused] t: Type) : Type0
[@@noextract_to "krml"] // primitive
val null_gen (t: Type) : Tot (ptr_gen t)
val ghost_void_ptr_of_ptr_gen (#[@@@unused] t: Type) (x: ptr_gen t) : GTot void_ptr
val ghost_ptr_gen_of_void_ptr (x: void_ptr) ([@@@unused] t: Type) : GTot (ptr_gen t)
val ghost_void_ptr_of_ptr_gen_of_void_ptr
(x: void_ptr)
(t: Type)
: Lemma
(ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t) == x)
[SMTPat (ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t))]
val ghost_ptr_gen_of_void_ptr_of_ptr_gen
(#t: Type)
(x: ptr_gen t)
: Lemma
(ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t == x)
[SMTPat (ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t)]
inline_for_extraction [@@noextract_to "krml"] // primitive
let ptr (#t: Type) (td: typedef t) : Tot Type0 = ptr_gen t | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Base.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | td: Pulse.C.Types.Base.typedef t -> Pulse.C.Types.Base.ptr td | Prims.Tot | [
"total"
] | [] | [
"Pulse.C.Types.Base.typedef",
"Pulse.C.Types.Base.null_gen",
"Pulse.C.Types.Base.ptr"
] | [] | false | false | false | false | false | let null (#t: Type) (td: typedef t) : Tot (ptr td) =
| null_gen t | false |
Pulse.C.Types.Base.fsti | Pulse.C.Types.Base.norm_field_steps | val norm_field_steps : Prims.list FStar.Pervasives.norm_step | let norm_field_steps = [
delta_attr [`%norm_field_attr];
iota; zeta; primops;
] | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Base.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 1,
"end_line": 356,
"start_col": 0,
"start_line": 353
} | module Pulse.C.Types.Base
open Pulse.Lib.Pervasives
/// Helper to compose two permissions into one
val prod_perm (p1 p2: perm) : Pure perm
(requires True)
(ensures (fun p ->
((p1 `lesser_equal_perm` full_perm /\ p2 `lesser_equal_perm` full_perm) ==>
p `lesser_equal_perm` full_perm) /\
p.v == (let open FStar.Real in p1.v *. p2.v)
))
[@@noextract_to "krml"] // proof-only
val typedef (t: Type0) : Type0
inline_for_extraction [@@noextract_to "krml"]
let typeof (#t: Type0) (td: typedef t) : Tot Type0 = t
val fractionable (#t: Type0) (td: typedef t) (x: t) : GTot prop
val mk_fraction (#t: Type0) (td: typedef t) (x: t) (p: perm) : Ghost t
(requires (fractionable td x))
(ensures (fun y -> p `lesser_equal_perm` full_perm ==> fractionable td y))
val mk_fraction_full (#t: Type0) (td: typedef t) (x: t) : Lemma
(requires (fractionable td x))
(ensures (mk_fraction td x full_perm == x))
[SMTPat (mk_fraction td x full_perm)]
val mk_fraction_compose (#t: Type0) (td: typedef t) (x: t) (p1 p2: perm) : Lemma
(requires (fractionable td x /\ p1 `lesser_equal_perm` full_perm /\ p2 `lesser_equal_perm` full_perm))
(ensures (mk_fraction td (mk_fraction td x p1) p2 == mk_fraction td x (p1 `prod_perm` p2)))
val full (#t: Type0) (td: typedef t) (v: t) : GTot prop
val uninitialized (#t: Type0) (td: typedef t) : Ghost t
(requires True)
(ensures (fun y -> full td y /\ fractionable td y))
val unknown (#t: Type0) (td: typedef t) : Ghost t
(requires True)
(ensures (fun y -> fractionable td y))
val full_not_unknown
(#t: Type)
(td: typedef t)
(v: t)
: Lemma
(requires (full td v))
(ensures (~ (v == unknown td)))
[SMTPat (full td v)]
val mk_fraction_unknown (#t: Type0) (td: typedef t) (p: perm) : Lemma
(ensures (mk_fraction td (unknown td) p == unknown td))
val mk_fraction_eq_unknown (#t: Type0) (td: typedef t) (v: t) (p: perm) : Lemma
(requires (fractionable td v /\ mk_fraction td v p == unknown td))
(ensures (v == unknown td))
// To be extracted as: void*
[@@noextract_to "krml"] // primitive
val void_ptr : Type0
// To be extracted as: NULL
[@@noextract_to "krml"] // primitive
val void_null: void_ptr
// To be extracted as: *t
[@@noextract_to "krml"] // primitive
val ptr_gen ([@@@unused] t: Type) : Type0
[@@noextract_to "krml"] // primitive
val null_gen (t: Type) : Tot (ptr_gen t)
val ghost_void_ptr_of_ptr_gen (#[@@@unused] t: Type) (x: ptr_gen t) : GTot void_ptr
val ghost_ptr_gen_of_void_ptr (x: void_ptr) ([@@@unused] t: Type) : GTot (ptr_gen t)
val ghost_void_ptr_of_ptr_gen_of_void_ptr
(x: void_ptr)
(t: Type)
: Lemma
(ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t) == x)
[SMTPat (ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t))]
val ghost_ptr_gen_of_void_ptr_of_ptr_gen
(#t: Type)
(x: ptr_gen t)
: Lemma
(ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t == x)
[SMTPat (ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t)]
inline_for_extraction [@@noextract_to "krml"] // primitive
let ptr (#t: Type) (td: typedef t) : Tot Type0 = ptr_gen t
inline_for_extraction [@@noextract_to "krml"] // primitive
let null (#t: Type) (td: typedef t) : Tot (ptr td) = null_gen t
inline_for_extraction [@@noextract_to "krml"]
let ref (#t: Type) (td: typedef t) : Tot Type0 = (p: ptr td { ~ (p == null td) })
val pts_to (#t: Type) (#[@@@equate_by_smt]td: typedef t) (r: ref td) ([@@@equate_by_smt] v: Ghost.erased t) : vprop
let pts_to_or_null
(#t: Type) (#[@@@equate_by_smt]td: typedef t) (p: ptr td) ([@@@equate_by_smt] v: Ghost.erased t) : vprop
= if FStar.StrongExcludedMiddle.strong_excluded_middle (p == null _)
then emp
else pts_to p v
[@@noextract_to "krml"] // primitive
val is_null
(#t: Type)
// (#opened: _)
(#td: typedef t)
(#v: Ghost.erased t)
(p: ptr td)
// : STAtomicBase bool false opened Unobservable
: stt bool
(pts_to_or_null p v)
(fun res -> pts_to_or_null p v ** pure (
res == true <==> p == null _
))
```pulse
ghost
fn assert_null
(#t: Type)
(#td: typedef t)
(#v: Ghost.erased t)
(p: ptr td)
requires
(pts_to_or_null p v ** pure (
p == null _
))
ensures emp
{
rewrite (pts_to_or_null p v) as emp
}
```
```pulse
ghost
fn assert_not_null
(#t: Type)
(#td: typedef t)
(#v: Ghost.erased t)
(p: ptr td)
requires
(pts_to_or_null p v ** pure (
~ (p == null _)
))
returns _:(squash (~ (p == null _)))
ensures
(pts_to p v)
{
rewrite (pts_to_or_null p v) as (pts_to p v)
}
```
[@@noextract_to "krml"] // primitive
// val void_ptr_of_ptr (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: ptr td) : STAtomicBase void_ptr false opened Unobservable
val void_ptr_of_ptr (#t: Type) (#td: typedef t) (#v: Ghost.erased t) (x: ptr td) : stt void_ptr
(pts_to_or_null x v)
(fun y -> pts_to_or_null x v ** pure (
y == ghost_void_ptr_of_ptr_gen x
))
[@@noextract_to "krml"] inline_for_extraction
// let void_ptr_of_ref (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: ref td) : STAtomicBase void_ptr false opened Unobservable
```pulse
fn void_ptr_of_ref (#t: Type) (#td: typedef t) (#v: Ghost.erased t) (x: ref td)
requires
(pts_to x v)
returns y: void_ptr
ensures
(pts_to x v ** pure (
y == ghost_void_ptr_of_ptr_gen x
))
{
rewrite (pts_to x v) as (pts_to_or_null x v);
let res = void_ptr_of_ptr x;
rewrite (pts_to_or_null x v) as (pts_to x v);
res
}
```
[@@noextract_to "krml"] // primitive
// val ptr_of_void_ptr (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: void_ptr) : STAtomicBase (ptr td) false opened Unobservable
val ptr_of_void_ptr (#t: Type) (#td: typedef t) (#v: Ghost.erased t) (x: void_ptr) : stt (ptr td)
(pts_to_or_null #t #td (ghost_ptr_gen_of_void_ptr x t) v)
(fun y -> pts_to_or_null y v ** pure (
y == ghost_ptr_gen_of_void_ptr x t
))
[@@noextract_to "krml"] inline_for_extraction
// let ref_of_void_ptr (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: void_ptr) (y': Ghost.erased (ref td)) : STAtomicBase (ref td) false opened Unobservable
```pulse
fn ref_of_void_ptr (#t: Type) (#td: typedef t) (#v: Ghost.erased t) (x: void_ptr) (y': Ghost.erased (ref td))
requires
(pts_to y' v ** pure (
ghost_ptr_gen_of_void_ptr x t == Ghost.reveal y'
))
returns y: (ref td)
ensures
(pts_to y v ** pure (
Ghost.reveal y' == y
))
{
rewrite (pts_to y' v) as (pts_to_or_null #t #td (ghost_ptr_gen_of_void_ptr x t) v);
let y = ptr_of_void_ptr #t #td #v x;
rewrite (pts_to_or_null y v) as (pts_to y v);
y
}
```
val ref_equiv
(#t: Type)
(#td: typedef t)
(r1 r2: ref td)
: Tot vprop
val pts_to_equiv
(#t: Type)
(#td: typedef t)
(r1 r2: ref td)
(v: Ghost.erased t)
: stt_ghost unit
(ref_equiv r1 r2 ** pts_to r1 v)
(fun _ -> ref_equiv r1 r2 ** pts_to r2 v)
val freeable
(#t: Type)
(#td: typedef t)
(r: ref td)
: Tot vprop
val freeable_dup
(#t: Type)
(#td: typedef t)
(r: ref td)
: stt_ghost unit
(freeable r)
(fun _ -> freeable r ** freeable r)
val freeable_equiv
(#t: Type)
(#td: typedef t)
(r1 r2: ref td)
: stt_ghost unit
(ref_equiv r1 r2 ** freeable r1)
(fun _ -> ref_equiv r1 r2 ** freeable r2)
let freeable_or_null
(#t: Type)
(#td: typedef t)
(r: ptr td)
: Tot vprop
= if FStar.StrongExcludedMiddle.strong_excluded_middle (r == null _)
then emp
else freeable r
(*
let freeable_or_null_dup
(#opened: _)
(#t: Type)
(#td: typedef t)
(r: ptr td)
: SteelGhostT vprop opened
(freeable_or_null r)
(fun _ -> freeable_or_null r ** freeable_or_null r)
= if FStar.StrongExcludedMiddle.strong_excluded_middle (r == null _)
then ()
else freeable r
*)
[@@noextract_to "krml"] // primitive
val alloc
(#t: Type)
(td: typedef t)
: stt (ptr td)
emp
(fun p -> pts_to_or_null p (uninitialized td) ** freeable_or_null p)
[@@noextract_to "krml"] // primitive
val free
(#t: Type)
(#td: typedef t)
(#v: Ghost.erased t)
(r: ref td)
: stt unit
(pts_to r v ** freeable r ** pure (
full td v
))
(fun _ -> emp)
val mk_fraction_split_gen
(#t: Type) (#td: typedef t) (r: ref td) (v: t { fractionable td v }) (p p1 p2: perm)
: stt_ghost unit
(pts_to r (mk_fraction td v p) ** pure (
p == p1 `sum_perm` p2 /\ p `lesser_equal_perm` full_perm
))
(fun _ -> pts_to r (mk_fraction td v p1) ** pts_to r (mk_fraction td v p2))
val mk_fraction_split
(#t: Type) (#td: typedef t) (r: ref td) (v: Ghost.erased t { fractionable td v }) (p1 p2: perm)
: stt_ghost unit
(pts_to r v ** pure (
full_perm == p1 `sum_perm` p2
))
(fun _ -> pts_to r (mk_fraction td v p1) ** pts_to r (mk_fraction td v p2))
(*
= mk_fraction_full td v;
rewrite (pts_to _ _) (pts_to _ _);
mk_fraction_split_gen r v full_perm p1 p2
*)
val mk_fraction_join
(#t: Type) (#td: typedef t) (r: ref td) (v: t { fractionable td v }) (p1 p2: perm)
: stt_ghost unit
(pts_to r (mk_fraction td v p1) ** pts_to r (mk_fraction td v p2))
(fun _ -> pts_to r (mk_fraction td v (p1 `sum_perm` p2)))
val fractional_permissions_theorem
(#t: Type)
(#td: typedef t)
(v1: t { fractionable td v1 })
(v2: t { fractionable td v2 })
(p1 p2: perm)
(r: ref td)
: stt_ghost unit
(pts_to r (mk_fraction td v1 p1) ** pts_to r (mk_fraction td v2 p2) ** pure (
full td v1 /\ full td v2
))
(fun _ -> pts_to r (mk_fraction td v1 p1) ** pts_to r (mk_fraction td v2 p2) ** pure (
v1 == v2 /\ (p1 `sum_perm` p2) `lesser_equal_perm` full_perm
))
[@@noextract_to "krml"] // primitive
val copy
(#t: Type)
(#td: typedef t)
(#v_src: Ghost.erased t { full td v_src /\ fractionable td v_src })
(#p_src: perm)
(#v_dst: Ghost.erased t { full td v_dst })
(src: ref td)
(dst: ref td)
: stt unit
(pts_to src (mk_fraction td v_src p_src) ** pts_to dst v_dst)
(fun _ -> pts_to src (mk_fraction td v_src p_src) ** pts_to dst v_src)
val norm_field_attr : unit | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Base.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.list FStar.Pervasives.norm_step | Prims.Tot | [
"total"
] | [] | [
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.delta_attr",
"Prims.string",
"Prims.Nil",
"FStar.Pervasives.iota",
"FStar.Pervasives.zeta",
"FStar.Pervasives.primops"
] | [] | false | false | false | true | false | let norm_field_steps =
| [delta_attr [`%norm_field_attr]; iota; zeta; primops] | false |
|
Vale.Transformers.MovMovElim.fst | Vale.Transformers.MovMovElim.lemma_mov_mov_is_mov | val lemma_mov_mov_is_mov (i1 i2: ins) (s: machine_state)
: Lemma (requires (safe_mov_mov_elim [i1; i2]))
(ensures
(let s1 = machine_eval_ins i2 (machine_eval_ins i1 s) in
let s2 = machine_eval_ins i2 s in
s1.ms_ok ==> equiv_states s1 s2)) | val lemma_mov_mov_is_mov (i1 i2: ins) (s: machine_state)
: Lemma (requires (safe_mov_mov_elim [i1; i2]))
(ensures
(let s1 = machine_eval_ins i2 (machine_eval_ins i1 s) in
let s2 = machine_eval_ins i2 s in
s1.ms_ok ==> equiv_states s1 s2)) | let lemma_mov_mov_is_mov (i1 i2:ins) (s:machine_state) :
Lemma
(requires (safe_mov_mov_elim [i1; i2]))
(ensures (
let s1 = machine_eval_ins i2 (machine_eval_ins i1 s) in
let s2 = machine_eval_ins i2 s in
s1.ms_ok ==> equiv_states s1 s2)) =
let Instr ii1 oprs1 (AnnotateMov64 ()) = i1 in
let Instr ii2 oprs2 (AnnotateMov64 ()) = i2 in
let oprs1:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs1 in
let oprs2:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs2 in
let (dst1, (src1, ())) = oprs1 in
let (dst2, (src2, ())) = oprs2 in
let dst = assert (dst1 == dst2); dst1 in
let pre_s1 = machine_eval_ins i1 s in
let s1 = machine_eval_ins i2 pre_s1 in
let s2 = machine_eval_ins i2 s in
if s1.ms_ok then (
assert (pre_s1.ms_ok);
let v1 = eval_operand src1 s in
let v2' = eval_operand src2 s in
let v2 = eval_operand src2 pre_s1 in
assert (v2 == v2');
lemma_double_update_reg dst s pre_s1 s1 s2 v1 v2
) else () | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.MovMovElim.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 86,
"start_col": 0,
"start_line": 60
} | module Vale.Transformers.MovMovElim
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.InstructionReorder
open Vale.X64.InsLemmas
open Vale.Transformers.PeepHole
(*
* AR: this proof relies on multiple inductive type inversions to know that
* oprs1 is a Mov64 (resp. for oprs2)
*
* this used to go through earlier with just ifuel 1, because F* was weakening
* the branch VCs with discriminator expressions, thereby unintentionally
* triggering the inversions, this is no longer true in F*, and hence more ifuel
*)
#push-options "--ifuel 4"
let safe_mov_mov_elim (is:list ins) : Tot bool =
match is with
| [Instr i1 oprs1 (AnnotateMov64 ()); Instr i2 oprs2 (AnnotateMov64 ())] ->
let oprs1:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs1 in
let oprs2:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs2 in
let (dst1, (src1, ())) = oprs1 in
let (dst2, (src2, ())) = oprs2 in
dst1 = dst2 && OReg? dst1 && (
let OReg rd = dst1 in
match src2 with
| OConst _ -> true
| OReg rs2 -> not (rs2 = rd)
| OStack (m, _) | OMem (m, _) ->
match m with
| MConst _ -> true
| _ -> false // TODO: Can we relax this restriction?
)
| _ -> false
#pop-options
let mov_mov_elim_ph = {
ph = (fun is ->
if safe_mov_mov_elim is then (
let [i1; i2] = is in
Some [i2]
) else None);
input_hint = 2;
}
module T = Vale.Def.Types_s
module H = Vale.Arch.Heap | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.InsLemmas.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.PeepHole.fsti.checked",
"Vale.Transformers.InstructionReorder.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"Vale.Arch.Heap.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Transformers.MovMovElim.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Arch.Heap",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Vale.Def.Types_s",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.PeepHole",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsLemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers.InstructionReorder",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
i1: Vale.X64.Machine_Semantics_s.ins ->
i2: Vale.X64.Machine_Semantics_s.ins ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma (requires Vale.Transformers.MovMovElim.safe_mov_mov_elim [i1; i2])
(ensures
(let s1 =
Vale.X64.Machine_Semantics_s.machine_eval_ins i2
(Vale.X64.Machine_Semantics_s.machine_eval_ins i1 s)
in
let s2 = Vale.X64.Machine_Semantics_s.machine_eval_ins i2 s in
Mkmachine_state?.ms_ok s1 ==> Vale.Transformers.InstructionReorder.equiv_states s1 s2)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Instruction_s.instr_t_record",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs",
"Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args",
"Vale.X64.Machine_s.operand64",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"Vale.Transformers.PeepHole.lemma_double_update_reg",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Vale.Def.Types_s.nat64",
"Vale.Def.Words_s.nat64",
"Vale.X64.Machine_Semantics_s.eval_operand",
"Prims.b2t",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.machine_eval_ins",
"FStar.Pervasives.norm",
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.zeta",
"FStar.Pervasives.iota",
"FStar.Pervasives.delta_attr",
"Prims.string",
"Prims.Nil",
"Vale.X64.Instruction_s.instr_out",
"FStar.Pervasives.Native.Mktuple2",
"Vale.X64.Instruction_s.instr_operand_inout",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.Out",
"Vale.X64.Instruction_s.IOpEx",
"Vale.X64.Instruction_s.IOp64",
"Vale.Transformers.PeepHole.coerce_to_normal",
"Vale.X64.Instruction_s.out",
"Vale.X64.Instruction_s.op64",
"Vale.Transformers.MovMovElim.safe_mov_mov_elim",
"Prims.squash",
"Prims.l_imp",
"Vale.Transformers.InstructionReorder.equiv_states",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_mov_mov_is_mov (i1 i2: ins) (s: machine_state)
: Lemma (requires (safe_mov_mov_elim [i1; i2]))
(ensures
(let s1 = machine_eval_ins i2 (machine_eval_ins i1 s) in
let s2 = machine_eval_ins i2 s in
s1.ms_ok ==> equiv_states s1 s2)) =
| let Instr ii1 oprs1 (AnnotateMov64 ()) = i1 in
let Instr ii2 oprs2 (AnnotateMov64 ()) = i2 in
let oprs1:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs1
in
let oprs2:normal (instr_operands_t [out op64] [op64]) =
coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs2
in
let dst1, (src1, ()) = oprs1 in
let dst2, (src2, ()) = oprs2 in
let dst =
assert (dst1 == dst2);
dst1
in
let pre_s1 = machine_eval_ins i1 s in
let s1 = machine_eval_ins i2 pre_s1 in
let s2 = machine_eval_ins i2 s in
if s1.ms_ok
then
(assert (pre_s1.ms_ok);
let v1 = eval_operand src1 s in
let v2' = eval_operand src2 s in
let v2 = eval_operand src2 pre_s1 in
assert (v2 == v2');
lemma_double_update_reg dst s pre_s1 s1 s2 v1 v2) | false |
Vale.AES.GCM_BE.fst | Vale.AES.GCM_BE.gcm_blocks_helper_simplified | val gcm_blocks_helper_simplified (alg:algorithm) (key:seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes:seq quad32)
(p_num_bytes a_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE h enc_hash length_quad:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\
a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
length a_bytes == 1 /\
is_aes_key_word alg key /\
j0_BE == compute_iv_BE h iv /\
h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > length a128 * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads c_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0
)))
(ensures (let auth_raw_quads = append a128 a_bytes in
let auth_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let plain_raw_quads = append p128 p_bytes in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher_raw_quads = append c128 c_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_raw_quads)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes) /\
be_quad32_to_bytes enc_hash ==
snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key)
iv plain_bytes auth_bytes))
) | val gcm_blocks_helper_simplified (alg:algorithm) (key:seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes:seq quad32)
(p_num_bytes a_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE h enc_hash length_quad:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\
a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
length a_bytes == 1 /\
is_aes_key_word alg key /\
j0_BE == compute_iv_BE h iv /\
h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > length a128 * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads c_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0
)))
(ensures (let auth_raw_quads = append a128 a_bytes in
let auth_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let plain_raw_quads = append p128 p_bytes in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher_raw_quads = append c128 c_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_raw_quads)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes) /\
be_quad32_to_bytes enc_hash ==
snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key)
iv plain_bytes auth_bytes))
) | let gcm_blocks_helper_simplified (alg:algorithm) (key:seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes:seq quad32)
(p_num_bytes a_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE h enc_hash length_quad:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\
a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
length a_bytes == 1 /\
is_aes_key_word alg key /\
j0_BE == compute_iv_BE h iv /\
h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > length a128 * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads c_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0
)))
(ensures (let auth_raw_quads = append a128 a_bytes in
let auth_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let plain_raw_quads = append p128 p_bytes in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher_raw_quads = append c128 c_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_raw_quads)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes) /\
be_quad32_to_bytes enc_hash ==
snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key)
iv plain_bytes auth_bytes))
)
=
gcm_blocks_helper alg key a128 a_bytes p128 p_bytes c128 c_bytes p_num_bytes a_num_bytes iv j0_BE h enc_hash length_quad;
let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in
let plain_raw_quads =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else p128
in
let cipher_raw_quads:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
lemma_length_simplifier a128 a_bytes auth_raw_quads a_num_bytes;
lemma_length_simplifier p128 p_bytes plain_raw_quads p_num_bytes;
lemma_length_simplifier c128 c_bytes cipher_raw_quads p_num_bytes;
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_BE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 635,
"start_col": 0,
"start_line": 539
} | module Vale.AES.GCM_BE
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.AES.GCM_BE_s
open Vale.AES.AES_BE_s
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.AES.GHash_BE_s
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open FStar.Calc
let upper3_equal (q0 q1:quad32) : bool =
q0.lo1 = q1.lo1 &&
q0.hi2 = q1.hi2 &&
q0.hi3 = q1.hi3
let lemma_be_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma
(requires slice b0 0 12 == slice b1 0 12)
(ensures upper3_equal (be_bytes_to_quad32 b0) (be_bytes_to_quad32 b1))
=
let q0 = be_bytes_to_quad32 b0 in
let q1 = be_bytes_to_quad32 b1 in
be_bytes_to_quad32_reveal ();
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #nat8);
assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\
index b1 i == index (slice b1 0 12) i))
let lemma_be_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma
(slice (be_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
=
assert (equal (slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
(slice (be_quad32_to_bytes q) 0 12));
()
let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_BE) (num_bytes:nat64) (h_BE j0:quad32) : Lemma
(requires
length iv_extra_b == 1 /\
length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\
num_bytes == 96/8 /\
(let iv_BE = index iv_extra_b 0 in
j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\
(let raw_quads = append iv_b iv_extra_b in
let iv_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 num_bytes in
iv_bytes == iv))
(ensures j0 == compute_iv_BE h_BE iv)
=
assert (length iv == 12);
assert (length iv_b == 0);
lemma_empty iv_b;
append_empty_l iv_extra_b;
assert (append iv_b iv_extra_b == iv_extra_b);
let q = index iv_extra_b 0 in
be_seq_quad32_to_bytes_of_singleton q;
assert (equal iv_extra_b (create 1 q));
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b) == be_quad32_to_bytes q);
calc (==) {
slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12;
== {}
slice (pad_to_128_bits iv) 0 12;
};
calc (==) {
be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b)) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits iv);
};
calc (==) {
j0;
== {}
set_to_one q;
== { be_bytes_to_quad32_to_bytes q }
set_to_one (be_bytes_to_quad32 (be_quad32_to_bytes q));
== {
lemma_be_seq_quad32_to_bytes_prefix_equality q;
lemma_be_bytes_to_quad32_prefix_equality
(be_quad32_to_bytes q)
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
}
set_to_one (be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)));
== { lemma_be_bytes_to_quad32_prefix_equality
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
(pad_to_128_bits iv) }
set_to_one (be_bytes_to_quad32 (pad_to_128_bits iv));
== {compute_iv_BE_reveal ()}
compute_iv_BE h_BE iv;
};
()
let lemma_compute_iv_hard (iv:supported_iv_BE) (quads:seq quad32) (length_quad h_BE j0:quad32) : Lemma
(requires
~(length iv == 96/8) /\
quads == be_bytes_to_seq_quad32 (pad_to_128_bits iv) /\
j0 == ghash_incremental h_BE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 0)
(nat_to_two 32 (8 * length iv))))
(ensures j0 == compute_iv_BE h_BE iv)
=
ghash_incremental_to_ghash h_BE (append quads (create 1 length_quad));
compute_iv_BE_reveal ();
()
let gcm_encrypt_BE_fst_helper (iv:supported_iv_BE) (iv_enc iv_BE:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma
(requires
is_aes_key_word alg key /\
length plain < pow2_32 /\
length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
iv_enc == inc32 (compute_iv_BE h_BE iv) 1 /\
cipher == gctr_encrypt iv_enc plain alg key
))
(ensures cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth))
=
gcm_encrypt_BE_reveal ()
let gcm_encrypt_BE_snd_helper (iv:supported_iv_BE) (j0_BE length_quad32 hash mac:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma
(requires
is_aes_key_word alg key /\
length plain < pow2_32 /\
length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth) /\
length_quad32 == two_two_to_four (Mktwo (nat_to_two 32 (8 * length auth)) (nat_to_two 32 (8 * length plain))) /\
(let auth_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits auth) in
let cipher_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits cipher) in
hash == ghash_BE h_BE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\
be_quad32_to_bytes mac == gctr_encrypt j0_BE (be_quad32_to_bytes hash) alg key)
))
(ensures be_quad32_to_bytes mac == snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth))
=
gcm_encrypt_BE_reveal ()
#reset-options "--z3rlimit 10"
let gcm_blocks_helper_enc (alg:algorithm) (key:seq nat32)
(p128 p_bytes c128 c_bytes:seq quad32)
(auth_bytes:seq nat8)
(p_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
(length auth_bytes) < pow2_32 /\
is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\
(let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2
)))
(ensures (let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
//cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key))
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes)))
=
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
gctr_partial_opaque_completed alg plain cipher key ctr_BE_2;
if p_num_bytes > length p128 * 16 then (
gctr_partial_reveal ();
assert (gctr_partial alg (length p128) plain cipher key ctr_BE_2);
assert (equal (slice plain 0 (length p128))
(slice p128 0 (length p128)));
assert (equal (slice cipher 0 (length p128))
(slice c128 0 (length p128)));
gctr_partial_opaque_ignores_postfix
alg (length p128)
plain p128
cipher c128
key ctr_BE_2;
assert (gctr_partial alg (length p128) p128 c128 key ctr_BE_2);
gctr_partial_opaque_completed alg p128 c128 key ctr_BE_2;
let num_blocks = p_num_bytes / 16 in
assert(index cipher num_blocks == quad32_xor (index plain num_blocks) (aes_encrypt_word alg key (inc32 ctr_BE_2 num_blocks)));
gctr_encrypt_block_offset ctr_BE_2 (index plain num_blocks) alg key num_blocks;
assert( gctr_encrypt_block ctr_BE_2 (index plain num_blocks) alg key num_blocks ==
gctr_encrypt_block (inc32 ctr_BE_2 num_blocks) (index plain num_blocks) alg key 0);
aes_encrypt_word_reveal ();
gctr_partial_to_full_advanced ctr_BE_2 plain cipher alg key p_num_bytes;
assert (cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key)
) else (
gctr_partial_to_full_basic ctr_BE_2 plain alg key cipher;
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher) == gctr_encrypt ctr_BE_2 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) alg key);
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
assert (equal plain_bytes (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)));
assert (equal cipher_bytes (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)));
assert (cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key)
);
gcm_encrypt_BE_fst_helper iv ctr_BE_2 j0_BE plain_bytes auth_bytes cipher_bytes alg key;
()
let slice_append_back (#a:Type) (x y:seq a) (i:nat) : Lemma
(requires length x <= i /\ i <= length x + length y)
(ensures slice (append x y) 0 i == append x (slice y 0 (i - length x)))
=
assert (equal (slice (append x y) 0 i) (append x (slice y 0 (i - length x))));
()
let append_distributes_be_seq_quad32_to_bytes (x y:seq quad32) :
Lemma (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append x y)) == append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE x)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE y)))
=
append_distributes_be_seq_quad32_to_bytes x y
let pad_to_128_bits_multiple_append (x y:seq nat8) : Lemma
(requires length x % 16 == 0)
(ensures pad_to_128_bits (append x y) == append x (pad_to_128_bits y))
=
assert (equal (pad_to_128_bits (append x y)) (append x (pad_to_128_bits y)))
#reset-options "--z3rlimit 100"
let gcm_blocks_helper (alg:algorithm) (key:seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes:seq quad32)
(p_num_bytes a_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE h enc_hash length_quad:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\
a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
length a_bytes == 1 /\
is_aes_key_word alg key /\
j0_BE = compute_iv_BE h iv /\
h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads c_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0
)))
(ensures (let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let plain_raw_quads =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else p128
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes) /\
be_quad32_to_bytes enc_hash ==
snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key)
iv plain_bytes auth_bytes)))
=
let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads c_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
let hash = ghash_BE h final_quads in
gcm_blocks_helper_enc alg key p128 p_bytes c128 c_bytes auth_input_bytes p_num_bytes iv j0_BE;
calc (==) {
enc_hash;
== {}
gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0;
== {}
gctr_encrypt_block ctr_BE_1 hash alg key 0;
== {}
quad32_xor hash (aes_encrypt_word alg key ctr_BE_1);
};
calc (==) {
gctr_encrypt ctr_BE_1 (be_quad32_to_bytes hash) alg key;
== { gctr_encrypt_one_block ctr_BE_1 hash alg key }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 (quad32_xor hash (aes_encrypt_word alg key ctr_BE_1))));
== {}
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 enc_hash));
== { be_seq_quad32_to_bytes_of_singleton enc_hash }
be_quad32_to_bytes enc_hash;
};
if p_num_bytes > length p128 * 16 then (
let c = append c128 c_bytes in
calc (==) {
append (append auth_quads c128) c_bytes;
== { append_assoc auth_quads c128 c_bytes }
append auth_quads (append c128 c_bytes);
== {}
append auth_quads c;
};
calc (==) {
append (append (append auth_quads c128) c_bytes) (create 1 length_quad);
= {} // See previous calc
append (append auth_quads (append c128 c_bytes)) (create 1 length_quad);
== { append_assoc auth_quads c (create 1 length_quad) }
append auth_quads (append c (create 1 length_quad));
};
let raw_quads_old = append auth_quads c in
calc (==) {
raw_quads;
== {}
be_bytes_to_seq_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes));
== {
calc (==) {
pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes);
== {
calc (==) {
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes;
== { append_distributes_be_seq_quad32_to_bytes auth_quads c }
slice (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))) 0 total_bytes;
== { slice_append_back (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))
total_bytes }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes);
== {}
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) cipher_bytes;
}
}
pad_to_128_bits (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) cipher_bytes);
== { pad_to_128_bits_multiple_append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) cipher_bytes }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (pad_to_128_bits cipher_bytes);
}
}
be_bytes_to_seq_quad32 (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (pad_to_128_bits cipher_bytes));
== { append_distributes_be_bytes_to_seq_quad32
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(pad_to_128_bits cipher_bytes) }
append (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))) (be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes));
== { be_bytes_to_seq_quad32_to_bytes auth_quads }
append auth_quads (be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes));
};
let auth_padded_quads' = be_bytes_to_seq_quad32 (pad_to_128_bits auth_input_bytes) in
let cipher_padded_quads' = be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes) in
calc (==) {
append raw_quads (create 1 length_quad);
== {}
append (append auth_quads (be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes))) (create 1 length_quad);
== { assert (equal auth_quads auth_padded_quads') }
append (append auth_padded_quads' cipher_padded_quads') (create 1 length_quad);
== { append_assoc auth_padded_quads' cipher_padded_quads' (create 1 length_quad) }
append auth_padded_quads' (append cipher_padded_quads' (create 1 length_quad));
};
gcm_encrypt_BE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key;
()
) else (
calc (==) {
append (append auth_quads c128) (create 1 length_quad);
== { append_assoc auth_quads c128 (create 1 length_quad) }
append auth_quads (append c128 (create 1 length_quad));
};
let c = c128 in
calc (==) {
be_bytes_to_seq_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes));
== { assert (equal (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes)) }
be_bytes_to_seq_quad32 (pad_to_128_bits (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)));
== { assert (pad_to_128_bits (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) == (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))) }
be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c));
== { be_bytes_to_seq_quad32_to_bytes c }
c;
};
gcm_encrypt_BE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key;
()
);
()
let lemma_length_simplifier (s bytes t:seq quad32) (num_bytes:nat) : Lemma
(requires t == (if num_bytes > (length s) * 16 then append s bytes else s) /\
(num_bytes <= (length s) * 16 ==> num_bytes == (length s * 16)) /\
length s * 16 <= num_bytes /\
num_bytes < length s * 16 + 16 /\
length bytes == 1
)
(ensures slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE t)) 0 num_bytes ==
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append s bytes))) 0 num_bytes)
=
if num_bytes > (length s) * 16 then (
()
) else (
calc (==) {
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append s bytes))) 0 num_bytes;
== { append_distributes_be_seq_quad32_to_bytes s bytes }
slice (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE bytes))) 0 num_bytes;
== { Vale.Lib.Seqs.lemma_slice_first_exactly_in_append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE bytes)) }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s);
== { assert (length (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == num_bytes) }
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes;
};
()
) | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.GHash_BE_s.fst.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.GCM_BE_s.fst.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_BE.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
alg: Vale.AES.AES_common_s.algorithm ->
key: FStar.Seq.Base.seq Vale.Def.Words_s.nat32 ->
a128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
a_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
p128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
p_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
c128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
c_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
p_num_bytes: Prims.nat ->
a_num_bytes: Prims.nat ->
iv: Vale.AES.GCM_BE_s.supported_iv_BE ->
j0_BE: Vale.Def.Types_s.quad32 ->
h: Vale.Def.Types_s.quad32 ->
enc_hash: Vale.Def.Types_s.quad32 ->
length_quad: Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(requires
FStar.Seq.Base.length p128 * 16 <= p_num_bytes /\
p_num_bytes < FStar.Seq.Base.length p128 * 16 + 16 /\
FStar.Seq.Base.length a128 * 16 <= a_num_bytes /\
a_num_bytes < FStar.Seq.Base.length a128 * 16 + 16 /\ a_num_bytes < Vale.Def.Words_s.pow2_32 /\
FStar.Seq.Base.length p128 == FStar.Seq.Base.length c128 /\
FStar.Seq.Base.length p_bytes == 1 /\ FStar.Seq.Base.length c_bytes == 1 /\
FStar.Seq.Base.length a_bytes == 1 /\ Vale.AES.AES_BE_s.is_aes_key_word alg key /\
j0_BE == Vale.AES.GCM_BE_s.compute_iv_BE h iv /\
h = Vale.AES.AES_BE_s.aes_encrypt_word alg key (Vale.Def.Words_s.Mkfour 0 0 0 0) /\
p_num_bytes < Vale.Def.Words_s.pow2_32 /\ a_num_bytes < Vale.Def.Words_s.pow2_32 /\
length_quad ==
Vale.Def.Words.Four_s.two_two_to_four (Vale.Def.Words_s.Mktwo
(Vale.Def.Words.Two_s.nat_to_two 32 (8 * a_num_bytes))
(Vale.Def.Words.Two_s.nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1 = j0_BE in
let ctr_BE_2 = Vale.AES.GCTR_BE_s.inc32 j0_BE 1 in
let plain =
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true -> FStar.Seq.Base.append p128 p_bytes
| _ -> p128)
<:
FStar.Seq.Base.seq Vale.Def.Types_s.quad32
in
let cipher =
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true -> FStar.Seq.Base.append c128 c_bytes
| _ -> c128)
<:
FStar.Seq.Base.seq Vale.Def.Types_s.quad32
in
let cipher_bound =
FStar.Seq.Base.length p128 +
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true -> 1
| _ -> 0)
in
Vale.AES.GCTR_BE.gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
(match a_num_bytes > FStar.Seq.Base.length a128 * 16 with
| true -> FStar.Seq.Base.append a128 a_bytes
| _ -> a128)
<:
FStar.Seq.Base.seq (Vale.Def.Words_s.four Vale.Def.Words_s.nat32)
in
let auth_input_bytes =
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
auth_raw_quads))
0
a_num_bytes
in
let auth_padded_bytes = Vale.AES.GCTR_BE_s.pad_to_128_bits auth_input_bytes in
let auth_quads = Vale.Def.Types_s.be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = FStar.Seq.Base.append auth_quads c128 in
let total_bytes = FStar.Seq.Base.length auth_quads * 16 + p_num_bytes in
let raw_quads =
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true ->
let raw_quads = FStar.Seq.Base.append raw_quads c_bytes in
let input_bytes =
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
raw_quads))
0
total_bytes
in
let input_padded_bytes = Vale.AES.GCTR_BE_s.pad_to_128_bits input_bytes in
Vale.Def.Types_s.be_bytes_to_seq_quad32 input_padded_bytes
| _ -> raw_quads)
<:
FStar.Seq.Base.seq Vale.Def.Types_s.quad32
in
let final_quads =
FStar.Seq.Base.append raw_quads (FStar.Seq.Base.create 1 length_quad)
in
enc_hash ==
Vale.AES.GCTR_BE_s.gctr_encrypt_block ctr_BE_1
(Vale.AES.GHash_BE_s.ghash_BE h final_quads)
alg
key
0)))
(ensures
(let auth_raw_quads = FStar.Seq.Base.append a128 a_bytes in
let auth_bytes =
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
auth_raw_quads))
0
a_num_bytes
in
let plain_raw_quads = FStar.Seq.Base.append p128 p_bytes in
let plain_bytes =
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
plain_raw_quads))
0
p_num_bytes
in
let cipher_raw_quads = FStar.Seq.Base.append c128 c_bytes in
let cipher_bytes =
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
cipher_raw_quads))
0
p_num_bytes
in
FStar.Seq.Base.length auth_bytes < Vale.Def.Words_s.pow2_32 /\
FStar.Seq.Base.length plain_bytes < Vale.Def.Words_s.pow2_32 /\
cipher_bytes ==
FStar.Pervasives.Native.fst (Vale.AES.GCM_BE_s.gcm_encrypt_BE alg
(Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE key)
iv
plain_bytes
auth_bytes) /\
Vale.Arch.Types.be_quad32_to_bytes enc_hash ==
FStar.Pervasives.Native.snd (Vale.AES.GCM_BE_s.gcm_encrypt_BE alg
(Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE key)
iv
plain_bytes
auth_bytes))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.AES.AES_common_s.algorithm",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat32",
"Vale.Def.Types_s.quad32",
"Prims.nat",
"Vale.AES.GCM_BE_s.supported_iv_BE",
"Prims.unit",
"Vale.AES.GCM_BE.lemma_length_simplifier",
"Prims.op_GreaterThan",
"FStar.Mul.op_Star",
"FStar.Seq.Base.length",
"FStar.Seq.Base.append",
"Prims.bool",
"Vale.AES.GCM_BE.gcm_blocks_helper",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Addition",
"Vale.Def.Words_s.pow2_32",
"Prims.eq2",
"Prims.int",
"Vale.AES.AES_BE_s.is_aes_key_word",
"Vale.AES.GCM_BE_s.compute_iv_BE",
"Prims.op_Equality",
"Vale.AES.AES_BE_s.aes_encrypt_word",
"Vale.Def.Words_s.Mkfour",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words_s.four",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Def.Words.Four_s.two_two_to_four",
"Vale.Def.Words_s.Mktwo",
"Vale.Def.Words_s.two",
"Vale.Def.Words.Two_s.nat_to_two",
"Vale.AES.GCTR_BE.gctr_partial",
"Vale.AES.GCTR_BE_s.gctr_encrypt_block",
"Vale.AES.GHash_BE_s.ghash_BE",
"FStar.Seq.Base.create",
"Vale.Def.Types_s.be_bytes_to_seq_quad32",
"Vale.Def.Words_s.nat8",
"Vale.AES.GCTR_BE_s.pad_to_128_bits",
"FStar.Seq.Base.slice",
"Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE",
"Vale.Def.Words.Seq_s.seq_four_to_seq_BE",
"Vale.AES.GCTR_BE_s.inc32",
"Prims.squash",
"FStar.Pervasives.Native.fst",
"Vale.Def.Types_s.nat8",
"Vale.AES.GCM_BE_s.gcm_encrypt_BE",
"Vale.Arch.Types.be_quad32_to_bytes",
"FStar.Pervasives.Native.snd",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let gcm_blocks_helper_simplified
(alg: algorithm)
(key: seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes: seq quad32)
(p_num_bytes a_num_bytes: nat)
(iv: supported_iv_BE)
(j0_BE h enc_hash length_quad: quad32)
: Lemma
(requires
length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\ length p128 == length c128 /\ length p_bytes == 1 /\
length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_word alg key /\
j0_BE == compute_iv_BE h iv /\ h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad ==
two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then append c128 c_bytes else c128
in
let cipher_bound:nat = length p128 + (if p_num_bytes > length p128 * 16 then 1 else 0) in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > length a128 * 16 then append a128 a_bytes else a128
in
let auth_input_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes
in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16
then
let raw_quads = append raw_quads c_bytes in
let input_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes
in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0)))
(ensures
(let auth_raw_quads = append a128 a_bytes in
let auth_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes
in
let plain_raw_quads = append p128 p_bytes in
let plain_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes
in
let cipher_raw_quads = append c128 c_bytes in
let cipher_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_raw_quads)) 0 p_num_bytes
in
length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\
cipher_bytes ==
fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes) /\
be_quad32_to_bytes enc_hash ==
snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes))) =
| gcm_blocks_helper alg key a128 a_bytes p128 p_bytes c128 c_bytes p_num_bytes a_num_bytes iv j0_BE h
enc_hash length_quad;
let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in
let plain_raw_quads = if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128 in
let cipher_raw_quads:seq quad32 =
if p_num_bytes > length p128 * 16 then append c128 c_bytes else c128
in
lemma_length_simplifier a128 a_bytes auth_raw_quads a_num_bytes;
lemma_length_simplifier p128 p_bytes plain_raw_quads p_num_bytes;
lemma_length_simplifier c128 c_bytes cipher_raw_quads p_num_bytes;
() | false |
Vale.AES.GCM_BE.fst | Vale.AES.GCM_BE.gcm_blocks_dec_helper_simplified | val gcm_blocks_dec_helper_simplified (alg:algorithm) (key:seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes:seq quad32)
(p_num_bytes a_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE h enc_hash length_quad:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\
a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
length a_bytes == 1 /\
is_aes_key_word alg key /\
j0_BE == compute_iv_BE h iv /\
h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads p128 in
let total_bytes = (length auth_quads) * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads p_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0
)))
(ensures(let auth_raw_quads = append a128 a_bytes in
let auth_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let plain_raw_quads = append p128 p_bytes in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher_raw_quads = append c128 c_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_raw_quads)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
be_quad32_to_bytes enc_hash == gcm_decrypt_BE_tag alg (seq_nat32_to_seq_nat8_BE key)
iv plain_bytes auth_bytes)) | val gcm_blocks_dec_helper_simplified (alg:algorithm) (key:seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes:seq quad32)
(p_num_bytes a_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE h enc_hash length_quad:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\
a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
length a_bytes == 1 /\
is_aes_key_word alg key /\
j0_BE == compute_iv_BE h iv /\
h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads p128 in
let total_bytes = (length auth_quads) * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads p_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0
)))
(ensures(let auth_raw_quads = append a128 a_bytes in
let auth_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let plain_raw_quads = append p128 p_bytes in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher_raw_quads = append c128 c_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_raw_quads)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
be_quad32_to_bytes enc_hash == gcm_decrypt_BE_tag alg (seq_nat32_to_seq_nat8_BE key)
iv plain_bytes auth_bytes)) | let gcm_blocks_dec_helper_simplified (alg:algorithm) (key:seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes:seq quad32)
(p_num_bytes a_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE h enc_hash length_quad:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\
a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
length a_bytes == 1 /\
is_aes_key_word alg key /\
j0_BE == compute_iv_BE h iv /\
h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads p128 in
let total_bytes = (length auth_quads) * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads p_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0
)))
(ensures(let auth_raw_quads = append a128 a_bytes in
let auth_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let plain_raw_quads = append p128 p_bytes in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher_raw_quads = append c128 c_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_raw_quads)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
be_quad32_to_bytes enc_hash == gcm_decrypt_BE_tag alg (seq_nat32_to_seq_nat8_BE key)
iv plain_bytes auth_bytes))
=
gcm_blocks_dec_helper alg key a128 a_bytes p128 p_bytes c128 c_bytes p_num_bytes a_num_bytes iv j0_BE h enc_hash length_quad;
let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in
let plain_raw_quads =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else p128
in
let cipher_raw_quads:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
lemma_length_simplifier a128 a_bytes auth_raw_quads a_num_bytes;
lemma_length_simplifier p128 p_bytes plain_raw_quads p_num_bytes;
lemma_length_simplifier c128 c_bytes cipher_raw_quads p_num_bytes;
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_BE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 1049,
"start_col": 0,
"start_line": 956
} | module Vale.AES.GCM_BE
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.AES.GCM_BE_s
open Vale.AES.AES_BE_s
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.AES.GHash_BE_s
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open FStar.Calc
let upper3_equal (q0 q1:quad32) : bool =
q0.lo1 = q1.lo1 &&
q0.hi2 = q1.hi2 &&
q0.hi3 = q1.hi3
let lemma_be_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma
(requires slice b0 0 12 == slice b1 0 12)
(ensures upper3_equal (be_bytes_to_quad32 b0) (be_bytes_to_quad32 b1))
=
let q0 = be_bytes_to_quad32 b0 in
let q1 = be_bytes_to_quad32 b1 in
be_bytes_to_quad32_reveal ();
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #nat8);
assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\
index b1 i == index (slice b1 0 12) i))
let lemma_be_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma
(slice (be_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
=
assert (equal (slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
(slice (be_quad32_to_bytes q) 0 12));
()
let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_BE) (num_bytes:nat64) (h_BE j0:quad32) : Lemma
(requires
length iv_extra_b == 1 /\
length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\
num_bytes == 96/8 /\
(let iv_BE = index iv_extra_b 0 in
j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\
(let raw_quads = append iv_b iv_extra_b in
let iv_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 num_bytes in
iv_bytes == iv))
(ensures j0 == compute_iv_BE h_BE iv)
=
assert (length iv == 12);
assert (length iv_b == 0);
lemma_empty iv_b;
append_empty_l iv_extra_b;
assert (append iv_b iv_extra_b == iv_extra_b);
let q = index iv_extra_b 0 in
be_seq_quad32_to_bytes_of_singleton q;
assert (equal iv_extra_b (create 1 q));
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b) == be_quad32_to_bytes q);
calc (==) {
slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12;
== {}
slice (pad_to_128_bits iv) 0 12;
};
calc (==) {
be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b)) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits iv);
};
calc (==) {
j0;
== {}
set_to_one q;
== { be_bytes_to_quad32_to_bytes q }
set_to_one (be_bytes_to_quad32 (be_quad32_to_bytes q));
== {
lemma_be_seq_quad32_to_bytes_prefix_equality q;
lemma_be_bytes_to_quad32_prefix_equality
(be_quad32_to_bytes q)
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
}
set_to_one (be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)));
== { lemma_be_bytes_to_quad32_prefix_equality
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
(pad_to_128_bits iv) }
set_to_one (be_bytes_to_quad32 (pad_to_128_bits iv));
== {compute_iv_BE_reveal ()}
compute_iv_BE h_BE iv;
};
()
let lemma_compute_iv_hard (iv:supported_iv_BE) (quads:seq quad32) (length_quad h_BE j0:quad32) : Lemma
(requires
~(length iv == 96/8) /\
quads == be_bytes_to_seq_quad32 (pad_to_128_bits iv) /\
j0 == ghash_incremental h_BE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 0)
(nat_to_two 32 (8 * length iv))))
(ensures j0 == compute_iv_BE h_BE iv)
=
ghash_incremental_to_ghash h_BE (append quads (create 1 length_quad));
compute_iv_BE_reveal ();
()
let gcm_encrypt_BE_fst_helper (iv:supported_iv_BE) (iv_enc iv_BE:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma
(requires
is_aes_key_word alg key /\
length plain < pow2_32 /\
length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
iv_enc == inc32 (compute_iv_BE h_BE iv) 1 /\
cipher == gctr_encrypt iv_enc plain alg key
))
(ensures cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth))
=
gcm_encrypt_BE_reveal ()
let gcm_encrypt_BE_snd_helper (iv:supported_iv_BE) (j0_BE length_quad32 hash mac:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma
(requires
is_aes_key_word alg key /\
length plain < pow2_32 /\
length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth) /\
length_quad32 == two_two_to_four (Mktwo (nat_to_two 32 (8 * length auth)) (nat_to_two 32 (8 * length plain))) /\
(let auth_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits auth) in
let cipher_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits cipher) in
hash == ghash_BE h_BE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\
be_quad32_to_bytes mac == gctr_encrypt j0_BE (be_quad32_to_bytes hash) alg key)
))
(ensures be_quad32_to_bytes mac == snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth))
=
gcm_encrypt_BE_reveal ()
#reset-options "--z3rlimit 10"
let gcm_blocks_helper_enc (alg:algorithm) (key:seq nat32)
(p128 p_bytes c128 c_bytes:seq quad32)
(auth_bytes:seq nat8)
(p_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
(length auth_bytes) < pow2_32 /\
is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\
(let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2
)))
(ensures (let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
//cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key))
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes)))
=
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
gctr_partial_opaque_completed alg plain cipher key ctr_BE_2;
if p_num_bytes > length p128 * 16 then (
gctr_partial_reveal ();
assert (gctr_partial alg (length p128) plain cipher key ctr_BE_2);
assert (equal (slice plain 0 (length p128))
(slice p128 0 (length p128)));
assert (equal (slice cipher 0 (length p128))
(slice c128 0 (length p128)));
gctr_partial_opaque_ignores_postfix
alg (length p128)
plain p128
cipher c128
key ctr_BE_2;
assert (gctr_partial alg (length p128) p128 c128 key ctr_BE_2);
gctr_partial_opaque_completed alg p128 c128 key ctr_BE_2;
let num_blocks = p_num_bytes / 16 in
assert(index cipher num_blocks == quad32_xor (index plain num_blocks) (aes_encrypt_word alg key (inc32 ctr_BE_2 num_blocks)));
gctr_encrypt_block_offset ctr_BE_2 (index plain num_blocks) alg key num_blocks;
assert( gctr_encrypt_block ctr_BE_2 (index plain num_blocks) alg key num_blocks ==
gctr_encrypt_block (inc32 ctr_BE_2 num_blocks) (index plain num_blocks) alg key 0);
aes_encrypt_word_reveal ();
gctr_partial_to_full_advanced ctr_BE_2 plain cipher alg key p_num_bytes;
assert (cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key)
) else (
gctr_partial_to_full_basic ctr_BE_2 plain alg key cipher;
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher) == gctr_encrypt ctr_BE_2 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) alg key);
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
assert (equal plain_bytes (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)));
assert (equal cipher_bytes (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)));
assert (cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key)
);
gcm_encrypt_BE_fst_helper iv ctr_BE_2 j0_BE plain_bytes auth_bytes cipher_bytes alg key;
()
let slice_append_back (#a:Type) (x y:seq a) (i:nat) : Lemma
(requires length x <= i /\ i <= length x + length y)
(ensures slice (append x y) 0 i == append x (slice y 0 (i - length x)))
=
assert (equal (slice (append x y) 0 i) (append x (slice y 0 (i - length x))));
()
let append_distributes_be_seq_quad32_to_bytes (x y:seq quad32) :
Lemma (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append x y)) == append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE x)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE y)))
=
append_distributes_be_seq_quad32_to_bytes x y
let pad_to_128_bits_multiple_append (x y:seq nat8) : Lemma
(requires length x % 16 == 0)
(ensures pad_to_128_bits (append x y) == append x (pad_to_128_bits y))
=
assert (equal (pad_to_128_bits (append x y)) (append x (pad_to_128_bits y)))
#reset-options "--z3rlimit 100"
let gcm_blocks_helper (alg:algorithm) (key:seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes:seq quad32)
(p_num_bytes a_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE h enc_hash length_quad:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\
a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
length a_bytes == 1 /\
is_aes_key_word alg key /\
j0_BE = compute_iv_BE h iv /\
h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads c_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0
)))
(ensures (let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let plain_raw_quads =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else p128
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes) /\
be_quad32_to_bytes enc_hash ==
snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key)
iv plain_bytes auth_bytes)))
=
let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads c_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
let hash = ghash_BE h final_quads in
gcm_blocks_helper_enc alg key p128 p_bytes c128 c_bytes auth_input_bytes p_num_bytes iv j0_BE;
calc (==) {
enc_hash;
== {}
gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0;
== {}
gctr_encrypt_block ctr_BE_1 hash alg key 0;
== {}
quad32_xor hash (aes_encrypt_word alg key ctr_BE_1);
};
calc (==) {
gctr_encrypt ctr_BE_1 (be_quad32_to_bytes hash) alg key;
== { gctr_encrypt_one_block ctr_BE_1 hash alg key }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 (quad32_xor hash (aes_encrypt_word alg key ctr_BE_1))));
== {}
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 enc_hash));
== { be_seq_quad32_to_bytes_of_singleton enc_hash }
be_quad32_to_bytes enc_hash;
};
if p_num_bytes > length p128 * 16 then (
let c = append c128 c_bytes in
calc (==) {
append (append auth_quads c128) c_bytes;
== { append_assoc auth_quads c128 c_bytes }
append auth_quads (append c128 c_bytes);
== {}
append auth_quads c;
};
calc (==) {
append (append (append auth_quads c128) c_bytes) (create 1 length_quad);
= {} // See previous calc
append (append auth_quads (append c128 c_bytes)) (create 1 length_quad);
== { append_assoc auth_quads c (create 1 length_quad) }
append auth_quads (append c (create 1 length_quad));
};
let raw_quads_old = append auth_quads c in
calc (==) {
raw_quads;
== {}
be_bytes_to_seq_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes));
== {
calc (==) {
pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes);
== {
calc (==) {
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes;
== { append_distributes_be_seq_quad32_to_bytes auth_quads c }
slice (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))) 0 total_bytes;
== { slice_append_back (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))
total_bytes }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes);
== {}
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) cipher_bytes;
}
}
pad_to_128_bits (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) cipher_bytes);
== { pad_to_128_bits_multiple_append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) cipher_bytes }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (pad_to_128_bits cipher_bytes);
}
}
be_bytes_to_seq_quad32 (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (pad_to_128_bits cipher_bytes));
== { append_distributes_be_bytes_to_seq_quad32
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(pad_to_128_bits cipher_bytes) }
append (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))) (be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes));
== { be_bytes_to_seq_quad32_to_bytes auth_quads }
append auth_quads (be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes));
};
let auth_padded_quads' = be_bytes_to_seq_quad32 (pad_to_128_bits auth_input_bytes) in
let cipher_padded_quads' = be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes) in
calc (==) {
append raw_quads (create 1 length_quad);
== {}
append (append auth_quads (be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes))) (create 1 length_quad);
== { assert (equal auth_quads auth_padded_quads') }
append (append auth_padded_quads' cipher_padded_quads') (create 1 length_quad);
== { append_assoc auth_padded_quads' cipher_padded_quads' (create 1 length_quad) }
append auth_padded_quads' (append cipher_padded_quads' (create 1 length_quad));
};
gcm_encrypt_BE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key;
()
) else (
calc (==) {
append (append auth_quads c128) (create 1 length_quad);
== { append_assoc auth_quads c128 (create 1 length_quad) }
append auth_quads (append c128 (create 1 length_quad));
};
let c = c128 in
calc (==) {
be_bytes_to_seq_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes));
== { assert (equal (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes)) }
be_bytes_to_seq_quad32 (pad_to_128_bits (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)));
== { assert (pad_to_128_bits (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) == (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))) }
be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c));
== { be_bytes_to_seq_quad32_to_bytes c }
c;
};
gcm_encrypt_BE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key;
()
);
()
let lemma_length_simplifier (s bytes t:seq quad32) (num_bytes:nat) : Lemma
(requires t == (if num_bytes > (length s) * 16 then append s bytes else s) /\
(num_bytes <= (length s) * 16 ==> num_bytes == (length s * 16)) /\
length s * 16 <= num_bytes /\
num_bytes < length s * 16 + 16 /\
length bytes == 1
)
(ensures slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE t)) 0 num_bytes ==
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append s bytes))) 0 num_bytes)
=
if num_bytes > (length s) * 16 then (
()
) else (
calc (==) {
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append s bytes))) 0 num_bytes;
== { append_distributes_be_seq_quad32_to_bytes s bytes }
slice (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE bytes))) 0 num_bytes;
== { Vale.Lib.Seqs.lemma_slice_first_exactly_in_append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE bytes)) }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s);
== { assert (length (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == num_bytes) }
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes;
};
()
)
#reset-options "--z3rlimit 10"
let gcm_blocks_helper_simplified (alg:algorithm) (key:seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes:seq quad32)
(p_num_bytes a_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE h enc_hash length_quad:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\
a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
length a_bytes == 1 /\
is_aes_key_word alg key /\
j0_BE == compute_iv_BE h iv /\
h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > length a128 * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads c_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0
)))
(ensures (let auth_raw_quads = append a128 a_bytes in
let auth_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let plain_raw_quads = append p128 p_bytes in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher_raw_quads = append c128 c_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_raw_quads)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes) /\
be_quad32_to_bytes enc_hash ==
snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key)
iv plain_bytes auth_bytes))
)
=
gcm_blocks_helper alg key a128 a_bytes p128 p_bytes c128 c_bytes p_num_bytes a_num_bytes iv j0_BE h enc_hash length_quad;
let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in
let plain_raw_quads =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else p128
in
let cipher_raw_quads:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
lemma_length_simplifier a128 a_bytes auth_raw_quads a_num_bytes;
lemma_length_simplifier p128 p_bytes plain_raw_quads p_num_bytes;
lemma_length_simplifier c128 c_bytes cipher_raw_quads p_num_bytes;
()
let lemma_gcm_encrypt_decrypt_equiv (alg:algorithm) (key:seq nat32) (iv:supported_iv_BE) (j0_BE:quad32) (plain cipher auth alleged_tag:seq nat8) : Lemma
(requires
is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv) /\
length cipher < pow2_32 /\
length auth < pow2_32 /\
plain == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv cipher auth)
)
(ensures plain == fst (gcm_decrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv cipher auth alleged_tag))
=
gcm_encrypt_BE_reveal ();
gcm_decrypt_BE_reveal ();
()
let gcm_blocks_helper_dec_simplified (alg:algorithm) (key:seq nat32)
(p128 p_bytes c128 c_bytes:seq quad32)
(auth_bytes alleged_tag:seq nat8)
(p_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
(length auth_bytes) < pow2_32 /\
is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\
(let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2
))
(ensures (let plain_raw_quads = append p128 p_bytes in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher_raw_quads = append c128 c_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_raw_quads)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
cipher_bytes == fst (gcm_decrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes alleged_tag)))
=
gcm_blocks_helper_enc alg key p128 p_bytes c128 c_bytes auth_bytes p_num_bytes iv j0_BE;
let plain_raw_quads =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else p128
in
let cipher_raw_quads:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
lemma_length_simplifier p128 p_bytes plain_raw_quads p_num_bytes;
lemma_length_simplifier c128 c_bytes cipher_raw_quads p_num_bytes;
let plain_raw_quads = append p128 p_bytes in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher_raw_quads = append c128 c_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_raw_quads)) 0 p_num_bytes in
assert (cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes));
lemma_gcm_encrypt_decrypt_equiv alg key iv j0_BE cipher_bytes plain_bytes auth_bytes alleged_tag;
()
#reset-options "--z3rlimit 60"
let gcm_blocks_dec_helper (alg:algorithm) (key:seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes:seq quad32)
(p_num_bytes a_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE h enc_hash length_quad:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\
a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
length a_bytes == 1 /\
is_aes_key_word alg key /\
j0_BE = compute_iv_BE h iv /\
h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads p128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads p_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0
)))
(ensures (let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let plain_raw_quads =
if p_num_bytes >length p128 * 16 then
append p128 p_bytes
else p128
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
be_quad32_to_bytes enc_hash == gcm_decrypt_BE_tag alg (seq_nat32_to_seq_nat8_BE key)
iv plain_bytes auth_bytes))
=
let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
let auth_raw_quads =
if a_num_bytes > length a128 * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads p128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads p_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
let hash = ghash_BE h final_quads in
calc (==) {
enc_hash;
== {}
gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0;
== {}
gctr_encrypt_block ctr_BE_1 hash alg key 0;
== {}
quad32_xor hash (aes_encrypt_word alg key ctr_BE_1);
};
calc (==) {
gctr_encrypt ctr_BE_1 (be_quad32_to_bytes hash) alg key;
== { gctr_encrypt_one_block ctr_BE_1 hash alg key }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 (quad32_xor hash (aes_encrypt_word alg key ctr_BE_1))));
== {}
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 enc_hash));
== { be_seq_quad32_to_bytes_of_singleton enc_hash }
be_quad32_to_bytes enc_hash;
};
if p_num_bytes > length p128 * 16 then (
let c = append p128 p_bytes in
calc (==) {
append (append auth_quads p128) p_bytes;
== { append_assoc auth_quads p128 p_bytes }
append auth_quads (append p128 p_bytes);
== {}
append auth_quads c;
};
calc (==) {
append (append (append auth_quads p128) p_bytes) (create 1 length_quad);
= {} // See previous calc
append (append auth_quads (append p128 p_bytes)) (create 1 length_quad);
== { append_assoc auth_quads c (create 1 length_quad) }
append auth_quads (append c (create 1 length_quad));
};
let raw_quads_old = append auth_quads c in
calc (==) {
raw_quads;
== {}
be_bytes_to_seq_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes));
== {
calc (==) {
pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes);
== {
calc (==) {
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes;
== { append_distributes_be_seq_quad32_to_bytes auth_quads c }
slice (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))) 0 total_bytes;
== { slice_append_back (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))
total_bytes }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes);
== { assert(equal (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes) plain_bytes) }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) plain_bytes;
}
}
pad_to_128_bits (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) plain_bytes);
== { pad_to_128_bits_multiple_append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) plain_bytes }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (pad_to_128_bits plain_bytes);
}
}
be_bytes_to_seq_quad32 (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (pad_to_128_bits plain_bytes));
== { append_distributes_be_bytes_to_seq_quad32
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(pad_to_128_bits plain_bytes) }
append (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))) (be_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes));
== { be_bytes_to_seq_quad32_to_bytes auth_quads }
append auth_quads (be_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes));
};
let auth_padded_quads' = be_bytes_to_seq_quad32 (pad_to_128_bits auth_input_bytes) in
let cipher_padded_quads' = be_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes) in
calc (==) {
append raw_quads (create 1 length_quad);
== {}
append (append auth_quads (be_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes))) (create 1 length_quad);
== { assert (equal auth_quads auth_padded_quads') }
append (append auth_padded_quads' cipher_padded_quads') (create 1 length_quad);
== { append_assoc auth_padded_quads' cipher_padded_quads' (create 1 length_quad) }
append auth_padded_quads' (append cipher_padded_quads' (create 1 length_quad));
};
()
) else (
calc (==) {
append (append auth_quads p128) (create 1 length_quad);
== { append_assoc auth_quads p128 (create 1 length_quad) }
append auth_quads (append p128 (create 1 length_quad));
};
let c = p128 in
calc (==) {
be_bytes_to_seq_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes));
== { assert (equal (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes)) }
be_bytes_to_seq_quad32 (pad_to_128_bits (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)));
== { assert (pad_to_128_bits (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) == (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))) }
be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c));
== { be_bytes_to_seq_quad32_to_bytes c }
c;
};
()
);
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.GHash_BE_s.fst.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.GCM_BE_s.fst.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_BE.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
alg: Vale.AES.AES_common_s.algorithm ->
key: FStar.Seq.Base.seq Vale.Def.Words_s.nat32 ->
a128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
a_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
p128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
p_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
c128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
c_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
p_num_bytes: Prims.nat ->
a_num_bytes: Prims.nat ->
iv: Vale.AES.GCM_BE_s.supported_iv_BE ->
j0_BE: Vale.Def.Types_s.quad32 ->
h: Vale.Def.Types_s.quad32 ->
enc_hash: Vale.Def.Types_s.quad32 ->
length_quad: Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(requires
FStar.Seq.Base.length p128 * 16 <= p_num_bytes /\
p_num_bytes < FStar.Seq.Base.length p128 * 16 + 16 /\
FStar.Seq.Base.length a128 * 16 <= a_num_bytes /\
a_num_bytes < FStar.Seq.Base.length a128 * 16 + 16 /\ a_num_bytes < Vale.Def.Words_s.pow2_32 /\
FStar.Seq.Base.length p128 == FStar.Seq.Base.length c128 /\
FStar.Seq.Base.length p_bytes == 1 /\ FStar.Seq.Base.length c_bytes == 1 /\
FStar.Seq.Base.length a_bytes == 1 /\ Vale.AES.AES_BE_s.is_aes_key_word alg key /\
j0_BE == Vale.AES.GCM_BE_s.compute_iv_BE h iv /\
h = Vale.AES.AES_BE_s.aes_encrypt_word alg key (Vale.Def.Words_s.Mkfour 0 0 0 0) /\
p_num_bytes < Vale.Def.Words_s.pow2_32 /\ a_num_bytes < Vale.Def.Words_s.pow2_32 /\
length_quad ==
Vale.Def.Words.Four_s.two_two_to_four (Vale.Def.Words_s.Mktwo
(Vale.Def.Words.Two_s.nat_to_two 32 (8 * a_num_bytes))
(Vale.Def.Words.Two_s.nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1 = j0_BE in
let ctr_BE_2 = Vale.AES.GCTR_BE_s.inc32 j0_BE 1 in
let plain =
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true -> FStar.Seq.Base.append p128 p_bytes
| _ -> p128)
<:
FStar.Seq.Base.seq Vale.Def.Types_s.quad32
in
let cipher =
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true -> FStar.Seq.Base.append c128 c_bytes
| _ -> c128)
<:
FStar.Seq.Base.seq Vale.Def.Types_s.quad32
in
let cipher_bound =
FStar.Seq.Base.length p128 +
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true -> 1
| _ -> 0)
in
Vale.AES.GCTR_BE.gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
(match a_num_bytes > FStar.Seq.Base.length a128 * 16 with
| true -> FStar.Seq.Base.append a128 a_bytes
| _ -> a128)
<:
FStar.Seq.Base.seq (Vale.Def.Words_s.four Vale.Def.Words_s.nat32)
in
let auth_input_bytes =
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
auth_raw_quads))
0
a_num_bytes
in
let auth_padded_bytes = Vale.AES.GCTR_BE_s.pad_to_128_bits auth_input_bytes in
let auth_quads = Vale.Def.Types_s.be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = FStar.Seq.Base.append auth_quads p128 in
let total_bytes = FStar.Seq.Base.length auth_quads * 16 + p_num_bytes in
let raw_quads =
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true ->
let raw_quads = FStar.Seq.Base.append raw_quads p_bytes in
let input_bytes =
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
raw_quads))
0
total_bytes
in
let input_padded_bytes = Vale.AES.GCTR_BE_s.pad_to_128_bits input_bytes in
Vale.Def.Types_s.be_bytes_to_seq_quad32 input_padded_bytes
| _ -> raw_quads)
<:
FStar.Seq.Base.seq Vale.Def.Types_s.quad32
in
let final_quads =
FStar.Seq.Base.append raw_quads (FStar.Seq.Base.create 1 length_quad)
in
enc_hash ==
Vale.AES.GCTR_BE_s.gctr_encrypt_block ctr_BE_1
(Vale.AES.GHash_BE_s.ghash_BE h final_quads)
alg
key
0)))
(ensures
(let auth_raw_quads = FStar.Seq.Base.append a128 a_bytes in
let auth_bytes =
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
auth_raw_quads))
0
a_num_bytes
in
let plain_raw_quads = FStar.Seq.Base.append p128 p_bytes in
let plain_bytes =
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
plain_raw_quads))
0
p_num_bytes
in
let cipher_raw_quads = FStar.Seq.Base.append c128 c_bytes in
let cipher_bytes =
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
cipher_raw_quads))
0
p_num_bytes
in
FStar.Seq.Base.length auth_bytes < Vale.Def.Words_s.pow2_32 /\
FStar.Seq.Base.length plain_bytes < Vale.Def.Words_s.pow2_32 /\
Vale.Arch.Types.be_quad32_to_bytes enc_hash ==
Vale.AES.GCM_BE.gcm_decrypt_BE_tag alg
(Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE key)
iv
plain_bytes
auth_bytes)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.AES.AES_common_s.algorithm",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat32",
"Vale.Def.Types_s.quad32",
"Prims.nat",
"Vale.AES.GCM_BE_s.supported_iv_BE",
"Prims.unit",
"Vale.AES.GCM_BE.lemma_length_simplifier",
"Prims.op_GreaterThan",
"FStar.Mul.op_Star",
"FStar.Seq.Base.length",
"FStar.Seq.Base.append",
"Prims.bool",
"Vale.AES.GCM_BE.gcm_blocks_dec_helper",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Addition",
"Vale.Def.Words_s.pow2_32",
"Prims.eq2",
"Prims.int",
"Vale.AES.AES_BE_s.is_aes_key_word",
"Vale.AES.GCM_BE_s.compute_iv_BE",
"Prims.op_Equality",
"Vale.AES.AES_BE_s.aes_encrypt_word",
"Vale.Def.Words_s.Mkfour",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words_s.four",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Def.Words.Four_s.two_two_to_four",
"Vale.Def.Words_s.Mktwo",
"Vale.Def.Words_s.two",
"Vale.Def.Words.Two_s.nat_to_two",
"Vale.AES.GCTR_BE.gctr_partial",
"Vale.AES.GCTR_BE_s.gctr_encrypt_block",
"Vale.AES.GHash_BE_s.ghash_BE",
"FStar.Seq.Base.create",
"Vale.Def.Types_s.be_bytes_to_seq_quad32",
"Vale.Def.Words_s.nat8",
"Vale.AES.GCTR_BE_s.pad_to_128_bits",
"FStar.Seq.Base.slice",
"Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE",
"Vale.Def.Words.Seq_s.seq_four_to_seq_BE",
"Vale.AES.GCTR_BE_s.inc32",
"Prims.squash",
"Vale.Arch.Types.be_quad32_to_bytes",
"Vale.AES.GCM_BE.gcm_decrypt_BE_tag",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let gcm_blocks_dec_helper_simplified
(alg: algorithm)
(key: seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes: seq quad32)
(p_num_bytes a_num_bytes: nat)
(iv: supported_iv_BE)
(j0_BE h enc_hash length_quad: quad32)
: Lemma
(requires
length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\ length p128 == length c128 /\ length p_bytes == 1 /\
length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_word alg key /\
j0_BE == compute_iv_BE h iv /\ h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad ==
two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then append c128 c_bytes else c128
in
let cipher_bound:nat = length p128 + (if p_num_bytes > length p128 * 16 then 1 else 0) in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes
in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads p128 in
let total_bytes = (length auth_quads) * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16
then
let raw_quads = append raw_quads p_bytes in
let input_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes
in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0)))
(ensures
(let auth_raw_quads = append a128 a_bytes in
let auth_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes
in
let plain_raw_quads = append p128 p_bytes in
let plain_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes
in
let cipher_raw_quads = append c128 c_bytes in
let cipher_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_raw_quads)) 0 p_num_bytes
in
length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\
be_quad32_to_bytes enc_hash ==
gcm_decrypt_BE_tag alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes)) =
| gcm_blocks_dec_helper alg key a128 a_bytes p128 p_bytes c128 c_bytes p_num_bytes a_num_bytes iv
j0_BE h enc_hash length_quad;
let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in
let plain_raw_quads = if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128 in
let cipher_raw_quads:seq quad32 =
if p_num_bytes > length p128 * 16 then append c128 c_bytes else c128
in
lemma_length_simplifier a128 a_bytes auth_raw_quads a_num_bytes;
lemma_length_simplifier p128 p_bytes plain_raw_quads p_num_bytes;
lemma_length_simplifier c128 c_bytes cipher_raw_quads p_num_bytes;
() | false |
Pruning.fst | Pruning.tau1 | val tau1 : _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | let tau1 =
(fun () -> prune "";
addns "FStar.List";
addns "Prims") | {
"file_name": "examples/native_tactics/Pruning.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 26,
"end_line": 75,
"start_col": 0,
"start_line": 72
} | (*
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 Pruning
open FStar.Algebra.Monoid
open FStar.Array
open FStar.Axiomatic.Array
open FStar.BitVector
open FStar.Bytes
open FStar.Char
open FStar.Classical
open FStar.Constructive
open FStar.Crypto
open FStar.DependentMap
open FStar.ErasedLogic
open FStar.Fin
open FStar.Float
open FStar.FunctionalExtensionality
open FStar.Ghost
open FStar.Heap
open FStar.IndefiniteDescription
open FStar.Int
open FStar.Int128
open FStar.Int16
open FStar.Int32
open FStar.Int64
open FStar.Int8
open FStar.Int.Cast
open FStar.Integers
open FStar.IO
open FStar.List
open FStar.List.Tot
open FStar.List.Tot.Base
open FStar.List.Tot.Properties
open FStar.Map
open FStar.MarkovsPrinciple
open FStar.Math.Lemmas
open FStar.Math.Lib
open FStar.Matrix2
open FStar.MRef
open FStar.Mul
open FStar.Option
open FStar.Order
open FStar.OrdMap
open FStar.OrdMapProps
open FStar.OrdSet
open FStar.OrdSetProps
open FStar.PredicateExtensionality
open FStar.PropositionalExtensionality
open FStar.Reflection.V2
open FStar.Tactics.V2
open FStar.List
// This query will go the SMT, in the default proof namespace
let f (x:int) = assert (x + 1 == 1 + x) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.PropositionalExtensionality.fst.checked",
"FStar.PredicateExtensionality.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSetProps.fst.checked",
"FStar.OrdSet.fsti.checked",
"FStar.OrdMapProps.fst.checked",
"FStar.OrdMap.fsti.checked",
"FStar.Order.fst.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.MRef.fsti.checked",
"FStar.Matrix2.fsti.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.MarkovsPrinciple.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Integers.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Float.fsti.checked",
"FStar.Fin.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.DependentMap.fsti.checked",
"FStar.Crypto.fst.checked",
"FStar.Constructive.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.Bytes.fsti.checked",
"FStar.BitVector.fst.checked",
"FStar.Axiomatic.Array.fst.checked",
"FStar.Array.fsti.checked",
"FStar.Algebra.Monoid.fst.checked"
],
"interface_file": false,
"source_file": "Pruning.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PropositionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PredicateExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.OrdSetProps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.OrdSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.OrdMapProps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.OrdMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Order",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Option",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.MRef",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Matrix2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.MarkovsPrinciple",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot.Properties",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int8",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int16",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int128",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IndefiniteDescription",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Float",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Fin",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.ErasedLogic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DependentMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Crypto",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Constructive",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Axiomatic.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Algebra.Monoid",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"FStar.Stubs.Tactics.V2.Builtins.addns",
"FStar.Stubs.Tactics.V2.Builtins.prune"
] | [] | false | true | false | false | false | let tau1 =
| (fun () ->
prune "";
addns "FStar.List";
addns "Prims") | false |
|
Pulse.C.Types.Base.fsti | Pulse.C.Types.Base.pts_to_or_null | val pts_to_or_null
(#t: Type)
(#[@@@ equate_by_smt]td: typedef t)
(p: ptr td)
([@@@ equate_by_smt]v: Ghost.erased t)
: vprop | val pts_to_or_null
(#t: Type)
(#[@@@ equate_by_smt]td: typedef t)
(p: ptr td)
([@@@ equate_by_smt]v: Ghost.erased t)
: vprop | let pts_to_or_null
(#t: Type) (#[@@@equate_by_smt]td: typedef t) (p: ptr td) ([@@@equate_by_smt] v: Ghost.erased t) : vprop
= if FStar.StrongExcludedMiddle.strong_excluded_middle (p == null _)
then emp
else pts_to p v | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Base.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 17,
"end_line": 107,
"start_col": 0,
"start_line": 103
} | module Pulse.C.Types.Base
open Pulse.Lib.Pervasives
/// Helper to compose two permissions into one
val prod_perm (p1 p2: perm) : Pure perm
(requires True)
(ensures (fun p ->
((p1 `lesser_equal_perm` full_perm /\ p2 `lesser_equal_perm` full_perm) ==>
p `lesser_equal_perm` full_perm) /\
p.v == (let open FStar.Real in p1.v *. p2.v)
))
[@@noextract_to "krml"] // proof-only
val typedef (t: Type0) : Type0
inline_for_extraction [@@noextract_to "krml"]
let typeof (#t: Type0) (td: typedef t) : Tot Type0 = t
val fractionable (#t: Type0) (td: typedef t) (x: t) : GTot prop
val mk_fraction (#t: Type0) (td: typedef t) (x: t) (p: perm) : Ghost t
(requires (fractionable td x))
(ensures (fun y -> p `lesser_equal_perm` full_perm ==> fractionable td y))
val mk_fraction_full (#t: Type0) (td: typedef t) (x: t) : Lemma
(requires (fractionable td x))
(ensures (mk_fraction td x full_perm == x))
[SMTPat (mk_fraction td x full_perm)]
val mk_fraction_compose (#t: Type0) (td: typedef t) (x: t) (p1 p2: perm) : Lemma
(requires (fractionable td x /\ p1 `lesser_equal_perm` full_perm /\ p2 `lesser_equal_perm` full_perm))
(ensures (mk_fraction td (mk_fraction td x p1) p2 == mk_fraction td x (p1 `prod_perm` p2)))
val full (#t: Type0) (td: typedef t) (v: t) : GTot prop
val uninitialized (#t: Type0) (td: typedef t) : Ghost t
(requires True)
(ensures (fun y -> full td y /\ fractionable td y))
val unknown (#t: Type0) (td: typedef t) : Ghost t
(requires True)
(ensures (fun y -> fractionable td y))
val full_not_unknown
(#t: Type)
(td: typedef t)
(v: t)
: Lemma
(requires (full td v))
(ensures (~ (v == unknown td)))
[SMTPat (full td v)]
val mk_fraction_unknown (#t: Type0) (td: typedef t) (p: perm) : Lemma
(ensures (mk_fraction td (unknown td) p == unknown td))
val mk_fraction_eq_unknown (#t: Type0) (td: typedef t) (v: t) (p: perm) : Lemma
(requires (fractionable td v /\ mk_fraction td v p == unknown td))
(ensures (v == unknown td))
// To be extracted as: void*
[@@noextract_to "krml"] // primitive
val void_ptr : Type0
// To be extracted as: NULL
[@@noextract_to "krml"] // primitive
val void_null: void_ptr
// To be extracted as: *t
[@@noextract_to "krml"] // primitive
val ptr_gen ([@@@unused] t: Type) : Type0
[@@noextract_to "krml"] // primitive
val null_gen (t: Type) : Tot (ptr_gen t)
val ghost_void_ptr_of_ptr_gen (#[@@@unused] t: Type) (x: ptr_gen t) : GTot void_ptr
val ghost_ptr_gen_of_void_ptr (x: void_ptr) ([@@@unused] t: Type) : GTot (ptr_gen t)
val ghost_void_ptr_of_ptr_gen_of_void_ptr
(x: void_ptr)
(t: Type)
: Lemma
(ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t) == x)
[SMTPat (ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t))]
val ghost_ptr_gen_of_void_ptr_of_ptr_gen
(#t: Type)
(x: ptr_gen t)
: Lemma
(ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t == x)
[SMTPat (ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t)]
inline_for_extraction [@@noextract_to "krml"] // primitive
let ptr (#t: Type) (td: typedef t) : Tot Type0 = ptr_gen t
inline_for_extraction [@@noextract_to "krml"] // primitive
let null (#t: Type) (td: typedef t) : Tot (ptr td) = null_gen t
inline_for_extraction [@@noextract_to "krml"]
let ref (#t: Type) (td: typedef t) : Tot Type0 = (p: ptr td { ~ (p == null td) })
val pts_to (#t: Type) (#[@@@equate_by_smt]td: typedef t) (r: ref td) ([@@@equate_by_smt] v: Ghost.erased t) : vprop | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Base.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Pulse.C.Types.Base.ptr td -> v: FStar.Ghost.erased t -> Pulse.Lib.Core.vprop | Prims.Tot | [
"total"
] | [] | [
"Pulse.C.Types.Base.typedef",
"Pulse.C.Types.Base.ptr",
"FStar.Ghost.erased",
"FStar.StrongExcludedMiddle.strong_excluded_middle",
"Prims.eq2",
"Pulse.C.Types.Base.null",
"Pulse.Lib.Core.emp",
"Prims.bool",
"Pulse.C.Types.Base.pts_to",
"Pulse.Lib.Core.vprop"
] | [] | false | false | false | false | false | let pts_to_or_null
(#t: Type)
(#[@@@ equate_by_smt]td: typedef t)
(p: ptr td)
([@@@ equate_by_smt]v: Ghost.erased t)
: vprop =
| if FStar.StrongExcludedMiddle.strong_excluded_middle (p == null _) then emp else pts_to p v | false |
Pruning.fst | Pruning.tau2 | val tau2 : _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | let tau2 =
(fun () ->
prune "";
FStar.Tactics.split ();
(* rev [1;2] == [2;1] *)
addns "FStar.List";
addns "Prims";
smt ();
(* 1 == 1 *)
smt ()) | {
"file_name": "examples/native_tactics/Pruning.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 18,
"end_line": 91,
"start_col": 0,
"start_line": 82
} | (*
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 Pruning
open FStar.Algebra.Monoid
open FStar.Array
open FStar.Axiomatic.Array
open FStar.BitVector
open FStar.Bytes
open FStar.Char
open FStar.Classical
open FStar.Constructive
open FStar.Crypto
open FStar.DependentMap
open FStar.ErasedLogic
open FStar.Fin
open FStar.Float
open FStar.FunctionalExtensionality
open FStar.Ghost
open FStar.Heap
open FStar.IndefiniteDescription
open FStar.Int
open FStar.Int128
open FStar.Int16
open FStar.Int32
open FStar.Int64
open FStar.Int8
open FStar.Int.Cast
open FStar.Integers
open FStar.IO
open FStar.List
open FStar.List.Tot
open FStar.List.Tot.Base
open FStar.List.Tot.Properties
open FStar.Map
open FStar.MarkovsPrinciple
open FStar.Math.Lemmas
open FStar.Math.Lib
open FStar.Matrix2
open FStar.MRef
open FStar.Mul
open FStar.Option
open FStar.Order
open FStar.OrdMap
open FStar.OrdMapProps
open FStar.OrdSet
open FStar.OrdSetProps
open FStar.PredicateExtensionality
open FStar.PropositionalExtensionality
open FStar.Reflection.V2
open FStar.Tactics.V2
open FStar.List
// This query will go the SMT, in the default proof namespace
let f (x:int) = assert (x + 1 == 1 + x)
[@@plugin]
let tau1 =
(fun () -> prune "";
addns "FStar.List";
addns "Prims")
// This one should be sent in a pruned context
let _ = assert (rev [1;2] == [2;1]) by tau1 () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.PropositionalExtensionality.fst.checked",
"FStar.PredicateExtensionality.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSetProps.fst.checked",
"FStar.OrdSet.fsti.checked",
"FStar.OrdMapProps.fst.checked",
"FStar.OrdMap.fsti.checked",
"FStar.Order.fst.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.MRef.fsti.checked",
"FStar.Matrix2.fsti.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.MarkovsPrinciple.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Integers.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Float.fsti.checked",
"FStar.Fin.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.DependentMap.fsti.checked",
"FStar.Crypto.fst.checked",
"FStar.Constructive.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.Bytes.fsti.checked",
"FStar.BitVector.fst.checked",
"FStar.Axiomatic.Array.fst.checked",
"FStar.Array.fsti.checked",
"FStar.Algebra.Monoid.fst.checked"
],
"interface_file": false,
"source_file": "Pruning.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PropositionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PredicateExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.OrdSetProps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.OrdSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.OrdMapProps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.OrdMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Order",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Option",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.MRef",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Matrix2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.MarkovsPrinciple",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot.Properties",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int8",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int16",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int128",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IndefiniteDescription",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Float",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Fin",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.ErasedLogic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DependentMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Crypto",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Constructive",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Axiomatic.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Algebra.Monoid",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.smt",
"FStar.Stubs.Tactics.V2.Builtins.addns",
"FStar.Tactics.V1.Logic.split",
"FStar.Stubs.Tactics.V2.Builtins.prune"
] | [] | false | true | false | false | false | let tau2 =
| (fun () ->
prune "";
FStar.Tactics.split ();
addns "FStar.List";
addns "Prims";
smt ();
smt ()) | false |
|
Pulse.C.Types.Base.fsti | Pulse.C.Types.Base.freeable_or_null | val freeable_or_null (#t: Type) (#td: typedef t) (r: ptr td) : Tot vprop | val freeable_or_null (#t: Type) (#td: typedef t) (r: ptr td) : Tot vprop | let freeable_or_null
(#t: Type)
(#td: typedef t)
(r: ptr td)
: Tot vprop
= if FStar.StrongExcludedMiddle.strong_excluded_middle (r == null _)
then emp
else freeable r | {
"file_name": "share/steel/examples/pulse/lib/c/Pulse.C.Types.Base.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 17,
"end_line": 259,
"start_col": 0,
"start_line": 252
} | module Pulse.C.Types.Base
open Pulse.Lib.Pervasives
/// Helper to compose two permissions into one
val prod_perm (p1 p2: perm) : Pure perm
(requires True)
(ensures (fun p ->
((p1 `lesser_equal_perm` full_perm /\ p2 `lesser_equal_perm` full_perm) ==>
p `lesser_equal_perm` full_perm) /\
p.v == (let open FStar.Real in p1.v *. p2.v)
))
[@@noextract_to "krml"] // proof-only
val typedef (t: Type0) : Type0
inline_for_extraction [@@noextract_to "krml"]
let typeof (#t: Type0) (td: typedef t) : Tot Type0 = t
val fractionable (#t: Type0) (td: typedef t) (x: t) : GTot prop
val mk_fraction (#t: Type0) (td: typedef t) (x: t) (p: perm) : Ghost t
(requires (fractionable td x))
(ensures (fun y -> p `lesser_equal_perm` full_perm ==> fractionable td y))
val mk_fraction_full (#t: Type0) (td: typedef t) (x: t) : Lemma
(requires (fractionable td x))
(ensures (mk_fraction td x full_perm == x))
[SMTPat (mk_fraction td x full_perm)]
val mk_fraction_compose (#t: Type0) (td: typedef t) (x: t) (p1 p2: perm) : Lemma
(requires (fractionable td x /\ p1 `lesser_equal_perm` full_perm /\ p2 `lesser_equal_perm` full_perm))
(ensures (mk_fraction td (mk_fraction td x p1) p2 == mk_fraction td x (p1 `prod_perm` p2)))
val full (#t: Type0) (td: typedef t) (v: t) : GTot prop
val uninitialized (#t: Type0) (td: typedef t) : Ghost t
(requires True)
(ensures (fun y -> full td y /\ fractionable td y))
val unknown (#t: Type0) (td: typedef t) : Ghost t
(requires True)
(ensures (fun y -> fractionable td y))
val full_not_unknown
(#t: Type)
(td: typedef t)
(v: t)
: Lemma
(requires (full td v))
(ensures (~ (v == unknown td)))
[SMTPat (full td v)]
val mk_fraction_unknown (#t: Type0) (td: typedef t) (p: perm) : Lemma
(ensures (mk_fraction td (unknown td) p == unknown td))
val mk_fraction_eq_unknown (#t: Type0) (td: typedef t) (v: t) (p: perm) : Lemma
(requires (fractionable td v /\ mk_fraction td v p == unknown td))
(ensures (v == unknown td))
// To be extracted as: void*
[@@noextract_to "krml"] // primitive
val void_ptr : Type0
// To be extracted as: NULL
[@@noextract_to "krml"] // primitive
val void_null: void_ptr
// To be extracted as: *t
[@@noextract_to "krml"] // primitive
val ptr_gen ([@@@unused] t: Type) : Type0
[@@noextract_to "krml"] // primitive
val null_gen (t: Type) : Tot (ptr_gen t)
val ghost_void_ptr_of_ptr_gen (#[@@@unused] t: Type) (x: ptr_gen t) : GTot void_ptr
val ghost_ptr_gen_of_void_ptr (x: void_ptr) ([@@@unused] t: Type) : GTot (ptr_gen t)
val ghost_void_ptr_of_ptr_gen_of_void_ptr
(x: void_ptr)
(t: Type)
: Lemma
(ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t) == x)
[SMTPat (ghost_void_ptr_of_ptr_gen (ghost_ptr_gen_of_void_ptr x t))]
val ghost_ptr_gen_of_void_ptr_of_ptr_gen
(#t: Type)
(x: ptr_gen t)
: Lemma
(ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t == x)
[SMTPat (ghost_ptr_gen_of_void_ptr (ghost_void_ptr_of_ptr_gen x) t)]
inline_for_extraction [@@noextract_to "krml"] // primitive
let ptr (#t: Type) (td: typedef t) : Tot Type0 = ptr_gen t
inline_for_extraction [@@noextract_to "krml"] // primitive
let null (#t: Type) (td: typedef t) : Tot (ptr td) = null_gen t
inline_for_extraction [@@noextract_to "krml"]
let ref (#t: Type) (td: typedef t) : Tot Type0 = (p: ptr td { ~ (p == null td) })
val pts_to (#t: Type) (#[@@@equate_by_smt]td: typedef t) (r: ref td) ([@@@equate_by_smt] v: Ghost.erased t) : vprop
let pts_to_or_null
(#t: Type) (#[@@@equate_by_smt]td: typedef t) (p: ptr td) ([@@@equate_by_smt] v: Ghost.erased t) : vprop
= if FStar.StrongExcludedMiddle.strong_excluded_middle (p == null _)
then emp
else pts_to p v
[@@noextract_to "krml"] // primitive
val is_null
(#t: Type)
// (#opened: _)
(#td: typedef t)
(#v: Ghost.erased t)
(p: ptr td)
// : STAtomicBase bool false opened Unobservable
: stt bool
(pts_to_or_null p v)
(fun res -> pts_to_or_null p v ** pure (
res == true <==> p == null _
))
```pulse
ghost
fn assert_null
(#t: Type)
(#td: typedef t)
(#v: Ghost.erased t)
(p: ptr td)
requires
(pts_to_or_null p v ** pure (
p == null _
))
ensures emp
{
rewrite (pts_to_or_null p v) as emp
}
```
```pulse
ghost
fn assert_not_null
(#t: Type)
(#td: typedef t)
(#v: Ghost.erased t)
(p: ptr td)
requires
(pts_to_or_null p v ** pure (
~ (p == null _)
))
returns _:(squash (~ (p == null _)))
ensures
(pts_to p v)
{
rewrite (pts_to_or_null p v) as (pts_to p v)
}
```
[@@noextract_to "krml"] // primitive
// val void_ptr_of_ptr (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: ptr td) : STAtomicBase void_ptr false opened Unobservable
val void_ptr_of_ptr (#t: Type) (#td: typedef t) (#v: Ghost.erased t) (x: ptr td) : stt void_ptr
(pts_to_or_null x v)
(fun y -> pts_to_or_null x v ** pure (
y == ghost_void_ptr_of_ptr_gen x
))
[@@noextract_to "krml"] inline_for_extraction
// let void_ptr_of_ref (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: ref td) : STAtomicBase void_ptr false opened Unobservable
```pulse
fn void_ptr_of_ref (#t: Type) (#td: typedef t) (#v: Ghost.erased t) (x: ref td)
requires
(pts_to x v)
returns y: void_ptr
ensures
(pts_to x v ** pure (
y == ghost_void_ptr_of_ptr_gen x
))
{
rewrite (pts_to x v) as (pts_to_or_null x v);
let res = void_ptr_of_ptr x;
rewrite (pts_to_or_null x v) as (pts_to x v);
res
}
```
[@@noextract_to "krml"] // primitive
// val ptr_of_void_ptr (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: void_ptr) : STAtomicBase (ptr td) false opened Unobservable
val ptr_of_void_ptr (#t: Type) (#td: typedef t) (#v: Ghost.erased t) (x: void_ptr) : stt (ptr td)
(pts_to_or_null #t #td (ghost_ptr_gen_of_void_ptr x t) v)
(fun y -> pts_to_or_null y v ** pure (
y == ghost_ptr_gen_of_void_ptr x t
))
[@@noextract_to "krml"] inline_for_extraction
// let ref_of_void_ptr (#t: Type) (#opened: _) (#td: typedef t) (#v: Ghost.erased t) (x: void_ptr) (y': Ghost.erased (ref td)) : STAtomicBase (ref td) false opened Unobservable
```pulse
fn ref_of_void_ptr (#t: Type) (#td: typedef t) (#v: Ghost.erased t) (x: void_ptr) (y': Ghost.erased (ref td))
requires
(pts_to y' v ** pure (
ghost_ptr_gen_of_void_ptr x t == Ghost.reveal y'
))
returns y: (ref td)
ensures
(pts_to y v ** pure (
Ghost.reveal y' == y
))
{
rewrite (pts_to y' v) as (pts_to_or_null #t #td (ghost_ptr_gen_of_void_ptr x t) v);
let y = ptr_of_void_ptr #t #td #v x;
rewrite (pts_to_or_null y v) as (pts_to y v);
y
}
```
val ref_equiv
(#t: Type)
(#td: typedef t)
(r1 r2: ref td)
: Tot vprop
val pts_to_equiv
(#t: Type)
(#td: typedef t)
(r1 r2: ref td)
(v: Ghost.erased t)
: stt_ghost unit
(ref_equiv r1 r2 ** pts_to r1 v)
(fun _ -> ref_equiv r1 r2 ** pts_to r2 v)
val freeable
(#t: Type)
(#td: typedef t)
(r: ref td)
: Tot vprop
val freeable_dup
(#t: Type)
(#td: typedef t)
(r: ref td)
: stt_ghost unit
(freeable r)
(fun _ -> freeable r ** freeable r)
val freeable_equiv
(#t: Type)
(#td: typedef t)
(r1 r2: ref td)
: stt_ghost unit
(ref_equiv r1 r2 ** freeable r1)
(fun _ -> ref_equiv r1 r2 ** freeable r2) | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.C.Types.Base.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: Pulse.C.Types.Base.ptr td -> Pulse.Lib.Core.vprop | Prims.Tot | [
"total"
] | [] | [
"Pulse.C.Types.Base.typedef",
"Pulse.C.Types.Base.ptr",
"FStar.StrongExcludedMiddle.strong_excluded_middle",
"Prims.eq2",
"Pulse.C.Types.Base.null",
"Pulse.Lib.Core.emp",
"Prims.bool",
"Pulse.C.Types.Base.freeable",
"Pulse.Lib.Core.vprop"
] | [] | false | false | false | false | false | let freeable_or_null (#t: Type) (#td: typedef t) (r: ptr td) : Tot vprop =
| if FStar.StrongExcludedMiddle.strong_excluded_middle (r == null _) then emp else freeable r | false |
Steel.ST.HigherReference.fst | Steel.ST.HigherReference.with_local | val with_local
(#t: Type)
(init: t)
(#pre: vprop)
(#ret_t: Type)
(#post: ret_t -> vprop)
(body: (r: ref t) ->
STT ret_t
(pts_to r full_perm init `star` pre)
(fun v -> exists_ (pts_to r full_perm) `star` post v)
)
: STF ret_t pre post True (fun _ -> True) | val with_local
(#t: Type)
(init: t)
(#pre: vprop)
(#ret_t: Type)
(#post: ret_t -> vprop)
(body: (r: ref t) ->
STT ret_t
(pts_to r full_perm init `star` pre)
(fun v -> exists_ (pts_to r full_perm) `star` post v)
)
: STF ret_t pre post True (fun _ -> True) | let with_local
(#t: Type)
(init: t)
(#pre: vprop)
(#ret_t: Type)
(#post: ret_t -> vprop)
(body: (r: ref t) ->
STT ret_t
(pts_to r full_perm init `star` pre)
(fun v -> exists_ (pts_to r full_perm) `star` post v)
)
: STF ret_t pre post True (fun _ -> True)
= _push_frame ();
let r = _alloca init in
let v = body r in
let _ = elim_exists () in
_free_and_pop_frame r;
return v | {
"file_name": "lib/steel/Steel.ST.HigherReference.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 10,
"end_line": 145,
"start_col": 0,
"start_line": 128
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.HigherReference
open FStar.Ghost
open Steel.ST.Util
open Steel.ST.Coercions
module R = Steel.HigherReference
let ref (a:Type u#1)
: Type0
= R.ref a
let null (#a:Type)
: ref a
= R.null #a
let is_null (#a:Type) (r:ref a)
: b:bool{b <==> r == null}
= R.is_null r
let pts_to (#a:Type)
(r:ref a)
([@@@smt_fallback] p:perm)
([@@@smt_fallback] v:a)
: vprop
= R.pts_to r p v
let pts_to_injective_eq
(#a: Type)
(#opened:inames)
(#p0 #p1:perm)
(#v0 #v1:a)
(r: ref a)
: STGhost unit opened
(pts_to r p0 v0 `star` pts_to r p1 v1)
(fun _ -> pts_to r p0 v0 `star` pts_to r p1 v0)
(requires True)
(ensures fun _ -> v0 == v1)
= coerce_ghost
(fun _ -> R.higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #(hide v0) #(hide v1) r)
let pts_to_not_null #a #opened #p #v r
= extract_fact #opened (pts_to r p v) (r =!= null) (R.pts_to_not_null r p v);
()
let alloc (#a:Type) (x:a)
: ST (ref a)
emp
(fun r -> pts_to r full_perm x)
(requires True)
(ensures fun r -> not (is_null r))
= let r = coerce_steel (fun _ -> R.alloc x) in
r
let read (#a:Type)
(#p:perm)
(#v:erased a)
(r:ref a)
: ST a
(pts_to r p v)
(fun _ -> pts_to r p v)
(requires True)
(ensures fun x -> x == Ghost.reveal v)
= let u = coerce_steel (fun _ -> R.read r) in
return u
let write (#a:Type)
(#v:erased a)
(r:ref a)
(x:a)
: STT unit
(pts_to r full_perm v)
(fun _ -> pts_to r full_perm x)
= coerce_steel (fun _ -> R.write r x);
return ()
let free (#a:Type)
(#v:erased a)
(r:ref a)
: STT unit
(pts_to r full_perm v)
(fun _ -> emp)
= coerce_steel(fun _ -> R.free r);
return ()
/// Local primitive, to be extracted to Low* EPushFrame. To remember
/// that we need to call some pop_frame later, we insert some dummy
/// vprop into the context.
let _stack_frame : vprop = pure True
let _push_frame () : STT unit emp (fun _ -> _stack_frame) =
rewrite (pure True) _stack_frame
/// Local primitive, to be extracted to Low* EBufCreate
let _alloca (#a:Type) (x:a)
: ST (ref a)
emp
(fun r -> pts_to r full_perm x)
(requires True)
(ensures fun r -> not (is_null r))
= alloc x
/// Local primitive, to be extracted to Low* EPopFrame
let _free_and_pop_frame
(#a:Type)
(#v:erased a)
(r:ref a)
: STT unit
(pts_to r full_perm v `star` _stack_frame)
(fun _ -> emp)
= free r;
rewrite _stack_frame (pure True);
elim_pure _ | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Coercions.fsti.checked",
"Steel.HigherReference.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.HigherReference.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Steel.ST.Coercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | init: t -> body: (r: Steel.ST.HigherReference.ref t -> Steel.ST.Effect.STT ret_t)
-> Steel.ST.Effect.STF ret_t | Steel.ST.Effect.STF | [] | [] | [
"Steel.Effect.Common.vprop",
"Steel.ST.HigherReference.ref",
"Steel.Effect.Common.star",
"Steel.ST.HigherReference.pts_to",
"Steel.FractionalPermission.full_perm",
"Steel.ST.Util.exists_",
"Steel.ST.Util.return",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Prims.unit",
"Steel.ST.HigherReference._free_and_pop_frame",
"FStar.Ghost.erased",
"Steel.ST.Util.elim_exists",
"Steel.ST.HigherReference._alloca",
"Steel.ST.HigherReference._push_frame",
"Prims.l_True"
] | [] | false | true | false | false | false | let with_local
(#t: Type)
(init: t)
(#pre: vprop)
(#ret_t: Type)
(#post: (ret_t -> vprop))
(body:
(r: ref t
-> STT ret_t
((pts_to r full_perm init) `star` pre)
(fun v -> (exists_ (pts_to r full_perm)) `star` (post v))))
: STF ret_t pre post True (fun _ -> True) =
| _push_frame ();
let r = _alloca init in
let v = body r in
let _ = elim_exists () in
_free_and_pop_frame r;
return v | false |
FStar.Fin.fst | FStar.Fin.is_reflexive | val is_reflexive (#a:Type) (r: binary_relation a) : Type0 | val is_reflexive (#a:Type) (r: binary_relation a) : Type0 | let is_reflexive #a r = forall (x:a). x `r` x | {
"file_name": "ulib/FStar.Fin.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 50,
"end_line": 58,
"start_col": 0,
"start_line": 58
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Fin
/// This module is supposed to contain various lemmas about
/// finiteness. For now, it mainly provides a basic pigeonhole
/// principle
///
/// TODO: We might generalize this to also support general utilities
/// for reasoning about cardinality, relation with injections and
/// surjections, etc.
///
/// UPD. November 8, 2022 -- added support for custom equivalence relation-aware
/// pigeon principle lemma.
///
/// For better readability of lemmas, Argument types are kept explicit,
/// effectively duplicating the interface file declarations.
module S = FStar.Seq
(** Find an index of an element in [s] starting from [i] that validates [p] *)
let rec find (#a: Type) (s: S.seq a) (p: (a -> bool)) (i: under (S.length s)) =
if p (S.index s i)
then Some i
else if i + 1 < S.length s
then find #a s p (i + 1)
else None
(** Given a sequence [s] all of whose elements are at most [n], if the
length of [s] is greater than [n], then there are two distinct
indexes in [s] that contain the same element *)
let rec pigeonhole (#n: pos) (s: S.seq (under n)) =
if n = 1 then (0, 1)
else let k0 = S.index s 0 in
match find s (fun k -> k = k0) 1 with
| Some i -> 0, i
| None -> let (i1,i2) =
pigeonhole (S.init #(under (n-1)) n
(fun i -> let k = S.index s (i+1) in
if k<k0 then k else k-1))
in (i1+1, i2+1) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Fin.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: FStar.Fin.binary_relation a -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Fin.binary_relation",
"Prims.l_Forall",
"Prims.b2t"
] | [] | false | false | false | true | true | let is_reflexive #a r =
| forall (x: a). x `r` x | false |
FStar.Fin.fst | FStar.Fin.is_symmetric | val is_symmetric (#a:Type) (r: binary_relation a) : Type0 | val is_symmetric (#a:Type) (r: binary_relation a) : Type0 | let is_symmetric #a r = forall (x y:a). x `r` y == y `r` x | {
"file_name": "ulib/FStar.Fin.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 61,
"end_line": 61,
"start_col": 0,
"start_line": 61
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Fin
/// This module is supposed to contain various lemmas about
/// finiteness. For now, it mainly provides a basic pigeonhole
/// principle
///
/// TODO: We might generalize this to also support general utilities
/// for reasoning about cardinality, relation with injections and
/// surjections, etc.
///
/// UPD. November 8, 2022 -- added support for custom equivalence relation-aware
/// pigeon principle lemma.
///
/// For better readability of lemmas, Argument types are kept explicit,
/// effectively duplicating the interface file declarations.
module S = FStar.Seq
(** Find an index of an element in [s] starting from [i] that validates [p] *)
let rec find (#a: Type) (s: S.seq a) (p: (a -> bool)) (i: under (S.length s)) =
if p (S.index s i)
then Some i
else if i + 1 < S.length s
then find #a s p (i + 1)
else None
(** Given a sequence [s] all of whose elements are at most [n], if the
length of [s] is greater than [n], then there are two distinct
indexes in [s] that contain the same element *)
let rec pigeonhole (#n: pos) (s: S.seq (under n)) =
if n = 1 then (0, 1)
else let k0 = S.index s 0 in
match find s (fun k -> k = k0) 1 with
| Some i -> 0, i
| None -> let (i1,i2) =
pigeonhole (S.init #(under (n-1)) n
(fun i -> let k = S.index s (i+1) in
if k<k0 then k else k-1))
in (i1+1, i2+1)
[@@"opaque_to_smt"]
let is_reflexive #a r = forall (x:a). x `r` x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Fin.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: FStar.Fin.binary_relation a -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Fin.binary_relation",
"Prims.l_Forall",
"Prims.eq2",
"Prims.bool"
] | [] | false | false | false | true | true | let is_symmetric #a r =
| forall (x: a) (y: a). x `r` y == y `r` x | false |
Pruning.fst | Pruning.f | val f : x: FStar.Integers.int -> Prims.unit | let f (x:int) = assert (x + 1 == 1 + x) | {
"file_name": "examples/native_tactics/Pruning.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 39,
"end_line": 69,
"start_col": 0,
"start_line": 69
} | (*
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 Pruning
open FStar.Algebra.Monoid
open FStar.Array
open FStar.Axiomatic.Array
open FStar.BitVector
open FStar.Bytes
open FStar.Char
open FStar.Classical
open FStar.Constructive
open FStar.Crypto
open FStar.DependentMap
open FStar.ErasedLogic
open FStar.Fin
open FStar.Float
open FStar.FunctionalExtensionality
open FStar.Ghost
open FStar.Heap
open FStar.IndefiniteDescription
open FStar.Int
open FStar.Int128
open FStar.Int16
open FStar.Int32
open FStar.Int64
open FStar.Int8
open FStar.Int.Cast
open FStar.Integers
open FStar.IO
open FStar.List
open FStar.List.Tot
open FStar.List.Tot.Base
open FStar.List.Tot.Properties
open FStar.Map
open FStar.MarkovsPrinciple
open FStar.Math.Lemmas
open FStar.Math.Lib
open FStar.Matrix2
open FStar.MRef
open FStar.Mul
open FStar.Option
open FStar.Order
open FStar.OrdMap
open FStar.OrdMapProps
open FStar.OrdSet
open FStar.OrdSetProps
open FStar.PredicateExtensionality
open FStar.PropositionalExtensionality
open FStar.Reflection.V2
open FStar.Tactics.V2
open FStar.List | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.PropositionalExtensionality.fst.checked",
"FStar.PredicateExtensionality.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSetProps.fst.checked",
"FStar.OrdSet.fsti.checked",
"FStar.OrdMapProps.fst.checked",
"FStar.OrdMap.fsti.checked",
"FStar.Order.fst.checked",
"FStar.Option.fst.checked",
"FStar.Mul.fst.checked",
"FStar.MRef.fsti.checked",
"FStar.Matrix2.fsti.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.MarkovsPrinciple.fst.checked",
"FStar.Map.fsti.checked",
"FStar.List.Tot.Properties.fst.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.Integers.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Heap.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Float.fsti.checked",
"FStar.Fin.fsti.checked",
"FStar.ErasedLogic.fst.checked",
"FStar.DependentMap.fsti.checked",
"FStar.Crypto.fst.checked",
"FStar.Constructive.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.Bytes.fsti.checked",
"FStar.BitVector.fst.checked",
"FStar.Axiomatic.Array.fst.checked",
"FStar.Array.fsti.checked",
"FStar.Algebra.Monoid.fst.checked"
],
"interface_file": false,
"source_file": "Pruning.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PropositionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.PredicateExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.OrdSetProps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.OrdSet",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.OrdMapProps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.OrdMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Order",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Option",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.MRef",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Matrix2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.MarkovsPrinciple",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Map",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot.Properties",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int.Cast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int8",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int16",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int128",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Int",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IndefiniteDescription",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Float",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Fin",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.ErasedLogic",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.DependentMap",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Crypto",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Constructive",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Axiomatic.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Algebra.Monoid",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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.Integers.int -> Prims.unit | Prims.Tot | [
"total"
] | [] | [
"FStar.Integers.int",
"Prims._assert",
"Prims.eq2",
"FStar.Integers.int_t",
"FStar.Integers.Signed",
"FStar.Integers.Winfinite",
"FStar.Integers.op_Plus",
"Prims.unit"
] | [] | false | false | false | true | false | let f (x: int) =
| assert (x + 1 == 1 + x) | false |
|
FStar.Fin.fst | FStar.Fin.is_transitive | val is_transitive (#a:Type) (r: binary_relation a) : Type0 | val is_transitive (#a:Type) (r: binary_relation a) : Type0 | let is_transitive #a r = forall (x y z:a). x `r` y /\ y `r` z ==> x `r` z | {
"file_name": "ulib/FStar.Fin.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 73,
"end_line": 64,
"start_col": 0,
"start_line": 64
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Fin
/// This module is supposed to contain various lemmas about
/// finiteness. For now, it mainly provides a basic pigeonhole
/// principle
///
/// TODO: We might generalize this to also support general utilities
/// for reasoning about cardinality, relation with injections and
/// surjections, etc.
///
/// UPD. November 8, 2022 -- added support for custom equivalence relation-aware
/// pigeon principle lemma.
///
/// For better readability of lemmas, Argument types are kept explicit,
/// effectively duplicating the interface file declarations.
module S = FStar.Seq
(** Find an index of an element in [s] starting from [i] that validates [p] *)
let rec find (#a: Type) (s: S.seq a) (p: (a -> bool)) (i: under (S.length s)) =
if p (S.index s i)
then Some i
else if i + 1 < S.length s
then find #a s p (i + 1)
else None
(** Given a sequence [s] all of whose elements are at most [n], if the
length of [s] is greater than [n], then there are two distinct
indexes in [s] that contain the same element *)
let rec pigeonhole (#n: pos) (s: S.seq (under n)) =
if n = 1 then (0, 1)
else let k0 = S.index s 0 in
match find s (fun k -> k = k0) 1 with
| Some i -> 0, i
| None -> let (i1,i2) =
pigeonhole (S.init #(under (n-1)) n
(fun i -> let k = S.index s (i+1) in
if k<k0 then k else k-1))
in (i1+1, i2+1)
[@@"opaque_to_smt"]
let is_reflexive #a r = forall (x:a). x `r` x
[@@"opaque_to_smt"]
let is_symmetric #a r = forall (x y:a). x `r` y == y `r` x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Fin.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: FStar.Fin.binary_relation a -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Fin.binary_relation",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.l_and",
"Prims.b2t"
] | [] | false | false | false | true | true | let is_transitive #a r =
| forall (x: a) (y: a) (z: a). x `r` y /\ y `r` z ==> x `r` z | false |
FStar.Fin.fst | FStar.Fin.find | val find (#a: Type) (s: S.seq a) (p: (a -> bool)) (i: under (S.length s))
: Pure (option (in_ s))
(requires True)
(ensures (function
| None -> (forall (k: nat{i <= k /\ k < S.length s}). p (S.index s k) == false)
| Some j -> i <= j /\ p (S.index s j)))
(decreases (S.length s - i)) | val find (#a: Type) (s: S.seq a) (p: (a -> bool)) (i: under (S.length s))
: Pure (option (in_ s))
(requires True)
(ensures (function
| None -> (forall (k: nat{i <= k /\ k < S.length s}). p (S.index s k) == false)
| Some j -> i <= j /\ p (S.index s j)))
(decreases (S.length s - i)) | let rec find (#a: Type) (s: S.seq a) (p: (a -> bool)) (i: under (S.length s)) =
if p (S.index s i)
then Some i
else if i + 1 < S.length s
then find #a s p (i + 1)
else None | {
"file_name": "ulib/FStar.Fin.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 16,
"end_line": 41,
"start_col": 0,
"start_line": 36
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Fin
/// This module is supposed to contain various lemmas about
/// finiteness. For now, it mainly provides a basic pigeonhole
/// principle
///
/// TODO: We might generalize this to also support general utilities
/// for reasoning about cardinality, relation with injections and
/// surjections, etc.
///
/// UPD. November 8, 2022 -- added support for custom equivalence relation-aware
/// pigeon principle lemma.
///
/// For better readability of lemmas, Argument types are kept explicit,
/// effectively duplicating the interface file declarations.
module S = FStar.Seq | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Fin.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq a -> p: (_: a -> Prims.bool) -> i: FStar.Fin.under (FStar.Seq.Base.length s)
-> Prims.Pure (FStar.Pervasives.Native.option (FStar.Fin.in_ s)) | Prims.Pure | [
""
] | [] | [
"FStar.Seq.Base.seq",
"Prims.bool",
"FStar.Fin.under",
"FStar.Seq.Base.length",
"FStar.Seq.Base.index",
"FStar.Pervasives.Native.Some",
"FStar.Fin.in_",
"Prims.op_LessThan",
"Prims.op_Addition",
"FStar.Fin.find",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.option"
] | [
"recursion"
] | false | false | false | false | false | let rec find (#a: Type) (s: S.seq a) (p: (a -> bool)) (i: under (S.length s)) =
| if p (S.index s i) then Some i else if i + 1 < S.length s then find #a s p (i + 1) else None | false |
Hacl.Impl.Blake2.Generic.fst | Hacl.Impl.Blake2.Generic.blake2_init | val blake2_init:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms | val blake2_init:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms | let blake2_init #al #ms hash kk nn =
push_frame ();
let h0 = ST.get() in
let tmp = create 8ul (Spec.nat_to_word al 0) in
let r0 = rowi hash 0ul in
let r1 = rowi hash 1ul in
let r2 = rowi hash 2ul in
let r3 = rowi hash 3ul in
let iv0 = get_iv al 0ul in
let iv1 = get_iv al 1ul in
let iv2 = get_iv al 2ul in
let iv3 = get_iv al 3ul in
let iv4 = get_iv al 4ul in
let iv5 = get_iv al 5ul in
let iv6 = get_iv al 6ul in
let iv7 = get_iv al 7ul in
create_row #al #ms r2 iv0 iv1 iv2 iv3;
create_row #al #ms r3 iv4 iv5 iv6 iv7;
let salt = create (salt_len al) (u8 0) in
let personal = create (personal_len al) (u8 0) in
let p = create_default_params al salt personal in
serialize_params al kk nn p tmp;
let tmp0 = tmp.(0ul) in
let tmp1 = tmp.(1ul) in
let tmp2 = tmp.(2ul) in
let tmp3 = tmp.(3ul) in
let tmp4 = tmp.(4ul) in
let tmp5 = tmp.(5ul) in
let tmp6 = tmp.(6ul) in
let tmp7 = tmp.(7ul) in
let iv0' = iv0 ^. tmp0 in
let iv1' = iv1 ^. tmp1 in
let iv2' = iv2 ^. tmp2 in
let iv3' = iv3 ^. tmp3 in
let iv4' = iv4 ^. tmp4 in
let iv5' = iv5 ^. tmp5 in
let iv6' = iv6 ^. tmp6 in
let iv7' = iv7 ^. tmp7 in
create_row #al #ms r0 iv0' iv1' iv2' iv3';
create_row #al #ms r1 iv4' iv5' iv6' iv7';
let h1 = ST.get() in
assert (disjoint hash tmp);
assert (modifies (loc hash `union` loc tmp) h0 h1);
Lib.Sequence.eq_intro (state_v h1 hash) (Spec.blake2_init_hash al (Spec.blake2_default_params al) (v kk) (v nn));
pop_frame () | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 14,
"end_line": 818,
"start_col": 0,
"start_line": 774
} | module Hacl.Impl.Blake2.Generic
open FStar.Mul
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Lib.LoopCombinators
module ST = FStar.HyperStack.ST
module Seq = Lib.Sequence
module Loops = Lib.LoopCombinators
module Spec = Spec.Blake2
open Hacl.Impl.Blake2.Constants
open Hacl.Impl.Blake2.Core
#set-options "--z3rlimit 50 --max_ifuel 0 --max_fuel 0"
noextract
let is_valid_blake2_config (a : Spec.alg) (m : m_spec) =
match a, m with
| Spec.Blake2S, M32 | Spec.Blake2S, M128
| Spec.Blake2B, M32 | Spec.Blake2B, M256 -> true
| _ -> false
inline_for_extraction noextract
let valid_m_spec (a : Spec.alg) = m:m_spec{is_valid_blake2_config a m}
/// Accessors for constants
inline_for_extraction noextract
val get_iv:
a:Spec.alg
-> s: size_t{size_v s < 8} ->
Stack (word_t a)
(requires (fun h -> True))
(ensures (fun h0 z h1 -> h0 == h1 /\
v z == v (Seq.index (Spec.ivTable a) (v s))))
let get_iv a s =
recall_contents #(Spec.pub_word_t Spec.Blake2S) #8ul ivTable_S (Spec.ivTable Spec.Blake2S);
recall_contents #(Spec.pub_word_t Spec.Blake2B) #8ul ivTable_B (Spec.ivTable Spec.Blake2B);
[@inline_let]
let ivTable: (x:glbuffer (Spec.pub_word_t a) 8ul{witnessed x (Spec.ivTable a) /\ recallable x}) =
match a with
| Spec.Blake2S -> ivTable_S
| Spec.Blake2B -> ivTable_B
in
let r = index ivTable s in
secret #(Spec.wt a) r
inline_for_extraction noextract
val get_sigma:
s: size_t{v s < 160} ->
Stack Spec.sigma_elt_t
(requires (fun h -> True))
(ensures (fun h0 z h1 -> h0 == h1 /\ z == Lib.Sequence.(Spec.sigmaTable.[v s])))
let get_sigma s =
recall_contents sigmaTable Spec.sigmaTable;
index sigmaTable s
inline_for_extraction noextract
val get_sigma_sub:
start: size_t ->
i: size_t{v i < 16 /\ v start + v i < 160} ->
Stack Spec.sigma_elt_t
(requires (fun h -> True))
(ensures (fun h0 z h1 -> h0 == h1 /\ v z == v (Seq.index Spec.sigmaTable (v start + v i))))
let get_sigma_sub start i = get_sigma (start +. i)
inline_for_extraction noextract
let rounds_t (a:Spec.alg): size_t = size (Spec.rounds a)
inline_for_extraction noextract
val size_to_word: al:Spec.alg -> s:size_t -> u:word_t al{u == Spec.nat_to_word al (v s)}
let size_to_word al s = match al with
| Spec.Blake2S -> size_to_uint32 s
| Spec.Blake2B -> size_to_uint64 s
inline_for_extraction noextract
val size_to_limb: al:Spec.alg -> s:size_t -> u:Spec.limb_t al{u == Spec.nat_to_limb al (v s)}
let size_to_limb al s = match al with
| Spec.Blake2S -> size_to_uint64 s
| Spec.Blake2B -> to_u128 (size_to_uint64 s)
/// Constants
/// Define algorithm functions
inline_for_extraction noextract
val g1: #al:Spec.alg -> #m:m_spec -> wv:state_p al m -> a:index_t -> b:index_t -> r:rotval (Spec.wt al) ->
Stack unit
(requires (fun h -> live h wv /\ a <> b))
(ensures (fun h0 _ h1 -> modifies (loc wv) h0 h1
/\ (state_v h1 wv) == Spec.g1 al (state_v h0 wv) (v a) (v b) r))
let g1 #al #m wv a b r =
let h0 = ST.get() in
let wv_a = rowi wv a in
let wv_b = rowi wv b in
xor_row wv_a wv_b;
ror_row wv_a r;
let h2 = ST.get() in
Lib.Sequence.eq_intro (state_v h2 wv) (Spec.g1 al (state_v h0 wv) (v a) (v b) r)
#push-options "--z3rlimit 100 --max_fuel 1 --max_ifuel 1"
inline_for_extraction noextract
val g2: #al:Spec.alg -> #m:m_spec -> wv:state_p al m -> a:index_t -> b:index_t -> x:row_p al m ->
Stack unit
(requires (fun h -> live h wv /\ live h x /\ disjoint wv x /\ a <> b))
(ensures (fun h0 _ h1 -> modifies (loc wv) h0 h1
/\ state_v h1 wv == Spec.g2 al (state_v h0 wv) (v a) (v b) (row_v h0 x)))
let g2 #al #m wv a b x =
let h0 = ST.get() in
let wv_a = rowi wv a in
let wv_b = rowi wv b in
add_row wv_a wv_b;
add_row wv_a x;
let h1 = ST.get() in
Lib.Sequence.eq_intro (state_v h1 wv) (Spec.g2 al (state_v h0 wv) (v a) (v b) (row_v h0 x))
#push-options "--z3rlimit 100 --max_fuel 1 --max_ifuel 1"
inline_for_extraction noextract
val g2z: #al:Spec.alg -> #m:m_spec -> wv:state_p al m -> a:index_t -> b:index_t ->
Stack unit
(requires (fun h -> live h wv /\ a <> b))
(ensures (fun h0 _ h1 -> modifies (loc wv) h0 h1
/\ state_v h1 wv == Spec.g2z al (state_v h0 wv) (v a) (v b)))
let g2z #al #m wv a b =
let h0 = ST.get() in
let wv_a = rowi wv a in
let wv_b = rowi wv b in
add_row wv_a wv_b;
let h1 = ST.get() in
Lib.Sequence.eq_intro (state_v h1 wv) (Spec.g2z al (state_v h0 wv) (v a) (v b))
inline_for_extraction noextract
val blake2_mixing : #al:Spec.alg -> #m:m_spec -> wv:state_p al m -> x:row_p al m -> y:row_p al m ->
Stack unit
(requires (fun h -> live h wv /\ live h x /\ live h y /\ disjoint wv x /\ disjoint wv y))
(ensures (fun h0 _ h1 -> modifies (loc wv) h0 h1
/\ state_v h1 wv == Spec.blake2_mixing al (state_v h0 wv) (row_v h0 x) (row_v h0 y)))
let blake2_mixing #al #m wv x y =
let h0 = ST.get() in
push_frame ();
let a = 0ul in
let b = 1ul in
let c = 2ul in
let d = 3ul in
[@inline_let]
let r0 = normalize_term (Lib.Sequence.index (Spec.rTable al) 0) in
normalize_term_spec (Lib.Sequence.index (Spec.rTable al) 0);
[@inline_let]
let r1 = normalize_term (Lib.Sequence.index (Spec.rTable al) 1) in
normalize_term_spec (Lib.Sequence.index (Spec.rTable al) 1);
[@inline_let]
let r2 = normalize_term (Lib.Sequence.index (Spec.rTable al) 2) in
normalize_term_spec (Lib.Sequence.index (Spec.rTable al) 2);
[@inline_let]
let r3 = normalize_term (Lib.Sequence.index (Spec.rTable al) 3) in
normalize_term_spec (Lib.Sequence.index (Spec.rTable al) 3);
let h1 = ST.get() in
g2 wv a b x;
g1 wv d a r0;
g2z wv c d;
g1 wv b c r1;
g2 wv a b y;
g1 wv d a r2;
g2z wv c d;
g1 wv b c r3;
let h2 = ST.get() in
pop_frame ();
let h3 = ST.get() in
assert(modifies (loc wv) h0 h3);
Lib.Sequence.eq_intro (state_v h2 wv) (Spec.blake2_mixing al (state_v h1 wv) (row_v h1 x) (row_v h1 y))
#pop-options
inline_for_extraction noextract
val diag: #a:Spec.alg -> #m:m_spec -> wv:state_p a m
-> Stack unit
(requires (fun h -> live h wv))
(ensures (fun h0 _ h1 -> modifies (loc wv) h0 h1 /\
state_v h1 wv == Spec.diag (state_v h0 wv)))
let diag #a #m wv =
let r1 = rowi wv 1ul in
let r2 = rowi wv 2ul in
let r3 = rowi wv 3ul in
let h0 = ST.get() in
permr_row r1 1ul;
permr_row r2 2ul;
permr_row r3 3ul
inline_for_extraction noextract
val undiag: #a:Spec.alg -> #m:m_spec -> wv:state_p a m
-> Stack unit
(requires (fun h -> live h wv))
(ensures (fun h0 _ h1 -> modifies (loc wv) h0 h1 /\
state_v h1 wv == Spec.undiag (state_v h0 wv)))
let undiag #a #m wv =
let r1 = rowi wv 1ul in
let r2 = rowi wv 2ul in
let r3 = rowi wv 3ul in
let h0 = ST.get() in
permr_row r1 3ul;
permr_row r2 2ul;
permr_row r3 1ul
inline_for_extraction noextract
val gather_state: #a:Spec.alg -> #ms:m_spec -> st:state_p a ms -> m:block_w a -> start:size_t{v start <= 144} -> Stack unit
(requires (fun h -> live h st /\ live h m /\ disjoint st m))
(ensures (fun h0 _ h1 -> modifies (loc st) h0 h1 /\
state_v h1 st == Spec.gather_state a (as_seq h0 m) (v start)))
inline_for_extraction noextract
let get_sigma' (start: size_t { v start <= 144 }) (i: size_t { normalize (i <=. 15ul) }):
Stack Spec.sigma_elt_t
(requires (fun h -> True))
(ensures (fun h0 z h1 ->
h0 == h1 /\ z == Lib.Sequence.(Spec.sigmaTable.[v start + v i])))
=
get_sigma (start +! i)
#push-options "--z3rlimit 500"
let gather_state #a #ms st m start =
let h0 = ST.get() in
let r0 = rowi st 0ul in
let r1 = rowi st 1ul in
let r2 = rowi st 2ul in
let r3 = rowi st 3ul in
let s0 = get_sigma' start 0ul in
let s1 = get_sigma' start 1ul in
let s2 = get_sigma' start 2ul in
let s3 = get_sigma' start 3ul in
let s4 = get_sigma' start 4ul in
let s5 = get_sigma' start 5ul in
let s6 = get_sigma' start 6ul in
let s7 = get_sigma' start 7ul in
let s8 = get_sigma' start 8ul in
let s9 = get_sigma' start 9ul in
let s10 = get_sigma' start 10ul in
let s11 = get_sigma' start 11ul in
let s12 = get_sigma' start 12ul in
let s13 = get_sigma' start 13ul in
let s14 = get_sigma' start 14ul in
let s15 = get_sigma' start 15ul in
let h1 = ST.get() in
gather_row r0 m s0 s2 s4 s6;
let h2 = ST.get() in
gather_row r1 m s1 s3 s5 s7;
let h3 = ST.get() in
gather_row r2 m s8 s10 s12 s14;
let h4 = ST.get() in
gather_row r3 m s9 s11 s13 s15;
let h5 = ST.get() in
assert(modifies (loc st) h0 h5);
Lib.Sequence.eq_intro (state_v h5 st) (Spec.gather_state a (as_seq h0 m) (v start))
inline_for_extraction noextract
val blake2_round : #al:Spec.alg -> #ms:m_spec -> wv:state_p al ms -> m:block_w al -> i:size_t ->
Stack unit
(requires (fun h -> live h wv /\ live h m /\ disjoint wv m))
(ensures (fun h0 _ h1 -> modifies (loc wv) h0 h1
/\ state_v h1 wv == Spec.blake2_round al (as_seq h0 m) (v i) (state_v h0 wv)))
let blake2_round #al #ms wv m i =
push_frame();
let start_idx = (i %. size 10) *. size 16 in
assert (v start_idx == (v i % 10) * 16);
assert (v start_idx <= 144);
let m_st = alloc_state al ms in
gather_state m_st m start_idx;
let x = rowi m_st 0ul in
let y = rowi m_st 1ul in
let z = rowi m_st 2ul in
let w = rowi m_st 3ul in
let h1 = ST.get() in
assert (disjoint wv m_st);
assert (disjoint m_st wv);
assert (disjoint x wv);
assert (disjoint wv x);
assert (disjoint y wv);
assert (disjoint wv y);
assert (disjoint z wv);
assert (disjoint wv z);
assert (disjoint w wv);
assert (disjoint wv w);
blake2_mixing wv x y;
diag wv;
blake2_mixing wv z w;
undiag wv;
pop_frame ()
inline_for_extraction noextract
val blake2_compress0:
#al:Spec.alg
-> m_s: block_p al
-> m_w: block_w al
-> Stack unit
(requires (fun h -> live h m_s /\ live h m_w /\ disjoint m_s m_w))
(ensures (fun h0 _ h1 -> modifies (loc m_w) h0 h1
/\ as_seq h1 m_w == Spec.blake2_compress0 al (as_seq h0 m_s)))
let blake2_compress0 #al m_s m_w =
uints_from_bytes_le m_w m_s
inline_for_extraction noextract
val blake2_compress1:
#al:Spec.alg
-> #m:m_spec
-> wv: state_p al m
-> s_iv: state_p al m
-> offset: Spec.limb_t al
-> flag: bool ->
Stack unit
(requires (fun h -> live h wv /\ live h s_iv /\ disjoint wv s_iv))
(ensures (fun h0 _ h1 -> modifies (loc wv) h0 h1
/\ state_v h1 wv == Spec.blake2_compress1 al (state_v h0 s_iv) offset flag))
let blake2_compress1 #al #m wv s_iv offset flag =
let h0 = ST.get() in
push_frame();
let mask = alloc_row al m in
[@inline_let]
let wv_12 = Spec.limb_to_word al offset in
[@inline_let]
let wv_13 = Spec.limb_to_word al (offset >>. (size (bits (Spec.wt al)))) in
// SH: TODO: for some reason, ``ones`` below doesn't get inlined by KaRaMeL,
// causing an extraction problem. The 3 lines below are a hack to fix
// extraction for the time being:
// [> let wv_14 = if flag then (ones (Spec.wt al) SEC) else (Spec.zero al) in
// After investigation, it is because ones is [@(strict_on_arguments [0])],
// and so isn't unfolded if its first argument is not normalized to a constant.
// However, the first argument should always be normalized (I checked the
// output generated by KaRaMeL and the definitions).
(**) normalize_term_spec (Spec.wt al);
[@inline_let] let wt_al = normalize_term (Spec.wt al) in
let wv_14 = if flag then ones wt_al SEC else (Spec.zero al) in
// end of the TODO
let wv_15 = Spec.zero al in
create_row mask wv_12 wv_13 wv_14 wv_15;
copy_state wv s_iv;
let wv3 = rowi wv 3ul in
xor_row wv3 mask;
pop_frame();
let h1 = ST.get() in
assert(modifies (loc wv) h0 h1);
Lib.Sequence.eq_intro (state_v h1 wv) (Spec.blake2_compress1 al (state_v h0 s_iv) offset flag)
inline_for_extraction noextract
val blake2_compress2 :
#al:Spec.alg
-> #ms:m_spec
-> wv: state_p al ms
-> m: block_w al ->
Stack unit
(requires (fun h -> live h wv /\ live h m /\ disjoint wv m))
(ensures (fun h0 _ h1 -> modifies1 wv h0 h1
/\ state_v h1 wv == Spec.blake2_compress2 al (state_v h0 wv) (as_seq h0 m)))
#push-options "--z3rlimit 400"
let blake2_compress2 #al #ms wv m =
let h0 = ST.get () in
[@inline_let]
let a_spec = Spec.state al in
[@inline_let]
let refl h = state_v h wv in
[@inline_let]
let footprint = Ghost.hide(loc wv) in
[@inline_let]
let spec h = Spec.blake2_round al h.[|m|] in
loop_refl h0 (rounds_t al) a_spec refl footprint spec
(fun i ->
Loops.unfold_repeati (Spec.rounds al) (spec h0) (state_v h0 wv) (v i);
blake2_round wv m i)
#pop-options
inline_for_extraction noextract
val blake2_compress3 :
#al:Spec.alg
-> #ms:m_spec
-> s_iv:state_p al ms
-> wv:state_p al ms ->
Stack unit
(requires (fun h -> live h s_iv /\ live h wv /\ disjoint s_iv wv))
(ensures (fun h0 _ h1 -> modifies (loc s_iv) h0 h1
/\ state_v h1 s_iv == Spec.blake2_compress3 al (state_v h0 wv) (state_v h0 s_iv)))
let blake2_compress3 #al #ms s_iv wv =
let h0 = ST.get() in
let s0 = rowi s_iv 0ul in
let s1 = rowi s_iv 1ul in
let r0 = rowi wv 0ul in
let r1 = rowi wv 1ul in
let r2 = rowi wv 2ul in
let r3 = rowi wv 3ul in
assert (disjoint s0 wv);
assert (disjoint wv s0);
assert (disjoint s1 wv);
assert (disjoint wv s1);
assert (disjoint r0 s0);
assert (disjoint r2 s0);
assert (disjoint r1 s1);
assert (disjoint r3 s1);
xor_row s0 r0;
let h1 = ST.get() in
xor_row s0 r2;
let h2 = ST.get() in
xor_row s1 r1;
let h3 = ST.get() in
xor_row s1 r3;
let h4 = ST.get() in
assert (modifies (loc s_iv) h0 h4);
let open Lib.Sequence in
assert (row_v h0 r0 == (state_v h0 wv).[0]);
assert (row_v h1 r2 == (state_v h0 wv).[2]);
assert (row_v h4 s0 == Spec.(((state_v h0 s_iv).[0] ^| (state_v h0 wv).[0]) ^| (state_v h0 wv).[2]));
assert (row_v h4 s1 == Spec.(((state_v h0 s_iv).[1] ^| (state_v h0 wv).[1]) ^| (state_v h0 wv).[3]));
eq_intro (state_v h2 s_iv) ((state_v h0 s_iv).[0] <- row_v h4 s0);
eq_intro (state_v h4 s_iv) ((state_v h2 s_iv).[1] <- row_v h4 s1);
eq_intro (state_v h4 s_iv) (Spec.blake2_compress3 al (state_v h0 wv) (state_v h0 s_iv))
inline_for_extraction noextract
let compress_t (al:Spec.alg) (ms:m_spec) =
wv:state_p al ms
-> s: state_p al ms
-> m: block_p al
-> offset: Spec.limb_t al
-> flag: bool ->
Stack unit
(requires (fun h -> live h wv /\ live h s /\ live h m /\ disjoint s m /\ disjoint wv s /\ disjoint wv m))
(ensures (fun h0 _ h1 -> modifies (loc s |+| loc wv) h0 h1
/\ state_v h1 s == Spec.blake2_compress al (state_v h0 s) h0.[|m|] offset flag))
inline_for_extraction noextract
val blake2_compress: #al:Spec.alg -> #ms:m_spec -> compress_t al ms
let blake2_compress #al #ms wv s m offset flag =
push_frame();
let m_w = create 16ul (Spec.zero al) in
blake2_compress0 #al m m_w;
blake2_compress1 wv s offset flag;
blake2_compress2 wv m_w;
blake2_compress3 s wv;
pop_frame()
inline_for_extraction noextract
let blake2_update_block_st (al:Spec.alg) (ms:m_spec) =
wv:state_p al ms
-> hash: state_p al ms
-> flag: bool
-> totlen: Spec.limb_t al{v totlen <= Spec.max_limb al}
-> d: block_p al ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h d /\ disjoint hash d /\ disjoint wv hash /\ disjoint wv d))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1
/\ state_v h1 hash == Spec.blake2_update_block al flag (v totlen) h0.[|d|] (state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_block: #al:Spec.alg -> #ms:m_spec -> blake2_update_block_st al ms
let blake2_update_block #al #ms wv hash flag totlen d =
blake2_compress wv hash d totlen flag
inline_for_extraction noextract
let blake2_update1_st (al:Spec.alg) (ms:m_spec) =
#len:size_t
-> wv: state_p al ms
-> hash: state_p al ms
-> prev: Spec.limb_t al{v prev + v len <= Spec.max_limb al}
-> d: lbuffer uint8 len
-> i: size_t{v i < length d / Spec.size_block al} ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h d /\ disjoint hash d /\ disjoint wv hash /\ disjoint wv d))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1
/\ state_v h1 hash == Spec.blake2_update1 al (v prev) h0.[|d|] (v i) (state_v h0 hash)))
inline_for_extraction noextract
val blake2_update1: #al:Spec.alg -> #ms:m_spec -> blake2_update_block: blake2_update_block_st al ms -> blake2_update1_st al ms
let blake2_update1 #al #ms blake2_update_block #len wv hash prev d i =
let totlen = prev +. size_to_limb al ((i+!1ul) *! size_block al) in
assert (v totlen == v prev + (v i + 1) * Spec.size_block al);
let b = sub d (i *. size_block al) (size_block al) in
let h = ST.get() in
assert (as_seq h b == Spec.get_blocki al (as_seq h d) (v i));
blake2_update_block wv hash false totlen b
inline_for_extraction noextract
let blake2_update_last_st (al:Spec.alg) (ms:m_spec) =
#len:size_t
-> wv: state_p al ms
-> hash: state_p al ms
-> prev: Spec.limb_t al{v prev + v len <= Spec.max_limb al}
-> rem: size_t {v rem <= v len /\ v rem <= Spec.size_block al}
-> d: lbuffer uint8 len ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h d /\ disjoint hash d /\ disjoint wv hash /\ disjoint wv d))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1
/\ state_v h1 hash == Spec.blake2_update_last al (v prev) (v rem) h0.[|d|] (state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_last:
#al:Spec.alg
-> #ms:m_spec
-> blake2_update_block: blake2_update_block_st al ms
-> blake2_update_last_st al ms
let blake2_update_last #al #ms blake2_update_block #len wv hash prev rem d =
let h0 = ST.get () in
[@inline_let]
let spec _ h1 = state_v h1 hash == Spec.blake2_update_last al (v prev) (v rem) h0.[|d|] (state_v h0 hash) in
salloc1 h0 (size_block al) (u8 0) (Ghost.hide (loc hash |+| loc wv)) spec
(fun last_block ->
let last = sub d (len -! rem) rem in
let h1 = ST.get() in
update_sub last_block 0ul rem last;
let h2 = ST.get() in
as_seq_gsub h1 d (len -! rem) rem;
assert (as_seq h1 last == Seq.sub (as_seq h1 d) (v len - v rem) (v rem));
assert (as_seq h1 last == Seq.slice (as_seq h0 d) (v len - v rem) (v len));
assert (as_seq h2 last_block == Spec.get_last_padded_block al (as_seq h0 d) (v rem));
let totlen = prev +. (size_to_limb al len) in
blake2_update_block wv hash true totlen last_block;
let h3 = ST.get() in
assert (v totlen == v prev + v len);
assert (state_v h3 hash == Spec.blake2_update_block al true (v totlen) (as_seq h2 last_block) (state_v h0 hash)))
inline_for_extraction noextract
let blake2_init_st (al:Spec.alg) (ms:m_spec) =
hash: state_p al ms
-> kk: size_t{v kk <= Spec.max_key al}
-> nn: size_t{1 <= v nn /\ v nn <= Spec.max_output al} ->
Stack unit
(requires (fun h -> live h hash))
(ensures (fun h0 _ h1 -> modifies (loc hash) h0 h1 /\
state_v h1 hash == Spec.blake2_init_hash al (Spec.blake2_default_params al) (v kk) (v nn)))
inline_for_extraction noextract
val serialize_params (al:Spec.alg)
(kk:size_t{v kk <= Spec.max_key al})
(nn: size_t{1 <= v nn /\ v nn <= Spec.max_output al})
(p: blake2_params al)
(b: lbuffer (word_t al) 8ul)
: Stack unit
(requires fun h ->
live h b /\
blake2_params_inv h p /\
LowStar.Buffer.loc_disjoint (loc b) (blake2_params_loc p) /\
as_seq h b == Seq.create 8 (Spec.nat_to_word al 0)
)
(ensures fun h0 _ h1 ->
modifies (loc b) h0 h1 /\
as_seq h1 b == Spec.serialize_blake2_params
(Spec.set_key_length (Spec.set_digest_length (blake2_params_v h0 p) (v nn)) (v kk)))
#push-options "--z3rlimit 100 --fuel 0"
inline_for_extraction noextract
let serialize_params_blake2s
(kk:size_t{v kk <= Spec.max_key Spec.Blake2S})
(nn: size_t{1 <= v nn /\ v nn <= Spec.max_output Spec.Blake2S})
(p: blake2_params Spec.Blake2S)
(b: lbuffer (word_t Spec.Blake2S) 8ul)
: Stack unit
(requires fun h -> live h b /\
blake2_params_inv h p /\
LowStar.Buffer.loc_disjoint (loc b) (blake2_params_loc p) /\
as_seq h b == Seq.create 8 (u32 0)
)
(ensures fun h0 _ h1 ->
modifies (loc b) h0 h1 /\
as_seq h1 b == Spec.serialize_blake2_params
(Spec.set_key_length (Spec.set_digest_length (blake2_params_v h0 p) (v nn)) (v kk)))
= let h0 = ST.get () in
[@inline_let]
let kk_shift_8 = shift_left (to_u32 kk) (size 8) in
[@inline_let]
let fanout_shift_16 = shift_left (to_u32 p.fanout) (size 16) in
[@inline_let]
let depth_shift_24 = shift_left (to_u32 p.depth) (size 24) in
[@inline_let]
let v0 = (to_u32 nn) ^. kk_shift_8 ^. fanout_shift_16 ^. depth_shift_24 in
[@inline_let]
let v1 = p.leaf_length in
[@inline_let]
let v2 = p.node_offset in
[@inline_let]
let node_depth_shift_16 = shift_left (to_u32 p.node_depth) (size 16) in
[@inline_let]
let inner_length_shift_16 = shift_left (to_u32 p.inner_length) (size 24) in
[@inline_let]
let v3 = (to_u32 p.xof_length) ^. node_depth_shift_16 ^. inner_length_shift_16 in
uints_from_bytes_le (sub b 4ul 2ul) p.salt;
uints_from_bytes_le (sub b 6ul 2ul) p.personal;
// AF: Putting these writes *after* modifications on a subbuffer of b helps with modifies-reasoning:
// By putting them before, F* struggles with proving that b[0..3] is not modified by uints_from_bytes_le
b.(0ul) <- v0;
b.(1ul) <- v1;
b.(2ul) <- v2;
b.(3ul) <- v3;
let h1 = ST.get () in
let aux () : Lemma (as_seq h1 b `Seq.equal` Spec.serialize_blake2s_params
(Spec.set_key_length (Spec.set_digest_length (blake2_params_v h0 p) (v nn)) (v kk))) =
let open Lib.Sequence in
let open Lib.ByteSequence in
let s0 = (u32 (v nn)) ^.
(u32 (v kk) <<. (size 8)) ^.
(u32 (v p.fanout) <<. (size 16)) ^.
(u32 (v p.depth) <<. (size 24)) in
let s1 = p.leaf_length in
let s2 = p.node_offset in
let s3 = (u32 (v p.xof_length)) ^.
(u32 (v p.node_depth) <<. (size 16)) ^.
(u32 (v p.inner_length) <<. (size 24)) in
let salt_u32: lseq uint32 2 = uints_from_bytes_le (as_seq h0 (get_salt p)) in
let s4 = salt_u32.[0] in
let s5 = salt_u32.[1] in
let personal_u32: lseq uint32 2 = uints_from_bytes_le (as_seq h0 (get_personal p)) in
let s6 = personal_u32.[0] in
let s7 = personal_u32.[1] in
[@inline_let]
let l = [s0; s1; s2; s3; s4; s5; s6; s7] in
assert_norm (List.Tot.length l == 8);
// There seems to be something not triggering with createL, requiring the
// following lemma calls, and assert_norms to relate List.index to the
// actual elements
assert_norm (List.Tot.index l 0 == s0);
assert_norm (List.Tot.index l 1 == s1);
assert_norm (List.Tot.index l 2 == s2);
assert_norm (List.Tot.index l 3 == s3);
assert_norm (List.Tot.index l 4 == s4);
assert_norm (List.Tot.index l 5 == s5);
assert_norm (List.Tot.index l 6 == s6);
assert_norm (List.Tot.index l 7 == s7);
of_list_index l 0;
of_list_index l 1;
of_list_index l 2;
of_list_index l 3;
of_list_index l 4;
of_list_index l 5;
of_list_index l 6;
of_list_index l 7
in
aux()
inline_for_extraction noextract
let serialize_params_blake2b
(kk:size_t{v kk <= Spec.max_key Spec.Blake2B})
(nn: size_t{1 <= v nn /\ v nn <= Spec.max_output Spec.Blake2B})
(p: blake2_params Spec.Blake2B)
(b: lbuffer (word_t Spec.Blake2B) 8ul)
: Stack unit
(requires fun h -> live h b /\
blake2_params_inv #Spec.Blake2B h p /\
LowStar.Buffer.loc_disjoint (loc b) (blake2_params_loc p) /\
as_seq h b == Seq.create 8 (u64 0)
)
(ensures fun h0 _ h1 ->
modifies (loc b) h0 h1 /\
as_seq h1 b == Spec.serialize_blake2_params
(Spec.set_key_length (Spec.set_digest_length (blake2_params_v h0 p) (v nn)) (v kk)))
= let h0 = ST.get () in
[@inline_let]
let kk_shift_8 = shift_left (to_u64 kk) (size 8) in
[@inline_let]
let fanout_shift_16 = shift_left (to_u64 p.fanout) (size 16) in
[@inline_let]
let depth_shift_24 = shift_left (to_u64 p.depth) (size 24) in
[@inline_let]
let leaf_length_shift_32 = shift_left (to_u64 p.leaf_length) (size 32) in
[@inline_let]
let v0 = (to_u64 nn) ^. kk_shift_8 ^. fanout_shift_16 ^. depth_shift_24 ^. leaf_length_shift_32 in
[@inline_let]
let xof_length_shift_32 = shift_left (to_u64 p.xof_length) (size 32) in
[@inline_let]
let v1 = (to_u64 p.node_offset) ^. xof_length_shift_32 in
[@inline_let]
let inner_length_shift_8 = shift_left (to_u64 p.inner_length) (size 8) in
[@inline_let]
let v2 = (to_u64 p.node_depth) ^. inner_length_shift_8 in
uints_from_bytes_le (sub b 4ul 2ul) p.salt;
uints_from_bytes_le (sub b 6ul 2ul) p.personal;
b.(0ul) <- v0;
b.(1ul) <- v1;
b.(2ul) <- v2;
b.(3ul) <- (u64 0);
let h1 = ST.get () in
let aux () : Lemma (as_seq h1 b `Seq.equal` Spec.serialize_blake2b_params
(Spec.set_key_length (Spec.set_digest_length (blake2_params_v h0 p) (v nn)) (v kk))) =
let open Lib.Sequence in
let open Lib.ByteSequence in
let s0 = (u64 (v nn)) ^.
(u64 (v kk) <<. (size 8)) ^.
(u64 (v p.fanout) <<. (size 16)) ^.
(u64 (v p.depth) <<. (size 24)) ^.
(u64 (v p.leaf_length) <<. (size 32)) in
let s1 = (u64 (v p.node_offset)) ^.
(u64 (v p.xof_length) <<. (size 32)) in
// The serialization corresponding to s2 contains node_depth and inner_length,
// followed by the 14 reserved bytes which always seem to be zeros, and can hence
// be ignored when building the corresponding uint64 using xor's
let s2 = (u64 (v p.node_depth)) ^.
(u64 (v p.inner_length) <<. (size 8)) in
// s3 corresponds to the remaining of the reserved bytes
let s3 = u64 0 in
let salt_u64: lseq uint64 2 = uints_from_bytes_le (as_seq h0 (get_salt p)) in
let s4 = salt_u64.[0] in
let s5 = salt_u64.[1] in
let personal_u64: lseq uint64 2 = uints_from_bytes_le (as_seq h0 (get_personal p)) in
let s6 = personal_u64.[0] in
let s7 = personal_u64.[1] in
[@inline_let]
let l = [s0; s1; s2; s3; s4; s5; s6; s7] in
assert_norm (List.Tot.length l == 8);
// There seems to be something not triggering with createL, requiring the
// following lemma calls, and assert_norms to relate List.index to the
// actual elements
assert_norm (List.Tot.index l 0 == s0);
assert_norm (List.Tot.index l 1 == s1);
assert_norm (List.Tot.index l 2 == s2);
assert_norm (List.Tot.index l 3 == s3);
assert_norm (List.Tot.index l 4 == s4);
assert_norm (List.Tot.index l 5 == s5);
assert_norm (List.Tot.index l 6 == s6);
assert_norm (List.Tot.index l 7 == s7);
of_list_index l 0;
of_list_index l 1;
of_list_index l 2;
of_list_index l 3;
of_list_index l 4;
of_list_index l 5;
of_list_index l 6;
of_list_index l 7
in
aux()
#pop-options
let serialize_params al kk nn p b =
match al with
| Spec.Blake2S -> serialize_params_blake2s kk nn p b
| Spec.Blake2B -> serialize_params_blake2b kk nn p b
inline_for_extraction noextract
val blake2_init:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms | {
"checked_file": "/",
"dependencies": [
"Spec.Blake2.fst.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"Hacl.Impl.Blake2.Constants.fst.checked",
"FStar.UInt32.fsti.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",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Blake2.Constants",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Blake2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Blake2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Blake2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 500,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Impl.Blake2.Generic.blake2_init_st al ms | Prims.Tot | [
"total"
] | [] | [
"Spec.Blake2.Definitions.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Hacl.Impl.Blake2.Core.state_p",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Spec.Blake2.Definitions.max_key",
"Prims.l_and",
"Spec.Blake2.Definitions.max_output",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Lib.Sequence.eq_intro",
"Spec.Blake2.Definitions.row",
"Hacl.Impl.Blake2.Core.state_v",
"Spec.Blake2.blake2_init_hash",
"Spec.Blake2.Definitions.blake2_default_params",
"Prims._assert",
"Lib.Buffer.modifies",
"Lib.Buffer.union",
"Lib.Buffer.loc",
"Lib.Buffer.MUT",
"Hacl.Impl.Blake2.Core.element_t",
"Hacl.Impl.Blake2.Core.word_t",
"Lib.Buffer.disjoint",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Impl.Blake2.Core.create_row",
"Lib.IntTypes.int_t",
"Spec.Blake2.Definitions.wt",
"Lib.IntTypes.SEC",
"Lib.IntTypes.op_Hat_Dot",
"Lib.Buffer.op_Array_Access",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.Blake2.Generic.serialize_params",
"Hacl.Impl.Blake2.Core.blake2_params",
"Hacl.Impl.Blake2.Core.create_default_params",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.U8",
"Hacl.Impl.Blake2.Core.personal_len",
"Lib.Buffer.create",
"Lib.IntTypes.uint8",
"Lib.IntTypes.u8",
"Lib.Buffer.lbuffer",
"Hacl.Impl.Blake2.Core.salt_len",
"Hacl.Impl.Blake2.Generic.get_iv",
"Hacl.Impl.Blake2.Core.row_len",
"Hacl.Impl.Blake2.Core.rowi",
"Hacl.Impl.Blake2.Core.row_p",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Spec.Blake2.Definitions.nat_to_word",
"FStar.HyperStack.ST.push_frame"
] | [] | false | false | false | false | false | let blake2_init #al #ms hash kk nn =
| push_frame ();
let h0 = ST.get () in
let tmp = create 8ul (Spec.nat_to_word al 0) in
let r0 = rowi hash 0ul in
let r1 = rowi hash 1ul in
let r2 = rowi hash 2ul in
let r3 = rowi hash 3ul in
let iv0 = get_iv al 0ul in
let iv1 = get_iv al 1ul in
let iv2 = get_iv al 2ul in
let iv3 = get_iv al 3ul in
let iv4 = get_iv al 4ul in
let iv5 = get_iv al 5ul in
let iv6 = get_iv al 6ul in
let iv7 = get_iv al 7ul in
create_row #al #ms r2 iv0 iv1 iv2 iv3;
create_row #al #ms r3 iv4 iv5 iv6 iv7;
let salt = create (salt_len al) (u8 0) in
let personal = create (personal_len al) (u8 0) in
let p = create_default_params al salt personal in
serialize_params al kk nn p tmp;
let tmp0 = tmp.(0ul) in
let tmp1 = tmp.(1ul) in
let tmp2 = tmp.(2ul) in
let tmp3 = tmp.(3ul) in
let tmp4 = tmp.(4ul) in
let tmp5 = tmp.(5ul) in
let tmp6 = tmp.(6ul) in
let tmp7 = tmp.(7ul) in
let iv0' = iv0 ^. tmp0 in
let iv1' = iv1 ^. tmp1 in
let iv2' = iv2 ^. tmp2 in
let iv3' = iv3 ^. tmp3 in
let iv4' = iv4 ^. tmp4 in
let iv5' = iv5 ^. tmp5 in
let iv6' = iv6 ^. tmp6 in
let iv7' = iv7 ^. tmp7 in
create_row #al #ms r0 iv0' iv1' iv2' iv3';
create_row #al #ms r1 iv4' iv5' iv6' iv7';
let h1 = ST.get () in
assert (disjoint hash tmp);
assert (modifies ((loc hash) `union` (loc tmp)) h0 h1);
Lib.Sequence.eq_intro (state_v h1 hash)
(Spec.blake2_init_hash al (Spec.blake2_default_params al) (v kk) (v nn));
pop_frame () | false |
FStar.Fin.fst | FStar.Fin.is_reflexive_intro | val is_reflexive_intro (#a:Type) (r: binary_relation a)
: Lemma (requires forall (x:a). r x x) (ensures is_reflexive r) | val is_reflexive_intro (#a:Type) (r: binary_relation a)
: Lemma (requires forall (x:a). r x x) (ensures is_reflexive r) | let is_reflexive_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a) | {
"file_name": "ulib/FStar.Fin.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 78,
"end_line": 66,
"start_col": 0,
"start_line": 66
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Fin
/// This module is supposed to contain various lemmas about
/// finiteness. For now, it mainly provides a basic pigeonhole
/// principle
///
/// TODO: We might generalize this to also support general utilities
/// for reasoning about cardinality, relation with injections and
/// surjections, etc.
///
/// UPD. November 8, 2022 -- added support for custom equivalence relation-aware
/// pigeon principle lemma.
///
/// For better readability of lemmas, Argument types are kept explicit,
/// effectively duplicating the interface file declarations.
module S = FStar.Seq
(** Find an index of an element in [s] starting from [i] that validates [p] *)
let rec find (#a: Type) (s: S.seq a) (p: (a -> bool)) (i: under (S.length s)) =
if p (S.index s i)
then Some i
else if i + 1 < S.length s
then find #a s p (i + 1)
else None
(** Given a sequence [s] all of whose elements are at most [n], if the
length of [s] is greater than [n], then there are two distinct
indexes in [s] that contain the same element *)
let rec pigeonhole (#n: pos) (s: S.seq (under n)) =
if n = 1 then (0, 1)
else let k0 = S.index s 0 in
match find s (fun k -> k = k0) 1 with
| Some i -> 0, i
| None -> let (i1,i2) =
pigeonhole (S.init #(under (n-1)) n
(fun i -> let k = S.index s (i+1) in
if k<k0 then k else k-1))
in (i1+1, i2+1)
[@@"opaque_to_smt"]
let is_reflexive #a r = forall (x:a). x `r` x
[@@"opaque_to_smt"]
let is_symmetric #a r = forall (x y:a). x `r` y == y `r` x
[@@"opaque_to_smt"]
let is_transitive #a r = forall (x y z:a). x `r` y /\ y `r` z ==> x `r` z | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Fin.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: FStar.Fin.binary_relation a
-> FStar.Pervasives.Lemma (requires forall (x: a). r x x) (ensures FStar.Fin.is_reflexive r) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Fin.binary_relation",
"FStar.Pervasives.reveal_opaque",
"FStar.Fin.is_reflexive",
"Prims.unit"
] | [] | true | false | true | false | false | let is_reflexive_intro #a r =
| reveal_opaque (`%is_reflexive) (is_reflexive #a) | false |
FStar.Fin.fst | FStar.Fin.is_symmetric_intro | val is_symmetric_intro (#a:Type) (r: binary_relation a)
: Lemma (requires forall (x:a). r x x) (ensures is_reflexive r) | val is_symmetric_intro (#a:Type) (r: binary_relation a)
: Lemma (requires forall (x:a). r x x) (ensures is_reflexive r) | let is_symmetric_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a) | {
"file_name": "ulib/FStar.Fin.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 78,
"end_line": 68,
"start_col": 0,
"start_line": 68
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Fin
/// This module is supposed to contain various lemmas about
/// finiteness. For now, it mainly provides a basic pigeonhole
/// principle
///
/// TODO: We might generalize this to also support general utilities
/// for reasoning about cardinality, relation with injections and
/// surjections, etc.
///
/// UPD. November 8, 2022 -- added support for custom equivalence relation-aware
/// pigeon principle lemma.
///
/// For better readability of lemmas, Argument types are kept explicit,
/// effectively duplicating the interface file declarations.
module S = FStar.Seq
(** Find an index of an element in [s] starting from [i] that validates [p] *)
let rec find (#a: Type) (s: S.seq a) (p: (a -> bool)) (i: under (S.length s)) =
if p (S.index s i)
then Some i
else if i + 1 < S.length s
then find #a s p (i + 1)
else None
(** Given a sequence [s] all of whose elements are at most [n], if the
length of [s] is greater than [n], then there are two distinct
indexes in [s] that contain the same element *)
let rec pigeonhole (#n: pos) (s: S.seq (under n)) =
if n = 1 then (0, 1)
else let k0 = S.index s 0 in
match find s (fun k -> k = k0) 1 with
| Some i -> 0, i
| None -> let (i1,i2) =
pigeonhole (S.init #(under (n-1)) n
(fun i -> let k = S.index s (i+1) in
if k<k0 then k else k-1))
in (i1+1, i2+1)
[@@"opaque_to_smt"]
let is_reflexive #a r = forall (x:a). x `r` x
[@@"opaque_to_smt"]
let is_symmetric #a r = forall (x y:a). x `r` y == y `r` x
[@@"opaque_to_smt"]
let is_transitive #a r = forall (x y z:a). x `r` y /\ y `r` z ==> x `r` z
let is_reflexive_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Fin.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: FStar.Fin.binary_relation a
-> FStar.Pervasives.Lemma (requires forall (x: a). r x x) (ensures FStar.Fin.is_reflexive r) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Fin.binary_relation",
"FStar.Pervasives.reveal_opaque",
"FStar.Fin.is_reflexive",
"Prims.unit"
] | [] | true | false | true | false | false | let is_symmetric_intro #a r =
| reveal_opaque (`%is_reflexive) (is_reflexive #a) | false |
FStar.Fin.fst | FStar.Fin.is_transitive_intro | val is_transitive_intro (#a:Type) (r: binary_relation a)
: Lemma (requires forall (x:a). r x x) (ensures is_reflexive r) | val is_transitive_intro (#a:Type) (r: binary_relation a)
: Lemma (requires forall (x:a). r x x) (ensures is_reflexive r) | let is_transitive_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a) | {
"file_name": "ulib/FStar.Fin.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 79,
"end_line": 70,
"start_col": 0,
"start_line": 70
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Fin
/// This module is supposed to contain various lemmas about
/// finiteness. For now, it mainly provides a basic pigeonhole
/// principle
///
/// TODO: We might generalize this to also support general utilities
/// for reasoning about cardinality, relation with injections and
/// surjections, etc.
///
/// UPD. November 8, 2022 -- added support for custom equivalence relation-aware
/// pigeon principle lemma.
///
/// For better readability of lemmas, Argument types are kept explicit,
/// effectively duplicating the interface file declarations.
module S = FStar.Seq
(** Find an index of an element in [s] starting from [i] that validates [p] *)
let rec find (#a: Type) (s: S.seq a) (p: (a -> bool)) (i: under (S.length s)) =
if p (S.index s i)
then Some i
else if i + 1 < S.length s
then find #a s p (i + 1)
else None
(** Given a sequence [s] all of whose elements are at most [n], if the
length of [s] is greater than [n], then there are two distinct
indexes in [s] that contain the same element *)
let rec pigeonhole (#n: pos) (s: S.seq (under n)) =
if n = 1 then (0, 1)
else let k0 = S.index s 0 in
match find s (fun k -> k = k0) 1 with
| Some i -> 0, i
| None -> let (i1,i2) =
pigeonhole (S.init #(under (n-1)) n
(fun i -> let k = S.index s (i+1) in
if k<k0 then k else k-1))
in (i1+1, i2+1)
[@@"opaque_to_smt"]
let is_reflexive #a r = forall (x:a). x `r` x
[@@"opaque_to_smt"]
let is_symmetric #a r = forall (x y:a). x `r` y == y `r` x
[@@"opaque_to_smt"]
let is_transitive #a r = forall (x y z:a). x `r` y /\ y `r` z ==> x `r` z
let is_reflexive_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a)
let is_symmetric_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Fin.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: FStar.Fin.binary_relation a
-> FStar.Pervasives.Lemma (requires forall (x: a). r x x) (ensures FStar.Fin.is_reflexive r) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Fin.binary_relation",
"FStar.Pervasives.reveal_opaque",
"FStar.Fin.is_reflexive",
"Prims.unit"
] | [] | true | false | true | false | false | let is_transitive_intro #a r =
| reveal_opaque (`%is_reflexive) (is_reflexive #a) | false |
FStar.Fin.fst | FStar.Fin.pigeonhole | val pigeonhole (#n: pos) (s: S.seq (under n))
: Pure (in_ s * in_ s)
(requires S.length s = n + 1)
(ensures (fun (i1, i2) -> i1 < i2 /\ S.index s i1 = S.index s i2))
(decreases n) | val pigeonhole (#n: pos) (s: S.seq (under n))
: Pure (in_ s * in_ s)
(requires S.length s = n + 1)
(ensures (fun (i1, i2) -> i1 < i2 /\ S.index s i1 = S.index s i2))
(decreases n) | let rec pigeonhole (#n: pos) (s: S.seq (under n)) =
if n = 1 then (0, 1)
else let k0 = S.index s 0 in
match find s (fun k -> k = k0) 1 with
| Some i -> 0, i
| None -> let (i1,i2) =
pigeonhole (S.init #(under (n-1)) n
(fun i -> let k = S.index s (i+1) in
if k<k0 then k else k-1))
in (i1+1, i2+1) | {
"file_name": "ulib/FStar.Fin.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 29,
"end_line": 55,
"start_col": 0,
"start_line": 46
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Fin
/// This module is supposed to contain various lemmas about
/// finiteness. For now, it mainly provides a basic pigeonhole
/// principle
///
/// TODO: We might generalize this to also support general utilities
/// for reasoning about cardinality, relation with injections and
/// surjections, etc.
///
/// UPD. November 8, 2022 -- added support for custom equivalence relation-aware
/// pigeon principle lemma.
///
/// For better readability of lemmas, Argument types are kept explicit,
/// effectively duplicating the interface file declarations.
module S = FStar.Seq
(** Find an index of an element in [s] starting from [i] that validates [p] *)
let rec find (#a: Type) (s: S.seq a) (p: (a -> bool)) (i: under (S.length s)) =
if p (S.index s i)
then Some i
else if i + 1 < S.length s
then find #a s p (i + 1)
else None
(** Given a sequence [s] all of whose elements are at most [n], if the
length of [s] is greater than [n], then there are two distinct | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Fin.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq (FStar.Fin.under n) -> Prims.Pure (FStar.Fin.in_ s * FStar.Fin.in_ s) | Prims.Pure | [
""
] | [] | [
"Prims.pos",
"FStar.Seq.Base.seq",
"FStar.Fin.under",
"Prims.op_Equality",
"Prims.int",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Fin.in_",
"Prims.bool",
"FStar.Fin.find",
"Prims.op_Subtraction",
"FStar.Seq.Base.init",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.index",
"Prims.op_Addition",
"FStar.Pervasives.Native.tuple2",
"FStar.Fin.pigeonhole"
] | [
"recursion"
] | false | false | false | false | false | let rec pigeonhole (#n: pos) (s: S.seq (under n)) =
| if n = 1
then (0, 1)
else
let k0 = S.index s 0 in
match find s (fun k -> k = k0) 1 with
| Some i -> 0, i
| None ->
let i1, i2 =
pigeonhole (S.init #(under (n - 1))
n
(fun i ->
let k = S.index s (i + 1) in
if k < k0 then k else k - 1))
in
(i1 + 1, i2 + 1) | false |
FStar.Fin.fst | FStar.Fin.symm_lemma | val symm_lemma (#a:Type) (eq:equivalence_relation a) (x y:a)
: Lemma (eq x y == eq y x) | val symm_lemma (#a:Type) (eq:equivalence_relation a) (x y:a)
: Lemma (eq x y == eq y x) | let symm_lemma #a _ _ _ = reveal_opaque (`%is_symmetric) (is_symmetric #a) | {
"file_name": "ulib/FStar.Fin.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 77,
"end_line": 74,
"start_col": 0,
"start_line": 74
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Fin
/// This module is supposed to contain various lemmas about
/// finiteness. For now, it mainly provides a basic pigeonhole
/// principle
///
/// TODO: We might generalize this to also support general utilities
/// for reasoning about cardinality, relation with injections and
/// surjections, etc.
///
/// UPD. November 8, 2022 -- added support for custom equivalence relation-aware
/// pigeon principle lemma.
///
/// For better readability of lemmas, Argument types are kept explicit,
/// effectively duplicating the interface file declarations.
module S = FStar.Seq
(** Find an index of an element in [s] starting from [i] that validates [p] *)
let rec find (#a: Type) (s: S.seq a) (p: (a -> bool)) (i: under (S.length s)) =
if p (S.index s i)
then Some i
else if i + 1 < S.length s
then find #a s p (i + 1)
else None
(** Given a sequence [s] all of whose elements are at most [n], if the
length of [s] is greater than [n], then there are two distinct
indexes in [s] that contain the same element *)
let rec pigeonhole (#n: pos) (s: S.seq (under n)) =
if n = 1 then (0, 1)
else let k0 = S.index s 0 in
match find s (fun k -> k = k0) 1 with
| Some i -> 0, i
| None -> let (i1,i2) =
pigeonhole (S.init #(under (n-1)) n
(fun i -> let k = S.index s (i+1) in
if k<k0 then k else k-1))
in (i1+1, i2+1)
[@@"opaque_to_smt"]
let is_reflexive #a r = forall (x:a). x `r` x
[@@"opaque_to_smt"]
let is_symmetric #a r = forall (x y:a). x `r` y == y `r` x
[@@"opaque_to_smt"]
let is_transitive #a r = forall (x y z:a). x `r` y /\ y `r` z ==> x `r` z
let is_reflexive_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a)
let is_symmetric_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a)
let is_transitive_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a)
let refl_lemma #a _ _ = reveal_opaque (`%is_reflexive) (is_reflexive #a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Fin.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | eq: FStar.Fin.equivalence_relation a -> x: a -> y: a
-> FStar.Pervasives.Lemma (ensures eq x y == eq y x) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Fin.equivalence_relation",
"FStar.Pervasives.reveal_opaque",
"FStar.Fin.binary_relation",
"FStar.Fin.is_symmetric",
"Prims.unit"
] | [] | true | false | true | false | false | let symm_lemma #a _ _ _ =
| reveal_opaque (`%is_symmetric) (is_symmetric #a) | false |
FStar.Fin.fst | FStar.Fin.refl_lemma | val refl_lemma (#a:Type) (eq: equivalence_relation a) (x:a)
: Lemma (eq x x) | val refl_lemma (#a:Type) (eq: equivalence_relation a) (x:a)
: Lemma (eq x x) | let refl_lemma #a _ _ = reveal_opaque (`%is_reflexive) (is_reflexive #a) | {
"file_name": "ulib/FStar.Fin.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 77,
"end_line": 72,
"start_col": 0,
"start_line": 72
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Fin
/// This module is supposed to contain various lemmas about
/// finiteness. For now, it mainly provides a basic pigeonhole
/// principle
///
/// TODO: We might generalize this to also support general utilities
/// for reasoning about cardinality, relation with injections and
/// surjections, etc.
///
/// UPD. November 8, 2022 -- added support for custom equivalence relation-aware
/// pigeon principle lemma.
///
/// For better readability of lemmas, Argument types are kept explicit,
/// effectively duplicating the interface file declarations.
module S = FStar.Seq
(** Find an index of an element in [s] starting from [i] that validates [p] *)
let rec find (#a: Type) (s: S.seq a) (p: (a -> bool)) (i: under (S.length s)) =
if p (S.index s i)
then Some i
else if i + 1 < S.length s
then find #a s p (i + 1)
else None
(** Given a sequence [s] all of whose elements are at most [n], if the
length of [s] is greater than [n], then there are two distinct
indexes in [s] that contain the same element *)
let rec pigeonhole (#n: pos) (s: S.seq (under n)) =
if n = 1 then (0, 1)
else let k0 = S.index s 0 in
match find s (fun k -> k = k0) 1 with
| Some i -> 0, i
| None -> let (i1,i2) =
pigeonhole (S.init #(under (n-1)) n
(fun i -> let k = S.index s (i+1) in
if k<k0 then k else k-1))
in (i1+1, i2+1)
[@@"opaque_to_smt"]
let is_reflexive #a r = forall (x:a). x `r` x
[@@"opaque_to_smt"]
let is_symmetric #a r = forall (x y:a). x `r` y == y `r` x
[@@"opaque_to_smt"]
let is_transitive #a r = forall (x y z:a). x `r` y /\ y `r` z ==> x `r` z
let is_reflexive_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a)
let is_symmetric_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a)
let is_transitive_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Fin.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | eq: FStar.Fin.equivalence_relation a -> x: a -> FStar.Pervasives.Lemma (ensures eq x x) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Fin.equivalence_relation",
"FStar.Pervasives.reveal_opaque",
"FStar.Fin.binary_relation",
"FStar.Fin.is_reflexive",
"Prims.unit"
] | [] | true | false | true | false | false | let refl_lemma #a _ _ =
| reveal_opaque (`%is_reflexive) (is_reflexive #a) | false |
FStar.Fin.fst | FStar.Fin.trans_lemma | val trans_lemma (#a:Type) (eq: equivalence_relation a) (x y z:a)
: Lemma (requires (eq x y \/ eq y x) /\ (eq y z \/ eq z y))
(ensures (x `eq` z) && (z `eq` x)) | val trans_lemma (#a:Type) (eq: equivalence_relation a) (x y z:a)
: Lemma (requires (eq x y \/ eq y x) /\ (eq y z \/ eq z y))
(ensures (x `eq` z) && (z `eq` x)) | let trans_lemma #a _ _ _ _ = reveal_opaque (`%is_transitive) (is_transitive #a);
reveal_opaque (`%is_symmetric) (is_symmetric #a) | {
"file_name": "ulib/FStar.Fin.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 77,
"end_line": 77,
"start_col": 0,
"start_line": 76
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Fin
/// This module is supposed to contain various lemmas about
/// finiteness. For now, it mainly provides a basic pigeonhole
/// principle
///
/// TODO: We might generalize this to also support general utilities
/// for reasoning about cardinality, relation with injections and
/// surjections, etc.
///
/// UPD. November 8, 2022 -- added support for custom equivalence relation-aware
/// pigeon principle lemma.
///
/// For better readability of lemmas, Argument types are kept explicit,
/// effectively duplicating the interface file declarations.
module S = FStar.Seq
(** Find an index of an element in [s] starting from [i] that validates [p] *)
let rec find (#a: Type) (s: S.seq a) (p: (a -> bool)) (i: under (S.length s)) =
if p (S.index s i)
then Some i
else if i + 1 < S.length s
then find #a s p (i + 1)
else None
(** Given a sequence [s] all of whose elements are at most [n], if the
length of [s] is greater than [n], then there are two distinct
indexes in [s] that contain the same element *)
let rec pigeonhole (#n: pos) (s: S.seq (under n)) =
if n = 1 then (0, 1)
else let k0 = S.index s 0 in
match find s (fun k -> k = k0) 1 with
| Some i -> 0, i
| None -> let (i1,i2) =
pigeonhole (S.init #(under (n-1)) n
(fun i -> let k = S.index s (i+1) in
if k<k0 then k else k-1))
in (i1+1, i2+1)
[@@"opaque_to_smt"]
let is_reflexive #a r = forall (x:a). x `r` x
[@@"opaque_to_smt"]
let is_symmetric #a r = forall (x y:a). x `r` y == y `r` x
[@@"opaque_to_smt"]
let is_transitive #a r = forall (x y z:a). x `r` y /\ y `r` z ==> x `r` z
let is_reflexive_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a)
let is_symmetric_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a)
let is_transitive_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a)
let refl_lemma #a _ _ = reveal_opaque (`%is_reflexive) (is_reflexive #a)
let symm_lemma #a _ _ _ = reveal_opaque (`%is_symmetric) (is_symmetric #a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Fin.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | eq: FStar.Fin.equivalence_relation a -> x: a -> y: a -> z: a
-> FStar.Pervasives.Lemma (requires (eq x y \/ eq y x) /\ (eq y z \/ eq z y))
(ensures eq x z && eq z x) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Fin.equivalence_relation",
"FStar.Pervasives.reveal_opaque",
"FStar.Fin.binary_relation",
"FStar.Fin.is_symmetric",
"Prims.unit",
"FStar.Fin.is_transitive"
] | [] | true | false | true | false | false | let trans_lemma #a _ _ _ _ =
| reveal_opaque (`%is_transitive) (is_transitive #a);
reveal_opaque (`%is_symmetric) (is_symmetric #a) | false |
Steel.ST.Array.Util.fst | Steel.ST.Array.Util.array_literal | val array_literal
(#a:Type0)
(n:US.t)
(f:(i:US.t{US.v i < US.v n} -> a))
: ST (A.array a)
emp
(fun arr ->
A.pts_to arr full_perm (Seq.init (US.v n) (fun i -> f (US.uint_to_t i))))
(requires US.v n > 0)
(ensures fun arr -> A.length arr == US.v n) | val array_literal
(#a:Type0)
(n:US.t)
(f:(i:US.t{US.v i < US.v n} -> a))
: ST (A.array a)
emp
(fun arr ->
A.pts_to arr full_perm (Seq.init (US.v n) (fun i -> f (US.uint_to_t i))))
(requires US.v n > 0)
(ensures fun arr -> A.length arr == US.v n) | let array_literal #a n f =
let arr = A.alloc (f 0sz) n in
intro_pure
(array_literal_inv_pure n f 1 (Seq.create (US.v n) (f 0sz)));
intro_exists
(Seq.create (US.v n) (f 0sz))
(array_literal_inv n arr f 1);
Loops.for_loop
1sz
n
(fun i -> exists_ (array_literal_inv n arr f i))
(array_literal_loop_body n arr f);
let s = elim_exists () in
A.pts_to_length arr s;
elim_pure (array_literal_inv_pure n f (US.v n) s);
assert (Seq.equal s (Seq.init (US.v n) (fun i -> f (US.uint_to_t i))));
rewrite (A.pts_to arr full_perm s) _;
return arr | {
"file_name": "lib/steel/Steel.ST.Array.Util.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 12,
"end_line": 100,
"start_col": 0,
"start_line": 80
} | (*
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 Steel.ST.Array.Util
module G = FStar.Ghost
module US = FStar.SizeT
module R = Steel.ST.Reference
module A = Steel.ST.Array
module Loops = Steel.ST.Loops
open Steel.FractionalPermission
open Steel.ST.Effect
open Steel.ST.Util
/// Implementation of array_literal using a for loop
let array_literal_inv_pure
(#a:Type0)
(n:US.t)
(f:(i:US.t{US.v i < US.v n} -> a))
(i:Loops.nat_at_most n)
(s:Seq.seq a)
: prop
= forall (j:nat).
(j < i /\ j < Seq.length s) ==> Seq.index s j == f (US.uint_to_t j)
[@@ __reduce__]
let array_literal_inv
(#a:Type0)
(n:US.t)
(arr:A.array a)
(f:(i:US.t{US.v i < US.v n} -> a))
(i:Loops.nat_at_most n)
: Seq.seq a -> vprop
= fun s ->
A.pts_to arr full_perm s
`star`
pure (array_literal_inv_pure n f i s)
inline_for_extraction
let array_literal_loop_body
(#a:Type0)
(n:US.t)
(arr:A.array a{A.length arr == US.v n})
(f:(i:US.t{US.v i < US.v n} -> a))
: i:Loops.u32_between 0sz n ->
STT unit
(exists_ (array_literal_inv n arr f (US.v i)))
(fun _ -> exists_ (array_literal_inv n arr f (US.v i + 1)))
= fun i ->
let s = elim_exists () in
();
A.pts_to_length arr s;
elim_pure (array_literal_inv_pure n f (US.v i) s);
A.write arr i (f i);
intro_pure
(array_literal_inv_pure n f (US.v i + 1) (Seq.upd s (US.v i) (f i)));
intro_exists
(Seq.upd s (US.v i) (f i))
(array_literal_inv n arr f (US.v i + 1)) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Reference.fsti.checked",
"Steel.ST.Loops.fsti.checked",
"Steel.ST.Effect.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.Array.Util.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.ST.Loops",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Steel.ST.Reference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: FStar.SizeT.t -> f: (i: FStar.SizeT.t{FStar.SizeT.v i < FStar.SizeT.v n} -> a)
-> Steel.ST.Effect.ST (Steel.ST.Array.array a) | Steel.ST.Effect.ST | [] | [] | [
"FStar.SizeT.t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.SizeT.v",
"Steel.ST.Util.return",
"Steel.ST.Array.array",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.ST.Array.pts_to",
"Steel.FractionalPermission.full_perm",
"FStar.Seq.Base.init",
"Prims.nat",
"FStar.SizeT.uint_to_t",
"Steel.Effect.Common.vprop",
"Prims.unit",
"Steel.ST.Util.rewrite",
"FStar.Ghost.reveal",
"FStar.Seq.Base.seq",
"Prims._assert",
"FStar.Seq.Base.equal",
"Steel.ST.Util.elim_pure",
"Steel.ST.Array.Util.array_literal_inv_pure",
"Steel.ST.Array.pts_to_length",
"FStar.Ghost.erased",
"Steel.ST.Util.elim_exists",
"Steel.Effect.Common.VStar",
"Steel.ST.Util.pure",
"Steel.ST.Loops.for_loop",
"FStar.SizeT.__uint_to_t",
"Steel.ST.Loops.nat_at_most",
"Steel.ST.Util.exists_",
"Steel.ST.Array.Util.array_literal_inv",
"Steel.ST.Array.Util.array_literal_loop_body",
"Steel.ST.Util.intro_exists",
"FStar.Seq.Base.create",
"Steel.ST.Util.intro_pure",
"Steel.ST.Array.alloc"
] | [] | false | true | false | false | false | let array_literal #a n f =
| let arr = A.alloc (f 0sz) n in
intro_pure (array_literal_inv_pure n f 1 (Seq.create (US.v n) (f 0sz)));
intro_exists (Seq.create (US.v n) (f 0sz)) (array_literal_inv n arr f 1);
Loops.for_loop 1sz
n
(fun i -> exists_ (array_literal_inv n arr f i))
(array_literal_loop_body n arr f);
let s = elim_exists () in
A.pts_to_length arr s;
elim_pure (array_literal_inv_pure n f (US.v n) s);
assert (Seq.equal s (Seq.init (US.v n) (fun i -> f (US.uint_to_t i))));
rewrite (A.pts_to arr full_perm s) _;
return arr | false |
FStar.Fin.fst | FStar.Fin.contains_eq_means_nonempty | val contains_eq_means_nonempty (#a:Type) (eq:equivalence_relation a) (s: S.seq a) (x:a)
: Lemma (requires contains_eq eq s x)
(ensures S.length s > 0)
[SMTPat(contains_eq eq s x)] | val contains_eq_means_nonempty (#a:Type) (eq:equivalence_relation a) (s: S.seq a) (x:a)
: Lemma (requires contains_eq eq s x)
(ensures S.length s > 0)
[SMTPat(contains_eq eq s x)] | let contains_eq_means_nonempty #a (eq:equivalence_relation a) (s: S.seq a) (x:a)
: Lemma (requires contains_eq eq s x)
(ensures S.length s > 0)
[SMTPat(contains_eq eq s x)]
= reveal_opaque (`%contains_eq) (contains_eq eq) | {
"file_name": "ulib/FStar.Fin.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 50,
"end_line": 84,
"start_col": 0,
"start_line": 80
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Fin
/// This module is supposed to contain various lemmas about
/// finiteness. For now, it mainly provides a basic pigeonhole
/// principle
///
/// TODO: We might generalize this to also support general utilities
/// for reasoning about cardinality, relation with injections and
/// surjections, etc.
///
/// UPD. November 8, 2022 -- added support for custom equivalence relation-aware
/// pigeon principle lemma.
///
/// For better readability of lemmas, Argument types are kept explicit,
/// effectively duplicating the interface file declarations.
module S = FStar.Seq
(** Find an index of an element in [s] starting from [i] that validates [p] *)
let rec find (#a: Type) (s: S.seq a) (p: (a -> bool)) (i: under (S.length s)) =
if p (S.index s i)
then Some i
else if i + 1 < S.length s
then find #a s p (i + 1)
else None
(** Given a sequence [s] all of whose elements are at most [n], if the
length of [s] is greater than [n], then there are two distinct
indexes in [s] that contain the same element *)
let rec pigeonhole (#n: pos) (s: S.seq (under n)) =
if n = 1 then (0, 1)
else let k0 = S.index s 0 in
match find s (fun k -> k = k0) 1 with
| Some i -> 0, i
| None -> let (i1,i2) =
pigeonhole (S.init #(under (n-1)) n
(fun i -> let k = S.index s (i+1) in
if k<k0 then k else k-1))
in (i1+1, i2+1)
[@@"opaque_to_smt"]
let is_reflexive #a r = forall (x:a). x `r` x
[@@"opaque_to_smt"]
let is_symmetric #a r = forall (x y:a). x `r` y == y `r` x
[@@"opaque_to_smt"]
let is_transitive #a r = forall (x y z:a). x `r` y /\ y `r` z ==> x `r` z
let is_reflexive_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a)
let is_symmetric_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a)
let is_transitive_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a)
let refl_lemma #a _ _ = reveal_opaque (`%is_reflexive) (is_reflexive #a)
let symm_lemma #a _ _ _ = reveal_opaque (`%is_symmetric) (is_symmetric #a)
let trans_lemma #a _ _ _ _ = reveal_opaque (`%is_transitive) (is_transitive #a);
reveal_opaque (`%is_symmetric) (is_symmetric #a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Fin.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | eq: FStar.Fin.equivalence_relation a -> s: FStar.Seq.Base.seq a -> x: a
-> FStar.Pervasives.Lemma (requires FStar.Fin.contains_eq eq s x)
(ensures FStar.Seq.Base.length s > 0)
[SMTPat (FStar.Fin.contains_eq eq s x)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Fin.equivalence_relation",
"FStar.Seq.Base.seq",
"FStar.Pervasives.reveal_opaque",
"Prims.logical",
"FStar.Fin.contains_eq",
"Prims.unit",
"Prims.squash",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.Seq.Base.length",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let contains_eq_means_nonempty #a (eq: equivalence_relation a) (s: S.seq a) (x: a)
: Lemma (requires contains_eq eq s x) (ensures S.length s > 0) [SMTPat (contains_eq eq s x)] =
| reveal_opaque (`%contains_eq) (contains_eq eq) | false |
FStar.Fin.fst | FStar.Fin.find_eq | val find_eq (#a:Type) (eq:equivalence_relation a) (s: S.seq a) (x:a { contains_eq eq s x })
: (i: nat { (i < S.length s)
/\ (x `eq` S.index s i)
/\ (forall (j: under i). not (x `eq` S.index s j)) }) | val find_eq (#a:Type) (eq:equivalence_relation a) (s: S.seq a) (x:a { contains_eq eq s x })
: (i: nat { (i < S.length s)
/\ (x `eq` S.index s i)
/\ (forall (j: under i). not (x `eq` S.index s j)) }) | let rec find_eq #a (eq:equivalence_relation a) (s: S.seq a)
(x:a { contains_eq eq s x })
: Tot (i: nat { (i < S.length s) /\
(x `eq` S.index s i) /\
(forall (j: under i). not (x `eq` S.index s j)) })
(decreases S.length s)
= reveal_opaque (`%contains_eq) (contains_eq eq);
if S.length s = 1 then 0
else if x `eq` S.index s 0 then 0
else begin
tail_contains_eq eq s x;
let ieq = find_eq eq (S.tail s) x in
let aux (i: under (1 + ieq))
: Lemma (not (x `eq` S.index s i))
= if i > 0
then assert (S.index (S.tail s) (i-1) == S.index s i)
in Classical.forall_intro aux;
1 + ieq
end | {
"file_name": "ulib/FStar.Fin.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 12,
"end_line": 116,
"start_col": 0,
"start_line": 98
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Fin
/// This module is supposed to contain various lemmas about
/// finiteness. For now, it mainly provides a basic pigeonhole
/// principle
///
/// TODO: We might generalize this to also support general utilities
/// for reasoning about cardinality, relation with injections and
/// surjections, etc.
///
/// UPD. November 8, 2022 -- added support for custom equivalence relation-aware
/// pigeon principle lemma.
///
/// For better readability of lemmas, Argument types are kept explicit,
/// effectively duplicating the interface file declarations.
module S = FStar.Seq
(** Find an index of an element in [s] starting from [i] that validates [p] *)
let rec find (#a: Type) (s: S.seq a) (p: (a -> bool)) (i: under (S.length s)) =
if p (S.index s i)
then Some i
else if i + 1 < S.length s
then find #a s p (i + 1)
else None
(** Given a sequence [s] all of whose elements are at most [n], if the
length of [s] is greater than [n], then there are two distinct
indexes in [s] that contain the same element *)
let rec pigeonhole (#n: pos) (s: S.seq (under n)) =
if n = 1 then (0, 1)
else let k0 = S.index s 0 in
match find s (fun k -> k = k0) 1 with
| Some i -> 0, i
| None -> let (i1,i2) =
pigeonhole (S.init #(under (n-1)) n
(fun i -> let k = S.index s (i+1) in
if k<k0 then k else k-1))
in (i1+1, i2+1)
[@@"opaque_to_smt"]
let is_reflexive #a r = forall (x:a). x `r` x
[@@"opaque_to_smt"]
let is_symmetric #a r = forall (x y:a). x `r` y == y `r` x
[@@"opaque_to_smt"]
let is_transitive #a r = forall (x y z:a). x `r` y /\ y `r` z ==> x `r` z
let is_reflexive_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a)
let is_symmetric_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a)
let is_transitive_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a)
let refl_lemma #a _ _ = reveal_opaque (`%is_reflexive) (is_reflexive #a)
let symm_lemma #a _ _ _ = reveal_opaque (`%is_symmetric) (is_symmetric #a)
let trans_lemma #a _ _ _ _ = reveal_opaque (`%is_transitive) (is_transitive #a);
reveal_opaque (`%is_symmetric) (is_symmetric #a)
let contains_eq_means_nonempty #a (eq:equivalence_relation a) (s: S.seq a) (x:a)
: Lemma (requires contains_eq eq s x)
(ensures S.length s > 0)
[SMTPat(contains_eq eq s x)]
= reveal_opaque (`%contains_eq) (contains_eq eq)
let tail_contains_eq #a (eq: equivalence_relation a) (s:S.seq a)
(x:a { contains_eq eq s x /\ ~(eq x (S.head s)) })
: Lemma (contains_eq eq (S.tail s) x)
= let t = S.tail s in
reveal_opaque (`%contains_eq) (contains_eq eq);
eliminate exists (i: under (S.length s)). eq x (S.index s i)
returns exists (k: under (S.length t)). eq x (S.index t k)
with _. assert (S.index s i == S.index t (i-1))
(** retrieves the index of an element given prior knowledge of its presense
unlike find function above, that returns option, this one guarantees | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Fin.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
eq: FStar.Fin.equivalence_relation a ->
s: FStar.Seq.Base.seq a ->
x: a{FStar.Fin.contains_eq eq s x}
-> Prims.Tot
(i:
Prims.nat
{ i < FStar.Seq.Base.length s /\ eq x (FStar.Seq.Base.index s i) /\
(forall (j: FStar.Fin.under i). Prims.op_Negation (eq x (FStar.Seq.Base.index s j))) }) | Prims.Tot | [
"",
"total"
] | [] | [
"FStar.Fin.equivalence_relation",
"FStar.Seq.Base.seq",
"FStar.Fin.contains_eq",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"Prims.bool",
"FStar.Seq.Base.index",
"Prims.op_Addition",
"Prims.unit",
"FStar.Classical.forall_intro",
"FStar.Fin.under",
"Prims.b2t",
"Prims.op_Negation",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Prims.op_GreaterThan",
"Prims._assert",
"Prims.eq2",
"FStar.Seq.Properties.tail",
"Prims.op_Subtraction",
"Prims.nat",
"Prims.l_and",
"Prims.op_LessThan",
"Prims.l_Forall",
"FStar.Fin.find_eq",
"FStar.Fin.tail_contains_eq",
"FStar.Pervasives.reveal_opaque",
"Prims.logical"
] | [
"recursion"
] | false | false | false | false | false | let rec find_eq #a (eq: equivalence_relation a) (s: S.seq a) (x: a{contains_eq eq s x})
: Tot
(i:
nat
{ (i < S.length s) /\ (x `eq` (S.index s i)) /\
(forall (j: under i). not (x `eq` (S.index s j))) }) (decreases S.length s) =
| reveal_opaque (`%contains_eq) (contains_eq eq);
if S.length s = 1
then 0
else
if x `eq` (S.index s 0)
then 0
else
(tail_contains_eq eq s x;
let ieq = find_eq eq (S.tail s) x in
let aux (i: under (1 + ieq)) : Lemma (not (x `eq` (S.index s i))) =
if i > 0 then assert (S.index (S.tail s) (i - 1) == S.index s i)
in
Classical.forall_intro aux;
1 + ieq) | false |
FStar.Fin.fst | FStar.Fin.tail_contains_eq | val tail_contains_eq
(#a: _)
(eq: equivalence_relation a)
(s: S.seq a)
(x: a{contains_eq eq s x /\ ~(eq x (S.head s))})
: Lemma (contains_eq eq (S.tail s) x) | val tail_contains_eq
(#a: _)
(eq: equivalence_relation a)
(s: S.seq a)
(x: a{contains_eq eq s x /\ ~(eq x (S.head s))})
: Lemma (contains_eq eq (S.tail s) x) | let tail_contains_eq #a (eq: equivalence_relation a) (s:S.seq a)
(x:a { contains_eq eq s x /\ ~(eq x (S.head s)) })
: Lemma (contains_eq eq (S.tail s) x)
= let t = S.tail s in
reveal_opaque (`%contains_eq) (contains_eq eq);
eliminate exists (i: under (S.length s)). eq x (S.index s i)
returns exists (k: under (S.length t)). eq x (S.index t k)
with _. assert (S.index s i == S.index t (i-1)) | {
"file_name": "ulib/FStar.Fin.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 51,
"end_line": 93,
"start_col": 0,
"start_line": 86
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Fin
/// This module is supposed to contain various lemmas about
/// finiteness. For now, it mainly provides a basic pigeonhole
/// principle
///
/// TODO: We might generalize this to also support general utilities
/// for reasoning about cardinality, relation with injections and
/// surjections, etc.
///
/// UPD. November 8, 2022 -- added support for custom equivalence relation-aware
/// pigeon principle lemma.
///
/// For better readability of lemmas, Argument types are kept explicit,
/// effectively duplicating the interface file declarations.
module S = FStar.Seq
(** Find an index of an element in [s] starting from [i] that validates [p] *)
let rec find (#a: Type) (s: S.seq a) (p: (a -> bool)) (i: under (S.length s)) =
if p (S.index s i)
then Some i
else if i + 1 < S.length s
then find #a s p (i + 1)
else None
(** Given a sequence [s] all of whose elements are at most [n], if the
length of [s] is greater than [n], then there are two distinct
indexes in [s] that contain the same element *)
let rec pigeonhole (#n: pos) (s: S.seq (under n)) =
if n = 1 then (0, 1)
else let k0 = S.index s 0 in
match find s (fun k -> k = k0) 1 with
| Some i -> 0, i
| None -> let (i1,i2) =
pigeonhole (S.init #(under (n-1)) n
(fun i -> let k = S.index s (i+1) in
if k<k0 then k else k-1))
in (i1+1, i2+1)
[@@"opaque_to_smt"]
let is_reflexive #a r = forall (x:a). x `r` x
[@@"opaque_to_smt"]
let is_symmetric #a r = forall (x y:a). x `r` y == y `r` x
[@@"opaque_to_smt"]
let is_transitive #a r = forall (x y z:a). x `r` y /\ y `r` z ==> x `r` z
let is_reflexive_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a)
let is_symmetric_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a)
let is_transitive_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a)
let refl_lemma #a _ _ = reveal_opaque (`%is_reflexive) (is_reflexive #a)
let symm_lemma #a _ _ _ = reveal_opaque (`%is_symmetric) (is_symmetric #a)
let trans_lemma #a _ _ _ _ = reveal_opaque (`%is_transitive) (is_transitive #a);
reveal_opaque (`%is_symmetric) (is_symmetric #a)
let contains_eq_means_nonempty #a (eq:equivalence_relation a) (s: S.seq a) (x:a)
: Lemma (requires contains_eq eq s x)
(ensures S.length s > 0)
[SMTPat(contains_eq eq s x)]
= reveal_opaque (`%contains_eq) (contains_eq eq) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Fin.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
eq: FStar.Fin.equivalence_relation a ->
s: FStar.Seq.Base.seq a ->
x: a{FStar.Fin.contains_eq eq s x /\ ~(eq x (FStar.Seq.Properties.head s))}
-> FStar.Pervasives.Lemma (ensures FStar.Fin.contains_eq eq (FStar.Seq.Properties.tail s) x) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Fin.equivalence_relation",
"FStar.Seq.Base.seq",
"Prims.l_and",
"FStar.Fin.contains_eq",
"Prims.l_not",
"Prims.b2t",
"FStar.Seq.Properties.head",
"FStar.Classical.Sugar.exists_elim",
"FStar.Fin.under",
"FStar.Seq.Base.length",
"FStar.Seq.Base.index",
"Prims.l_Exists",
"Prims.squash",
"Prims._assert",
"Prims.eq2",
"Prims.op_Subtraction",
"Prims.unit",
"FStar.Pervasives.reveal_opaque",
"Prims.logical",
"FStar.Seq.Properties.tail",
"Prims.l_True",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let tail_contains_eq
#a
(eq: equivalence_relation a)
(s: S.seq a)
(x: a{contains_eq eq s x /\ ~(eq x (S.head s))})
: Lemma (contains_eq eq (S.tail s) x) =
| let t = S.tail s in
reveal_opaque (`%contains_eq) (contains_eq eq);
eliminate exists (i: under (S.length s)).
eq x (S.index s i)
returns exists (k: under (S.length t)). eq x (S.index t k)
with _.
assert (S.index s i == S.index t (i - 1)) | false |
Clear.fst | Clear.l1 | val l1 : x: Prims.bool -> y: Prims.int -> z: Prims.unit -> Prims.unit | let l1 (x : bool) (y : int) (z : unit) =
assert (phi ==> (psi ==> xi)) by tau1 () | {
"file_name": "examples/native_tactics/Clear.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 44,
"end_line": 35,
"start_col": 0,
"start_line": 34
} | (*
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 Clear
open FStar.Tactics.V2
assume val phi : Type
assume val psi : Type
assume val xi : Type
assume val p : squash xi
[@@plugin]
let tau1 = fun () ->
let _ = implies_intro () in
clear_top ();
let _ = implies_intro () in
clear_top ();
exact (`p) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Clear.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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.bool -> y: Prims.int -> z: Prims.unit -> Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Prims.int",
"Prims.unit",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.l_imp",
"Clear.phi",
"Clear.psi",
"Clear.xi",
"Clear.tau1"
] | [] | false | false | false | true | false | let l1 (x: bool) (y: int) (z: unit) =
| FStar.Tactics.Effect.assert_by_tactic (phi ==> (psi ==> xi))
(fun _ ->
();
tau1 ()) | false |
|
Clear.fst | Clear.tau1 | val tau1 : _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | let tau1 = fun () ->
let _ = implies_intro () in
clear_top ();
let _ = implies_intro () in
clear_top ();
exact (`p) | {
"file_name": "examples/native_tactics/Clear.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 26,
"end_line": 32,
"start_col": 0,
"start_line": 27
} | (*
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 Clear
open FStar.Tactics.V2
assume val phi : Type
assume val psi : Type
assume val xi : Type
assume val p : squash xi | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Clear.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.exact",
"FStar.Stubs.Tactics.V2.Builtins.clear_top",
"FStar.Tactics.NamedView.binding",
"FStar.Tactics.V2.Logic.implies_intro"
] | [] | false | true | false | false | false | let tau1 =
| fun () ->
let _ = implies_intro () in
clear_top ();
let _ = implies_intro () in
clear_top ();
exact (`p) | false |
|
Clear.fst | Clear.tau2 | val tau2 : _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | let tau2 = fun () -> let e = cur_env () in
let n = List.length (vars_of_env e) in
let u = `int in
clear_all_of_type u;
let e = cur_env () in
// We're removing two binders
guard (List.length (vars_of_env e) = n - 2) | {
"file_name": "examples/native_tactics/Clear.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 66,
"end_line": 57,
"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 Clear
open FStar.Tactics.V2
assume val phi : Type
assume val psi : Type
assume val xi : Type
assume val p : squash xi
[@@plugin]
let tau1 = fun () ->
let _ = implies_intro () in
clear_top ();
let _ = implies_intro () in
clear_top ();
exact (`p)
let l1 (x : bool) (y : int) (z : unit) =
assert (phi ==> (psi ==> xi)) by tau1 ()
let clear_all_of_type (t : typ) : Tac unit =
let e = cur_env () in
let bs = vars_of_env e in
let _ = map (fun b -> if term_eq (type_of_binding b) t
then clear b
else ())
// We need to traverse the list backwards, to clear rightmost
// binders first. Otherwise, if we go left-first, we will revert/intro
// over a binder we want to clear and cause it to be refreshed.
(List.rev bs) in
() | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Clear.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.guard",
"Prims.op_Equality",
"Prims.int",
"FStar.List.Tot.Base.length",
"FStar.Stubs.Reflection.V2.Data.binding",
"FStar.Stubs.Reflection.V2.Builtins.vars_of_env",
"Prims.op_Subtraction",
"FStar.Stubs.Reflection.Types.env",
"FStar.Tactics.V2.Derived.cur_env",
"Clear.clear_all_of_type",
"FStar.Stubs.Reflection.Types.term",
"Prims.nat"
] | [] | false | true | false | false | false | let tau2 =
| fun () ->
let e = cur_env () in
let n = List.length (vars_of_env e) in
let u = `int in
clear_all_of_type u;
let e = cur_env () in
guard (List.length (vars_of_env e) = n - 2) | false |
|
Clear.fst | Clear.clear_all_of_type | val clear_all_of_type (t: typ) : Tac unit | val clear_all_of_type (t: typ) : Tac unit | let clear_all_of_type (t : typ) : Tac unit =
let e = cur_env () in
let bs = vars_of_env e in
let _ = map (fun b -> if term_eq (type_of_binding b) t
then clear b
else ())
// We need to traverse the list backwards, to clear rightmost
// binders first. Otherwise, if we go left-first, we will revert/intro
// over a binder we want to clear and cause it to be refreshed.
(List.rev bs) in
() | {
"file_name": "examples/native_tactics/Clear.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 6,
"end_line": 48,
"start_col": 0,
"start_line": 38
} | (*
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 Clear
open FStar.Tactics.V2
assume val phi : Type
assume val psi : Type
assume val xi : Type
assume val p : squash xi
[@@plugin]
let tau1 = fun () ->
let _ = implies_intro () in
clear_top ();
let _ = implies_intro () in
clear_top ();
exact (`p)
let l1 (x : bool) (y : int) (z : unit) =
assert (phi ==> (psi ==> xi)) by tau1 () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Clear.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: FStar.Stubs.Reflection.Types.typ -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Stubs.Reflection.Types.typ",
"Prims.unit",
"Prims.list",
"FStar.Tactics.Util.map",
"FStar.Stubs.Reflection.V2.Data.binding",
"FStar.Stubs.Reflection.V2.Builtins.term_eq",
"FStar.Tactics.V2.Derived.type_of_binding",
"FStar.Stubs.Tactics.V2.Builtins.clear",
"Prims.bool",
"FStar.List.Tot.Base.rev",
"FStar.Stubs.Reflection.V2.Builtins.vars_of_env",
"FStar.Stubs.Reflection.Types.env",
"FStar.Tactics.V2.Derived.cur_env"
] | [] | false | true | false | false | false | let clear_all_of_type (t: typ) : Tac unit =
| let e = cur_env () in
let bs = vars_of_env e in
let _ = map (fun b -> if term_eq (type_of_binding b) t then clear b) (List.rev bs) in
() | false |
FStar.Fin.fst | FStar.Fin.pigeonhole_eq | val pigeonhole_eq (#a:Type) (eq: equivalence_relation a)
(holes: S.seq a{S.length holes > 0})
(pigeons: S.seq (items_of eq holes))
: Pure (under (S.length pigeons) * under (S.length pigeons))
(requires S.length pigeons > S.length holes)
(ensures (fun (i1, i2) -> i1 < i2 /\ (S.index pigeons i1 `eq` S.index pigeons i2)))
(decreases S.length holes) | val pigeonhole_eq (#a:Type) (eq: equivalence_relation a)
(holes: S.seq a{S.length holes > 0})
(pigeons: S.seq (items_of eq holes))
: Pure (under (S.length pigeons) * under (S.length pigeons))
(requires S.length pigeons > S.length holes)
(ensures (fun (i1, i2) -> i1 < i2 /\ (S.index pigeons i1 `eq` S.index pigeons i2)))
(decreases S.length holes) | let rec pigeonhole_eq (#a:Type) (eq: equivalence_relation a)
(holes: S.seq a{S.length holes > 0})
(pigeons: S.seq (items_of eq holes)) =
if S.length holes = 1
then begin
reveal_opaque (`%contains_eq) (contains_eq eq);
trans_lemma eq (S.index pigeons 0) (S.index holes 0) (S.index pigeons 1);
(0,1)
end
else let first_pigeon = S.index pigeons 0 in
match find pigeons (fun k -> eq k first_pigeon) 1 with
| Some i -> (symm_lemma eq (S.index pigeons 0) (S.index pigeons i); (0,i))
| None ->
let index_of_first_pigeon = find_eq eq holes first_pigeon in //we carefully carve first_pigeon from (holes)
let holes_except_first_pigeon = S.append (S.slice holes 0 (index_of_first_pigeon))
(S.slice holes (index_of_first_pigeon+1) (S.length holes)) in
let all_but_first_pigeon_remain_in_reduced (x: items_of eq holes { not (eq x first_pigeon) })
: Lemma (contains_eq eq holes_except_first_pigeon x)
= let index_of_x_in_holes = find_eq eq holes x in
reveal_opaque (`%contains_eq) (contains_eq eq);
if index_of_x_in_holes < index_of_first_pigeon
then assert (S.index holes index_of_x_in_holes == S.index holes_except_first_pigeon index_of_x_in_holes)
else begin
// this serves to prove index_of_x_in_holes > index_of_first_pigeon (no equality!)
Classical.move_requires (trans_lemma eq x (S.index holes index_of_x_in_holes)) first_pigeon;
// append/slice smtpat hint
assert (S.index holes index_of_x_in_holes == S.index holes_except_first_pigeon (index_of_x_in_holes-1))
end
in Classical.forall_intro all_but_first_pigeon_remain_in_reduced;
let i1, i2 = pigeonhole_eq (eq) (holes_except_first_pigeon)
(S.init #(items_of eq holes_except_first_pigeon)
(S.length pigeons - 1)
(fun i -> S.index pigeons (i+1)))
in (i1+1, i2+1) | {
"file_name": "ulib/FStar.Fin.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 21,
"end_line": 161,
"start_col": 0,
"start_line": 128
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Fin
/// This module is supposed to contain various lemmas about
/// finiteness. For now, it mainly provides a basic pigeonhole
/// principle
///
/// TODO: We might generalize this to also support general utilities
/// for reasoning about cardinality, relation with injections and
/// surjections, etc.
///
/// UPD. November 8, 2022 -- added support for custom equivalence relation-aware
/// pigeon principle lemma.
///
/// For better readability of lemmas, Argument types are kept explicit,
/// effectively duplicating the interface file declarations.
module S = FStar.Seq
(** Find an index of an element in [s] starting from [i] that validates [p] *)
let rec find (#a: Type) (s: S.seq a) (p: (a -> bool)) (i: under (S.length s)) =
if p (S.index s i)
then Some i
else if i + 1 < S.length s
then find #a s p (i + 1)
else None
(** Given a sequence [s] all of whose elements are at most [n], if the
length of [s] is greater than [n], then there are two distinct
indexes in [s] that contain the same element *)
let rec pigeonhole (#n: pos) (s: S.seq (under n)) =
if n = 1 then (0, 1)
else let k0 = S.index s 0 in
match find s (fun k -> k = k0) 1 with
| Some i -> 0, i
| None -> let (i1,i2) =
pigeonhole (S.init #(under (n-1)) n
(fun i -> let k = S.index s (i+1) in
if k<k0 then k else k-1))
in (i1+1, i2+1)
[@@"opaque_to_smt"]
let is_reflexive #a r = forall (x:a). x `r` x
[@@"opaque_to_smt"]
let is_symmetric #a r = forall (x y:a). x `r` y == y `r` x
[@@"opaque_to_smt"]
let is_transitive #a r = forall (x y z:a). x `r` y /\ y `r` z ==> x `r` z
let is_reflexive_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a)
let is_symmetric_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a)
let is_transitive_intro #a r = reveal_opaque (`%is_reflexive) (is_reflexive #a)
let refl_lemma #a _ _ = reveal_opaque (`%is_reflexive) (is_reflexive #a)
let symm_lemma #a _ _ _ = reveal_opaque (`%is_symmetric) (is_symmetric #a)
let trans_lemma #a _ _ _ _ = reveal_opaque (`%is_transitive) (is_transitive #a);
reveal_opaque (`%is_symmetric) (is_symmetric #a)
let contains_eq_means_nonempty #a (eq:equivalence_relation a) (s: S.seq a) (x:a)
: Lemma (requires contains_eq eq s x)
(ensures S.length s > 0)
[SMTPat(contains_eq eq s x)]
= reveal_opaque (`%contains_eq) (contains_eq eq)
let tail_contains_eq #a (eq: equivalence_relation a) (s:S.seq a)
(x:a { contains_eq eq s x /\ ~(eq x (S.head s)) })
: Lemma (contains_eq eq (S.tail s) x)
= let t = S.tail s in
reveal_opaque (`%contains_eq) (contains_eq eq);
eliminate exists (i: under (S.length s)). eq x (S.index s i)
returns exists (k: under (S.length t)). eq x (S.index t k)
with _. assert (S.index s i == S.index t (i-1))
(** retrieves the index of an element given prior knowledge of its presense
unlike find function above, that returns option, this one guarantees
success, thus returning bare index instead. *)
let rec find_eq #a (eq:equivalence_relation a) (s: S.seq a)
(x:a { contains_eq eq s x })
: Tot (i: nat { (i < S.length s) /\
(x `eq` S.index s i) /\
(forall (j: under i). not (x `eq` S.index s j)) })
(decreases S.length s)
= reveal_opaque (`%contains_eq) (contains_eq eq);
if S.length s = 1 then 0
else if x `eq` S.index s 0 then 0
else begin
tail_contains_eq eq s x;
let ieq = find_eq eq (S.tail s) x in
let aux (i: under (1 + ieq))
: Lemma (not (x `eq` S.index s i))
= if i > 0
then assert (S.index (S.tail s) (i-1) == S.index s i)
in Classical.forall_intro aux;
1 + ieq
end
(** pigeonhole principle for setoids:
If we have a nonempty sequence (all), and a sequence (s),
and we know in advance that each item of (s) equals some
item in (all), equals meaning (eq), not (==),
then we automatically know that there are at least
2 equivalent elements in (s).
This procedure returns the first such pair. *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.Fin.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
eq: FStar.Fin.equivalence_relation a ->
holes: FStar.Seq.Base.seq a {FStar.Seq.Base.length holes > 0} ->
pigeons: FStar.Seq.Base.seq (FStar.Fin.items_of eq holes)
-> Prims.Pure
(FStar.Fin.under (FStar.Seq.Base.length pigeons) *
FStar.Fin.under (FStar.Seq.Base.length pigeons)) | Prims.Pure | [
""
] | [] | [
"FStar.Fin.equivalence_relation",
"FStar.Seq.Base.seq",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.Seq.Base.length",
"FStar.Fin.items_of",
"Prims.op_Equality",
"Prims.int",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Fin.under",
"Prims.unit",
"FStar.Fin.trans_lemma",
"FStar.Seq.Base.index",
"FStar.Pervasives.reveal_opaque",
"Prims.logical",
"FStar.Fin.contains_eq",
"Prims.bool",
"FStar.Fin.find",
"FStar.Fin.in_",
"FStar.Fin.symm_lemma",
"FStar.Seq.Base.init",
"Prims.op_Subtraction",
"Prims.nat",
"Prims.op_LessThan",
"Prims.op_Addition",
"FStar.Pervasives.Native.tuple2",
"FStar.Fin.pigeonhole_eq",
"FStar.Classical.forall_intro",
"Prims.op_Negation",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Prims._assert",
"Prims.eq2",
"FStar.Classical.move_requires",
"Prims.l_and",
"Prims.l_or",
"Prims.op_AmpAmp",
"Prims.l_Forall",
"FStar.Fin.find_eq",
"FStar.Seq.Base.append",
"FStar.Seq.Base.slice"
] | [
"recursion"
] | false | false | false | false | false | let rec pigeonhole_eq
(#a: Type)
(eq: equivalence_relation a)
(holes: S.seq a {S.length holes > 0})
(pigeons: S.seq (items_of eq holes))
=
| if S.length holes = 1
then
(reveal_opaque (`%contains_eq) (contains_eq eq);
trans_lemma eq (S.index pigeons 0) (S.index holes 0) (S.index pigeons 1);
(0, 1))
else
let first_pigeon = S.index pigeons 0 in
match find pigeons (fun k -> eq k first_pigeon) 1 with
| Some i ->
(symm_lemma eq (S.index pigeons 0) (S.index pigeons i);
(0, i))
| None ->
let index_of_first_pigeon = find_eq eq holes first_pigeon in
let holes_except_first_pigeon =
S.append (S.slice holes 0 (index_of_first_pigeon))
(S.slice holes (index_of_first_pigeon + 1) (S.length holes))
in
let all_but_first_pigeon_remain_in_reduced (x: items_of eq holes {not (eq x first_pigeon)})
: Lemma (contains_eq eq holes_except_first_pigeon x) =
let index_of_x_in_holes = find_eq eq holes x in
reveal_opaque (`%contains_eq) (contains_eq eq);
if index_of_x_in_holes < index_of_first_pigeon
then
assert (S.index holes index_of_x_in_holes ==
S.index holes_except_first_pigeon index_of_x_in_holes)
else
(Classical.move_requires (trans_lemma eq x (S.index holes index_of_x_in_holes)) first_pigeon;
assert (S.index holes index_of_x_in_holes ==
S.index holes_except_first_pigeon (index_of_x_in_holes - 1)))
in
Classical.forall_intro all_but_first_pigeon_remain_in_reduced;
let i1, i2 =
pigeonhole_eq (eq)
(holes_except_first_pigeon)
(S.init #(items_of eq holes_except_first_pigeon)
(S.length pigeons - 1)
(fun i -> S.index pigeons (i + 1)))
in
(i1 + 1, i2 + 1) | false |
Pulse.Checker.Prover.Match.fst | Pulse.Checker.Prover.Match.equational | val equational (t: term) : bool | val equational (t: term) : bool | let equational (t:term) : bool =
match t.t with
| Tm_FStar host_term ->
(match R.inspect_ln host_term with
| R.Tv_Match _ _ _ -> true
| _ -> false)
| _ -> false | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Match.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 14,
"end_line": 45,
"start_col": 0,
"start_line": 39
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Prover.Match
open Pulse.Syntax
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Typing.Metatheory
open Pulse.Typing.Util
open Pulse.Checker.VPropEquiv
open Pulse.Checker.Prover.Base
open Pulse.Checker.Prover.Util
module RU = Pulse.RuntimeUtils
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module TermEq = FStar.Reflection.V2.TermEq
module T = FStar.Tactics.V2
module RUtil = Pulse.Reflection.Util
module P = Pulse.Syntax.Printer
module PS = Pulse.Checker.Prover.Substs
module Metatheory = Pulse.Typing.Metatheory | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Util.fsti.checked",
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Readback.fsti.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Prover.Util.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.Match.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.Reflection.Util",
"short_module": "RUtil"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2.TermEq",
"short_module": "TermEq"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.VPropEquiv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Metatheory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Pulse.Syntax.Base.term -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.__proj__Mkterm__item__t",
"Pulse.Syntax.Base.host_term",
"FStar.Stubs.Reflection.V2.Builtins.inspect_ln",
"FStar.Stubs.Reflection.Types.term",
"FStar.Pervasives.Native.option",
"FStar.Stubs.Reflection.Types.match_returns_ascription",
"Prims.list",
"FStar.Stubs.Reflection.V2.Data.branch",
"FStar.Stubs.Reflection.V2.Data.term_view",
"Prims.bool",
"Pulse.Syntax.Base.term'"
] | [] | false | false | false | true | false | let equational (t: term) : bool =
| match t.t with
| Tm_FStar host_term ->
(match R.inspect_ln host_term with
| R.Tv_Match _ _ _ -> true
| _ -> false)
| _ -> false | false |
Pulse.Checker.Prover.Match.fst | Pulse.Checker.Prover.Match.refl_uvar | val refl_uvar (t: R.term) (uvs: env) : option var | val refl_uvar (t: R.term) (uvs: env) : option var | let refl_uvar (t:R.term) (uvs:env) : option var =
let open R in
match inspect_ln t with
| Tv_Var v ->
let {uniq=n} = inspect_namedv v in
if contains uvs n then Some n else None
| _ -> None | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Match.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 13,
"end_line": 178,
"start_col": 0,
"start_line": 172
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Prover.Match
open Pulse.Syntax
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Typing.Metatheory
open Pulse.Typing.Util
open Pulse.Checker.VPropEquiv
open Pulse.Checker.Prover.Base
open Pulse.Checker.Prover.Util
module RU = Pulse.RuntimeUtils
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module TermEq = FStar.Reflection.V2.TermEq
module T = FStar.Tactics.V2
module RUtil = Pulse.Reflection.Util
module P = Pulse.Syntax.Printer
module PS = Pulse.Checker.Prover.Substs
module Metatheory = Pulse.Typing.Metatheory
let equational (t:term) : bool =
match t.t with
| Tm_FStar host_term ->
(match R.inspect_ln host_term with
| R.Tv_Match _ _ _ -> true
| _ -> false)
| _ -> false
let type_of_fv (g:env) (fv:R.fv)
: T.Tac (option R.term)
= let n = R.inspect_fv fv in
match R.lookup_typ (fstar_env g) n with
| None -> None
| Some se ->
match R.inspect_sigelt se with
| R.Unk -> None
| R.Sg_Let _ lbs -> (
L.tryPick
(fun lb ->
let lbv = R.inspect_lb lb in
if R.inspect_fv lbv.lb_fv = n
then Some lbv.lb_typ
else None)
lbs
)
| R.Sg_Val _ _ t -> Some t
| R.Sg_Inductive _nm _univs params typ _ -> None
let is_smt_fallback (t:R.term) : bool =
match R.inspect_ln t with
| R.Tv_FVar fv ->
let name = R.inspect_fv fv in
name = ["Steel";"Effect";"Common";"smt_fallback"] ||
name = ["Pulse"; "Lib"; "Core"; "equate_by_smt"]
| _ -> false
(*
When comparing t0 =?= t1, if they are not syntactically equal, we
have to decide whether or not we should fire an SMT query to compare
them for provable equality.
The criterion is as follows:
1. We allow an SMT query if either t0 or t1 is "equational". For now, that means
that either is a match expression.
2. Otherwise, if they are both applications of `f v0...vn` and `f u0...un`
of the same head symbol `f`, a top-level constant, then we check if the
type of `f` decorates any of its binders with the `smt_fallback` attribute.
- If none of them are marked as such,
then we check if `f v0...` is syntactically equal to `f u0...`
and allow an SMT query to check if vn = vm. That is, the default behavior
for predicates is that they *last* argument is eligible for SMT equality.
- Otherwise, for each binder that is NOT marked as `smt_fallback`, we check
if the corresponding argument is syntactically equal. If so, we allow
t0 and t1 to be compared for SMT equality.
For example, Steel.ST.Reference.pts_to is defined like so:
/// For instance, [pts_to r (sum_perm (half_perm p) (half_perm p)) (v + 1)]
/// is unifiable with [pts_to r p (1 + v)]
val pts_to (#a:Type0)
(r:ref a)
([@@@smt_fallback] p:perm)
([@@@smt_fallback] v:a)
: vprop
*)
let eligible_for_smt_equality (g:env) (t0 t1:term)
: T.Tac bool
= let either_equational () = equational t0 || equational t1 in
let head_eq (t0 t1:R.term) =
match R.inspect_ln t0, R.inspect_ln t1 with
| R.Tv_App h0 _, R.Tv_App h1 _ ->
TermEq.term_eq h0 h1
| _ -> false
in
match t0.t, t1.t with
| Tm_FStar t0, Tm_FStar t1 -> (
let h0, args0 = R.collect_app_ln t0 in
let h1, args1 = R.collect_app_ln t1 in
if TermEq.term_eq h0 h1 && L.length args0 = L.length args1
then (
match R.inspect_ln h0 with
| R.Tv_FVar fv
| R.Tv_UInst fv _ -> (
match type_of_fv g fv with
| None -> either_equational()
| Some t ->
let bs, _ = R.collect_arr_ln_bs t in
let is_smt_fallback (b:R.binder) =
let bview = R.inspect_binder b in
L.existsb is_smt_fallback bview.attrs
in
let some_fallbacks, fallbacks =
L.fold_right
(fun b (some_fallbacks, bs) ->
if is_smt_fallback b
then true, true::bs
else some_fallbacks, false::bs)
bs (false, [])
in
if not some_fallbacks
then (
//if none of the binders are marked fallback
//then, by default, consider only the last argument as
//fallback
head_eq t0 t1
)
else (
let rec aux args0 args1 fallbacks =
match args0, args1, fallbacks with
| (a0, _)::args0, (a1, _)::args1, b::fallbacks ->
if b
then aux args0 args1 fallbacks
else if not (TermEq.term_eq a0 a1)
then false
else aux args0 args1 fallbacks
| [], [], [] -> true
| _ -> either_equational() //unequal lengths
in
aux args0 args1 fallbacks
)
)
| _ -> either_equational ()
)
else either_equational ()
)
| Tm_ForallSL _ _ _, Tm_ForallSL _ _ _ -> true
| _ -> either_equational () | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Util.fsti.checked",
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Readback.fsti.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Prover.Util.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.Match.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.Reflection.Util",
"short_module": "RUtil"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2.TermEq",
"short_module": "TermEq"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.VPropEquiv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Metatheory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: FStar.Stubs.Reflection.Types.term -> uvs: Pulse.Typing.Env.env
-> FStar.Pervasives.Native.option Pulse.Syntax.Base.var | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.term",
"Pulse.Typing.Env.env",
"FStar.Stubs.Reflection.V2.Builtins.inspect_ln",
"FStar.Stubs.Reflection.Types.namedv",
"Prims.nat",
"FStar.Sealed.sealed",
"FStar.Stubs.Reflection.Types.typ",
"FStar.Stubs.Reflection.V2.Data.ppname_t",
"Pulse.Typing.Env.contains",
"FStar.Pervasives.Native.Some",
"Pulse.Syntax.Base.var",
"Prims.bool",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.option",
"FStar.Stubs.Reflection.V2.Data.namedv_view",
"Prims.precedes",
"FStar.Stubs.Reflection.V2.Builtins.inspect_namedv",
"FStar.Stubs.Reflection.V2.Data.term_view"
] | [] | false | false | false | true | false | let refl_uvar (t: R.term) (uvs: env) : option var =
| let open R in
match inspect_ln t with
| Tv_Var v ->
let { uniq = n } = inspect_namedv v in
if contains uvs n then Some n else None
| _ -> None | false |
Clear.fst | Clear.l2 | val l2 : x: Prims.int -> y: Prims.bool -> z: Prims.int -> Prims.unit | let l2 (x : int) (y : bool) (z : int) =
assert (phi ==> (psi ==> xi)) by tau2 () | {
"file_name": "examples/native_tactics/Clear.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 44,
"end_line": 60,
"start_col": 0,
"start_line": 59
} | (*
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 Clear
open FStar.Tactics.V2
assume val phi : Type
assume val psi : Type
assume val xi : Type
assume val p : squash xi
[@@plugin]
let tau1 = fun () ->
let _ = implies_intro () in
clear_top ();
let _ = implies_intro () in
clear_top ();
exact (`p)
let l1 (x : bool) (y : int) (z : unit) =
assert (phi ==> (psi ==> xi)) by tau1 ()
let clear_all_of_type (t : typ) : Tac unit =
let e = cur_env () in
let bs = vars_of_env e in
let _ = map (fun b -> if term_eq (type_of_binding b) t
then clear b
else ())
// We need to traverse the list backwards, to clear rightmost
// binders first. Otherwise, if we go left-first, we will revert/intro
// over a binder we want to clear and cause it to be refreshed.
(List.rev bs) in
()
[@@plugin]
let tau2 = fun () -> let e = cur_env () in
let n = List.length (vars_of_env e) in
let u = `int in
clear_all_of_type u;
let e = cur_env () in
// We're removing two binders
guard (List.length (vars_of_env e) = n - 2) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.fst.checked"
],
"interface_file": false,
"source_file": "Clear.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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.int -> y: Prims.bool -> z: Prims.int -> Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Prims.bool",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.l_imp",
"Clear.phi",
"Clear.psi",
"Clear.xi",
"Prims.unit",
"Clear.tau2"
] | [] | false | false | false | true | false | let l2 (x: int) (y: bool) (z: int) =
| FStar.Tactics.Effect.assert_by_tactic (phi ==> (psi ==> xi))
(fun _ ->
();
tau2 ()) | false |
|
Pulse.Checker.Prover.Match.fst | Pulse.Checker.Prover.Match.is_uvar | val is_uvar (t: term) (uvs: env) : option var | val is_uvar (t: term) (uvs: env) : option var | let is_uvar (t:term) (uvs:env) : option var =
match t.t with
| Tm_FStar t -> refl_uvar t uvs
| _ -> None | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Match.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 13,
"end_line": 183,
"start_col": 0,
"start_line": 180
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Prover.Match
open Pulse.Syntax
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Typing.Metatheory
open Pulse.Typing.Util
open Pulse.Checker.VPropEquiv
open Pulse.Checker.Prover.Base
open Pulse.Checker.Prover.Util
module RU = Pulse.RuntimeUtils
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module TermEq = FStar.Reflection.V2.TermEq
module T = FStar.Tactics.V2
module RUtil = Pulse.Reflection.Util
module P = Pulse.Syntax.Printer
module PS = Pulse.Checker.Prover.Substs
module Metatheory = Pulse.Typing.Metatheory
let equational (t:term) : bool =
match t.t with
| Tm_FStar host_term ->
(match R.inspect_ln host_term with
| R.Tv_Match _ _ _ -> true
| _ -> false)
| _ -> false
let type_of_fv (g:env) (fv:R.fv)
: T.Tac (option R.term)
= let n = R.inspect_fv fv in
match R.lookup_typ (fstar_env g) n with
| None -> None
| Some se ->
match R.inspect_sigelt se with
| R.Unk -> None
| R.Sg_Let _ lbs -> (
L.tryPick
(fun lb ->
let lbv = R.inspect_lb lb in
if R.inspect_fv lbv.lb_fv = n
then Some lbv.lb_typ
else None)
lbs
)
| R.Sg_Val _ _ t -> Some t
| R.Sg_Inductive _nm _univs params typ _ -> None
let is_smt_fallback (t:R.term) : bool =
match R.inspect_ln t with
| R.Tv_FVar fv ->
let name = R.inspect_fv fv in
name = ["Steel";"Effect";"Common";"smt_fallback"] ||
name = ["Pulse"; "Lib"; "Core"; "equate_by_smt"]
| _ -> false
(*
When comparing t0 =?= t1, if they are not syntactically equal, we
have to decide whether or not we should fire an SMT query to compare
them for provable equality.
The criterion is as follows:
1. We allow an SMT query if either t0 or t1 is "equational". For now, that means
that either is a match expression.
2. Otherwise, if they are both applications of `f v0...vn` and `f u0...un`
of the same head symbol `f`, a top-level constant, then we check if the
type of `f` decorates any of its binders with the `smt_fallback` attribute.
- If none of them are marked as such,
then we check if `f v0...` is syntactically equal to `f u0...`
and allow an SMT query to check if vn = vm. That is, the default behavior
for predicates is that they *last* argument is eligible for SMT equality.
- Otherwise, for each binder that is NOT marked as `smt_fallback`, we check
if the corresponding argument is syntactically equal. If so, we allow
t0 and t1 to be compared for SMT equality.
For example, Steel.ST.Reference.pts_to is defined like so:
/// For instance, [pts_to r (sum_perm (half_perm p) (half_perm p)) (v + 1)]
/// is unifiable with [pts_to r p (1 + v)]
val pts_to (#a:Type0)
(r:ref a)
([@@@smt_fallback] p:perm)
([@@@smt_fallback] v:a)
: vprop
*)
let eligible_for_smt_equality (g:env) (t0 t1:term)
: T.Tac bool
= let either_equational () = equational t0 || equational t1 in
let head_eq (t0 t1:R.term) =
match R.inspect_ln t0, R.inspect_ln t1 with
| R.Tv_App h0 _, R.Tv_App h1 _ ->
TermEq.term_eq h0 h1
| _ -> false
in
match t0.t, t1.t with
| Tm_FStar t0, Tm_FStar t1 -> (
let h0, args0 = R.collect_app_ln t0 in
let h1, args1 = R.collect_app_ln t1 in
if TermEq.term_eq h0 h1 && L.length args0 = L.length args1
then (
match R.inspect_ln h0 with
| R.Tv_FVar fv
| R.Tv_UInst fv _ -> (
match type_of_fv g fv with
| None -> either_equational()
| Some t ->
let bs, _ = R.collect_arr_ln_bs t in
let is_smt_fallback (b:R.binder) =
let bview = R.inspect_binder b in
L.existsb is_smt_fallback bview.attrs
in
let some_fallbacks, fallbacks =
L.fold_right
(fun b (some_fallbacks, bs) ->
if is_smt_fallback b
then true, true::bs
else some_fallbacks, false::bs)
bs (false, [])
in
if not some_fallbacks
then (
//if none of the binders are marked fallback
//then, by default, consider only the last argument as
//fallback
head_eq t0 t1
)
else (
let rec aux args0 args1 fallbacks =
match args0, args1, fallbacks with
| (a0, _)::args0, (a1, _)::args1, b::fallbacks ->
if b
then aux args0 args1 fallbacks
else if not (TermEq.term_eq a0 a1)
then false
else aux args0 args1 fallbacks
| [], [], [] -> true
| _ -> either_equational() //unequal lengths
in
aux args0 args1 fallbacks
)
)
| _ -> either_equational ()
)
else either_equational ()
)
| Tm_ForallSL _ _ _, Tm_ForallSL _ _ _ -> true
| _ -> either_equational ()
let refl_uvar (t:R.term) (uvs:env) : option var =
let open R in
match inspect_ln t with
| Tv_Var v ->
let {uniq=n} = inspect_namedv v in
if contains uvs n then Some n else None
| _ -> None | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Util.fsti.checked",
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Readback.fsti.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Prover.Util.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.Match.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.Reflection.Util",
"short_module": "RUtil"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2.TermEq",
"short_module": "TermEq"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.VPropEquiv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Metatheory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Pulse.Syntax.Base.term -> uvs: Pulse.Typing.Env.env
-> FStar.Pervasives.Native.option Pulse.Syntax.Base.var | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.term",
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.__proj__Mkterm__item__t",
"Pulse.Syntax.Base.host_term",
"Pulse.Checker.Prover.Match.refl_uvar",
"Pulse.Syntax.Base.term'",
"FStar.Pervasives.Native.None",
"Pulse.Syntax.Base.var",
"FStar.Pervasives.Native.option"
] | [] | false | false | false | true | false | let is_uvar (t: term) (uvs: env) : option var =
| match t.t with
| Tm_FStar t -> refl_uvar t uvs
| _ -> None | false |
Pulse.Checker.Prover.Match.fst | Pulse.Checker.Prover.Match.contains_uvar | val contains_uvar (t: term) (uvs g: env) : T.Tac bool | val contains_uvar (t: term) (uvs g: env) : T.Tac bool | let contains_uvar (t:term) (uvs:env) (g:env) : T.Tac bool =
not (check_disjoint uvs (freevars t)) | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Match.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 39,
"end_line": 186,
"start_col": 0,
"start_line": 185
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Prover.Match
open Pulse.Syntax
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Typing.Metatheory
open Pulse.Typing.Util
open Pulse.Checker.VPropEquiv
open Pulse.Checker.Prover.Base
open Pulse.Checker.Prover.Util
module RU = Pulse.RuntimeUtils
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module TermEq = FStar.Reflection.V2.TermEq
module T = FStar.Tactics.V2
module RUtil = Pulse.Reflection.Util
module P = Pulse.Syntax.Printer
module PS = Pulse.Checker.Prover.Substs
module Metatheory = Pulse.Typing.Metatheory
let equational (t:term) : bool =
match t.t with
| Tm_FStar host_term ->
(match R.inspect_ln host_term with
| R.Tv_Match _ _ _ -> true
| _ -> false)
| _ -> false
let type_of_fv (g:env) (fv:R.fv)
: T.Tac (option R.term)
= let n = R.inspect_fv fv in
match R.lookup_typ (fstar_env g) n with
| None -> None
| Some se ->
match R.inspect_sigelt se with
| R.Unk -> None
| R.Sg_Let _ lbs -> (
L.tryPick
(fun lb ->
let lbv = R.inspect_lb lb in
if R.inspect_fv lbv.lb_fv = n
then Some lbv.lb_typ
else None)
lbs
)
| R.Sg_Val _ _ t -> Some t
| R.Sg_Inductive _nm _univs params typ _ -> None
let is_smt_fallback (t:R.term) : bool =
match R.inspect_ln t with
| R.Tv_FVar fv ->
let name = R.inspect_fv fv in
name = ["Steel";"Effect";"Common";"smt_fallback"] ||
name = ["Pulse"; "Lib"; "Core"; "equate_by_smt"]
| _ -> false
(*
When comparing t0 =?= t1, if they are not syntactically equal, we
have to decide whether or not we should fire an SMT query to compare
them for provable equality.
The criterion is as follows:
1. We allow an SMT query if either t0 or t1 is "equational". For now, that means
that either is a match expression.
2. Otherwise, if they are both applications of `f v0...vn` and `f u0...un`
of the same head symbol `f`, a top-level constant, then we check if the
type of `f` decorates any of its binders with the `smt_fallback` attribute.
- If none of them are marked as such,
then we check if `f v0...` is syntactically equal to `f u0...`
and allow an SMT query to check if vn = vm. That is, the default behavior
for predicates is that they *last* argument is eligible for SMT equality.
- Otherwise, for each binder that is NOT marked as `smt_fallback`, we check
if the corresponding argument is syntactically equal. If so, we allow
t0 and t1 to be compared for SMT equality.
For example, Steel.ST.Reference.pts_to is defined like so:
/// For instance, [pts_to r (sum_perm (half_perm p) (half_perm p)) (v + 1)]
/// is unifiable with [pts_to r p (1 + v)]
val pts_to (#a:Type0)
(r:ref a)
([@@@smt_fallback] p:perm)
([@@@smt_fallback] v:a)
: vprop
*)
let eligible_for_smt_equality (g:env) (t0 t1:term)
: T.Tac bool
= let either_equational () = equational t0 || equational t1 in
let head_eq (t0 t1:R.term) =
match R.inspect_ln t0, R.inspect_ln t1 with
| R.Tv_App h0 _, R.Tv_App h1 _ ->
TermEq.term_eq h0 h1
| _ -> false
in
match t0.t, t1.t with
| Tm_FStar t0, Tm_FStar t1 -> (
let h0, args0 = R.collect_app_ln t0 in
let h1, args1 = R.collect_app_ln t1 in
if TermEq.term_eq h0 h1 && L.length args0 = L.length args1
then (
match R.inspect_ln h0 with
| R.Tv_FVar fv
| R.Tv_UInst fv _ -> (
match type_of_fv g fv with
| None -> either_equational()
| Some t ->
let bs, _ = R.collect_arr_ln_bs t in
let is_smt_fallback (b:R.binder) =
let bview = R.inspect_binder b in
L.existsb is_smt_fallback bview.attrs
in
let some_fallbacks, fallbacks =
L.fold_right
(fun b (some_fallbacks, bs) ->
if is_smt_fallback b
then true, true::bs
else some_fallbacks, false::bs)
bs (false, [])
in
if not some_fallbacks
then (
//if none of the binders are marked fallback
//then, by default, consider only the last argument as
//fallback
head_eq t0 t1
)
else (
let rec aux args0 args1 fallbacks =
match args0, args1, fallbacks with
| (a0, _)::args0, (a1, _)::args1, b::fallbacks ->
if b
then aux args0 args1 fallbacks
else if not (TermEq.term_eq a0 a1)
then false
else aux args0 args1 fallbacks
| [], [], [] -> true
| _ -> either_equational() //unequal lengths
in
aux args0 args1 fallbacks
)
)
| _ -> either_equational ()
)
else either_equational ()
)
| Tm_ForallSL _ _ _, Tm_ForallSL _ _ _ -> true
| _ -> either_equational ()
let refl_uvar (t:R.term) (uvs:env) : option var =
let open R in
match inspect_ln t with
| Tv_Var v ->
let {uniq=n} = inspect_namedv v in
if contains uvs n then Some n else None
| _ -> None
let is_uvar (t:term) (uvs:env) : option var =
match t.t with
| Tm_FStar t -> refl_uvar t uvs
| _ -> None | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Util.fsti.checked",
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Readback.fsti.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Prover.Util.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.Match.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.Reflection.Util",
"short_module": "RUtil"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2.TermEq",
"short_module": "TermEq"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.VPropEquiv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Metatheory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Pulse.Syntax.Base.term -> uvs: Pulse.Typing.Env.env -> g: Pulse.Typing.Env.env
-> FStar.Tactics.Effect.Tac Prims.bool | FStar.Tactics.Effect.Tac | [] | [] | [
"Pulse.Syntax.Base.term",
"Pulse.Typing.Env.env",
"Prims.op_Negation",
"Pulse.Typing.Env.check_disjoint",
"Pulse.Syntax.Naming.freevars",
"Prims.bool"
] | [] | false | true | false | false | false | let contains_uvar (t: term) (uvs g: env) : T.Tac bool =
| not (check_disjoint uvs (freevars t)) | false |
Pulse.Checker.Prover.Match.fst | Pulse.Checker.Prover.Match.move_hd_end | val move_hd_end (g: env) (l: list vprop {Cons? l})
: vprop_equiv g (list_as_vprop l) (list_as_vprop (L.tl l @ [L.hd l])) | val move_hd_end (g: env) (l: list vprop {Cons? l})
: vprop_equiv g (list_as_vprop l) (list_as_vprop (L.tl l @ [L.hd l])) | let move_hd_end (g:env) (l:list vprop { Cons? l })
: vprop_equiv g (list_as_vprop l) (list_as_vprop (L.tl l @ [L.hd l])) = RU.magic () | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Match.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 85,
"end_line": 374,
"start_col": 0,
"start_line": 373
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Prover.Match
open Pulse.Syntax
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Typing.Metatheory
open Pulse.Typing.Util
open Pulse.Checker.VPropEquiv
open Pulse.Checker.Prover.Base
open Pulse.Checker.Prover.Util
module RU = Pulse.RuntimeUtils
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module TermEq = FStar.Reflection.V2.TermEq
module T = FStar.Tactics.V2
module RUtil = Pulse.Reflection.Util
module P = Pulse.Syntax.Printer
module PS = Pulse.Checker.Prover.Substs
module Metatheory = Pulse.Typing.Metatheory
let equational (t:term) : bool =
match t.t with
| Tm_FStar host_term ->
(match R.inspect_ln host_term with
| R.Tv_Match _ _ _ -> true
| _ -> false)
| _ -> false
let type_of_fv (g:env) (fv:R.fv)
: T.Tac (option R.term)
= let n = R.inspect_fv fv in
match R.lookup_typ (fstar_env g) n with
| None -> None
| Some se ->
match R.inspect_sigelt se with
| R.Unk -> None
| R.Sg_Let _ lbs -> (
L.tryPick
(fun lb ->
let lbv = R.inspect_lb lb in
if R.inspect_fv lbv.lb_fv = n
then Some lbv.lb_typ
else None)
lbs
)
| R.Sg_Val _ _ t -> Some t
| R.Sg_Inductive _nm _univs params typ _ -> None
let is_smt_fallback (t:R.term) : bool =
match R.inspect_ln t with
| R.Tv_FVar fv ->
let name = R.inspect_fv fv in
name = ["Steel";"Effect";"Common";"smt_fallback"] ||
name = ["Pulse"; "Lib"; "Core"; "equate_by_smt"]
| _ -> false
(*
When comparing t0 =?= t1, if they are not syntactically equal, we
have to decide whether or not we should fire an SMT query to compare
them for provable equality.
The criterion is as follows:
1. We allow an SMT query if either t0 or t1 is "equational". For now, that means
that either is a match expression.
2. Otherwise, if they are both applications of `f v0...vn` and `f u0...un`
of the same head symbol `f`, a top-level constant, then we check if the
type of `f` decorates any of its binders with the `smt_fallback` attribute.
- If none of them are marked as such,
then we check if `f v0...` is syntactically equal to `f u0...`
and allow an SMT query to check if vn = vm. That is, the default behavior
for predicates is that they *last* argument is eligible for SMT equality.
- Otherwise, for each binder that is NOT marked as `smt_fallback`, we check
if the corresponding argument is syntactically equal. If so, we allow
t0 and t1 to be compared for SMT equality.
For example, Steel.ST.Reference.pts_to is defined like so:
/// For instance, [pts_to r (sum_perm (half_perm p) (half_perm p)) (v + 1)]
/// is unifiable with [pts_to r p (1 + v)]
val pts_to (#a:Type0)
(r:ref a)
([@@@smt_fallback] p:perm)
([@@@smt_fallback] v:a)
: vprop
*)
let eligible_for_smt_equality (g:env) (t0 t1:term)
: T.Tac bool
= let either_equational () = equational t0 || equational t1 in
let head_eq (t0 t1:R.term) =
match R.inspect_ln t0, R.inspect_ln t1 with
| R.Tv_App h0 _, R.Tv_App h1 _ ->
TermEq.term_eq h0 h1
| _ -> false
in
match t0.t, t1.t with
| Tm_FStar t0, Tm_FStar t1 -> (
let h0, args0 = R.collect_app_ln t0 in
let h1, args1 = R.collect_app_ln t1 in
if TermEq.term_eq h0 h1 && L.length args0 = L.length args1
then (
match R.inspect_ln h0 with
| R.Tv_FVar fv
| R.Tv_UInst fv _ -> (
match type_of_fv g fv with
| None -> either_equational()
| Some t ->
let bs, _ = R.collect_arr_ln_bs t in
let is_smt_fallback (b:R.binder) =
let bview = R.inspect_binder b in
L.existsb is_smt_fallback bview.attrs
in
let some_fallbacks, fallbacks =
L.fold_right
(fun b (some_fallbacks, bs) ->
if is_smt_fallback b
then true, true::bs
else some_fallbacks, false::bs)
bs (false, [])
in
if not some_fallbacks
then (
//if none of the binders are marked fallback
//then, by default, consider only the last argument as
//fallback
head_eq t0 t1
)
else (
let rec aux args0 args1 fallbacks =
match args0, args1, fallbacks with
| (a0, _)::args0, (a1, _)::args1, b::fallbacks ->
if b
then aux args0 args1 fallbacks
else if not (TermEq.term_eq a0 a1)
then false
else aux args0 args1 fallbacks
| [], [], [] -> true
| _ -> either_equational() //unequal lengths
in
aux args0 args1 fallbacks
)
)
| _ -> either_equational ()
)
else either_equational ()
)
| Tm_ForallSL _ _ _, Tm_ForallSL _ _ _ -> true
| _ -> either_equational ()
let refl_uvar (t:R.term) (uvs:env) : option var =
let open R in
match inspect_ln t with
| Tv_Var v ->
let {uniq=n} = inspect_namedv v in
if contains uvs n then Some n else None
| _ -> None
let is_uvar (t:term) (uvs:env) : option var =
match t.t with
| Tm_FStar t -> refl_uvar t uvs
| _ -> None
let contains_uvar (t:term) (uvs:env) (g:env) : T.Tac bool =
not (check_disjoint uvs (freevars t))
let is_reveal_uvar (t:term) (uvs:env) : option (universe & term & var) =
match is_pure_app t with
| Some (hd, None, arg) ->
(match is_pure_app hd with
| Some (hd, Some Implicit, ty) ->
let arg_uvar_index_opt = is_uvar arg uvs in
(match arg_uvar_index_opt with
| Some n ->
(match is_fvar hd with
| Some (l, [u]) ->
if l = RUtil.reveal_lid
then Some (u, ty, n)
else None
| _ -> None)
| _ -> None)
| _ -> None)
| _ -> None
let is_reveal (t:term) : bool =
match leftmost_head t with
| Some hd ->
(match is_fvar hd with
| Some (l, [_]) -> l = RUtil.reveal_lid
| _ -> false)
| _ -> false
module RT = FStar.Reflection.Typing
//
// Call into the F* unifier to solve for uvs by unifying p and q
//
let try_solve_uvars (g:env) (uvs:env { disjoint uvs g }) (p q:term)
: T.Tac (ss:PS.ss_t { PS.dom ss `Set.subset` freevars q }) =
let uvs = uvs
|> bindings_with_ppname
|> L.rev
|> L.map (fun (({name}, x, t):(ppname & _ & _)) ->
let nv_view = {
R.uniq = x;
R.sort = elab_term t;
R.ppname = name;
} in
let nv = R.pack_namedv nv_view in
nv, elab_term t
) in
let l, issues = RU.with_context (get_context g) (fun _ ->
T.try_unify (elab_env g) uvs (elab_term p) (elab_term q))
in
T.log_issues issues;
// build ss
let ss = PS.empty in
assume (PS.dom ss `Set.subset` freevars q);
match l with
| None -> ss
| Some l ->
let q_names = freevars q in
L.fold_left (fun (ss:(ss:PS.ss_t { PS.dom ss `Set.subset` freevars q })) (x, t) ->
let nv_view = R.inspect_namedv x in
let topt = readback_ty t in
match topt with
| Some t ->
if Set.mem nv_view.uniq q_names &&
not (Set.mem nv_view.uniq (PS.dom ss))
then begin
let ss_new = PS.push ss nv_view.uniq t in
assert (nv_view.uniq `Set.mem` freevars q);
assert (PS.dom ss `Set.subset` freevars q);
assume (PS.dom ss_new `Set.subset` freevars q);
ss_new
end
else ss
| None -> ss
) ss l
let unify (g:env) (uvs:env { disjoint uvs g})
(p q:term)
: T.Tac (ss:PS.ss_t { PS.dom ss `Set.subset` freevars q } &
option (RT.equiv (elab_env g) (elab_term p) (elab_term ss.(q)))) =
let ss = try_solve_uvars g uvs p q in
let q_ss = readback_ty (elab_term ss.(q)) in
match q_ss with
| None -> (| ss, None |)
| Some q ->
if eq_tm p q
then (| ss, Some (RT.Rel_refl _ _ _) |)
else if contains_uvar q uvs g
then (| ss, None |)
else if eligible_for_smt_equality g p q
then let v0 = elab_term p in
let v1 = elab_term q in
match check_equiv_now (elab_env g) v0 v1 with
| Some token, _ -> (| ss, Some (RT.Rel_eq_token _ _ _ (FStar.Squash.return_squash token)) |)
| None, _ -> (| ss, None |)
else (| ss, None |)
let try_match_pq (g:env) (uvs:env { disjoint uvs g}) (p q:vprop)
: T.Tac (ss:PS.ss_t { PS.dom ss `Set.subset` freevars q } &
option (vprop_equiv g p ss.(q))) =
let r = unify g uvs p q in
match r with
| (| ss, None |) -> (| ss, None |)
| (| ss, Some _ |) -> (| ss, Some (RU.magic #(vprop_equiv _ _ _) ()) |)
let coerce_eq (#a #b:Type) (x:a) (_:squash (a == b)) : y:b{y == x} = x
let match_step (#preamble:preamble) (pst:prover_state preamble)
(p:vprop) (remaining_ctxt':list vprop)
(q:vprop) (unsolved':list vprop)
(_:squash (pst.remaining_ctxt == p::remaining_ctxt' /\
pst.unsolved == q::unsolved'))
: T.Tac (option (pst':prover_state preamble { pst' `pst_extends` pst })) =
let q_ss = pst.ss.(q) in
assume (freevars q_ss `Set.disjoint` PS.dom pst.ss);
let (| ss_q, ropt |) = try_match_pq pst.pg pst.uvs p q_ss in
debug_prover pst.pg (fun _ ->
Printf.sprintf "prover matcher: tried to match p %s and q (partially substituted) %s, result: %s"
(P.term_to_string p) (P.term_to_string (ss_q.(q_ss))) (if None? ropt then "fail" else "success"));
match ropt with
| None -> None
| Some veq ->
assert (PS.dom ss_q `Set.disjoint` PS.dom pst.ss);
let ss_new = PS.push_ss pst.ss ss_q in
let veq : vprop_equiv pst.pg p (ss_q.(pst.ss.(q))) = veq in
assume (ss_q.(pst.ss.(q)) == ss_new.(q));
let veq : vprop_equiv pst.pg p ss_new.(q) = coerce_eq veq () in
let remaining_ctxt_new = remaining_ctxt' in
let solved_new = q * pst.solved in
let unsolved_new = unsolved' in
let k
: continuation_elaborator
preamble.g0 (preamble.ctxt * preamble.frame)
pst.pg ((list_as_vprop pst.remaining_ctxt * preamble.frame) * pst.ss.(pst.solved)) = pst.k in
assume (pst.ss.(pst.solved) == ss_new.(pst.solved));
let k
: continuation_elaborator
preamble.g0 (preamble.ctxt * preamble.frame)
pst.pg ((list_as_vprop (p::remaining_ctxt_new) * preamble.frame) * ss_new.(pst.solved)) =
coerce_eq k () in
let k
: continuation_elaborator
preamble.g0 (preamble.ctxt * preamble.frame)
pst.pg ((list_as_vprop remaining_ctxt_new * preamble.frame) * (ss_new.(q) * ss_new.(pst.solved))) =
k_elab_equiv k (VE_Refl _ _) (RU.magic ()) in
assume (ss_new.(q) * ss_new.(pst.solved) == ss_new.(q * pst.solved));
let k
: continuation_elaborator
preamble.g0 (preamble.ctxt * preamble.frame)
pst.pg ((list_as_vprop remaining_ctxt_new * preamble.frame) * (ss_new.(solved_new))) =
coerce_eq k () in
assume (freevars ss_new.(solved_new) `Set.subset` dom pst.pg);
let pst' : prover_state preamble =
{ pst with remaining_ctxt=remaining_ctxt_new;
remaining_ctxt_frame_typing=RU.magic ();
ss=ss_new;
nts=None;
solved=solved_new;
unsolved=unsolved_new;
k;
goals_inv=RU.magic ();
solved_inv=() } in
assume (ss_new `ss_extends` pst.ss);
Some pst' | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Util.fsti.checked",
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Readback.fsti.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Prover.Util.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.Match.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.Reflection.Util",
"short_module": "RUtil"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2.TermEq",
"short_module": "TermEq"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.VPropEquiv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Metatheory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: Pulse.Typing.Env.env -> l: Prims.list Pulse.Syntax.Base.vprop {Cons? l}
-> Pulse.Typing.vprop_equiv g
(Pulse.Typing.Combinators.list_as_vprop l)
(Pulse.Typing.Combinators.list_as_vprop (FStar.List.Tot.Base.tl l @ [FStar.List.Tot.Base.hd l]
)) | Prims.Tot | [
"total"
] | [] | [
"Pulse.Typing.Env.env",
"Prims.list",
"Pulse.Syntax.Base.vprop",
"Prims.b2t",
"Prims.uu___is_Cons",
"Pulse.RuntimeUtils.magic",
"Pulse.Typing.vprop_equiv",
"Pulse.Typing.Combinators.list_as_vprop",
"FStar.List.Tot.Base.append",
"FStar.List.Tot.Base.tl",
"Prims.Cons",
"FStar.List.Tot.Base.hd",
"Prims.Nil"
] | [] | false | false | false | false | false | let move_hd_end (g: env) (l: list vprop {Cons? l})
: vprop_equiv g (list_as_vprop l) (list_as_vprop (L.tl l @ [L.hd l])) =
| RU.magic () | false |
Pulse.Checker.Prover.Match.fst | Pulse.Checker.Prover.Match.remaining_ctxt_equiv_pst | val remaining_ctxt_equiv_pst
(#preamble: _)
(pst: prover_state preamble)
(remaining_ctxt': list vprop)
(d: vprop_equiv pst.pg (list_as_vprop pst.remaining_ctxt) (list_as_vprop remaining_ctxt'))
: prover_state preamble | val remaining_ctxt_equiv_pst
(#preamble: _)
(pst: prover_state preamble)
(remaining_ctxt': list vprop)
(d: vprop_equiv pst.pg (list_as_vprop pst.remaining_ctxt) (list_as_vprop remaining_ctxt'))
: prover_state preamble | let remaining_ctxt_equiv_pst (#preamble:_) (pst:prover_state preamble) (remaining_ctxt':list vprop)
(d:vprop_equiv pst.pg (list_as_vprop pst.remaining_ctxt) (list_as_vprop remaining_ctxt'))
: prover_state preamble =
{ pst with remaining_ctxt = remaining_ctxt';
remaining_ctxt_frame_typing = RU.magic ();
k = k_elab_equiv pst.k (VE_Refl _ _) (RU.magic ()) } | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Match.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 65,
"end_line": 381,
"start_col": 0,
"start_line": 376
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Prover.Match
open Pulse.Syntax
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Typing.Metatheory
open Pulse.Typing.Util
open Pulse.Checker.VPropEquiv
open Pulse.Checker.Prover.Base
open Pulse.Checker.Prover.Util
module RU = Pulse.RuntimeUtils
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module TermEq = FStar.Reflection.V2.TermEq
module T = FStar.Tactics.V2
module RUtil = Pulse.Reflection.Util
module P = Pulse.Syntax.Printer
module PS = Pulse.Checker.Prover.Substs
module Metatheory = Pulse.Typing.Metatheory
let equational (t:term) : bool =
match t.t with
| Tm_FStar host_term ->
(match R.inspect_ln host_term with
| R.Tv_Match _ _ _ -> true
| _ -> false)
| _ -> false
let type_of_fv (g:env) (fv:R.fv)
: T.Tac (option R.term)
= let n = R.inspect_fv fv in
match R.lookup_typ (fstar_env g) n with
| None -> None
| Some se ->
match R.inspect_sigelt se with
| R.Unk -> None
| R.Sg_Let _ lbs -> (
L.tryPick
(fun lb ->
let lbv = R.inspect_lb lb in
if R.inspect_fv lbv.lb_fv = n
then Some lbv.lb_typ
else None)
lbs
)
| R.Sg_Val _ _ t -> Some t
| R.Sg_Inductive _nm _univs params typ _ -> None
let is_smt_fallback (t:R.term) : bool =
match R.inspect_ln t with
| R.Tv_FVar fv ->
let name = R.inspect_fv fv in
name = ["Steel";"Effect";"Common";"smt_fallback"] ||
name = ["Pulse"; "Lib"; "Core"; "equate_by_smt"]
| _ -> false
(*
When comparing t0 =?= t1, if they are not syntactically equal, we
have to decide whether or not we should fire an SMT query to compare
them for provable equality.
The criterion is as follows:
1. We allow an SMT query if either t0 or t1 is "equational". For now, that means
that either is a match expression.
2. Otherwise, if they are both applications of `f v0...vn` and `f u0...un`
of the same head symbol `f`, a top-level constant, then we check if the
type of `f` decorates any of its binders with the `smt_fallback` attribute.
- If none of them are marked as such,
then we check if `f v0...` is syntactically equal to `f u0...`
and allow an SMT query to check if vn = vm. That is, the default behavior
for predicates is that they *last* argument is eligible for SMT equality.
- Otherwise, for each binder that is NOT marked as `smt_fallback`, we check
if the corresponding argument is syntactically equal. If so, we allow
t0 and t1 to be compared for SMT equality.
For example, Steel.ST.Reference.pts_to is defined like so:
/// For instance, [pts_to r (sum_perm (half_perm p) (half_perm p)) (v + 1)]
/// is unifiable with [pts_to r p (1 + v)]
val pts_to (#a:Type0)
(r:ref a)
([@@@smt_fallback] p:perm)
([@@@smt_fallback] v:a)
: vprop
*)
let eligible_for_smt_equality (g:env) (t0 t1:term)
: T.Tac bool
= let either_equational () = equational t0 || equational t1 in
let head_eq (t0 t1:R.term) =
match R.inspect_ln t0, R.inspect_ln t1 with
| R.Tv_App h0 _, R.Tv_App h1 _ ->
TermEq.term_eq h0 h1
| _ -> false
in
match t0.t, t1.t with
| Tm_FStar t0, Tm_FStar t1 -> (
let h0, args0 = R.collect_app_ln t0 in
let h1, args1 = R.collect_app_ln t1 in
if TermEq.term_eq h0 h1 && L.length args0 = L.length args1
then (
match R.inspect_ln h0 with
| R.Tv_FVar fv
| R.Tv_UInst fv _ -> (
match type_of_fv g fv with
| None -> either_equational()
| Some t ->
let bs, _ = R.collect_arr_ln_bs t in
let is_smt_fallback (b:R.binder) =
let bview = R.inspect_binder b in
L.existsb is_smt_fallback bview.attrs
in
let some_fallbacks, fallbacks =
L.fold_right
(fun b (some_fallbacks, bs) ->
if is_smt_fallback b
then true, true::bs
else some_fallbacks, false::bs)
bs (false, [])
in
if not some_fallbacks
then (
//if none of the binders are marked fallback
//then, by default, consider only the last argument as
//fallback
head_eq t0 t1
)
else (
let rec aux args0 args1 fallbacks =
match args0, args1, fallbacks with
| (a0, _)::args0, (a1, _)::args1, b::fallbacks ->
if b
then aux args0 args1 fallbacks
else if not (TermEq.term_eq a0 a1)
then false
else aux args0 args1 fallbacks
| [], [], [] -> true
| _ -> either_equational() //unequal lengths
in
aux args0 args1 fallbacks
)
)
| _ -> either_equational ()
)
else either_equational ()
)
| Tm_ForallSL _ _ _, Tm_ForallSL _ _ _ -> true
| _ -> either_equational ()
let refl_uvar (t:R.term) (uvs:env) : option var =
let open R in
match inspect_ln t with
| Tv_Var v ->
let {uniq=n} = inspect_namedv v in
if contains uvs n then Some n else None
| _ -> None
let is_uvar (t:term) (uvs:env) : option var =
match t.t with
| Tm_FStar t -> refl_uvar t uvs
| _ -> None
let contains_uvar (t:term) (uvs:env) (g:env) : T.Tac bool =
not (check_disjoint uvs (freevars t))
let is_reveal_uvar (t:term) (uvs:env) : option (universe & term & var) =
match is_pure_app t with
| Some (hd, None, arg) ->
(match is_pure_app hd with
| Some (hd, Some Implicit, ty) ->
let arg_uvar_index_opt = is_uvar arg uvs in
(match arg_uvar_index_opt with
| Some n ->
(match is_fvar hd with
| Some (l, [u]) ->
if l = RUtil.reveal_lid
then Some (u, ty, n)
else None
| _ -> None)
| _ -> None)
| _ -> None)
| _ -> None
let is_reveal (t:term) : bool =
match leftmost_head t with
| Some hd ->
(match is_fvar hd with
| Some (l, [_]) -> l = RUtil.reveal_lid
| _ -> false)
| _ -> false
module RT = FStar.Reflection.Typing
//
// Call into the F* unifier to solve for uvs by unifying p and q
//
let try_solve_uvars (g:env) (uvs:env { disjoint uvs g }) (p q:term)
: T.Tac (ss:PS.ss_t { PS.dom ss `Set.subset` freevars q }) =
let uvs = uvs
|> bindings_with_ppname
|> L.rev
|> L.map (fun (({name}, x, t):(ppname & _ & _)) ->
let nv_view = {
R.uniq = x;
R.sort = elab_term t;
R.ppname = name;
} in
let nv = R.pack_namedv nv_view in
nv, elab_term t
) in
let l, issues = RU.with_context (get_context g) (fun _ ->
T.try_unify (elab_env g) uvs (elab_term p) (elab_term q))
in
T.log_issues issues;
// build ss
let ss = PS.empty in
assume (PS.dom ss `Set.subset` freevars q);
match l with
| None -> ss
| Some l ->
let q_names = freevars q in
L.fold_left (fun (ss:(ss:PS.ss_t { PS.dom ss `Set.subset` freevars q })) (x, t) ->
let nv_view = R.inspect_namedv x in
let topt = readback_ty t in
match topt with
| Some t ->
if Set.mem nv_view.uniq q_names &&
not (Set.mem nv_view.uniq (PS.dom ss))
then begin
let ss_new = PS.push ss nv_view.uniq t in
assert (nv_view.uniq `Set.mem` freevars q);
assert (PS.dom ss `Set.subset` freevars q);
assume (PS.dom ss_new `Set.subset` freevars q);
ss_new
end
else ss
| None -> ss
) ss l
let unify (g:env) (uvs:env { disjoint uvs g})
(p q:term)
: T.Tac (ss:PS.ss_t { PS.dom ss `Set.subset` freevars q } &
option (RT.equiv (elab_env g) (elab_term p) (elab_term ss.(q)))) =
let ss = try_solve_uvars g uvs p q in
let q_ss = readback_ty (elab_term ss.(q)) in
match q_ss with
| None -> (| ss, None |)
| Some q ->
if eq_tm p q
then (| ss, Some (RT.Rel_refl _ _ _) |)
else if contains_uvar q uvs g
then (| ss, None |)
else if eligible_for_smt_equality g p q
then let v0 = elab_term p in
let v1 = elab_term q in
match check_equiv_now (elab_env g) v0 v1 with
| Some token, _ -> (| ss, Some (RT.Rel_eq_token _ _ _ (FStar.Squash.return_squash token)) |)
| None, _ -> (| ss, None |)
else (| ss, None |)
let try_match_pq (g:env) (uvs:env { disjoint uvs g}) (p q:vprop)
: T.Tac (ss:PS.ss_t { PS.dom ss `Set.subset` freevars q } &
option (vprop_equiv g p ss.(q))) =
let r = unify g uvs p q in
match r with
| (| ss, None |) -> (| ss, None |)
| (| ss, Some _ |) -> (| ss, Some (RU.magic #(vprop_equiv _ _ _) ()) |)
let coerce_eq (#a #b:Type) (x:a) (_:squash (a == b)) : y:b{y == x} = x
let match_step (#preamble:preamble) (pst:prover_state preamble)
(p:vprop) (remaining_ctxt':list vprop)
(q:vprop) (unsolved':list vprop)
(_:squash (pst.remaining_ctxt == p::remaining_ctxt' /\
pst.unsolved == q::unsolved'))
: T.Tac (option (pst':prover_state preamble { pst' `pst_extends` pst })) =
let q_ss = pst.ss.(q) in
assume (freevars q_ss `Set.disjoint` PS.dom pst.ss);
let (| ss_q, ropt |) = try_match_pq pst.pg pst.uvs p q_ss in
debug_prover pst.pg (fun _ ->
Printf.sprintf "prover matcher: tried to match p %s and q (partially substituted) %s, result: %s"
(P.term_to_string p) (P.term_to_string (ss_q.(q_ss))) (if None? ropt then "fail" else "success"));
match ropt with
| None -> None
| Some veq ->
assert (PS.dom ss_q `Set.disjoint` PS.dom pst.ss);
let ss_new = PS.push_ss pst.ss ss_q in
let veq : vprop_equiv pst.pg p (ss_q.(pst.ss.(q))) = veq in
assume (ss_q.(pst.ss.(q)) == ss_new.(q));
let veq : vprop_equiv pst.pg p ss_new.(q) = coerce_eq veq () in
let remaining_ctxt_new = remaining_ctxt' in
let solved_new = q * pst.solved in
let unsolved_new = unsolved' in
let k
: continuation_elaborator
preamble.g0 (preamble.ctxt * preamble.frame)
pst.pg ((list_as_vprop pst.remaining_ctxt * preamble.frame) * pst.ss.(pst.solved)) = pst.k in
assume (pst.ss.(pst.solved) == ss_new.(pst.solved));
let k
: continuation_elaborator
preamble.g0 (preamble.ctxt * preamble.frame)
pst.pg ((list_as_vprop (p::remaining_ctxt_new) * preamble.frame) * ss_new.(pst.solved)) =
coerce_eq k () in
let k
: continuation_elaborator
preamble.g0 (preamble.ctxt * preamble.frame)
pst.pg ((list_as_vprop remaining_ctxt_new * preamble.frame) * (ss_new.(q) * ss_new.(pst.solved))) =
k_elab_equiv k (VE_Refl _ _) (RU.magic ()) in
assume (ss_new.(q) * ss_new.(pst.solved) == ss_new.(q * pst.solved));
let k
: continuation_elaborator
preamble.g0 (preamble.ctxt * preamble.frame)
pst.pg ((list_as_vprop remaining_ctxt_new * preamble.frame) * (ss_new.(solved_new))) =
coerce_eq k () in
assume (freevars ss_new.(solved_new) `Set.subset` dom pst.pg);
let pst' : prover_state preamble =
{ pst with remaining_ctxt=remaining_ctxt_new;
remaining_ctxt_frame_typing=RU.magic ();
ss=ss_new;
nts=None;
solved=solved_new;
unsolved=unsolved_new;
k;
goals_inv=RU.magic ();
solved_inv=() } in
assume (ss_new `ss_extends` pst.ss);
Some pst'
let move_hd_end (g:env) (l:list vprop { Cons? l })
: vprop_equiv g (list_as_vprop l) (list_as_vprop (L.tl l @ [L.hd l])) = RU.magic () | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Util.fsti.checked",
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Readback.fsti.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Prover.Util.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.Match.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.Reflection.Util",
"short_module": "RUtil"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2.TermEq",
"short_module": "TermEq"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.VPropEquiv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Metatheory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
pst: Pulse.Checker.Prover.Base.prover_state preamble ->
remaining_ctxt': Prims.list Pulse.Syntax.Base.vprop ->
d:
Pulse.Typing.vprop_equiv (Mkprover_state?.pg pst)
(Pulse.Typing.Combinators.list_as_vprop (Mkprover_state?.remaining_ctxt pst))
(Pulse.Typing.Combinators.list_as_vprop remaining_ctxt')
-> Pulse.Checker.Prover.Base.prover_state preamble | Prims.Tot | [
"total"
] | [] | [
"Pulse.Checker.Prover.Base.preamble",
"Pulse.Checker.Prover.Base.prover_state",
"Prims.list",
"Pulse.Syntax.Base.vprop",
"Pulse.Typing.vprop_equiv",
"Pulse.Checker.Prover.Base.__proj__Mkprover_state__item__pg",
"Pulse.Typing.Combinators.list_as_vprop",
"Pulse.Checker.Prover.Base.__proj__Mkprover_state__item__remaining_ctxt",
"Pulse.Checker.Prover.Base.Mkprover_state",
"Pulse.RuntimeUtils.magic",
"Pulse.Checker.Prover.Base.vprop_typing",
"Pulse.Checker.Prover.Base.op_Star",
"Pulse.Checker.Prover.Base.__proj__Mkpreamble__item__frame",
"Pulse.Checker.Prover.Base.__proj__Mkprover_state__item__uvs",
"Pulse.Checker.Prover.Base.__proj__Mkprover_state__item__ss",
"Pulse.Checker.Prover.Base.__proj__Mkprover_state__item__nts",
"Pulse.Checker.Prover.Base.__proj__Mkprover_state__item__solved",
"Pulse.Checker.Prover.Base.__proj__Mkprover_state__item__unsolved",
"Pulse.Checker.Base.k_elab_equiv",
"Pulse.Checker.Prover.Base.__proj__Mkpreamble__item__g0",
"Pulse.Checker.Prover.Base.__proj__Mkpreamble__item__ctxt",
"Pulse.Checker.Prover.Base.op_Array_Access",
"Pulse.Checker.Prover.Base.__proj__Mkprover_state__item__k",
"Pulse.Typing.VE_Refl",
"Pulse.Checker.Prover.Base.__proj__Mkprover_state__item__goals_inv",
"Pulse.Checker.Prover.Base.__proj__Mkprover_state__item__solved_inv"
] | [] | false | false | false | false | false | let remaining_ctxt_equiv_pst
(#preamble: _)
(pst: prover_state preamble)
(remaining_ctxt': list vprop)
(d: vprop_equiv pst.pg (list_as_vprop pst.remaining_ctxt) (list_as_vprop remaining_ctxt'))
: prover_state preamble =
| {
pst with
remaining_ctxt = remaining_ctxt';
remaining_ctxt_frame_typing = RU.magic ();
k = k_elab_equiv pst.k (VE_Refl _ _) (RU.magic ())
} | false |
Pulse.Checker.Prover.Match.fst | Pulse.Checker.Prover.Match.has_structure | val has_structure (q: vprop) : bool | val has_structure (q: vprop) : bool | let has_structure (q:vprop) : bool =
match q.t with
| Tm_Star _ _ -> true
| _ -> false | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Match.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 14,
"end_line": 417,
"start_col": 0,
"start_line": 414
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Prover.Match
open Pulse.Syntax
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Typing.Metatheory
open Pulse.Typing.Util
open Pulse.Checker.VPropEquiv
open Pulse.Checker.Prover.Base
open Pulse.Checker.Prover.Util
module RU = Pulse.RuntimeUtils
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module TermEq = FStar.Reflection.V2.TermEq
module T = FStar.Tactics.V2
module RUtil = Pulse.Reflection.Util
module P = Pulse.Syntax.Printer
module PS = Pulse.Checker.Prover.Substs
module Metatheory = Pulse.Typing.Metatheory
let equational (t:term) : bool =
match t.t with
| Tm_FStar host_term ->
(match R.inspect_ln host_term with
| R.Tv_Match _ _ _ -> true
| _ -> false)
| _ -> false
let type_of_fv (g:env) (fv:R.fv)
: T.Tac (option R.term)
= let n = R.inspect_fv fv in
match R.lookup_typ (fstar_env g) n with
| None -> None
| Some se ->
match R.inspect_sigelt se with
| R.Unk -> None
| R.Sg_Let _ lbs -> (
L.tryPick
(fun lb ->
let lbv = R.inspect_lb lb in
if R.inspect_fv lbv.lb_fv = n
then Some lbv.lb_typ
else None)
lbs
)
| R.Sg_Val _ _ t -> Some t
| R.Sg_Inductive _nm _univs params typ _ -> None
let is_smt_fallback (t:R.term) : bool =
match R.inspect_ln t with
| R.Tv_FVar fv ->
let name = R.inspect_fv fv in
name = ["Steel";"Effect";"Common";"smt_fallback"] ||
name = ["Pulse"; "Lib"; "Core"; "equate_by_smt"]
| _ -> false
(*
When comparing t0 =?= t1, if they are not syntactically equal, we
have to decide whether or not we should fire an SMT query to compare
them for provable equality.
The criterion is as follows:
1. We allow an SMT query if either t0 or t1 is "equational". For now, that means
that either is a match expression.
2. Otherwise, if they are both applications of `f v0...vn` and `f u0...un`
of the same head symbol `f`, a top-level constant, then we check if the
type of `f` decorates any of its binders with the `smt_fallback` attribute.
- If none of them are marked as such,
then we check if `f v0...` is syntactically equal to `f u0...`
and allow an SMT query to check if vn = vm. That is, the default behavior
for predicates is that they *last* argument is eligible for SMT equality.
- Otherwise, for each binder that is NOT marked as `smt_fallback`, we check
if the corresponding argument is syntactically equal. If so, we allow
t0 and t1 to be compared for SMT equality.
For example, Steel.ST.Reference.pts_to is defined like so:
/// For instance, [pts_to r (sum_perm (half_perm p) (half_perm p)) (v + 1)]
/// is unifiable with [pts_to r p (1 + v)]
val pts_to (#a:Type0)
(r:ref a)
([@@@smt_fallback] p:perm)
([@@@smt_fallback] v:a)
: vprop
*)
let eligible_for_smt_equality (g:env) (t0 t1:term)
: T.Tac bool
= let either_equational () = equational t0 || equational t1 in
let head_eq (t0 t1:R.term) =
match R.inspect_ln t0, R.inspect_ln t1 with
| R.Tv_App h0 _, R.Tv_App h1 _ ->
TermEq.term_eq h0 h1
| _ -> false
in
match t0.t, t1.t with
| Tm_FStar t0, Tm_FStar t1 -> (
let h0, args0 = R.collect_app_ln t0 in
let h1, args1 = R.collect_app_ln t1 in
if TermEq.term_eq h0 h1 && L.length args0 = L.length args1
then (
match R.inspect_ln h0 with
| R.Tv_FVar fv
| R.Tv_UInst fv _ -> (
match type_of_fv g fv with
| None -> either_equational()
| Some t ->
let bs, _ = R.collect_arr_ln_bs t in
let is_smt_fallback (b:R.binder) =
let bview = R.inspect_binder b in
L.existsb is_smt_fallback bview.attrs
in
let some_fallbacks, fallbacks =
L.fold_right
(fun b (some_fallbacks, bs) ->
if is_smt_fallback b
then true, true::bs
else some_fallbacks, false::bs)
bs (false, [])
in
if not some_fallbacks
then (
//if none of the binders are marked fallback
//then, by default, consider only the last argument as
//fallback
head_eq t0 t1
)
else (
let rec aux args0 args1 fallbacks =
match args0, args1, fallbacks with
| (a0, _)::args0, (a1, _)::args1, b::fallbacks ->
if b
then aux args0 args1 fallbacks
else if not (TermEq.term_eq a0 a1)
then false
else aux args0 args1 fallbacks
| [], [], [] -> true
| _ -> either_equational() //unequal lengths
in
aux args0 args1 fallbacks
)
)
| _ -> either_equational ()
)
else either_equational ()
)
| Tm_ForallSL _ _ _, Tm_ForallSL _ _ _ -> true
| _ -> either_equational ()
let refl_uvar (t:R.term) (uvs:env) : option var =
let open R in
match inspect_ln t with
| Tv_Var v ->
let {uniq=n} = inspect_namedv v in
if contains uvs n then Some n else None
| _ -> None
let is_uvar (t:term) (uvs:env) : option var =
match t.t with
| Tm_FStar t -> refl_uvar t uvs
| _ -> None
let contains_uvar (t:term) (uvs:env) (g:env) : T.Tac bool =
not (check_disjoint uvs (freevars t))
let is_reveal_uvar (t:term) (uvs:env) : option (universe & term & var) =
match is_pure_app t with
| Some (hd, None, arg) ->
(match is_pure_app hd with
| Some (hd, Some Implicit, ty) ->
let arg_uvar_index_opt = is_uvar arg uvs in
(match arg_uvar_index_opt with
| Some n ->
(match is_fvar hd with
| Some (l, [u]) ->
if l = RUtil.reveal_lid
then Some (u, ty, n)
else None
| _ -> None)
| _ -> None)
| _ -> None)
| _ -> None
let is_reveal (t:term) : bool =
match leftmost_head t with
| Some hd ->
(match is_fvar hd with
| Some (l, [_]) -> l = RUtil.reveal_lid
| _ -> false)
| _ -> false
module RT = FStar.Reflection.Typing
//
// Call into the F* unifier to solve for uvs by unifying p and q
//
let try_solve_uvars (g:env) (uvs:env { disjoint uvs g }) (p q:term)
: T.Tac (ss:PS.ss_t { PS.dom ss `Set.subset` freevars q }) =
let uvs = uvs
|> bindings_with_ppname
|> L.rev
|> L.map (fun (({name}, x, t):(ppname & _ & _)) ->
let nv_view = {
R.uniq = x;
R.sort = elab_term t;
R.ppname = name;
} in
let nv = R.pack_namedv nv_view in
nv, elab_term t
) in
let l, issues = RU.with_context (get_context g) (fun _ ->
T.try_unify (elab_env g) uvs (elab_term p) (elab_term q))
in
T.log_issues issues;
// build ss
let ss = PS.empty in
assume (PS.dom ss `Set.subset` freevars q);
match l with
| None -> ss
| Some l ->
let q_names = freevars q in
L.fold_left (fun (ss:(ss:PS.ss_t { PS.dom ss `Set.subset` freevars q })) (x, t) ->
let nv_view = R.inspect_namedv x in
let topt = readback_ty t in
match topt with
| Some t ->
if Set.mem nv_view.uniq q_names &&
not (Set.mem nv_view.uniq (PS.dom ss))
then begin
let ss_new = PS.push ss nv_view.uniq t in
assert (nv_view.uniq `Set.mem` freevars q);
assert (PS.dom ss `Set.subset` freevars q);
assume (PS.dom ss_new `Set.subset` freevars q);
ss_new
end
else ss
| None -> ss
) ss l
let unify (g:env) (uvs:env { disjoint uvs g})
(p q:term)
: T.Tac (ss:PS.ss_t { PS.dom ss `Set.subset` freevars q } &
option (RT.equiv (elab_env g) (elab_term p) (elab_term ss.(q)))) =
let ss = try_solve_uvars g uvs p q in
let q_ss = readback_ty (elab_term ss.(q)) in
match q_ss with
| None -> (| ss, None |)
| Some q ->
if eq_tm p q
then (| ss, Some (RT.Rel_refl _ _ _) |)
else if contains_uvar q uvs g
then (| ss, None |)
else if eligible_for_smt_equality g p q
then let v0 = elab_term p in
let v1 = elab_term q in
match check_equiv_now (elab_env g) v0 v1 with
| Some token, _ -> (| ss, Some (RT.Rel_eq_token _ _ _ (FStar.Squash.return_squash token)) |)
| None, _ -> (| ss, None |)
else (| ss, None |)
let try_match_pq (g:env) (uvs:env { disjoint uvs g}) (p q:vprop)
: T.Tac (ss:PS.ss_t { PS.dom ss `Set.subset` freevars q } &
option (vprop_equiv g p ss.(q))) =
let r = unify g uvs p q in
match r with
| (| ss, None |) -> (| ss, None |)
| (| ss, Some _ |) -> (| ss, Some (RU.magic #(vprop_equiv _ _ _) ()) |)
let coerce_eq (#a #b:Type) (x:a) (_:squash (a == b)) : y:b{y == x} = x
let match_step (#preamble:preamble) (pst:prover_state preamble)
(p:vprop) (remaining_ctxt':list vprop)
(q:vprop) (unsolved':list vprop)
(_:squash (pst.remaining_ctxt == p::remaining_ctxt' /\
pst.unsolved == q::unsolved'))
: T.Tac (option (pst':prover_state preamble { pst' `pst_extends` pst })) =
let q_ss = pst.ss.(q) in
assume (freevars q_ss `Set.disjoint` PS.dom pst.ss);
let (| ss_q, ropt |) = try_match_pq pst.pg pst.uvs p q_ss in
debug_prover pst.pg (fun _ ->
Printf.sprintf "prover matcher: tried to match p %s and q (partially substituted) %s, result: %s"
(P.term_to_string p) (P.term_to_string (ss_q.(q_ss))) (if None? ropt then "fail" else "success"));
match ropt with
| None -> None
| Some veq ->
assert (PS.dom ss_q `Set.disjoint` PS.dom pst.ss);
let ss_new = PS.push_ss pst.ss ss_q in
let veq : vprop_equiv pst.pg p (ss_q.(pst.ss.(q))) = veq in
assume (ss_q.(pst.ss.(q)) == ss_new.(q));
let veq : vprop_equiv pst.pg p ss_new.(q) = coerce_eq veq () in
let remaining_ctxt_new = remaining_ctxt' in
let solved_new = q * pst.solved in
let unsolved_new = unsolved' in
let k
: continuation_elaborator
preamble.g0 (preamble.ctxt * preamble.frame)
pst.pg ((list_as_vprop pst.remaining_ctxt * preamble.frame) * pst.ss.(pst.solved)) = pst.k in
assume (pst.ss.(pst.solved) == ss_new.(pst.solved));
let k
: continuation_elaborator
preamble.g0 (preamble.ctxt * preamble.frame)
pst.pg ((list_as_vprop (p::remaining_ctxt_new) * preamble.frame) * ss_new.(pst.solved)) =
coerce_eq k () in
let k
: continuation_elaborator
preamble.g0 (preamble.ctxt * preamble.frame)
pst.pg ((list_as_vprop remaining_ctxt_new * preamble.frame) * (ss_new.(q) * ss_new.(pst.solved))) =
k_elab_equiv k (VE_Refl _ _) (RU.magic ()) in
assume (ss_new.(q) * ss_new.(pst.solved) == ss_new.(q * pst.solved));
let k
: continuation_elaborator
preamble.g0 (preamble.ctxt * preamble.frame)
pst.pg ((list_as_vprop remaining_ctxt_new * preamble.frame) * (ss_new.(solved_new))) =
coerce_eq k () in
assume (freevars ss_new.(solved_new) `Set.subset` dom pst.pg);
let pst' : prover_state preamble =
{ pst with remaining_ctxt=remaining_ctxt_new;
remaining_ctxt_frame_typing=RU.magic ();
ss=ss_new;
nts=None;
solved=solved_new;
unsolved=unsolved_new;
k;
goals_inv=RU.magic ();
solved_inv=() } in
assume (ss_new `ss_extends` pst.ss);
Some pst'
let move_hd_end (g:env) (l:list vprop { Cons? l })
: vprop_equiv g (list_as_vprop l) (list_as_vprop (L.tl l @ [L.hd l])) = RU.magic ()
let remaining_ctxt_equiv_pst (#preamble:_) (pst:prover_state preamble) (remaining_ctxt':list vprop)
(d:vprop_equiv pst.pg (list_as_vprop pst.remaining_ctxt) (list_as_vprop remaining_ctxt'))
: prover_state preamble =
{ pst with remaining_ctxt = remaining_ctxt';
remaining_ctxt_frame_typing = RU.magic ();
k = k_elab_equiv pst.k (VE_Refl _ _) (RU.magic ()) }
let rec match_q_aux (#preamble:_) (pst:prover_state preamble)
(q:vprop) (unsolved':list vprop)
(_:squash (pst.unsolved == q::unsolved'))
(i:nat)
: T.Tac (option (pst':prover_state preamble { pst' `pst_extends` pst })) =
if L.length pst.remaining_ctxt = 0
then None
else if i = L.length pst.remaining_ctxt
then None
else
let p = L.hd pst.remaining_ctxt in
let pst_opt =
match_step pst p (L.tl pst.remaining_ctxt) q unsolved' () in
match pst_opt with
| Some pst -> Some pst
| None ->
let pst =
remaining_ctxt_equiv_pst pst (L.tl pst.remaining_ctxt @ [L.hd pst.remaining_ctxt])
(move_hd_end pst.pg pst.remaining_ctxt) in
match_q_aux pst q unsolved' () (i+1)
//
// THIS SHOULD GO AWAY SOON
//
let ___canon___ (q:vprop) : Dv (r:vprop { r == q }) =
assume False;
match Pulse.Readback.readback_ty (elab_term q) with
| None -> q
| Some q -> q | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Util.fsti.checked",
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Readback.fsti.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Prover.Util.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.Match.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.Reflection.Util",
"short_module": "RUtil"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2.TermEq",
"short_module": "TermEq"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.VPropEquiv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Metatheory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | q: Pulse.Syntax.Base.vprop -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.vprop",
"Pulse.Syntax.Base.__proj__Mkterm__item__t",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.term'",
"Prims.bool"
] | [] | false | false | false | true | false | let has_structure (q: vprop) : bool =
| match q.t with
| Tm_Star _ _ -> true
| _ -> false | false |
Vale.AES.GCM_BE.fst | Vale.AES.GCM_BE.gcm_blocks_helper | val gcm_blocks_helper
(alg: algorithm)
(key: seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes: seq quad32)
(p_num_bytes a_num_bytes: nat)
(iv: supported_iv_BE)
(j0_BE h enc_hash length_quad: quad32)
: Lemma
(requires
length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\ length p128 == length c128 /\ length p_bytes == 1 /\
length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_word alg key /\
j0_BE = compute_iv_BE h iv /\ h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad ==
two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then append c128 c_bytes else c128
in
let cipher_bound:nat = length p128 + (if p_num_bytes > length p128 * 16 then 1 else 0) in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes
in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16
then
let raw_quads = append raw_quads c_bytes in
let input_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes
in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0)))
(ensures
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes
in
let plain_raw_quads =
if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128
in
let plain_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then append c128 c_bytes else c128
in
let cipher_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes
in
length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\
cipher_bytes ==
fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes) /\
be_quad32_to_bytes enc_hash ==
snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes))) | val gcm_blocks_helper
(alg: algorithm)
(key: seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes: seq quad32)
(p_num_bytes a_num_bytes: nat)
(iv: supported_iv_BE)
(j0_BE h enc_hash length_quad: quad32)
: Lemma
(requires
length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\ length p128 == length c128 /\ length p_bytes == 1 /\
length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_word alg key /\
j0_BE = compute_iv_BE h iv /\ h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad ==
two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then append c128 c_bytes else c128
in
let cipher_bound:nat = length p128 + (if p_num_bytes > length p128 * 16 then 1 else 0) in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes
in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16
then
let raw_quads = append raw_quads c_bytes in
let input_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes
in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0)))
(ensures
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes
in
let plain_raw_quads =
if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128
in
let plain_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then append c128 c_bytes else c128
in
let cipher_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes
in
length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\
cipher_bytes ==
fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes) /\
be_quad32_to_bytes enc_hash ==
snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes))) | let gcm_blocks_helper (alg:algorithm) (key:seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes:seq quad32)
(p_num_bytes a_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE h enc_hash length_quad:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\
a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
length a_bytes == 1 /\
is_aes_key_word alg key /\
j0_BE = compute_iv_BE h iv /\
h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads c_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0
)))
(ensures (let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let plain_raw_quads =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else p128
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes) /\
be_quad32_to_bytes enc_hash ==
snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key)
iv plain_bytes auth_bytes)))
=
let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads c_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
let hash = ghash_BE h final_quads in
gcm_blocks_helper_enc alg key p128 p_bytes c128 c_bytes auth_input_bytes p_num_bytes iv j0_BE;
calc (==) {
enc_hash;
== {}
gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0;
== {}
gctr_encrypt_block ctr_BE_1 hash alg key 0;
== {}
quad32_xor hash (aes_encrypt_word alg key ctr_BE_1);
};
calc (==) {
gctr_encrypt ctr_BE_1 (be_quad32_to_bytes hash) alg key;
== { gctr_encrypt_one_block ctr_BE_1 hash alg key }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 (quad32_xor hash (aes_encrypt_word alg key ctr_BE_1))));
== {}
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 enc_hash));
== { be_seq_quad32_to_bytes_of_singleton enc_hash }
be_quad32_to_bytes enc_hash;
};
if p_num_bytes > length p128 * 16 then (
let c = append c128 c_bytes in
calc (==) {
append (append auth_quads c128) c_bytes;
== { append_assoc auth_quads c128 c_bytes }
append auth_quads (append c128 c_bytes);
== {}
append auth_quads c;
};
calc (==) {
append (append (append auth_quads c128) c_bytes) (create 1 length_quad);
= {} // See previous calc
append (append auth_quads (append c128 c_bytes)) (create 1 length_quad);
== { append_assoc auth_quads c (create 1 length_quad) }
append auth_quads (append c (create 1 length_quad));
};
let raw_quads_old = append auth_quads c in
calc (==) {
raw_quads;
== {}
be_bytes_to_seq_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes));
== {
calc (==) {
pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes);
== {
calc (==) {
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes;
== { append_distributes_be_seq_quad32_to_bytes auth_quads c }
slice (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))) 0 total_bytes;
== { slice_append_back (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))
total_bytes }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes);
== {}
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) cipher_bytes;
}
}
pad_to_128_bits (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) cipher_bytes);
== { pad_to_128_bits_multiple_append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) cipher_bytes }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (pad_to_128_bits cipher_bytes);
}
}
be_bytes_to_seq_quad32 (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (pad_to_128_bits cipher_bytes));
== { append_distributes_be_bytes_to_seq_quad32
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(pad_to_128_bits cipher_bytes) }
append (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))) (be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes));
== { be_bytes_to_seq_quad32_to_bytes auth_quads }
append auth_quads (be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes));
};
let auth_padded_quads' = be_bytes_to_seq_quad32 (pad_to_128_bits auth_input_bytes) in
let cipher_padded_quads' = be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes) in
calc (==) {
append raw_quads (create 1 length_quad);
== {}
append (append auth_quads (be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes))) (create 1 length_quad);
== { assert (equal auth_quads auth_padded_quads') }
append (append auth_padded_quads' cipher_padded_quads') (create 1 length_quad);
== { append_assoc auth_padded_quads' cipher_padded_quads' (create 1 length_quad) }
append auth_padded_quads' (append cipher_padded_quads' (create 1 length_quad));
};
gcm_encrypt_BE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key;
()
) else (
calc (==) {
append (append auth_quads c128) (create 1 length_quad);
== { append_assoc auth_quads c128 (create 1 length_quad) }
append auth_quads (append c128 (create 1 length_quad));
};
let c = c128 in
calc (==) {
be_bytes_to_seq_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes));
== { assert (equal (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes)) }
be_bytes_to_seq_quad32 (pad_to_128_bits (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)));
== { assert (pad_to_128_bits (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) == (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))) }
be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c));
== { be_bytes_to_seq_quad32_to_bytes c }
c;
};
gcm_encrypt_BE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key;
()
);
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_BE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 511,
"start_col": 0,
"start_line": 272
} | module Vale.AES.GCM_BE
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.AES.GCM_BE_s
open Vale.AES.AES_BE_s
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.AES.GHash_BE_s
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open FStar.Calc
let upper3_equal (q0 q1:quad32) : bool =
q0.lo1 = q1.lo1 &&
q0.hi2 = q1.hi2 &&
q0.hi3 = q1.hi3
let lemma_be_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma
(requires slice b0 0 12 == slice b1 0 12)
(ensures upper3_equal (be_bytes_to_quad32 b0) (be_bytes_to_quad32 b1))
=
let q0 = be_bytes_to_quad32 b0 in
let q1 = be_bytes_to_quad32 b1 in
be_bytes_to_quad32_reveal ();
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #nat8);
assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\
index b1 i == index (slice b1 0 12) i))
let lemma_be_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma
(slice (be_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
=
assert (equal (slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
(slice (be_quad32_to_bytes q) 0 12));
()
let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_BE) (num_bytes:nat64) (h_BE j0:quad32) : Lemma
(requires
length iv_extra_b == 1 /\
length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\
num_bytes == 96/8 /\
(let iv_BE = index iv_extra_b 0 in
j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\
(let raw_quads = append iv_b iv_extra_b in
let iv_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 num_bytes in
iv_bytes == iv))
(ensures j0 == compute_iv_BE h_BE iv)
=
assert (length iv == 12);
assert (length iv_b == 0);
lemma_empty iv_b;
append_empty_l iv_extra_b;
assert (append iv_b iv_extra_b == iv_extra_b);
let q = index iv_extra_b 0 in
be_seq_quad32_to_bytes_of_singleton q;
assert (equal iv_extra_b (create 1 q));
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b) == be_quad32_to_bytes q);
calc (==) {
slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12;
== {}
slice (pad_to_128_bits iv) 0 12;
};
calc (==) {
be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b)) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits iv);
};
calc (==) {
j0;
== {}
set_to_one q;
== { be_bytes_to_quad32_to_bytes q }
set_to_one (be_bytes_to_quad32 (be_quad32_to_bytes q));
== {
lemma_be_seq_quad32_to_bytes_prefix_equality q;
lemma_be_bytes_to_quad32_prefix_equality
(be_quad32_to_bytes q)
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
}
set_to_one (be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)));
== { lemma_be_bytes_to_quad32_prefix_equality
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
(pad_to_128_bits iv) }
set_to_one (be_bytes_to_quad32 (pad_to_128_bits iv));
== {compute_iv_BE_reveal ()}
compute_iv_BE h_BE iv;
};
()
let lemma_compute_iv_hard (iv:supported_iv_BE) (quads:seq quad32) (length_quad h_BE j0:quad32) : Lemma
(requires
~(length iv == 96/8) /\
quads == be_bytes_to_seq_quad32 (pad_to_128_bits iv) /\
j0 == ghash_incremental h_BE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 0)
(nat_to_two 32 (8 * length iv))))
(ensures j0 == compute_iv_BE h_BE iv)
=
ghash_incremental_to_ghash h_BE (append quads (create 1 length_quad));
compute_iv_BE_reveal ();
()
let gcm_encrypt_BE_fst_helper (iv:supported_iv_BE) (iv_enc iv_BE:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma
(requires
is_aes_key_word alg key /\
length plain < pow2_32 /\
length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
iv_enc == inc32 (compute_iv_BE h_BE iv) 1 /\
cipher == gctr_encrypt iv_enc plain alg key
))
(ensures cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth))
=
gcm_encrypt_BE_reveal ()
let gcm_encrypt_BE_snd_helper (iv:supported_iv_BE) (j0_BE length_quad32 hash mac:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma
(requires
is_aes_key_word alg key /\
length plain < pow2_32 /\
length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth) /\
length_quad32 == two_two_to_four (Mktwo (nat_to_two 32 (8 * length auth)) (nat_to_two 32 (8 * length plain))) /\
(let auth_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits auth) in
let cipher_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits cipher) in
hash == ghash_BE h_BE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\
be_quad32_to_bytes mac == gctr_encrypt j0_BE (be_quad32_to_bytes hash) alg key)
))
(ensures be_quad32_to_bytes mac == snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth))
=
gcm_encrypt_BE_reveal ()
#reset-options "--z3rlimit 10"
let gcm_blocks_helper_enc (alg:algorithm) (key:seq nat32)
(p128 p_bytes c128 c_bytes:seq quad32)
(auth_bytes:seq nat8)
(p_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
(length auth_bytes) < pow2_32 /\
is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\
(let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2
)))
(ensures (let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
//cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key))
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes)))
=
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
gctr_partial_opaque_completed alg plain cipher key ctr_BE_2;
if p_num_bytes > length p128 * 16 then (
gctr_partial_reveal ();
assert (gctr_partial alg (length p128) plain cipher key ctr_BE_2);
assert (equal (slice plain 0 (length p128))
(slice p128 0 (length p128)));
assert (equal (slice cipher 0 (length p128))
(slice c128 0 (length p128)));
gctr_partial_opaque_ignores_postfix
alg (length p128)
plain p128
cipher c128
key ctr_BE_2;
assert (gctr_partial alg (length p128) p128 c128 key ctr_BE_2);
gctr_partial_opaque_completed alg p128 c128 key ctr_BE_2;
let num_blocks = p_num_bytes / 16 in
assert(index cipher num_blocks == quad32_xor (index plain num_blocks) (aes_encrypt_word alg key (inc32 ctr_BE_2 num_blocks)));
gctr_encrypt_block_offset ctr_BE_2 (index plain num_blocks) alg key num_blocks;
assert( gctr_encrypt_block ctr_BE_2 (index plain num_blocks) alg key num_blocks ==
gctr_encrypt_block (inc32 ctr_BE_2 num_blocks) (index plain num_blocks) alg key 0);
aes_encrypt_word_reveal ();
gctr_partial_to_full_advanced ctr_BE_2 plain cipher alg key p_num_bytes;
assert (cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key)
) else (
gctr_partial_to_full_basic ctr_BE_2 plain alg key cipher;
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher) == gctr_encrypt ctr_BE_2 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) alg key);
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
assert (equal plain_bytes (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)));
assert (equal cipher_bytes (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)));
assert (cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key)
);
gcm_encrypt_BE_fst_helper iv ctr_BE_2 j0_BE plain_bytes auth_bytes cipher_bytes alg key;
()
let slice_append_back (#a:Type) (x y:seq a) (i:nat) : Lemma
(requires length x <= i /\ i <= length x + length y)
(ensures slice (append x y) 0 i == append x (slice y 0 (i - length x)))
=
assert (equal (slice (append x y) 0 i) (append x (slice y 0 (i - length x))));
()
let append_distributes_be_seq_quad32_to_bytes (x y:seq quad32) :
Lemma (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append x y)) == append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE x)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE y)))
=
append_distributes_be_seq_quad32_to_bytes x y
let pad_to_128_bits_multiple_append (x y:seq nat8) : Lemma
(requires length x % 16 == 0)
(ensures pad_to_128_bits (append x y) == append x (pad_to_128_bits y))
=
assert (equal (pad_to_128_bits (append x y)) (append x (pad_to_128_bits y))) | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.GHash_BE_s.fst.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.GCM_BE_s.fst.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_BE.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
alg: Vale.AES.AES_common_s.algorithm ->
key: FStar.Seq.Base.seq Vale.Def.Words_s.nat32 ->
a128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
a_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
p128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
p_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
c128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
c_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
p_num_bytes: Prims.nat ->
a_num_bytes: Prims.nat ->
iv: Vale.AES.GCM_BE_s.supported_iv_BE ->
j0_BE: Vale.Def.Types_s.quad32 ->
h: Vale.Def.Types_s.quad32 ->
enc_hash: Vale.Def.Types_s.quad32 ->
length_quad: Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(requires
FStar.Seq.Base.length p128 * 16 <= p_num_bytes /\
p_num_bytes < FStar.Seq.Base.length p128 * 16 + 16 /\
FStar.Seq.Base.length a128 * 16 <= a_num_bytes /\
a_num_bytes < FStar.Seq.Base.length a128 * 16 + 16 /\ a_num_bytes < Vale.Def.Words_s.pow2_32 /\
FStar.Seq.Base.length p128 == FStar.Seq.Base.length c128 /\
FStar.Seq.Base.length p_bytes == 1 /\ FStar.Seq.Base.length c_bytes == 1 /\
FStar.Seq.Base.length a_bytes == 1 /\ Vale.AES.AES_BE_s.is_aes_key_word alg key /\
j0_BE = Vale.AES.GCM_BE_s.compute_iv_BE h iv /\
h = Vale.AES.AES_BE_s.aes_encrypt_word alg key (Vale.Def.Words_s.Mkfour 0 0 0 0) /\
p_num_bytes < Vale.Def.Words_s.pow2_32 /\ a_num_bytes < Vale.Def.Words_s.pow2_32 /\
length_quad ==
Vale.Def.Words.Four_s.two_two_to_four (Vale.Def.Words_s.Mktwo
(Vale.Def.Words.Two_s.nat_to_two 32 (8 * a_num_bytes))
(Vale.Def.Words.Two_s.nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1 = j0_BE in
let ctr_BE_2 = Vale.AES.GCTR_BE_s.inc32 j0_BE 1 in
let plain =
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true -> FStar.Seq.Base.append p128 p_bytes
| _ -> p128)
<:
FStar.Seq.Base.seq Vale.Def.Types_s.quad32
in
let cipher =
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true -> FStar.Seq.Base.append c128 c_bytes
| _ -> c128)
<:
FStar.Seq.Base.seq Vale.Def.Types_s.quad32
in
let cipher_bound =
FStar.Seq.Base.length p128 +
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true -> 1
| _ -> 0)
in
Vale.AES.GCTR_BE.gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
(match a_num_bytes > FStar.Seq.Base.length a128 * 16 with
| true -> FStar.Seq.Base.append a128 a_bytes
| _ -> a128)
<:
FStar.Seq.Base.seq (Vale.Def.Words_s.four Vale.Def.Words_s.nat32)
in
let auth_input_bytes =
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
auth_raw_quads))
0
a_num_bytes
in
let auth_padded_bytes = Vale.AES.GCTR_BE_s.pad_to_128_bits auth_input_bytes in
let auth_quads = Vale.Def.Types_s.be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = FStar.Seq.Base.append auth_quads c128 in
let total_bytes = FStar.Seq.Base.length auth_quads * 16 + p_num_bytes in
let raw_quads =
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true ->
let raw_quads = FStar.Seq.Base.append raw_quads c_bytes in
let input_bytes =
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
raw_quads))
0
total_bytes
in
let input_padded_bytes = Vale.AES.GCTR_BE_s.pad_to_128_bits input_bytes in
Vale.Def.Types_s.be_bytes_to_seq_quad32 input_padded_bytes
| _ -> raw_quads)
<:
FStar.Seq.Base.seq Vale.Def.Types_s.quad32
in
let final_quads =
FStar.Seq.Base.append raw_quads (FStar.Seq.Base.create 1 length_quad)
in
enc_hash ==
Vale.AES.GCTR_BE_s.gctr_encrypt_block ctr_BE_1
(Vale.AES.GHash_BE_s.ghash_BE h final_quads)
alg
key
0)))
(ensures
(let auth_raw_quads =
(match a_num_bytes > FStar.Seq.Base.length a128 * 16 with
| true -> FStar.Seq.Base.append a128 a_bytes
| _ -> a128)
<:
FStar.Seq.Base.seq (Vale.Def.Words_s.four Vale.Def.Words_s.nat32)
in
let auth_bytes =
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
auth_raw_quads))
0
a_num_bytes
in
let plain_raw_quads =
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true -> FStar.Seq.Base.append p128 p_bytes
| _ -> p128)
<:
FStar.Seq.Base.seq (Vale.Def.Words_s.four Vale.Def.Words_s.nat32)
in
let plain_bytes =
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
plain_raw_quads))
0
p_num_bytes
in
let cipher =
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true -> FStar.Seq.Base.append c128 c_bytes
| _ -> c128)
<:
FStar.Seq.Base.seq Vale.Def.Types_s.quad32
in
let cipher_bytes =
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
cipher))
0
p_num_bytes
in
FStar.Seq.Base.length auth_bytes < Vale.Def.Words_s.pow2_32 /\
FStar.Seq.Base.length plain_bytes < Vale.Def.Words_s.pow2_32 /\
cipher_bytes ==
FStar.Pervasives.Native.fst (Vale.AES.GCM_BE_s.gcm_encrypt_BE alg
(Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE key)
iv
plain_bytes
auth_bytes) /\
Vale.Arch.Types.be_quad32_to_bytes enc_hash ==
FStar.Pervasives.Native.snd (Vale.AES.GCM_BE_s.gcm_encrypt_BE alg
(Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE key)
iv
plain_bytes
auth_bytes))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.AES.AES_common_s.algorithm",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat32",
"Vale.Def.Types_s.quad32",
"Prims.nat",
"Vale.AES.GCM_BE_s.supported_iv_BE",
"Prims.unit",
"Prims.op_GreaterThan",
"FStar.Mul.op_Star",
"FStar.Seq.Base.length",
"Vale.AES.GCM_BE.gcm_encrypt_BE_snd_helper",
"FStar.Calc.calc_finish",
"Prims.eq2",
"FStar.Seq.Base.append",
"FStar.Seq.Base.create",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"Vale.Def.Types_s.be_bytes_to_seq_quad32",
"Vale.AES.GCTR_BE_s.pad_to_128_bits",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.append_assoc",
"Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE",
"Vale.Def.Words.Seq_s.seq_four_to_seq_BE",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words_s.nat8",
"FStar.Seq.Base.slice",
"Vale.Def.Types_s.nat8",
"Vale.AES.GCM_BE.append_distributes_be_seq_quad32_to_bytes",
"Vale.AES.GCM_BE.slice_append_back",
"Vale.AES.GCM_BE.pad_to_128_bits_multiple_append",
"Vale.Arch.Types.append_distributes_be_bytes_to_seq_quad32",
"Vale.Arch.Types.be_bytes_to_seq_quad32_to_bytes",
"Prims.b2t",
"Prims.op_Equality",
"Prims.bool",
"Vale.AES.GCTR_BE_s.gctr_encrypt",
"Vale.Arch.Types.be_quad32_to_bytes",
"Vale.Def.Words_s.four",
"Vale.Def.Types_s.quad32_xor",
"Vale.AES.AES_BE_s.aes_encrypt_word",
"Vale.AES.GCTR_BE.gctr_encrypt_one_block",
"Vale.Arch.Types.be_seq_quad32_to_bytes_of_singleton",
"Vale.AES.GCTR_BE_s.gctr_encrypt_block",
"Vale.AES.GHash_BE_s.ghash_BE",
"Vale.AES.GCM_BE.gcm_blocks_helper_enc",
"Prims.int",
"Prims.op_Addition",
"Vale.AES.GCTR_BE_s.inc32",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Vale.Def.Words_s.pow2_32",
"Vale.AES.AES_BE_s.is_aes_key_word",
"Vale.AES.GCM_BE_s.compute_iv_BE",
"Vale.Def.Words_s.Mkfour",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Def.Words.Four_s.two_two_to_four",
"Vale.Def.Words_s.Mktwo",
"Vale.Def.Words_s.two",
"Vale.Def.Words.Two_s.nat_to_two",
"Vale.AES.GCTR_BE.gctr_partial",
"FStar.Pervasives.Native.fst",
"Vale.AES.GCM_BE_s.gcm_encrypt_BE",
"FStar.Pervasives.Native.snd",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let gcm_blocks_helper
(alg: algorithm)
(key: seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes: seq quad32)
(p_num_bytes a_num_bytes: nat)
(iv: supported_iv_BE)
(j0_BE h enc_hash length_quad: quad32)
: Lemma
(requires
length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\ length p128 == length c128 /\ length p_bytes == 1 /\
length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_word alg key /\
j0_BE = compute_iv_BE h iv /\ h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad ==
two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then append c128 c_bytes else c128
in
let cipher_bound:nat = length p128 + (if p_num_bytes > length p128 * 16 then 1 else 0) in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes
in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16
then
let raw_quads = append raw_quads c_bytes in
let input_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes
in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0)))
(ensures
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes
in
let plain_raw_quads =
if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128
in
let plain_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then append c128 c_bytes else c128
in
let cipher_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes
in
length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\
cipher_bytes ==
fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes) /\
be_quad32_to_bytes enc_hash ==
snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes))) =
| let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 = if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128 in
let cipher:seq quad32 = if p_num_bytes > length p128 * 16 then append c128 c_bytes else c128 in
let cipher_bound:nat = length p128 + (if p_num_bytes > length p128 * 16 then 1 else 0) in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in
let auth_input_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes
in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16
then
let raw_quads = append raw_quads c_bytes in
let input_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes
in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
let hash = ghash_BE h final_quads in
gcm_blocks_helper_enc alg key p128 p_bytes c128 c_bytes auth_input_bytes p_num_bytes iv j0_BE;
calc ( == ) {
enc_hash;
( == ) { () }
gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0;
( == ) { () }
gctr_encrypt_block ctr_BE_1 hash alg key 0;
( == ) { () }
quad32_xor hash (aes_encrypt_word alg key ctr_BE_1);
};
calc ( == ) {
gctr_encrypt ctr_BE_1 (be_quad32_to_bytes hash) alg key;
( == ) { gctr_encrypt_one_block ctr_BE_1 hash alg key }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1
(quad32_xor hash (aes_encrypt_word alg key ctr_BE_1))));
( == ) { () }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 enc_hash));
( == ) { be_seq_quad32_to_bytes_of_singleton enc_hash }
be_quad32_to_bytes enc_hash;
};
if p_num_bytes > length p128 * 16
then
(let c = append c128 c_bytes in
calc ( == ) {
append (append auth_quads c128) c_bytes;
( == ) { append_assoc auth_quads c128 c_bytes }
append auth_quads (append c128 c_bytes);
( == ) { () }
append auth_quads c;
};
calc ( == ) {
append (append (append auth_quads c128) c_bytes) (create 1 length_quad);
( = ) { () }
append (append auth_quads (append c128 c_bytes)) (create 1 length_quad);
( == ) { append_assoc auth_quads c (create 1 length_quad) }
append auth_quads (append c (create 1 length_quad));
};
let raw_quads_old = append auth_quads c in
calc ( == ) {
raw_quads;
( == ) { () }
be_bytes_to_seq_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old
))
0
total_bytes));
( == ) { calc ( == ) {
pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old))
0
total_bytes);
( == ) { calc ( == ) {
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes;
( == ) { append_distributes_be_seq_quad32_to_bytes auth_quads c }
slice (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)))
0
total_bytes;
( == ) { slice_append_back (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))
total_bytes }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes);
( == ) { () }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) cipher_bytes;
} }
pad_to_128_bits (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
cipher_bytes);
( == ) { pad_to_128_bits_multiple_append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads
))
cipher_bytes }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(pad_to_128_bits cipher_bytes);
} }
be_bytes_to_seq_quad32 (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(pad_to_128_bits cipher_bytes));
( == ) { append_distributes_be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE
auth_quads))
(pad_to_128_bits cipher_bytes) }
append (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)))
(be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes));
( == ) { be_bytes_to_seq_quad32_to_bytes auth_quads }
append auth_quads (be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes));
};
let auth_padded_quads' = be_bytes_to_seq_quad32 (pad_to_128_bits auth_input_bytes) in
let cipher_padded_quads' = be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes) in
calc ( == ) {
append raw_quads (create 1 length_quad);
( == ) { () }
append (append auth_quads (be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes)))
(create 1 length_quad);
( == ) { assert (equal auth_quads auth_padded_quads') }
append (append auth_padded_quads' cipher_padded_quads') (create 1 length_quad);
( == ) { append_assoc auth_padded_quads' cipher_padded_quads' (create 1 length_quad) }
append auth_padded_quads' (append cipher_padded_quads' (create 1 length_quad));
};
gcm_encrypt_BE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes
cipher_bytes alg key;
())
else
(calc ( == ) {
append (append auth_quads c128) (create 1 length_quad);
( == ) { append_assoc auth_quads c128 (create 1 length_quad) }
append auth_quads (append c128 (create 1 length_quad));
};
let c = c128 in
calc ( == ) {
be_bytes_to_seq_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c
))
0
p_num_bytes));
( == ) { assert (equal (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))
(slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes)) }
be_bytes_to_seq_quad32 (pad_to_128_bits (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)));
( == ) { assert (pad_to_128_bits (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) ==
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))) }
be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c));
( == ) { be_bytes_to_seq_quad32_to_bytes c }
c;
};
gcm_encrypt_BE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes
cipher_bytes alg key;
());
() | false |
Hacl.Impl.Ed25519.Group.fst | Hacl.Impl.Ed25519.Group.a_spec | val a_spec : Type0 | let a_spec = S.aff_point_c | {
"file_name": "code/ed25519/Hacl.Impl.Ed25519.Group.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 21,
"start_col": 0,
"start_line": 21
} | module Hacl.Impl.Ed25519.Group
module ST = FStar.HyperStack.ST
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum25519
open Hacl.Impl.Ed25519.PointConstants
module LSeq = Lib.Sequence
module F51 = Hacl.Impl.Ed25519.Field51
module BE = Hacl.Impl.Exponentiation.Definitions
module S = Spec.Ed25519
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0" | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.Lemmas.fsti.checked",
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Exponentiation.Definitions.fst.checked",
"Hacl.Impl.Ed25519.PointDouble.fst.checked",
"Hacl.Impl.Ed25519.PointConstants.fst.checked",
"Hacl.Impl.Ed25519.PointAdd.fst.checked",
"Hacl.Impl.Ed25519.Field51.fst.checked",
"Hacl.Bignum25519.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Ed25519.Group.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Field51",
"short_module": "F51"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519.PointConstants",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | Type0 | Prims.Tot | [
"total"
] | [] | [
"Spec.Ed25519.aff_point_c"
] | [] | false | false | false | true | true | let a_spec =
| S.aff_point_c | false |
|
Hacl.Impl.Blake2.Generic.fst | Hacl.Impl.Blake2.Generic.blake2_round | val blake2_round : #al:Spec.alg -> #ms:m_spec -> wv:state_p al ms -> m:block_w al -> i:size_t ->
Stack unit
(requires (fun h -> live h wv /\ live h m /\ disjoint wv m))
(ensures (fun h0 _ h1 -> modifies (loc wv) h0 h1
/\ state_v h1 wv == Spec.blake2_round al (as_seq h0 m) (v i) (state_v h0 wv))) | val blake2_round : #al:Spec.alg -> #ms:m_spec -> wv:state_p al ms -> m:block_w al -> i:size_t ->
Stack unit
(requires (fun h -> live h wv /\ live h m /\ disjoint wv m))
(ensures (fun h0 _ h1 -> modifies (loc wv) h0 h1
/\ state_v h1 wv == Spec.blake2_round al (as_seq h0 m) (v i) (state_v h0 wv))) | let blake2_round #al #ms wv m i =
push_frame();
let start_idx = (i %. size 10) *. size 16 in
assert (v start_idx == (v i % 10) * 16);
assert (v start_idx <= 144);
let m_st = alloc_state al ms in
gather_state m_st m start_idx;
let x = rowi m_st 0ul in
let y = rowi m_st 1ul in
let z = rowi m_st 2ul in
let w = rowi m_st 3ul in
let h1 = ST.get() in
assert (disjoint wv m_st);
assert (disjoint m_st wv);
assert (disjoint x wv);
assert (disjoint wv x);
assert (disjoint y wv);
assert (disjoint wv y);
assert (disjoint z wv);
assert (disjoint wv z);
assert (disjoint w wv);
assert (disjoint wv w);
blake2_mixing wv x y;
diag wv;
blake2_mixing wv z w;
undiag wv;
pop_frame () | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 14,
"end_line": 304,
"start_col": 0,
"start_line": 278
} | module Hacl.Impl.Blake2.Generic
open FStar.Mul
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Lib.LoopCombinators
module ST = FStar.HyperStack.ST
module Seq = Lib.Sequence
module Loops = Lib.LoopCombinators
module Spec = Spec.Blake2
open Hacl.Impl.Blake2.Constants
open Hacl.Impl.Blake2.Core
#set-options "--z3rlimit 50 --max_ifuel 0 --max_fuel 0"
noextract
let is_valid_blake2_config (a : Spec.alg) (m : m_spec) =
match a, m with
| Spec.Blake2S, M32 | Spec.Blake2S, M128
| Spec.Blake2B, M32 | Spec.Blake2B, M256 -> true
| _ -> false
inline_for_extraction noextract
let valid_m_spec (a : Spec.alg) = m:m_spec{is_valid_blake2_config a m}
/// Accessors for constants
inline_for_extraction noextract
val get_iv:
a:Spec.alg
-> s: size_t{size_v s < 8} ->
Stack (word_t a)
(requires (fun h -> True))
(ensures (fun h0 z h1 -> h0 == h1 /\
v z == v (Seq.index (Spec.ivTable a) (v s))))
let get_iv a s =
recall_contents #(Spec.pub_word_t Spec.Blake2S) #8ul ivTable_S (Spec.ivTable Spec.Blake2S);
recall_contents #(Spec.pub_word_t Spec.Blake2B) #8ul ivTable_B (Spec.ivTable Spec.Blake2B);
[@inline_let]
let ivTable: (x:glbuffer (Spec.pub_word_t a) 8ul{witnessed x (Spec.ivTable a) /\ recallable x}) =
match a with
| Spec.Blake2S -> ivTable_S
| Spec.Blake2B -> ivTable_B
in
let r = index ivTable s in
secret #(Spec.wt a) r
inline_for_extraction noextract
val get_sigma:
s: size_t{v s < 160} ->
Stack Spec.sigma_elt_t
(requires (fun h -> True))
(ensures (fun h0 z h1 -> h0 == h1 /\ z == Lib.Sequence.(Spec.sigmaTable.[v s])))
let get_sigma s =
recall_contents sigmaTable Spec.sigmaTable;
index sigmaTable s
inline_for_extraction noextract
val get_sigma_sub:
start: size_t ->
i: size_t{v i < 16 /\ v start + v i < 160} ->
Stack Spec.sigma_elt_t
(requires (fun h -> True))
(ensures (fun h0 z h1 -> h0 == h1 /\ v z == v (Seq.index Spec.sigmaTable (v start + v i))))
let get_sigma_sub start i = get_sigma (start +. i)
inline_for_extraction noextract
let rounds_t (a:Spec.alg): size_t = size (Spec.rounds a)
inline_for_extraction noextract
val size_to_word: al:Spec.alg -> s:size_t -> u:word_t al{u == Spec.nat_to_word al (v s)}
let size_to_word al s = match al with
| Spec.Blake2S -> size_to_uint32 s
| Spec.Blake2B -> size_to_uint64 s
inline_for_extraction noextract
val size_to_limb: al:Spec.alg -> s:size_t -> u:Spec.limb_t al{u == Spec.nat_to_limb al (v s)}
let size_to_limb al s = match al with
| Spec.Blake2S -> size_to_uint64 s
| Spec.Blake2B -> to_u128 (size_to_uint64 s)
/// Constants
/// Define algorithm functions
inline_for_extraction noextract
val g1: #al:Spec.alg -> #m:m_spec -> wv:state_p al m -> a:index_t -> b:index_t -> r:rotval (Spec.wt al) ->
Stack unit
(requires (fun h -> live h wv /\ a <> b))
(ensures (fun h0 _ h1 -> modifies (loc wv) h0 h1
/\ (state_v h1 wv) == Spec.g1 al (state_v h0 wv) (v a) (v b) r))
let g1 #al #m wv a b r =
let h0 = ST.get() in
let wv_a = rowi wv a in
let wv_b = rowi wv b in
xor_row wv_a wv_b;
ror_row wv_a r;
let h2 = ST.get() in
Lib.Sequence.eq_intro (state_v h2 wv) (Spec.g1 al (state_v h0 wv) (v a) (v b) r)
#push-options "--z3rlimit 100 --max_fuel 1 --max_ifuel 1"
inline_for_extraction noextract
val g2: #al:Spec.alg -> #m:m_spec -> wv:state_p al m -> a:index_t -> b:index_t -> x:row_p al m ->
Stack unit
(requires (fun h -> live h wv /\ live h x /\ disjoint wv x /\ a <> b))
(ensures (fun h0 _ h1 -> modifies (loc wv) h0 h1
/\ state_v h1 wv == Spec.g2 al (state_v h0 wv) (v a) (v b) (row_v h0 x)))
let g2 #al #m wv a b x =
let h0 = ST.get() in
let wv_a = rowi wv a in
let wv_b = rowi wv b in
add_row wv_a wv_b;
add_row wv_a x;
let h1 = ST.get() in
Lib.Sequence.eq_intro (state_v h1 wv) (Spec.g2 al (state_v h0 wv) (v a) (v b) (row_v h0 x))
#push-options "--z3rlimit 100 --max_fuel 1 --max_ifuel 1"
inline_for_extraction noextract
val g2z: #al:Spec.alg -> #m:m_spec -> wv:state_p al m -> a:index_t -> b:index_t ->
Stack unit
(requires (fun h -> live h wv /\ a <> b))
(ensures (fun h0 _ h1 -> modifies (loc wv) h0 h1
/\ state_v h1 wv == Spec.g2z al (state_v h0 wv) (v a) (v b)))
let g2z #al #m wv a b =
let h0 = ST.get() in
let wv_a = rowi wv a in
let wv_b = rowi wv b in
add_row wv_a wv_b;
let h1 = ST.get() in
Lib.Sequence.eq_intro (state_v h1 wv) (Spec.g2z al (state_v h0 wv) (v a) (v b))
inline_for_extraction noextract
val blake2_mixing : #al:Spec.alg -> #m:m_spec -> wv:state_p al m -> x:row_p al m -> y:row_p al m ->
Stack unit
(requires (fun h -> live h wv /\ live h x /\ live h y /\ disjoint wv x /\ disjoint wv y))
(ensures (fun h0 _ h1 -> modifies (loc wv) h0 h1
/\ state_v h1 wv == Spec.blake2_mixing al (state_v h0 wv) (row_v h0 x) (row_v h0 y)))
let blake2_mixing #al #m wv x y =
let h0 = ST.get() in
push_frame ();
let a = 0ul in
let b = 1ul in
let c = 2ul in
let d = 3ul in
[@inline_let]
let r0 = normalize_term (Lib.Sequence.index (Spec.rTable al) 0) in
normalize_term_spec (Lib.Sequence.index (Spec.rTable al) 0);
[@inline_let]
let r1 = normalize_term (Lib.Sequence.index (Spec.rTable al) 1) in
normalize_term_spec (Lib.Sequence.index (Spec.rTable al) 1);
[@inline_let]
let r2 = normalize_term (Lib.Sequence.index (Spec.rTable al) 2) in
normalize_term_spec (Lib.Sequence.index (Spec.rTable al) 2);
[@inline_let]
let r3 = normalize_term (Lib.Sequence.index (Spec.rTable al) 3) in
normalize_term_spec (Lib.Sequence.index (Spec.rTable al) 3);
let h1 = ST.get() in
g2 wv a b x;
g1 wv d a r0;
g2z wv c d;
g1 wv b c r1;
g2 wv a b y;
g1 wv d a r2;
g2z wv c d;
g1 wv b c r3;
let h2 = ST.get() in
pop_frame ();
let h3 = ST.get() in
assert(modifies (loc wv) h0 h3);
Lib.Sequence.eq_intro (state_v h2 wv) (Spec.blake2_mixing al (state_v h1 wv) (row_v h1 x) (row_v h1 y))
#pop-options
inline_for_extraction noextract
val diag: #a:Spec.alg -> #m:m_spec -> wv:state_p a m
-> Stack unit
(requires (fun h -> live h wv))
(ensures (fun h0 _ h1 -> modifies (loc wv) h0 h1 /\
state_v h1 wv == Spec.diag (state_v h0 wv)))
let diag #a #m wv =
let r1 = rowi wv 1ul in
let r2 = rowi wv 2ul in
let r3 = rowi wv 3ul in
let h0 = ST.get() in
permr_row r1 1ul;
permr_row r2 2ul;
permr_row r3 3ul
inline_for_extraction noextract
val undiag: #a:Spec.alg -> #m:m_spec -> wv:state_p a m
-> Stack unit
(requires (fun h -> live h wv))
(ensures (fun h0 _ h1 -> modifies (loc wv) h0 h1 /\
state_v h1 wv == Spec.undiag (state_v h0 wv)))
let undiag #a #m wv =
let r1 = rowi wv 1ul in
let r2 = rowi wv 2ul in
let r3 = rowi wv 3ul in
let h0 = ST.get() in
permr_row r1 3ul;
permr_row r2 2ul;
permr_row r3 1ul
inline_for_extraction noextract
val gather_state: #a:Spec.alg -> #ms:m_spec -> st:state_p a ms -> m:block_w a -> start:size_t{v start <= 144} -> Stack unit
(requires (fun h -> live h st /\ live h m /\ disjoint st m))
(ensures (fun h0 _ h1 -> modifies (loc st) h0 h1 /\
state_v h1 st == Spec.gather_state a (as_seq h0 m) (v start)))
inline_for_extraction noextract
let get_sigma' (start: size_t { v start <= 144 }) (i: size_t { normalize (i <=. 15ul) }):
Stack Spec.sigma_elt_t
(requires (fun h -> True))
(ensures (fun h0 z h1 ->
h0 == h1 /\ z == Lib.Sequence.(Spec.sigmaTable.[v start + v i])))
=
get_sigma (start +! i)
#push-options "--z3rlimit 500"
let gather_state #a #ms st m start =
let h0 = ST.get() in
let r0 = rowi st 0ul in
let r1 = rowi st 1ul in
let r2 = rowi st 2ul in
let r3 = rowi st 3ul in
let s0 = get_sigma' start 0ul in
let s1 = get_sigma' start 1ul in
let s2 = get_sigma' start 2ul in
let s3 = get_sigma' start 3ul in
let s4 = get_sigma' start 4ul in
let s5 = get_sigma' start 5ul in
let s6 = get_sigma' start 6ul in
let s7 = get_sigma' start 7ul in
let s8 = get_sigma' start 8ul in
let s9 = get_sigma' start 9ul in
let s10 = get_sigma' start 10ul in
let s11 = get_sigma' start 11ul in
let s12 = get_sigma' start 12ul in
let s13 = get_sigma' start 13ul in
let s14 = get_sigma' start 14ul in
let s15 = get_sigma' start 15ul in
let h1 = ST.get() in
gather_row r0 m s0 s2 s4 s6;
let h2 = ST.get() in
gather_row r1 m s1 s3 s5 s7;
let h3 = ST.get() in
gather_row r2 m s8 s10 s12 s14;
let h4 = ST.get() in
gather_row r3 m s9 s11 s13 s15;
let h5 = ST.get() in
assert(modifies (loc st) h0 h5);
Lib.Sequence.eq_intro (state_v h5 st) (Spec.gather_state a (as_seq h0 m) (v start))
inline_for_extraction noextract
val blake2_round : #al:Spec.alg -> #ms:m_spec -> wv:state_p al ms -> m:block_w al -> i:size_t ->
Stack unit
(requires (fun h -> live h wv /\ live h m /\ disjoint wv m))
(ensures (fun h0 _ h1 -> modifies (loc wv) h0 h1
/\ state_v h1 wv == Spec.blake2_round al (as_seq h0 m) (v i) (state_v h0 wv))) | {
"checked_file": "/",
"dependencies": [
"Spec.Blake2.fst.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"Hacl.Impl.Blake2.Constants.fst.checked",
"FStar.UInt32.fsti.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",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Blake2.Constants",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Blake2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Blake2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Blake2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 500,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
wv: Hacl.Impl.Blake2.Core.state_p al ms ->
m: Hacl.Impl.Blake2.Core.block_w al ->
i: Lib.IntTypes.size_t
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Spec.Blake2.Definitions.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Hacl.Impl.Blake2.Core.state_p",
"Hacl.Impl.Blake2.Core.block_w",
"Lib.IntTypes.size_t",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Hacl.Impl.Blake2.Generic.undiag",
"Hacl.Impl.Blake2.Generic.blake2_mixing",
"Hacl.Impl.Blake2.Generic.diag",
"Prims._assert",
"Lib.Buffer.disjoint",
"Lib.Buffer.MUT",
"Hacl.Impl.Blake2.Core.element_t",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Lib.Buffer.lbuffer_t",
"Hacl.Impl.Blake2.Core.row_len",
"Hacl.Impl.Blake2.Core.rowi",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.Blake2.Core.row_p",
"Hacl.Impl.Blake2.Generic.gather_state",
"Lib.IntTypes.mul_mod",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Hacl.Impl.Blake2.Core.alloc_state",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.v",
"Prims.eq2",
"Prims.int",
"FStar.Mul.op_Star",
"Prims.op_Modulus",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Star_Dot",
"Lib.IntTypes.op_Percent_Dot",
"Lib.IntTypes.size",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let blake2_round #al #ms wv m i =
| push_frame ();
let start_idx = (i %. size 10) *. size 16 in
assert (v start_idx == (v i % 10) * 16);
assert (v start_idx <= 144);
let m_st = alloc_state al ms in
gather_state m_st m start_idx;
let x = rowi m_st 0ul in
let y = rowi m_st 1ul in
let z = rowi m_st 2ul in
let w = rowi m_st 3ul in
let h1 = ST.get () in
assert (disjoint wv m_st);
assert (disjoint m_st wv);
assert (disjoint x wv);
assert (disjoint wv x);
assert (disjoint y wv);
assert (disjoint wv y);
assert (disjoint z wv);
assert (disjoint wv z);
assert (disjoint w wv);
assert (disjoint wv w);
blake2_mixing wv x y;
diag wv;
blake2_mixing wv z w;
undiag wv;
pop_frame () | false |
Hacl.HMAC_DRBG.fst | Hacl.HMAC_DRBG.mk_generate | val mk_generate: #a:supported_alg -> HMAC.compute_st a -> generate_st a | val mk_generate: #a:supported_alg -> HMAC.compute_st a -> generate_st a | let mk_generate #a hmac output st n additional_input_len additional_input =
if st.reseed_counter.(0ul) >. reseed_interval then
false
else
begin
S.hmac_input_bound a;
Math.Lemmas.lemma_div_mod (v n) (hash_length a);
let State k v ctr = st in
if additional_input_len >. 0ul then
update hmac additional_input_len additional_input k v;
let output:lbuffer uint8 n = output in
let max = n /. hash_len a in
let out = sub output 0ul (max *! hash_len a) in
[@inline_let]
let a_spec = S.a_spec a in
[@inline_let]
let refl h i = as_seq h v in
[@inline_let]
let spec h0 = S.generate_loop a (as_seq h0 k) (uint_v max) in
let h0 = ST.get () in
fill_blocks h0 (hash_len a) max out a_spec refl (fun i -> loc v) spec
(fun i ->
LSeq.unfold_generate_blocks
(hash_length a) (uint_v max) a_spec (spec h0) (as_seq h0 v) (uint_v i);
hmac v k (hash_len a) v (hash_len a);
copy (sub out (i *! hash_len a) (hash_len a)) v
);
if max *! hash_len a <. n then
begin
let h1 = ST.get () in
let block = sub output (max *! hash_len a) (n -! (max *! hash_len a)) in
hmac v k (hash_len a) v (hash_len a);
copy block (sub v 0ul (n -! (max *! hash_len a)));
let h2 = ST.get () in
LSeq.eq_intro (as_seq h2 output)
(as_seq h1 out `LSeq.op_At_Bar` as_seq h2 block)
end;
update hmac additional_input_len additional_input k v;
let old_ctr = ctr.(0ul) in
ctr.(0ul) <- old_ctr +! 1ul;
true
end | {
"file_name": "code/drbg/Hacl.HMAC_DRBG.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 7,
"end_line": 302,
"start_col": 0,
"start_line": 261
} | module Hacl.HMAC_DRBG
open FStar.HyperStack.ST
module ST = FStar.HyperStack.ST
open Spec.Hash.Definitions
open Lib.IntTypes
open Lib.Buffer
module HS = FStar.HyperStack
module B = LowStar.Buffer
module LSeq = Lib.Sequence
module HMAC = Hacl.HMAC
module S = Spec.HMAC_DRBG
friend Spec.HMAC_DRBG
unfold
let hash_len (a:supported_alg) = Hacl.Hash.Definitions.hash_len a
#set-options "--fuel 0 --ifuel 0 --z3rlimit 50"
inline_for_extraction noextract
val update_round: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> n:uint8
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 v /\ live h0 data /\
disjoint k v /\
// HMAC input length must fit in size_t
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
as_seq h1 k == Spec.Agile.HMAC.hmac a
(as_seq h0 k)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))) /\
as_seq h1 v == Spec.Agile.HMAC.hmac a (as_seq h1 k) (as_seq h0 v) /\
modifies2 k v h0 h1)
let update_round #a hmac len data n k v =
let h0 = ST.get() in
push_frame();
let input_len = hash_len a +! 1ul +! len in
let input = create input_len (u8 0) in
let k' = sub input 0ul (hash_len a) in
copy k' v;
if len <> 0ul then copy (sub input (hash_len a +! 1ul) len) data;
input.(hash_len a) <- n;
let h1 = ST.get() in
assert (Seq.equal (as_seq h1 input)
(Seq.append (as_seq h0 v) (Seq.cons n (as_seq h0 data))));
S.hmac_input_bound a;
hmac k' k (hash_len a) input input_len;
hmac v k' (hash_len a) v (hash_len a);
copy k k';
pop_frame()
inline_for_extraction noextract
val update: #a:supported_alg
-> hmac:HMAC.compute_st a
-> len:size_t
-> data:lbuffer uint8 len
-> k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> Stack unit
(requires fun h0 ->
live h0 data /\ live h0 k /\ live h0 v /\
disjoint k v /\ disjoint k data /\ disjoint v data /\
hash_length a + 1 + uint_v len + block_length a < pow2 32)
(ensures fun h0 _ h1 ->
S.hmac_input_bound a;
let k', v' = S.update #a (as_seq h0 data) (as_seq h0 k) (as_seq h0 v) in
modifies2 k v h0 h1 /\
as_seq h1 k == k' /\
as_seq h1 v == v')
let update #a hmac len data k v =
update_round hmac len data (u8 0) k v;
if len <> 0ul then
update_round hmac len data (u8 1) k v
noeq
type state (a:supported_alg) =
| State:
k:lbuffer uint8 (hash_len a)
-> v:lbuffer uint8 (hash_len a)
-> reseed_counter:lbuffer size_t 1ul
{disjoint k v /\ disjoint k reseed_counter /\ disjoint v reseed_counter}
-> state a
let freeable #a st =
let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.freeable k /\ B.freeable v /\ B.freeable ctr
let footprint #a st =
let k:B.buffer uint8 = st.k in
let v:B.buffer uint8 = st.v in
let ctr:B.buffer size_t = st.reseed_counter in
B.loc_addr_of_buffer k |+| B.loc_addr_of_buffer v |+| B.loc_addr_of_buffer ctr
let invariant #a st h =
live h st.k /\ live h st.v /\ live h st.reseed_counter /\ (
// JP: the disjoint predicate from lib hardcodes loc_buffer instead of
// loc_addr_of_buffer, which prevents us from writing a proper free function
// (probably why it wasn't written here in the first place)... we add on top
// of the lib-style predicate a non-lib-style predicate which allows writing
// an actual free function
let k = st.k <: B.buffer uint8 in
let v = st.v <: B.buffer uint8 in
let ctr = st.reseed_counter <: B.buffer size_t in
B.(all_disjoint [ loc_addr_of_buffer k; loc_addr_of_buffer v; loc_addr_of_buffer ctr ]))
let repr #a st h =
S.State (as_seq h st.k) (as_seq h st.v) (v (bget h st.reseed_counter 0))
let alloca a =
let k =
match a with
| SHA1 -> create (hash_len SHA1) (u8 0)
| SHA2_256 -> create (hash_len SHA2_256) (u8 0)
| SHA2_384 -> create (hash_len SHA2_384) (u8 0)
| SHA2_512 -> create (hash_len SHA2_512) (u8 0)
in
let v =
match a with
| SHA1 -> create (hash_len SHA1) (u8 0)
| SHA2_256 -> create (hash_len SHA2_256) (u8 0)
| SHA2_384 -> create (hash_len SHA2_384) (u8 0)
| SHA2_512 -> create (hash_len SHA2_512) (u8 0)
in
let ctr = create 1ul 1ul in
State k v ctr
let create_in a r =
let k:B.buffer uint8 =
match a with
| SHA1 -> B.malloc r (u8 0) (hash_len SHA1)
| SHA2_256 -> B.malloc r (u8 0) (hash_len SHA2_256)
| SHA2_384 -> B.malloc r (u8 0) (hash_len SHA2_384)
| SHA2_512 -> B.malloc r (u8 0) (hash_len SHA2_512)
in
let v:B.buffer uint8 =
match a with
| SHA1 -> B.malloc r (u8 0) (hash_len SHA1)
| SHA2_256 -> B.malloc r (u8 0) (hash_len SHA2_256)
| SHA2_384 -> B.malloc r (u8 0) (hash_len SHA2_384)
| SHA2_512 -> B.malloc r (u8 0) (hash_len SHA2_512)
in
let ctr:B.buffer size_t = B.malloc r 1ul 1ul in
State k v ctr
#push-options "--z3rlimit 200"
let mk_instantiate #a hmac st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
=
let h0 = ST.get () in
push_frame();
let seed_material = create (entropy_input_len +! nonce_len +! personalization_string_len) (u8 0) in
copy (sub seed_material 0ul entropy_input_len) entropy_input;
copy (sub seed_material entropy_input_len nonce_len) nonce;
copy (sub seed_material (entropy_input_len +! nonce_len) personalization_string_len) personalization_string;
let State k v ctr = st in
memset k (u8 0) (hash_len a);
memset v (u8 1) (hash_len a);
let h1 = ST.get () in
assert (Seq.equal (as_seq h1 seed_material)
(Seq.append (as_seq h0 entropy_input) (Seq.append (as_seq h0 nonce)
(as_seq h0 personalization_string))));
assert (LSeq.equal (as_seq h1 k) (LSeq.create (hash_length a) (u8 0)));
assert (LSeq.equal (as_seq h1 v) (LSeq.create (hash_length a) (u8 1)));
ctr.(0ul) <- 1ul;
update hmac (entropy_input_len +! nonce_len +! personalization_string_len)
seed_material k v;
pop_frame()
#pop-options
let instantiate a st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
=
match a with
| SHA1 ->
mk_instantiate Hacl.HMAC.compute_sha1 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
| SHA2_256 ->
mk_instantiate Hacl.HMAC.compute_sha2_256 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
| SHA2_384 ->
mk_instantiate Hacl.HMAC.compute_sha2_384 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
| SHA2_512 ->
mk_instantiate Hacl.HMAC.compute_sha2_512 st
entropy_input_len entropy_input
nonce_len nonce
personalization_string_len personalization_string
let mk_reseed #a hmac st
entropy_input_len entropy_input
additional_input_len additional_input
=
let h0 = ST.get () in
push_frame();
let seed_material = create (entropy_input_len +! additional_input_len) (u8 0) in
copy (sub seed_material 0ul entropy_input_len) entropy_input;
copy (sub seed_material entropy_input_len additional_input_len) additional_input;
let h1 = ST.get () in
LSeq.eq_intro (as_seq h1 seed_material)
LSeq.(as_seq h0 entropy_input @| as_seq h0 additional_input);
let State k v ctr: state a = st in
update hmac (entropy_input_len +! additional_input_len) seed_material k v;
ctr.(0ul) <- 1ul;
pop_frame()
let reseed a st
entropy_input_len entropy_input
additional_input_input_len additional_input_input =
match a with
| SHA1 ->
mk_reseed Hacl.HMAC.compute_sha1 st
entropy_input_len entropy_input
additional_input_input_len additional_input_input
| SHA2_256 ->
mk_reseed Hacl.HMAC.compute_sha2_256 st
entropy_input_len entropy_input
additional_input_input_len additional_input_input
| SHA2_384 ->
mk_reseed Hacl.HMAC.compute_sha2_384 st
entropy_input_len entropy_input
additional_input_input_len additional_input_input
| SHA2_512 ->
mk_reseed Hacl.HMAC.compute_sha2_512 st
entropy_input_len entropy_input
additional_input_input_len additional_input_input
#push-options "--z3rlimit 300" | {
"checked_file": "/",
"dependencies": [
"Spec.HMAC_DRBG.fst.checked",
"Spec.HMAC_DRBG.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HMAC.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.HMAC.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.HMAC_DRBG.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.HMAC_DRBG",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.HMAC",
"short_module": "HMAC"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.HMAC_DRBG",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.HMAC",
"short_module": "HMAC"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | hmac: Hacl.HMAC.compute_st a -> Hacl.HMAC_DRBG.generate_st a | Prims.Tot | [
"total"
] | [] | [
"Hacl.HMAC_DRBG.supported_alg",
"Hacl.HMAC.compute_st",
"Lib.Buffer.buffer",
"Lib.IntTypes.uint8",
"Hacl.HMAC_DRBG.state",
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer",
"Prims.bool",
"Hacl.HMAC_DRBG.hash_len",
"FStar.UInt32.__uint_to_t",
"Prims.l_and",
"Lib.Buffer.disjoint",
"Lib.Buffer.MUT",
"Prims.unit",
"Lib.Buffer.op_Array_Assignment",
"Lib.IntTypes.op_Plus_Bang",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.int_t",
"Lib.Buffer.op_Array_Access",
"Hacl.HMAC_DRBG.update",
"Lib.IntTypes.op_Less_Dot",
"Lib.IntTypes.op_Star_Bang",
"Lib.Sequence.eq_intro",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.IntTypes.v",
"Lib.Buffer.as_seq",
"Lib.Sequence.op_At_Bar",
"Lib.IntTypes.op_Subtraction_Bang",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Lib.Buffer.copy",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.sub",
"Lib.IntTypes.mul",
"Hacl.Hash.Definitions.hash_len",
"Lib.Buffer.sub",
"Lib.Buffer.fill_blocks",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.Buffer.loc",
"LowStar.Monotonic.Buffer.loc",
"LowStar.Monotonic.Buffer.loc_disjoint",
"LowStar.Monotonic.Buffer.loc_includes",
"LowStar.Monotonic.Buffer.address_liveness_insensitive_locs",
"Prims.op_LessThan",
"Lib.Sequence.unfold_generate_blocks",
"Spec.Hash.Definitions.hash_length",
"Lib.IntTypes.uint_v",
"Prims.nat",
"Spec.HMAC_DRBG.a_spec",
"FStar.Pervasives.Native.tuple2",
"Prims.op_Addition",
"Lib.Sequence.lseq",
"Prims.l_True",
"Spec.HMAC_DRBG.generate_loop",
"Prims.op_Subtraction",
"Prims.pow2",
"Lib.IntTypes.op_Slash_Dot",
"Lib.IntTypes.op_Greater_Dot",
"FStar.Math.Lemmas.lemma_div_mod",
"Spec.HMAC_DRBG.hmac_input_bound",
"Hacl.HMAC_DRBG.reseed_interval",
"Hacl.HMAC_DRBG.__proj__State__item__reseed_counter"
] | [] | false | false | false | false | false | let mk_generate #a hmac output st n additional_input_len additional_input =
| if st.reseed_counter.(0ul) >. reseed_interval
then false
else
(S.hmac_input_bound a;
Math.Lemmas.lemma_div_mod (v n) (hash_length a);
let State k v ctr = st in
if additional_input_len >. 0ul then update hmac additional_input_len additional_input k v;
let output:lbuffer uint8 n = output in
let max = n /. hash_len a in
let out = sub output 0ul (max *! hash_len a) in
[@@ inline_let ]let a_spec = S.a_spec a in
[@@ inline_let ]let refl h i = as_seq h v in
[@@ inline_let ]let spec h0 = S.generate_loop a (as_seq h0 k) (uint_v max) in
let h0 = ST.get () in
fill_blocks h0
(hash_len a)
max
out
a_spec
refl
(fun i -> loc v)
spec
(fun i ->
LSeq.unfold_generate_blocks (hash_length a)
(uint_v max)
a_spec
(spec h0)
(as_seq h0 v)
(uint_v i);
hmac v k (hash_len a) v (hash_len a);
copy (sub out (i *! hash_len a) (hash_len a)) v);
if max *! hash_len a <. n
then
(let h1 = ST.get () in
let block = sub output (max *! hash_len a) (n -! (max *! hash_len a)) in
hmac v k (hash_len a) v (hash_len a);
copy block (sub v 0ul (n -! (max *! hash_len a)));
let h2 = ST.get () in
LSeq.eq_intro (as_seq h2 output) ((as_seq h1 out) `LSeq.op_At_Bar` (as_seq h2 block)));
update hmac additional_input_len additional_input k v;
let old_ctr = ctr.(0ul) in
ctr.(0ul) <- old_ctr +! 1ul;
true) | false |
Pulse.Checker.Prover.Match.fst | Pulse.Checker.Prover.Match.is_smt_fallback | val is_smt_fallback (t: R.term) : bool | val is_smt_fallback (t: R.term) : bool | let is_smt_fallback (t:R.term) : bool =
match R.inspect_ln t with
| R.Tv_FVar fv ->
let name = R.inspect_fv fv in
name = ["Steel";"Effect";"Common";"smt_fallback"] ||
name = ["Pulse"; "Lib"; "Core"; "equate_by_smt"]
| _ -> false | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Match.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 14,
"end_line": 73,
"start_col": 0,
"start_line": 67
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Prover.Match
open Pulse.Syntax
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Typing.Metatheory
open Pulse.Typing.Util
open Pulse.Checker.VPropEquiv
open Pulse.Checker.Prover.Base
open Pulse.Checker.Prover.Util
module RU = Pulse.RuntimeUtils
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module TermEq = FStar.Reflection.V2.TermEq
module T = FStar.Tactics.V2
module RUtil = Pulse.Reflection.Util
module P = Pulse.Syntax.Printer
module PS = Pulse.Checker.Prover.Substs
module Metatheory = Pulse.Typing.Metatheory
let equational (t:term) : bool =
match t.t with
| Tm_FStar host_term ->
(match R.inspect_ln host_term with
| R.Tv_Match _ _ _ -> true
| _ -> false)
| _ -> false
let type_of_fv (g:env) (fv:R.fv)
: T.Tac (option R.term)
= let n = R.inspect_fv fv in
match R.lookup_typ (fstar_env g) n with
| None -> None
| Some se ->
match R.inspect_sigelt se with
| R.Unk -> None
| R.Sg_Let _ lbs -> (
L.tryPick
(fun lb ->
let lbv = R.inspect_lb lb in
if R.inspect_fv lbv.lb_fv = n
then Some lbv.lb_typ
else None)
lbs
)
| R.Sg_Val _ _ t -> Some t
| R.Sg_Inductive _nm _univs params typ _ -> None | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Util.fsti.checked",
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Readback.fsti.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Prover.Util.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.Match.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.Reflection.Util",
"short_module": "RUtil"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2.TermEq",
"short_module": "TermEq"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.VPropEquiv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Metatheory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: FStar.Stubs.Reflection.Types.term -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.V2.Builtins.inspect_ln",
"FStar.Stubs.Reflection.Types.fv",
"Prims.op_BarBar",
"Prims.op_Equality",
"Prims.list",
"Prims.string",
"Prims.Cons",
"Prims.Nil",
"FStar.Stubs.Reflection.Types.name",
"FStar.Stubs.Reflection.V2.Builtins.inspect_fv",
"FStar.Stubs.Reflection.V2.Data.term_view",
"Prims.bool"
] | [] | false | false | false | true | false | let is_smt_fallback (t: R.term) : bool =
| match R.inspect_ln t with
| R.Tv_FVar fv ->
let name = R.inspect_fv fv in
name = ["Steel"; "Effect"; "Common"; "smt_fallback"] ||
name = ["Pulse"; "Lib"; "Core"; "equate_by_smt"]
| _ -> false | false |
Pulse.Checker.Prover.Match.fst | Pulse.Checker.Prover.Match.type_of_fv | val type_of_fv (g: env) (fv: R.fv) : T.Tac (option R.term) | val type_of_fv (g: env) (fv: R.fv) : T.Tac (option R.term) | let type_of_fv (g:env) (fv:R.fv)
: T.Tac (option R.term)
= let n = R.inspect_fv fv in
match R.lookup_typ (fstar_env g) n with
| None -> None
| Some se ->
match R.inspect_sigelt se with
| R.Unk -> None
| R.Sg_Let _ lbs -> (
L.tryPick
(fun lb ->
let lbv = R.inspect_lb lb in
if R.inspect_fv lbv.lb_fv = n
then Some lbv.lb_typ
else None)
lbs
)
| R.Sg_Val _ _ t -> Some t
| R.Sg_Inductive _nm _univs params typ _ -> None | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Match.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 54,
"end_line": 65,
"start_col": 0,
"start_line": 47
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Prover.Match
open Pulse.Syntax
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Typing.Metatheory
open Pulse.Typing.Util
open Pulse.Checker.VPropEquiv
open Pulse.Checker.Prover.Base
open Pulse.Checker.Prover.Util
module RU = Pulse.RuntimeUtils
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module TermEq = FStar.Reflection.V2.TermEq
module T = FStar.Tactics.V2
module RUtil = Pulse.Reflection.Util
module P = Pulse.Syntax.Printer
module PS = Pulse.Checker.Prover.Substs
module Metatheory = Pulse.Typing.Metatheory
let equational (t:term) : bool =
match t.t with
| Tm_FStar host_term ->
(match R.inspect_ln host_term with
| R.Tv_Match _ _ _ -> true
| _ -> false)
| _ -> false | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Util.fsti.checked",
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Readback.fsti.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Prover.Util.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.Match.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.Reflection.Util",
"short_module": "RUtil"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2.TermEq",
"short_module": "TermEq"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.VPropEquiv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Metatheory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: Pulse.Typing.Env.env -> fv: FStar.Stubs.Reflection.Types.fv
-> FStar.Tactics.Effect.Tac (FStar.Pervasives.Native.option FStar.Stubs.Reflection.Types.term) | FStar.Tactics.Effect.Tac | [] | [] | [
"Pulse.Typing.Env.env",
"FStar.Stubs.Reflection.Types.fv",
"FStar.Stubs.Reflection.V2.Builtins.lookup_typ",
"Pulse.Typing.Env.fstar_env",
"FStar.Pervasives.Native.None",
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.Types.sigelt",
"FStar.Stubs.Reflection.V2.Builtins.inspect_sigelt",
"Prims.bool",
"Prims.list",
"FStar.Stubs.Reflection.Types.letbinding",
"FStar.List.Tot.Base.tryPick",
"FStar.Stubs.Reflection.Types.typ",
"Prims.op_Equality",
"FStar.Stubs.Reflection.Types.name",
"FStar.Stubs.Reflection.V2.Builtins.inspect_fv",
"FStar.Stubs.Reflection.V2.Data.__proj__Mklb_view__item__lb_fv",
"FStar.Pervasives.Native.Some",
"FStar.Stubs.Reflection.V2.Data.__proj__Mklb_view__item__lb_typ",
"FStar.Pervasives.Native.option",
"FStar.Stubs.Reflection.V2.Data.lb_view",
"Prims.precedes",
"FStar.Stubs.Reflection.V2.Builtins.inspect_lb",
"FStar.Stubs.Reflection.Types.univ_name",
"FStar.Stubs.Reflection.Types.binders",
"FStar.Stubs.Reflection.V2.Data.ctor"
] | [] | false | true | false | false | false | let type_of_fv (g: env) (fv: R.fv) : T.Tac (option R.term) =
| let n = R.inspect_fv fv in
match R.lookup_typ (fstar_env g) n with
| None -> None
| Some se ->
match R.inspect_sigelt se with
| R.Unk -> None
| R.Sg_Let _ lbs ->
(L.tryPick (fun lb ->
let lbv = R.inspect_lb lb in
if R.inspect_fv lbv.lb_fv = n then Some lbv.lb_typ else None)
lbs)
| R.Sg_Val _ _ t -> Some t
| R.Sg_Inductive _nm _univs params typ _ -> None | false |
Pulse.Checker.Prover.Match.fst | Pulse.Checker.Prover.Match.is_reveal | val is_reveal (t: term) : bool | val is_reveal (t: term) : bool | let is_reveal (t:term) : bool =
match leftmost_head t with
| Some hd ->
(match is_fvar hd with
| Some (l, [_]) -> l = RUtil.reveal_lid
| _ -> false)
| _ -> false | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Match.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 14,
"end_line": 212,
"start_col": 0,
"start_line": 206
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Prover.Match
open Pulse.Syntax
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Typing.Metatheory
open Pulse.Typing.Util
open Pulse.Checker.VPropEquiv
open Pulse.Checker.Prover.Base
open Pulse.Checker.Prover.Util
module RU = Pulse.RuntimeUtils
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module TermEq = FStar.Reflection.V2.TermEq
module T = FStar.Tactics.V2
module RUtil = Pulse.Reflection.Util
module P = Pulse.Syntax.Printer
module PS = Pulse.Checker.Prover.Substs
module Metatheory = Pulse.Typing.Metatheory
let equational (t:term) : bool =
match t.t with
| Tm_FStar host_term ->
(match R.inspect_ln host_term with
| R.Tv_Match _ _ _ -> true
| _ -> false)
| _ -> false
let type_of_fv (g:env) (fv:R.fv)
: T.Tac (option R.term)
= let n = R.inspect_fv fv in
match R.lookup_typ (fstar_env g) n with
| None -> None
| Some se ->
match R.inspect_sigelt se with
| R.Unk -> None
| R.Sg_Let _ lbs -> (
L.tryPick
(fun lb ->
let lbv = R.inspect_lb lb in
if R.inspect_fv lbv.lb_fv = n
then Some lbv.lb_typ
else None)
lbs
)
| R.Sg_Val _ _ t -> Some t
| R.Sg_Inductive _nm _univs params typ _ -> None
let is_smt_fallback (t:R.term) : bool =
match R.inspect_ln t with
| R.Tv_FVar fv ->
let name = R.inspect_fv fv in
name = ["Steel";"Effect";"Common";"smt_fallback"] ||
name = ["Pulse"; "Lib"; "Core"; "equate_by_smt"]
| _ -> false
(*
When comparing t0 =?= t1, if they are not syntactically equal, we
have to decide whether or not we should fire an SMT query to compare
them for provable equality.
The criterion is as follows:
1. We allow an SMT query if either t0 or t1 is "equational". For now, that means
that either is a match expression.
2. Otherwise, if they are both applications of `f v0...vn` and `f u0...un`
of the same head symbol `f`, a top-level constant, then we check if the
type of `f` decorates any of its binders with the `smt_fallback` attribute.
- If none of them are marked as such,
then we check if `f v0...` is syntactically equal to `f u0...`
and allow an SMT query to check if vn = vm. That is, the default behavior
for predicates is that they *last* argument is eligible for SMT equality.
- Otherwise, for each binder that is NOT marked as `smt_fallback`, we check
if the corresponding argument is syntactically equal. If so, we allow
t0 and t1 to be compared for SMT equality.
For example, Steel.ST.Reference.pts_to is defined like so:
/// For instance, [pts_to r (sum_perm (half_perm p) (half_perm p)) (v + 1)]
/// is unifiable with [pts_to r p (1 + v)]
val pts_to (#a:Type0)
(r:ref a)
([@@@smt_fallback] p:perm)
([@@@smt_fallback] v:a)
: vprop
*)
let eligible_for_smt_equality (g:env) (t0 t1:term)
: T.Tac bool
= let either_equational () = equational t0 || equational t1 in
let head_eq (t0 t1:R.term) =
match R.inspect_ln t0, R.inspect_ln t1 with
| R.Tv_App h0 _, R.Tv_App h1 _ ->
TermEq.term_eq h0 h1
| _ -> false
in
match t0.t, t1.t with
| Tm_FStar t0, Tm_FStar t1 -> (
let h0, args0 = R.collect_app_ln t0 in
let h1, args1 = R.collect_app_ln t1 in
if TermEq.term_eq h0 h1 && L.length args0 = L.length args1
then (
match R.inspect_ln h0 with
| R.Tv_FVar fv
| R.Tv_UInst fv _ -> (
match type_of_fv g fv with
| None -> either_equational()
| Some t ->
let bs, _ = R.collect_arr_ln_bs t in
let is_smt_fallback (b:R.binder) =
let bview = R.inspect_binder b in
L.existsb is_smt_fallback bview.attrs
in
let some_fallbacks, fallbacks =
L.fold_right
(fun b (some_fallbacks, bs) ->
if is_smt_fallback b
then true, true::bs
else some_fallbacks, false::bs)
bs (false, [])
in
if not some_fallbacks
then (
//if none of the binders are marked fallback
//then, by default, consider only the last argument as
//fallback
head_eq t0 t1
)
else (
let rec aux args0 args1 fallbacks =
match args0, args1, fallbacks with
| (a0, _)::args0, (a1, _)::args1, b::fallbacks ->
if b
then aux args0 args1 fallbacks
else if not (TermEq.term_eq a0 a1)
then false
else aux args0 args1 fallbacks
| [], [], [] -> true
| _ -> either_equational() //unequal lengths
in
aux args0 args1 fallbacks
)
)
| _ -> either_equational ()
)
else either_equational ()
)
| Tm_ForallSL _ _ _, Tm_ForallSL _ _ _ -> true
| _ -> either_equational ()
let refl_uvar (t:R.term) (uvs:env) : option var =
let open R in
match inspect_ln t with
| Tv_Var v ->
let {uniq=n} = inspect_namedv v in
if contains uvs n then Some n else None
| _ -> None
let is_uvar (t:term) (uvs:env) : option var =
match t.t with
| Tm_FStar t -> refl_uvar t uvs
| _ -> None
let contains_uvar (t:term) (uvs:env) (g:env) : T.Tac bool =
not (check_disjoint uvs (freevars t))
let is_reveal_uvar (t:term) (uvs:env) : option (universe & term & var) =
match is_pure_app t with
| Some (hd, None, arg) ->
(match is_pure_app hd with
| Some (hd, Some Implicit, ty) ->
let arg_uvar_index_opt = is_uvar arg uvs in
(match arg_uvar_index_opt with
| Some n ->
(match is_fvar hd with
| Some (l, [u]) ->
if l = RUtil.reveal_lid
then Some (u, ty, n)
else None
| _ -> None)
| _ -> None)
| _ -> None)
| _ -> None | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Util.fsti.checked",
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Readback.fsti.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Prover.Util.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.Match.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.Reflection.Util",
"short_module": "RUtil"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2.TermEq",
"short_module": "TermEq"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.VPropEquiv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Metatheory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Pulse.Syntax.Base.term -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Pure.leftmost_head",
"Pulse.Syntax.Pure.is_fvar",
"FStar.Stubs.Reflection.Types.name",
"Pulse.Syntax.Base.universe",
"Prims.op_Equality",
"Prims.list",
"Prims.string",
"Pulse.Reflection.Util.reveal_lid",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"Prims.bool"
] | [] | false | false | false | true | false | let is_reveal (t: term) : bool =
| match leftmost_head t with
| Some hd ->
(match is_fvar hd with
| Some (l, [_]) -> l = RUtil.reveal_lid
| _ -> false)
| _ -> false | false |
FStar.HyperStack.fst | FStar.HyperStack.stackref | val stackref : a: Type0 -> Type0 | let stackref (a:Type) = mstackref a (Heap.trivial_preorder a) | {
"file_name": "ulib/FStar.HyperStack.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 61,
"end_line": 22,
"start_col": 0,
"start_line": 22
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.HyperStack
include FStar.Monotonic.HyperStack
type reference (a:Type) = mreference a (Heap.trivial_preorder a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.HyperStack.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.HyperStack.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type0 -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.HyperStack.mstackref",
"FStar.Heap.trivial_preorder"
] | [] | false | false | false | true | true | let stackref (a: Type) =
| mstackref a (Heap.trivial_preorder a) | false |
|
FStar.HyperStack.fst | FStar.HyperStack.mmstackref | val mmstackref : a: Type0 -> Type0 | let mmstackref (a:Type) = mmmstackref a (Heap.trivial_preorder a) | {
"file_name": "ulib/FStar.HyperStack.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 65,
"end_line": 25,
"start_col": 0,
"start_line": 25
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.HyperStack
include FStar.Monotonic.HyperStack
type reference (a:Type) = mreference a (Heap.trivial_preorder a)
let stackref (a:Type) = mstackref a (Heap.trivial_preorder a)
let ref (a:Type) = mref a (Heap.trivial_preorder a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.HyperStack.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.HyperStack.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type0 -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.HyperStack.mmmstackref",
"FStar.Heap.trivial_preorder"
] | [] | false | false | false | true | true | let mmstackref (a: Type) =
| mmmstackref a (Heap.trivial_preorder a) | false |
|
Pulse.Checker.Prover.Match.fst | Pulse.Checker.Prover.Match.eligible_for_smt_equality | val eligible_for_smt_equality (g: env) (t0 t1: term) : T.Tac bool | val eligible_for_smt_equality (g: env) (t0 t1: term) : T.Tac bool | let eligible_for_smt_equality (g:env) (t0 t1:term)
: T.Tac bool
= let either_equational () = equational t0 || equational t1 in
let head_eq (t0 t1:R.term) =
match R.inspect_ln t0, R.inspect_ln t1 with
| R.Tv_App h0 _, R.Tv_App h1 _ ->
TermEq.term_eq h0 h1
| _ -> false
in
match t0.t, t1.t with
| Tm_FStar t0, Tm_FStar t1 -> (
let h0, args0 = R.collect_app_ln t0 in
let h1, args1 = R.collect_app_ln t1 in
if TermEq.term_eq h0 h1 && L.length args0 = L.length args1
then (
match R.inspect_ln h0 with
| R.Tv_FVar fv
| R.Tv_UInst fv _ -> (
match type_of_fv g fv with
| None -> either_equational()
| Some t ->
let bs, _ = R.collect_arr_ln_bs t in
let is_smt_fallback (b:R.binder) =
let bview = R.inspect_binder b in
L.existsb is_smt_fallback bview.attrs
in
let some_fallbacks, fallbacks =
L.fold_right
(fun b (some_fallbacks, bs) ->
if is_smt_fallback b
then true, true::bs
else some_fallbacks, false::bs)
bs (false, [])
in
if not some_fallbacks
then (
//if none of the binders are marked fallback
//then, by default, consider only the last argument as
//fallback
head_eq t0 t1
)
else (
let rec aux args0 args1 fallbacks =
match args0, args1, fallbacks with
| (a0, _)::args0, (a1, _)::args1, b::fallbacks ->
if b
then aux args0 args1 fallbacks
else if not (TermEq.term_eq a0 a1)
then false
else aux args0 args1 fallbacks
| [], [], [] -> true
| _ -> either_equational() //unequal lengths
in
aux args0 args1 fallbacks
)
)
| _ -> either_equational ()
)
else either_equational ()
)
| Tm_ForallSL _ _ _, Tm_ForallSL _ _ _ -> true
| _ -> either_equational () | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Match.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 31,
"end_line": 169,
"start_col": 0,
"start_line": 108
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Prover.Match
open Pulse.Syntax
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Typing.Metatheory
open Pulse.Typing.Util
open Pulse.Checker.VPropEquiv
open Pulse.Checker.Prover.Base
open Pulse.Checker.Prover.Util
module RU = Pulse.RuntimeUtils
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module TermEq = FStar.Reflection.V2.TermEq
module T = FStar.Tactics.V2
module RUtil = Pulse.Reflection.Util
module P = Pulse.Syntax.Printer
module PS = Pulse.Checker.Prover.Substs
module Metatheory = Pulse.Typing.Metatheory
let equational (t:term) : bool =
match t.t with
| Tm_FStar host_term ->
(match R.inspect_ln host_term with
| R.Tv_Match _ _ _ -> true
| _ -> false)
| _ -> false
let type_of_fv (g:env) (fv:R.fv)
: T.Tac (option R.term)
= let n = R.inspect_fv fv in
match R.lookup_typ (fstar_env g) n with
| None -> None
| Some se ->
match R.inspect_sigelt se with
| R.Unk -> None
| R.Sg_Let _ lbs -> (
L.tryPick
(fun lb ->
let lbv = R.inspect_lb lb in
if R.inspect_fv lbv.lb_fv = n
then Some lbv.lb_typ
else None)
lbs
)
| R.Sg_Val _ _ t -> Some t
| R.Sg_Inductive _nm _univs params typ _ -> None
let is_smt_fallback (t:R.term) : bool =
match R.inspect_ln t with
| R.Tv_FVar fv ->
let name = R.inspect_fv fv in
name = ["Steel";"Effect";"Common";"smt_fallback"] ||
name = ["Pulse"; "Lib"; "Core"; "equate_by_smt"]
| _ -> false
(*
When comparing t0 =?= t1, if they are not syntactically equal, we
have to decide whether or not we should fire an SMT query to compare
them for provable equality.
The criterion is as follows:
1. We allow an SMT query if either t0 or t1 is "equational". For now, that means
that either is a match expression.
2. Otherwise, if they are both applications of `f v0...vn` and `f u0...un`
of the same head symbol `f`, a top-level constant, then we check if the
type of `f` decorates any of its binders with the `smt_fallback` attribute.
- If none of them are marked as such,
then we check if `f v0...` is syntactically equal to `f u0...`
and allow an SMT query to check if vn = vm. That is, the default behavior
for predicates is that they *last* argument is eligible for SMT equality.
- Otherwise, for each binder that is NOT marked as `smt_fallback`, we check
if the corresponding argument is syntactically equal. If so, we allow
t0 and t1 to be compared for SMT equality.
For example, Steel.ST.Reference.pts_to is defined like so:
/// For instance, [pts_to r (sum_perm (half_perm p) (half_perm p)) (v + 1)]
/// is unifiable with [pts_to r p (1 + v)]
val pts_to (#a:Type0)
(r:ref a)
([@@@smt_fallback] p:perm)
([@@@smt_fallback] v:a)
: vprop | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Util.fsti.checked",
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Readback.fsti.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Prover.Util.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.Match.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.Reflection.Util",
"short_module": "RUtil"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2.TermEq",
"short_module": "TermEq"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.VPropEquiv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Metatheory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: Pulse.Typing.Env.env -> t0: Pulse.Syntax.Base.term -> t1: Pulse.Syntax.Base.term
-> FStar.Tactics.Effect.Tac Prims.bool | FStar.Tactics.Effect.Tac | [] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.term",
"FStar.Pervasives.Native.Mktuple2",
"Pulse.Syntax.Base.term'",
"Pulse.Syntax.Base.__proj__Mkterm__item__t",
"Pulse.Syntax.Base.host_term",
"FStar.Stubs.Reflection.Types.term",
"Prims.list",
"FStar.Stubs.Reflection.V2.Data.argv",
"Prims.op_AmpAmp",
"FStar.Reflection.V2.TermEq.term_eq",
"Prims.op_Equality",
"Prims.nat",
"FStar.List.Tot.Base.length",
"FStar.Stubs.Reflection.V2.Builtins.inspect_ln",
"FStar.Stubs.Reflection.Types.fv",
"FStar.Stubs.Reflection.Types.binder",
"FStar.Stubs.Reflection.Types.comp",
"Prims.bool",
"Prims.op_Negation",
"FStar.Pervasives.Native.tuple2",
"FStar.Stubs.Reflection.V2.Data.aqualv",
"FStar.Pervasives.Native.Mktuple3",
"FStar.Pervasives.Native.tuple3",
"FStar.List.Tot.Base.fold_right",
"Prims.Cons",
"Prims.Nil",
"FStar.List.Tot.Base.existsb",
"Pulse.Checker.Prover.Match.is_smt_fallback",
"FStar.Stubs.Reflection.V2.Data.__proj__Mkbinder_view__item__attrs",
"FStar.Stubs.Reflection.V2.Data.binder_view",
"Prims.precedes",
"FStar.Stubs.Reflection.V2.Builtins.inspect_binder",
"FStar.Reflection.V2.Derived.collect_arr_ln_bs",
"FStar.Pervasives.Native.option",
"Pulse.Checker.Prover.Match.type_of_fv",
"FStar.Stubs.Reflection.V2.Data.universes",
"FStar.Stubs.Reflection.V2.Data.term_view",
"FStar.Reflection.V2.Derived.collect_app_ln",
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.binder",
"Prims.unit",
"Prims.op_BarBar",
"Pulse.Checker.Prover.Match.equational"
] | [] | false | true | false | false | false | let eligible_for_smt_equality (g: env) (t0 t1: term) : T.Tac bool =
| let either_equational () = equational t0 || equational t1 in
let head_eq (t0 t1: R.term) =
match R.inspect_ln t0, R.inspect_ln t1 with
| R.Tv_App h0 _, R.Tv_App h1 _ -> TermEq.term_eq h0 h1
| _ -> false
in
match t0.t, t1.t with
| Tm_FStar t0, Tm_FStar t1 ->
(let h0, args0 = R.collect_app_ln t0 in
let h1, args1 = R.collect_app_ln t1 in
if TermEq.term_eq h0 h1 && L.length args0 = L.length args1
then
(match R.inspect_ln h0 with
| R.Tv_FVar fv
| R.Tv_UInst fv _ ->
(match type_of_fv g fv with
| None -> either_equational ()
| Some t ->
let bs, _ = R.collect_arr_ln_bs t in
let is_smt_fallback (b: R.binder) =
let bview = R.inspect_binder b in
L.existsb is_smt_fallback bview.attrs
in
let some_fallbacks, fallbacks =
L.fold_right (fun b (some_fallbacks, bs) ->
if is_smt_fallback b then true, true :: bs else some_fallbacks, false :: bs)
bs
(false, [])
in
if not some_fallbacks
then (head_eq t0 t1)
else
(let rec aux args0 args1 fallbacks =
match args0, args1, fallbacks with
| (a0, _) :: args0, (a1, _) :: args1, b :: fallbacks ->
if b
then aux args0 args1 fallbacks
else if not (TermEq.term_eq a0 a1) then false else aux args0 args1 fallbacks
| [], [], [] -> true
| _ -> either_equational ()
in
aux args0 args1 fallbacks))
| _ -> either_equational ())
else either_equational ())
| Tm_ForallSL _ _ _, Tm_ForallSL _ _ _ -> true
| _ -> either_equational () | false |
FStar.HyperStack.fst | FStar.HyperStack.ref | val ref : a: Type0 -> Type0 | let ref (a:Type) = mref a (Heap.trivial_preorder a) | {
"file_name": "ulib/FStar.HyperStack.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 51,
"end_line": 23,
"start_col": 0,
"start_line": 23
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.HyperStack
include FStar.Monotonic.HyperStack
type reference (a:Type) = mreference a (Heap.trivial_preorder a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.HyperStack.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.HyperStack.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type0 -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.HyperStack.mref",
"FStar.Heap.trivial_preorder"
] | [] | false | false | false | true | true | let ref (a: Type) =
| mref a (Heap.trivial_preorder a) | false |
|
FStar.HyperStack.fst | FStar.HyperStack.mmref | val mmref : a: Type0 -> Type0 | let mmref (a:Type) = mmmref a (Heap.trivial_preorder a) | {
"file_name": "ulib/FStar.HyperStack.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 55,
"end_line": 26,
"start_col": 0,
"start_line": 26
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.HyperStack
include FStar.Monotonic.HyperStack
type reference (a:Type) = mreference a (Heap.trivial_preorder a)
let stackref (a:Type) = mstackref a (Heap.trivial_preorder a)
let ref (a:Type) = mref a (Heap.trivial_preorder a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.HyperStack.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.HyperStack.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type0 -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.HyperStack.mmmref",
"FStar.Heap.trivial_preorder"
] | [] | false | false | false | true | true | let mmref (a: Type) =
| mmmref a (Heap.trivial_preorder a) | false |
|
FStar.HyperStack.fst | FStar.HyperStack.reference_distinct_sel_disjoint | val reference_distinct_sel_disjoint (#a: Type0) (h: mem) (r1 r2: reference a)
: Lemma
(requires
(h `contains` r1 /\ h `contains` r2 /\ frameOf r1 == frameOf r2 /\ as_addr r1 == as_addr r2)
) (ensures (sel h r1 == sel h r2)) | val reference_distinct_sel_disjoint (#a: Type0) (h: mem) (r1 r2: reference a)
: Lemma
(requires
(h `contains` r1 /\ h `contains` r2 /\ frameOf r1 == frameOf r2 /\ as_addr r1 == as_addr r2)
) (ensures (sel h r1 == sel h r2)) | let reference_distinct_sel_disjoint
(#a:Type0) (h: mem) (r1: reference a) (r2: reference a)
: Lemma
(requires (
h `contains` r1 /\
h `contains` r2 /\
frameOf r1 == frameOf r2 /\
as_addr r1 == as_addr r2
))
(ensures (
sel h r1 == sel h r2
))
= mreference_distinct_sel_disjoint h r1 r2 | {
"file_name": "ulib/FStar.HyperStack.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 42,
"end_line": 43,
"start_col": 0,
"start_line": 31
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.HyperStack
include FStar.Monotonic.HyperStack
type reference (a:Type) = mreference a (Heap.trivial_preorder a)
let stackref (a:Type) = mstackref a (Heap.trivial_preorder a)
let ref (a:Type) = mref a (Heap.trivial_preorder a)
let mmstackref (a:Type) = mmmstackref a (Heap.trivial_preorder a)
let mmref (a:Type) = mmmref a (Heap.trivial_preorder a)
type s_ref (i:rid) (a:Type) = s_mref i a (Heap.trivial_preorder a)
(* Two references with different reads are disjoint. *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Monotonic.HyperStack.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "FStar.HyperStack.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
h: FStar.Monotonic.HyperStack.mem ->
r1: FStar.HyperStack.reference a ->
r2: FStar.HyperStack.reference a
-> FStar.Pervasives.Lemma
(requires
FStar.Monotonic.HyperStack.contains h r1 /\ FStar.Monotonic.HyperStack.contains h r2 /\
FStar.Monotonic.HyperStack.frameOf r1 == FStar.Monotonic.HyperStack.frameOf r2 /\
FStar.Monotonic.HyperStack.as_addr r1 == FStar.Monotonic.HyperStack.as_addr r2)
(ensures FStar.Monotonic.HyperStack.sel h r1 == FStar.Monotonic.HyperStack.sel h r2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.reference",
"FStar.Monotonic.HyperStack.mreference_distinct_sel_disjoint",
"FStar.Heap.trivial_preorder",
"Prims.unit",
"Prims.l_and",
"FStar.Monotonic.HyperStack.contains",
"Prims.eq2",
"FStar.Monotonic.HyperHeap.rid",
"FStar.Monotonic.HyperStack.frameOf",
"Prims.pos",
"FStar.Monotonic.HyperStack.as_addr",
"Prims.squash",
"FStar.Monotonic.HyperStack.sel",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let reference_distinct_sel_disjoint (#a: Type0) (h: mem) (r1 r2: reference a)
: Lemma
(requires
(h `contains` r1 /\ h `contains` r2 /\ frameOf r1 == frameOf r2 /\ as_addr r1 == as_addr r2)
) (ensures (sel h r1 == sel h r2)) =
| mreference_distinct_sel_disjoint h r1 r2 | false |
Pulse.Checker.Prover.Match.fst | Pulse.Checker.Prover.Match.is_reveal_uvar | val is_reveal_uvar (t: term) (uvs: env) : option (universe & term & var) | val is_reveal_uvar (t: term) (uvs: env) : option (universe & term & var) | let is_reveal_uvar (t:term) (uvs:env) : option (universe & term & var) =
match is_pure_app t with
| Some (hd, None, arg) ->
(match is_pure_app hd with
| Some (hd, Some Implicit, ty) ->
let arg_uvar_index_opt = is_uvar arg uvs in
(match arg_uvar_index_opt with
| Some n ->
(match is_fvar hd with
| Some (l, [u]) ->
if l = RUtil.reveal_lid
then Some (u, ty, n)
else None
| _ -> None)
| _ -> None)
| _ -> None)
| _ -> None | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Match.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 13,
"end_line": 204,
"start_col": 0,
"start_line": 188
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Prover.Match
open Pulse.Syntax
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Typing.Metatheory
open Pulse.Typing.Util
open Pulse.Checker.VPropEquiv
open Pulse.Checker.Prover.Base
open Pulse.Checker.Prover.Util
module RU = Pulse.RuntimeUtils
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module TermEq = FStar.Reflection.V2.TermEq
module T = FStar.Tactics.V2
module RUtil = Pulse.Reflection.Util
module P = Pulse.Syntax.Printer
module PS = Pulse.Checker.Prover.Substs
module Metatheory = Pulse.Typing.Metatheory
let equational (t:term) : bool =
match t.t with
| Tm_FStar host_term ->
(match R.inspect_ln host_term with
| R.Tv_Match _ _ _ -> true
| _ -> false)
| _ -> false
let type_of_fv (g:env) (fv:R.fv)
: T.Tac (option R.term)
= let n = R.inspect_fv fv in
match R.lookup_typ (fstar_env g) n with
| None -> None
| Some se ->
match R.inspect_sigelt se with
| R.Unk -> None
| R.Sg_Let _ lbs -> (
L.tryPick
(fun lb ->
let lbv = R.inspect_lb lb in
if R.inspect_fv lbv.lb_fv = n
then Some lbv.lb_typ
else None)
lbs
)
| R.Sg_Val _ _ t -> Some t
| R.Sg_Inductive _nm _univs params typ _ -> None
let is_smt_fallback (t:R.term) : bool =
match R.inspect_ln t with
| R.Tv_FVar fv ->
let name = R.inspect_fv fv in
name = ["Steel";"Effect";"Common";"smt_fallback"] ||
name = ["Pulse"; "Lib"; "Core"; "equate_by_smt"]
| _ -> false
(*
When comparing t0 =?= t1, if they are not syntactically equal, we
have to decide whether or not we should fire an SMT query to compare
them for provable equality.
The criterion is as follows:
1. We allow an SMT query if either t0 or t1 is "equational". For now, that means
that either is a match expression.
2. Otherwise, if they are both applications of `f v0...vn` and `f u0...un`
of the same head symbol `f`, a top-level constant, then we check if the
type of `f` decorates any of its binders with the `smt_fallback` attribute.
- If none of them are marked as such,
then we check if `f v0...` is syntactically equal to `f u0...`
and allow an SMT query to check if vn = vm. That is, the default behavior
for predicates is that they *last* argument is eligible for SMT equality.
- Otherwise, for each binder that is NOT marked as `smt_fallback`, we check
if the corresponding argument is syntactically equal. If so, we allow
t0 and t1 to be compared for SMT equality.
For example, Steel.ST.Reference.pts_to is defined like so:
/// For instance, [pts_to r (sum_perm (half_perm p) (half_perm p)) (v + 1)]
/// is unifiable with [pts_to r p (1 + v)]
val pts_to (#a:Type0)
(r:ref a)
([@@@smt_fallback] p:perm)
([@@@smt_fallback] v:a)
: vprop
*)
let eligible_for_smt_equality (g:env) (t0 t1:term)
: T.Tac bool
= let either_equational () = equational t0 || equational t1 in
let head_eq (t0 t1:R.term) =
match R.inspect_ln t0, R.inspect_ln t1 with
| R.Tv_App h0 _, R.Tv_App h1 _ ->
TermEq.term_eq h0 h1
| _ -> false
in
match t0.t, t1.t with
| Tm_FStar t0, Tm_FStar t1 -> (
let h0, args0 = R.collect_app_ln t0 in
let h1, args1 = R.collect_app_ln t1 in
if TermEq.term_eq h0 h1 && L.length args0 = L.length args1
then (
match R.inspect_ln h0 with
| R.Tv_FVar fv
| R.Tv_UInst fv _ -> (
match type_of_fv g fv with
| None -> either_equational()
| Some t ->
let bs, _ = R.collect_arr_ln_bs t in
let is_smt_fallback (b:R.binder) =
let bview = R.inspect_binder b in
L.existsb is_smt_fallback bview.attrs
in
let some_fallbacks, fallbacks =
L.fold_right
(fun b (some_fallbacks, bs) ->
if is_smt_fallback b
then true, true::bs
else some_fallbacks, false::bs)
bs (false, [])
in
if not some_fallbacks
then (
//if none of the binders are marked fallback
//then, by default, consider only the last argument as
//fallback
head_eq t0 t1
)
else (
let rec aux args0 args1 fallbacks =
match args0, args1, fallbacks with
| (a0, _)::args0, (a1, _)::args1, b::fallbacks ->
if b
then aux args0 args1 fallbacks
else if not (TermEq.term_eq a0 a1)
then false
else aux args0 args1 fallbacks
| [], [], [] -> true
| _ -> either_equational() //unequal lengths
in
aux args0 args1 fallbacks
)
)
| _ -> either_equational ()
)
else either_equational ()
)
| Tm_ForallSL _ _ _, Tm_ForallSL _ _ _ -> true
| _ -> either_equational ()
let refl_uvar (t:R.term) (uvs:env) : option var =
let open R in
match inspect_ln t with
| Tv_Var v ->
let {uniq=n} = inspect_namedv v in
if contains uvs n then Some n else None
| _ -> None
let is_uvar (t:term) (uvs:env) : option var =
match t.t with
| Tm_FStar t -> refl_uvar t uvs
| _ -> None
let contains_uvar (t:term) (uvs:env) (g:env) : T.Tac bool =
not (check_disjoint uvs (freevars t)) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Util.fsti.checked",
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Readback.fsti.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Prover.Util.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.Match.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.Reflection.Util",
"short_module": "RUtil"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2.TermEq",
"short_module": "TermEq"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.VPropEquiv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Metatheory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Pulse.Syntax.Base.term -> uvs: Pulse.Typing.Env.env
-> FStar.Pervasives.Native.option ((Pulse.Syntax.Base.universe * Pulse.Syntax.Base.term) *
Pulse.Syntax.Base.var) | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.term",
"Pulse.Typing.Env.env",
"Pulse.Syntax.Pure.is_pure_app",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Pure.is_fvar",
"FStar.Stubs.Reflection.Types.name",
"Pulse.Syntax.Base.universe",
"Prims.op_Equality",
"Prims.list",
"Prims.string",
"Pulse.Reflection.Util.reveal_lid",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.tuple3",
"FStar.Pervasives.Native.Mktuple3",
"Prims.bool",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"Pulse.Checker.Prover.Match.is_uvar",
"Pulse.Syntax.Base.qualifier"
] | [] | false | false | false | true | false | let is_reveal_uvar (t: term) (uvs: env) : option (universe & term & var) =
| match is_pure_app t with
| Some (hd, None, arg) ->
(match is_pure_app hd with
| Some (hd, Some Implicit, ty) ->
let arg_uvar_index_opt = is_uvar arg uvs in
(match arg_uvar_index_opt with
| Some n ->
(match is_fvar hd with
| Some (l, [u]) -> if l = RUtil.reveal_lid then Some (u, ty, n) else None
| _ -> None)
| _ -> None)
| _ -> None)
| _ -> None | false |
Vale.AES.GCM_BE.fst | Vale.AES.GCM_BE.gcm_blocks_dec_helper | val gcm_blocks_dec_helper
(alg: algorithm)
(key: seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes: seq quad32)
(p_num_bytes a_num_bytes: nat)
(iv: supported_iv_BE)
(j0_BE h enc_hash length_quad: quad32)
: Lemma
(requires
length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\ length p128 == length c128 /\ length p_bytes == 1 /\
length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_word alg key /\
j0_BE = compute_iv_BE h iv /\ h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad ==
two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then append c128 c_bytes else c128
in
let cipher_bound:nat = length p128 + (if p_num_bytes > length p128 * 16 then 1 else 0) in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes
in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads p128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16
then
let raw_quads = append raw_quads p_bytes in
let input_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes
in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0)))
(ensures
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes
in
let plain_raw_quads =
if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128
in
let plain_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then append c128 c_bytes else c128
in
let cipher_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes
in
length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\
be_quad32_to_bytes enc_hash ==
gcm_decrypt_BE_tag alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes)) | val gcm_blocks_dec_helper
(alg: algorithm)
(key: seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes: seq quad32)
(p_num_bytes a_num_bytes: nat)
(iv: supported_iv_BE)
(j0_BE h enc_hash length_quad: quad32)
: Lemma
(requires
length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\ length p128 == length c128 /\ length p_bytes == 1 /\
length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_word alg key /\
j0_BE = compute_iv_BE h iv /\ h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad ==
two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then append c128 c_bytes else c128
in
let cipher_bound:nat = length p128 + (if p_num_bytes > length p128 * 16 then 1 else 0) in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes
in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads p128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16
then
let raw_quads = append raw_quads p_bytes in
let input_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes
in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0)))
(ensures
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes
in
let plain_raw_quads =
if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128
in
let plain_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then append c128 c_bytes else c128
in
let cipher_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes
in
length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\
be_quad32_to_bytes enc_hash ==
gcm_decrypt_BE_tag alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes)) | let gcm_blocks_dec_helper (alg:algorithm) (key:seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes:seq quad32)
(p_num_bytes a_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE h enc_hash length_quad:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\
a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
length a_bytes == 1 /\
is_aes_key_word alg key /\
j0_BE = compute_iv_BE h iv /\
h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads p128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads p_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0
)))
(ensures (let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let plain_raw_quads =
if p_num_bytes >length p128 * 16 then
append p128 p_bytes
else p128
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
be_quad32_to_bytes enc_hash == gcm_decrypt_BE_tag alg (seq_nat32_to_seq_nat8_BE key)
iv plain_bytes auth_bytes))
=
let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
let auth_raw_quads =
if a_num_bytes > length a128 * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads p128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads p_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
let hash = ghash_BE h final_quads in
calc (==) {
enc_hash;
== {}
gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0;
== {}
gctr_encrypt_block ctr_BE_1 hash alg key 0;
== {}
quad32_xor hash (aes_encrypt_word alg key ctr_BE_1);
};
calc (==) {
gctr_encrypt ctr_BE_1 (be_quad32_to_bytes hash) alg key;
== { gctr_encrypt_one_block ctr_BE_1 hash alg key }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 (quad32_xor hash (aes_encrypt_word alg key ctr_BE_1))));
== {}
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 enc_hash));
== { be_seq_quad32_to_bytes_of_singleton enc_hash }
be_quad32_to_bytes enc_hash;
};
if p_num_bytes > length p128 * 16 then (
let c = append p128 p_bytes in
calc (==) {
append (append auth_quads p128) p_bytes;
== { append_assoc auth_quads p128 p_bytes }
append auth_quads (append p128 p_bytes);
== {}
append auth_quads c;
};
calc (==) {
append (append (append auth_quads p128) p_bytes) (create 1 length_quad);
= {} // See previous calc
append (append auth_quads (append p128 p_bytes)) (create 1 length_quad);
== { append_assoc auth_quads c (create 1 length_quad) }
append auth_quads (append c (create 1 length_quad));
};
let raw_quads_old = append auth_quads c in
calc (==) {
raw_quads;
== {}
be_bytes_to_seq_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes));
== {
calc (==) {
pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes);
== {
calc (==) {
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes;
== { append_distributes_be_seq_quad32_to_bytes auth_quads c }
slice (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))) 0 total_bytes;
== { slice_append_back (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))
total_bytes }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes);
== { assert(equal (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes) plain_bytes) }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) plain_bytes;
}
}
pad_to_128_bits (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) plain_bytes);
== { pad_to_128_bits_multiple_append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) plain_bytes }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (pad_to_128_bits plain_bytes);
}
}
be_bytes_to_seq_quad32 (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (pad_to_128_bits plain_bytes));
== { append_distributes_be_bytes_to_seq_quad32
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(pad_to_128_bits plain_bytes) }
append (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))) (be_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes));
== { be_bytes_to_seq_quad32_to_bytes auth_quads }
append auth_quads (be_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes));
};
let auth_padded_quads' = be_bytes_to_seq_quad32 (pad_to_128_bits auth_input_bytes) in
let cipher_padded_quads' = be_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes) in
calc (==) {
append raw_quads (create 1 length_quad);
== {}
append (append auth_quads (be_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes))) (create 1 length_quad);
== { assert (equal auth_quads auth_padded_quads') }
append (append auth_padded_quads' cipher_padded_quads') (create 1 length_quad);
== { append_assoc auth_padded_quads' cipher_padded_quads' (create 1 length_quad) }
append auth_padded_quads' (append cipher_padded_quads' (create 1 length_quad));
};
()
) else (
calc (==) {
append (append auth_quads p128) (create 1 length_quad);
== { append_assoc auth_quads p128 (create 1 length_quad) }
append auth_quads (append p128 (create 1 length_quad));
};
let c = p128 in
calc (==) {
be_bytes_to_seq_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes));
== { assert (equal (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes)) }
be_bytes_to_seq_quad32 (pad_to_128_bits (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)));
== { assert (pad_to_128_bits (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) == (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))) }
be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c));
== { be_bytes_to_seq_quad32_to_bytes c }
c;
};
()
);
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_BE.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 953,
"start_col": 0,
"start_line": 721
} | module Vale.AES.GCM_BE
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.Types
open Vale.AES.GCM_BE_s
open Vale.AES.AES_BE_s
open Vale.AES.GCM_helpers_BE
open Vale.AES.GCTR_BE_s
open Vale.AES.GCTR_BE
open Vale.AES.GHash_BE_s
open FStar.Mul
open FStar.Seq
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open FStar.Calc
let upper3_equal (q0 q1:quad32) : bool =
q0.lo1 = q1.lo1 &&
q0.hi2 = q1.hi2 &&
q0.hi3 = q1.hi3
let lemma_be_bytes_to_quad32_prefix_equality (b0:seq nat8 {length b0 == 16}) (b1:seq nat8 {length b1 == 16}) : Lemma
(requires slice b0 0 12 == slice b1 0 12)
(ensures upper3_equal (be_bytes_to_quad32 b0) (be_bytes_to_quad32 b1))
=
let q0 = be_bytes_to_quad32 b0 in
let q1 = be_bytes_to_quad32 b1 in
be_bytes_to_quad32_reveal ();
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #nat8);
assert (forall (i:int). (0 <= i /\ i < 12) ==> (index b0 i == index (slice b0 0 12) i /\
index b1 i == index (slice b1 0 12) i))
let lemma_be_seq_quad32_to_bytes_prefix_equality (q:quad32) : Lemma
(slice (be_quad32_to_bytes q) 0 12 == slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
=
assert (equal (slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12)
(slice (be_quad32_to_bytes q) 0 12));
()
let lemma_compute_iv_easy (iv_b iv_extra_b:seq quad32) (iv:supported_iv_BE) (num_bytes:nat64) (h_BE j0:quad32) : Lemma
(requires
length iv_extra_b == 1 /\
length iv_b * (128/8) <= num_bytes /\ num_bytes < length iv_b * (128/8) + 128/8 /\
num_bytes == 96/8 /\
(let iv_BE = index iv_extra_b 0 in
j0 == Mkfour 1 iv_BE.lo1 iv_BE.hi2 iv_BE.hi3) /\
(let raw_quads = append iv_b iv_extra_b in
let iv_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 num_bytes in
iv_bytes == iv))
(ensures j0 == compute_iv_BE h_BE iv)
=
assert (length iv == 12);
assert (length iv_b == 0);
lemma_empty iv_b;
append_empty_l iv_extra_b;
assert (append iv_b iv_extra_b == iv_extra_b);
let q = index iv_extra_b 0 in
be_seq_quad32_to_bytes_of_singleton q;
assert (equal iv_extra_b (create 1 q));
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b) == be_quad32_to_bytes q);
calc (==) {
slice (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)) 0 12;
== {}
slice (pad_to_128_bits iv) 0 12;
};
calc (==) {
be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE iv_extra_b)) 0 num_bytes));
== {}
be_bytes_to_quad32 (pad_to_128_bits iv);
};
calc (==) {
j0;
== {}
set_to_one q;
== { be_bytes_to_quad32_to_bytes q }
set_to_one (be_bytes_to_quad32 (be_quad32_to_bytes q));
== {
lemma_be_seq_quad32_to_bytes_prefix_equality q;
lemma_be_bytes_to_quad32_prefix_equality
(be_quad32_to_bytes q)
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
}
set_to_one (be_bytes_to_quad32 (pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12)));
== { lemma_be_bytes_to_quad32_prefix_equality
(pad_to_128_bits (slice (be_quad32_to_bytes q) 0 12))
(pad_to_128_bits iv) }
set_to_one (be_bytes_to_quad32 (pad_to_128_bits iv));
== {compute_iv_BE_reveal ()}
compute_iv_BE h_BE iv;
};
()
let lemma_compute_iv_hard (iv:supported_iv_BE) (quads:seq quad32) (length_quad h_BE j0:quad32) : Lemma
(requires
~(length iv == 96/8) /\
quads == be_bytes_to_seq_quad32 (pad_to_128_bits iv) /\
j0 == ghash_incremental h_BE (Mkfour 0 0 0 0) (append quads (create 1 length_quad)) /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 0)
(nat_to_two 32 (8 * length iv))))
(ensures j0 == compute_iv_BE h_BE iv)
=
ghash_incremental_to_ghash h_BE (append quads (create 1 length_quad));
compute_iv_BE_reveal ();
()
let gcm_encrypt_BE_fst_helper (iv:supported_iv_BE) (iv_enc iv_BE:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma
(requires
is_aes_key_word alg key /\
length plain < pow2_32 /\
length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
iv_enc == inc32 (compute_iv_BE h_BE iv) 1 /\
cipher == gctr_encrypt iv_enc plain alg key
))
(ensures cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth))
=
gcm_encrypt_BE_reveal ()
let gcm_encrypt_BE_snd_helper (iv:supported_iv_BE) (j0_BE length_quad32 hash mac:quad32) (plain auth cipher:seq nat8) (alg:algorithm) (key:seq nat32) : Lemma
(requires
is_aes_key_word alg key /\
length plain < pow2_32 /\
length auth < pow2_32 /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
cipher == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth) /\
length_quad32 == two_two_to_four (Mktwo (nat_to_two 32 (8 * length auth)) (nat_to_two 32 (8 * length plain))) /\
(let auth_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits auth) in
let cipher_padded_quads = be_bytes_to_seq_quad32 (pad_to_128_bits cipher) in
hash == ghash_BE h_BE (append auth_padded_quads (append cipher_padded_quads (create 1 length_quad32))) /\
be_quad32_to_bytes mac == gctr_encrypt j0_BE (be_quad32_to_bytes hash) alg key)
))
(ensures be_quad32_to_bytes mac == snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain auth))
=
gcm_encrypt_BE_reveal ()
#reset-options "--z3rlimit 10"
let gcm_blocks_helper_enc (alg:algorithm) (key:seq nat32)
(p128 p_bytes c128 c_bytes:seq quad32)
(auth_bytes:seq nat8)
(p_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
(length auth_bytes) < pow2_32 /\
is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\
(let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2
)))
(ensures (let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
//cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key))
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes)))
=
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
gctr_partial_opaque_completed alg plain cipher key ctr_BE_2;
if p_num_bytes > length p128 * 16 then (
gctr_partial_reveal ();
assert (gctr_partial alg (length p128) plain cipher key ctr_BE_2);
assert (equal (slice plain 0 (length p128))
(slice p128 0 (length p128)));
assert (equal (slice cipher 0 (length p128))
(slice c128 0 (length p128)));
gctr_partial_opaque_ignores_postfix
alg (length p128)
plain p128
cipher c128
key ctr_BE_2;
assert (gctr_partial alg (length p128) p128 c128 key ctr_BE_2);
gctr_partial_opaque_completed alg p128 c128 key ctr_BE_2;
let num_blocks = p_num_bytes / 16 in
assert(index cipher num_blocks == quad32_xor (index plain num_blocks) (aes_encrypt_word alg key (inc32 ctr_BE_2 num_blocks)));
gctr_encrypt_block_offset ctr_BE_2 (index plain num_blocks) alg key num_blocks;
assert( gctr_encrypt_block ctr_BE_2 (index plain num_blocks) alg key num_blocks ==
gctr_encrypt_block (inc32 ctr_BE_2 num_blocks) (index plain num_blocks) alg key 0);
aes_encrypt_word_reveal ();
gctr_partial_to_full_advanced ctr_BE_2 plain cipher alg key p_num_bytes;
assert (cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key)
) else (
gctr_partial_to_full_basic ctr_BE_2 plain alg key cipher;
assert (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher) == gctr_encrypt ctr_BE_2 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) alg key);
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
assert (equal plain_bytes (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)));
assert (equal cipher_bytes (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)));
assert (cipher_bytes == gctr_encrypt ctr_BE_2 plain_bytes alg key)
);
gcm_encrypt_BE_fst_helper iv ctr_BE_2 j0_BE plain_bytes auth_bytes cipher_bytes alg key;
()
let slice_append_back (#a:Type) (x y:seq a) (i:nat) : Lemma
(requires length x <= i /\ i <= length x + length y)
(ensures slice (append x y) 0 i == append x (slice y 0 (i - length x)))
=
assert (equal (slice (append x y) 0 i) (append x (slice y 0 (i - length x))));
()
let append_distributes_be_seq_quad32_to_bytes (x y:seq quad32) :
Lemma (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append x y)) == append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE x)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE y)))
=
append_distributes_be_seq_quad32_to_bytes x y
let pad_to_128_bits_multiple_append (x y:seq nat8) : Lemma
(requires length x % 16 == 0)
(ensures pad_to_128_bits (append x y) == append x (pad_to_128_bits y))
=
assert (equal (pad_to_128_bits (append x y)) (append x (pad_to_128_bits y)))
#reset-options "--z3rlimit 100"
let gcm_blocks_helper (alg:algorithm) (key:seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes:seq quad32)
(p_num_bytes a_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE h enc_hash length_quad:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\
a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
length a_bytes == 1 /\
is_aes_key_word alg key /\
j0_BE = compute_iv_BE h iv /\
h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads c_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0
)))
(ensures (let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let plain_raw_quads =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else p128
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes) /\
be_quad32_to_bytes enc_hash ==
snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key)
iv plain_bytes auth_bytes)))
=
let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads c_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
let hash = ghash_BE h final_quads in
gcm_blocks_helper_enc alg key p128 p_bytes c128 c_bytes auth_input_bytes p_num_bytes iv j0_BE;
calc (==) {
enc_hash;
== {}
gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0;
== {}
gctr_encrypt_block ctr_BE_1 hash alg key 0;
== {}
quad32_xor hash (aes_encrypt_word alg key ctr_BE_1);
};
calc (==) {
gctr_encrypt ctr_BE_1 (be_quad32_to_bytes hash) alg key;
== { gctr_encrypt_one_block ctr_BE_1 hash alg key }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 (quad32_xor hash (aes_encrypt_word alg key ctr_BE_1))));
== {}
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 enc_hash));
== { be_seq_quad32_to_bytes_of_singleton enc_hash }
be_quad32_to_bytes enc_hash;
};
if p_num_bytes > length p128 * 16 then (
let c = append c128 c_bytes in
calc (==) {
append (append auth_quads c128) c_bytes;
== { append_assoc auth_quads c128 c_bytes }
append auth_quads (append c128 c_bytes);
== {}
append auth_quads c;
};
calc (==) {
append (append (append auth_quads c128) c_bytes) (create 1 length_quad);
= {} // See previous calc
append (append auth_quads (append c128 c_bytes)) (create 1 length_quad);
== { append_assoc auth_quads c (create 1 length_quad) }
append auth_quads (append c (create 1 length_quad));
};
let raw_quads_old = append auth_quads c in
calc (==) {
raw_quads;
== {}
be_bytes_to_seq_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes));
== {
calc (==) {
pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes);
== {
calc (==) {
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes;
== { append_distributes_be_seq_quad32_to_bytes auth_quads c }
slice (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))) 0 total_bytes;
== { slice_append_back (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))
total_bytes }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes);
== {}
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) cipher_bytes;
}
}
pad_to_128_bits (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) cipher_bytes);
== { pad_to_128_bits_multiple_append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) cipher_bytes }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (pad_to_128_bits cipher_bytes);
}
}
be_bytes_to_seq_quad32 (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) (pad_to_128_bits cipher_bytes));
== { append_distributes_be_bytes_to_seq_quad32
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(pad_to_128_bits cipher_bytes) }
append (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))) (be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes));
== { be_bytes_to_seq_quad32_to_bytes auth_quads }
append auth_quads (be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes));
};
let auth_padded_quads' = be_bytes_to_seq_quad32 (pad_to_128_bits auth_input_bytes) in
let cipher_padded_quads' = be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes) in
calc (==) {
append raw_quads (create 1 length_quad);
== {}
append (append auth_quads (be_bytes_to_seq_quad32 (pad_to_128_bits cipher_bytes))) (create 1 length_quad);
== { assert (equal auth_quads auth_padded_quads') }
append (append auth_padded_quads' cipher_padded_quads') (create 1 length_quad);
== { append_assoc auth_padded_quads' cipher_padded_quads' (create 1 length_quad) }
append auth_padded_quads' (append cipher_padded_quads' (create 1 length_quad));
};
gcm_encrypt_BE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key;
()
) else (
calc (==) {
append (append auth_quads c128) (create 1 length_quad);
== { append_assoc auth_quads c128 (create 1 length_quad) }
append auth_quads (append c128 (create 1 length_quad));
};
let c = c128 in
calc (==) {
be_bytes_to_seq_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes));
== { assert (equal (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes)) }
be_bytes_to_seq_quad32 (pad_to_128_bits (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)));
== { assert (pad_to_128_bits (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) == (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))) }
be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c));
== { be_bytes_to_seq_quad32_to_bytes c }
c;
};
gcm_encrypt_BE_snd_helper iv j0_BE length_quad hash enc_hash plain_bytes auth_input_bytes cipher_bytes alg key;
()
);
()
let lemma_length_simplifier (s bytes t:seq quad32) (num_bytes:nat) : Lemma
(requires t == (if num_bytes > (length s) * 16 then append s bytes else s) /\
(num_bytes <= (length s) * 16 ==> num_bytes == (length s * 16)) /\
length s * 16 <= num_bytes /\
num_bytes < length s * 16 + 16 /\
length bytes == 1
)
(ensures slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE t)) 0 num_bytes ==
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append s bytes))) 0 num_bytes)
=
if num_bytes > (length s) * 16 then (
()
) else (
calc (==) {
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (append s bytes))) 0 num_bytes;
== { append_distributes_be_seq_quad32_to_bytes s bytes }
slice (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE bytes))) 0 num_bytes;
== { Vale.Lib.Seqs.lemma_slice_first_exactly_in_append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE bytes)) }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s);
== { assert (length (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == num_bytes) }
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 num_bytes;
};
()
)
#reset-options "--z3rlimit 10"
let gcm_blocks_helper_simplified (alg:algorithm) (key:seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes:seq quad32)
(p_num_bytes a_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE h enc_hash length_quad:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\
a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
length a_bytes == 1 /\
is_aes_key_word alg key /\
j0_BE == compute_iv_BE h iv /\
h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad == two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > length a128 * 16 then append a128 a_bytes else a128
in
let auth_input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads c128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16 then
let raw_quads = append raw_quads c_bytes in
let input_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else
raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0
)))
(ensures (let auth_raw_quads = append a128 a_bytes in
let auth_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes in
let plain_raw_quads = append p128 p_bytes in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher_raw_quads = append c128 c_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_raw_quads)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes) /\
be_quad32_to_bytes enc_hash ==
snd (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key)
iv plain_bytes auth_bytes))
)
=
gcm_blocks_helper alg key a128 a_bytes p128 p_bytes c128 c_bytes p_num_bytes a_num_bytes iv j0_BE h enc_hash length_quad;
let auth_raw_quads = if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128 in
let plain_raw_quads =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else p128
in
let cipher_raw_quads:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
lemma_length_simplifier a128 a_bytes auth_raw_quads a_num_bytes;
lemma_length_simplifier p128 p_bytes plain_raw_quads p_num_bytes;
lemma_length_simplifier c128 c_bytes cipher_raw_quads p_num_bytes;
()
let lemma_gcm_encrypt_decrypt_equiv (alg:algorithm) (key:seq nat32) (iv:supported_iv_BE) (j0_BE:quad32) (plain cipher auth alleged_tag:seq nat8) : Lemma
(requires
is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv) /\
length cipher < pow2_32 /\
length auth < pow2_32 /\
plain == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv cipher auth)
)
(ensures plain == fst (gcm_decrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv cipher auth alleged_tag))
=
gcm_encrypt_BE_reveal ();
gcm_decrypt_BE_reveal ();
()
let gcm_blocks_helper_dec_simplified (alg:algorithm) (key:seq nat32)
(p128 p_bytes c128 c_bytes:seq quad32)
(auth_bytes alleged_tag:seq nat8)
(p_num_bytes:nat)
(iv:supported_iv_BE) (j0_BE:quad32) : Lemma
(requires // Required by gcm_blocks
length p128 * 16 <= p_num_bytes /\
p_num_bytes < length p128 * 16 + 16 /\
length p128 == length c128 /\
length p_bytes == 1 /\
length c_bytes == 1 /\
(length auth_bytes) < pow2_32 /\
is_aes_key_word alg key /\
(let h_BE = aes_encrypt_word alg key (Mkfour 0 0 0 0) in
j0_BE = compute_iv_BE h_BE iv) /\
// Ensured by gcm_blocks
p_num_bytes < pow2_32 /\
(let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else
p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
let cipher_bound:nat = length p128 +
(if p_num_bytes > length p128 * 16 then 1 else 0)
in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2
))
(ensures (let plain_raw_quads = append p128 p_bytes in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher_raw_quads = append c128 c_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_raw_quads)) 0 p_num_bytes in
length auth_bytes < pow2_32 /\
length plain_bytes < pow2_32 /\
cipher_bytes == fst (gcm_decrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes alleged_tag)))
=
gcm_blocks_helper_enc alg key p128 p_bytes c128 c_bytes auth_bytes p_num_bytes iv j0_BE;
let plain_raw_quads =
if p_num_bytes > length p128 * 16 then
append p128 p_bytes
else p128
in
let cipher_raw_quads:seq quad32 =
if p_num_bytes > length p128 * 16 then
append c128 c_bytes
else
c128
in
lemma_length_simplifier p128 p_bytes plain_raw_quads p_num_bytes;
lemma_length_simplifier c128 c_bytes cipher_raw_quads p_num_bytes;
let plain_raw_quads = append p128 p_bytes in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes in
let cipher_raw_quads = append c128 c_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher_raw_quads)) 0 p_num_bytes in
assert (cipher_bytes == fst (gcm_encrypt_BE alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes));
lemma_gcm_encrypt_decrypt_equiv alg key iv j0_BE cipher_bytes plain_bytes auth_bytes alleged_tag;
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.GHash_BE_s.fst.checked",
"Vale.AES.GCTR_BE_s.fst.checked",
"Vale.AES.GCTR_BE.fsti.checked",
"Vale.AES.GCM_helpers_BE.fsti.checked",
"Vale.AES.GCM_BE_s.fst.checked",
"Vale.AES.AES_BE_s.fst.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_BE.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_BE_s",
"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.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 60,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
alg: Vale.AES.AES_common_s.algorithm ->
key: FStar.Seq.Base.seq Vale.Def.Words_s.nat32 ->
a128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
a_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
p128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
p_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
c128: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
c_bytes: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
p_num_bytes: Prims.nat ->
a_num_bytes: Prims.nat ->
iv: Vale.AES.GCM_BE_s.supported_iv_BE ->
j0_BE: Vale.Def.Types_s.quad32 ->
h: Vale.Def.Types_s.quad32 ->
enc_hash: Vale.Def.Types_s.quad32 ->
length_quad: Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(requires
FStar.Seq.Base.length p128 * 16 <= p_num_bytes /\
p_num_bytes < FStar.Seq.Base.length p128 * 16 + 16 /\
FStar.Seq.Base.length a128 * 16 <= a_num_bytes /\
a_num_bytes < FStar.Seq.Base.length a128 * 16 + 16 /\ a_num_bytes < Vale.Def.Words_s.pow2_32 /\
FStar.Seq.Base.length p128 == FStar.Seq.Base.length c128 /\
FStar.Seq.Base.length p_bytes == 1 /\ FStar.Seq.Base.length c_bytes == 1 /\
FStar.Seq.Base.length a_bytes == 1 /\ Vale.AES.AES_BE_s.is_aes_key_word alg key /\
j0_BE = Vale.AES.GCM_BE_s.compute_iv_BE h iv /\
h = Vale.AES.AES_BE_s.aes_encrypt_word alg key (Vale.Def.Words_s.Mkfour 0 0 0 0) /\
p_num_bytes < Vale.Def.Words_s.pow2_32 /\ a_num_bytes < Vale.Def.Words_s.pow2_32 /\
length_quad ==
Vale.Def.Words.Four_s.two_two_to_four (Vale.Def.Words_s.Mktwo
(Vale.Def.Words.Two_s.nat_to_two 32 (8 * a_num_bytes))
(Vale.Def.Words.Two_s.nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1 = j0_BE in
let ctr_BE_2 = Vale.AES.GCTR_BE_s.inc32 j0_BE 1 in
let plain =
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true -> FStar.Seq.Base.append p128 p_bytes
| _ -> p128)
<:
FStar.Seq.Base.seq Vale.Def.Types_s.quad32
in
let cipher =
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true -> FStar.Seq.Base.append c128 c_bytes
| _ -> c128)
<:
FStar.Seq.Base.seq Vale.Def.Types_s.quad32
in
let cipher_bound =
FStar.Seq.Base.length p128 +
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true -> 1
| _ -> 0)
in
Vale.AES.GCTR_BE.gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
(match a_num_bytes > FStar.Seq.Base.length a128 * 16 with
| true -> FStar.Seq.Base.append a128 a_bytes
| _ -> a128)
<:
FStar.Seq.Base.seq (Vale.Def.Words_s.four Vale.Def.Words_s.nat32)
in
let auth_input_bytes =
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
auth_raw_quads))
0
a_num_bytes
in
let auth_padded_bytes = Vale.AES.GCTR_BE_s.pad_to_128_bits auth_input_bytes in
let auth_quads = Vale.Def.Types_s.be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = FStar.Seq.Base.append auth_quads p128 in
let total_bytes = FStar.Seq.Base.length auth_quads * 16 + p_num_bytes in
let raw_quads =
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true ->
let raw_quads = FStar.Seq.Base.append raw_quads p_bytes in
let input_bytes =
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
raw_quads))
0
total_bytes
in
let input_padded_bytes = Vale.AES.GCTR_BE_s.pad_to_128_bits input_bytes in
Vale.Def.Types_s.be_bytes_to_seq_quad32 input_padded_bytes
| _ -> raw_quads)
<:
FStar.Seq.Base.seq Vale.Def.Types_s.quad32
in
let final_quads =
FStar.Seq.Base.append raw_quads (FStar.Seq.Base.create 1 length_quad)
in
enc_hash ==
Vale.AES.GCTR_BE_s.gctr_encrypt_block ctr_BE_1
(Vale.AES.GHash_BE_s.ghash_BE h final_quads)
alg
key
0)))
(ensures
(let auth_raw_quads =
(match a_num_bytes > FStar.Seq.Base.length a128 * 16 with
| true -> FStar.Seq.Base.append a128 a_bytes
| _ -> a128)
<:
FStar.Seq.Base.seq (Vale.Def.Words_s.four Vale.Def.Words_s.nat32)
in
let auth_bytes =
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
auth_raw_quads))
0
a_num_bytes
in
let plain_raw_quads =
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true -> FStar.Seq.Base.append p128 p_bytes
| _ -> p128)
<:
FStar.Seq.Base.seq (Vale.Def.Words_s.four Vale.Def.Words_s.nat32)
in
let plain_bytes =
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
plain_raw_quads))
0
p_num_bytes
in
let cipher =
(match p_num_bytes > FStar.Seq.Base.length p128 * 16 with
| true -> FStar.Seq.Base.append c128 c_bytes
| _ -> c128)
<:
FStar.Seq.Base.seq Vale.Def.Types_s.quad32
in
let cipher_bytes =
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
cipher))
0
p_num_bytes
in
FStar.Seq.Base.length auth_bytes < Vale.Def.Words_s.pow2_32 /\
FStar.Seq.Base.length plain_bytes < Vale.Def.Words_s.pow2_32 /\
Vale.Arch.Types.be_quad32_to_bytes enc_hash ==
Vale.AES.GCM_BE.gcm_decrypt_BE_tag alg
(Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE key)
iv
plain_bytes
auth_bytes)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.AES.AES_common_s.algorithm",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat32",
"Vale.Def.Types_s.quad32",
"Prims.nat",
"Vale.AES.GCM_BE_s.supported_iv_BE",
"Prims.unit",
"Prims.op_GreaterThan",
"FStar.Mul.op_Star",
"FStar.Seq.Base.length",
"FStar.Calc.calc_finish",
"Prims.eq2",
"FStar.Seq.Base.append",
"FStar.Seq.Base.create",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"Vale.Def.Types_s.be_bytes_to_seq_quad32",
"Vale.AES.GCTR_BE_s.pad_to_128_bits",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.append_assoc",
"Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE",
"Vale.Def.Words.Seq_s.seq_four_to_seq_BE",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words_s.nat8",
"FStar.Seq.Base.slice",
"Vale.Def.Types_s.nat8",
"Vale.AES.GCM_BE.append_distributes_be_seq_quad32_to_bytes",
"Vale.AES.GCM_BE.slice_append_back",
"Vale.AES.GCM_BE.pad_to_128_bits_multiple_append",
"Vale.Arch.Types.append_distributes_be_bytes_to_seq_quad32",
"Vale.Arch.Types.be_bytes_to_seq_quad32_to_bytes",
"Prims.b2t",
"Prims.op_Equality",
"Prims.bool",
"Vale.AES.GCTR_BE_s.gctr_encrypt",
"Vale.Arch.Types.be_quad32_to_bytes",
"Vale.Def.Words_s.four",
"Vale.Def.Types_s.quad32_xor",
"Vale.AES.AES_BE_s.aes_encrypt_word",
"Vale.AES.GCTR_BE.gctr_encrypt_one_block",
"Vale.Arch.Types.be_seq_quad32_to_bytes_of_singleton",
"Vale.AES.GCTR_BE_s.gctr_encrypt_block",
"Vale.AES.GHash_BE_s.ghash_BE",
"Prims.int",
"Prims.op_Addition",
"Vale.AES.GCTR_BE_s.inc32",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Vale.Def.Words_s.pow2_32",
"Vale.AES.AES_BE_s.is_aes_key_word",
"Vale.AES.GCM_BE_s.compute_iv_BE",
"Vale.Def.Words_s.Mkfour",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Def.Words.Four_s.two_two_to_four",
"Vale.Def.Words_s.Mktwo",
"Vale.Def.Words_s.two",
"Vale.Def.Words.Two_s.nat_to_two",
"Vale.AES.GCTR_BE.gctr_partial",
"Vale.AES.GCM_BE.gcm_decrypt_BE_tag",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let gcm_blocks_dec_helper
(alg: algorithm)
(key: seq nat32)
(a128 a_bytes p128 p_bytes c128 c_bytes: seq quad32)
(p_num_bytes a_num_bytes: nat)
(iv: supported_iv_BE)
(j0_BE h enc_hash length_quad: quad32)
: Lemma
(requires
length p128 * 16 <= p_num_bytes /\ p_num_bytes < length p128 * 16 + 16 /\
length a128 * 16 <= a_num_bytes /\ a_num_bytes < length a128 * 16 + 16 /\
a_num_bytes < pow2_32 /\ length p128 == length c128 /\ length p_bytes == 1 /\
length c_bytes == 1 /\ length a_bytes == 1 /\ is_aes_key_word alg key /\
j0_BE = compute_iv_BE h iv /\ h = aes_encrypt_word alg key (Mkfour 0 0 0 0) /\
p_num_bytes < pow2_32 /\ a_num_bytes < pow2_32 /\
length_quad ==
two_two_to_four (Mktwo (nat_to_two 32 (8 * a_num_bytes)) (nat_to_two 32 (8 * p_num_bytes))) /\
(let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 =
if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then append c128 c_bytes else c128
in
let cipher_bound:nat = length p128 + (if p_num_bytes > length p128 * 16 then 1 else 0) in
gctr_partial alg cipher_bound plain cipher key ctr_BE_2 /\
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_input_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes
in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads p128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16
then
let raw_quads = append raw_quads p_bytes in
let input_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes
in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
enc_hash == gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0)))
(ensures
(let auth_raw_quads =
if a_num_bytes > (length a128) * 16 then append a128 a_bytes else a128
in
let auth_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes
in
let plain_raw_quads =
if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128
in
let plain_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain_raw_quads)) 0 p_num_bytes
in
let cipher:seq quad32 =
if p_num_bytes > length p128 * 16 then append c128 c_bytes else c128
in
let cipher_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes
in
length auth_bytes < pow2_32 /\ length plain_bytes < pow2_32 /\
be_quad32_to_bytes enc_hash ==
gcm_decrypt_BE_tag alg (seq_nat32_to_seq_nat8_BE key) iv plain_bytes auth_bytes)) =
| let ctr_BE_1:quad32 = j0_BE in
let ctr_BE_2:quad32 = inc32 j0_BE 1 in
let plain:seq quad32 = if p_num_bytes > length p128 * 16 then append p128 p_bytes else p128 in
let cipher:seq quad32 = if p_num_bytes > length p128 * 16 then append c128 c_bytes else c128 in
let cipher_bound:nat = length p128 + (if p_num_bytes > length p128 * 16 then 1 else 0) in
let plain_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE plain)) 0 p_num_bytes in
let cipher_bytes = slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE cipher)) 0 p_num_bytes in
let auth_raw_quads = if a_num_bytes > length a128 * 16 then append a128 a_bytes else a128 in
let auth_input_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_raw_quads)) 0 a_num_bytes
in
let auth_padded_bytes = pad_to_128_bits auth_input_bytes in
let auth_quads = be_bytes_to_seq_quad32 auth_padded_bytes in
let raw_quads = append auth_quads p128 in
let total_bytes = length auth_quads * 16 + p_num_bytes in
let raw_quads =
if p_num_bytes > length p128 * 16
then
let raw_quads = append raw_quads p_bytes in
let input_bytes =
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads)) 0 total_bytes
in
let input_padded_bytes = pad_to_128_bits input_bytes in
be_bytes_to_seq_quad32 input_padded_bytes
else raw_quads
in
let final_quads = append raw_quads (create 1 length_quad) in
let hash = ghash_BE h final_quads in
calc ( == ) {
enc_hash;
( == ) { () }
gctr_encrypt_block ctr_BE_1 (ghash_BE h final_quads) alg key 0;
( == ) { () }
gctr_encrypt_block ctr_BE_1 hash alg key 0;
( == ) { () }
quad32_xor hash (aes_encrypt_word alg key ctr_BE_1);
};
calc ( == ) {
gctr_encrypt ctr_BE_1 (be_quad32_to_bytes hash) alg key;
( == ) { gctr_encrypt_one_block ctr_BE_1 hash alg key }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1
(quad32_xor hash (aes_encrypt_word alg key ctr_BE_1))));
( == ) { () }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 enc_hash));
( == ) { be_seq_quad32_to_bytes_of_singleton enc_hash }
be_quad32_to_bytes enc_hash;
};
if p_num_bytes > length p128 * 16
then
(let c = append p128 p_bytes in
calc ( == ) {
append (append auth_quads p128) p_bytes;
( == ) { append_assoc auth_quads p128 p_bytes }
append auth_quads (append p128 p_bytes);
( == ) { () }
append auth_quads c;
};
calc ( == ) {
append (append (append auth_quads p128) p_bytes) (create 1 length_quad);
( = ) { () }
append (append auth_quads (append p128 p_bytes)) (create 1 length_quad);
( == ) { append_assoc auth_quads c (create 1 length_quad) }
append auth_quads (append c (create 1 length_quad));
};
let raw_quads_old = append auth_quads c in
calc ( == ) {
raw_quads;
( == ) { () }
be_bytes_to_seq_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old
))
0
total_bytes));
( == ) { calc ( == ) {
pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old))
0
total_bytes);
( == ) { calc ( == ) {
slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE raw_quads_old)) 0 total_bytes;
( == ) { append_distributes_be_seq_quad32_to_bytes auth_quads c }
slice (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)))
0
total_bytes;
( == ) { slice_append_back (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))
total_bytes }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes);
( == ) { assert (equal (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))
0
p_num_bytes)
plain_bytes) }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)) plain_bytes;
} }
pad_to_128_bits (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
plain_bytes);
( == ) { pad_to_128_bits_multiple_append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads
))
plain_bytes }
append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(pad_to_128_bits plain_bytes);
} }
be_bytes_to_seq_quad32 (append (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads))
(pad_to_128_bits plain_bytes));
( == ) { append_distributes_be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE
auth_quads))
(pad_to_128_bits plain_bytes) }
append (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE auth_quads)))
(be_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes));
( == ) { be_bytes_to_seq_quad32_to_bytes auth_quads }
append auth_quads (be_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes));
};
let auth_padded_quads' = be_bytes_to_seq_quad32 (pad_to_128_bits auth_input_bytes) in
let cipher_padded_quads' = be_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes) in
calc ( == ) {
append raw_quads (create 1 length_quad);
( == ) { () }
append (append auth_quads (be_bytes_to_seq_quad32 (pad_to_128_bits plain_bytes)))
(create 1 length_quad);
( == ) { assert (equal auth_quads auth_padded_quads') }
append (append auth_padded_quads' cipher_padded_quads') (create 1 length_quad);
( == ) { append_assoc auth_padded_quads' cipher_padded_quads' (create 1 length_quad) }
append auth_padded_quads' (append cipher_padded_quads' (create 1 length_quad));
};
())
else
(calc ( == ) {
append (append auth_quads p128) (create 1 length_quad);
( == ) { append_assoc auth_quads p128 (create 1 length_quad) }
append auth_quads (append p128 (create 1 length_quad));
};
let c = p128 in
calc ( == ) {
be_bytes_to_seq_quad32 (pad_to_128_bits (slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c
))
0
p_num_bytes));
( == ) { assert (equal (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))
(slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) 0 p_num_bytes)) }
be_bytes_to_seq_quad32 (pad_to_128_bits (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)));
( == ) { assert (pad_to_128_bits (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c)) ==
(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c))) }
be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE c));
( == ) { be_bytes_to_seq_quad32_to_bytes c }
c;
};
());
() | false |
Pulse.Checker.Prover.Match.fst | Pulse.Checker.Prover.Match.coerce_eq | val coerce_eq: #a: Type -> #b: Type -> x: a -> squash (a == b) -> y: b{y == x} | val coerce_eq: #a: Type -> #b: Type -> x: a -> squash (a == b) -> y: b{y == x} | let coerce_eq (#a #b:Type) (x:a) (_:squash (a == b)) : y:b{y == x} = x | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Match.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 70,
"end_line": 297,
"start_col": 0,
"start_line": 297
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Prover.Match
open Pulse.Syntax
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Typing.Metatheory
open Pulse.Typing.Util
open Pulse.Checker.VPropEquiv
open Pulse.Checker.Prover.Base
open Pulse.Checker.Prover.Util
module RU = Pulse.RuntimeUtils
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module TermEq = FStar.Reflection.V2.TermEq
module T = FStar.Tactics.V2
module RUtil = Pulse.Reflection.Util
module P = Pulse.Syntax.Printer
module PS = Pulse.Checker.Prover.Substs
module Metatheory = Pulse.Typing.Metatheory
let equational (t:term) : bool =
match t.t with
| Tm_FStar host_term ->
(match R.inspect_ln host_term with
| R.Tv_Match _ _ _ -> true
| _ -> false)
| _ -> false
let type_of_fv (g:env) (fv:R.fv)
: T.Tac (option R.term)
= let n = R.inspect_fv fv in
match R.lookup_typ (fstar_env g) n with
| None -> None
| Some se ->
match R.inspect_sigelt se with
| R.Unk -> None
| R.Sg_Let _ lbs -> (
L.tryPick
(fun lb ->
let lbv = R.inspect_lb lb in
if R.inspect_fv lbv.lb_fv = n
then Some lbv.lb_typ
else None)
lbs
)
| R.Sg_Val _ _ t -> Some t
| R.Sg_Inductive _nm _univs params typ _ -> None
let is_smt_fallback (t:R.term) : bool =
match R.inspect_ln t with
| R.Tv_FVar fv ->
let name = R.inspect_fv fv in
name = ["Steel";"Effect";"Common";"smt_fallback"] ||
name = ["Pulse"; "Lib"; "Core"; "equate_by_smt"]
| _ -> false
(*
When comparing t0 =?= t1, if they are not syntactically equal, we
have to decide whether or not we should fire an SMT query to compare
them for provable equality.
The criterion is as follows:
1. We allow an SMT query if either t0 or t1 is "equational". For now, that means
that either is a match expression.
2. Otherwise, if they are both applications of `f v0...vn` and `f u0...un`
of the same head symbol `f`, a top-level constant, then we check if the
type of `f` decorates any of its binders with the `smt_fallback` attribute.
- If none of them are marked as such,
then we check if `f v0...` is syntactically equal to `f u0...`
and allow an SMT query to check if vn = vm. That is, the default behavior
for predicates is that they *last* argument is eligible for SMT equality.
- Otherwise, for each binder that is NOT marked as `smt_fallback`, we check
if the corresponding argument is syntactically equal. If so, we allow
t0 and t1 to be compared for SMT equality.
For example, Steel.ST.Reference.pts_to is defined like so:
/// For instance, [pts_to r (sum_perm (half_perm p) (half_perm p)) (v + 1)]
/// is unifiable with [pts_to r p (1 + v)]
val pts_to (#a:Type0)
(r:ref a)
([@@@smt_fallback] p:perm)
([@@@smt_fallback] v:a)
: vprop
*)
let eligible_for_smt_equality (g:env) (t0 t1:term)
: T.Tac bool
= let either_equational () = equational t0 || equational t1 in
let head_eq (t0 t1:R.term) =
match R.inspect_ln t0, R.inspect_ln t1 with
| R.Tv_App h0 _, R.Tv_App h1 _ ->
TermEq.term_eq h0 h1
| _ -> false
in
match t0.t, t1.t with
| Tm_FStar t0, Tm_FStar t1 -> (
let h0, args0 = R.collect_app_ln t0 in
let h1, args1 = R.collect_app_ln t1 in
if TermEq.term_eq h0 h1 && L.length args0 = L.length args1
then (
match R.inspect_ln h0 with
| R.Tv_FVar fv
| R.Tv_UInst fv _ -> (
match type_of_fv g fv with
| None -> either_equational()
| Some t ->
let bs, _ = R.collect_arr_ln_bs t in
let is_smt_fallback (b:R.binder) =
let bview = R.inspect_binder b in
L.existsb is_smt_fallback bview.attrs
in
let some_fallbacks, fallbacks =
L.fold_right
(fun b (some_fallbacks, bs) ->
if is_smt_fallback b
then true, true::bs
else some_fallbacks, false::bs)
bs (false, [])
in
if not some_fallbacks
then (
//if none of the binders are marked fallback
//then, by default, consider only the last argument as
//fallback
head_eq t0 t1
)
else (
let rec aux args0 args1 fallbacks =
match args0, args1, fallbacks with
| (a0, _)::args0, (a1, _)::args1, b::fallbacks ->
if b
then aux args0 args1 fallbacks
else if not (TermEq.term_eq a0 a1)
then false
else aux args0 args1 fallbacks
| [], [], [] -> true
| _ -> either_equational() //unequal lengths
in
aux args0 args1 fallbacks
)
)
| _ -> either_equational ()
)
else either_equational ()
)
| Tm_ForallSL _ _ _, Tm_ForallSL _ _ _ -> true
| _ -> either_equational ()
let refl_uvar (t:R.term) (uvs:env) : option var =
let open R in
match inspect_ln t with
| Tv_Var v ->
let {uniq=n} = inspect_namedv v in
if contains uvs n then Some n else None
| _ -> None
let is_uvar (t:term) (uvs:env) : option var =
match t.t with
| Tm_FStar t -> refl_uvar t uvs
| _ -> None
let contains_uvar (t:term) (uvs:env) (g:env) : T.Tac bool =
not (check_disjoint uvs (freevars t))
let is_reveal_uvar (t:term) (uvs:env) : option (universe & term & var) =
match is_pure_app t with
| Some (hd, None, arg) ->
(match is_pure_app hd with
| Some (hd, Some Implicit, ty) ->
let arg_uvar_index_opt = is_uvar arg uvs in
(match arg_uvar_index_opt with
| Some n ->
(match is_fvar hd with
| Some (l, [u]) ->
if l = RUtil.reveal_lid
then Some (u, ty, n)
else None
| _ -> None)
| _ -> None)
| _ -> None)
| _ -> None
let is_reveal (t:term) : bool =
match leftmost_head t with
| Some hd ->
(match is_fvar hd with
| Some (l, [_]) -> l = RUtil.reveal_lid
| _ -> false)
| _ -> false
module RT = FStar.Reflection.Typing
//
// Call into the F* unifier to solve for uvs by unifying p and q
//
let try_solve_uvars (g:env) (uvs:env { disjoint uvs g }) (p q:term)
: T.Tac (ss:PS.ss_t { PS.dom ss `Set.subset` freevars q }) =
let uvs = uvs
|> bindings_with_ppname
|> L.rev
|> L.map (fun (({name}, x, t):(ppname & _ & _)) ->
let nv_view = {
R.uniq = x;
R.sort = elab_term t;
R.ppname = name;
} in
let nv = R.pack_namedv nv_view in
nv, elab_term t
) in
let l, issues = RU.with_context (get_context g) (fun _ ->
T.try_unify (elab_env g) uvs (elab_term p) (elab_term q))
in
T.log_issues issues;
// build ss
let ss = PS.empty in
assume (PS.dom ss `Set.subset` freevars q);
match l with
| None -> ss
| Some l ->
let q_names = freevars q in
L.fold_left (fun (ss:(ss:PS.ss_t { PS.dom ss `Set.subset` freevars q })) (x, t) ->
let nv_view = R.inspect_namedv x in
let topt = readback_ty t in
match topt with
| Some t ->
if Set.mem nv_view.uniq q_names &&
not (Set.mem nv_view.uniq (PS.dom ss))
then begin
let ss_new = PS.push ss nv_view.uniq t in
assert (nv_view.uniq `Set.mem` freevars q);
assert (PS.dom ss `Set.subset` freevars q);
assume (PS.dom ss_new `Set.subset` freevars q);
ss_new
end
else ss
| None -> ss
) ss l
let unify (g:env) (uvs:env { disjoint uvs g})
(p q:term)
: T.Tac (ss:PS.ss_t { PS.dom ss `Set.subset` freevars q } &
option (RT.equiv (elab_env g) (elab_term p) (elab_term ss.(q)))) =
let ss = try_solve_uvars g uvs p q in
let q_ss = readback_ty (elab_term ss.(q)) in
match q_ss with
| None -> (| ss, None |)
| Some q ->
if eq_tm p q
then (| ss, Some (RT.Rel_refl _ _ _) |)
else if contains_uvar q uvs g
then (| ss, None |)
else if eligible_for_smt_equality g p q
then let v0 = elab_term p in
let v1 = elab_term q in
match check_equiv_now (elab_env g) v0 v1 with
| Some token, _ -> (| ss, Some (RT.Rel_eq_token _ _ _ (FStar.Squash.return_squash token)) |)
| None, _ -> (| ss, None |)
else (| ss, None |)
let try_match_pq (g:env) (uvs:env { disjoint uvs g}) (p q:vprop)
: T.Tac (ss:PS.ss_t { PS.dom ss `Set.subset` freevars q } &
option (vprop_equiv g p ss.(q))) =
let r = unify g uvs p q in
match r with
| (| ss, None |) -> (| ss, None |)
| (| ss, Some _ |) -> (| ss, Some (RU.magic #(vprop_equiv _ _ _) ()) |) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Util.fsti.checked",
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Readback.fsti.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Prover.Util.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.Match.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.Reflection.Util",
"short_module": "RUtil"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2.TermEq",
"short_module": "TermEq"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.VPropEquiv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Metatheory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: a -> _: Prims.squash (a == b) -> y: b{y == x} | Prims.Tot | [
"total"
] | [] | [
"Prims.squash",
"Prims.eq2"
] | [] | false | false | false | false | false | let coerce_eq (#a: Type) (#b: Type) (x: a) (_: squash (a == b)) : y: b{y == x} =
| x | false |
Pulse.Checker.Prover.Match.fst | Pulse.Checker.Prover.Match.try_match_pq | val try_match_pq (g: env) (uvs: env{disjoint uvs g}) (p q: vprop)
: T.Tac (ss: PS.ss_t{(PS.dom ss) `Set.subset` (freevars q)} & option (vprop_equiv g p ss.(q))) | val try_match_pq (g: env) (uvs: env{disjoint uvs g}) (p q: vprop)
: T.Tac (ss: PS.ss_t{(PS.dom ss) `Set.subset` (freevars q)} & option (vprop_equiv g p ss.(q))) | let try_match_pq (g:env) (uvs:env { disjoint uvs g}) (p q:vprop)
: T.Tac (ss:PS.ss_t { PS.dom ss `Set.subset` freevars q } &
option (vprop_equiv g p ss.(q))) =
let r = unify g uvs p q in
match r with
| (| ss, None |) -> (| ss, None |)
| (| ss, Some _ |) -> (| ss, Some (RU.magic #(vprop_equiv _ _ _) ()) |) | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Match.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 73,
"end_line": 295,
"start_col": 0,
"start_line": 288
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Prover.Match
open Pulse.Syntax
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Typing.Metatheory
open Pulse.Typing.Util
open Pulse.Checker.VPropEquiv
open Pulse.Checker.Prover.Base
open Pulse.Checker.Prover.Util
module RU = Pulse.RuntimeUtils
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module TermEq = FStar.Reflection.V2.TermEq
module T = FStar.Tactics.V2
module RUtil = Pulse.Reflection.Util
module P = Pulse.Syntax.Printer
module PS = Pulse.Checker.Prover.Substs
module Metatheory = Pulse.Typing.Metatheory
let equational (t:term) : bool =
match t.t with
| Tm_FStar host_term ->
(match R.inspect_ln host_term with
| R.Tv_Match _ _ _ -> true
| _ -> false)
| _ -> false
let type_of_fv (g:env) (fv:R.fv)
: T.Tac (option R.term)
= let n = R.inspect_fv fv in
match R.lookup_typ (fstar_env g) n with
| None -> None
| Some se ->
match R.inspect_sigelt se with
| R.Unk -> None
| R.Sg_Let _ lbs -> (
L.tryPick
(fun lb ->
let lbv = R.inspect_lb lb in
if R.inspect_fv lbv.lb_fv = n
then Some lbv.lb_typ
else None)
lbs
)
| R.Sg_Val _ _ t -> Some t
| R.Sg_Inductive _nm _univs params typ _ -> None
let is_smt_fallback (t:R.term) : bool =
match R.inspect_ln t with
| R.Tv_FVar fv ->
let name = R.inspect_fv fv in
name = ["Steel";"Effect";"Common";"smt_fallback"] ||
name = ["Pulse"; "Lib"; "Core"; "equate_by_smt"]
| _ -> false
(*
When comparing t0 =?= t1, if they are not syntactically equal, we
have to decide whether or not we should fire an SMT query to compare
them for provable equality.
The criterion is as follows:
1. We allow an SMT query if either t0 or t1 is "equational". For now, that means
that either is a match expression.
2. Otherwise, if they are both applications of `f v0...vn` and `f u0...un`
of the same head symbol `f`, a top-level constant, then we check if the
type of `f` decorates any of its binders with the `smt_fallback` attribute.
- If none of them are marked as such,
then we check if `f v0...` is syntactically equal to `f u0...`
and allow an SMT query to check if vn = vm. That is, the default behavior
for predicates is that they *last* argument is eligible for SMT equality.
- Otherwise, for each binder that is NOT marked as `smt_fallback`, we check
if the corresponding argument is syntactically equal. If so, we allow
t0 and t1 to be compared for SMT equality.
For example, Steel.ST.Reference.pts_to is defined like so:
/// For instance, [pts_to r (sum_perm (half_perm p) (half_perm p)) (v + 1)]
/// is unifiable with [pts_to r p (1 + v)]
val pts_to (#a:Type0)
(r:ref a)
([@@@smt_fallback] p:perm)
([@@@smt_fallback] v:a)
: vprop
*)
let eligible_for_smt_equality (g:env) (t0 t1:term)
: T.Tac bool
= let either_equational () = equational t0 || equational t1 in
let head_eq (t0 t1:R.term) =
match R.inspect_ln t0, R.inspect_ln t1 with
| R.Tv_App h0 _, R.Tv_App h1 _ ->
TermEq.term_eq h0 h1
| _ -> false
in
match t0.t, t1.t with
| Tm_FStar t0, Tm_FStar t1 -> (
let h0, args0 = R.collect_app_ln t0 in
let h1, args1 = R.collect_app_ln t1 in
if TermEq.term_eq h0 h1 && L.length args0 = L.length args1
then (
match R.inspect_ln h0 with
| R.Tv_FVar fv
| R.Tv_UInst fv _ -> (
match type_of_fv g fv with
| None -> either_equational()
| Some t ->
let bs, _ = R.collect_arr_ln_bs t in
let is_smt_fallback (b:R.binder) =
let bview = R.inspect_binder b in
L.existsb is_smt_fallback bview.attrs
in
let some_fallbacks, fallbacks =
L.fold_right
(fun b (some_fallbacks, bs) ->
if is_smt_fallback b
then true, true::bs
else some_fallbacks, false::bs)
bs (false, [])
in
if not some_fallbacks
then (
//if none of the binders are marked fallback
//then, by default, consider only the last argument as
//fallback
head_eq t0 t1
)
else (
let rec aux args0 args1 fallbacks =
match args0, args1, fallbacks with
| (a0, _)::args0, (a1, _)::args1, b::fallbacks ->
if b
then aux args0 args1 fallbacks
else if not (TermEq.term_eq a0 a1)
then false
else aux args0 args1 fallbacks
| [], [], [] -> true
| _ -> either_equational() //unequal lengths
in
aux args0 args1 fallbacks
)
)
| _ -> either_equational ()
)
else either_equational ()
)
| Tm_ForallSL _ _ _, Tm_ForallSL _ _ _ -> true
| _ -> either_equational ()
let refl_uvar (t:R.term) (uvs:env) : option var =
let open R in
match inspect_ln t with
| Tv_Var v ->
let {uniq=n} = inspect_namedv v in
if contains uvs n then Some n else None
| _ -> None
let is_uvar (t:term) (uvs:env) : option var =
match t.t with
| Tm_FStar t -> refl_uvar t uvs
| _ -> None
let contains_uvar (t:term) (uvs:env) (g:env) : T.Tac bool =
not (check_disjoint uvs (freevars t))
let is_reveal_uvar (t:term) (uvs:env) : option (universe & term & var) =
match is_pure_app t with
| Some (hd, None, arg) ->
(match is_pure_app hd with
| Some (hd, Some Implicit, ty) ->
let arg_uvar_index_opt = is_uvar arg uvs in
(match arg_uvar_index_opt with
| Some n ->
(match is_fvar hd with
| Some (l, [u]) ->
if l = RUtil.reveal_lid
then Some (u, ty, n)
else None
| _ -> None)
| _ -> None)
| _ -> None)
| _ -> None
let is_reveal (t:term) : bool =
match leftmost_head t with
| Some hd ->
(match is_fvar hd with
| Some (l, [_]) -> l = RUtil.reveal_lid
| _ -> false)
| _ -> false
module RT = FStar.Reflection.Typing
//
// Call into the F* unifier to solve for uvs by unifying p and q
//
let try_solve_uvars (g:env) (uvs:env { disjoint uvs g }) (p q:term)
: T.Tac (ss:PS.ss_t { PS.dom ss `Set.subset` freevars q }) =
let uvs = uvs
|> bindings_with_ppname
|> L.rev
|> L.map (fun (({name}, x, t):(ppname & _ & _)) ->
let nv_view = {
R.uniq = x;
R.sort = elab_term t;
R.ppname = name;
} in
let nv = R.pack_namedv nv_view in
nv, elab_term t
) in
let l, issues = RU.with_context (get_context g) (fun _ ->
T.try_unify (elab_env g) uvs (elab_term p) (elab_term q))
in
T.log_issues issues;
// build ss
let ss = PS.empty in
assume (PS.dom ss `Set.subset` freevars q);
match l with
| None -> ss
| Some l ->
let q_names = freevars q in
L.fold_left (fun (ss:(ss:PS.ss_t { PS.dom ss `Set.subset` freevars q })) (x, t) ->
let nv_view = R.inspect_namedv x in
let topt = readback_ty t in
match topt with
| Some t ->
if Set.mem nv_view.uniq q_names &&
not (Set.mem nv_view.uniq (PS.dom ss))
then begin
let ss_new = PS.push ss nv_view.uniq t in
assert (nv_view.uniq `Set.mem` freevars q);
assert (PS.dom ss `Set.subset` freevars q);
assume (PS.dom ss_new `Set.subset` freevars q);
ss_new
end
else ss
| None -> ss
) ss l
let unify (g:env) (uvs:env { disjoint uvs g})
(p q:term)
: T.Tac (ss:PS.ss_t { PS.dom ss `Set.subset` freevars q } &
option (RT.equiv (elab_env g) (elab_term p) (elab_term ss.(q)))) =
let ss = try_solve_uvars g uvs p q in
let q_ss = readback_ty (elab_term ss.(q)) in
match q_ss with
| None -> (| ss, None |)
| Some q ->
if eq_tm p q
then (| ss, Some (RT.Rel_refl _ _ _) |)
else if contains_uvar q uvs g
then (| ss, None |)
else if eligible_for_smt_equality g p q
then let v0 = elab_term p in
let v1 = elab_term q in
match check_equiv_now (elab_env g) v0 v1 with
| Some token, _ -> (| ss, Some (RT.Rel_eq_token _ _ _ (FStar.Squash.return_squash token)) |)
| None, _ -> (| ss, None |)
else (| ss, None |) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Util.fsti.checked",
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Readback.fsti.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Prover.Util.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.Match.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.Reflection.Util",
"short_module": "RUtil"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2.TermEq",
"short_module": "TermEq"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.VPropEquiv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Metatheory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
g: Pulse.Typing.Env.env ->
uvs: Pulse.Typing.Env.env{Pulse.Typing.Env.disjoint uvs g} ->
p: Pulse.Syntax.Base.vprop ->
q: Pulse.Syntax.Base.vprop
-> FStar.Tactics.Effect.Tac
(Prims.dtuple2 (ss:
Pulse.Checker.Prover.Substs.ss_t
{FStar.Set.subset (Pulse.Checker.Prover.Substs.dom ss) (Pulse.Syntax.Naming.freevars q)}
)
(fun ss -> FStar.Pervasives.Native.option (Pulse.Typing.vprop_equiv g p ss.(q)))) | FStar.Tactics.Effect.Tac | [] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Typing.Env.disjoint",
"Pulse.Syntax.Base.vprop",
"Pulse.Checker.Prover.Substs.ss_t",
"FStar.Set.subset",
"Pulse.Syntax.Base.var",
"Pulse.Checker.Prover.Substs.dom",
"Pulse.Syntax.Naming.freevars",
"Prims.Mkdtuple2",
"FStar.Pervasives.Native.option",
"Pulse.Typing.vprop_equiv",
"Pulse.Checker.Prover.Base.op_Array_Access",
"FStar.Pervasives.Native.None",
"FStar.Reflection.Typing.equiv",
"Pulse.Typing.elab_env",
"Pulse.Elaborate.Pure.elab_term",
"FStar.Pervasives.Native.Some",
"Pulse.RuntimeUtils.magic",
"Prims.dtuple2",
"Pulse.Checker.Prover.Match.unify"
] | [] | false | true | false | false | false | let try_match_pq (g: env) (uvs: env{disjoint uvs g}) (p q: vprop)
: T.Tac (ss: PS.ss_t{(PS.dom ss) `Set.subset` (freevars q)} & option (vprop_equiv g p ss.(q))) =
| let r = unify g uvs p q in
match r with
| (| ss , None |) -> (| ss, None |)
| (| ss , Some _ |) -> (| ss, Some (RU.magic #(vprop_equiv _ _ _) ()) |) | false |
Hacl.Impl.Ed25519.Group.fst | Hacl.Impl.Ed25519.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/ed25519/Hacl.Impl.Ed25519.Group.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 28,
"start_col": 0,
"start_line": 28
} | module Hacl.Impl.Ed25519.Group
module ST = FStar.HyperStack.ST
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum25519
open Hacl.Impl.Ed25519.PointConstants
module LSeq = Lib.Sequence
module F51 = Hacl.Impl.Ed25519.Field51
module BE = Hacl.Impl.Exponentiation.Definitions
module S = Spec.Ed25519
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let a_spec = S.aff_point_c
unfold
let refl (a:LSeq.lseq uint64 20{F51.linv a}) : GTot a_spec =
S.to_aff_point (F51.refl_ext_point a) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.Lemmas.fsti.checked",
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Exponentiation.Definitions.fst.checked",
"Hacl.Impl.Ed25519.PointDouble.fst.checked",
"Hacl.Impl.Ed25519.PointConstants.fst.checked",
"Hacl.Impl.Ed25519.PointAdd.fst.checked",
"Hacl.Impl.Ed25519.Field51.fst.checked",
"Hacl.Bignum25519.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Ed25519.Group.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Field51",
"short_module": "F51"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519.PointConstants",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
Pulse.Checker.Prover.Match.fst | Pulse.Checker.Prover.Match.match_q_aux | val match_q_aux:
#preamble: _ ->
pst: prover_state preamble ->
q: vprop ->
unsolved': list vprop ->
squash (pst.unsolved == q :: unsolved') ->
i: nat
-> T.Tac (option (pst': prover_state preamble {pst' `pst_extends` pst})) | val match_q_aux:
#preamble: _ ->
pst: prover_state preamble ->
q: vprop ->
unsolved': list vprop ->
squash (pst.unsolved == q :: unsolved') ->
i: nat
-> T.Tac (option (pst': prover_state preamble {pst' `pst_extends` pst})) | let rec match_q_aux (#preamble:_) (pst:prover_state preamble)
(q:vprop) (unsolved':list vprop)
(_:squash (pst.unsolved == q::unsolved'))
(i:nat)
: T.Tac (option (pst':prover_state preamble { pst' `pst_extends` pst })) =
if L.length pst.remaining_ctxt = 0
then None
else if i = L.length pst.remaining_ctxt
then None
else
let p = L.hd pst.remaining_ctxt in
let pst_opt =
match_step pst p (L.tl pst.remaining_ctxt) q unsolved' () in
match pst_opt with
| Some pst -> Some pst
| None ->
let pst =
remaining_ctxt_equiv_pst pst (L.tl pst.remaining_ctxt @ [L.hd pst.remaining_ctxt])
(move_hd_end pst.pg pst.remaining_ctxt) in
match_q_aux pst q unsolved' () (i+1) | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Match.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 42,
"end_line": 403,
"start_col": 0,
"start_line": 383
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Prover.Match
open Pulse.Syntax
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Typing.Metatheory
open Pulse.Typing.Util
open Pulse.Checker.VPropEquiv
open Pulse.Checker.Prover.Base
open Pulse.Checker.Prover.Util
module RU = Pulse.RuntimeUtils
module L = FStar.List.Tot
module R = FStar.Reflection.V2
module TermEq = FStar.Reflection.V2.TermEq
module T = FStar.Tactics.V2
module RUtil = Pulse.Reflection.Util
module P = Pulse.Syntax.Printer
module PS = Pulse.Checker.Prover.Substs
module Metatheory = Pulse.Typing.Metatheory
let equational (t:term) : bool =
match t.t with
| Tm_FStar host_term ->
(match R.inspect_ln host_term with
| R.Tv_Match _ _ _ -> true
| _ -> false)
| _ -> false
let type_of_fv (g:env) (fv:R.fv)
: T.Tac (option R.term)
= let n = R.inspect_fv fv in
match R.lookup_typ (fstar_env g) n with
| None -> None
| Some se ->
match R.inspect_sigelt se with
| R.Unk -> None
| R.Sg_Let _ lbs -> (
L.tryPick
(fun lb ->
let lbv = R.inspect_lb lb in
if R.inspect_fv lbv.lb_fv = n
then Some lbv.lb_typ
else None)
lbs
)
| R.Sg_Val _ _ t -> Some t
| R.Sg_Inductive _nm _univs params typ _ -> None
let is_smt_fallback (t:R.term) : bool =
match R.inspect_ln t with
| R.Tv_FVar fv ->
let name = R.inspect_fv fv in
name = ["Steel";"Effect";"Common";"smt_fallback"] ||
name = ["Pulse"; "Lib"; "Core"; "equate_by_smt"]
| _ -> false
(*
When comparing t0 =?= t1, if they are not syntactically equal, we
have to decide whether or not we should fire an SMT query to compare
them for provable equality.
The criterion is as follows:
1. We allow an SMT query if either t0 or t1 is "equational". For now, that means
that either is a match expression.
2. Otherwise, if they are both applications of `f v0...vn` and `f u0...un`
of the same head symbol `f`, a top-level constant, then we check if the
type of `f` decorates any of its binders with the `smt_fallback` attribute.
- If none of them are marked as such,
then we check if `f v0...` is syntactically equal to `f u0...`
and allow an SMT query to check if vn = vm. That is, the default behavior
for predicates is that they *last* argument is eligible for SMT equality.
- Otherwise, for each binder that is NOT marked as `smt_fallback`, we check
if the corresponding argument is syntactically equal. If so, we allow
t0 and t1 to be compared for SMT equality.
For example, Steel.ST.Reference.pts_to is defined like so:
/// For instance, [pts_to r (sum_perm (half_perm p) (half_perm p)) (v + 1)]
/// is unifiable with [pts_to r p (1 + v)]
val pts_to (#a:Type0)
(r:ref a)
([@@@smt_fallback] p:perm)
([@@@smt_fallback] v:a)
: vprop
*)
let eligible_for_smt_equality (g:env) (t0 t1:term)
: T.Tac bool
= let either_equational () = equational t0 || equational t1 in
let head_eq (t0 t1:R.term) =
match R.inspect_ln t0, R.inspect_ln t1 with
| R.Tv_App h0 _, R.Tv_App h1 _ ->
TermEq.term_eq h0 h1
| _ -> false
in
match t0.t, t1.t with
| Tm_FStar t0, Tm_FStar t1 -> (
let h0, args0 = R.collect_app_ln t0 in
let h1, args1 = R.collect_app_ln t1 in
if TermEq.term_eq h0 h1 && L.length args0 = L.length args1
then (
match R.inspect_ln h0 with
| R.Tv_FVar fv
| R.Tv_UInst fv _ -> (
match type_of_fv g fv with
| None -> either_equational()
| Some t ->
let bs, _ = R.collect_arr_ln_bs t in
let is_smt_fallback (b:R.binder) =
let bview = R.inspect_binder b in
L.existsb is_smt_fallback bview.attrs
in
let some_fallbacks, fallbacks =
L.fold_right
(fun b (some_fallbacks, bs) ->
if is_smt_fallback b
then true, true::bs
else some_fallbacks, false::bs)
bs (false, [])
in
if not some_fallbacks
then (
//if none of the binders are marked fallback
//then, by default, consider only the last argument as
//fallback
head_eq t0 t1
)
else (
let rec aux args0 args1 fallbacks =
match args0, args1, fallbacks with
| (a0, _)::args0, (a1, _)::args1, b::fallbacks ->
if b
then aux args0 args1 fallbacks
else if not (TermEq.term_eq a0 a1)
then false
else aux args0 args1 fallbacks
| [], [], [] -> true
| _ -> either_equational() //unequal lengths
in
aux args0 args1 fallbacks
)
)
| _ -> either_equational ()
)
else either_equational ()
)
| Tm_ForallSL _ _ _, Tm_ForallSL _ _ _ -> true
| _ -> either_equational ()
let refl_uvar (t:R.term) (uvs:env) : option var =
let open R in
match inspect_ln t with
| Tv_Var v ->
let {uniq=n} = inspect_namedv v in
if contains uvs n then Some n else None
| _ -> None
let is_uvar (t:term) (uvs:env) : option var =
match t.t with
| Tm_FStar t -> refl_uvar t uvs
| _ -> None
let contains_uvar (t:term) (uvs:env) (g:env) : T.Tac bool =
not (check_disjoint uvs (freevars t))
let is_reveal_uvar (t:term) (uvs:env) : option (universe & term & var) =
match is_pure_app t with
| Some (hd, None, arg) ->
(match is_pure_app hd with
| Some (hd, Some Implicit, ty) ->
let arg_uvar_index_opt = is_uvar arg uvs in
(match arg_uvar_index_opt with
| Some n ->
(match is_fvar hd with
| Some (l, [u]) ->
if l = RUtil.reveal_lid
then Some (u, ty, n)
else None
| _ -> None)
| _ -> None)
| _ -> None)
| _ -> None
let is_reveal (t:term) : bool =
match leftmost_head t with
| Some hd ->
(match is_fvar hd with
| Some (l, [_]) -> l = RUtil.reveal_lid
| _ -> false)
| _ -> false
module RT = FStar.Reflection.Typing
//
// Call into the F* unifier to solve for uvs by unifying p and q
//
let try_solve_uvars (g:env) (uvs:env { disjoint uvs g }) (p q:term)
: T.Tac (ss:PS.ss_t { PS.dom ss `Set.subset` freevars q }) =
let uvs = uvs
|> bindings_with_ppname
|> L.rev
|> L.map (fun (({name}, x, t):(ppname & _ & _)) ->
let nv_view = {
R.uniq = x;
R.sort = elab_term t;
R.ppname = name;
} in
let nv = R.pack_namedv nv_view in
nv, elab_term t
) in
let l, issues = RU.with_context (get_context g) (fun _ ->
T.try_unify (elab_env g) uvs (elab_term p) (elab_term q))
in
T.log_issues issues;
// build ss
let ss = PS.empty in
assume (PS.dom ss `Set.subset` freevars q);
match l with
| None -> ss
| Some l ->
let q_names = freevars q in
L.fold_left (fun (ss:(ss:PS.ss_t { PS.dom ss `Set.subset` freevars q })) (x, t) ->
let nv_view = R.inspect_namedv x in
let topt = readback_ty t in
match topt with
| Some t ->
if Set.mem nv_view.uniq q_names &&
not (Set.mem nv_view.uniq (PS.dom ss))
then begin
let ss_new = PS.push ss nv_view.uniq t in
assert (nv_view.uniq `Set.mem` freevars q);
assert (PS.dom ss `Set.subset` freevars q);
assume (PS.dom ss_new `Set.subset` freevars q);
ss_new
end
else ss
| None -> ss
) ss l
let unify (g:env) (uvs:env { disjoint uvs g})
(p q:term)
: T.Tac (ss:PS.ss_t { PS.dom ss `Set.subset` freevars q } &
option (RT.equiv (elab_env g) (elab_term p) (elab_term ss.(q)))) =
let ss = try_solve_uvars g uvs p q in
let q_ss = readback_ty (elab_term ss.(q)) in
match q_ss with
| None -> (| ss, None |)
| Some q ->
if eq_tm p q
then (| ss, Some (RT.Rel_refl _ _ _) |)
else if contains_uvar q uvs g
then (| ss, None |)
else if eligible_for_smt_equality g p q
then let v0 = elab_term p in
let v1 = elab_term q in
match check_equiv_now (elab_env g) v0 v1 with
| Some token, _ -> (| ss, Some (RT.Rel_eq_token _ _ _ (FStar.Squash.return_squash token)) |)
| None, _ -> (| ss, None |)
else (| ss, None |)
let try_match_pq (g:env) (uvs:env { disjoint uvs g}) (p q:vprop)
: T.Tac (ss:PS.ss_t { PS.dom ss `Set.subset` freevars q } &
option (vprop_equiv g p ss.(q))) =
let r = unify g uvs p q in
match r with
| (| ss, None |) -> (| ss, None |)
| (| ss, Some _ |) -> (| ss, Some (RU.magic #(vprop_equiv _ _ _) ()) |)
let coerce_eq (#a #b:Type) (x:a) (_:squash (a == b)) : y:b{y == x} = x
let match_step (#preamble:preamble) (pst:prover_state preamble)
(p:vprop) (remaining_ctxt':list vprop)
(q:vprop) (unsolved':list vprop)
(_:squash (pst.remaining_ctxt == p::remaining_ctxt' /\
pst.unsolved == q::unsolved'))
: T.Tac (option (pst':prover_state preamble { pst' `pst_extends` pst })) =
let q_ss = pst.ss.(q) in
assume (freevars q_ss `Set.disjoint` PS.dom pst.ss);
let (| ss_q, ropt |) = try_match_pq pst.pg pst.uvs p q_ss in
debug_prover pst.pg (fun _ ->
Printf.sprintf "prover matcher: tried to match p %s and q (partially substituted) %s, result: %s"
(P.term_to_string p) (P.term_to_string (ss_q.(q_ss))) (if None? ropt then "fail" else "success"));
match ropt with
| None -> None
| Some veq ->
assert (PS.dom ss_q `Set.disjoint` PS.dom pst.ss);
let ss_new = PS.push_ss pst.ss ss_q in
let veq : vprop_equiv pst.pg p (ss_q.(pst.ss.(q))) = veq in
assume (ss_q.(pst.ss.(q)) == ss_new.(q));
let veq : vprop_equiv pst.pg p ss_new.(q) = coerce_eq veq () in
let remaining_ctxt_new = remaining_ctxt' in
let solved_new = q * pst.solved in
let unsolved_new = unsolved' in
let k
: continuation_elaborator
preamble.g0 (preamble.ctxt * preamble.frame)
pst.pg ((list_as_vprop pst.remaining_ctxt * preamble.frame) * pst.ss.(pst.solved)) = pst.k in
assume (pst.ss.(pst.solved) == ss_new.(pst.solved));
let k
: continuation_elaborator
preamble.g0 (preamble.ctxt * preamble.frame)
pst.pg ((list_as_vprop (p::remaining_ctxt_new) * preamble.frame) * ss_new.(pst.solved)) =
coerce_eq k () in
let k
: continuation_elaborator
preamble.g0 (preamble.ctxt * preamble.frame)
pst.pg ((list_as_vprop remaining_ctxt_new * preamble.frame) * (ss_new.(q) * ss_new.(pst.solved))) =
k_elab_equiv k (VE_Refl _ _) (RU.magic ()) in
assume (ss_new.(q) * ss_new.(pst.solved) == ss_new.(q * pst.solved));
let k
: continuation_elaborator
preamble.g0 (preamble.ctxt * preamble.frame)
pst.pg ((list_as_vprop remaining_ctxt_new * preamble.frame) * (ss_new.(solved_new))) =
coerce_eq k () in
assume (freevars ss_new.(solved_new) `Set.subset` dom pst.pg);
let pst' : prover_state preamble =
{ pst with remaining_ctxt=remaining_ctxt_new;
remaining_ctxt_frame_typing=RU.magic ();
ss=ss_new;
nts=None;
solved=solved_new;
unsolved=unsolved_new;
k;
goals_inv=RU.magic ();
solved_inv=() } in
assume (ss_new `ss_extends` pst.ss);
Some pst'
let move_hd_end (g:env) (l:list vprop { Cons? l })
: vprop_equiv g (list_as_vprop l) (list_as_vprop (L.tl l @ [L.hd l])) = RU.magic ()
let remaining_ctxt_equiv_pst (#preamble:_) (pst:prover_state preamble) (remaining_ctxt':list vprop)
(d:vprop_equiv pst.pg (list_as_vprop pst.remaining_ctxt) (list_as_vprop remaining_ctxt'))
: prover_state preamble =
{ pst with remaining_ctxt = remaining_ctxt';
remaining_ctxt_frame_typing = RU.magic ();
k = k_elab_equiv pst.k (VE_Refl _ _) (RU.magic ()) } | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Util.fsti.checked",
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Readback.fsti.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Prover.Util.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Squash.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Reflection.V2.TermEq.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.Match.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Pulse.Reflection.Util",
"short_module": "RUtil"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2.TermEq",
"short_module": "TermEq"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.VPropEquiv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Metatheory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
pst: Pulse.Checker.Prover.Base.prover_state preamble ->
q: Pulse.Syntax.Base.vprop ->
unsolved': Prims.list Pulse.Syntax.Base.vprop ->
_: Prims.squash (Mkprover_state?.unsolved pst == q :: unsolved') ->
i: Prims.nat
-> FStar.Tactics.Effect.Tac
(FStar.Pervasives.Native.option (pst':
Pulse.Checker.Prover.Base.prover_state preamble
{Pulse.Checker.Prover.Base.pst_extends pst' pst})) | FStar.Tactics.Effect.Tac | [] | [] | [
"Pulse.Checker.Prover.Base.preamble",
"Pulse.Checker.Prover.Base.prover_state",
"Pulse.Syntax.Base.vprop",
"Prims.list",
"Prims.squash",
"Prims.eq2",
"Pulse.Checker.Prover.Base.__proj__Mkprover_state__item__unsolved",
"Prims.Cons",
"Prims.nat",
"Prims.op_Equality",
"Prims.int",
"FStar.List.Tot.Base.length",
"Pulse.Checker.Prover.Base.__proj__Mkprover_state__item__remaining_ctxt",
"FStar.Pervasives.Native.None",
"Pulse.Checker.Prover.Base.pst_extends",
"FStar.Pervasives.Native.option",
"Prims.bool",
"FStar.Pervasives.Native.Some",
"Pulse.Checker.Prover.Match.match_q_aux",
"Prims.op_Addition",
"Pulse.Checker.Prover.Match.remaining_ctxt_equiv_pst",
"FStar.List.Tot.Base.append",
"FStar.List.Tot.Base.tl",
"FStar.List.Tot.Base.hd",
"Prims.Nil",
"Pulse.Checker.Prover.Match.move_hd_end",
"Pulse.Checker.Prover.Base.__proj__Mkprover_state__item__pg",
"Pulse.Checker.Prover.Match.match_step"
] | [
"recursion"
] | false | true | false | false | false | let rec match_q_aux
(#preamble: _)
(pst: prover_state preamble)
(q: vprop)
(unsolved': list vprop)
(_: squash (pst.unsolved == q :: unsolved'))
(i: nat)
: T.Tac (option (pst': prover_state preamble {pst' `pst_extends` pst})) =
| if L.length pst.remaining_ctxt = 0
then None
else
if i = L.length pst.remaining_ctxt
then None
else
let p = L.hd pst.remaining_ctxt in
let pst_opt = match_step pst p (L.tl pst.remaining_ctxt) q unsolved' () in
match pst_opt with
| Some pst -> Some pst
| None ->
let pst =
remaining_ctxt_equiv_pst pst
(L.tl pst.remaining_ctxt @ [L.hd pst.remaining_ctxt])
(move_hd_end pst.pg pst.remaining_ctxt)
in
match_q_aux pst q unsolved' () (i + 1) | false |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.