effect
stringclasses 48
values | original_source_type
stringlengths 0
23k
| opens_and_abbrevs
listlengths 2
92
| isa_cross_project_example
bool 1
class | source_definition
stringlengths 9
57.9k
| partial_definition
stringlengths 7
23.3k
| is_div
bool 2
classes | is_type
null | is_proof
bool 2
classes | completed_definiton
stringlengths 1
250k
| dependencies
dict | effect_flags
sequencelengths 0
2
| ideal_premises
sequencelengths 0
236
| mutual_with
sequencelengths 0
11
| file_context
stringlengths 0
407k
| interleaved
bool 1
class | is_simply_typed
bool 2
classes | file_name
stringlengths 5
48
| vconfig
dict | is_simple_lemma
null | source_type
stringlengths 10
23k
| proof_features
sequencelengths 0
1
| name
stringlengths 8
95
| source
dict | verbose_type
stringlengths 1
7.42k
| source_range
dict |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Prims.Tot | val step3_body'_aux
(mi: word_block)
(st: words_state SHA1)
(t: size_t{v t < 80})
(wt: word SHA1 {wt == w mi t})
: Tot (words_state SHA1) | [
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "Spec.Hash.Definitions",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let step3_body'_aux
(mi: word_block)
(st: words_state SHA1)
(t: size_t {v t < 80})
(wt: word SHA1 { wt == w mi t } )
: Tot (words_state SHA1)
= let sta = Seq.index st 0 in
let stb = Seq.index st 1 in
let stc = Seq.index st 2 in
let std = Seq.index st 3 in
let ste = Seq.index st 4 in
let _T = (sta <<<. 5ul) +. f t stb stc std +. ste +. k t +. wt in
let e = std in
let d = stc in
let c = stb <<<. 30ul in
let b = sta in
let a = _T in
let l : list uint32 = [
a;
b;
c;
d;
e;
] in
assert_norm (List.Tot.length l = 5);
Seq.seq_of_list l | val step3_body'_aux
(mi: word_block)
(st: words_state SHA1)
(t: size_t{v t < 80})
(wt: word SHA1 {wt == w mi t})
: Tot (words_state SHA1)
let step3_body'_aux
(mi: word_block)
(st: words_state SHA1)
(t: size_t{v t < 80})
(wt: word SHA1 {wt == w mi t})
: Tot (words_state SHA1) = | false | null | false | let sta = Seq.index st 0 in
let stb = Seq.index st 1 in
let stc = Seq.index st 2 in
let std = Seq.index st 3 in
let ste = Seq.index st 4 in
let _T = (sta <<<. 5ul) +. f t stb stc std +. ste +. k t +. wt in
let e = std in
let d = stc in
let c = stb <<<. 30ul in
let b = sta in
let a = _T in
let l:list uint32 = [a; b; c; d; e] in
assert_norm (List.Tot.length l = 5);
Seq.seq_of_list l | {
"checked_file": "Spec.SHA1.fst.checked",
"dependencies": [
"Spec.Loops.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.SHA1.fst"
} | [
"total"
] | [
"Spec.SHA1.word_block",
"Spec.Hash.Definitions.words_state",
"Spec.Hash.Definitions.SHA1",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Spec.Hash.Definitions.word",
"Prims.eq2",
"Spec.SHA1.w",
"FStar.Seq.Properties.seq_of_list",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.op_Equality",
"Prims.int",
"FStar.List.Tot.Base.length",
"Prims.list",
"Prims.Cons",
"Prims.Nil",
"Spec.Hash.Definitions.word_t",
"Lib.IntTypes.op_Less_Less_Less_Dot",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.op_Plus_Dot",
"Spec.SHA1.f",
"Spec.SHA1.k",
"FStar.Seq.Base.index"
] | [] | module Spec.SHA1
open Lib.IntTypes
module H = Spec.Hash.Definitions
module Seq = FStar.Seq
open Spec.Hash.Definitions
(* Source: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf *)
(* Section 5.3.1 *)
inline_for_extraction
let init_as_list : list uint32 = [
u32 0x67452301;
u32 0xefcdab89;
u32 0x98badcfe;
u32 0x10325476;
u32 0xc3d2e1f0;
]
let init : words_state SHA1 = Seq.seq_of_list init_as_list
(* Section 6.1.2 Step 1: message schedule *)
let rec w' (mi: Seq.lseq (word SHA1) (block_word_length SHA1)) (t: nat {t <= 79}) : GTot (word SHA1) (decreases (t)) =
if t < 16
then Seq.index mi (t)
else (w' mi (t - 3) ^. w' mi (t - 8) ^. w' mi (t - 14) ^. w' mi (t - 16)) <<<. 1ul
let w (mi: Seq.lseq (word SHA1) (block_word_length SHA1)) (t: size_t {v t <= 79}) : GTot (word SHA1) = w' mi (v t)
let compute_w_post
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat)
(res: Seq.lseq (word SHA1) n)
: GTot Type0
= (n <= 80 /\ (
forall (i: nat) . i < n ==> Seq.index res i == w' mi i
))
let compute_w_post_intro
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat)
(res: Seq.lseq (word SHA1) n)
(u: squash (n <= 80))
(f: (i: nat) -> Lemma
(requires (i < n))
(ensures (i < n /\ Seq.index res i == w' mi i)))
: Lemma
(compute_w_post mi n res)
= Classical.forall_intro (Classical.move_requires f)
inline_for_extraction
let compute_w_n'
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat { n <= 79 } )
(w: ((i: nat {i < n}) -> Tot (y: word SHA1 {y == w' mi i})))
: Tot (y: word SHA1 {y == w' mi n})
= let r =
if n < 16
then Seq.index mi n
else (w (n - 3) ^. w (n - 8) ^. w (n - 14) ^. w (n - 16)) <<<. 1ul
in
r
inline_for_extraction
let compute_w_n
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat { n <= 79 } )
(accu: Seq.lseq (word SHA1) n)
: Pure (word SHA1)
(requires (compute_w_post mi n accu))
(ensures (fun y -> n <= 79 /\ y == w' mi n))
= [@inline_let]
let w (i: nat {i < n}) : Tot (y: word SHA1 {y == w' mi i}) = Seq.index accu i in
compute_w_n' mi n w
inline_for_extraction
let compute_w_next
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat { n <= 79 } )
(accu: Seq.lseq (word SHA1) n)
: Pure (Seq.lseq (word SHA1) (n + 1))
(requires (compute_w_post mi n accu))
(ensures (fun accu' -> compute_w_post mi (n + 1) accu'))
= let wn = compute_w_n mi n accu in
let accu' = Seq.snoc accu wn in
assert (n + 1 <= 80);
let g
(i: nat)
: Lemma
(requires (i < n + 1))
(ensures (i < n + 1 /\ Seq.index accu' i == w' mi i))
= if i = n
then ()
else ()
in
compute_w_post_intro mi (n + 1) accu' () g;
accu'
let rec compute_w
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat)
(accu: Seq.lseq (word SHA1) n)
: Pure (Seq.lseq (word SHA1) 80)
(requires (compute_w_post mi n accu))
(ensures (fun res -> compute_w_post mi 80 res))
(decreases (80 - n))
= assert (n <= 80); // this assert is necessary for Z3 to prove that n <= 79 in the else branch
if n = 80
then accu
else compute_w mi (n + 1) (compute_w_next mi n accu)
(* Section 4.1.1: logical functions *)
inline_for_extraction
let f (t: size_t {v t <= 79}) (x y z: word SHA1) : Tot (word SHA1) =
if t <. 20ul
then
(x &. y) ^. (~. x &. z)
else if 39ul <. t && t <. 60ul
then
(x &. y) ^. (x &. z) ^. (y &. z)
else
x ^. y ^. z
(* Section 4.2.1 *)
inline_for_extraction
let k (t: size_t { v t <= 79 } ) : Tot (word SHA1) =
if t <. 20ul
then u32 0x5a827999
else if t <. 40ul
then u32 0x6ed9eba1
else if t <. 60ul
then u32 0x8f1bbcdc
else u32 0xca62c1d6
(* Section 6.1.2 Step 3 *)
let word_block = Seq.lseq (word SHA1) (block_word_length SHA1)
let step3_body'_aux
(mi: word_block)
(st: words_state SHA1)
(t: size_t {v t < 80})
(wt: word SHA1 { wt == w mi t } ) | false | false | Spec.SHA1.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val step3_body'_aux
(mi: word_block)
(st: words_state SHA1)
(t: size_t{v t < 80})
(wt: word SHA1 {wt == w mi t})
: Tot (words_state SHA1) | [] | Spec.SHA1.step3_body'_aux | {
"file_name": "specs/Spec.SHA1.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
mi: Spec.SHA1.word_block ->
st: Spec.Hash.Definitions.words_state Spec.Hash.Definitions.SHA1 ->
t: Lib.IntTypes.size_t{Lib.IntTypes.v t < 80} ->
wt: Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA1 {wt == Spec.SHA1.w mi t}
-> Spec.Hash.Definitions.words_state Spec.Hash.Definitions.SHA1 | {
"end_col": 19,
"end_line": 168,
"start_col": 1,
"start_line": 149
} |
FStar.Pervasives.Lemma | val compute_w_post_intro
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat)
(res: Seq.lseq (word SHA1) n)
(u: squash (n <= 80))
(f: (i: nat -> Lemma (requires (i < n)) (ensures (i < n /\ Seq.index res i == w' mi i))))
: Lemma (compute_w_post mi n res) | [
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "Spec.Hash.Definitions",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let compute_w_post_intro
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat)
(res: Seq.lseq (word SHA1) n)
(u: squash (n <= 80))
(f: (i: nat) -> Lemma
(requires (i < n))
(ensures (i < n /\ Seq.index res i == w' mi i)))
: Lemma
(compute_w_post mi n res)
= Classical.forall_intro (Classical.move_requires f) | val compute_w_post_intro
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat)
(res: Seq.lseq (word SHA1) n)
(u: squash (n <= 80))
(f: (i: nat -> Lemma (requires (i < n)) (ensures (i < n /\ Seq.index res i == w' mi i))))
: Lemma (compute_w_post mi n res)
let compute_w_post_intro
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat)
(res: Seq.lseq (word SHA1) n)
(u: squash (n <= 80))
(f: (i: nat -> Lemma (requires (i < n)) (ensures (i < n /\ Seq.index res i == w' mi i))))
: Lemma (compute_w_post mi n res) = | false | null | true | Classical.forall_intro (Classical.move_requires f) | {
"checked_file": "Spec.SHA1.fst.checked",
"dependencies": [
"Spec.Loops.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.SHA1.fst"
} | [
"lemma"
] | [
"FStar.Seq.Properties.lseq",
"Spec.Hash.Definitions.word",
"Spec.Hash.Definitions.SHA1",
"Spec.Hash.Definitions.block_word_length",
"Prims.nat",
"Prims.squash",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.unit",
"Prims.op_LessThan",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.index",
"Spec.SHA1.w'",
"Prims.Nil",
"FStar.Pervasives.pattern",
"FStar.Classical.forall_intro",
"Prims.l_imp",
"FStar.Classical.move_requires",
"Prims.l_True",
"Spec.SHA1.compute_w_post"
] | [] | module Spec.SHA1
open Lib.IntTypes
module H = Spec.Hash.Definitions
module Seq = FStar.Seq
open Spec.Hash.Definitions
(* Source: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf *)
(* Section 5.3.1 *)
inline_for_extraction
let init_as_list : list uint32 = [
u32 0x67452301;
u32 0xefcdab89;
u32 0x98badcfe;
u32 0x10325476;
u32 0xc3d2e1f0;
]
let init : words_state SHA1 = Seq.seq_of_list init_as_list
(* Section 6.1.2 Step 1: message schedule *)
let rec w' (mi: Seq.lseq (word SHA1) (block_word_length SHA1)) (t: nat {t <= 79}) : GTot (word SHA1) (decreases (t)) =
if t < 16
then Seq.index mi (t)
else (w' mi (t - 3) ^. w' mi (t - 8) ^. w' mi (t - 14) ^. w' mi (t - 16)) <<<. 1ul
let w (mi: Seq.lseq (word SHA1) (block_word_length SHA1)) (t: size_t {v t <= 79}) : GTot (word SHA1) = w' mi (v t)
let compute_w_post
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat)
(res: Seq.lseq (word SHA1) n)
: GTot Type0
= (n <= 80 /\ (
forall (i: nat) . i < n ==> Seq.index res i == w' mi i
))
let compute_w_post_intro
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat)
(res: Seq.lseq (word SHA1) n)
(u: squash (n <= 80))
(f: (i: nat) -> Lemma
(requires (i < n))
(ensures (i < n /\ Seq.index res i == w' mi i)))
: Lemma | false | false | Spec.SHA1.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val compute_w_post_intro
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat)
(res: Seq.lseq (word SHA1) n)
(u: squash (n <= 80))
(f: (i: nat -> Lemma (requires (i < n)) (ensures (i < n /\ Seq.index res i == w' mi i))))
: Lemma (compute_w_post mi n res) | [] | Spec.SHA1.compute_w_post_intro | {
"file_name": "specs/Spec.SHA1.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
mi:
FStar.Seq.Properties.lseq (Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA1)
(Spec.Hash.Definitions.block_word_length Spec.Hash.Definitions.SHA1) ->
n: Prims.nat ->
res: FStar.Seq.Properties.lseq (Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA1) n ->
u15: Prims.squash (n <= 80) ->
f:
(i: Prims.nat
-> FStar.Pervasives.Lemma (requires i < n)
(ensures i < n /\ FStar.Seq.Base.index res i == Spec.SHA1.w' mi i))
-> FStar.Pervasives.Lemma (ensures Spec.SHA1.compute_w_post mi n res) | {
"end_col": 52,
"end_line": 51,
"start_col": 2,
"start_line": 51
} |
Prims.GTot | val w' (mi: Seq.lseq (word SHA1) (block_word_length SHA1)) (t: nat{t <= 79})
: GTot (word SHA1) (decreases (t)) | [
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "Spec.Hash.Definitions",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec w' (mi: Seq.lseq (word SHA1) (block_word_length SHA1)) (t: nat {t <= 79}) : GTot (word SHA1) (decreases (t)) =
if t < 16
then Seq.index mi (t)
else (w' mi (t - 3) ^. w' mi (t - 8) ^. w' mi (t - 14) ^. w' mi (t - 16)) <<<. 1ul | val w' (mi: Seq.lseq (word SHA1) (block_word_length SHA1)) (t: nat{t <= 79})
: GTot (word SHA1) (decreases (t))
let rec w' (mi: Seq.lseq (word SHA1) (block_word_length SHA1)) (t: nat{t <= 79})
: GTot (word SHA1) (decreases (t)) = | false | null | false | if t < 16
then Seq.index mi (t)
else (w' mi (t - 3) ^. w' mi (t - 8) ^. w' mi (t - 14) ^. w' mi (t - 16)) <<<. 1ul | {
"checked_file": "Spec.SHA1.fst.checked",
"dependencies": [
"Spec.Loops.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.SHA1.fst"
} | [
"sometrivial",
""
] | [
"FStar.Seq.Properties.lseq",
"Spec.Hash.Definitions.word",
"Spec.Hash.Definitions.SHA1",
"Spec.Hash.Definitions.block_word_length",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"FStar.Seq.Base.index",
"Prims.bool",
"Lib.IntTypes.op_Less_Less_Less_Dot",
"Spec.Hash.Definitions.word_t",
"Lib.IntTypes.SEC",
"Lib.IntTypes.op_Hat_Dot",
"Spec.SHA1.w'",
"Prims.op_Subtraction",
"FStar.UInt32.__uint_to_t"
] | [] | module Spec.SHA1
open Lib.IntTypes
module H = Spec.Hash.Definitions
module Seq = FStar.Seq
open Spec.Hash.Definitions
(* Source: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf *)
(* Section 5.3.1 *)
inline_for_extraction
let init_as_list : list uint32 = [
u32 0x67452301;
u32 0xefcdab89;
u32 0x98badcfe;
u32 0x10325476;
u32 0xc3d2e1f0;
]
let init : words_state SHA1 = Seq.seq_of_list init_as_list
(* Section 6.1.2 Step 1: message schedule *) | false | false | Spec.SHA1.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val w' (mi: Seq.lseq (word SHA1) (block_word_length SHA1)) (t: nat{t <= 79})
: GTot (word SHA1) (decreases (t)) | [
"recursion"
] | Spec.SHA1.w' | {
"file_name": "specs/Spec.SHA1.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
mi:
FStar.Seq.Properties.lseq (Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA1)
(Spec.Hash.Definitions.block_word_length Spec.Hash.Definitions.SHA1) ->
t: Prims.nat{t <= 79}
-> Prims.GTot (Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA1) | {
"end_col": 84,
"end_line": 28,
"start_col": 2,
"start_line": 26
} |
Prims.Pure | val compute_w
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat)
(accu: Seq.lseq (word SHA1) n)
: Pure (Seq.lseq (word SHA1) 80)
(requires (compute_w_post mi n accu))
(ensures (fun res -> compute_w_post mi 80 res))
(decreases (80 - n)) | [
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "Spec.Hash.Definitions",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec compute_w
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat)
(accu: Seq.lseq (word SHA1) n)
: Pure (Seq.lseq (word SHA1) 80)
(requires (compute_w_post mi n accu))
(ensures (fun res -> compute_w_post mi 80 res))
(decreases (80 - n))
= assert (n <= 80); // this assert is necessary for Z3 to prove that n <= 79 in the else branch
if n = 80
then accu
else compute_w mi (n + 1) (compute_w_next mi n accu) | val compute_w
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat)
(accu: Seq.lseq (word SHA1) n)
: Pure (Seq.lseq (word SHA1) 80)
(requires (compute_w_post mi n accu))
(ensures (fun res -> compute_w_post mi 80 res))
(decreases (80 - n))
let rec compute_w
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat)
(accu: Seq.lseq (word SHA1) n)
: Pure (Seq.lseq (word SHA1) 80)
(requires (compute_w_post mi n accu))
(ensures (fun res -> compute_w_post mi 80 res))
(decreases (80 - n)) = | false | null | false | assert (n <= 80);
if n = 80 then accu else compute_w mi (n + 1) (compute_w_next mi n accu) | {
"checked_file": "Spec.SHA1.fst.checked",
"dependencies": [
"Spec.Loops.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.SHA1.fst"
} | [
""
] | [
"FStar.Seq.Properties.lseq",
"Spec.Hash.Definitions.word",
"Spec.Hash.Definitions.SHA1",
"Spec.Hash.Definitions.block_word_length",
"Prims.nat",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"Spec.SHA1.compute_w",
"Prims.op_Addition",
"Spec.SHA1.compute_w_next",
"Prims.unit",
"Prims._assert",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Spec.SHA1.compute_w_post"
] | [] | module Spec.SHA1
open Lib.IntTypes
module H = Spec.Hash.Definitions
module Seq = FStar.Seq
open Spec.Hash.Definitions
(* Source: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf *)
(* Section 5.3.1 *)
inline_for_extraction
let init_as_list : list uint32 = [
u32 0x67452301;
u32 0xefcdab89;
u32 0x98badcfe;
u32 0x10325476;
u32 0xc3d2e1f0;
]
let init : words_state SHA1 = Seq.seq_of_list init_as_list
(* Section 6.1.2 Step 1: message schedule *)
let rec w' (mi: Seq.lseq (word SHA1) (block_word_length SHA1)) (t: nat {t <= 79}) : GTot (word SHA1) (decreases (t)) =
if t < 16
then Seq.index mi (t)
else (w' mi (t - 3) ^. w' mi (t - 8) ^. w' mi (t - 14) ^. w' mi (t - 16)) <<<. 1ul
let w (mi: Seq.lseq (word SHA1) (block_word_length SHA1)) (t: size_t {v t <= 79}) : GTot (word SHA1) = w' mi (v t)
let compute_w_post
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat)
(res: Seq.lseq (word SHA1) n)
: GTot Type0
= (n <= 80 /\ (
forall (i: nat) . i < n ==> Seq.index res i == w' mi i
))
let compute_w_post_intro
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat)
(res: Seq.lseq (word SHA1) n)
(u: squash (n <= 80))
(f: (i: nat) -> Lemma
(requires (i < n))
(ensures (i < n /\ Seq.index res i == w' mi i)))
: Lemma
(compute_w_post mi n res)
= Classical.forall_intro (Classical.move_requires f)
inline_for_extraction
let compute_w_n'
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat { n <= 79 } )
(w: ((i: nat {i < n}) -> Tot (y: word SHA1 {y == w' mi i})))
: Tot (y: word SHA1 {y == w' mi n})
= let r =
if n < 16
then Seq.index mi n
else (w (n - 3) ^. w (n - 8) ^. w (n - 14) ^. w (n - 16)) <<<. 1ul
in
r
inline_for_extraction
let compute_w_n
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat { n <= 79 } )
(accu: Seq.lseq (word SHA1) n)
: Pure (word SHA1)
(requires (compute_w_post mi n accu))
(ensures (fun y -> n <= 79 /\ y == w' mi n))
= [@inline_let]
let w (i: nat {i < n}) : Tot (y: word SHA1 {y == w' mi i}) = Seq.index accu i in
compute_w_n' mi n w
inline_for_extraction
let compute_w_next
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat { n <= 79 } )
(accu: Seq.lseq (word SHA1) n)
: Pure (Seq.lseq (word SHA1) (n + 1))
(requires (compute_w_post mi n accu))
(ensures (fun accu' -> compute_w_post mi (n + 1) accu'))
= let wn = compute_w_n mi n accu in
let accu' = Seq.snoc accu wn in
assert (n + 1 <= 80);
let g
(i: nat)
: Lemma
(requires (i < n + 1))
(ensures (i < n + 1 /\ Seq.index accu' i == w' mi i))
= if i = n
then ()
else ()
in
compute_w_post_intro mi (n + 1) accu' () g;
accu'
let rec compute_w
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat)
(accu: Seq.lseq (word SHA1) n)
: Pure (Seq.lseq (word SHA1) 80)
(requires (compute_w_post mi n accu))
(ensures (fun res -> compute_w_post mi 80 res)) | false | false | Spec.SHA1.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val compute_w
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat)
(accu: Seq.lseq (word SHA1) n)
: Pure (Seq.lseq (word SHA1) 80)
(requires (compute_w_post mi n accu))
(ensures (fun res -> compute_w_post mi 80 res))
(decreases (80 - n)) | [
"recursion"
] | Spec.SHA1.compute_w | {
"file_name": "specs/Spec.SHA1.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
mi:
FStar.Seq.Properties.lseq (Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA1)
(Spec.Hash.Definitions.block_word_length Spec.Hash.Definitions.SHA1) ->
n: Prims.nat ->
accu: FStar.Seq.Properties.lseq (Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA1) n
-> Prims.Pure
(FStar.Seq.Properties.lseq (Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA1) 80) | {
"end_col": 54,
"end_line": 112,
"start_col": 2,
"start_line": 109
} |
Prims.Pure | val compute_w_next
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat{n <= 79})
(accu: Seq.lseq (word SHA1) n)
: Pure (Seq.lseq (word SHA1) (n + 1))
(requires (compute_w_post mi n accu))
(ensures (fun accu' -> compute_w_post mi (n + 1) accu')) | [
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "Spec.Hash.Definitions",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let compute_w_next
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat { n <= 79 } )
(accu: Seq.lseq (word SHA1) n)
: Pure (Seq.lseq (word SHA1) (n + 1))
(requires (compute_w_post mi n accu))
(ensures (fun accu' -> compute_w_post mi (n + 1) accu'))
= let wn = compute_w_n mi n accu in
let accu' = Seq.snoc accu wn in
assert (n + 1 <= 80);
let g
(i: nat)
: Lemma
(requires (i < n + 1))
(ensures (i < n + 1 /\ Seq.index accu' i == w' mi i))
= if i = n
then ()
else ()
in
compute_w_post_intro mi (n + 1) accu' () g;
accu' | val compute_w_next
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat{n <= 79})
(accu: Seq.lseq (word SHA1) n)
: Pure (Seq.lseq (word SHA1) (n + 1))
(requires (compute_w_post mi n accu))
(ensures (fun accu' -> compute_w_post mi (n + 1) accu'))
let compute_w_next
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat{n <= 79})
(accu: Seq.lseq (word SHA1) n)
: Pure (Seq.lseq (word SHA1) (n + 1))
(requires (compute_w_post mi n accu))
(ensures (fun accu' -> compute_w_post mi (n + 1) accu')) = | false | null | false | let wn = compute_w_n mi n accu in
let accu' = Seq.snoc accu wn in
assert (n + 1 <= 80);
let g (i: nat) : Lemma (requires (i < n + 1)) (ensures (i < n + 1 /\ Seq.index accu' i == w' mi i))
=
if i = n then ()
in
compute_w_post_intro mi (n + 1) accu' () g;
accu' | {
"checked_file": "Spec.SHA1.fst.checked",
"dependencies": [
"Spec.Loops.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.SHA1.fst"
} | [] | [
"FStar.Seq.Properties.lseq",
"Spec.Hash.Definitions.word",
"Spec.Hash.Definitions.SHA1",
"Spec.Hash.Definitions.block_word_length",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.unit",
"Spec.SHA1.compute_w_post_intro",
"Prims.op_Addition",
"Prims.op_LessThan",
"Prims.squash",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.index",
"Spec.SHA1.w'",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Prims.op_Equality",
"Prims.bool",
"Prims._assert",
"FStar.Seq.Base.seq",
"FStar.Seq.Properties.snoc",
"Spec.SHA1.compute_w_n",
"Spec.SHA1.compute_w_post"
] | [] | module Spec.SHA1
open Lib.IntTypes
module H = Spec.Hash.Definitions
module Seq = FStar.Seq
open Spec.Hash.Definitions
(* Source: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf *)
(* Section 5.3.1 *)
inline_for_extraction
let init_as_list : list uint32 = [
u32 0x67452301;
u32 0xefcdab89;
u32 0x98badcfe;
u32 0x10325476;
u32 0xc3d2e1f0;
]
let init : words_state SHA1 = Seq.seq_of_list init_as_list
(* Section 6.1.2 Step 1: message schedule *)
let rec w' (mi: Seq.lseq (word SHA1) (block_word_length SHA1)) (t: nat {t <= 79}) : GTot (word SHA1) (decreases (t)) =
if t < 16
then Seq.index mi (t)
else (w' mi (t - 3) ^. w' mi (t - 8) ^. w' mi (t - 14) ^. w' mi (t - 16)) <<<. 1ul
let w (mi: Seq.lseq (word SHA1) (block_word_length SHA1)) (t: size_t {v t <= 79}) : GTot (word SHA1) = w' mi (v t)
let compute_w_post
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat)
(res: Seq.lseq (word SHA1) n)
: GTot Type0
= (n <= 80 /\ (
forall (i: nat) . i < n ==> Seq.index res i == w' mi i
))
let compute_w_post_intro
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat)
(res: Seq.lseq (word SHA1) n)
(u: squash (n <= 80))
(f: (i: nat) -> Lemma
(requires (i < n))
(ensures (i < n /\ Seq.index res i == w' mi i)))
: Lemma
(compute_w_post mi n res)
= Classical.forall_intro (Classical.move_requires f)
inline_for_extraction
let compute_w_n'
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat { n <= 79 } )
(w: ((i: nat {i < n}) -> Tot (y: word SHA1 {y == w' mi i})))
: Tot (y: word SHA1 {y == w' mi n})
= let r =
if n < 16
then Seq.index mi n
else (w (n - 3) ^. w (n - 8) ^. w (n - 14) ^. w (n - 16)) <<<. 1ul
in
r
inline_for_extraction
let compute_w_n
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat { n <= 79 } )
(accu: Seq.lseq (word SHA1) n)
: Pure (word SHA1)
(requires (compute_w_post mi n accu))
(ensures (fun y -> n <= 79 /\ y == w' mi n))
= [@inline_let]
let w (i: nat {i < n}) : Tot (y: word SHA1 {y == w' mi i}) = Seq.index accu i in
compute_w_n' mi n w
inline_for_extraction
let compute_w_next
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat { n <= 79 } )
(accu: Seq.lseq (word SHA1) n)
: Pure (Seq.lseq (word SHA1) (n + 1))
(requires (compute_w_post mi n accu)) | false | false | Spec.SHA1.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val compute_w_next
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat{n <= 79})
(accu: Seq.lseq (word SHA1) n)
: Pure (Seq.lseq (word SHA1) (n + 1))
(requires (compute_w_post mi n accu))
(ensures (fun accu' -> compute_w_post mi (n + 1) accu')) | [] | Spec.SHA1.compute_w_next | {
"file_name": "specs/Spec.SHA1.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
mi:
FStar.Seq.Properties.lseq (Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA1)
(Spec.Hash.Definitions.block_word_length Spec.Hash.Definitions.SHA1) ->
n: Prims.nat{n <= 79} ->
accu: FStar.Seq.Properties.lseq (Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA1) n
-> Prims.Pure
(FStar.Seq.Properties.lseq (Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA1) (n + 1)) | {
"end_col": 7,
"end_line": 99,
"start_col": 1,
"start_line": 86
} |
Prims.Tot | val step4_aux (mi: word_block) (h: words_state SHA1) : Tot (words_state SHA1) | [
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "Spec.Hash.Definitions",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let step4_aux
(mi: word_block)
(h: words_state SHA1)
: Tot (words_state SHA1) =
let st = step3 mi h in
let sta = Seq.index st 0 in
let stb = Seq.index st 1 in
let stc = Seq.index st 2 in
let std = Seq.index st 3 in
let ste = Seq.index st 4 in
Seq.seq_of_list [
sta +. Seq.index h 0;
stb +. Seq.index h 1;
stc +. Seq.index h 2;
std +. Seq.index h 3;
ste +. Seq.index h 4;
] | val step4_aux (mi: word_block) (h: words_state SHA1) : Tot (words_state SHA1)
let step4_aux (mi: word_block) (h: words_state SHA1) : Tot (words_state SHA1) = | false | null | false | let st = step3 mi h in
let sta = Seq.index st 0 in
let stb = Seq.index st 1 in
let stc = Seq.index st 2 in
let std = Seq.index st 3 in
let ste = Seq.index st 4 in
Seq.seq_of_list [
sta +. Seq.index h 0;
stb +. Seq.index h 1;
stc +. Seq.index h 2;
std +. Seq.index h 3;
ste +. Seq.index h 4
] | {
"checked_file": "Spec.SHA1.fst.checked",
"dependencies": [
"Spec.Loops.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.SHA1.fst"
} | [
"total"
] | [
"Spec.SHA1.word_block",
"Spec.Hash.Definitions.words_state",
"Spec.Hash.Definitions.SHA1",
"FStar.Seq.Properties.seq_of_list",
"Spec.Hash.Definitions.word",
"Prims.Cons",
"Lib.IntTypes.op_Plus_Dot",
"Spec.Hash.Definitions.word_t",
"Lib.IntTypes.SEC",
"FStar.Seq.Base.index",
"Prims.Nil",
"Spec.SHA1.step3"
] | [] | module Spec.SHA1
open Lib.IntTypes
module H = Spec.Hash.Definitions
module Seq = FStar.Seq
open Spec.Hash.Definitions
(* Source: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf *)
(* Section 5.3.1 *)
inline_for_extraction
let init_as_list : list uint32 = [
u32 0x67452301;
u32 0xefcdab89;
u32 0x98badcfe;
u32 0x10325476;
u32 0xc3d2e1f0;
]
let init : words_state SHA1 = Seq.seq_of_list init_as_list
(* Section 6.1.2 Step 1: message schedule *)
let rec w' (mi: Seq.lseq (word SHA1) (block_word_length SHA1)) (t: nat {t <= 79}) : GTot (word SHA1) (decreases (t)) =
if t < 16
then Seq.index mi (t)
else (w' mi (t - 3) ^. w' mi (t - 8) ^. w' mi (t - 14) ^. w' mi (t - 16)) <<<. 1ul
let w (mi: Seq.lseq (word SHA1) (block_word_length SHA1)) (t: size_t {v t <= 79}) : GTot (word SHA1) = w' mi (v t)
let compute_w_post
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat)
(res: Seq.lseq (word SHA1) n)
: GTot Type0
= (n <= 80 /\ (
forall (i: nat) . i < n ==> Seq.index res i == w' mi i
))
let compute_w_post_intro
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat)
(res: Seq.lseq (word SHA1) n)
(u: squash (n <= 80))
(f: (i: nat) -> Lemma
(requires (i < n))
(ensures (i < n /\ Seq.index res i == w' mi i)))
: Lemma
(compute_w_post mi n res)
= Classical.forall_intro (Classical.move_requires f)
inline_for_extraction
let compute_w_n'
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat { n <= 79 } )
(w: ((i: nat {i < n}) -> Tot (y: word SHA1 {y == w' mi i})))
: Tot (y: word SHA1 {y == w' mi n})
= let r =
if n < 16
then Seq.index mi n
else (w (n - 3) ^. w (n - 8) ^. w (n - 14) ^. w (n - 16)) <<<. 1ul
in
r
inline_for_extraction
let compute_w_n
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat { n <= 79 } )
(accu: Seq.lseq (word SHA1) n)
: Pure (word SHA1)
(requires (compute_w_post mi n accu))
(ensures (fun y -> n <= 79 /\ y == w' mi n))
= [@inline_let]
let w (i: nat {i < n}) : Tot (y: word SHA1 {y == w' mi i}) = Seq.index accu i in
compute_w_n' mi n w
inline_for_extraction
let compute_w_next
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat { n <= 79 } )
(accu: Seq.lseq (word SHA1) n)
: Pure (Seq.lseq (word SHA1) (n + 1))
(requires (compute_w_post mi n accu))
(ensures (fun accu' -> compute_w_post mi (n + 1) accu'))
= let wn = compute_w_n mi n accu in
let accu' = Seq.snoc accu wn in
assert (n + 1 <= 80);
let g
(i: nat)
: Lemma
(requires (i < n + 1))
(ensures (i < n + 1 /\ Seq.index accu' i == w' mi i))
= if i = n
then ()
else ()
in
compute_w_post_intro mi (n + 1) accu' () g;
accu'
let rec compute_w
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat)
(accu: Seq.lseq (word SHA1) n)
: Pure (Seq.lseq (word SHA1) 80)
(requires (compute_w_post mi n accu))
(ensures (fun res -> compute_w_post mi 80 res))
(decreases (80 - n))
= assert (n <= 80); // this assert is necessary for Z3 to prove that n <= 79 in the else branch
if n = 80
then accu
else compute_w mi (n + 1) (compute_w_next mi n accu)
(* Section 4.1.1: logical functions *)
inline_for_extraction
let f (t: size_t {v t <= 79}) (x y z: word SHA1) : Tot (word SHA1) =
if t <. 20ul
then
(x &. y) ^. (~. x &. z)
else if 39ul <. t && t <. 60ul
then
(x &. y) ^. (x &. z) ^. (y &. z)
else
x ^. y ^. z
(* Section 4.2.1 *)
inline_for_extraction
let k (t: size_t { v t <= 79 } ) : Tot (word SHA1) =
if t <. 20ul
then u32 0x5a827999
else if t <. 40ul
then u32 0x6ed9eba1
else if t <. 60ul
then u32 0x8f1bbcdc
else u32 0xca62c1d6
(* Section 6.1.2 Step 3 *)
let word_block = Seq.lseq (word SHA1) (block_word_length SHA1)
let step3_body'_aux
(mi: word_block)
(st: words_state SHA1)
(t: size_t {v t < 80})
(wt: word SHA1 { wt == w mi t } )
: Tot (words_state SHA1)
= let sta = Seq.index st 0 in
let stb = Seq.index st 1 in
let stc = Seq.index st 2 in
let std = Seq.index st 3 in
let ste = Seq.index st 4 in
let _T = (sta <<<. 5ul) +. f t stb stc std +. ste +. k t +. wt in
let e = std in
let d = stc in
let c = stb <<<. 30ul in
let b = sta in
let a = _T in
let l : list uint32 = [
a;
b;
c;
d;
e;
] in
assert_norm (List.Tot.length l = 5);
Seq.seq_of_list l
[@"opaque_to_smt"]
let step3_body' = step3_body'_aux
#reset-options "--z3rlimit 50"
[@unifier_hint_injective]
inline_for_extraction
let step3_body_w_t
(mi: word_block)
: Tot Type
= (t: nat { t < 80 }) -> Tot (wt: word SHA1 { wt == w' mi t } )
let step3_body
(mi: word_block)
(w: step3_body_w_t mi)
(st: words_state SHA1)
(t: nat {t < 80})
: Tot (words_state SHA1)
= step3_body' mi st (size t) (w t)
inline_for_extraction
let index_compute_w
(mi: word_block)
(cwt: Seq.lseq (word SHA1) 80 { compute_w_post mi 80 cwt } )
: Tot (step3_body_w_t mi)
= fun (t: nat {t < 80}) -> (Seq.index cwt t <: (wt: word SHA1 { wt == w' mi t }))
let step3_aux
(mi: word_block)
(h: words_state SHA1)
: Tot (words_state SHA1)
= let cwt = compute_w mi 0 Seq.empty in
Spec.Loops.repeat_range 0 80 (step3_body mi (index_compute_w mi cwt)) h
[@"opaque_to_smt"]
let step3 = step3_aux
(* Section 6.1.2 Step 4 *)
let step4_aux
(mi: word_block) | false | true | Spec.SHA1.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val step4_aux (mi: word_block) (h: words_state SHA1) : Tot (words_state SHA1) | [] | Spec.SHA1.step4_aux | {
"file_name": "specs/Spec.SHA1.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | mi: Spec.SHA1.word_block -> h: Spec.Hash.Definitions.words_state Spec.Hash.Definitions.SHA1
-> Spec.Hash.Definitions.words_state Spec.Hash.Definitions.SHA1 | {
"end_col": 3,
"end_line": 224,
"start_col": 26,
"start_line": 211
} |
Prims.Tot | val init: init_t SHA1 | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "Spec.Hash.Definitions",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let init : words_state SHA1 = Seq.seq_of_list init_as_list | val init: init_t SHA1
let init:words_state SHA1 = | false | null | false | Seq.seq_of_list init_as_list | {
"checked_file": "Spec.SHA1.fst.checked",
"dependencies": [
"Spec.Loops.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.SHA1.fst"
} | [
"total"
] | [
"FStar.Seq.Properties.seq_of_list",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U32",
"Lib.IntTypes.SEC",
"Spec.SHA1.init_as_list",
"Spec.Hash.Definitions.words_state",
"Spec.Hash.Definitions.SHA1"
] | [] | module Spec.SHA1
open Lib.IntTypes
module H = Spec.Hash.Definitions
module Seq = FStar.Seq
open Spec.Hash.Definitions
(* Source: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf *)
(* Section 5.3.1 *)
inline_for_extraction
let init_as_list : list uint32 = [
u32 0x67452301;
u32 0xefcdab89;
u32 0x98badcfe;
u32 0x10325476;
u32 0xc3d2e1f0;
] | false | true | Spec.SHA1.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val init: init_t SHA1 | [] | Spec.SHA1.init | {
"file_name": "specs/Spec.SHA1.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Spec.Hash.Definitions.init_t Spec.Hash.Definitions.SHA1 | {
"end_col": 58,
"end_line": 21,
"start_col": 30,
"start_line": 21
} |
Prims.Tot | val compute_w_n'
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat{n <= 79})
(w: (i: nat{i < n} -> Tot (y: word SHA1 {y == w' mi i})))
: Tot (y: word SHA1 {y == w' mi n}) | [
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "Spec.Hash.Definitions",
"short_module": "H"
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let compute_w_n'
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat { n <= 79 } )
(w: ((i: nat {i < n}) -> Tot (y: word SHA1 {y == w' mi i})))
: Tot (y: word SHA1 {y == w' mi n})
= let r =
if n < 16
then Seq.index mi n
else (w (n - 3) ^. w (n - 8) ^. w (n - 14) ^. w (n - 16)) <<<. 1ul
in
r | val compute_w_n'
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat{n <= 79})
(w: (i: nat{i < n} -> Tot (y: word SHA1 {y == w' mi i})))
: Tot (y: word SHA1 {y == w' mi n})
let compute_w_n'
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat{n <= 79})
(w: (i: nat{i < n} -> Tot (y: word SHA1 {y == w' mi i})))
: Tot (y: word SHA1 {y == w' mi n}) = | false | null | false | let r =
if n < 16 then Seq.index mi n else (w (n - 3) ^. w (n - 8) ^. w (n - 14) ^. w (n - 16)) <<<. 1ul
in
r | {
"checked_file": "Spec.SHA1.fst.checked",
"dependencies": [
"Spec.Loops.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Spec.SHA1.fst"
} | [
"total"
] | [
"FStar.Seq.Properties.lseq",
"Spec.Hash.Definitions.word",
"Spec.Hash.Definitions.SHA1",
"Spec.Hash.Definitions.block_word_length",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.eq2",
"Spec.SHA1.w'",
"FStar.Seq.Base.index",
"Prims.bool",
"Lib.IntTypes.op_Less_Less_Less_Dot",
"Spec.Hash.Definitions.word_t",
"Lib.IntTypes.SEC",
"Lib.IntTypes.op_Hat_Dot",
"Prims.op_Subtraction",
"FStar.UInt32.__uint_to_t"
] | [] | module Spec.SHA1
open Lib.IntTypes
module H = Spec.Hash.Definitions
module Seq = FStar.Seq
open Spec.Hash.Definitions
(* Source: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf *)
(* Section 5.3.1 *)
inline_for_extraction
let init_as_list : list uint32 = [
u32 0x67452301;
u32 0xefcdab89;
u32 0x98badcfe;
u32 0x10325476;
u32 0xc3d2e1f0;
]
let init : words_state SHA1 = Seq.seq_of_list init_as_list
(* Section 6.1.2 Step 1: message schedule *)
let rec w' (mi: Seq.lseq (word SHA1) (block_word_length SHA1)) (t: nat {t <= 79}) : GTot (word SHA1) (decreases (t)) =
if t < 16
then Seq.index mi (t)
else (w' mi (t - 3) ^. w' mi (t - 8) ^. w' mi (t - 14) ^. w' mi (t - 16)) <<<. 1ul
let w (mi: Seq.lseq (word SHA1) (block_word_length SHA1)) (t: size_t {v t <= 79}) : GTot (word SHA1) = w' mi (v t)
let compute_w_post
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat)
(res: Seq.lseq (word SHA1) n)
: GTot Type0
= (n <= 80 /\ (
forall (i: nat) . i < n ==> Seq.index res i == w' mi i
))
let compute_w_post_intro
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat)
(res: Seq.lseq (word SHA1) n)
(u: squash (n <= 80))
(f: (i: nat) -> Lemma
(requires (i < n))
(ensures (i < n /\ Seq.index res i == w' mi i)))
: Lemma
(compute_w_post mi n res)
= Classical.forall_intro (Classical.move_requires f)
inline_for_extraction
let compute_w_n'
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat { n <= 79 } )
(w: ((i: nat {i < n}) -> Tot (y: word SHA1 {y == w' mi i}))) | false | false | Spec.SHA1.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val compute_w_n'
(mi: Seq.lseq (word SHA1) (block_word_length SHA1))
(n: nat{n <= 79})
(w: (i: nat{i < n} -> Tot (y: word SHA1 {y == w' mi i})))
: Tot (y: word SHA1 {y == w' mi n}) | [] | Spec.SHA1.compute_w_n' | {
"file_name": "specs/Spec.SHA1.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
mi:
FStar.Seq.Properties.lseq (Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA1)
(Spec.Hash.Definitions.block_word_length Spec.Hash.Definitions.SHA1) ->
n: Prims.nat{n <= 79} ->
w:
(i: Prims.nat{i < n}
-> y: Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA1 {y == Spec.SHA1.w' mi i})
-> y: Spec.Hash.Definitions.word Spec.Hash.Definitions.SHA1 {y == Spec.SHA1.w' mi n} | {
"end_col": 3,
"end_line": 64,
"start_col": 1,
"start_line": 59
} |
Prims.Tot | val null (#a:Type)
: ref a | [
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Steel.ST.Coercions",
"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
}
] | false | let null (#a:Type)
: ref a
= R.null #a | val null (#a:Type)
: ref a
let null (#a: Type) : ref a = | false | null | false | R.null #a | {
"checked_file": "Steel.ST.HigherReference.fst.checked",
"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"
} | [
"total"
] | [
"Steel.HigherReference.null",
"Steel.ST.HigherReference.ref"
] | [] | (*
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) | false | false | Steel.ST.HigherReference.fst | {
"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"
} | null | val null (#a:Type)
: ref a | [] | Steel.ST.HigherReference.null | {
"file_name": "lib/steel/Steel.ST.HigherReference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | Steel.ST.HigherReference.ref a | {
"end_col": 13,
"end_line": 29,
"start_col": 4,
"start_line": 29
} |
Prims.Tot | val _stack_frame:vprop | [
{
"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
}
] | false | let _stack_frame : vprop = pure True | val _stack_frame:vprop
let _stack_frame:vprop = | false | null | false | pure True | {
"checked_file": "Steel.ST.HigherReference.fst.checked",
"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"
} | [
"total"
] | [
"Steel.ST.Util.pure",
"Prims.l_True"
] | [] | (*
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 | false | true | Steel.ST.HigherReference.fst | {
"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"
} | null | val _stack_frame:vprop | [] | Steel.ST.HigherReference._stack_frame | {
"file_name": "lib/steel/Steel.ST.HigherReference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | Steel.Effect.Common.vprop | {
"end_col": 36,
"end_line": 103,
"start_col": 27,
"start_line": 103
} |
Prims.Tot | val ref ([@@@ strictly_positive] a:Type u#1)
: Type0 | [
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Steel.ST.Coercions",
"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
}
] | false | let ref (a:Type u#1)
: Type0
= R.ref a | val ref ([@@@ strictly_positive] a:Type u#1)
: Type0
let ref (a: Type u#1) : Type0 = | false | null | false | R.ref a | {
"checked_file": "Steel.ST.HigherReference.fst.checked",
"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"
} | [
"total"
] | [
"Steel.HigherReference.ref"
] | [] | (*
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) | false | true | Steel.ST.HigherReference.fst | {
"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"
} | null | val ref ([@@@ strictly_positive] a:Type u#1)
: Type0 | [] | Steel.ST.HigherReference.ref | {
"file_name": "lib/steel/Steel.ST.HigherReference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | a: Type -> Type0 | {
"end_col": 11,
"end_line": 25,
"start_col": 4,
"start_line": 25
} |
Prims.Tot | val pts_to (#a:Type)
(r:ref a)
([@@@smt_fallback] p:perm)
([@@@smt_fallback] v:a)
: vprop | [
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Steel.ST.Coercions",
"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
}
] | false | let pts_to (#a:Type)
(r:ref a)
([@@@smt_fallback] p:perm)
([@@@smt_fallback] v:a)
: vprop
= R.pts_to r p v | val pts_to (#a:Type)
(r:ref a)
([@@@smt_fallback] p:perm)
([@@@smt_fallback] v:a)
: vprop
let pts_to (#a: Type) (r: ref a) ([@@@ smt_fallback]p: perm) ([@@@ smt_fallback]v: a) : vprop = | false | null | false | R.pts_to r p v | {
"checked_file": "Steel.ST.HigherReference.fst.checked",
"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"
} | [
"total"
] | [
"Steel.ST.HigherReference.ref",
"Steel.FractionalPermission.perm",
"Steel.HigherReference.pts_to",
"Steel.Effect.Common.vprop"
] | [] | (*
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) | false | false | Steel.ST.HigherReference.fst | {
"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"
} | null | val pts_to (#a:Type)
(r:ref a)
([@@@smt_fallback] p:perm)
([@@@smt_fallback] v:a)
: vprop | [] | Steel.ST.HigherReference.pts_to | {
"file_name": "lib/steel/Steel.ST.HigherReference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.ST.HigherReference.ref a -> p: Steel.FractionalPermission.perm -> v: a
-> Steel.Effect.Common.vprop | {
"end_col": 18,
"end_line": 40,
"start_col": 4,
"start_line": 40
} |
Prims.Tot | val is_null (#a:Type) (r:ref a)
: b:bool{b <==> r == null} | [
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Steel.ST.Coercions",
"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
}
] | false | let is_null (#a:Type) (r:ref a)
: b:bool{b <==> r == null}
= R.is_null r | val is_null (#a:Type) (r:ref a)
: b:bool{b <==> r == null}
let is_null (#a: Type) (r: ref a) : b: bool{b <==> r == null} = | false | null | false | R.is_null r | {
"checked_file": "Steel.ST.HigherReference.fst.checked",
"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"
} | [
"total"
] | [
"Steel.ST.HigherReference.ref",
"Steel.HigherReference.is_null",
"Prims.bool",
"Prims.l_iff",
"Prims.b2t",
"Prims.eq2",
"Steel.ST.HigherReference.null"
] | [] | (*
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) | false | false | Steel.ST.HigherReference.fst | {
"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"
} | null | val is_null (#a:Type) (r:ref a)
: b:bool{b <==> r == null} | [] | Steel.ST.HigherReference.is_null | {
"file_name": "lib/steel/Steel.ST.HigherReference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.ST.HigherReference.ref a -> b: Prims.bool{b <==> r == Steel.ST.HigherReference.null} | {
"end_col": 15,
"end_line": 33,
"start_col": 4,
"start_line": 33
} |
Steel.ST.Effect.ST | val _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)) | [
{
"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
}
] | false | 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 | val _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))
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)) = | true | null | false | alloc x | {
"checked_file": "Steel.ST.HigherReference.fst.checked",
"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"
} | [] | [
"Steel.ST.HigherReference.alloc",
"Steel.ST.HigherReference.ref",
"Steel.Effect.Common.emp",
"Steel.ST.HigherReference.pts_to",
"Steel.FractionalPermission.full_perm",
"Steel.Effect.Common.vprop",
"Prims.l_True",
"Prims.b2t",
"Prims.op_Negation",
"Steel.ST.HigherReference.is_null"
] | [] | (*
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) | false | false | Steel.ST.HigherReference.fst | {
"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"
} | null | val _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)) | [] | Steel.ST.HigherReference._alloca | {
"file_name": "lib/steel/Steel.ST.HigherReference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | x: a -> Steel.ST.Effect.ST (Steel.ST.HigherReference.ref a) | {
"end_col": 9,
"end_line": 114,
"start_col": 2,
"start_line": 114
} |
Steel.ST.Effect.Ghost.STGhostT | val share (#a:Type)
(#uses:_)
(#p:perm)
(#v:erased a)
(r:ref a)
: STGhostT unit uses
(pts_to r p v)
(fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v) | [
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Steel.ST.Coercions",
"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
}
] | false | let share (#a:Type)
(#uses:_)
(#p:perm)
(#v:erased a)
(r:ref a)
: STGhostT unit uses
(pts_to r p v)
(fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v)
= coerce_ghost (fun _ -> R.share r) | val share (#a:Type)
(#uses:_)
(#p:perm)
(#v:erased a)
(r:ref a)
: STGhostT unit uses
(pts_to r p v)
(fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v)
let share (#a: Type) (#uses: _) (#p: perm) (#v: erased a) (r: ref a)
: STGhostT unit
uses
(pts_to r p v)
(fun _ -> (pts_to r (half_perm p) v) `star` (pts_to r (half_perm p) v)) = | true | null | false | coerce_ghost (fun _ -> R.share r) | {
"checked_file": "Steel.ST.HigherReference.fst.checked",
"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"
} | [] | [
"Steel.Memory.inames",
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"Steel.ST.HigherReference.ref",
"Steel.ST.Coercions.coerce_ghost",
"Prims.unit",
"Steel.Effect.Common.VUnit",
"Steel.Effect.Common.to_vprop'",
"Steel.HigherReference.pts_to_sl",
"FStar.Ghost.reveal",
"Steel.Effect.Common.star",
"Steel.FractionalPermission.half_perm",
"Steel.Effect.Common.vprop",
"Prims.l_True",
"Steel.HigherReference.share",
"Steel.ST.HigherReference.pts_to"
] | [] | (*
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
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
let share (#a:Type)
(#uses:_)
(#p:perm)
(#v:erased a)
(r:ref a)
: STGhostT unit uses
(pts_to r p v) | false | false | Steel.ST.HigherReference.fst | {
"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"
} | null | val share (#a:Type)
(#uses:_)
(#p:perm)
(#v:erased a)
(r:ref a)
: STGhostT unit uses
(pts_to r p v)
(fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v) | [] | Steel.ST.HigherReference.share | {
"file_name": "lib/steel/Steel.ST.HigherReference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.ST.HigherReference.ref a -> Steel.ST.Effect.Ghost.STGhostT Prims.unit | {
"end_col": 37,
"end_line": 176,
"start_col": 4,
"start_line": 176
} |
Steel.ST.Effect.Ghost.STGhost | val gather (#a:Type)
(#uses:_)
(#p0 p1:perm)
(#v0 #v1:erased a)
(r:ref a)
: STGhost unit uses
(pts_to r p0 v0 `star` pts_to r p1 v1)
(fun _ -> pts_to r (sum_perm p0 p1) v0)
(requires True)
(ensures fun _ -> v0 == v1) | [
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Steel.ST.Coercions",
"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
}
] | false | let gather (#a:Type)
(#uses:_)
(#p0 p1:perm)
(#v0 #v1:erased a)
(r:ref a)
: STGhost unit uses
(pts_to r p0 v0 `star` pts_to r p1 v1)
(fun _ -> pts_to r (sum_perm p0 p1) v0)
(requires True)
(ensures fun _ -> v0 == v1)
= coerce_ghost (fun _ -> R.gather #a #uses #p0 #p1 #v0 #v1 r) | val gather (#a:Type)
(#uses:_)
(#p0 p1:perm)
(#v0 #v1:erased a)
(r:ref a)
: STGhost unit uses
(pts_to r p0 v0 `star` pts_to r p1 v1)
(fun _ -> pts_to r (sum_perm p0 p1) v0)
(requires True)
(ensures fun _ -> v0 == v1)
let gather (#a: Type) (#uses: _) (#p0 p1: perm) (#v0 #v1: erased a) (r: ref a)
: STGhost unit
uses
((pts_to r p0 v0) `star` (pts_to r p1 v1))
(fun _ -> pts_to r (sum_perm p0 p1) v0)
(requires True)
(ensures fun _ -> v0 == v1) = | true | null | false | coerce_ghost (fun _ -> R.gather #a #uses #p0 #p1 #v0 #v1 r) | {
"checked_file": "Steel.ST.HigherReference.fst.checked",
"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"
} | [] | [
"Steel.Memory.inames",
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"Steel.ST.HigherReference.ref",
"Steel.ST.Coercions.coerce_ghost",
"Prims.unit",
"Steel.Effect.Common.star",
"Steel.Effect.Common.VUnit",
"Steel.Effect.Common.to_vprop'",
"Steel.HigherReference.pts_to_sl",
"FStar.Ghost.reveal",
"Steel.FractionalPermission.sum_perm",
"Steel.Effect.Common.vprop",
"Prims.l_True",
"Prims.eq2",
"Steel.HigherReference.gather",
"Steel.ST.HigherReference.pts_to"
] | [] | (*
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
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
let share (#a:Type)
(#uses:_)
(#p:perm)
(#v:erased a)
(r:ref a)
: STGhostT unit uses
(pts_to r p v)
(fun _ -> pts_to r (half_perm p) v `star` pts_to r (half_perm p) v)
= coerce_ghost (fun _ -> R.share r)
let gather (#a:Type)
(#uses:_)
(#p0 p1:perm)
(#v0 #v1:erased a)
(r:ref a)
: STGhost unit uses
(pts_to r p0 v0 `star` pts_to r p1 v1)
(fun _ -> pts_to r (sum_perm p0 p1) v0)
(requires True) | false | false | Steel.ST.HigherReference.fst | {
"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"
} | null | val gather (#a:Type)
(#uses:_)
(#p0 p1:perm)
(#v0 #v1:erased a)
(r:ref a)
: STGhost unit uses
(pts_to r p0 v0 `star` pts_to r p1 v1)
(fun _ -> pts_to r (sum_perm p0 p1) v0)
(requires True)
(ensures fun _ -> v0 == v1) | [] | Steel.ST.HigherReference.gather | {
"file_name": "lib/steel/Steel.ST.HigherReference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | p1: Steel.FractionalPermission.perm -> r: Steel.ST.HigherReference.ref a
-> Steel.ST.Effect.Ghost.STGhost Prims.unit | {
"end_col": 63,
"end_line": 188,
"start_col": 4,
"start_line": 188
} |
Steel.ST.Effect.STT | val _push_frame: Prims.unit -> STT unit emp (fun _ -> _stack_frame) | [
{
"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
}
] | false | let _push_frame () : STT unit emp (fun _ -> _stack_frame) =
rewrite (pure True) _stack_frame | val _push_frame: Prims.unit -> STT unit emp (fun _ -> _stack_frame)
let _push_frame () : STT unit emp (fun _ -> _stack_frame) = | true | null | false | rewrite (pure True) _stack_frame | {
"checked_file": "Steel.ST.HigherReference.fst.checked",
"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"
} | [] | [
"Prims.unit",
"Steel.ST.Util.rewrite",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.ST.Util.pure",
"Prims.l_True",
"Steel.ST.HigherReference._stack_frame",
"Steel.Effect.Common.emp",
"Steel.Effect.Common.vprop"
] | [] | (*
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 | false | false | Steel.ST.HigherReference.fst | {
"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"
} | null | val _push_frame: Prims.unit -> STT unit emp (fun _ -> _stack_frame) | [] | Steel.ST.HigherReference._push_frame | {
"file_name": "lib/steel/Steel.ST.HigherReference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | _: Prims.unit -> Steel.ST.Effect.STT Prims.unit | {
"end_col": 34,
"end_line": 105,
"start_col": 2,
"start_line": 105
} |
Steel.ST.Effect.Ghost.STGhost | val pts_to_not_null (#a:Type)
(#opened:inames)
(#p:perm)
(#v:a)
(r:ref a)
: STGhost unit opened
(pts_to r p v)
(fun _ -> pts_to r p v)
(requires True)
(ensures fun _ -> r =!= null) | [
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Steel.ST.Coercions",
"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
}
] | false | 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);
() | val pts_to_not_null (#a:Type)
(#opened:inames)
(#p:perm)
(#v:a)
(r:ref a)
: STGhost unit opened
(pts_to r p v)
(fun _ -> pts_to r p v)
(requires True)
(ensures fun _ -> r =!= null)
let pts_to_not_null #a #opened #p #v r = | true | null | false | extract_fact #opened (pts_to r p v) (r =!= null) (R.pts_to_not_null r p v);
() | {
"checked_file": "Steel.ST.HigherReference.fst.checked",
"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"
} | [] | [
"Steel.Memory.inames",
"Steel.FractionalPermission.perm",
"Steel.ST.HigherReference.ref",
"Prims.unit",
"Steel.ST.Effect.Ghost.extract_fact",
"Steel.ST.HigherReference.pts_to",
"Prims.l_not",
"Prims.eq2",
"Steel.ST.HigherReference.null",
"Steel.HigherReference.pts_to_not_null"
] | [] | (*
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) | false | false | Steel.ST.HigherReference.fst | {
"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"
} | null | val pts_to_not_null (#a:Type)
(#opened:inames)
(#p:perm)
(#v:a)
(r:ref a)
: STGhost unit opened
(pts_to r p v)
(fun _ -> pts_to r p v)
(requires True)
(ensures fun _ -> r =!= null) | [] | Steel.ST.HigherReference.pts_to_not_null | {
"file_name": "lib/steel/Steel.ST.HigherReference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.ST.HigherReference.ref a -> Steel.ST.Effect.Ghost.STGhost Prims.unit | {
"end_col": 6,
"end_line": 58,
"start_col": 4,
"start_line": 57
} |
Steel.ST.Effect.STT | val free (#a:Type)
(#v:erased a)
(r:ref a)
: STT unit
(pts_to r full_perm v) (fun _ -> emp) | [
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Steel.ST.Coercions",
"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
}
] | false | 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 () | val free (#a:Type)
(#v:erased a)
(r:ref a)
: STT unit
(pts_to r full_perm v) (fun _ -> emp)
let free (#a: Type) (#v: erased a) (r: ref a) : STT unit (pts_to r full_perm v) (fun _ -> emp) = | true | null | false | coerce_steel (fun _ -> R.free r);
return () | {
"checked_file": "Steel.ST.HigherReference.fst.checked",
"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"
} | [] | [
"FStar.Ghost.erased",
"Steel.ST.HigherReference.ref",
"Steel.ST.Util.return",
"Prims.unit",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"FStar.Algebra.CommMonoid.Equiv.__proj__CM__item__unit",
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.req",
"Steel.Effect.Common.rm",
"Steel.ST.Coercions.coerce_steel",
"Steel.Effect.Common.VUnit",
"Steel.Effect.Common.to_vprop'",
"Steel.HigherReference.pts_to_sl",
"Steel.FractionalPermission.full_perm",
"FStar.Ghost.reveal",
"Steel.Effect.Common.emp",
"Prims.l_True",
"Steel.HigherReference.free",
"Steel.ST.HigherReference.pts_to"
] | [] | (*
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) | false | false | Steel.ST.HigherReference.fst | {
"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"
} | null | val free (#a:Type)
(#v:erased a)
(r:ref a)
: STT unit
(pts_to r full_perm v) (fun _ -> emp) | [] | Steel.ST.HigherReference.free | {
"file_name": "lib/steel/Steel.ST.HigherReference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.ST.HigherReference.ref a -> Steel.ST.Effect.STT Prims.unit | {
"end_col": 13,
"end_line": 98,
"start_col": 4,
"start_line": 97
} |
Steel.ST.Effect.STT | val 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) | [
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Steel.ST.Coercions",
"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
}
] | false | 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 () | val 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)
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) = | true | null | false | coerce_steel (fun _ -> R.write r x);
return () | {
"checked_file": "Steel.ST.HigherReference.fst.checked",
"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"
} | [] | [
"FStar.Ghost.erased",
"Steel.ST.HigherReference.ref",
"Steel.ST.Util.return",
"Prims.unit",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.ST.HigherReference.pts_to",
"Steel.FractionalPermission.full_perm",
"Steel.Effect.Common.vprop",
"Steel.ST.Coercions.coerce_steel",
"Steel.Effect.Common.VUnit",
"Steel.Effect.Common.to_vprop'",
"Steel.HigherReference.pts_to_sl",
"FStar.Ghost.reveal",
"Prims.l_True",
"Steel.HigherReference.write"
] | [] | (*
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) | false | false | Steel.ST.HigherReference.fst | {
"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"
} | null | val 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) | [] | Steel.ST.HigherReference.write | {
"file_name": "lib/steel/Steel.ST.HigherReference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.ST.HigherReference.ref a -> x: a -> Steel.ST.Effect.STT Prims.unit | {
"end_col": 13,
"end_line": 89,
"start_col": 4,
"start_line": 88
} |
Steel.ST.Effect.Ghost.STGhost | val 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) | [
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Steel.ST.Coercions",
"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
}
] | false | 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) | val 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)
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) = | true | null | false | coerce_ghost (fun _ -> R.higher_ref_pts_to_injective_eq #a #opened #p0 #p1 #(hide v0) #(hide v1) r) | {
"checked_file": "Steel.ST.HigherReference.fst.checked",
"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"
} | [] | [
"Steel.Memory.inames",
"Steel.FractionalPermission.perm",
"Steel.ST.HigherReference.ref",
"Steel.ST.Coercions.coerce_ghost",
"Prims.unit",
"Steel.Effect.Common.star",
"Steel.Effect.Common.VUnit",
"Steel.Effect.Common.to_vprop'",
"Steel.HigherReference.pts_to_sl",
"FStar.Ghost.reveal",
"FStar.Ghost.hide",
"Steel.Effect.Common.vprop",
"Prims.l_True",
"Prims.eq2",
"FStar.Ghost.erased",
"Steel.HigherReference.higher_ref_pts_to_injective_eq",
"Steel.ST.HigherReference.pts_to"
] | [] | (*
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) | false | false | Steel.ST.HigherReference.fst | {
"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"
} | null | val 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) | [] | Steel.ST.HigherReference.pts_to_injective_eq | {
"file_name": "lib/steel/Steel.ST.HigherReference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.ST.HigherReference.ref a -> Steel.ST.Effect.Ghost.STGhost Prims.unit | {
"end_col": 90,
"end_line": 54,
"start_col": 4,
"start_line": 53
} |
Steel.ST.Effect.ST | val 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)) | [
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Steel.ST.Coercions",
"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
}
] | false | 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 | val 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 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)) = | true | null | false | let r = coerce_steel (fun _ -> R.alloc x) in
r | {
"checked_file": "Steel.ST.HigherReference.fst.checked",
"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"
} | [] | [
"Steel.ST.HigherReference.ref",
"Steel.HigherReference.ref",
"Steel.ST.Coercions.coerce_steel",
"Steel.Effect.Common.emp",
"Steel.Effect.Common.VUnit",
"Steel.Effect.Common.to_vprop'",
"Steel.HigherReference.pts_to_sl",
"Steel.FractionalPermission.full_perm",
"Steel.Effect.Common.vprop",
"Prims.l_True",
"Prims.b2t",
"Prims.op_Negation",
"Steel.HigherReference.is_null",
"Prims.unit",
"Steel.HigherReference.alloc",
"Steel.ST.HigherReference.pts_to",
"Steel.ST.HigherReference.is_null"
] | [] | (*
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) | false | false | Steel.ST.HigherReference.fst | {
"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"
} | null | val 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)) | [] | Steel.ST.HigherReference.alloc | {
"file_name": "lib/steel/Steel.ST.HigherReference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | x: a -> Steel.ST.Effect.ST (Steel.ST.HigherReference.ref a) | {
"end_col": 5,
"end_line": 67,
"start_col": 3,
"start_line": 66
} |
Steel.ST.Effect.ST | val read (#a:Type)
(#p:perm)
(#v:erased a)
(r:ref a)
: ST a
(pts_to r p v)
(fun x -> pts_to r p v)
(requires True)
(ensures fun x -> x == Ghost.reveal v) | [
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Steel.ST.Coercions",
"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
}
] | false | 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 | val read (#a:Type)
(#p:perm)
(#v:erased a)
(r:ref a)
: ST a
(pts_to r p v)
(fun x -> pts_to r p v)
(requires True)
(ensures fun x -> x == Ghost.reveal v)
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) = | true | null | false | let u = coerce_steel (fun _ -> R.read r) in
return u | {
"checked_file": "Steel.ST.HigherReference.fst.checked",
"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"
} | [] | [
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"Steel.ST.HigherReference.ref",
"Steel.ST.Util.return",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.ST.HigherReference.pts_to",
"FStar.Ghost.reveal",
"Steel.Effect.Common.vprop",
"Steel.ST.Coercions.coerce_steel",
"Steel.Effect.Common.VUnit",
"Steel.Effect.Common.to_vprop'",
"Steel.HigherReference.pts_to_sl",
"Prims.l_True",
"Prims.eq2",
"Prims.unit",
"Steel.HigherReference.read"
] | [] | (*
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) | false | false | Steel.ST.HigherReference.fst | {
"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"
} | null | val read (#a:Type)
(#p:perm)
(#v:erased a)
(r:ref a)
: ST a
(pts_to r p v)
(fun x -> pts_to r p v)
(requires True)
(ensures fun x -> x == Ghost.reveal v) | [] | Steel.ST.HigherReference.read | {
"file_name": "lib/steel/Steel.ST.HigherReference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.ST.HigherReference.ref a -> Steel.ST.Effect.ST a | {
"end_col": 12,
"end_line": 79,
"start_col": 3,
"start_line": 78
} |
Steel.ST.Effect.STT | val _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) | [
{
"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
}
] | false | 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 _ | val _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)
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) = | true | null | false | free r;
rewrite _stack_frame (pure True);
elim_pure _ | {
"checked_file": "Steel.ST.HigherReference.fst.checked",
"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"
} | [] | [
"FStar.Ghost.erased",
"Steel.ST.HigherReference.ref",
"Steel.ST.Util.elim_pure",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Prims.l_True",
"Prims.unit",
"Steel.ST.Util.rewrite",
"Steel.ST.HigherReference._stack_frame",
"Steel.ST.Util.pure",
"Steel.ST.HigherReference.free",
"Steel.Effect.Common.star",
"Steel.ST.HigherReference.pts_to",
"Steel.FractionalPermission.full_perm",
"FStar.Ghost.reveal",
"Steel.Effect.Common.emp",
"Steel.Effect.Common.vprop"
] | [] | (*
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) | false | false | Steel.ST.HigherReference.fst | {
"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"
} | null | val _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) | [] | Steel.ST.HigherReference._free_and_pop_frame | {
"file_name": "lib/steel/Steel.ST.HigherReference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | r: Steel.ST.HigherReference.ref a -> Steel.ST.Effect.STT Prims.unit | {
"end_col": 13,
"end_line": 126,
"start_col": 2,
"start_line": 124
} |
Steel.ST.Effect.STF | 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) | [
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Steel.ST.Coercions",
"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
}
] | 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 | 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) = | true | null | false | _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 | {
"checked_file": "Steel.ST.HigherReference.fst.checked",
"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"
} | [] | [
"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"
] | [] | (*
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
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)
) | false | false | Steel.ST.HigherReference.fst | {
"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"
} | null | 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) | [] | Steel.ST.HigherReference.with_named_local | {
"file_name": "lib/steel/Steel.ST.HigherReference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
init: t ->
name: Prims.string ->
body: (r: Steel.ST.HigherReference.ref t -> Steel.ST.Effect.STT ret_t)
-> Steel.ST.Effect.STF ret_t | {
"end_col": 10,
"end_line": 166,
"start_col": 2,
"start_line": 160
} |
Steel.ST.Effect.STF | 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) | [
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Steel.ST.Coercions",
"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
}
] | 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 | 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) = | true | null | false | _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": "Steel.ST.HigherReference.fst.checked",
"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"
} | [] | [
"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"
] | [] | (*
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)
) | false | false | Steel.ST.HigherReference.fst | {
"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"
} | null | 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) | [] | Steel.ST.HigherReference.with_local | {
"file_name": "lib/steel/Steel.ST.HigherReference.fst",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | init: t -> body: (r: Steel.ST.HigherReference.ref t -> Steel.ST.Effect.STT ret_t)
-> Steel.ST.Effect.STF ret_t | {
"end_col": 10,
"end_line": 145,
"start_col": 2,
"start_line": 140
} |
Prims.Tot | val parse_ifthenelse_kind (p: parse_ifthenelse_param) : Tot parser_kind | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_ifthenelse_kind
(p: parse_ifthenelse_param)
: Tot parser_kind
= and_then_kind p.parse_ifthenelse_tag_kind (parse_ifthenelse_payload_kind p) | val parse_ifthenelse_kind (p: parse_ifthenelse_param) : Tot parser_kind
let parse_ifthenelse_kind (p: parse_ifthenelse_param) : Tot parser_kind = | false | null | false | and_then_kind p.parse_ifthenelse_tag_kind (parse_ifthenelse_payload_kind p) | {
"checked_file": "LowParse.Spec.IfThenElse.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.IfThenElse.fst"
} | [
"total"
] | [
"LowParse.Spec.IfThenElse.parse_ifthenelse_param",
"LowParse.Spec.Combinators.and_then_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_kind",
"LowParse.Spec.IfThenElse.parse_ifthenelse_payload_kind",
"LowParse.Spec.Base.parser_kind"
] | [] | module LowParse.Spec.IfThenElse
include LowParse.Spec.Combinators
module Seq = FStar.Seq
[@@(noextract_to "krml")]
inline_for_extraction
noeq
type parse_ifthenelse_param = {
parse_ifthenelse_tag_kind: parser_kind;
parse_ifthenelse_tag_t: Type;
parse_ifthenelse_tag_parser: parser parse_ifthenelse_tag_kind parse_ifthenelse_tag_t;
parse_ifthenelse_tag_cond: (parse_ifthenelse_tag_t -> Tot bool);
parse_ifthenelse_payload_t: (bool -> Tot Type);
parse_ifthenelse_payload_parser: ((b: bool) -> Tot (k: parser_kind & parser k (parse_ifthenelse_payload_t b)));
parse_ifthenelse_t: Type;
parse_ifthenelse_synth: ((t: parse_ifthenelse_tag_t) -> (parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t)) -> GTot parse_ifthenelse_t);
parse_ifthenelse_synth_injective: (
(t1: parse_ifthenelse_tag_t) ->
(x1: parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t1)) ->
(t2: parse_ifthenelse_tag_t) ->
(x2: parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t2)) ->
Lemma
(requires (parse_ifthenelse_synth t1 x1 == parse_ifthenelse_synth t2 x2))
(ensures (t1 == t2 /\ coerce (parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t2)) x1 == x2))
);
}
inline_for_extraction
let parse_ifthenelse_payload_kind
(p: parse_ifthenelse_param)
: Tot parser_kind
= glb (dfst (p.parse_ifthenelse_payload_parser true)) (dfst (p.parse_ifthenelse_payload_parser false))
inline_for_extraction
let parse_ifthenelse_kind
(p: parse_ifthenelse_param) | false | true | LowParse.Spec.IfThenElse.fst | {
"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"
} | null | val parse_ifthenelse_kind (p: parse_ifthenelse_param) : Tot parser_kind | [] | LowParse.Spec.IfThenElse.parse_ifthenelse_kind | {
"file_name": "src/lowparse/LowParse.Spec.IfThenElse.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | p: LowParse.Spec.IfThenElse.parse_ifthenelse_param -> LowParse.Spec.Base.parser_kind | {
"end_col": 77,
"end_line": 39,
"start_col": 2,
"start_line": 39
} |
Prims.Tot | val parse_ifthenelse_payload_kind (p: parse_ifthenelse_param) : Tot parser_kind | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_ifthenelse_payload_kind
(p: parse_ifthenelse_param)
: Tot parser_kind
= glb (dfst (p.parse_ifthenelse_payload_parser true)) (dfst (p.parse_ifthenelse_payload_parser false)) | val parse_ifthenelse_payload_kind (p: parse_ifthenelse_param) : Tot parser_kind
let parse_ifthenelse_payload_kind (p: parse_ifthenelse_param) : Tot parser_kind = | false | null | false | glb (dfst (p.parse_ifthenelse_payload_parser true)) (dfst (p.parse_ifthenelse_payload_parser false)) | {
"checked_file": "LowParse.Spec.IfThenElse.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.IfThenElse.fst"
} | [
"total"
] | [
"LowParse.Spec.IfThenElse.parse_ifthenelse_param",
"LowParse.Spec.Base.glb",
"FStar.Pervasives.dfst",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_parser"
] | [] | module LowParse.Spec.IfThenElse
include LowParse.Spec.Combinators
module Seq = FStar.Seq
[@@(noextract_to "krml")]
inline_for_extraction
noeq
type parse_ifthenelse_param = {
parse_ifthenelse_tag_kind: parser_kind;
parse_ifthenelse_tag_t: Type;
parse_ifthenelse_tag_parser: parser parse_ifthenelse_tag_kind parse_ifthenelse_tag_t;
parse_ifthenelse_tag_cond: (parse_ifthenelse_tag_t -> Tot bool);
parse_ifthenelse_payload_t: (bool -> Tot Type);
parse_ifthenelse_payload_parser: ((b: bool) -> Tot (k: parser_kind & parser k (parse_ifthenelse_payload_t b)));
parse_ifthenelse_t: Type;
parse_ifthenelse_synth: ((t: parse_ifthenelse_tag_t) -> (parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t)) -> GTot parse_ifthenelse_t);
parse_ifthenelse_synth_injective: (
(t1: parse_ifthenelse_tag_t) ->
(x1: parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t1)) ->
(t2: parse_ifthenelse_tag_t) ->
(x2: parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t2)) ->
Lemma
(requires (parse_ifthenelse_synth t1 x1 == parse_ifthenelse_synth t2 x2))
(ensures (t1 == t2 /\ coerce (parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t2)) x1 == x2))
);
}
inline_for_extraction
let parse_ifthenelse_payload_kind
(p: parse_ifthenelse_param) | false | true | LowParse.Spec.IfThenElse.fst | {
"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"
} | null | val parse_ifthenelse_payload_kind (p: parse_ifthenelse_param) : Tot parser_kind | [] | LowParse.Spec.IfThenElse.parse_ifthenelse_payload_kind | {
"file_name": "src/lowparse/LowParse.Spec.IfThenElse.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | p: LowParse.Spec.IfThenElse.parse_ifthenelse_param -> LowParse.Spec.Base.parser_kind | {
"end_col": 102,
"end_line": 33,
"start_col": 2,
"start_line": 33
} |
Prims.Tot | val bare_serialize_ifthenelse (#p: parse_ifthenelse_param) (s: serialize_ifthenelse_param p)
: Tot (bare_serializer p.parse_ifthenelse_t) | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bare_serialize_ifthenelse
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (bare_serializer p.parse_ifthenelse_t)
= fun (d: p.parse_ifthenelse_t) ->
let (| t, y |) = s.serialize_ifthenelse_synth_recip d in
Seq.append (serialize s.serialize_ifthenelse_tag_serializer t) (serialize (s.serialize_ifthenelse_payload_serializer (p.parse_ifthenelse_tag_cond t)) y) | val bare_serialize_ifthenelse (#p: parse_ifthenelse_param) (s: serialize_ifthenelse_param p)
: Tot (bare_serializer p.parse_ifthenelse_t)
let bare_serialize_ifthenelse (#p: parse_ifthenelse_param) (s: serialize_ifthenelse_param p)
: Tot (bare_serializer p.parse_ifthenelse_t) = | false | null | false | fun (d: p.parse_ifthenelse_t) ->
let (| t , y |) = s.serialize_ifthenelse_synth_recip d in
Seq.append (serialize s.serialize_ifthenelse_tag_serializer t)
(serialize (s.serialize_ifthenelse_payload_serializer (p.parse_ifthenelse_tag_cond t)) y) | {
"checked_file": "LowParse.Spec.IfThenElse.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.IfThenElse.fst"
} | [
"total"
] | [
"LowParse.Spec.IfThenElse.parse_ifthenelse_param",
"LowParse.Spec.IfThenElse.serialize_ifthenelse_param",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_cond",
"FStar.Seq.Base.append",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.serialize",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_parser",
"LowParse.Spec.IfThenElse.__proj__Mkserialize_ifthenelse_param__item__serialize_ifthenelse_tag_serializer",
"Prims.__proj__Mkdtuple2__item___1",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_parser",
"FStar.Pervasives.dsnd",
"LowParse.Spec.IfThenElse.__proj__Mkserialize_ifthenelse_param__item__serialize_ifthenelse_payload_serializer",
"LowParse.Bytes.bytes",
"Prims.dtuple2",
"LowParse.Spec.IfThenElse.__proj__Mkserialize_ifthenelse_param__item__serialize_ifthenelse_synth_recip",
"LowParse.Spec.Base.bare_serializer"
] | [] | module LowParse.Spec.IfThenElse
include LowParse.Spec.Combinators
module Seq = FStar.Seq
[@@(noextract_to "krml")]
inline_for_extraction
noeq
type parse_ifthenelse_param = {
parse_ifthenelse_tag_kind: parser_kind;
parse_ifthenelse_tag_t: Type;
parse_ifthenelse_tag_parser: parser parse_ifthenelse_tag_kind parse_ifthenelse_tag_t;
parse_ifthenelse_tag_cond: (parse_ifthenelse_tag_t -> Tot bool);
parse_ifthenelse_payload_t: (bool -> Tot Type);
parse_ifthenelse_payload_parser: ((b: bool) -> Tot (k: parser_kind & parser k (parse_ifthenelse_payload_t b)));
parse_ifthenelse_t: Type;
parse_ifthenelse_synth: ((t: parse_ifthenelse_tag_t) -> (parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t)) -> GTot parse_ifthenelse_t);
parse_ifthenelse_synth_injective: (
(t1: parse_ifthenelse_tag_t) ->
(x1: parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t1)) ->
(t2: parse_ifthenelse_tag_t) ->
(x2: parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t2)) ->
Lemma
(requires (parse_ifthenelse_synth t1 x1 == parse_ifthenelse_synth t2 x2))
(ensures (t1 == t2 /\ coerce (parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t2)) x1 == x2))
);
}
inline_for_extraction
let parse_ifthenelse_payload_kind
(p: parse_ifthenelse_param)
: Tot parser_kind
= glb (dfst (p.parse_ifthenelse_payload_parser true)) (dfst (p.parse_ifthenelse_payload_parser false))
inline_for_extraction
let parse_ifthenelse_kind
(p: parse_ifthenelse_param)
: Tot parser_kind
= and_then_kind p.parse_ifthenelse_tag_kind (parse_ifthenelse_payload_kind p)
let parse_ifthenelse_synth_injective (p: parse_ifthenelse_param) (t: p.parse_ifthenelse_tag_t) : Lemma (synth_injective (p.parse_ifthenelse_synth t)) [SMTPat (synth_injective (p.parse_ifthenelse_synth t))] =
Classical.forall_intro_2 (fun x1 x2 -> Classical.move_requires (p.parse_ifthenelse_synth_injective t x1 t) x2)
let parse_ifthenelse_payload (p: parse_ifthenelse_param) (t: p.parse_ifthenelse_tag_t) : Tot (parser (parse_ifthenelse_payload_kind p) p.parse_ifthenelse_t) =
weaken (parse_ifthenelse_payload_kind p) (parse_synth (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t))) (p.parse_ifthenelse_synth t))
let parse_ifthenelse_payload_and_then_cases_injective (p: parse_ifthenelse_param) : Lemma
(and_then_cases_injective (parse_ifthenelse_payload p))
[SMTPat (and_then_cases_injective (parse_ifthenelse_payload p))]
= and_then_cases_injective_intro
(parse_ifthenelse_payload p)
(fun t1 t2 b1 b2 ->
parse_synth_eq (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t1))) (p.parse_ifthenelse_synth t1) b1;
parse_synth_eq (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t2))) (p.parse_ifthenelse_synth t2) b2;
let Some (x1, _) = parse (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t1))) b1 in
let Some (x2, _) = parse (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t2))) b2 in
p.parse_ifthenelse_synth_injective t1 x1 t2 x2
)
let parse_ifthenelse (p: parse_ifthenelse_param) : Tot (parser (parse_ifthenelse_kind p) p.parse_ifthenelse_t) =
and_then p.parse_ifthenelse_tag_parser (parse_ifthenelse_payload p)
let parse_ifthenelse_eq
(p: parse_ifthenelse_param)
(input: bytes)
: Lemma
(parse (parse_ifthenelse p) input == (
match parse p.parse_ifthenelse_tag_parser input with
| None -> None
| Some (t, consumed_t) ->
let b = p.parse_ifthenelse_tag_cond t in
let input' = Seq.slice input consumed_t (Seq.length input) in
match parse (dsnd (p.parse_ifthenelse_payload_parser b)) input' with
| None -> None
| Some (x, consumed_x) -> Some (p.parse_ifthenelse_synth t x, consumed_t + consumed_x)
))
= and_then_eq p.parse_ifthenelse_tag_parser (parse_ifthenelse_payload p) input;
match parse p.parse_ifthenelse_tag_parser input with
| None -> ()
| Some (t, consumed_t) ->
let b = p.parse_ifthenelse_tag_cond t in
let input' = Seq.slice input consumed_t (Seq.length input) in
let f : (p.parse_ifthenelse_payload_t (p.parse_ifthenelse_tag_cond t) -> GTot p.parse_ifthenelse_t) = (p.parse_ifthenelse_synth) t in
let f' = coerce (p.parse_ifthenelse_payload_t b -> GTot p.parse_ifthenelse_t) f in
parse_synth_eq
#(dfst (p.parse_ifthenelse_payload_parser b))
#(p.parse_ifthenelse_payload_t b)
#(p.parse_ifthenelse_t)
(dsnd (p.parse_ifthenelse_payload_parser b)) f' input'
noextract
inline_for_extraction
noeq
type serialize_ifthenelse_param (p: parse_ifthenelse_param) = {
serialize_ifthenelse_tag_serializer: serializer p.parse_ifthenelse_tag_parser;
serialize_ifthenelse_payload_serializer: ((b: bool) -> Tot (serializer (dsnd (p.parse_ifthenelse_payload_parser b))));
serialize_ifthenelse_synth_recip: (p.parse_ifthenelse_t -> GTot ( t: p.parse_ifthenelse_tag_t & (p.parse_ifthenelse_payload_t (p.parse_ifthenelse_tag_cond t))));
serialize_ifthenelse_synth_inverse: (
(x: p.parse_ifthenelse_t) ->
Lemma
(let (| t, y |) = serialize_ifthenelse_synth_recip x in
p.parse_ifthenelse_synth t y == x)
);
}
let bare_serialize_ifthenelse
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p) | false | false | LowParse.Spec.IfThenElse.fst | {
"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"
} | null | val bare_serialize_ifthenelse (#p: parse_ifthenelse_param) (s: serialize_ifthenelse_param p)
: Tot (bare_serializer p.parse_ifthenelse_t) | [] | LowParse.Spec.IfThenElse.bare_serialize_ifthenelse | {
"file_name": "src/lowparse/LowParse.Spec.IfThenElse.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | s: LowParse.Spec.IfThenElse.serialize_ifthenelse_param p
-> LowParse.Spec.Base.bare_serializer (Mkparse_ifthenelse_param?.parse_ifthenelse_t p) | {
"end_col": 154,
"end_line": 112,
"start_col": 2,
"start_line": 110
} |
Prims.Tot | val parse_ifthenelse (p: parse_ifthenelse_param)
: Tot (parser (parse_ifthenelse_kind p) p.parse_ifthenelse_t) | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_ifthenelse (p: parse_ifthenelse_param) : Tot (parser (parse_ifthenelse_kind p) p.parse_ifthenelse_t) =
and_then p.parse_ifthenelse_tag_parser (parse_ifthenelse_payload p) | val parse_ifthenelse (p: parse_ifthenelse_param)
: Tot (parser (parse_ifthenelse_kind p) p.parse_ifthenelse_t)
let parse_ifthenelse (p: parse_ifthenelse_param)
: Tot (parser (parse_ifthenelse_kind p) p.parse_ifthenelse_t) = | false | null | false | and_then p.parse_ifthenelse_tag_parser (parse_ifthenelse_payload p) | {
"checked_file": "LowParse.Spec.IfThenElse.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.IfThenElse.fst"
} | [
"total"
] | [
"LowParse.Spec.IfThenElse.parse_ifthenelse_param",
"LowParse.Spec.Combinators.and_then",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_parser",
"LowParse.Spec.IfThenElse.parse_ifthenelse_payload_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_t",
"LowParse.Spec.IfThenElse.parse_ifthenelse_payload",
"LowParse.Spec.Base.parser",
"LowParse.Spec.IfThenElse.parse_ifthenelse_kind"
] | [] | module LowParse.Spec.IfThenElse
include LowParse.Spec.Combinators
module Seq = FStar.Seq
[@@(noextract_to "krml")]
inline_for_extraction
noeq
type parse_ifthenelse_param = {
parse_ifthenelse_tag_kind: parser_kind;
parse_ifthenelse_tag_t: Type;
parse_ifthenelse_tag_parser: parser parse_ifthenelse_tag_kind parse_ifthenelse_tag_t;
parse_ifthenelse_tag_cond: (parse_ifthenelse_tag_t -> Tot bool);
parse_ifthenelse_payload_t: (bool -> Tot Type);
parse_ifthenelse_payload_parser: ((b: bool) -> Tot (k: parser_kind & parser k (parse_ifthenelse_payload_t b)));
parse_ifthenelse_t: Type;
parse_ifthenelse_synth: ((t: parse_ifthenelse_tag_t) -> (parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t)) -> GTot parse_ifthenelse_t);
parse_ifthenelse_synth_injective: (
(t1: parse_ifthenelse_tag_t) ->
(x1: parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t1)) ->
(t2: parse_ifthenelse_tag_t) ->
(x2: parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t2)) ->
Lemma
(requires (parse_ifthenelse_synth t1 x1 == parse_ifthenelse_synth t2 x2))
(ensures (t1 == t2 /\ coerce (parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t2)) x1 == x2))
);
}
inline_for_extraction
let parse_ifthenelse_payload_kind
(p: parse_ifthenelse_param)
: Tot parser_kind
= glb (dfst (p.parse_ifthenelse_payload_parser true)) (dfst (p.parse_ifthenelse_payload_parser false))
inline_for_extraction
let parse_ifthenelse_kind
(p: parse_ifthenelse_param)
: Tot parser_kind
= and_then_kind p.parse_ifthenelse_tag_kind (parse_ifthenelse_payload_kind p)
let parse_ifthenelse_synth_injective (p: parse_ifthenelse_param) (t: p.parse_ifthenelse_tag_t) : Lemma (synth_injective (p.parse_ifthenelse_synth t)) [SMTPat (synth_injective (p.parse_ifthenelse_synth t))] =
Classical.forall_intro_2 (fun x1 x2 -> Classical.move_requires (p.parse_ifthenelse_synth_injective t x1 t) x2)
let parse_ifthenelse_payload (p: parse_ifthenelse_param) (t: p.parse_ifthenelse_tag_t) : Tot (parser (parse_ifthenelse_payload_kind p) p.parse_ifthenelse_t) =
weaken (parse_ifthenelse_payload_kind p) (parse_synth (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t))) (p.parse_ifthenelse_synth t))
let parse_ifthenelse_payload_and_then_cases_injective (p: parse_ifthenelse_param) : Lemma
(and_then_cases_injective (parse_ifthenelse_payload p))
[SMTPat (and_then_cases_injective (parse_ifthenelse_payload p))]
= and_then_cases_injective_intro
(parse_ifthenelse_payload p)
(fun t1 t2 b1 b2 ->
parse_synth_eq (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t1))) (p.parse_ifthenelse_synth t1) b1;
parse_synth_eq (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t2))) (p.parse_ifthenelse_synth t2) b2;
let Some (x1, _) = parse (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t1))) b1 in
let Some (x2, _) = parse (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t2))) b2 in
p.parse_ifthenelse_synth_injective t1 x1 t2 x2
) | false | false | LowParse.Spec.IfThenElse.fst | {
"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"
} | null | val parse_ifthenelse (p: parse_ifthenelse_param)
: Tot (parser (parse_ifthenelse_kind p) p.parse_ifthenelse_t) | [] | LowParse.Spec.IfThenElse.parse_ifthenelse | {
"file_name": "src/lowparse/LowParse.Spec.IfThenElse.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | p: LowParse.Spec.IfThenElse.parse_ifthenelse_param
-> LowParse.Spec.Base.parser (LowParse.Spec.IfThenElse.parse_ifthenelse_kind p)
(Mkparse_ifthenelse_param?.parse_ifthenelse_t p) | {
"end_col": 69,
"end_line": 61,
"start_col": 2,
"start_line": 61
} |
FStar.Pervasives.Lemma | val parse_ifthenelse_synth_injective (p: parse_ifthenelse_param) (t: p.parse_ifthenelse_tag_t)
: Lemma (synth_injective (p.parse_ifthenelse_synth t))
[SMTPat (synth_injective (p.parse_ifthenelse_synth t))] | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_ifthenelse_synth_injective (p: parse_ifthenelse_param) (t: p.parse_ifthenelse_tag_t) : Lemma (synth_injective (p.parse_ifthenelse_synth t)) [SMTPat (synth_injective (p.parse_ifthenelse_synth t))] =
Classical.forall_intro_2 (fun x1 x2 -> Classical.move_requires (p.parse_ifthenelse_synth_injective t x1 t) x2) | val parse_ifthenelse_synth_injective (p: parse_ifthenelse_param) (t: p.parse_ifthenelse_tag_t)
: Lemma (synth_injective (p.parse_ifthenelse_synth t))
[SMTPat (synth_injective (p.parse_ifthenelse_synth t))]
let parse_ifthenelse_synth_injective (p: parse_ifthenelse_param) (t: p.parse_ifthenelse_tag_t)
: Lemma (synth_injective (p.parse_ifthenelse_synth t))
[SMTPat (synth_injective (p.parse_ifthenelse_synth t))] = | false | null | true | Classical.forall_intro_2 (fun x1 x2 ->
Classical.move_requires (p.parse_ifthenelse_synth_injective t x1 t) x2) | {
"checked_file": "LowParse.Spec.IfThenElse.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.IfThenElse.fst"
} | [
"lemma"
] | [
"LowParse.Spec.IfThenElse.parse_ifthenelse_param",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_t",
"FStar.Classical.forall_intro_2",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_cond",
"Prims.l_imp",
"Prims.eq2",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_synth",
"Prims.l_and",
"FStar.Classical.move_requires",
"LowParse.Spec.Base.coerce",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_synth_injective",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"LowParse.Spec.Combinators.synth_injective",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | module LowParse.Spec.IfThenElse
include LowParse.Spec.Combinators
module Seq = FStar.Seq
[@@(noextract_to "krml")]
inline_for_extraction
noeq
type parse_ifthenelse_param = {
parse_ifthenelse_tag_kind: parser_kind;
parse_ifthenelse_tag_t: Type;
parse_ifthenelse_tag_parser: parser parse_ifthenelse_tag_kind parse_ifthenelse_tag_t;
parse_ifthenelse_tag_cond: (parse_ifthenelse_tag_t -> Tot bool);
parse_ifthenelse_payload_t: (bool -> Tot Type);
parse_ifthenelse_payload_parser: ((b: bool) -> Tot (k: parser_kind & parser k (parse_ifthenelse_payload_t b)));
parse_ifthenelse_t: Type;
parse_ifthenelse_synth: ((t: parse_ifthenelse_tag_t) -> (parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t)) -> GTot parse_ifthenelse_t);
parse_ifthenelse_synth_injective: (
(t1: parse_ifthenelse_tag_t) ->
(x1: parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t1)) ->
(t2: parse_ifthenelse_tag_t) ->
(x2: parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t2)) ->
Lemma
(requires (parse_ifthenelse_synth t1 x1 == parse_ifthenelse_synth t2 x2))
(ensures (t1 == t2 /\ coerce (parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t2)) x1 == x2))
);
}
inline_for_extraction
let parse_ifthenelse_payload_kind
(p: parse_ifthenelse_param)
: Tot parser_kind
= glb (dfst (p.parse_ifthenelse_payload_parser true)) (dfst (p.parse_ifthenelse_payload_parser false))
inline_for_extraction
let parse_ifthenelse_kind
(p: parse_ifthenelse_param)
: Tot parser_kind
= and_then_kind p.parse_ifthenelse_tag_kind (parse_ifthenelse_payload_kind p) | false | false | LowParse.Spec.IfThenElse.fst | {
"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"
} | null | val parse_ifthenelse_synth_injective (p: parse_ifthenelse_param) (t: p.parse_ifthenelse_tag_t)
: Lemma (synth_injective (p.parse_ifthenelse_synth t))
[SMTPat (synth_injective (p.parse_ifthenelse_synth t))] | [] | LowParse.Spec.IfThenElse.parse_ifthenelse_synth_injective | {
"file_name": "src/lowparse/LowParse.Spec.IfThenElse.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
p: LowParse.Spec.IfThenElse.parse_ifthenelse_param ->
t: Mkparse_ifthenelse_param?.parse_ifthenelse_tag_t p
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.Combinators.synth_injective (Mkparse_ifthenelse_param?.parse_ifthenelse_synth p
t))
[
SMTPat (LowParse.Spec.Combinators.synth_injective (Mkparse_ifthenelse_param?.parse_ifthenelse_synth
p
t))
] | {
"end_col": 112,
"end_line": 42,
"start_col": 2,
"start_line": 42
} |
Prims.Tot | val serialize_ifthenelse
(#p: parse_ifthenelse_param)
(s:
serialize_ifthenelse_param p
{p.parse_ifthenelse_tag_kind.parser_kind_subkind == Some ParserStrong})
: Tot (serializer (parse_ifthenelse p)) | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialize_ifthenelse
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p { p.parse_ifthenelse_tag_kind.parser_kind_subkind == Some ParserStrong } )
: Tot (serializer (parse_ifthenelse p))
= bare_serialize_ifthenelse_correct s;
bare_serialize_ifthenelse s | val serialize_ifthenelse
(#p: parse_ifthenelse_param)
(s:
serialize_ifthenelse_param p
{p.parse_ifthenelse_tag_kind.parser_kind_subkind == Some ParserStrong})
: Tot (serializer (parse_ifthenelse p))
let serialize_ifthenelse
(#p: parse_ifthenelse_param)
(s:
serialize_ifthenelse_param p
{p.parse_ifthenelse_tag_kind.parser_kind_subkind == Some ParserStrong})
: Tot (serializer (parse_ifthenelse p)) = | false | null | false | bare_serialize_ifthenelse_correct s;
bare_serialize_ifthenelse s | {
"checked_file": "LowParse.Spec.IfThenElse.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.IfThenElse.fst"
} | [
"total"
] | [
"LowParse.Spec.IfThenElse.parse_ifthenelse_param",
"LowParse.Spec.IfThenElse.serialize_ifthenelse_param",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_kind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Spec.IfThenElse.bare_serialize_ifthenelse",
"Prims.unit",
"LowParse.Spec.IfThenElse.bare_serialize_ifthenelse_correct",
"LowParse.Spec.Base.serializer",
"LowParse.Spec.IfThenElse.parse_ifthenelse_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_t",
"LowParse.Spec.IfThenElse.parse_ifthenelse"
] | [] | module LowParse.Spec.IfThenElse
include LowParse.Spec.Combinators
module Seq = FStar.Seq
[@@(noextract_to "krml")]
inline_for_extraction
noeq
type parse_ifthenelse_param = {
parse_ifthenelse_tag_kind: parser_kind;
parse_ifthenelse_tag_t: Type;
parse_ifthenelse_tag_parser: parser parse_ifthenelse_tag_kind parse_ifthenelse_tag_t;
parse_ifthenelse_tag_cond: (parse_ifthenelse_tag_t -> Tot bool);
parse_ifthenelse_payload_t: (bool -> Tot Type);
parse_ifthenelse_payload_parser: ((b: bool) -> Tot (k: parser_kind & parser k (parse_ifthenelse_payload_t b)));
parse_ifthenelse_t: Type;
parse_ifthenelse_synth: ((t: parse_ifthenelse_tag_t) -> (parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t)) -> GTot parse_ifthenelse_t);
parse_ifthenelse_synth_injective: (
(t1: parse_ifthenelse_tag_t) ->
(x1: parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t1)) ->
(t2: parse_ifthenelse_tag_t) ->
(x2: parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t2)) ->
Lemma
(requires (parse_ifthenelse_synth t1 x1 == parse_ifthenelse_synth t2 x2))
(ensures (t1 == t2 /\ coerce (parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t2)) x1 == x2))
);
}
inline_for_extraction
let parse_ifthenelse_payload_kind
(p: parse_ifthenelse_param)
: Tot parser_kind
= glb (dfst (p.parse_ifthenelse_payload_parser true)) (dfst (p.parse_ifthenelse_payload_parser false))
inline_for_extraction
let parse_ifthenelse_kind
(p: parse_ifthenelse_param)
: Tot parser_kind
= and_then_kind p.parse_ifthenelse_tag_kind (parse_ifthenelse_payload_kind p)
let parse_ifthenelse_synth_injective (p: parse_ifthenelse_param) (t: p.parse_ifthenelse_tag_t) : Lemma (synth_injective (p.parse_ifthenelse_synth t)) [SMTPat (synth_injective (p.parse_ifthenelse_synth t))] =
Classical.forall_intro_2 (fun x1 x2 -> Classical.move_requires (p.parse_ifthenelse_synth_injective t x1 t) x2)
let parse_ifthenelse_payload (p: parse_ifthenelse_param) (t: p.parse_ifthenelse_tag_t) : Tot (parser (parse_ifthenelse_payload_kind p) p.parse_ifthenelse_t) =
weaken (parse_ifthenelse_payload_kind p) (parse_synth (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t))) (p.parse_ifthenelse_synth t))
let parse_ifthenelse_payload_and_then_cases_injective (p: parse_ifthenelse_param) : Lemma
(and_then_cases_injective (parse_ifthenelse_payload p))
[SMTPat (and_then_cases_injective (parse_ifthenelse_payload p))]
= and_then_cases_injective_intro
(parse_ifthenelse_payload p)
(fun t1 t2 b1 b2 ->
parse_synth_eq (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t1))) (p.parse_ifthenelse_synth t1) b1;
parse_synth_eq (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t2))) (p.parse_ifthenelse_synth t2) b2;
let Some (x1, _) = parse (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t1))) b1 in
let Some (x2, _) = parse (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t2))) b2 in
p.parse_ifthenelse_synth_injective t1 x1 t2 x2
)
let parse_ifthenelse (p: parse_ifthenelse_param) : Tot (parser (parse_ifthenelse_kind p) p.parse_ifthenelse_t) =
and_then p.parse_ifthenelse_tag_parser (parse_ifthenelse_payload p)
let parse_ifthenelse_eq
(p: parse_ifthenelse_param)
(input: bytes)
: Lemma
(parse (parse_ifthenelse p) input == (
match parse p.parse_ifthenelse_tag_parser input with
| None -> None
| Some (t, consumed_t) ->
let b = p.parse_ifthenelse_tag_cond t in
let input' = Seq.slice input consumed_t (Seq.length input) in
match parse (dsnd (p.parse_ifthenelse_payload_parser b)) input' with
| None -> None
| Some (x, consumed_x) -> Some (p.parse_ifthenelse_synth t x, consumed_t + consumed_x)
))
= and_then_eq p.parse_ifthenelse_tag_parser (parse_ifthenelse_payload p) input;
match parse p.parse_ifthenelse_tag_parser input with
| None -> ()
| Some (t, consumed_t) ->
let b = p.parse_ifthenelse_tag_cond t in
let input' = Seq.slice input consumed_t (Seq.length input) in
let f : (p.parse_ifthenelse_payload_t (p.parse_ifthenelse_tag_cond t) -> GTot p.parse_ifthenelse_t) = (p.parse_ifthenelse_synth) t in
let f' = coerce (p.parse_ifthenelse_payload_t b -> GTot p.parse_ifthenelse_t) f in
parse_synth_eq
#(dfst (p.parse_ifthenelse_payload_parser b))
#(p.parse_ifthenelse_payload_t b)
#(p.parse_ifthenelse_t)
(dsnd (p.parse_ifthenelse_payload_parser b)) f' input'
noextract
inline_for_extraction
noeq
type serialize_ifthenelse_param (p: parse_ifthenelse_param) = {
serialize_ifthenelse_tag_serializer: serializer p.parse_ifthenelse_tag_parser;
serialize_ifthenelse_payload_serializer: ((b: bool) -> Tot (serializer (dsnd (p.parse_ifthenelse_payload_parser b))));
serialize_ifthenelse_synth_recip: (p.parse_ifthenelse_t -> GTot ( t: p.parse_ifthenelse_tag_t & (p.parse_ifthenelse_payload_t (p.parse_ifthenelse_tag_cond t))));
serialize_ifthenelse_synth_inverse: (
(x: p.parse_ifthenelse_t) ->
Lemma
(let (| t, y |) = serialize_ifthenelse_synth_recip x in
p.parse_ifthenelse_synth t y == x)
);
}
let bare_serialize_ifthenelse
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (bare_serializer p.parse_ifthenelse_t)
= fun (d: p.parse_ifthenelse_t) ->
let (| t, y |) = s.serialize_ifthenelse_synth_recip d in
Seq.append (serialize s.serialize_ifthenelse_tag_serializer t) (serialize (s.serialize_ifthenelse_payload_serializer (p.parse_ifthenelse_tag_cond t)) y)
let bare_serialize_ifthenelse_correct
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Lemma
(requires (p.parse_ifthenelse_tag_kind.parser_kind_subkind == Some ParserStrong))
(ensures (serializer_correct (parse_ifthenelse p) (bare_serialize_ifthenelse s)))
= let prf
(x: p.parse_ifthenelse_t)
: Lemma
(let sq = bare_serialize_ifthenelse s x in
parse (parse_ifthenelse p) sq == Some (x, Seq.length sq))
= let sq = bare_serialize_ifthenelse s x in
parse_ifthenelse_eq p sq;
let (| t, y |) = s.serialize_ifthenelse_synth_recip x in
let sqt = serialize s.serialize_ifthenelse_tag_serializer t in
let sqp = serialize (s.serialize_ifthenelse_payload_serializer (p.parse_ifthenelse_tag_cond t)) y in
parse_strong_prefix p.parse_ifthenelse_tag_parser sqt sq;
assert (Seq.slice sq (Seq.length sqt) (Seq.length sq) `Seq.equal` sqp);
s.serialize_ifthenelse_synth_inverse x
in
Classical.forall_intro prf
let serialize_ifthenelse
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p { p.parse_ifthenelse_tag_kind.parser_kind_subkind == Some ParserStrong } ) | false | false | LowParse.Spec.IfThenElse.fst | {
"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"
} | null | val serialize_ifthenelse
(#p: parse_ifthenelse_param)
(s:
serialize_ifthenelse_param p
{p.parse_ifthenelse_tag_kind.parser_kind_subkind == Some ParserStrong})
: Tot (serializer (parse_ifthenelse p)) | [] | LowParse.Spec.IfThenElse.serialize_ifthenelse | {
"file_name": "src/lowparse/LowParse.Spec.IfThenElse.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s:
LowParse.Spec.IfThenElse.serialize_ifthenelse_param p
{ Mkparser_kind'?.parser_kind_subkind (Mkparse_ifthenelse_param?.parse_ifthenelse_tag_kind p
) ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong }
-> LowParse.Spec.Base.serializer (LowParse.Spec.IfThenElse.parse_ifthenelse p) | {
"end_col": 29,
"end_line": 141,
"start_col": 2,
"start_line": 140
} |
Prims.Tot | val parse_ifthenelse_payload (p: parse_ifthenelse_param) (t: p.parse_ifthenelse_tag_t)
: Tot (parser (parse_ifthenelse_payload_kind p) p.parse_ifthenelse_t) | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_ifthenelse_payload (p: parse_ifthenelse_param) (t: p.parse_ifthenelse_tag_t) : Tot (parser (parse_ifthenelse_payload_kind p) p.parse_ifthenelse_t) =
weaken (parse_ifthenelse_payload_kind p) (parse_synth (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t))) (p.parse_ifthenelse_synth t)) | val parse_ifthenelse_payload (p: parse_ifthenelse_param) (t: p.parse_ifthenelse_tag_t)
: Tot (parser (parse_ifthenelse_payload_kind p) p.parse_ifthenelse_t)
let parse_ifthenelse_payload (p: parse_ifthenelse_param) (t: p.parse_ifthenelse_tag_t)
: Tot (parser (parse_ifthenelse_payload_kind p) p.parse_ifthenelse_t) = | false | null | false | weaken (parse_ifthenelse_payload_kind p)
(parse_synth (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t)))
(p.parse_ifthenelse_synth t)) | {
"checked_file": "LowParse.Spec.IfThenElse.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.IfThenElse.fst"
} | [
"total"
] | [
"LowParse.Spec.IfThenElse.parse_ifthenelse_param",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_t",
"LowParse.Spec.Base.weaken",
"LowParse.Spec.IfThenElse.parse_ifthenelse_payload_kind",
"Prims.__proj__Mkdtuple2__item___1",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_cond",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_parser",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_t",
"LowParse.Spec.Combinators.parse_synth",
"FStar.Pervasives.dsnd",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_synth"
] | [] | module LowParse.Spec.IfThenElse
include LowParse.Spec.Combinators
module Seq = FStar.Seq
[@@(noextract_to "krml")]
inline_for_extraction
noeq
type parse_ifthenelse_param = {
parse_ifthenelse_tag_kind: parser_kind;
parse_ifthenelse_tag_t: Type;
parse_ifthenelse_tag_parser: parser parse_ifthenelse_tag_kind parse_ifthenelse_tag_t;
parse_ifthenelse_tag_cond: (parse_ifthenelse_tag_t -> Tot bool);
parse_ifthenelse_payload_t: (bool -> Tot Type);
parse_ifthenelse_payload_parser: ((b: bool) -> Tot (k: parser_kind & parser k (parse_ifthenelse_payload_t b)));
parse_ifthenelse_t: Type;
parse_ifthenelse_synth: ((t: parse_ifthenelse_tag_t) -> (parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t)) -> GTot parse_ifthenelse_t);
parse_ifthenelse_synth_injective: (
(t1: parse_ifthenelse_tag_t) ->
(x1: parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t1)) ->
(t2: parse_ifthenelse_tag_t) ->
(x2: parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t2)) ->
Lemma
(requires (parse_ifthenelse_synth t1 x1 == parse_ifthenelse_synth t2 x2))
(ensures (t1 == t2 /\ coerce (parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t2)) x1 == x2))
);
}
inline_for_extraction
let parse_ifthenelse_payload_kind
(p: parse_ifthenelse_param)
: Tot parser_kind
= glb (dfst (p.parse_ifthenelse_payload_parser true)) (dfst (p.parse_ifthenelse_payload_parser false))
inline_for_extraction
let parse_ifthenelse_kind
(p: parse_ifthenelse_param)
: Tot parser_kind
= and_then_kind p.parse_ifthenelse_tag_kind (parse_ifthenelse_payload_kind p)
let parse_ifthenelse_synth_injective (p: parse_ifthenelse_param) (t: p.parse_ifthenelse_tag_t) : Lemma (synth_injective (p.parse_ifthenelse_synth t)) [SMTPat (synth_injective (p.parse_ifthenelse_synth t))] =
Classical.forall_intro_2 (fun x1 x2 -> Classical.move_requires (p.parse_ifthenelse_synth_injective t x1 t) x2) | false | false | LowParse.Spec.IfThenElse.fst | {
"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"
} | null | val parse_ifthenelse_payload (p: parse_ifthenelse_param) (t: p.parse_ifthenelse_tag_t)
: Tot (parser (parse_ifthenelse_payload_kind p) p.parse_ifthenelse_t) | [] | LowParse.Spec.IfThenElse.parse_ifthenelse_payload | {
"file_name": "src/lowparse/LowParse.Spec.IfThenElse.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
p: LowParse.Spec.IfThenElse.parse_ifthenelse_param ->
t: Mkparse_ifthenelse_param?.parse_ifthenelse_tag_t p
-> LowParse.Spec.Base.parser (LowParse.Spec.IfThenElse.parse_ifthenelse_payload_kind p)
(Mkparse_ifthenelse_param?.parse_ifthenelse_t p) | {
"end_col": 160,
"end_line": 45,
"start_col": 2,
"start_line": 45
} |
FStar.Pervasives.Lemma | val parse_ifthenelse_payload_and_then_cases_injective (p: parse_ifthenelse_param)
: Lemma (and_then_cases_injective (parse_ifthenelse_payload p))
[SMTPat (and_then_cases_injective (parse_ifthenelse_payload p))] | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_ifthenelse_payload_and_then_cases_injective (p: parse_ifthenelse_param) : Lemma
(and_then_cases_injective (parse_ifthenelse_payload p))
[SMTPat (and_then_cases_injective (parse_ifthenelse_payload p))]
= and_then_cases_injective_intro
(parse_ifthenelse_payload p)
(fun t1 t2 b1 b2 ->
parse_synth_eq (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t1))) (p.parse_ifthenelse_synth t1) b1;
parse_synth_eq (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t2))) (p.parse_ifthenelse_synth t2) b2;
let Some (x1, _) = parse (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t1))) b1 in
let Some (x2, _) = parse (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t2))) b2 in
p.parse_ifthenelse_synth_injective t1 x1 t2 x2
) | val parse_ifthenelse_payload_and_then_cases_injective (p: parse_ifthenelse_param)
: Lemma (and_then_cases_injective (parse_ifthenelse_payload p))
[SMTPat (and_then_cases_injective (parse_ifthenelse_payload p))]
let parse_ifthenelse_payload_and_then_cases_injective (p: parse_ifthenelse_param)
: Lemma (and_then_cases_injective (parse_ifthenelse_payload p))
[SMTPat (and_then_cases_injective (parse_ifthenelse_payload p))] = | false | null | true | and_then_cases_injective_intro (parse_ifthenelse_payload p)
(fun t1 t2 b1 b2 ->
parse_synth_eq (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t1)))
(p.parse_ifthenelse_synth t1)
b1;
parse_synth_eq (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t2)))
(p.parse_ifthenelse_synth t2)
b2;
let Some (x1, _) =
parse (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t1))) b1
in
let Some (x2, _) =
parse (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t2))) b2
in
p.parse_ifthenelse_synth_injective t1 x1 t2 x2) | {
"checked_file": "LowParse.Spec.IfThenElse.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.IfThenElse.fst"
} | [
"lemma"
] | [
"LowParse.Spec.IfThenElse.parse_ifthenelse_param",
"LowParse.Spec.Combinators.and_then_cases_injective_intro",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_t",
"LowParse.Spec.IfThenElse.parse_ifthenelse_payload",
"LowParse.Bytes.bytes",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_cond",
"LowParse.Spec.Base.consumed_length",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_synth_injective",
"Prims.unit",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.parse",
"FStar.Pervasives.dsnd",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_parser",
"LowParse.Spec.Combinators.parse_synth_eq",
"Prims.__proj__Mkdtuple2__item___1",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_synth",
"Prims.l_True",
"Prims.squash",
"LowParse.Spec.Combinators.and_then_cases_injective",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | module LowParse.Spec.IfThenElse
include LowParse.Spec.Combinators
module Seq = FStar.Seq
[@@(noextract_to "krml")]
inline_for_extraction
noeq
type parse_ifthenelse_param = {
parse_ifthenelse_tag_kind: parser_kind;
parse_ifthenelse_tag_t: Type;
parse_ifthenelse_tag_parser: parser parse_ifthenelse_tag_kind parse_ifthenelse_tag_t;
parse_ifthenelse_tag_cond: (parse_ifthenelse_tag_t -> Tot bool);
parse_ifthenelse_payload_t: (bool -> Tot Type);
parse_ifthenelse_payload_parser: ((b: bool) -> Tot (k: parser_kind & parser k (parse_ifthenelse_payload_t b)));
parse_ifthenelse_t: Type;
parse_ifthenelse_synth: ((t: parse_ifthenelse_tag_t) -> (parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t)) -> GTot parse_ifthenelse_t);
parse_ifthenelse_synth_injective: (
(t1: parse_ifthenelse_tag_t) ->
(x1: parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t1)) ->
(t2: parse_ifthenelse_tag_t) ->
(x2: parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t2)) ->
Lemma
(requires (parse_ifthenelse_synth t1 x1 == parse_ifthenelse_synth t2 x2))
(ensures (t1 == t2 /\ coerce (parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t2)) x1 == x2))
);
}
inline_for_extraction
let parse_ifthenelse_payload_kind
(p: parse_ifthenelse_param)
: Tot parser_kind
= glb (dfst (p.parse_ifthenelse_payload_parser true)) (dfst (p.parse_ifthenelse_payload_parser false))
inline_for_extraction
let parse_ifthenelse_kind
(p: parse_ifthenelse_param)
: Tot parser_kind
= and_then_kind p.parse_ifthenelse_tag_kind (parse_ifthenelse_payload_kind p)
let parse_ifthenelse_synth_injective (p: parse_ifthenelse_param) (t: p.parse_ifthenelse_tag_t) : Lemma (synth_injective (p.parse_ifthenelse_synth t)) [SMTPat (synth_injective (p.parse_ifthenelse_synth t))] =
Classical.forall_intro_2 (fun x1 x2 -> Classical.move_requires (p.parse_ifthenelse_synth_injective t x1 t) x2)
let parse_ifthenelse_payload (p: parse_ifthenelse_param) (t: p.parse_ifthenelse_tag_t) : Tot (parser (parse_ifthenelse_payload_kind p) p.parse_ifthenelse_t) =
weaken (parse_ifthenelse_payload_kind p) (parse_synth (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t))) (p.parse_ifthenelse_synth t))
let parse_ifthenelse_payload_and_then_cases_injective (p: parse_ifthenelse_param) : Lemma
(and_then_cases_injective (parse_ifthenelse_payload p)) | false | false | LowParse.Spec.IfThenElse.fst | {
"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"
} | null | val parse_ifthenelse_payload_and_then_cases_injective (p: parse_ifthenelse_param)
: Lemma (and_then_cases_injective (parse_ifthenelse_payload p))
[SMTPat (and_then_cases_injective (parse_ifthenelse_payload p))] | [] | LowParse.Spec.IfThenElse.parse_ifthenelse_payload_and_then_cases_injective | {
"file_name": "src/lowparse/LowParse.Spec.IfThenElse.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | p: LowParse.Spec.IfThenElse.parse_ifthenelse_param
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.Combinators.and_then_cases_injective (LowParse.Spec.IfThenElse.parse_ifthenelse_payload
p))
[
SMTPat (LowParse.Spec.Combinators.and_then_cases_injective (LowParse.Spec.IfThenElse.parse_ifthenelse_payload
p))
] | {
"end_col": 5,
"end_line": 58,
"start_col": 2,
"start_line": 50
} |
FStar.Pervasives.Lemma | val serialize_ifthenelse_synth_inverse'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(tg: p.parse_ifthenelse_tag_t)
(pl: p.parse_ifthenelse_payload_t (p.parse_ifthenelse_tag_cond tg))
: Lemma (s.serialize_ifthenelse_synth_recip (p.parse_ifthenelse_synth tg pl) == (| tg, pl |)) | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialize_ifthenelse_synth_inverse'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(tg: p.parse_ifthenelse_tag_t)
(pl: p.parse_ifthenelse_payload_t (p.parse_ifthenelse_tag_cond tg))
: Lemma
(s.serialize_ifthenelse_synth_recip (p.parse_ifthenelse_synth tg pl) == (| tg, pl |))
= let (| tg', pl' |) = s.serialize_ifthenelse_synth_recip (p.parse_ifthenelse_synth tg pl) in
s.serialize_ifthenelse_synth_inverse (p.parse_ifthenelse_synth tg pl);
p.parse_ifthenelse_synth_injective tg pl tg' pl' | val serialize_ifthenelse_synth_inverse'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(tg: p.parse_ifthenelse_tag_t)
(pl: p.parse_ifthenelse_payload_t (p.parse_ifthenelse_tag_cond tg))
: Lemma (s.serialize_ifthenelse_synth_recip (p.parse_ifthenelse_synth tg pl) == (| tg, pl |))
let serialize_ifthenelse_synth_inverse'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(tg: p.parse_ifthenelse_tag_t)
(pl: p.parse_ifthenelse_payload_t (p.parse_ifthenelse_tag_cond tg))
: Lemma (s.serialize_ifthenelse_synth_recip (p.parse_ifthenelse_synth tg pl) == (| tg, pl |)) = | false | null | true | let (| tg' , pl' |) = s.serialize_ifthenelse_synth_recip (p.parse_ifthenelse_synth tg pl) in
s.serialize_ifthenelse_synth_inverse (p.parse_ifthenelse_synth tg pl);
p.parse_ifthenelse_synth_injective tg pl tg' pl' | {
"checked_file": "LowParse.Spec.IfThenElse.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.IfThenElse.fst"
} | [
"lemma"
] | [
"LowParse.Spec.IfThenElse.parse_ifthenelse_param",
"LowParse.Spec.IfThenElse.serialize_ifthenelse_param",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_cond",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_synth_injective",
"Prims.unit",
"LowParse.Spec.IfThenElse.__proj__Mkserialize_ifthenelse_param__item__serialize_ifthenelse_synth_inverse",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_synth",
"Prims.dtuple2",
"LowParse.Spec.IfThenElse.__proj__Mkserialize_ifthenelse_param__item__serialize_ifthenelse_synth_recip",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Prims.Mkdtuple2",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.IfThenElse
include LowParse.Spec.Combinators
module Seq = FStar.Seq
[@@(noextract_to "krml")]
inline_for_extraction
noeq
type parse_ifthenelse_param = {
parse_ifthenelse_tag_kind: parser_kind;
parse_ifthenelse_tag_t: Type;
parse_ifthenelse_tag_parser: parser parse_ifthenelse_tag_kind parse_ifthenelse_tag_t;
parse_ifthenelse_tag_cond: (parse_ifthenelse_tag_t -> Tot bool);
parse_ifthenelse_payload_t: (bool -> Tot Type);
parse_ifthenelse_payload_parser: ((b: bool) -> Tot (k: parser_kind & parser k (parse_ifthenelse_payload_t b)));
parse_ifthenelse_t: Type;
parse_ifthenelse_synth: ((t: parse_ifthenelse_tag_t) -> (parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t)) -> GTot parse_ifthenelse_t);
parse_ifthenelse_synth_injective: (
(t1: parse_ifthenelse_tag_t) ->
(x1: parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t1)) ->
(t2: parse_ifthenelse_tag_t) ->
(x2: parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t2)) ->
Lemma
(requires (parse_ifthenelse_synth t1 x1 == parse_ifthenelse_synth t2 x2))
(ensures (t1 == t2 /\ coerce (parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t2)) x1 == x2))
);
}
inline_for_extraction
let parse_ifthenelse_payload_kind
(p: parse_ifthenelse_param)
: Tot parser_kind
= glb (dfst (p.parse_ifthenelse_payload_parser true)) (dfst (p.parse_ifthenelse_payload_parser false))
inline_for_extraction
let parse_ifthenelse_kind
(p: parse_ifthenelse_param)
: Tot parser_kind
= and_then_kind p.parse_ifthenelse_tag_kind (parse_ifthenelse_payload_kind p)
let parse_ifthenelse_synth_injective (p: parse_ifthenelse_param) (t: p.parse_ifthenelse_tag_t) : Lemma (synth_injective (p.parse_ifthenelse_synth t)) [SMTPat (synth_injective (p.parse_ifthenelse_synth t))] =
Classical.forall_intro_2 (fun x1 x2 -> Classical.move_requires (p.parse_ifthenelse_synth_injective t x1 t) x2)
let parse_ifthenelse_payload (p: parse_ifthenelse_param) (t: p.parse_ifthenelse_tag_t) : Tot (parser (parse_ifthenelse_payload_kind p) p.parse_ifthenelse_t) =
weaken (parse_ifthenelse_payload_kind p) (parse_synth (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t))) (p.parse_ifthenelse_synth t))
let parse_ifthenelse_payload_and_then_cases_injective (p: parse_ifthenelse_param) : Lemma
(and_then_cases_injective (parse_ifthenelse_payload p))
[SMTPat (and_then_cases_injective (parse_ifthenelse_payload p))]
= and_then_cases_injective_intro
(parse_ifthenelse_payload p)
(fun t1 t2 b1 b2 ->
parse_synth_eq (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t1))) (p.parse_ifthenelse_synth t1) b1;
parse_synth_eq (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t2))) (p.parse_ifthenelse_synth t2) b2;
let Some (x1, _) = parse (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t1))) b1 in
let Some (x2, _) = parse (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t2))) b2 in
p.parse_ifthenelse_synth_injective t1 x1 t2 x2
)
let parse_ifthenelse (p: parse_ifthenelse_param) : Tot (parser (parse_ifthenelse_kind p) p.parse_ifthenelse_t) =
and_then p.parse_ifthenelse_tag_parser (parse_ifthenelse_payload p)
let parse_ifthenelse_eq
(p: parse_ifthenelse_param)
(input: bytes)
: Lemma
(parse (parse_ifthenelse p) input == (
match parse p.parse_ifthenelse_tag_parser input with
| None -> None
| Some (t, consumed_t) ->
let b = p.parse_ifthenelse_tag_cond t in
let input' = Seq.slice input consumed_t (Seq.length input) in
match parse (dsnd (p.parse_ifthenelse_payload_parser b)) input' with
| None -> None
| Some (x, consumed_x) -> Some (p.parse_ifthenelse_synth t x, consumed_t + consumed_x)
))
= and_then_eq p.parse_ifthenelse_tag_parser (parse_ifthenelse_payload p) input;
match parse p.parse_ifthenelse_tag_parser input with
| None -> ()
| Some (t, consumed_t) ->
let b = p.parse_ifthenelse_tag_cond t in
let input' = Seq.slice input consumed_t (Seq.length input) in
let f : (p.parse_ifthenelse_payload_t (p.parse_ifthenelse_tag_cond t) -> GTot p.parse_ifthenelse_t) = (p.parse_ifthenelse_synth) t in
let f' = coerce (p.parse_ifthenelse_payload_t b -> GTot p.parse_ifthenelse_t) f in
parse_synth_eq
#(dfst (p.parse_ifthenelse_payload_parser b))
#(p.parse_ifthenelse_payload_t b)
#(p.parse_ifthenelse_t)
(dsnd (p.parse_ifthenelse_payload_parser b)) f' input'
noextract
inline_for_extraction
noeq
type serialize_ifthenelse_param (p: parse_ifthenelse_param) = {
serialize_ifthenelse_tag_serializer: serializer p.parse_ifthenelse_tag_parser;
serialize_ifthenelse_payload_serializer: ((b: bool) -> Tot (serializer (dsnd (p.parse_ifthenelse_payload_parser b))));
serialize_ifthenelse_synth_recip: (p.parse_ifthenelse_t -> GTot ( t: p.parse_ifthenelse_tag_t & (p.parse_ifthenelse_payload_t (p.parse_ifthenelse_tag_cond t))));
serialize_ifthenelse_synth_inverse: (
(x: p.parse_ifthenelse_t) ->
Lemma
(let (| t, y |) = serialize_ifthenelse_synth_recip x in
p.parse_ifthenelse_synth t y == x)
);
}
let bare_serialize_ifthenelse
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (bare_serializer p.parse_ifthenelse_t)
= fun (d: p.parse_ifthenelse_t) ->
let (| t, y |) = s.serialize_ifthenelse_synth_recip d in
Seq.append (serialize s.serialize_ifthenelse_tag_serializer t) (serialize (s.serialize_ifthenelse_payload_serializer (p.parse_ifthenelse_tag_cond t)) y)
let bare_serialize_ifthenelse_correct
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Lemma
(requires (p.parse_ifthenelse_tag_kind.parser_kind_subkind == Some ParserStrong))
(ensures (serializer_correct (parse_ifthenelse p) (bare_serialize_ifthenelse s)))
= let prf
(x: p.parse_ifthenelse_t)
: Lemma
(let sq = bare_serialize_ifthenelse s x in
parse (parse_ifthenelse p) sq == Some (x, Seq.length sq))
= let sq = bare_serialize_ifthenelse s x in
parse_ifthenelse_eq p sq;
let (| t, y |) = s.serialize_ifthenelse_synth_recip x in
let sqt = serialize s.serialize_ifthenelse_tag_serializer t in
let sqp = serialize (s.serialize_ifthenelse_payload_serializer (p.parse_ifthenelse_tag_cond t)) y in
parse_strong_prefix p.parse_ifthenelse_tag_parser sqt sq;
assert (Seq.slice sq (Seq.length sqt) (Seq.length sq) `Seq.equal` sqp);
s.serialize_ifthenelse_synth_inverse x
in
Classical.forall_intro prf
let serialize_ifthenelse
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p { p.parse_ifthenelse_tag_kind.parser_kind_subkind == Some ParserStrong } )
: Tot (serializer (parse_ifthenelse p))
= bare_serialize_ifthenelse_correct s;
bare_serialize_ifthenelse s
let serialize_ifthenelse_synth_inverse'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(tg: p.parse_ifthenelse_tag_t)
(pl: p.parse_ifthenelse_payload_t (p.parse_ifthenelse_tag_cond tg))
: Lemma | false | false | LowParse.Spec.IfThenElse.fst | {
"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"
} | null | val serialize_ifthenelse_synth_inverse'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(tg: p.parse_ifthenelse_tag_t)
(pl: p.parse_ifthenelse_payload_t (p.parse_ifthenelse_tag_cond tg))
: Lemma (s.serialize_ifthenelse_synth_recip (p.parse_ifthenelse_synth tg pl) == (| tg, pl |)) | [] | LowParse.Spec.IfThenElse.serialize_ifthenelse_synth_inverse' | {
"file_name": "src/lowparse/LowParse.Spec.IfThenElse.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s: LowParse.Spec.IfThenElse.serialize_ifthenelse_param p ->
tg: Mkparse_ifthenelse_param?.parse_ifthenelse_tag_t p ->
pl:
Mkparse_ifthenelse_param?.parse_ifthenelse_payload_t p
(Mkparse_ifthenelse_param?.parse_ifthenelse_tag_cond p tg)
-> FStar.Pervasives.Lemma
(ensures
Mkserialize_ifthenelse_param?.serialize_ifthenelse_synth_recip s
(Mkparse_ifthenelse_param?.parse_ifthenelse_synth p tg pl) ==
(| tg, pl |)) | {
"end_col": 50,
"end_line": 152,
"start_col": 1,
"start_line": 150
} |
FStar.Pervasives.Lemma | val parse_ifthenelse_parse_tag_payload
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(input: bytes)
: Lemma (requires (Some? (parse (parse_ifthenelse p) input)))
(ensures
(let Some (x, _) = parse (parse_ifthenelse p) input in
match parse p.parse_ifthenelse_tag_parser input with
| None -> False
| Some (tg, consumed) ->
let input' = Seq.slice input consumed (Seq.length input) in
match
parse (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond tg)))
input'
with
| None -> False
| Some (pl, consumed') -> s.serialize_ifthenelse_synth_recip x == (| tg, pl |))) | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_ifthenelse_parse_tag_payload
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(input: bytes)
: Lemma
(requires (Some? (parse (parse_ifthenelse p) input)))
(ensures (
let Some (x, _) = parse (parse_ifthenelse p) input in
match parse p.parse_ifthenelse_tag_parser input with
| None -> False
| Some (tg, consumed) ->
let input' = Seq.slice input consumed (Seq.length input) in
begin match parse (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond tg))) input' with
| None -> False
| Some (pl, consumed') ->
s.serialize_ifthenelse_synth_recip x == (| tg, pl |)
end
))
= parse_ifthenelse_eq p input;
let Some (t, consumed) = parse p.parse_ifthenelse_tag_parser input in
let input' = Seq.slice input consumed (Seq.length input) in
let Some (t1, _) = parse (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t))) input' in
serialize_ifthenelse_synth_inverse' s t t1 | val parse_ifthenelse_parse_tag_payload
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(input: bytes)
: Lemma (requires (Some? (parse (parse_ifthenelse p) input)))
(ensures
(let Some (x, _) = parse (parse_ifthenelse p) input in
match parse p.parse_ifthenelse_tag_parser input with
| None -> False
| Some (tg, consumed) ->
let input' = Seq.slice input consumed (Seq.length input) in
match
parse (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond tg)))
input'
with
| None -> False
| Some (pl, consumed') -> s.serialize_ifthenelse_synth_recip x == (| tg, pl |)))
let parse_ifthenelse_parse_tag_payload
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(input: bytes)
: Lemma (requires (Some? (parse (parse_ifthenelse p) input)))
(ensures
(let Some (x, _) = parse (parse_ifthenelse p) input in
match parse p.parse_ifthenelse_tag_parser input with
| None -> False
| Some (tg, consumed) ->
let input' = Seq.slice input consumed (Seq.length input) in
match
parse (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond tg)))
input'
with
| None -> False
| Some (pl, consumed') -> s.serialize_ifthenelse_synth_recip x == (| tg, pl |))) = | false | null | true | parse_ifthenelse_eq p input;
let Some (t, consumed) = parse p.parse_ifthenelse_tag_parser input in
let input' = Seq.slice input consumed (Seq.length input) in
let Some (t1, _) =
parse (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t))) input'
in
serialize_ifthenelse_synth_inverse' s t t1 | {
"checked_file": "LowParse.Spec.IfThenElse.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.IfThenElse.fst"
} | [
"lemma"
] | [
"LowParse.Spec.IfThenElse.parse_ifthenelse_param",
"LowParse.Spec.IfThenElse.serialize_ifthenelse_param",
"LowParse.Bytes.bytes",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_t",
"LowParse.Spec.Base.consumed_length",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_cond",
"LowParse.Spec.IfThenElse.serialize_ifthenelse_synth_inverse'",
"Prims.unit",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.parse",
"FStar.Pervasives.dsnd",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_parser",
"FStar.Seq.Base.seq",
"LowParse.Bytes.byte",
"FStar.Seq.Base.slice",
"FStar.Seq.Base.length",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_parser",
"LowParse.Spec.IfThenElse.parse_ifthenelse_eq",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_t",
"LowParse.Spec.IfThenElse.parse_ifthenelse",
"Prims.squash",
"Prims.l_False",
"Prims.eq2",
"Prims.dtuple2",
"LowParse.Spec.IfThenElse.__proj__Mkserialize_ifthenelse_param__item__serialize_ifthenelse_synth_recip",
"Prims.Mkdtuple2",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.IfThenElse
include LowParse.Spec.Combinators
module Seq = FStar.Seq
[@@(noextract_to "krml")]
inline_for_extraction
noeq
type parse_ifthenelse_param = {
parse_ifthenelse_tag_kind: parser_kind;
parse_ifthenelse_tag_t: Type;
parse_ifthenelse_tag_parser: parser parse_ifthenelse_tag_kind parse_ifthenelse_tag_t;
parse_ifthenelse_tag_cond: (parse_ifthenelse_tag_t -> Tot bool);
parse_ifthenelse_payload_t: (bool -> Tot Type);
parse_ifthenelse_payload_parser: ((b: bool) -> Tot (k: parser_kind & parser k (parse_ifthenelse_payload_t b)));
parse_ifthenelse_t: Type;
parse_ifthenelse_synth: ((t: parse_ifthenelse_tag_t) -> (parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t)) -> GTot parse_ifthenelse_t);
parse_ifthenelse_synth_injective: (
(t1: parse_ifthenelse_tag_t) ->
(x1: parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t1)) ->
(t2: parse_ifthenelse_tag_t) ->
(x2: parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t2)) ->
Lemma
(requires (parse_ifthenelse_synth t1 x1 == parse_ifthenelse_synth t2 x2))
(ensures (t1 == t2 /\ coerce (parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t2)) x1 == x2))
);
}
inline_for_extraction
let parse_ifthenelse_payload_kind
(p: parse_ifthenelse_param)
: Tot parser_kind
= glb (dfst (p.parse_ifthenelse_payload_parser true)) (dfst (p.parse_ifthenelse_payload_parser false))
inline_for_extraction
let parse_ifthenelse_kind
(p: parse_ifthenelse_param)
: Tot parser_kind
= and_then_kind p.parse_ifthenelse_tag_kind (parse_ifthenelse_payload_kind p)
let parse_ifthenelse_synth_injective (p: parse_ifthenelse_param) (t: p.parse_ifthenelse_tag_t) : Lemma (synth_injective (p.parse_ifthenelse_synth t)) [SMTPat (synth_injective (p.parse_ifthenelse_synth t))] =
Classical.forall_intro_2 (fun x1 x2 -> Classical.move_requires (p.parse_ifthenelse_synth_injective t x1 t) x2)
let parse_ifthenelse_payload (p: parse_ifthenelse_param) (t: p.parse_ifthenelse_tag_t) : Tot (parser (parse_ifthenelse_payload_kind p) p.parse_ifthenelse_t) =
weaken (parse_ifthenelse_payload_kind p) (parse_synth (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t))) (p.parse_ifthenelse_synth t))
let parse_ifthenelse_payload_and_then_cases_injective (p: parse_ifthenelse_param) : Lemma
(and_then_cases_injective (parse_ifthenelse_payload p))
[SMTPat (and_then_cases_injective (parse_ifthenelse_payload p))]
= and_then_cases_injective_intro
(parse_ifthenelse_payload p)
(fun t1 t2 b1 b2 ->
parse_synth_eq (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t1))) (p.parse_ifthenelse_synth t1) b1;
parse_synth_eq (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t2))) (p.parse_ifthenelse_synth t2) b2;
let Some (x1, _) = parse (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t1))) b1 in
let Some (x2, _) = parse (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t2))) b2 in
p.parse_ifthenelse_synth_injective t1 x1 t2 x2
)
let parse_ifthenelse (p: parse_ifthenelse_param) : Tot (parser (parse_ifthenelse_kind p) p.parse_ifthenelse_t) =
and_then p.parse_ifthenelse_tag_parser (parse_ifthenelse_payload p)
let parse_ifthenelse_eq
(p: parse_ifthenelse_param)
(input: bytes)
: Lemma
(parse (parse_ifthenelse p) input == (
match parse p.parse_ifthenelse_tag_parser input with
| None -> None
| Some (t, consumed_t) ->
let b = p.parse_ifthenelse_tag_cond t in
let input' = Seq.slice input consumed_t (Seq.length input) in
match parse (dsnd (p.parse_ifthenelse_payload_parser b)) input' with
| None -> None
| Some (x, consumed_x) -> Some (p.parse_ifthenelse_synth t x, consumed_t + consumed_x)
))
= and_then_eq p.parse_ifthenelse_tag_parser (parse_ifthenelse_payload p) input;
match parse p.parse_ifthenelse_tag_parser input with
| None -> ()
| Some (t, consumed_t) ->
let b = p.parse_ifthenelse_tag_cond t in
let input' = Seq.slice input consumed_t (Seq.length input) in
let f : (p.parse_ifthenelse_payload_t (p.parse_ifthenelse_tag_cond t) -> GTot p.parse_ifthenelse_t) = (p.parse_ifthenelse_synth) t in
let f' = coerce (p.parse_ifthenelse_payload_t b -> GTot p.parse_ifthenelse_t) f in
parse_synth_eq
#(dfst (p.parse_ifthenelse_payload_parser b))
#(p.parse_ifthenelse_payload_t b)
#(p.parse_ifthenelse_t)
(dsnd (p.parse_ifthenelse_payload_parser b)) f' input'
noextract
inline_for_extraction
noeq
type serialize_ifthenelse_param (p: parse_ifthenelse_param) = {
serialize_ifthenelse_tag_serializer: serializer p.parse_ifthenelse_tag_parser;
serialize_ifthenelse_payload_serializer: ((b: bool) -> Tot (serializer (dsnd (p.parse_ifthenelse_payload_parser b))));
serialize_ifthenelse_synth_recip: (p.parse_ifthenelse_t -> GTot ( t: p.parse_ifthenelse_tag_t & (p.parse_ifthenelse_payload_t (p.parse_ifthenelse_tag_cond t))));
serialize_ifthenelse_synth_inverse: (
(x: p.parse_ifthenelse_t) ->
Lemma
(let (| t, y |) = serialize_ifthenelse_synth_recip x in
p.parse_ifthenelse_synth t y == x)
);
}
let bare_serialize_ifthenelse
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (bare_serializer p.parse_ifthenelse_t)
= fun (d: p.parse_ifthenelse_t) ->
let (| t, y |) = s.serialize_ifthenelse_synth_recip d in
Seq.append (serialize s.serialize_ifthenelse_tag_serializer t) (serialize (s.serialize_ifthenelse_payload_serializer (p.parse_ifthenelse_tag_cond t)) y)
let bare_serialize_ifthenelse_correct
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Lemma
(requires (p.parse_ifthenelse_tag_kind.parser_kind_subkind == Some ParserStrong))
(ensures (serializer_correct (parse_ifthenelse p) (bare_serialize_ifthenelse s)))
= let prf
(x: p.parse_ifthenelse_t)
: Lemma
(let sq = bare_serialize_ifthenelse s x in
parse (parse_ifthenelse p) sq == Some (x, Seq.length sq))
= let sq = bare_serialize_ifthenelse s x in
parse_ifthenelse_eq p sq;
let (| t, y |) = s.serialize_ifthenelse_synth_recip x in
let sqt = serialize s.serialize_ifthenelse_tag_serializer t in
let sqp = serialize (s.serialize_ifthenelse_payload_serializer (p.parse_ifthenelse_tag_cond t)) y in
parse_strong_prefix p.parse_ifthenelse_tag_parser sqt sq;
assert (Seq.slice sq (Seq.length sqt) (Seq.length sq) `Seq.equal` sqp);
s.serialize_ifthenelse_synth_inverse x
in
Classical.forall_intro prf
let serialize_ifthenelse
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p { p.parse_ifthenelse_tag_kind.parser_kind_subkind == Some ParserStrong } )
: Tot (serializer (parse_ifthenelse p))
= bare_serialize_ifthenelse_correct s;
bare_serialize_ifthenelse s
let serialize_ifthenelse_synth_inverse'
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(tg: p.parse_ifthenelse_tag_t)
(pl: p.parse_ifthenelse_payload_t (p.parse_ifthenelse_tag_cond tg))
: Lemma
(s.serialize_ifthenelse_synth_recip (p.parse_ifthenelse_synth tg pl) == (| tg, pl |))
= let (| tg', pl' |) = s.serialize_ifthenelse_synth_recip (p.parse_ifthenelse_synth tg pl) in
s.serialize_ifthenelse_synth_inverse (p.parse_ifthenelse_synth tg pl);
p.parse_ifthenelse_synth_injective tg pl tg' pl'
let parse_ifthenelse_parse_tag_payload
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(input: bytes)
: Lemma
(requires (Some? (parse (parse_ifthenelse p) input)))
(ensures (
let Some (x, _) = parse (parse_ifthenelse p) input in
match parse p.parse_ifthenelse_tag_parser input with
| None -> False
| Some (tg, consumed) ->
let input' = Seq.slice input consumed (Seq.length input) in
begin match parse (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond tg))) input' with
| None -> False
| Some (pl, consumed') ->
s.serialize_ifthenelse_synth_recip x == (| tg, pl |)
end | false | false | LowParse.Spec.IfThenElse.fst | {
"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"
} | null | val parse_ifthenelse_parse_tag_payload
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
(input: bytes)
: Lemma (requires (Some? (parse (parse_ifthenelse p) input)))
(ensures
(let Some (x, _) = parse (parse_ifthenelse p) input in
match parse p.parse_ifthenelse_tag_parser input with
| None -> False
| Some (tg, consumed) ->
let input' = Seq.slice input consumed (Seq.length input) in
match
parse (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond tg)))
input'
with
| None -> False
| Some (pl, consumed') -> s.serialize_ifthenelse_synth_recip x == (| tg, pl |))) | [] | LowParse.Spec.IfThenElse.parse_ifthenelse_parse_tag_payload | {
"file_name": "src/lowparse/LowParse.Spec.IfThenElse.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | s: LowParse.Spec.IfThenElse.serialize_ifthenelse_param p -> input: LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(requires Some? (LowParse.Spec.Base.parse (LowParse.Spec.IfThenElse.parse_ifthenelse p) input)
)
(ensures
(let _ = LowParse.Spec.Base.parse (LowParse.Spec.IfThenElse.parse_ifthenelse p) input in
(let FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ x _) = _ in
(match
LowParse.Spec.Base.parse (Mkparse_ifthenelse_param?.parse_ifthenelse_tag_parser p)
input
with
| FStar.Pervasives.Native.None #_ -> Prims.l_False
| FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ tg consumed) ->
let input' = FStar.Seq.Base.slice input consumed (FStar.Seq.Base.length input) in
(match
LowParse.Spec.Base.parse (FStar.Pervasives.dsnd (Mkparse_ifthenelse_param?.parse_ifthenelse_payload_parser
p
(Mkparse_ifthenelse_param?.parse_ifthenelse_tag_cond p tg)))
input'
with
| FStar.Pervasives.Native.None #_ -> Prims.l_False
| FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ pl _) ->
Mkserialize_ifthenelse_param?.serialize_ifthenelse_synth_recip s x ==
(| tg, pl |))
<:
Type0)
<:
Type0)
<:
Type0)) | {
"end_col": 44,
"end_line": 176,
"start_col": 2,
"start_line": 172
} |
FStar.Pervasives.Lemma | val bare_serialize_ifthenelse_correct (#p: parse_ifthenelse_param) (s: serialize_ifthenelse_param p)
: Lemma (requires (p.parse_ifthenelse_tag_kind.parser_kind_subkind == Some ParserStrong))
(ensures (serializer_correct (parse_ifthenelse p) (bare_serialize_ifthenelse s))) | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bare_serialize_ifthenelse_correct
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Lemma
(requires (p.parse_ifthenelse_tag_kind.parser_kind_subkind == Some ParserStrong))
(ensures (serializer_correct (parse_ifthenelse p) (bare_serialize_ifthenelse s)))
= let prf
(x: p.parse_ifthenelse_t)
: Lemma
(let sq = bare_serialize_ifthenelse s x in
parse (parse_ifthenelse p) sq == Some (x, Seq.length sq))
= let sq = bare_serialize_ifthenelse s x in
parse_ifthenelse_eq p sq;
let (| t, y |) = s.serialize_ifthenelse_synth_recip x in
let sqt = serialize s.serialize_ifthenelse_tag_serializer t in
let sqp = serialize (s.serialize_ifthenelse_payload_serializer (p.parse_ifthenelse_tag_cond t)) y in
parse_strong_prefix p.parse_ifthenelse_tag_parser sqt sq;
assert (Seq.slice sq (Seq.length sqt) (Seq.length sq) `Seq.equal` sqp);
s.serialize_ifthenelse_synth_inverse x
in
Classical.forall_intro prf | val bare_serialize_ifthenelse_correct (#p: parse_ifthenelse_param) (s: serialize_ifthenelse_param p)
: Lemma (requires (p.parse_ifthenelse_tag_kind.parser_kind_subkind == Some ParserStrong))
(ensures (serializer_correct (parse_ifthenelse p) (bare_serialize_ifthenelse s)))
let bare_serialize_ifthenelse_correct (#p: parse_ifthenelse_param) (s: serialize_ifthenelse_param p)
: Lemma (requires (p.parse_ifthenelse_tag_kind.parser_kind_subkind == Some ParserStrong))
(ensures (serializer_correct (parse_ifthenelse p) (bare_serialize_ifthenelse s))) = | false | null | true | let prf (x: p.parse_ifthenelse_t)
: Lemma
(let sq = bare_serialize_ifthenelse s x in
parse (parse_ifthenelse p) sq == Some (x, Seq.length sq)) =
let sq = bare_serialize_ifthenelse s x in
parse_ifthenelse_eq p sq;
let (| t , y |) = s.serialize_ifthenelse_synth_recip x in
let sqt = serialize s.serialize_ifthenelse_tag_serializer t in
let sqp =
serialize (s.serialize_ifthenelse_payload_serializer (p.parse_ifthenelse_tag_cond t)) y
in
parse_strong_prefix p.parse_ifthenelse_tag_parser sqt sq;
assert ((Seq.slice sq (Seq.length sqt) (Seq.length sq)) `Seq.equal` sqp);
s.serialize_ifthenelse_synth_inverse x
in
Classical.forall_intro prf | {
"checked_file": "LowParse.Spec.IfThenElse.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.IfThenElse.fst"
} | [
"lemma"
] | [
"LowParse.Spec.IfThenElse.parse_ifthenelse_param",
"LowParse.Spec.IfThenElse.serialize_ifthenelse_param",
"FStar.Classical.forall_intro",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_t",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.consumed_length",
"LowParse.Spec.IfThenElse.bare_serialize_ifthenelse",
"LowParse.Spec.Base.parse",
"LowParse.Spec.IfThenElse.parse_ifthenelse",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_cond",
"LowParse.Spec.IfThenElse.__proj__Mkserialize_ifthenelse_param__item__serialize_ifthenelse_synth_inverse",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.slice",
"LowParse.Spec.Base.parse_strong_prefix",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_kind",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_parser",
"LowParse.Bytes.bytes",
"LowParse.Spec.Base.serialize",
"Prims.__proj__Mkdtuple2__item___1",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_parser",
"FStar.Pervasives.dsnd",
"LowParse.Spec.IfThenElse.__proj__Mkserialize_ifthenelse_param__item__serialize_ifthenelse_payload_serializer",
"LowParse.Spec.IfThenElse.__proj__Mkserialize_ifthenelse_param__item__serialize_ifthenelse_tag_serializer",
"Prims.dtuple2",
"LowParse.Spec.IfThenElse.__proj__Mkserialize_ifthenelse_param__item__serialize_ifthenelse_synth_recip",
"LowParse.Spec.IfThenElse.parse_ifthenelse_eq",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Spec.Base.serializer_correct",
"LowParse.Spec.IfThenElse.parse_ifthenelse_kind"
] | [] | module LowParse.Spec.IfThenElse
include LowParse.Spec.Combinators
module Seq = FStar.Seq
[@@(noextract_to "krml")]
inline_for_extraction
noeq
type parse_ifthenelse_param = {
parse_ifthenelse_tag_kind: parser_kind;
parse_ifthenelse_tag_t: Type;
parse_ifthenelse_tag_parser: parser parse_ifthenelse_tag_kind parse_ifthenelse_tag_t;
parse_ifthenelse_tag_cond: (parse_ifthenelse_tag_t -> Tot bool);
parse_ifthenelse_payload_t: (bool -> Tot Type);
parse_ifthenelse_payload_parser: ((b: bool) -> Tot (k: parser_kind & parser k (parse_ifthenelse_payload_t b)));
parse_ifthenelse_t: Type;
parse_ifthenelse_synth: ((t: parse_ifthenelse_tag_t) -> (parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t)) -> GTot parse_ifthenelse_t);
parse_ifthenelse_synth_injective: (
(t1: parse_ifthenelse_tag_t) ->
(x1: parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t1)) ->
(t2: parse_ifthenelse_tag_t) ->
(x2: parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t2)) ->
Lemma
(requires (parse_ifthenelse_synth t1 x1 == parse_ifthenelse_synth t2 x2))
(ensures (t1 == t2 /\ coerce (parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t2)) x1 == x2))
);
}
inline_for_extraction
let parse_ifthenelse_payload_kind
(p: parse_ifthenelse_param)
: Tot parser_kind
= glb (dfst (p.parse_ifthenelse_payload_parser true)) (dfst (p.parse_ifthenelse_payload_parser false))
inline_for_extraction
let parse_ifthenelse_kind
(p: parse_ifthenelse_param)
: Tot parser_kind
= and_then_kind p.parse_ifthenelse_tag_kind (parse_ifthenelse_payload_kind p)
let parse_ifthenelse_synth_injective (p: parse_ifthenelse_param) (t: p.parse_ifthenelse_tag_t) : Lemma (synth_injective (p.parse_ifthenelse_synth t)) [SMTPat (synth_injective (p.parse_ifthenelse_synth t))] =
Classical.forall_intro_2 (fun x1 x2 -> Classical.move_requires (p.parse_ifthenelse_synth_injective t x1 t) x2)
let parse_ifthenelse_payload (p: parse_ifthenelse_param) (t: p.parse_ifthenelse_tag_t) : Tot (parser (parse_ifthenelse_payload_kind p) p.parse_ifthenelse_t) =
weaken (parse_ifthenelse_payload_kind p) (parse_synth (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t))) (p.parse_ifthenelse_synth t))
let parse_ifthenelse_payload_and_then_cases_injective (p: parse_ifthenelse_param) : Lemma
(and_then_cases_injective (parse_ifthenelse_payload p))
[SMTPat (and_then_cases_injective (parse_ifthenelse_payload p))]
= and_then_cases_injective_intro
(parse_ifthenelse_payload p)
(fun t1 t2 b1 b2 ->
parse_synth_eq (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t1))) (p.parse_ifthenelse_synth t1) b1;
parse_synth_eq (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t2))) (p.parse_ifthenelse_synth t2) b2;
let Some (x1, _) = parse (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t1))) b1 in
let Some (x2, _) = parse (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t2))) b2 in
p.parse_ifthenelse_synth_injective t1 x1 t2 x2
)
let parse_ifthenelse (p: parse_ifthenelse_param) : Tot (parser (parse_ifthenelse_kind p) p.parse_ifthenelse_t) =
and_then p.parse_ifthenelse_tag_parser (parse_ifthenelse_payload p)
let parse_ifthenelse_eq
(p: parse_ifthenelse_param)
(input: bytes)
: Lemma
(parse (parse_ifthenelse p) input == (
match parse p.parse_ifthenelse_tag_parser input with
| None -> None
| Some (t, consumed_t) ->
let b = p.parse_ifthenelse_tag_cond t in
let input' = Seq.slice input consumed_t (Seq.length input) in
match parse (dsnd (p.parse_ifthenelse_payload_parser b)) input' with
| None -> None
| Some (x, consumed_x) -> Some (p.parse_ifthenelse_synth t x, consumed_t + consumed_x)
))
= and_then_eq p.parse_ifthenelse_tag_parser (parse_ifthenelse_payload p) input;
match parse p.parse_ifthenelse_tag_parser input with
| None -> ()
| Some (t, consumed_t) ->
let b = p.parse_ifthenelse_tag_cond t in
let input' = Seq.slice input consumed_t (Seq.length input) in
let f : (p.parse_ifthenelse_payload_t (p.parse_ifthenelse_tag_cond t) -> GTot p.parse_ifthenelse_t) = (p.parse_ifthenelse_synth) t in
let f' = coerce (p.parse_ifthenelse_payload_t b -> GTot p.parse_ifthenelse_t) f in
parse_synth_eq
#(dfst (p.parse_ifthenelse_payload_parser b))
#(p.parse_ifthenelse_payload_t b)
#(p.parse_ifthenelse_t)
(dsnd (p.parse_ifthenelse_payload_parser b)) f' input'
noextract
inline_for_extraction
noeq
type serialize_ifthenelse_param (p: parse_ifthenelse_param) = {
serialize_ifthenelse_tag_serializer: serializer p.parse_ifthenelse_tag_parser;
serialize_ifthenelse_payload_serializer: ((b: bool) -> Tot (serializer (dsnd (p.parse_ifthenelse_payload_parser b))));
serialize_ifthenelse_synth_recip: (p.parse_ifthenelse_t -> GTot ( t: p.parse_ifthenelse_tag_t & (p.parse_ifthenelse_payload_t (p.parse_ifthenelse_tag_cond t))));
serialize_ifthenelse_synth_inverse: (
(x: p.parse_ifthenelse_t) ->
Lemma
(let (| t, y |) = serialize_ifthenelse_synth_recip x in
p.parse_ifthenelse_synth t y == x)
);
}
let bare_serialize_ifthenelse
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Tot (bare_serializer p.parse_ifthenelse_t)
= fun (d: p.parse_ifthenelse_t) ->
let (| t, y |) = s.serialize_ifthenelse_synth_recip d in
Seq.append (serialize s.serialize_ifthenelse_tag_serializer t) (serialize (s.serialize_ifthenelse_payload_serializer (p.parse_ifthenelse_tag_cond t)) y)
let bare_serialize_ifthenelse_correct
(#p: parse_ifthenelse_param)
(s: serialize_ifthenelse_param p)
: Lemma
(requires (p.parse_ifthenelse_tag_kind.parser_kind_subkind == Some ParserStrong)) | false | false | LowParse.Spec.IfThenElse.fst | {
"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"
} | null | val bare_serialize_ifthenelse_correct (#p: parse_ifthenelse_param) (s: serialize_ifthenelse_param p)
: Lemma (requires (p.parse_ifthenelse_tag_kind.parser_kind_subkind == Some ParserStrong))
(ensures (serializer_correct (parse_ifthenelse p) (bare_serialize_ifthenelse s))) | [] | LowParse.Spec.IfThenElse.bare_serialize_ifthenelse_correct | {
"file_name": "src/lowparse/LowParse.Spec.IfThenElse.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | s: LowParse.Spec.IfThenElse.serialize_ifthenelse_param p
-> FStar.Pervasives.Lemma
(requires
Mkparser_kind'?.parser_kind_subkind (Mkparse_ifthenelse_param?.parse_ifthenelse_tag_kind p) ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong)
(ensures
LowParse.Spec.Base.serializer_correct (LowParse.Spec.IfThenElse.parse_ifthenelse p)
(LowParse.Spec.IfThenElse.bare_serialize_ifthenelse s)) | {
"end_col": 28,
"end_line": 134,
"start_col": 1,
"start_line": 120
} |
FStar.Pervasives.Lemma | val parse_ifthenelse_eq (p: parse_ifthenelse_param) (input: bytes)
: Lemma
(parse (parse_ifthenelse p) input ==
(match parse p.parse_ifthenelse_tag_parser input with
| None -> None
| Some (t, consumed_t) ->
let b = p.parse_ifthenelse_tag_cond t in
let input' = Seq.slice input consumed_t (Seq.length input) in
match parse (dsnd (p.parse_ifthenelse_payload_parser b)) input' with
| None -> None
| Some (x, consumed_x) -> Some (p.parse_ifthenelse_synth t x, consumed_t + consumed_x))) | [
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_ifthenelse_eq
(p: parse_ifthenelse_param)
(input: bytes)
: Lemma
(parse (parse_ifthenelse p) input == (
match parse p.parse_ifthenelse_tag_parser input with
| None -> None
| Some (t, consumed_t) ->
let b = p.parse_ifthenelse_tag_cond t in
let input' = Seq.slice input consumed_t (Seq.length input) in
match parse (dsnd (p.parse_ifthenelse_payload_parser b)) input' with
| None -> None
| Some (x, consumed_x) -> Some (p.parse_ifthenelse_synth t x, consumed_t + consumed_x)
))
= and_then_eq p.parse_ifthenelse_tag_parser (parse_ifthenelse_payload p) input;
match parse p.parse_ifthenelse_tag_parser input with
| None -> ()
| Some (t, consumed_t) ->
let b = p.parse_ifthenelse_tag_cond t in
let input' = Seq.slice input consumed_t (Seq.length input) in
let f : (p.parse_ifthenelse_payload_t (p.parse_ifthenelse_tag_cond t) -> GTot p.parse_ifthenelse_t) = (p.parse_ifthenelse_synth) t in
let f' = coerce (p.parse_ifthenelse_payload_t b -> GTot p.parse_ifthenelse_t) f in
parse_synth_eq
#(dfst (p.parse_ifthenelse_payload_parser b))
#(p.parse_ifthenelse_payload_t b)
#(p.parse_ifthenelse_t)
(dsnd (p.parse_ifthenelse_payload_parser b)) f' input' | val parse_ifthenelse_eq (p: parse_ifthenelse_param) (input: bytes)
: Lemma
(parse (parse_ifthenelse p) input ==
(match parse p.parse_ifthenelse_tag_parser input with
| None -> None
| Some (t, consumed_t) ->
let b = p.parse_ifthenelse_tag_cond t in
let input' = Seq.slice input consumed_t (Seq.length input) in
match parse (dsnd (p.parse_ifthenelse_payload_parser b)) input' with
| None -> None
| Some (x, consumed_x) -> Some (p.parse_ifthenelse_synth t x, consumed_t + consumed_x)))
let parse_ifthenelse_eq (p: parse_ifthenelse_param) (input: bytes)
: Lemma
(parse (parse_ifthenelse p) input ==
(match parse p.parse_ifthenelse_tag_parser input with
| None -> None
| Some (t, consumed_t) ->
let b = p.parse_ifthenelse_tag_cond t in
let input' = Seq.slice input consumed_t (Seq.length input) in
match parse (dsnd (p.parse_ifthenelse_payload_parser b)) input' with
| None -> None
| Some (x, consumed_x) -> Some (p.parse_ifthenelse_synth t x, consumed_t + consumed_x))) = | false | null | true | and_then_eq p.parse_ifthenelse_tag_parser (parse_ifthenelse_payload p) input;
match parse p.parse_ifthenelse_tag_parser input with
| None -> ()
| Some (t, consumed_t) ->
let b = p.parse_ifthenelse_tag_cond t in
let input' = Seq.slice input consumed_t (Seq.length input) in
let f:(p.parse_ifthenelse_payload_t (p.parse_ifthenelse_tag_cond t) -> GTot p.parse_ifthenelse_t)
=
(p.parse_ifthenelse_synth) t
in
let f' = coerce (p.parse_ifthenelse_payload_t b -> GTot p.parse_ifthenelse_t) f in
parse_synth_eq #(dfst (p.parse_ifthenelse_payload_parser b))
#(p.parse_ifthenelse_payload_t b)
#(p.parse_ifthenelse_t)
(dsnd (p.parse_ifthenelse_payload_parser b))
f'
input' | {
"checked_file": "LowParse.Spec.IfThenElse.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.IfThenElse.fst"
} | [
"lemma"
] | [
"LowParse.Spec.IfThenElse.parse_ifthenelse_param",
"LowParse.Bytes.bytes",
"LowParse.Spec.Base.parse",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_parser",
"LowParse.Spec.Base.consumed_length",
"LowParse.Spec.Combinators.parse_synth_eq",
"FStar.Pervasives.dfst",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_t",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_payload_parser",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_t",
"FStar.Pervasives.dsnd",
"LowParse.Spec.Base.coerce",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_cond",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_synth",
"FStar.Seq.Base.seq",
"LowParse.Bytes.byte",
"FStar.Seq.Base.slice",
"FStar.Seq.Base.length",
"Prims.bool",
"Prims.unit",
"LowParse.Spec.Combinators.and_then_eq",
"LowParse.Spec.IfThenElse.__proj__Mkparse_ifthenelse_param__item__parse_ifthenelse_tag_kind",
"LowParse.Spec.IfThenElse.parse_ifthenelse_payload_kind",
"LowParse.Spec.IfThenElse.parse_ifthenelse_payload",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.IfThenElse.parse_ifthenelse",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.Mktuple2",
"Prims.op_Addition",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.IfThenElse
include LowParse.Spec.Combinators
module Seq = FStar.Seq
[@@(noextract_to "krml")]
inline_for_extraction
noeq
type parse_ifthenelse_param = {
parse_ifthenelse_tag_kind: parser_kind;
parse_ifthenelse_tag_t: Type;
parse_ifthenelse_tag_parser: parser parse_ifthenelse_tag_kind parse_ifthenelse_tag_t;
parse_ifthenelse_tag_cond: (parse_ifthenelse_tag_t -> Tot bool);
parse_ifthenelse_payload_t: (bool -> Tot Type);
parse_ifthenelse_payload_parser: ((b: bool) -> Tot (k: parser_kind & parser k (parse_ifthenelse_payload_t b)));
parse_ifthenelse_t: Type;
parse_ifthenelse_synth: ((t: parse_ifthenelse_tag_t) -> (parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t)) -> GTot parse_ifthenelse_t);
parse_ifthenelse_synth_injective: (
(t1: parse_ifthenelse_tag_t) ->
(x1: parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t1)) ->
(t2: parse_ifthenelse_tag_t) ->
(x2: parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t2)) ->
Lemma
(requires (parse_ifthenelse_synth t1 x1 == parse_ifthenelse_synth t2 x2))
(ensures (t1 == t2 /\ coerce (parse_ifthenelse_payload_t (parse_ifthenelse_tag_cond t2)) x1 == x2))
);
}
inline_for_extraction
let parse_ifthenelse_payload_kind
(p: parse_ifthenelse_param)
: Tot parser_kind
= glb (dfst (p.parse_ifthenelse_payload_parser true)) (dfst (p.parse_ifthenelse_payload_parser false))
inline_for_extraction
let parse_ifthenelse_kind
(p: parse_ifthenelse_param)
: Tot parser_kind
= and_then_kind p.parse_ifthenelse_tag_kind (parse_ifthenelse_payload_kind p)
let parse_ifthenelse_synth_injective (p: parse_ifthenelse_param) (t: p.parse_ifthenelse_tag_t) : Lemma (synth_injective (p.parse_ifthenelse_synth t)) [SMTPat (synth_injective (p.parse_ifthenelse_synth t))] =
Classical.forall_intro_2 (fun x1 x2 -> Classical.move_requires (p.parse_ifthenelse_synth_injective t x1 t) x2)
let parse_ifthenelse_payload (p: parse_ifthenelse_param) (t: p.parse_ifthenelse_tag_t) : Tot (parser (parse_ifthenelse_payload_kind p) p.parse_ifthenelse_t) =
weaken (parse_ifthenelse_payload_kind p) (parse_synth (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t))) (p.parse_ifthenelse_synth t))
let parse_ifthenelse_payload_and_then_cases_injective (p: parse_ifthenelse_param) : Lemma
(and_then_cases_injective (parse_ifthenelse_payload p))
[SMTPat (and_then_cases_injective (parse_ifthenelse_payload p))]
= and_then_cases_injective_intro
(parse_ifthenelse_payload p)
(fun t1 t2 b1 b2 ->
parse_synth_eq (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t1))) (p.parse_ifthenelse_synth t1) b1;
parse_synth_eq (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t2))) (p.parse_ifthenelse_synth t2) b2;
let Some (x1, _) = parse (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t1))) b1 in
let Some (x2, _) = parse (dsnd (p.parse_ifthenelse_payload_parser (p.parse_ifthenelse_tag_cond t2))) b2 in
p.parse_ifthenelse_synth_injective t1 x1 t2 x2
)
let parse_ifthenelse (p: parse_ifthenelse_param) : Tot (parser (parse_ifthenelse_kind p) p.parse_ifthenelse_t) =
and_then p.parse_ifthenelse_tag_parser (parse_ifthenelse_payload p)
let parse_ifthenelse_eq
(p: parse_ifthenelse_param)
(input: bytes)
: Lemma
(parse (parse_ifthenelse p) input == (
match parse p.parse_ifthenelse_tag_parser input with
| None -> None
| Some (t, consumed_t) ->
let b = p.parse_ifthenelse_tag_cond t in
let input' = Seq.slice input consumed_t (Seq.length input) in
match parse (dsnd (p.parse_ifthenelse_payload_parser b)) input' with
| None -> None
| Some (x, consumed_x) -> Some (p.parse_ifthenelse_synth t x, consumed_t + consumed_x) | false | false | LowParse.Spec.IfThenElse.fst | {
"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"
} | null | val parse_ifthenelse_eq (p: parse_ifthenelse_param) (input: bytes)
: Lemma
(parse (parse_ifthenelse p) input ==
(match parse p.parse_ifthenelse_tag_parser input with
| None -> None
| Some (t, consumed_t) ->
let b = p.parse_ifthenelse_tag_cond t in
let input' = Seq.slice input consumed_t (Seq.length input) in
match parse (dsnd (p.parse_ifthenelse_payload_parser b)) input' with
| None -> None
| Some (x, consumed_x) -> Some (p.parse_ifthenelse_synth t x, consumed_t + consumed_x))) | [] | LowParse.Spec.IfThenElse.parse_ifthenelse_eq | {
"file_name": "src/lowparse/LowParse.Spec.IfThenElse.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | p: LowParse.Spec.IfThenElse.parse_ifthenelse_param -> input: LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.Base.parse (LowParse.Spec.IfThenElse.parse_ifthenelse p) input ==
(match
LowParse.Spec.Base.parse (Mkparse_ifthenelse_param?.parse_ifthenelse_tag_parser p) input
with
| FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None
| FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ t consumed_t) ->
let b = Mkparse_ifthenelse_param?.parse_ifthenelse_tag_cond p t in
let input' = FStar.Seq.Base.slice input consumed_t (FStar.Seq.Base.length input) in
(match
LowParse.Spec.Base.parse (FStar.Pervasives.dsnd (Mkparse_ifthenelse_param?.parse_ifthenelse_payload_parser
p
b))
input'
with
| FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None
| FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ x consumed_x) ->
FStar.Pervasives.Native.Some
(Mkparse_ifthenelse_param?.parse_ifthenelse_synth p t x, consumed_t + consumed_x))
<:
FStar.Pervasives.Native.option (Mkparse_ifthenelse_param?.parse_ifthenelse_t p *
LowParse.Spec.Base.consumed_length input))) | {
"end_col": 62,
"end_line": 89,
"start_col": 2,
"start_line": 77
} |
Prims.Tot | [
{
"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
}
] | false | 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 | let is_valid_blake2_config (a: Spec.alg) (m: m_spec) = | false | null | false | match a, m with
| Spec.Blake2S, M32 | Spec.Blake2S, M128 | Spec.Blake2B, M32 | Spec.Blake2B, M256 -> true
| _ -> false | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.tuple2",
"Prims.bool"
] | [] | 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 | false | true | Hacl.Impl.Blake2.Generic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val is_valid_blake2_config : a: Spec.Blake2.alg -> m: Hacl.Impl.Blake2.Core.m_spec -> Prims.bool | [] | Hacl.Impl.Blake2.Generic.is_valid_blake2_config | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Blake2.alg -> m: Hacl.Impl.Blake2.Core.m_spec -> Prims.bool | {
"end_col": 14,
"end_line": 27,
"start_col": 2,
"start_line": 24
} |
|
Prims.Tot | [
{
"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
}
] | false | let valid_m_spec (a : Spec.alg) = m:m_spec{is_valid_blake2_config a m} | let valid_m_spec (a: Spec.alg) = | false | null | false | m: m_spec{is_valid_blake2_config a m} | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Prims.b2t",
"Hacl.Impl.Blake2.Generic.is_valid_blake2_config"
] | [] | 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 | false | true | Hacl.Impl.Blake2.Generic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val valid_m_spec : a: Spec.Blake2.alg -> Type0 | [] | Hacl.Impl.Blake2.Generic.valid_m_spec | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Blake2.alg -> Type0 | {
"end_col": 70,
"end_line": 30,
"start_col": 34,
"start_line": 30
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"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
}
] | false | let blake2_malloc_st (al:Spec.alg) (ms:m_spec) = r:rid -> ST.ST (state_p al ms)
(requires (fun h ->
ST.is_eternal_region r))
(ensures (fun h0 s h1 ->
live h1 s /\
M.(modifies loc_none h0 h1) /\
B.fresh_loc (loc_addr_of_buffer s) h0 h1 /\
(M.loc_includes (M.loc_region_only true r) (loc_addr_of_buffer s)) /\
freeable s)) | let blake2_malloc_st (al: Spec.alg) (ms: m_spec) = | false | null | false | r: rid
-> ST.ST (state_p al ms)
(requires (fun h -> ST.is_eternal_region r))
(ensures
(fun h0 s h1 ->
live h1 s /\ M.(modifies loc_none h0 h1) /\ B.fresh_loc (loc_addr_of_buffer s) h0 h1 /\
(M.loc_includes (M.loc_region_only true r) (loc_addr_of_buffer s)) /\ freeable s)) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"FStar.Monotonic.HyperHeap.rid",
"Hacl.Impl.Blake2.Core.state_p",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.is_eternal_region",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Impl.Blake2.Core.element_t",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_none",
"LowStar.Monotonic.Buffer.fresh_loc",
"Lib.Buffer.loc_addr_of_buffer",
"LowStar.Monotonic.Buffer.loc_includes",
"LowStar.Monotonic.Buffer.loc_region_only",
"Lib.Buffer.freeable"
] | [] | 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 (v kk) (v nn)))
inline_for_extraction noextract
val blake2_init:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms
let blake2_init #al #ms hash kk nn =
let h0 = ST.get() 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 kk_shift_8 = shift_left (size_to_word al kk) (size 8) in
let iv0' = iv0 ^. (Spec.nat_to_word al 0x01010000) ^. kk_shift_8 ^. (size_to_word al nn) 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(modifies (loc hash) h0 h1);
Lib.Sequence.eq_intro (state_v h1 hash) (Spec.blake2_init_hash al (v kk) (v nn))
#push-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let _ : squash (inversion Spec.alg) = allow_inversion Spec.alg
inline_for_extraction noextract
val split_blocks: al:Spec.alg -> len:size_t -> r:(size_t & size_t){
let (x,y) = r in
let (sx,sy) = Spec.split al (v len) in
sx == v x /\
sy == v y}
let split_blocks al len =
let nb = len /. size_block al in
let rem = len %. size_block al in
if rem =. 0ul && nb >. 0ul then
let nb' = nb -! 1ul in
let rem' = size_block al in
(nb',rem')
else (nb,rem)
inline_for_extraction noextract
let blake2_update_multi_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}
-> blocks: lbuffer uint8 len
-> nb : size_t{length blocks >= v nb * v (size_block al) } ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h blocks /\
disjoint hash blocks /\ disjoint wv hash /\ disjoint wv blocks))
(ensures (fun h0 _ h1 ->
modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash == repeati (v nb) (Spec.blake2_update1 al (v prev) h0.[|blocks|])
(state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_multi (#al : Spec.alg) (#ms : m_spec) :
blake2_update_block:blake2_update_block_st al ms
-> blake2_update_multi_st al ms
let blake2_update_multi #al #ms blake2_update_block #len wv hash prev blocks nb =
let h0 = ST.get () in
[@inline_let]
let a_spec = Spec.state al in
[@inline_let]
let refl h = state_v h hash in
[@inline_let]
let footprint = Ghost.hide(loc hash |+| loc wv) in
[@inline_let]
let spec h = Spec.blake2_update1 al (v prev) h.[|blocks|] in
loop_refl h0 nb a_spec refl footprint spec
(fun i ->
Loops.unfold_repeati (v nb) (spec h0) (state_v h0 hash) (v i);
blake2_update1 #al #ms blake2_update_block #len wv hash prev blocks i)
inline_for_extraction noextract
let blake2_update_blocks_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}
-> blocks: lbuffer uint8 len ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h blocks /\ disjoint hash blocks /\ disjoint wv hash /\ disjoint wv blocks))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash ==
Spec.blake2_update_blocks al (v prev) h0.[|blocks|] (state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_blocks (#al : Spec.alg) (#ms : m_spec) :
blake2_update_multi_st al ms
-> blake2_update_last_st al ms
-> blake2_update_blocks_st al ms
let blake2_update_blocks #al #ms blake2_update_multi blake2_update_last #len wv hash prev blocks =
let (nb,rem) = split_blocks al len in
blake2_update_multi wv hash prev blocks nb;
blake2_update_last #len wv hash prev rem blocks
inline_for_extraction noextract
let blake2_finish_st (al:Spec.alg) (ms:m_spec) =
nn: size_t{1 <= v nn /\ v nn <= Spec.max_output al}
-> output: lbuffer uint8 nn
-> hash: state_p al ms ->
Stack unit
(requires (fun h -> live h hash /\ live h output /\ disjoint output hash))
(ensures (fun h0 _ h1 -> modifies (loc output) h0 h1
/\ h1.[|output|] == Spec.blake2_finish al (state_v h0 hash) (v nn)))
inline_for_extraction noextract
val blake2_finish:#al:Spec.alg -> #ms:m_spec -> blake2_finish_st al ms
let blake2_finish #al #ms nn output hash =
let h0 = ST.get () in
[@inline_let]
let double_row = 2ul *. size_row al in
[@inline_let]
let spec _ h1 = h1.[|output|] == Spec.blake2_finish al (state_v h0 hash) (v nn) in
salloc1 h0 double_row (u8 0) (Ghost.hide (loc output)) spec
(fun full ->
let first = sub full 0ul (size_row al) in
let second = sub full (size_row al) (size_row al) in
let row0 = rowi hash 0ul in
let row1 = rowi hash 1ul in
store_row first row0;
store_row second row1;
let h1 = ST.get() in
Lib.Sequence.eq_intro (as_seq h1 full)
(Lib.Sequence.(as_seq h1 (gsub full 0ul (size_row al)) @|
as_seq h1 (gsub full (size_row al) (size_row al))));
let final = sub full (size 0) nn in
copy output final)
inline_for_extraction noextract
let blake2_update_key_st (al:Spec.alg) (ms:m_spec) =
wv:state_p al ms
-> hash: state_p al ms
-> kk: size_t{v kk > 0 /\ v kk <= Spec.max_key al}
-> k: lbuffer uint8 kk
-> ll: size_t ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h k /\
disjoint hash k /\ disjoint wv hash /\ disjoint wv k))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1
/\ state_v h1 hash == Spec.blake2_update_key al (v kk) h0.[|k|] (v ll) (state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_key:
#al:Spec.alg
-> #ms:m_spec
-> blake2_update_block_st al ms
-> blake2_update_key_st al ms
inline_for_extraction noextract
let blake2_update_key #al #ms blake2_update_block wv hash kk k ll =
let lb = size_to_limb al (size_block al) in
assert (v lb = Spec.size_block al);
let h0 = ST.get () in
salloc1 h0 (size_block al) (u8 0) (Ghost.hide (loc hash |+| loc wv))
(fun _ h1 -> live h1 hash /\ state_v h1 hash == Spec.blake2_update_key al (v kk) h0.[|k|] (v ll) (state_v h0 hash))
(fun key_block ->
update_sub key_block 0ul kk k;
let h1 = ST.get() in
if ll =. 0ul then
blake2_update_block wv hash true lb key_block
else
blake2_update_block wv hash false lb key_block)
inline_for_extraction noextract
let blake2_update_st (al:Spec.alg) (ms:m_spec) =
wv:state_p al ms
-> hash: state_p al ms
-> kk: size_t{v kk <= Spec.max_key al}
-> k: lbuffer uint8 kk
-> ll: size_t
-> d: lbuffer uint8 ll ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h k /\ live h d /\
disjoint hash k /\ disjoint wv hash /\ disjoint wv k /\
disjoint hash d /\ disjoint wv d /\ disjoint d k))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1
/\ state_v h1 hash == Spec.blake2_update al (v kk) h0.[|k|] h0.[|d|] (state_v h0 hash)))
inline_for_extraction noextract
val blake2_update:
#al:Spec.alg
-> #ms:m_spec
-> blake2_update_key_st al ms
-> blake2_update_blocks_st al ms
-> blake2_update_st al ms
inline_for_extraction noextract
let blake2_update #al #ms blake2_update_key blake2_update_blocks
wv hash kk k ll d =
let lb = size_to_limb al (size_block al) in
assert (v lb = Spec.size_block al);
if kk >. 0ul then (
blake2_update_key wv hash kk k ll;
if ll =. 0ul then ()
else blake2_update_blocks wv hash lb d)
else blake2_update_blocks wv hash (size_to_limb al 0ul) d
inline_for_extraction noextract
let blake2_st (al:Spec.alg) (ms:m_spec) =
nn:size_t{1 <= v nn /\ v nn <= Spec.max_output al}
-> output: lbuffer uint8 nn
-> ll: size_t
-> d: lbuffer uint8 ll
-> kk: size_t{v kk <= Spec.max_key al}
-> k: lbuffer uint8 kk ->
Stack unit
(requires (fun h -> live h output /\ live h d /\ live h k
/\ disjoint output d /\ disjoint output k /\ disjoint d k))
(ensures (fun h0 _ h1 -> modifies1 output h0 h1
/\ h1.[|output|] == Spec.blake2 al h0.[|d|] (v kk) h0.[|k|] (v nn)))
inline_for_extraction noextract
val blake2:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms
-> blake2_update_st al ms
-> blake2_finish_st al ms
-> blake2_st al ms
#push-options "--z3rlimit 100"
let blake2 #al #ms blake2_init blake2_update blake2_finish nn output ll d kk k =
[@inline_let]
let stlen = le_sigh al ms in
[@inline_let]
let stzero = zero_element al ms in
let h0 = ST.get() in
[@inline_let]
let spec _ h1 = h1.[|output|] == Spec.blake2 al h0.[|d|] (v kk) h0.[|k|] (v nn) in
salloc1 h0 stlen stzero (Ghost.hide (loc output)) spec
(fun h ->
assert (max_size_t <= Spec.max_limb al);
let h1 = ST.get() in
salloc1 h1 stlen stzero (Ghost.hide (loc output |+| loc h)) spec
(fun wv ->
blake2_init h kk nn;
blake2_update wv h kk k ll d;
blake2_finish nn output h))
#pop-options
module B = LowStar.Buffer
module M = LowStar.Modifies
// A little wrapper needed by EverCrypt.Hash | false | true | Hacl.Impl.Blake2.Generic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val blake2_malloc_st : al: Spec.Blake2.alg -> ms: Hacl.Impl.Blake2.Core.m_spec -> Type0 | [] | Hacl.Impl.Blake2.Generic.blake2_malloc_st | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | al: Spec.Blake2.alg -> ms: Hacl.Impl.Blake2.Core.m_spec -> Type0 | {
"end_col": 16,
"end_line": 825,
"start_col": 49,
"start_line": 817
} |
|
Prims.Tot | [
{
"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
}
] | false | 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))) | let blake2_update_block_st (al: Spec.alg) (ms: m_spec) = | false | null | false |
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))) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Hacl.Impl.Blake2.Core.state_p",
"Prims.bool",
"Spec.Blake2.limb_t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.v",
"Spec.Blake2.limb_inttype",
"Lib.IntTypes.SEC",
"Spec.Blake2.max_limb",
"Hacl.Impl.Blake2.Core.block_p",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Impl.Blake2.Core.element_t",
"Lib.IntTypes.uint8",
"Lib.Buffer.disjoint",
"Lib.Buffer.modifies",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.Buffer.loc",
"Prims.eq2",
"Spec.Blake2.state",
"Hacl.Impl.Blake2.Core.state_v",
"Spec.Blake2.blake2_update_block",
"Lib.Buffer.op_Brack_Lens_Access",
"Hacl.Impl.Blake2.Core.size_block"
] | [] | 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 | false | true | Hacl.Impl.Blake2.Generic.fst | {
"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"
} | null | val blake2_update_block_st : al: Spec.Blake2.alg -> ms: Hacl.Impl.Blake2.Core.m_spec -> Type0 | [] | Hacl.Impl.Blake2.Generic.blake2_update_block_st | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | al: Spec.Blake2.alg -> ms: Hacl.Impl.Blake2.Core.m_spec -> Type0 | {
"end_col": 119,
"end_line": 472,
"start_col": 4,
"start_line": 464
} |
|
Prims.Tot | [
{
"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
}
] | false | 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)) | let compress_t (al: Spec.alg) (ms: m_spec) = | false | null | false | 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)) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Hacl.Impl.Blake2.Core.state_p",
"Hacl.Impl.Blake2.Core.block_p",
"Spec.Blake2.limb_t",
"Prims.bool",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Impl.Blake2.Core.element_t",
"Lib.IntTypes.uint8",
"Lib.Buffer.disjoint",
"Lib.Buffer.modifies",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.Buffer.loc",
"Prims.eq2",
"Spec.Blake2.state",
"Hacl.Impl.Blake2.Core.state_v",
"Spec.Blake2.blake2_compress",
"Lib.Buffer.op_Brack_Lens_Access",
"Hacl.Impl.Blake2.Core.size_block"
] | [] | 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 | false | true | Hacl.Impl.Blake2.Generic.fst | {
"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"
} | null | val compress_t : al: Spec.Blake2.alg -> ms: Hacl.Impl.Blake2.Core.m_spec -> Type0 | [] | Hacl.Impl.Blake2.Generic.compress_t | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | al: Spec.Blake2.alg -> ms: Hacl.Impl.Blake2.Core.m_spec -> Type0 | {
"end_col": 105,
"end_line": 447,
"start_col": 4,
"start_line": 439
} |
|
Prims.Tot | [
{
"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
}
] | false | let blake2_update_key_st (al:Spec.alg) (ms:m_spec) =
wv:state_p al ms
-> hash: state_p al ms
-> kk: size_t{v kk > 0 /\ v kk <= Spec.max_key al}
-> k: lbuffer uint8 kk
-> ll: size_t ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h k /\
disjoint hash k /\ disjoint wv hash /\ disjoint wv k))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1
/\ state_v h1 hash == Spec.blake2_update_key al (v kk) h0.[|k|] (v ll) (state_v h0 hash))) | let blake2_update_key_st (al: Spec.alg) (ms: m_spec) = | false | null | false |
wv: state_p al ms ->
hash: state_p al ms ->
kk: size_t{v kk > 0 /\ v kk <= Spec.max_key al} ->
k: lbuffer uint8 kk ->
ll: size_t
-> Stack unit
(requires
(fun h ->
live h wv /\ live h hash /\ live h k /\ disjoint hash k /\ disjoint wv hash /\
disjoint wv k))
(ensures
(fun h0 _ h1 ->
modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash == Spec.blake2_update_key al (v kk) h0.[| k |] (v ll) (state_v h0 hash))
) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Hacl.Impl.Blake2.Core.state_p",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"Spec.Blake2.max_key",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Impl.Blake2.Core.element_t",
"Lib.Buffer.disjoint",
"Lib.Buffer.modifies",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.Buffer.loc",
"Prims.eq2",
"Spec.Blake2.state",
"Hacl.Impl.Blake2.Core.state_v",
"Spec.Blake2.blake2_update_key",
"Lib.Buffer.op_Brack_Lens_Access"
] | [] | 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 (v kk) (v nn)))
inline_for_extraction noextract
val blake2_init:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms
let blake2_init #al #ms hash kk nn =
let h0 = ST.get() 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 kk_shift_8 = shift_left (size_to_word al kk) (size 8) in
let iv0' = iv0 ^. (Spec.nat_to_word al 0x01010000) ^. kk_shift_8 ^. (size_to_word al nn) 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(modifies (loc hash) h0 h1);
Lib.Sequence.eq_intro (state_v h1 hash) (Spec.blake2_init_hash al (v kk) (v nn))
#push-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let _ : squash (inversion Spec.alg) = allow_inversion Spec.alg
inline_for_extraction noextract
val split_blocks: al:Spec.alg -> len:size_t -> r:(size_t & size_t){
let (x,y) = r in
let (sx,sy) = Spec.split al (v len) in
sx == v x /\
sy == v y}
let split_blocks al len =
let nb = len /. size_block al in
let rem = len %. size_block al in
if rem =. 0ul && nb >. 0ul then
let nb' = nb -! 1ul in
let rem' = size_block al in
(nb',rem')
else (nb,rem)
inline_for_extraction noextract
let blake2_update_multi_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}
-> blocks: lbuffer uint8 len
-> nb : size_t{length blocks >= v nb * v (size_block al) } ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h blocks /\
disjoint hash blocks /\ disjoint wv hash /\ disjoint wv blocks))
(ensures (fun h0 _ h1 ->
modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash == repeati (v nb) (Spec.blake2_update1 al (v prev) h0.[|blocks|])
(state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_multi (#al : Spec.alg) (#ms : m_spec) :
blake2_update_block:blake2_update_block_st al ms
-> blake2_update_multi_st al ms
let blake2_update_multi #al #ms blake2_update_block #len wv hash prev blocks nb =
let h0 = ST.get () in
[@inline_let]
let a_spec = Spec.state al in
[@inline_let]
let refl h = state_v h hash in
[@inline_let]
let footprint = Ghost.hide(loc hash |+| loc wv) in
[@inline_let]
let spec h = Spec.blake2_update1 al (v prev) h.[|blocks|] in
loop_refl h0 nb a_spec refl footprint spec
(fun i ->
Loops.unfold_repeati (v nb) (spec h0) (state_v h0 hash) (v i);
blake2_update1 #al #ms blake2_update_block #len wv hash prev blocks i)
inline_for_extraction noextract
let blake2_update_blocks_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}
-> blocks: lbuffer uint8 len ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h blocks /\ disjoint hash blocks /\ disjoint wv hash /\ disjoint wv blocks))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash ==
Spec.blake2_update_blocks al (v prev) h0.[|blocks|] (state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_blocks (#al : Spec.alg) (#ms : m_spec) :
blake2_update_multi_st al ms
-> blake2_update_last_st al ms
-> blake2_update_blocks_st al ms
let blake2_update_blocks #al #ms blake2_update_multi blake2_update_last #len wv hash prev blocks =
let (nb,rem) = split_blocks al len in
blake2_update_multi wv hash prev blocks nb;
blake2_update_last #len wv hash prev rem blocks
inline_for_extraction noextract
let blake2_finish_st (al:Spec.alg) (ms:m_spec) =
nn: size_t{1 <= v nn /\ v nn <= Spec.max_output al}
-> output: lbuffer uint8 nn
-> hash: state_p al ms ->
Stack unit
(requires (fun h -> live h hash /\ live h output /\ disjoint output hash))
(ensures (fun h0 _ h1 -> modifies (loc output) h0 h1
/\ h1.[|output|] == Spec.blake2_finish al (state_v h0 hash) (v nn)))
inline_for_extraction noextract
val blake2_finish:#al:Spec.alg -> #ms:m_spec -> blake2_finish_st al ms
let blake2_finish #al #ms nn output hash =
let h0 = ST.get () in
[@inline_let]
let double_row = 2ul *. size_row al in
[@inline_let]
let spec _ h1 = h1.[|output|] == Spec.blake2_finish al (state_v h0 hash) (v nn) in
salloc1 h0 double_row (u8 0) (Ghost.hide (loc output)) spec
(fun full ->
let first = sub full 0ul (size_row al) in
let second = sub full (size_row al) (size_row al) in
let row0 = rowi hash 0ul in
let row1 = rowi hash 1ul in
store_row first row0;
store_row second row1;
let h1 = ST.get() in
Lib.Sequence.eq_intro (as_seq h1 full)
(Lib.Sequence.(as_seq h1 (gsub full 0ul (size_row al)) @|
as_seq h1 (gsub full (size_row al) (size_row al))));
let final = sub full (size 0) nn in
copy output final)
inline_for_extraction noextract | false | true | Hacl.Impl.Blake2.Generic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val blake2_update_key_st : al: Spec.Blake2.alg -> ms: Hacl.Impl.Blake2.Core.m_spec -> Type0 | [] | Hacl.Impl.Blake2.Generic.blake2_update_key_st | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | al: Spec.Blake2.alg -> ms: Hacl.Impl.Blake2.Core.m_spec -> Type0 | {
"end_col": 115,
"end_line": 709,
"start_col": 4,
"start_line": 700
} |
|
Prims.Tot | val impl_state_len (al: Spec.alg) (ms: m_spec) : size_t | [
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"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
}
] | false | let impl_state_len (al:Spec.alg) (ms:m_spec) : size_t = //{size_v s == impl_state_length i} =
(**) mul_mod_lemma 4ul (row_len al ms);
match al, ms with
| Spec.Blake2S, M32
| Spec.Blake2B, M32 | Spec.Blake2B, M128 -> 16ul
| Spec.Blake2S, M128 | Spec.Blake2S, M256
| Spec.Blake2B, M256 -> 4ul | val impl_state_len (al: Spec.alg) (ms: m_spec) : size_t
let impl_state_len (al: Spec.alg) (ms: m_spec) : size_t = | false | null | false | mul_mod_lemma 4ul (row_len al ms);
match al, ms with
| Spec.Blake2S, M32 | Spec.Blake2B, M32 | Spec.Blake2B, M128 -> 16ul
| Spec.Blake2S, M128 | Spec.Blake2S, M256 | Spec.Blake2B, M256 -> 4ul | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"FStar.Pervasives.Native.Mktuple2",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.size_t",
"Prims.unit",
"Lib.IntTypes.mul_mod_lemma",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Blake2.Core.row_len"
] | [] | 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 (v kk) (v nn)))
inline_for_extraction noextract
val blake2_init:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms
let blake2_init #al #ms hash kk nn =
let h0 = ST.get() 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 kk_shift_8 = shift_left (size_to_word al kk) (size 8) in
let iv0' = iv0 ^. (Spec.nat_to_word al 0x01010000) ^. kk_shift_8 ^. (size_to_word al nn) 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(modifies (loc hash) h0 h1);
Lib.Sequence.eq_intro (state_v h1 hash) (Spec.blake2_init_hash al (v kk) (v nn))
#push-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let _ : squash (inversion Spec.alg) = allow_inversion Spec.alg
inline_for_extraction noextract
val split_blocks: al:Spec.alg -> len:size_t -> r:(size_t & size_t){
let (x,y) = r in
let (sx,sy) = Spec.split al (v len) in
sx == v x /\
sy == v y}
let split_blocks al len =
let nb = len /. size_block al in
let rem = len %. size_block al in
if rem =. 0ul && nb >. 0ul then
let nb' = nb -! 1ul in
let rem' = size_block al in
(nb',rem')
else (nb,rem)
inline_for_extraction noextract
let blake2_update_multi_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}
-> blocks: lbuffer uint8 len
-> nb : size_t{length blocks >= v nb * v (size_block al) } ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h blocks /\
disjoint hash blocks /\ disjoint wv hash /\ disjoint wv blocks))
(ensures (fun h0 _ h1 ->
modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash == repeati (v nb) (Spec.blake2_update1 al (v prev) h0.[|blocks|])
(state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_multi (#al : Spec.alg) (#ms : m_spec) :
blake2_update_block:blake2_update_block_st al ms
-> blake2_update_multi_st al ms
let blake2_update_multi #al #ms blake2_update_block #len wv hash prev blocks nb =
let h0 = ST.get () in
[@inline_let]
let a_spec = Spec.state al in
[@inline_let]
let refl h = state_v h hash in
[@inline_let]
let footprint = Ghost.hide(loc hash |+| loc wv) in
[@inline_let]
let spec h = Spec.blake2_update1 al (v prev) h.[|blocks|] in
loop_refl h0 nb a_spec refl footprint spec
(fun i ->
Loops.unfold_repeati (v nb) (spec h0) (state_v h0 hash) (v i);
blake2_update1 #al #ms blake2_update_block #len wv hash prev blocks i)
inline_for_extraction noextract
let blake2_update_blocks_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}
-> blocks: lbuffer uint8 len ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h blocks /\ disjoint hash blocks /\ disjoint wv hash /\ disjoint wv blocks))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash ==
Spec.blake2_update_blocks al (v prev) h0.[|blocks|] (state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_blocks (#al : Spec.alg) (#ms : m_spec) :
blake2_update_multi_st al ms
-> blake2_update_last_st al ms
-> blake2_update_blocks_st al ms
let blake2_update_blocks #al #ms blake2_update_multi blake2_update_last #len wv hash prev blocks =
let (nb,rem) = split_blocks al len in
blake2_update_multi wv hash prev blocks nb;
blake2_update_last #len wv hash prev rem blocks
inline_for_extraction noextract
let blake2_finish_st (al:Spec.alg) (ms:m_spec) =
nn: size_t{1 <= v nn /\ v nn <= Spec.max_output al}
-> output: lbuffer uint8 nn
-> hash: state_p al ms ->
Stack unit
(requires (fun h -> live h hash /\ live h output /\ disjoint output hash))
(ensures (fun h0 _ h1 -> modifies (loc output) h0 h1
/\ h1.[|output|] == Spec.blake2_finish al (state_v h0 hash) (v nn)))
inline_for_extraction noextract
val blake2_finish:#al:Spec.alg -> #ms:m_spec -> blake2_finish_st al ms
let blake2_finish #al #ms nn output hash =
let h0 = ST.get () in
[@inline_let]
let double_row = 2ul *. size_row al in
[@inline_let]
let spec _ h1 = h1.[|output|] == Spec.blake2_finish al (state_v h0 hash) (v nn) in
salloc1 h0 double_row (u8 0) (Ghost.hide (loc output)) spec
(fun full ->
let first = sub full 0ul (size_row al) in
let second = sub full (size_row al) (size_row al) in
let row0 = rowi hash 0ul in
let row1 = rowi hash 1ul in
store_row first row0;
store_row second row1;
let h1 = ST.get() in
Lib.Sequence.eq_intro (as_seq h1 full)
(Lib.Sequence.(as_seq h1 (gsub full 0ul (size_row al)) @|
as_seq h1 (gsub full (size_row al) (size_row al))));
let final = sub full (size 0) nn in
copy output final)
inline_for_extraction noextract
let blake2_update_key_st (al:Spec.alg) (ms:m_spec) =
wv:state_p al ms
-> hash: state_p al ms
-> kk: size_t{v kk > 0 /\ v kk <= Spec.max_key al}
-> k: lbuffer uint8 kk
-> ll: size_t ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h k /\
disjoint hash k /\ disjoint wv hash /\ disjoint wv k))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1
/\ state_v h1 hash == Spec.blake2_update_key al (v kk) h0.[|k|] (v ll) (state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_key:
#al:Spec.alg
-> #ms:m_spec
-> blake2_update_block_st al ms
-> blake2_update_key_st al ms
inline_for_extraction noextract
let blake2_update_key #al #ms blake2_update_block wv hash kk k ll =
let lb = size_to_limb al (size_block al) in
assert (v lb = Spec.size_block al);
let h0 = ST.get () in
salloc1 h0 (size_block al) (u8 0) (Ghost.hide (loc hash |+| loc wv))
(fun _ h1 -> live h1 hash /\ state_v h1 hash == Spec.blake2_update_key al (v kk) h0.[|k|] (v ll) (state_v h0 hash))
(fun key_block ->
update_sub key_block 0ul kk k;
let h1 = ST.get() in
if ll =. 0ul then
blake2_update_block wv hash true lb key_block
else
blake2_update_block wv hash false lb key_block)
inline_for_extraction noextract
let blake2_update_st (al:Spec.alg) (ms:m_spec) =
wv:state_p al ms
-> hash: state_p al ms
-> kk: size_t{v kk <= Spec.max_key al}
-> k: lbuffer uint8 kk
-> ll: size_t
-> d: lbuffer uint8 ll ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h k /\ live h d /\
disjoint hash k /\ disjoint wv hash /\ disjoint wv k /\
disjoint hash d /\ disjoint wv d /\ disjoint d k))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1
/\ state_v h1 hash == Spec.blake2_update al (v kk) h0.[|k|] h0.[|d|] (state_v h0 hash)))
inline_for_extraction noextract
val blake2_update:
#al:Spec.alg
-> #ms:m_spec
-> blake2_update_key_st al ms
-> blake2_update_blocks_st al ms
-> blake2_update_st al ms
inline_for_extraction noextract
let blake2_update #al #ms blake2_update_key blake2_update_blocks
wv hash kk k ll d =
let lb = size_to_limb al (size_block al) in
assert (v lb = Spec.size_block al);
if kk >. 0ul then (
blake2_update_key wv hash kk k ll;
if ll =. 0ul then ()
else blake2_update_blocks wv hash lb d)
else blake2_update_blocks wv hash (size_to_limb al 0ul) d
inline_for_extraction noextract
let blake2_st (al:Spec.alg) (ms:m_spec) =
nn:size_t{1 <= v nn /\ v nn <= Spec.max_output al}
-> output: lbuffer uint8 nn
-> ll: size_t
-> d: lbuffer uint8 ll
-> kk: size_t{v kk <= Spec.max_key al}
-> k: lbuffer uint8 kk ->
Stack unit
(requires (fun h -> live h output /\ live h d /\ live h k
/\ disjoint output d /\ disjoint output k /\ disjoint d k))
(ensures (fun h0 _ h1 -> modifies1 output h0 h1
/\ h1.[|output|] == Spec.blake2 al h0.[|d|] (v kk) h0.[|k|] (v nn)))
inline_for_extraction noextract
val blake2:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms
-> blake2_update_st al ms
-> blake2_finish_st al ms
-> blake2_st al ms
#push-options "--z3rlimit 100"
let blake2 #al #ms blake2_init blake2_update blake2_finish nn output ll d kk k =
[@inline_let]
let stlen = le_sigh al ms in
[@inline_let]
let stzero = zero_element al ms in
let h0 = ST.get() in
[@inline_let]
let spec _ h1 = h1.[|output|] == Spec.blake2 al h0.[|d|] (v kk) h0.[|k|] (v nn) in
salloc1 h0 stlen stzero (Ghost.hide (loc output)) spec
(fun h ->
assert (max_size_t <= Spec.max_limb al);
let h1 = ST.get() in
salloc1 h1 stlen stzero (Ghost.hide (loc output |+| loc h)) spec
(fun wv ->
blake2_init h kk nn;
blake2_update wv h kk k ll d;
blake2_finish nn output h))
#pop-options
module B = LowStar.Buffer
module M = LowStar.Modifies
// A little wrapper needed by EverCrypt.Hash
inline_for_extraction noextract
let blake2_malloc_st (al:Spec.alg) (ms:m_spec) = r:rid -> ST.ST (state_p al ms)
(requires (fun h ->
ST.is_eternal_region r))
(ensures (fun h0 s h1 ->
live h1 s /\
M.(modifies loc_none h0 h1) /\
B.fresh_loc (loc_addr_of_buffer s) h0 h1 /\
(M.loc_includes (M.loc_region_only true r) (loc_addr_of_buffer s)) /\
freeable s))
inline_for_extraction noextract
val blake2_malloc:
al:Spec.alg
-> ms:m_spec
-> blake2_malloc_st al ms
#push-options "--ifuel 1"
inline_for_extraction noextract | false | true | Hacl.Impl.Blake2.Generic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val impl_state_len (al: Spec.alg) (ms: m_spec) : size_t | [] | Hacl.Impl.Blake2.Generic.impl_state_len | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | al: Spec.Blake2.alg -> ms: Hacl.Impl.Blake2.Core.m_spec -> Lib.IntTypes.size_t | {
"end_col": 31,
"end_line": 841,
"start_col": 9,
"start_line": 836
} |
Prims.Tot | [
{
"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
}
] | false | let blake2_update_blocks_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}
-> blocks: lbuffer uint8 len ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h blocks /\ disjoint hash blocks /\ disjoint wv hash /\ disjoint wv blocks))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash ==
Spec.blake2_update_blocks al (v prev) h0.[|blocks|] (state_v h0 hash))) | let blake2_update_blocks_st (al: Spec.alg) (ms: m_spec) = | false | null | false |
#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} ->
blocks: lbuffer uint8 len
-> Stack unit
(requires
(fun h ->
live h wv /\ live h hash /\ live h blocks /\ disjoint hash blocks /\ disjoint wv hash /\
disjoint wv blocks))
(ensures
(fun h0 _ h1 ->
modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash ==
Spec.blake2_update_blocks al (v prev) h0.[| blocks |] (state_v h0 hash))) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Lib.IntTypes.size_t",
"Hacl.Impl.Blake2.Core.state_p",
"Spec.Blake2.limb_t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.v",
"Spec.Blake2.limb_inttype",
"Lib.IntTypes.SEC",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Spec.Blake2.max_limb",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Impl.Blake2.Core.element_t",
"Lib.Buffer.disjoint",
"Lib.Buffer.modifies",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.Buffer.loc",
"Prims.eq2",
"Spec.Blake2.state",
"Hacl.Impl.Blake2.Core.state_v",
"Spec.Blake2.blake2_update_blocks",
"Lib.Buffer.op_Brack_Lens_Access"
] | [] | 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 (v kk) (v nn)))
inline_for_extraction noextract
val blake2_init:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms
let blake2_init #al #ms hash kk nn =
let h0 = ST.get() 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 kk_shift_8 = shift_left (size_to_word al kk) (size 8) in
let iv0' = iv0 ^. (Spec.nat_to_word al 0x01010000) ^. kk_shift_8 ^. (size_to_word al nn) 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(modifies (loc hash) h0 h1);
Lib.Sequence.eq_intro (state_v h1 hash) (Spec.blake2_init_hash al (v kk) (v nn))
#push-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let _ : squash (inversion Spec.alg) = allow_inversion Spec.alg
inline_for_extraction noextract
val split_blocks: al:Spec.alg -> len:size_t -> r:(size_t & size_t){
let (x,y) = r in
let (sx,sy) = Spec.split al (v len) in
sx == v x /\
sy == v y}
let split_blocks al len =
let nb = len /. size_block al in
let rem = len %. size_block al in
if rem =. 0ul && nb >. 0ul then
let nb' = nb -! 1ul in
let rem' = size_block al in
(nb',rem')
else (nb,rem)
inline_for_extraction noextract
let blake2_update_multi_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}
-> blocks: lbuffer uint8 len
-> nb : size_t{length blocks >= v nb * v (size_block al) } ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h blocks /\
disjoint hash blocks /\ disjoint wv hash /\ disjoint wv blocks))
(ensures (fun h0 _ h1 ->
modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash == repeati (v nb) (Spec.blake2_update1 al (v prev) h0.[|blocks|])
(state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_multi (#al : Spec.alg) (#ms : m_spec) :
blake2_update_block:blake2_update_block_st al ms
-> blake2_update_multi_st al ms
let blake2_update_multi #al #ms blake2_update_block #len wv hash prev blocks nb =
let h0 = ST.get () in
[@inline_let]
let a_spec = Spec.state al in
[@inline_let]
let refl h = state_v h hash in
[@inline_let]
let footprint = Ghost.hide(loc hash |+| loc wv) in
[@inline_let]
let spec h = Spec.blake2_update1 al (v prev) h.[|blocks|] in
loop_refl h0 nb a_spec refl footprint spec
(fun i ->
Loops.unfold_repeati (v nb) (spec h0) (state_v h0 hash) (v i);
blake2_update1 #al #ms blake2_update_block #len wv hash prev blocks i)
inline_for_extraction noextract | false | true | Hacl.Impl.Blake2.Generic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val blake2_update_blocks_st : al: Spec.Blake2.alg -> ms: Hacl.Impl.Blake2.Core.m_spec -> Type0 | [] | Hacl.Impl.Blake2.Generic.blake2_update_blocks_st | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | al: Spec.Blake2.alg -> ms: Hacl.Impl.Blake2.Core.m_spec -> Type0 | {
"end_col": 77,
"end_line": 650,
"start_col": 5,
"start_line": 641
} |
|
Prims.Tot | [
{
"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
}
] | false | 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))) | let blake2_update_last_st (al: Spec.alg) (ms: m_spec) = | false | null | false |
#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))) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Lib.IntTypes.size_t",
"Hacl.Impl.Blake2.Core.state_p",
"Spec.Blake2.limb_t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.v",
"Spec.Blake2.limb_inttype",
"Lib.IntTypes.SEC",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Spec.Blake2.max_limb",
"Prims.l_and",
"Spec.Blake2.size_block",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Impl.Blake2.Core.element_t",
"Lib.Buffer.disjoint",
"Lib.Buffer.modifies",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.Buffer.loc",
"Prims.eq2",
"Spec.Blake2.state",
"Hacl.Impl.Blake2.Core.state_v",
"Spec.Blake2.blake2_update_last",
"Lib.Buffer.op_Brack_Lens_Access"
] | [] | 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 | false | true | Hacl.Impl.Blake2.Generic.fst | {
"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"
} | null | val blake2_update_last_st : al: Spec.Blake2.alg -> ms: Hacl.Impl.Blake2.Core.m_spec -> Type0 | [] | Hacl.Impl.Blake2.Generic.blake2_update_last_st | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | al: Spec.Blake2.alg -> ms: Hacl.Impl.Blake2.Core.m_spec -> Type0 | {
"end_col": 119,
"end_line": 515,
"start_col": 3,
"start_line": 506
} |
|
Prims.Tot | val rounds_t (a: Spec.alg) : size_t | [
{
"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
}
] | false | let rounds_t (a:Spec.alg): size_t = size (Spec.rounds a) | val rounds_t (a: Spec.alg) : size_t
let rounds_t (a: Spec.alg) : size_t = | false | null | false | size (Spec.rounds a) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.alg",
"Lib.IntTypes.size",
"Spec.Blake2.rounds",
"Lib.IntTypes.size_t"
] | [] | 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) | false | true | Hacl.Impl.Blake2.Generic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val rounds_t (a: Spec.alg) : size_t | [] | Hacl.Impl.Blake2.Generic.rounds_t | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Blake2.alg -> Lib.IntTypes.size_t | {
"end_col": 56,
"end_line": 79,
"start_col": 36,
"start_line": 79
} |
Prims.Tot | [
{
"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
}
] | false | let blake2_finish_st (al:Spec.alg) (ms:m_spec) =
nn: size_t{1 <= v nn /\ v nn <= Spec.max_output al}
-> output: lbuffer uint8 nn
-> hash: state_p al ms ->
Stack unit
(requires (fun h -> live h hash /\ live h output /\ disjoint output hash))
(ensures (fun h0 _ h1 -> modifies (loc output) h0 h1
/\ h1.[|output|] == Spec.blake2_finish al (state_v h0 hash) (v nn))) | let blake2_finish_st (al: Spec.alg) (ms: m_spec) = | false | null | false |
nn: size_t{1 <= v nn /\ v nn <= Spec.max_output al} ->
output: lbuffer uint8 nn ->
hash: state_p al ms
-> Stack unit
(requires (fun h -> live h hash /\ live h output /\ disjoint output hash))
(ensures
(fun h0 _ h1 ->
modifies (loc output) h0 h1 /\
h1.[| output |] == Spec.blake2_finish al (state_v h0 hash) (v nn))) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Spec.Blake2.max_output",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.Impl.Blake2.Core.state_p",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Impl.Blake2.Core.element_t",
"Lib.Buffer.disjoint",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Prims.eq2",
"Lib.Sequence.lseq",
"Lib.Buffer.op_Brack_Lens_Access",
"Spec.Blake2.blake2_finish",
"Hacl.Impl.Blake2.Core.state_v"
] | [] | 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 (v kk) (v nn)))
inline_for_extraction noextract
val blake2_init:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms
let blake2_init #al #ms hash kk nn =
let h0 = ST.get() 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 kk_shift_8 = shift_left (size_to_word al kk) (size 8) in
let iv0' = iv0 ^. (Spec.nat_to_word al 0x01010000) ^. kk_shift_8 ^. (size_to_word al nn) 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(modifies (loc hash) h0 h1);
Lib.Sequence.eq_intro (state_v h1 hash) (Spec.blake2_init_hash al (v kk) (v nn))
#push-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let _ : squash (inversion Spec.alg) = allow_inversion Spec.alg
inline_for_extraction noextract
val split_blocks: al:Spec.alg -> len:size_t -> r:(size_t & size_t){
let (x,y) = r in
let (sx,sy) = Spec.split al (v len) in
sx == v x /\
sy == v y}
let split_blocks al len =
let nb = len /. size_block al in
let rem = len %. size_block al in
if rem =. 0ul && nb >. 0ul then
let nb' = nb -! 1ul in
let rem' = size_block al in
(nb',rem')
else (nb,rem)
inline_for_extraction noextract
let blake2_update_multi_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}
-> blocks: lbuffer uint8 len
-> nb : size_t{length blocks >= v nb * v (size_block al) } ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h blocks /\
disjoint hash blocks /\ disjoint wv hash /\ disjoint wv blocks))
(ensures (fun h0 _ h1 ->
modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash == repeati (v nb) (Spec.blake2_update1 al (v prev) h0.[|blocks|])
(state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_multi (#al : Spec.alg) (#ms : m_spec) :
blake2_update_block:blake2_update_block_st al ms
-> blake2_update_multi_st al ms
let blake2_update_multi #al #ms blake2_update_block #len wv hash prev blocks nb =
let h0 = ST.get () in
[@inline_let]
let a_spec = Spec.state al in
[@inline_let]
let refl h = state_v h hash in
[@inline_let]
let footprint = Ghost.hide(loc hash |+| loc wv) in
[@inline_let]
let spec h = Spec.blake2_update1 al (v prev) h.[|blocks|] in
loop_refl h0 nb a_spec refl footprint spec
(fun i ->
Loops.unfold_repeati (v nb) (spec h0) (state_v h0 hash) (v i);
blake2_update1 #al #ms blake2_update_block #len wv hash prev blocks i)
inline_for_extraction noextract
let blake2_update_blocks_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}
-> blocks: lbuffer uint8 len ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h blocks /\ disjoint hash blocks /\ disjoint wv hash /\ disjoint wv blocks))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash ==
Spec.blake2_update_blocks al (v prev) h0.[|blocks|] (state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_blocks (#al : Spec.alg) (#ms : m_spec) :
blake2_update_multi_st al ms
-> blake2_update_last_st al ms
-> blake2_update_blocks_st al ms
let blake2_update_blocks #al #ms blake2_update_multi blake2_update_last #len wv hash prev blocks =
let (nb,rem) = split_blocks al len in
blake2_update_multi wv hash prev blocks nb;
blake2_update_last #len wv hash prev rem blocks
inline_for_extraction noextract | false | true | Hacl.Impl.Blake2.Generic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val blake2_finish_st : al: Spec.Blake2.alg -> ms: Hacl.Impl.Blake2.Core.m_spec -> Type0 | [] | Hacl.Impl.Blake2.Generic.blake2_finish_st | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | al: Spec.Blake2.alg -> ms: Hacl.Impl.Blake2.Core.m_spec -> Type0 | {
"end_col": 93,
"end_line": 671,
"start_col": 4,
"start_line": 665
} |
|
Prims.Tot | val size_to_word: al:Spec.alg -> s:size_t -> u:word_t al{u == Spec.nat_to_word al (v s)} | [
{
"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
}
] | false | let size_to_word al s = match al with
| Spec.Blake2S -> size_to_uint32 s
| Spec.Blake2B -> size_to_uint64 s | 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 = | false | null | false | match al with
| Spec.Blake2S -> size_to_uint32 s
| Spec.Blake2B -> size_to_uint64 s | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.alg",
"Lib.IntTypes.size_t",
"Lib.IntTypes.size_to_uint32",
"Lib.IntTypes.size_to_uint64",
"Hacl.Impl.Blake2.Core.word_t",
"Prims.eq2",
"Spec.Blake2.word_t",
"Spec.Blake2.nat_to_word",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB"
] | [] | 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 | false | false | Hacl.Impl.Blake2.Generic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val size_to_word: al:Spec.alg -> s:size_t -> u:word_t al{u == Spec.nat_to_word al (v s)} | [] | Hacl.Impl.Blake2.Generic.size_to_word | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | al: Spec.Blake2.alg -> s: Lib.IntTypes.size_t
-> u13: Hacl.Impl.Blake2.Core.word_t al {u13 == Spec.Blake2.nat_to_word al (Lib.IntTypes.v s)} | {
"end_col": 36,
"end_line": 85,
"start_col": 24,
"start_line": 83
} |
Prims.Tot | [
{
"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
}
] | false | 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 (v kk) (v nn))) | let blake2_init_st (al: Spec.alg) (ms: m_spec) = | false | null | false |
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 (v kk) (v nn))) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.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.max_key",
"Prims.l_and",
"Spec.Blake2.max_output",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Impl.Blake2.Core.element_t",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Prims.eq2",
"Spec.Blake2.state",
"Hacl.Impl.Blake2.Core.state_v",
"Spec.Blake2.blake2_init_hash"
] | [] | 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 | false | true | Hacl.Impl.Blake2.Generic.fst | {
"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"
} | null | val blake2_init_st : al: Spec.Blake2.alg -> ms: Hacl.Impl.Blake2.Core.m_spec -> Type0 | [] | Hacl.Impl.Blake2.Generic.blake2_init_st | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | al: Spec.Blake2.alg -> ms: Hacl.Impl.Blake2.Core.m_spec -> Type0 | {
"end_col": 65,
"end_line": 552,
"start_col": 4,
"start_line": 546
} |
|
Prims.Tot | [
{
"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
}
] | false | let blake2_st (al:Spec.alg) (ms:m_spec) =
nn:size_t{1 <= v nn /\ v nn <= Spec.max_output al}
-> output: lbuffer uint8 nn
-> ll: size_t
-> d: lbuffer uint8 ll
-> kk: size_t{v kk <= Spec.max_key al}
-> k: lbuffer uint8 kk ->
Stack unit
(requires (fun h -> live h output /\ live h d /\ live h k
/\ disjoint output d /\ disjoint output k /\ disjoint d k))
(ensures (fun h0 _ h1 -> modifies1 output h0 h1
/\ h1.[|output|] == Spec.blake2 al h0.[|d|] (v kk) h0.[|k|] (v nn))) | let blake2_st (al: Spec.alg) (ms: m_spec) = | false | null | false |
nn: size_t{1 <= v nn /\ v nn <= Spec.max_output al} ->
output: lbuffer uint8 nn ->
ll: size_t ->
d: lbuffer uint8 ll ->
kk: size_t{v kk <= Spec.max_key al} ->
k: lbuffer uint8 kk
-> Stack unit
(requires
(fun h ->
live h output /\ live h d /\ live h k /\ disjoint output d /\ disjoint output k /\
disjoint d k))
(ensures
(fun h0 _ h1 ->
modifies1 output h0 h1 /\
h1.[| output |] == Spec.blake2 al h0.[| d |] (v kk) h0.[| k |] (v nn))) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Spec.Blake2.max_output",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Spec.Blake2.max_key",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Lib.Buffer.disjoint",
"Lib.Buffer.modifies1",
"Prims.eq2",
"Lib.Sequence.lseq",
"Lib.Buffer.op_Brack_Lens_Access",
"Spec.Blake2.blake2"
] | [] | 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 (v kk) (v nn)))
inline_for_extraction noextract
val blake2_init:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms
let blake2_init #al #ms hash kk nn =
let h0 = ST.get() 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 kk_shift_8 = shift_left (size_to_word al kk) (size 8) in
let iv0' = iv0 ^. (Spec.nat_to_word al 0x01010000) ^. kk_shift_8 ^. (size_to_word al nn) 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(modifies (loc hash) h0 h1);
Lib.Sequence.eq_intro (state_v h1 hash) (Spec.blake2_init_hash al (v kk) (v nn))
#push-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let _ : squash (inversion Spec.alg) = allow_inversion Spec.alg
inline_for_extraction noextract
val split_blocks: al:Spec.alg -> len:size_t -> r:(size_t & size_t){
let (x,y) = r in
let (sx,sy) = Spec.split al (v len) in
sx == v x /\
sy == v y}
let split_blocks al len =
let nb = len /. size_block al in
let rem = len %. size_block al in
if rem =. 0ul && nb >. 0ul then
let nb' = nb -! 1ul in
let rem' = size_block al in
(nb',rem')
else (nb,rem)
inline_for_extraction noextract
let blake2_update_multi_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}
-> blocks: lbuffer uint8 len
-> nb : size_t{length blocks >= v nb * v (size_block al) } ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h blocks /\
disjoint hash blocks /\ disjoint wv hash /\ disjoint wv blocks))
(ensures (fun h0 _ h1 ->
modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash == repeati (v nb) (Spec.blake2_update1 al (v prev) h0.[|blocks|])
(state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_multi (#al : Spec.alg) (#ms : m_spec) :
blake2_update_block:blake2_update_block_st al ms
-> blake2_update_multi_st al ms
let blake2_update_multi #al #ms blake2_update_block #len wv hash prev blocks nb =
let h0 = ST.get () in
[@inline_let]
let a_spec = Spec.state al in
[@inline_let]
let refl h = state_v h hash in
[@inline_let]
let footprint = Ghost.hide(loc hash |+| loc wv) in
[@inline_let]
let spec h = Spec.blake2_update1 al (v prev) h.[|blocks|] in
loop_refl h0 nb a_spec refl footprint spec
(fun i ->
Loops.unfold_repeati (v nb) (spec h0) (state_v h0 hash) (v i);
blake2_update1 #al #ms blake2_update_block #len wv hash prev blocks i)
inline_for_extraction noextract
let blake2_update_blocks_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}
-> blocks: lbuffer uint8 len ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h blocks /\ disjoint hash blocks /\ disjoint wv hash /\ disjoint wv blocks))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash ==
Spec.blake2_update_blocks al (v prev) h0.[|blocks|] (state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_blocks (#al : Spec.alg) (#ms : m_spec) :
blake2_update_multi_st al ms
-> blake2_update_last_st al ms
-> blake2_update_blocks_st al ms
let blake2_update_blocks #al #ms blake2_update_multi blake2_update_last #len wv hash prev blocks =
let (nb,rem) = split_blocks al len in
blake2_update_multi wv hash prev blocks nb;
blake2_update_last #len wv hash prev rem blocks
inline_for_extraction noextract
let blake2_finish_st (al:Spec.alg) (ms:m_spec) =
nn: size_t{1 <= v nn /\ v nn <= Spec.max_output al}
-> output: lbuffer uint8 nn
-> hash: state_p al ms ->
Stack unit
(requires (fun h -> live h hash /\ live h output /\ disjoint output hash))
(ensures (fun h0 _ h1 -> modifies (loc output) h0 h1
/\ h1.[|output|] == Spec.blake2_finish al (state_v h0 hash) (v nn)))
inline_for_extraction noextract
val blake2_finish:#al:Spec.alg -> #ms:m_spec -> blake2_finish_st al ms
let blake2_finish #al #ms nn output hash =
let h0 = ST.get () in
[@inline_let]
let double_row = 2ul *. size_row al in
[@inline_let]
let spec _ h1 = h1.[|output|] == Spec.blake2_finish al (state_v h0 hash) (v nn) in
salloc1 h0 double_row (u8 0) (Ghost.hide (loc output)) spec
(fun full ->
let first = sub full 0ul (size_row al) in
let second = sub full (size_row al) (size_row al) in
let row0 = rowi hash 0ul in
let row1 = rowi hash 1ul in
store_row first row0;
store_row second row1;
let h1 = ST.get() in
Lib.Sequence.eq_intro (as_seq h1 full)
(Lib.Sequence.(as_seq h1 (gsub full 0ul (size_row al)) @|
as_seq h1 (gsub full (size_row al) (size_row al))));
let final = sub full (size 0) nn in
copy output final)
inline_for_extraction noextract
let blake2_update_key_st (al:Spec.alg) (ms:m_spec) =
wv:state_p al ms
-> hash: state_p al ms
-> kk: size_t{v kk > 0 /\ v kk <= Spec.max_key al}
-> k: lbuffer uint8 kk
-> ll: size_t ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h k /\
disjoint hash k /\ disjoint wv hash /\ disjoint wv k))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1
/\ state_v h1 hash == Spec.blake2_update_key al (v kk) h0.[|k|] (v ll) (state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_key:
#al:Spec.alg
-> #ms:m_spec
-> blake2_update_block_st al ms
-> blake2_update_key_st al ms
inline_for_extraction noextract
let blake2_update_key #al #ms blake2_update_block wv hash kk k ll =
let lb = size_to_limb al (size_block al) in
assert (v lb = Spec.size_block al);
let h0 = ST.get () in
salloc1 h0 (size_block al) (u8 0) (Ghost.hide (loc hash |+| loc wv))
(fun _ h1 -> live h1 hash /\ state_v h1 hash == Spec.blake2_update_key al (v kk) h0.[|k|] (v ll) (state_v h0 hash))
(fun key_block ->
update_sub key_block 0ul kk k;
let h1 = ST.get() in
if ll =. 0ul then
blake2_update_block wv hash true lb key_block
else
blake2_update_block wv hash false lb key_block)
inline_for_extraction noextract
let blake2_update_st (al:Spec.alg) (ms:m_spec) =
wv:state_p al ms
-> hash: state_p al ms
-> kk: size_t{v kk <= Spec.max_key al}
-> k: lbuffer uint8 kk
-> ll: size_t
-> d: lbuffer uint8 ll ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h k /\ live h d /\
disjoint hash k /\ disjoint wv hash /\ disjoint wv k /\
disjoint hash d /\ disjoint wv d /\ disjoint d k))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1
/\ state_v h1 hash == Spec.blake2_update al (v kk) h0.[|k|] h0.[|d|] (state_v h0 hash)))
inline_for_extraction noextract
val blake2_update:
#al:Spec.alg
-> #ms:m_spec
-> blake2_update_key_st al ms
-> blake2_update_blocks_st al ms
-> blake2_update_st al ms
inline_for_extraction noextract
let blake2_update #al #ms blake2_update_key blake2_update_blocks
wv hash kk k ll d =
let lb = size_to_limb al (size_block al) in
assert (v lb = Spec.size_block al);
if kk >. 0ul then (
blake2_update_key wv hash kk k ll;
if ll =. 0ul then ()
else blake2_update_blocks wv hash lb d)
else blake2_update_blocks wv hash (size_to_limb al 0ul) d
inline_for_extraction noextract | false | true | Hacl.Impl.Blake2.Generic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val blake2_st : al: Spec.Blake2.alg -> ms: Hacl.Impl.Blake2.Core.m_spec -> Type0 | [] | Hacl.Impl.Blake2.Generic.blake2_st | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | al: Spec.Blake2.alg -> ms: Hacl.Impl.Blake2.Core.m_spec -> Type0 | {
"end_col": 93,
"end_line": 781,
"start_col": 4,
"start_line": 771
} |
|
FStar.HyperStack.ST.Stack | 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]))) | [
{
"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
}
] | false | let get_sigma s =
recall_contents sigmaTable Spec.sigmaTable;
index sigmaTable s | 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 = | true | null | false | recall_contents sigmaTable Spec.sigmaTable;
index sigmaTable s | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [] | [
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Buffer.index",
"Lib.Buffer.CONST",
"Spec.Blake2.sigma_elt_t",
"FStar.UInt32.uint_to_t",
"Hacl.Impl.Blake2.Constants.sigmaTable",
"Prims.unit",
"Lib.Buffer.recall_contents",
"Spec.Blake2.sigmaTable"
] | [] | 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]))) | false | false | Hacl.Impl.Blake2.Generic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | 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]))) | [] | Hacl.Impl.Blake2.Generic.get_sigma | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | s: Lib.IntTypes.size_t{Lib.IntTypes.v s < 160} -> FStar.HyperStack.ST.Stack Spec.Blake2.sigma_elt_t | {
"end_col": 20,
"end_line": 65,
"start_col": 2,
"start_line": 64
} |
Prims.Tot | val split_blocks: al:Spec.alg -> len:size_t -> r:(size_t & size_t){
let (x,y) = r in
let (sx,sy) = Spec.split al (v len) in
sx == v x /\
sy == v y} | [
{
"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
}
] | false | let split_blocks al len =
let nb = len /. size_block al in
let rem = len %. size_block al in
if rem =. 0ul && nb >. 0ul then
let nb' = nb -! 1ul in
let rem' = size_block al in
(nb',rem')
else (nb,rem) | val split_blocks: al:Spec.alg -> len:size_t -> r:(size_t & size_t){
let (x,y) = r in
let (sx,sy) = Spec.split al (v len) in
sx == v x /\
sy == v y}
let split_blocks al len = | false | null | false | let nb = len /. size_block al in
let rem = len %. size_block al in
if rem =. 0ul && nb >. 0ul
then
let nb' = nb -! 1ul in
let rem' = size_block al in
(nb', rem')
else (nb, rem) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.alg",
"Lib.IntTypes.size_t",
"Prims.op_AmpAmp",
"Lib.IntTypes.op_Equals_Dot",
"Lib.IntTypes.U32",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.op_Greater_Dot",
"FStar.Pervasives.Native.Mktuple2",
"Lib.IntTypes.int_t",
"Lib.IntTypes.PUB",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Lib.IntTypes.v",
"Prims.op_Multiply",
"Spec.Blake2.size_word",
"Hacl.Impl.Blake2.Core.size_block",
"Lib.IntTypes.op_Subtraction_Bang",
"Prims.bool",
"FStar.Pervasives.Native.tuple2",
"Prims.nat",
"Prims.l_and",
"Prims.eq2",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.range",
"Prims.op_Addition",
"Spec.Blake2.size_block",
"Spec.Blake2.split",
"Lib.IntTypes.op_Percent_Dot",
"Lib.IntTypes.op_Slash_Dot"
] | [] | 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 (v kk) (v nn)))
inline_for_extraction noextract
val blake2_init:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms
let blake2_init #al #ms hash kk nn =
let h0 = ST.get() 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 kk_shift_8 = shift_left (size_to_word al kk) (size 8) in
let iv0' = iv0 ^. (Spec.nat_to_word al 0x01010000) ^. kk_shift_8 ^. (size_to_word al nn) 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(modifies (loc hash) h0 h1);
Lib.Sequence.eq_intro (state_v h1 hash) (Spec.blake2_init_hash al (v kk) (v nn))
#push-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let _ : squash (inversion Spec.alg) = allow_inversion Spec.alg
inline_for_extraction noextract
val split_blocks: al:Spec.alg -> len:size_t -> r:(size_t & size_t){
let (x,y) = r in
let (sx,sy) = Spec.split al (v len) in
sx == v x /\
sy == v y} | false | false | Hacl.Impl.Blake2.Generic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val split_blocks: al:Spec.alg -> len:size_t -> r:(size_t & size_t){
let (x,y) = r in
let (sx,sy) = Spec.split al (v len) in
sx == v x /\
sy == v y} | [] | Hacl.Impl.Blake2.Generic.split_blocks | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | al: Spec.Blake2.alg -> len: Lib.IntTypes.size_t
-> r:
(Lib.IntTypes.size_t * Lib.IntTypes.size_t)
{ let _ = r in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ x y = _ in
let _ = Spec.Blake2.split al (Lib.IntTypes.v len) in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ sx sy = _ in
sx == Lib.IntTypes.v x /\ sy == Lib.IntTypes.v y)
<:
Type0)
<:
Type0 } | {
"end_col": 15,
"end_line": 601,
"start_col": 25,
"start_line": 594
} |
Prims.Tot | [
{
"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
}
] | false | let blake2_update_st (al:Spec.alg) (ms:m_spec) =
wv:state_p al ms
-> hash: state_p al ms
-> kk: size_t{v kk <= Spec.max_key al}
-> k: lbuffer uint8 kk
-> ll: size_t
-> d: lbuffer uint8 ll ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h k /\ live h d /\
disjoint hash k /\ disjoint wv hash /\ disjoint wv k /\
disjoint hash d /\ disjoint wv d /\ disjoint d k))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1
/\ state_v h1 hash == Spec.blake2_update al (v kk) h0.[|k|] h0.[|d|] (state_v h0 hash))) | let blake2_update_st (al: Spec.alg) (ms: m_spec) = | false | null | false |
wv: state_p al ms ->
hash: state_p al ms ->
kk: size_t{v kk <= Spec.max_key al} ->
k: lbuffer uint8 kk ->
ll: size_t ->
d: lbuffer uint8 ll
-> Stack unit
(requires
(fun h ->
live h wv /\ live h hash /\ live h k /\ live h d /\ disjoint hash k /\ disjoint wv hash /\
disjoint wv k /\ disjoint hash d /\ disjoint wv d /\ disjoint d k))
(ensures
(fun h0 _ h1 ->
modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash == Spec.blake2_update al (v kk) h0.[| k |] h0.[| d |] (state_v h0 hash))
) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.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.max_key",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Impl.Blake2.Core.element_t",
"Lib.Buffer.disjoint",
"Lib.Buffer.modifies",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.Buffer.loc",
"Prims.eq2",
"Spec.Blake2.state",
"Hacl.Impl.Blake2.Core.state_v",
"Spec.Blake2.blake2_update",
"Lib.Buffer.op_Brack_Lens_Access"
] | [] | 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 (v kk) (v nn)))
inline_for_extraction noextract
val blake2_init:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms
let blake2_init #al #ms hash kk nn =
let h0 = ST.get() 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 kk_shift_8 = shift_left (size_to_word al kk) (size 8) in
let iv0' = iv0 ^. (Spec.nat_to_word al 0x01010000) ^. kk_shift_8 ^. (size_to_word al nn) 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(modifies (loc hash) h0 h1);
Lib.Sequence.eq_intro (state_v h1 hash) (Spec.blake2_init_hash al (v kk) (v nn))
#push-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let _ : squash (inversion Spec.alg) = allow_inversion Spec.alg
inline_for_extraction noextract
val split_blocks: al:Spec.alg -> len:size_t -> r:(size_t & size_t){
let (x,y) = r in
let (sx,sy) = Spec.split al (v len) in
sx == v x /\
sy == v y}
let split_blocks al len =
let nb = len /. size_block al in
let rem = len %. size_block al in
if rem =. 0ul && nb >. 0ul then
let nb' = nb -! 1ul in
let rem' = size_block al in
(nb',rem')
else (nb,rem)
inline_for_extraction noextract
let blake2_update_multi_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}
-> blocks: lbuffer uint8 len
-> nb : size_t{length blocks >= v nb * v (size_block al) } ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h blocks /\
disjoint hash blocks /\ disjoint wv hash /\ disjoint wv blocks))
(ensures (fun h0 _ h1 ->
modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash == repeati (v nb) (Spec.blake2_update1 al (v prev) h0.[|blocks|])
(state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_multi (#al : Spec.alg) (#ms : m_spec) :
blake2_update_block:blake2_update_block_st al ms
-> blake2_update_multi_st al ms
let blake2_update_multi #al #ms blake2_update_block #len wv hash prev blocks nb =
let h0 = ST.get () in
[@inline_let]
let a_spec = Spec.state al in
[@inline_let]
let refl h = state_v h hash in
[@inline_let]
let footprint = Ghost.hide(loc hash |+| loc wv) in
[@inline_let]
let spec h = Spec.blake2_update1 al (v prev) h.[|blocks|] in
loop_refl h0 nb a_spec refl footprint spec
(fun i ->
Loops.unfold_repeati (v nb) (spec h0) (state_v h0 hash) (v i);
blake2_update1 #al #ms blake2_update_block #len wv hash prev blocks i)
inline_for_extraction noextract
let blake2_update_blocks_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}
-> blocks: lbuffer uint8 len ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h blocks /\ disjoint hash blocks /\ disjoint wv hash /\ disjoint wv blocks))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash ==
Spec.blake2_update_blocks al (v prev) h0.[|blocks|] (state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_blocks (#al : Spec.alg) (#ms : m_spec) :
blake2_update_multi_st al ms
-> blake2_update_last_st al ms
-> blake2_update_blocks_st al ms
let blake2_update_blocks #al #ms blake2_update_multi blake2_update_last #len wv hash prev blocks =
let (nb,rem) = split_blocks al len in
blake2_update_multi wv hash prev blocks nb;
blake2_update_last #len wv hash prev rem blocks
inline_for_extraction noextract
let blake2_finish_st (al:Spec.alg) (ms:m_spec) =
nn: size_t{1 <= v nn /\ v nn <= Spec.max_output al}
-> output: lbuffer uint8 nn
-> hash: state_p al ms ->
Stack unit
(requires (fun h -> live h hash /\ live h output /\ disjoint output hash))
(ensures (fun h0 _ h1 -> modifies (loc output) h0 h1
/\ h1.[|output|] == Spec.blake2_finish al (state_v h0 hash) (v nn)))
inline_for_extraction noextract
val blake2_finish:#al:Spec.alg -> #ms:m_spec -> blake2_finish_st al ms
let blake2_finish #al #ms nn output hash =
let h0 = ST.get () in
[@inline_let]
let double_row = 2ul *. size_row al in
[@inline_let]
let spec _ h1 = h1.[|output|] == Spec.blake2_finish al (state_v h0 hash) (v nn) in
salloc1 h0 double_row (u8 0) (Ghost.hide (loc output)) spec
(fun full ->
let first = sub full 0ul (size_row al) in
let second = sub full (size_row al) (size_row al) in
let row0 = rowi hash 0ul in
let row1 = rowi hash 1ul in
store_row first row0;
store_row second row1;
let h1 = ST.get() in
Lib.Sequence.eq_intro (as_seq h1 full)
(Lib.Sequence.(as_seq h1 (gsub full 0ul (size_row al)) @|
as_seq h1 (gsub full (size_row al) (size_row al))));
let final = sub full (size 0) nn in
copy output final)
inline_for_extraction noextract
let blake2_update_key_st (al:Spec.alg) (ms:m_spec) =
wv:state_p al ms
-> hash: state_p al ms
-> kk: size_t{v kk > 0 /\ v kk <= Spec.max_key al}
-> k: lbuffer uint8 kk
-> ll: size_t ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h k /\
disjoint hash k /\ disjoint wv hash /\ disjoint wv k))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1
/\ state_v h1 hash == Spec.blake2_update_key al (v kk) h0.[|k|] (v ll) (state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_key:
#al:Spec.alg
-> #ms:m_spec
-> blake2_update_block_st al ms
-> blake2_update_key_st al ms
inline_for_extraction noextract
let blake2_update_key #al #ms blake2_update_block wv hash kk k ll =
let lb = size_to_limb al (size_block al) in
assert (v lb = Spec.size_block al);
let h0 = ST.get () in
salloc1 h0 (size_block al) (u8 0) (Ghost.hide (loc hash |+| loc wv))
(fun _ h1 -> live h1 hash /\ state_v h1 hash == Spec.blake2_update_key al (v kk) h0.[|k|] (v ll) (state_v h0 hash))
(fun key_block ->
update_sub key_block 0ul kk k;
let h1 = ST.get() in
if ll =. 0ul then
blake2_update_block wv hash true lb key_block
else
blake2_update_block wv hash false lb key_block)
inline_for_extraction noextract | false | true | Hacl.Impl.Blake2.Generic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val blake2_update_st : al: Spec.Blake2.alg -> ms: Hacl.Impl.Blake2.Core.m_spec -> Type0 | [] | Hacl.Impl.Blake2.Generic.blake2_update_st | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | al: Spec.Blake2.alg -> ms: Hacl.Impl.Blake2.Core.m_spec -> Type0 | {
"end_col": 113,
"end_line": 746,
"start_col": 4,
"start_line": 735
} |
|
Prims.Tot | [
{
"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
}
] | false | let blake2_update_multi_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}
-> blocks: lbuffer uint8 len
-> nb : size_t{length blocks >= v nb * v (size_block al) } ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h blocks /\
disjoint hash blocks /\ disjoint wv hash /\ disjoint wv blocks))
(ensures (fun h0 _ h1 ->
modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash == repeati (v nb) (Spec.blake2_update1 al (v prev) h0.[|blocks|])
(state_v h0 hash))) | let blake2_update_multi_st (al: Spec.alg) (ms: m_spec) = | false | null | false |
#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} ->
blocks: lbuffer uint8 len ->
nb: size_t{length blocks >= v nb * v (size_block al)}
-> Stack unit
(requires
(fun h ->
live h wv /\ live h hash /\ live h blocks /\ disjoint hash blocks /\ disjoint wv hash /\
disjoint wv blocks))
(ensures
(fun h0 _ h1 ->
modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash ==
repeati (v nb) (Spec.blake2_update1 al (v prev) h0.[| blocks |]) (state_v h0 hash))) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Lib.IntTypes.size_t",
"Hacl.Impl.Blake2.Core.state_p",
"Spec.Blake2.limb_t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.v",
"Spec.Blake2.limb_inttype",
"Lib.IntTypes.SEC",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Spec.Blake2.max_limb",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Prims.op_GreaterThanOrEqual",
"Lib.Buffer.length",
"Lib.Buffer.MUT",
"FStar.Mul.op_Star",
"Hacl.Impl.Blake2.Core.size_block",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Hacl.Impl.Blake2.Core.element_t",
"Lib.Buffer.disjoint",
"Lib.Buffer.modifies",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.Buffer.loc",
"Prims.eq2",
"Spec.Blake2.state",
"Hacl.Impl.Blake2.Core.state_v",
"Lib.LoopCombinators.repeati",
"Spec.Blake2.blake2_update1",
"Lib.Buffer.op_Brack_Lens_Access"
] | [] | 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 (v kk) (v nn)))
inline_for_extraction noextract
val blake2_init:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms
let blake2_init #al #ms hash kk nn =
let h0 = ST.get() 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 kk_shift_8 = shift_left (size_to_word al kk) (size 8) in
let iv0' = iv0 ^. (Spec.nat_to_word al 0x01010000) ^. kk_shift_8 ^. (size_to_word al nn) 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(modifies (loc hash) h0 h1);
Lib.Sequence.eq_intro (state_v h1 hash) (Spec.blake2_init_hash al (v kk) (v nn))
#push-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let _ : squash (inversion Spec.alg) = allow_inversion Spec.alg
inline_for_extraction noextract
val split_blocks: al:Spec.alg -> len:size_t -> r:(size_t & size_t){
let (x,y) = r in
let (sx,sy) = Spec.split al (v len) in
sx == v x /\
sy == v y}
let split_blocks al len =
let nb = len /. size_block al in
let rem = len %. size_block al in
if rem =. 0ul && nb >. 0ul then
let nb' = nb -! 1ul in
let rem' = size_block al in
(nb',rem')
else (nb,rem)
inline_for_extraction noextract | false | true | Hacl.Impl.Blake2.Generic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val blake2_update_multi_st : al: Spec.Blake2.alg -> ms: Hacl.Impl.Blake2.Core.m_spec -> Type0 | [] | Hacl.Impl.Blake2.Generic.blake2_update_multi_st | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | al: Spec.Blake2.alg -> ms: Hacl.Impl.Blake2.Core.m_spec -> Type0 | {
"end_col": 52,
"end_line": 617,
"start_col": 5,
"start_line": 605
} |
|
Prims.Tot | val size_to_limb: al:Spec.alg -> s:size_t -> u:Spec.limb_t al{u == Spec.nat_to_limb al (v s)} | [
{
"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
}
] | false | let size_to_limb al s = match al with
| Spec.Blake2S -> size_to_uint64 s
| Spec.Blake2B -> to_u128 (size_to_uint64 s) | 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 = | false | null | false | match al with
| Spec.Blake2S -> size_to_uint64 s
| Spec.Blake2B -> to_u128 (size_to_uint64 s) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.alg",
"Lib.IntTypes.size_t",
"Lib.IntTypes.size_to_uint64",
"Lib.IntTypes.to_u128",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Spec.Blake2.limb_t",
"Prims.eq2",
"Spec.Blake2.nat_to_limb",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB"
] | [] | 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 | false | false | Hacl.Impl.Blake2.Generic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val size_to_limb: al:Spec.alg -> s:size_t -> u:Spec.limb_t al{u == Spec.nat_to_limb al (v s)} | [] | Hacl.Impl.Blake2.Generic.size_to_limb | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | al: Spec.Blake2.alg -> s: Lib.IntTypes.size_t
-> u15: Spec.Blake2.limb_t al {u15 == Spec.Blake2.nat_to_limb al (Lib.IntTypes.v s)} | {
"end_col": 46,
"end_line": 91,
"start_col": 24,
"start_line": 89
} |
FStar.HyperStack.ST.Stack | 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)))) | [
{
"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
}
] | false | 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 | 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 = | true | null | false | 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 | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [] | [
"Spec.Blake2.alg",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.size_v",
"Lib.IntTypes.secret",
"Spec.Blake2.wt",
"Hacl.Impl.Blake2.Core.word_t",
"Spec.Blake2.pub_word_t",
"Lib.Buffer.index",
"Lib.Buffer.CONST",
"FStar.UInt32.uint_to_t",
"Lib.Buffer.lbuffer_t",
"FStar.UInt32.t",
"Prims.eq2",
"LowStar.ConstBuffer.qual",
"LowStar.ConstBuffer.qual_of",
"LowStar.ConstBuffer.IMMUTABLE",
"Prims.l_and",
"Lib.Buffer.witnessed",
"Spec.Blake2.ivTable",
"Lib.Buffer.recallable",
"Hacl.Impl.Blake2.Constants.ivTable_S",
"Hacl.Impl.Blake2.Constants.ivTable_B",
"Prims.unit",
"Lib.Buffer.recall_contents",
"Spec.Blake2.Blake2B",
"FStar.UInt32.__uint_to_t",
"Spec.Blake2.Blake2S"
] | [] | 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)))) | false | false | Hacl.Impl.Blake2.Generic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | 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)))) | [] | Hacl.Impl.Blake2.Generic.get_iv | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Blake2.alg -> s: Lib.IntTypes.size_t{Lib.IntTypes.size_v s < 8}
-> FStar.HyperStack.ST.Stack (Hacl.Impl.Blake2.Core.word_t a) | {
"end_col": 23,
"end_line": 53,
"start_col": 2,
"start_line": 44
} |
FStar.HyperStack.ST.Stack | 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)))) | [
{
"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
}
] | false | let get_sigma_sub start i = get_sigma (start +. i) | 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 = | true | null | false | get_sigma (start +. i) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [] | [
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_Addition",
"Hacl.Impl.Blake2.Generic.get_sigma",
"Lib.IntTypes.op_Plus_Dot",
"Spec.Blake2.sigma_elt_t"
] | [] | 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)))) | false | false | Hacl.Impl.Blake2.Generic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | 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)))) | [] | Hacl.Impl.Blake2.Generic.get_sigma_sub | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
start: Lib.IntTypes.size_t ->
i: Lib.IntTypes.size_t{Lib.IntTypes.v i < 16 /\ Lib.IntTypes.v start + Lib.IntTypes.v i < 160}
-> FStar.HyperStack.ST.Stack Spec.Blake2.sigma_elt_t | {
"end_col": 50,
"end_line": 76,
"start_col": 28,
"start_line": 76
} |
Prims.Tot | val blake2_update_blocks (#al : Spec.alg) (#ms : m_spec) :
blake2_update_multi_st al ms
-> blake2_update_last_st al ms
-> blake2_update_blocks_st al ms | [
{
"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
}
] | false | let blake2_update_blocks #al #ms blake2_update_multi blake2_update_last #len wv hash prev blocks =
let (nb,rem) = split_blocks al len in
blake2_update_multi wv hash prev blocks nb;
blake2_update_last #len wv hash prev rem blocks | val blake2_update_blocks (#al : Spec.alg) (#ms : m_spec) :
blake2_update_multi_st al ms
-> blake2_update_last_st al ms
-> blake2_update_blocks_st al ms
let blake2_update_blocks #al #ms blake2_update_multi blake2_update_last #len wv hash prev blocks = | false | null | false | let nb, rem = split_blocks al len in
blake2_update_multi wv hash prev blocks nb;
blake2_update_last #len wv hash prev rem blocks | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Hacl.Impl.Blake2.Generic.blake2_update_multi_st",
"Hacl.Impl.Blake2.Generic.blake2_update_last_st",
"Lib.IntTypes.size_t",
"Hacl.Impl.Blake2.Core.state_p",
"Spec.Blake2.limb_t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.v",
"Spec.Blake2.limb_inttype",
"Lib.IntTypes.SEC",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Spec.Blake2.max_limb",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Prims.unit",
"FStar.Pervasives.Native.tuple2",
"Lib.IntTypes.int_t",
"Spec.Blake2.split",
"Prims.nat",
"Prims.l_and",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.range",
"Hacl.Impl.Blake2.Generic.split_blocks"
] | [] | 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 (v kk) (v nn)))
inline_for_extraction noextract
val blake2_init:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms
let blake2_init #al #ms hash kk nn =
let h0 = ST.get() 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 kk_shift_8 = shift_left (size_to_word al kk) (size 8) in
let iv0' = iv0 ^. (Spec.nat_to_word al 0x01010000) ^. kk_shift_8 ^. (size_to_word al nn) 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(modifies (loc hash) h0 h1);
Lib.Sequence.eq_intro (state_v h1 hash) (Spec.blake2_init_hash al (v kk) (v nn))
#push-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let _ : squash (inversion Spec.alg) = allow_inversion Spec.alg
inline_for_extraction noextract
val split_blocks: al:Spec.alg -> len:size_t -> r:(size_t & size_t){
let (x,y) = r in
let (sx,sy) = Spec.split al (v len) in
sx == v x /\
sy == v y}
let split_blocks al len =
let nb = len /. size_block al in
let rem = len %. size_block al in
if rem =. 0ul && nb >. 0ul then
let nb' = nb -! 1ul in
let rem' = size_block al in
(nb',rem')
else (nb,rem)
inline_for_extraction noextract
let blake2_update_multi_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}
-> blocks: lbuffer uint8 len
-> nb : size_t{length blocks >= v nb * v (size_block al) } ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h blocks /\
disjoint hash blocks /\ disjoint wv hash /\ disjoint wv blocks))
(ensures (fun h0 _ h1 ->
modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash == repeati (v nb) (Spec.blake2_update1 al (v prev) h0.[|blocks|])
(state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_multi (#al : Spec.alg) (#ms : m_spec) :
blake2_update_block:blake2_update_block_st al ms
-> blake2_update_multi_st al ms
let blake2_update_multi #al #ms blake2_update_block #len wv hash prev blocks nb =
let h0 = ST.get () in
[@inline_let]
let a_spec = Spec.state al in
[@inline_let]
let refl h = state_v h hash in
[@inline_let]
let footprint = Ghost.hide(loc hash |+| loc wv) in
[@inline_let]
let spec h = Spec.blake2_update1 al (v prev) h.[|blocks|] in
loop_refl h0 nb a_spec refl footprint spec
(fun i ->
Loops.unfold_repeati (v nb) (spec h0) (state_v h0 hash) (v i);
blake2_update1 #al #ms blake2_update_block #len wv hash prev blocks i)
inline_for_extraction noextract
let blake2_update_blocks_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}
-> blocks: lbuffer uint8 len ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h blocks /\ disjoint hash blocks /\ disjoint wv hash /\ disjoint wv blocks))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash ==
Spec.blake2_update_blocks al (v prev) h0.[|blocks|] (state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_blocks (#al : Spec.alg) (#ms : m_spec) :
blake2_update_multi_st al ms
-> blake2_update_last_st al ms
-> blake2_update_blocks_st al ms | false | false | Hacl.Impl.Blake2.Generic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val blake2_update_blocks (#al : Spec.alg) (#ms : m_spec) :
blake2_update_multi_st al ms
-> blake2_update_last_st al ms
-> blake2_update_blocks_st al ms | [] | Hacl.Impl.Blake2.Generic.blake2_update_blocks | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
blake2_update_multi: Hacl.Impl.Blake2.Generic.blake2_update_multi_st al ms ->
blake2_update_last: Hacl.Impl.Blake2.Generic.blake2_update_last_st al ms
-> Hacl.Impl.Blake2.Generic.blake2_update_blocks_st al ms | {
"end_col": 49,
"end_line": 661,
"start_col": 98,
"start_line": 658
} |
FStar.HyperStack.ST.Stack | 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))) | [
{
"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
}
] | false | 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) | 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)))
let blake2_compress2 #al #ms wv m = | true | null | false | 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) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Hacl.Impl.Blake2.Core.state_p",
"Hacl.Impl.Blake2.Core.block_w",
"Lib.Buffer.loop_refl",
"Hacl.Impl.Blake2.Generic.rounds_t",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Blake2.Generic.blake2_round",
"Prims.unit",
"Lib.LoopCombinators.unfold_repeati",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Spec.Blake2.wt",
"Lib.IntTypes.SEC",
"Spec.Blake2.rounds",
"Hacl.Impl.Blake2.Core.state_v",
"FStar.Monotonic.HyperStack.mem",
"Prims.nat",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.pow2",
"Spec.Blake2.blake2_round",
"Lib.Buffer.op_Brack_Lens_Access",
"Lib.Buffer.MUT",
"Hacl.Impl.Blake2.Core.word_t",
"FStar.UInt32.__uint_to_t",
"FStar.Ghost.erased",
"LowStar.Monotonic.Buffer.loc",
"FStar.Ghost.hide",
"Lib.Buffer.loc",
"Hacl.Impl.Blake2.Core.element_t",
"Spec.Blake2.state",
"FStar.HyperStack.ST.get"
] | [] | 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))) | false | false | Hacl.Impl.Blake2.Generic.fst | {
"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": 400,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | 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))) | [] | Hacl.Impl.Blake2.Generic.blake2_compress2 | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | wv: Hacl.Impl.Blake2.Core.state_p al ms -> m: Hacl.Impl.Blake2.Core.block_w al
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 24,
"end_line": 387,
"start_col": 35,
"start_line": 374
} |
Prims.Tot | [
{
"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
}
] | false | 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))) | let blake2_update1_st (al: Spec.alg) (ms: m_spec) = | false | null | false |
#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))) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Lib.IntTypes.size_t",
"Hacl.Impl.Blake2.Core.state_p",
"Spec.Blake2.limb_t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.v",
"Spec.Blake2.limb_inttype",
"Lib.IntTypes.SEC",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Spec.Blake2.max_limb",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Prims.op_LessThan",
"Prims.op_Division",
"Lib.Buffer.length",
"Lib.Buffer.MUT",
"Spec.Blake2.size_block",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Hacl.Impl.Blake2.Core.element_t",
"Lib.Buffer.disjoint",
"Lib.Buffer.modifies",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.Buffer.loc",
"Prims.eq2",
"Spec.Blake2.state",
"Hacl.Impl.Blake2.Core.state_v",
"Spec.Blake2.blake2_update1",
"Lib.Buffer.op_Brack_Lens_Access"
] | [] | 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 | false | true | Hacl.Impl.Blake2.Generic.fst | {
"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"
} | null | val blake2_update1_st : al: Spec.Blake2.alg -> ms: Hacl.Impl.Blake2.Core.m_spec -> Type0 | [] | Hacl.Impl.Blake2.Generic.blake2_update1_st | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | al: Spec.Blake2.alg -> ms: Hacl.Impl.Blake2.Core.m_spec -> Type0 | {
"end_col": 113,
"end_line": 491,
"start_col": 3,
"start_line": 482
} |
|
FStar.HyperStack.ST.Stack | val 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 ]))) | [
{
"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
}
] | false | 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) | val 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 ])))
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 ]))) = | true | null | false | get_sigma (start +! i) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [] | [
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"FStar.Pervasives.normalize",
"Lib.IntTypes.op_Less_Equals_Dot",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.Blake2.Generic.get_sigma",
"Lib.IntTypes.op_Plus_Bang",
"Spec.Blake2.sigma_elt_t",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2",
"Lib.Sequence.op_String_Access",
"Spec.Blake2.size_sigmaTable",
"Spec.Blake2.sigmaTable",
"Prims.op_Addition"
] | [] | 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]))) | false | false | Hacl.Impl.Blake2.Generic.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val 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 ]))) | [] | Hacl.Impl.Blake2.Generic.get_sigma' | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
start: Lib.IntTypes.size_t{Lib.IntTypes.v start <= 144} ->
i: Lib.IntTypes.size_t{FStar.Pervasives.normalize (i <=. 15ul)}
-> FStar.HyperStack.ST.Stack Spec.Blake2.sigma_elt_t | {
"end_col": 24,
"end_line": 234,
"start_col": 2,
"start_line": 234
} |
FStar.HyperStack.ST.Stack | 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))) | [
{
"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
}
] | false | let blake2_compress0 #al m_s m_w =
uints_from_bytes_le m_w m_s | 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 = | true | null | false | uints_from_bytes_le m_w m_s | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.block_p",
"Hacl.Impl.Blake2.Core.block_w",
"Lib.ByteBuffer.uints_from_bytes_le",
"Spec.Blake2.wt",
"Lib.IntTypes.SEC",
"FStar.UInt32.__uint_to_t",
"Prims.unit"
] | [] | 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))) | false | false | Hacl.Impl.Blake2.Generic.fst | {
"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"
} | null | 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))) | [] | Hacl.Impl.Blake2.Generic.blake2_compress0 | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | m_s: Hacl.Impl.Blake2.Core.block_p al -> m_w: Hacl.Impl.Blake2.Core.block_w al
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 29,
"end_line": 317,
"start_col": 2,
"start_line": 317
} |
Prims.Tot | val blake2_update_block: #al:Spec.alg -> #ms:m_spec -> blake2_update_block_st al ms | [
{
"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
}
] | false | let blake2_update_block #al #ms wv hash flag totlen d =
blake2_compress wv hash d totlen flag | 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 = | false | null | false | blake2_compress wv hash d totlen flag | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Hacl.Impl.Blake2.Core.state_p",
"Prims.bool",
"Spec.Blake2.limb_t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.v",
"Spec.Blake2.limb_inttype",
"Lib.IntTypes.SEC",
"Spec.Blake2.max_limb",
"Hacl.Impl.Blake2.Core.block_p",
"Hacl.Impl.Blake2.Generic.blake2_compress",
"Prims.unit"
] | [] | 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 | false | false | Hacl.Impl.Blake2.Generic.fst | {
"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"
} | null | val blake2_update_block: #al:Spec.alg -> #ms:m_spec -> blake2_update_block_st al ms | [] | Hacl.Impl.Blake2.Generic.blake2_update_block | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Impl.Blake2.Generic.blake2_update_block_st al ms | {
"end_col": 41,
"end_line": 478,
"start_col": 4,
"start_line": 478
} |
Prims.Tot | val blake2_update:
#al:Spec.alg
-> #ms:m_spec
-> blake2_update_key_st al ms
-> blake2_update_blocks_st al ms
-> blake2_update_st al ms | [
{
"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
}
] | false | let blake2_update #al #ms blake2_update_key blake2_update_blocks
wv hash kk k ll d =
let lb = size_to_limb al (size_block al) in
assert (v lb = Spec.size_block al);
if kk >. 0ul then (
blake2_update_key wv hash kk k ll;
if ll =. 0ul then ()
else blake2_update_blocks wv hash lb d)
else blake2_update_blocks wv hash (size_to_limb al 0ul) d | val blake2_update:
#al:Spec.alg
-> #ms:m_spec
-> blake2_update_key_st al ms
-> blake2_update_blocks_st al ms
-> blake2_update_st al ms
let blake2_update #al #ms blake2_update_key blake2_update_blocks wv hash kk k ll d = | false | null | false | let lb = size_to_limb al (size_block al) in
assert (v lb = Spec.size_block al);
if kk >. 0ul
then
(blake2_update_key wv hash kk k ll;
if ll =. 0ul then () else blake2_update_blocks wv hash lb d)
else blake2_update_blocks wv hash (size_to_limb al 0ul) d | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Hacl.Impl.Blake2.Generic.blake2_update_key_st",
"Hacl.Impl.Blake2.Generic.blake2_update_blocks_st",
"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.max_key",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Lib.IntTypes.op_Greater_Dot",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.op_Equals_Dot",
"Prims.unit",
"Prims.bool",
"Hacl.Impl.Blake2.Generic.size_to_limb",
"Prims._assert",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Lib.IntTypes.range",
"Spec.Blake2.limb_inttype",
"Prims.l_and",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.max_size_t",
"Lib.IntTypes.SEC",
"Spec.Blake2.size_block",
"Spec.Blake2.limb_t",
"Prims.eq2",
"Spec.Blake2.nat_to_limb",
"Hacl.Impl.Blake2.Core.size_block"
] | [] | 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 (v kk) (v nn)))
inline_for_extraction noextract
val blake2_init:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms
let blake2_init #al #ms hash kk nn =
let h0 = ST.get() 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 kk_shift_8 = shift_left (size_to_word al kk) (size 8) in
let iv0' = iv0 ^. (Spec.nat_to_word al 0x01010000) ^. kk_shift_8 ^. (size_to_word al nn) 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(modifies (loc hash) h0 h1);
Lib.Sequence.eq_intro (state_v h1 hash) (Spec.blake2_init_hash al (v kk) (v nn))
#push-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let _ : squash (inversion Spec.alg) = allow_inversion Spec.alg
inline_for_extraction noextract
val split_blocks: al:Spec.alg -> len:size_t -> r:(size_t & size_t){
let (x,y) = r in
let (sx,sy) = Spec.split al (v len) in
sx == v x /\
sy == v y}
let split_blocks al len =
let nb = len /. size_block al in
let rem = len %. size_block al in
if rem =. 0ul && nb >. 0ul then
let nb' = nb -! 1ul in
let rem' = size_block al in
(nb',rem')
else (nb,rem)
inline_for_extraction noextract
let blake2_update_multi_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}
-> blocks: lbuffer uint8 len
-> nb : size_t{length blocks >= v nb * v (size_block al) } ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h blocks /\
disjoint hash blocks /\ disjoint wv hash /\ disjoint wv blocks))
(ensures (fun h0 _ h1 ->
modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash == repeati (v nb) (Spec.blake2_update1 al (v prev) h0.[|blocks|])
(state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_multi (#al : Spec.alg) (#ms : m_spec) :
blake2_update_block:blake2_update_block_st al ms
-> blake2_update_multi_st al ms
let blake2_update_multi #al #ms blake2_update_block #len wv hash prev blocks nb =
let h0 = ST.get () in
[@inline_let]
let a_spec = Spec.state al in
[@inline_let]
let refl h = state_v h hash in
[@inline_let]
let footprint = Ghost.hide(loc hash |+| loc wv) in
[@inline_let]
let spec h = Spec.blake2_update1 al (v prev) h.[|blocks|] in
loop_refl h0 nb a_spec refl footprint spec
(fun i ->
Loops.unfold_repeati (v nb) (spec h0) (state_v h0 hash) (v i);
blake2_update1 #al #ms blake2_update_block #len wv hash prev blocks i)
inline_for_extraction noextract
let blake2_update_blocks_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}
-> blocks: lbuffer uint8 len ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h blocks /\ disjoint hash blocks /\ disjoint wv hash /\ disjoint wv blocks))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash ==
Spec.blake2_update_blocks al (v prev) h0.[|blocks|] (state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_blocks (#al : Spec.alg) (#ms : m_spec) :
blake2_update_multi_st al ms
-> blake2_update_last_st al ms
-> blake2_update_blocks_st al ms
let blake2_update_blocks #al #ms blake2_update_multi blake2_update_last #len wv hash prev blocks =
let (nb,rem) = split_blocks al len in
blake2_update_multi wv hash prev blocks nb;
blake2_update_last #len wv hash prev rem blocks
inline_for_extraction noextract
let blake2_finish_st (al:Spec.alg) (ms:m_spec) =
nn: size_t{1 <= v nn /\ v nn <= Spec.max_output al}
-> output: lbuffer uint8 nn
-> hash: state_p al ms ->
Stack unit
(requires (fun h -> live h hash /\ live h output /\ disjoint output hash))
(ensures (fun h0 _ h1 -> modifies (loc output) h0 h1
/\ h1.[|output|] == Spec.blake2_finish al (state_v h0 hash) (v nn)))
inline_for_extraction noextract
val blake2_finish:#al:Spec.alg -> #ms:m_spec -> blake2_finish_st al ms
let blake2_finish #al #ms nn output hash =
let h0 = ST.get () in
[@inline_let]
let double_row = 2ul *. size_row al in
[@inline_let]
let spec _ h1 = h1.[|output|] == Spec.blake2_finish al (state_v h0 hash) (v nn) in
salloc1 h0 double_row (u8 0) (Ghost.hide (loc output)) spec
(fun full ->
let first = sub full 0ul (size_row al) in
let second = sub full (size_row al) (size_row al) in
let row0 = rowi hash 0ul in
let row1 = rowi hash 1ul in
store_row first row0;
store_row second row1;
let h1 = ST.get() in
Lib.Sequence.eq_intro (as_seq h1 full)
(Lib.Sequence.(as_seq h1 (gsub full 0ul (size_row al)) @|
as_seq h1 (gsub full (size_row al) (size_row al))));
let final = sub full (size 0) nn in
copy output final)
inline_for_extraction noextract
let blake2_update_key_st (al:Spec.alg) (ms:m_spec) =
wv:state_p al ms
-> hash: state_p al ms
-> kk: size_t{v kk > 0 /\ v kk <= Spec.max_key al}
-> k: lbuffer uint8 kk
-> ll: size_t ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h k /\
disjoint hash k /\ disjoint wv hash /\ disjoint wv k))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1
/\ state_v h1 hash == Spec.blake2_update_key al (v kk) h0.[|k|] (v ll) (state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_key:
#al:Spec.alg
-> #ms:m_spec
-> blake2_update_block_st al ms
-> blake2_update_key_st al ms
inline_for_extraction noextract
let blake2_update_key #al #ms blake2_update_block wv hash kk k ll =
let lb = size_to_limb al (size_block al) in
assert (v lb = Spec.size_block al);
let h0 = ST.get () in
salloc1 h0 (size_block al) (u8 0) (Ghost.hide (loc hash |+| loc wv))
(fun _ h1 -> live h1 hash /\ state_v h1 hash == Spec.blake2_update_key al (v kk) h0.[|k|] (v ll) (state_v h0 hash))
(fun key_block ->
update_sub key_block 0ul kk k;
let h1 = ST.get() in
if ll =. 0ul then
blake2_update_block wv hash true lb key_block
else
blake2_update_block wv hash false lb key_block)
inline_for_extraction noextract
let blake2_update_st (al:Spec.alg) (ms:m_spec) =
wv:state_p al ms
-> hash: state_p al ms
-> kk: size_t{v kk <= Spec.max_key al}
-> k: lbuffer uint8 kk
-> ll: size_t
-> d: lbuffer uint8 ll ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h k /\ live h d /\
disjoint hash k /\ disjoint wv hash /\ disjoint wv k /\
disjoint hash d /\ disjoint wv d /\ disjoint d k))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1
/\ state_v h1 hash == Spec.blake2_update al (v kk) h0.[|k|] h0.[|d|] (state_v h0 hash)))
inline_for_extraction noextract
val blake2_update:
#al:Spec.alg
-> #ms:m_spec
-> blake2_update_key_st al ms
-> blake2_update_blocks_st al ms
-> blake2_update_st al ms
inline_for_extraction noextract | false | false | Hacl.Impl.Blake2.Generic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val blake2_update:
#al:Spec.alg
-> #ms:m_spec
-> blake2_update_key_st al ms
-> blake2_update_blocks_st al ms
-> blake2_update_st al ms | [] | Hacl.Impl.Blake2.Generic.blake2_update | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
blake2_update_key: Hacl.Impl.Blake2.Generic.blake2_update_key_st al ms ->
blake2_update_blocks: Hacl.Impl.Blake2.Generic.blake2_update_blocks_st al ms
-> Hacl.Impl.Blake2.Generic.blake2_update_st al ms | {
"end_col": 61,
"end_line": 766,
"start_col": 37,
"start_line": 759
} |
FStar.HyperStack.ST.Stack | 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))) | [
{
"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
}
] | false | 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)) | 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 = | true | null | false | 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)) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Hacl.Impl.Blake2.Core.state_p",
"Hacl.Impl.Blake2.Core.index_t",
"Lib.Sequence.eq_intro",
"Spec.Blake2.row",
"Hacl.Impl.Blake2.Core.state_v",
"Spec.Blake2.g2z",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Impl.Blake2.Core.add_row",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Hacl.Impl.Blake2.Core.element_t",
"Hacl.Impl.Blake2.Core.row_len",
"Hacl.Impl.Blake2.Core.rowi",
"Hacl.Impl.Blake2.Core.row_p"
] | [] | 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))) | false | false | Hacl.Impl.Blake2.Generic.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | 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))) | [] | Hacl.Impl.Blake2.Generic.g2z | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
wv: Hacl.Impl.Blake2.Core.state_p al m ->
a: Hacl.Impl.Blake2.Core.index_t ->
b: Hacl.Impl.Blake2.Core.index_t
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 82,
"end_line": 145,
"start_col": 23,
"start_line": 139
} |
FStar.HyperStack.ST.Stack | 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)) | [
{
"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
}
] | false | 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) | 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 = | true | null | false | 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) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Hacl.Impl.Blake2.Core.state_p",
"Hacl.Impl.Blake2.Core.index_t",
"Lib.IntTypes.rotval",
"Spec.Blake2.wt",
"Lib.Sequence.eq_intro",
"Spec.Blake2.row",
"Hacl.Impl.Blake2.Core.state_v",
"Spec.Blake2.g1",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Impl.Blake2.Core.ror_row",
"Hacl.Impl.Blake2.Core.xor_row",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Hacl.Impl.Blake2.Core.element_t",
"Hacl.Impl.Blake2.Core.row_len",
"Hacl.Impl.Blake2.Core.rowi",
"Hacl.Impl.Blake2.Core.row_p"
] | [] | 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)) | false | false | Hacl.Impl.Blake2.Generic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | 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)) | [] | Hacl.Impl.Blake2.Generic.g1 | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
wv: Hacl.Impl.Blake2.Core.state_p al m ->
a: Hacl.Impl.Blake2.Core.index_t ->
b: Hacl.Impl.Blake2.Core.index_t ->
r: Lib.IntTypes.rotval (Spec.Blake2.wt al)
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 82,
"end_line": 111,
"start_col": 24,
"start_line": 104
} |
FStar.HyperStack.ST.Stack | 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))) | [
{
"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
}
] | false | 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 | 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 = | true | null | false | 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 | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Hacl.Impl.Blake2.Core.state_p",
"Hacl.Impl.Blake2.Core.permr_row",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Hacl.Impl.Blake2.Core.element_t",
"Hacl.Impl.Blake2.Core.row_len",
"Hacl.Impl.Blake2.Core.rowi",
"Hacl.Impl.Blake2.Core.row_p"
] | [] | 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 /\ | false | false | Hacl.Impl.Blake2.Generic.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | 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))) | [] | Hacl.Impl.Blake2.Generic.undiag | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | wv: Hacl.Impl.Blake2.Core.state_p a m -> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 18,
"end_line": 218,
"start_col": 21,
"start_line": 211
} |
FStar.HyperStack.ST.Stack | 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))) | [
{
"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
}
] | false | 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 | 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 = | true | null | false | 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 | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Hacl.Impl.Blake2.Core.state_p",
"Hacl.Impl.Blake2.Core.permr_row",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Hacl.Impl.Blake2.Core.element_t",
"Hacl.Impl.Blake2.Core.row_len",
"Hacl.Impl.Blake2.Core.rowi",
"Hacl.Impl.Blake2.Core.row_p"
] | [] | 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 /\ | false | false | Hacl.Impl.Blake2.Generic.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | 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))) | [] | Hacl.Impl.Blake2.Generic.diag | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | wv: Hacl.Impl.Blake2.Core.state_p a m -> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 18,
"end_line": 202,
"start_col": 19,
"start_line": 195
} |
Prims.Tot | val blake2_finish:#al:Spec.alg -> #ms:m_spec -> blake2_finish_st al ms | [
{
"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
}
] | false | let blake2_finish #al #ms nn output hash =
let h0 = ST.get () in
[@inline_let]
let double_row = 2ul *. size_row al in
[@inline_let]
let spec _ h1 = h1.[|output|] == Spec.blake2_finish al (state_v h0 hash) (v nn) in
salloc1 h0 double_row (u8 0) (Ghost.hide (loc output)) spec
(fun full ->
let first = sub full 0ul (size_row al) in
let second = sub full (size_row al) (size_row al) in
let row0 = rowi hash 0ul in
let row1 = rowi hash 1ul in
store_row first row0;
store_row second row1;
let h1 = ST.get() in
Lib.Sequence.eq_intro (as_seq h1 full)
(Lib.Sequence.(as_seq h1 (gsub full 0ul (size_row al)) @|
as_seq h1 (gsub full (size_row al) (size_row al))));
let final = sub full (size 0) nn in
copy output final) | val blake2_finish:#al:Spec.alg -> #ms:m_spec -> blake2_finish_st al ms
let blake2_finish #al #ms nn output hash = | false | null | false | let h0 = ST.get () in
[@@ inline_let ]let double_row = 2ul *. size_row al in
[@@ inline_let ]let spec _ h1 = h1.[| output |] == Spec.blake2_finish al (state_v h0 hash) (v nn) in
salloc1 h0
double_row
(u8 0)
(Ghost.hide (loc output))
spec
(fun full ->
let first = sub full 0ul (size_row al) in
let second = sub full (size_row al) (size_row al) in
let row0 = rowi hash 0ul in
let row1 = rowi hash 1ul in
store_row first row0;
store_row second row1;
let h1 = ST.get () in
Lib.Sequence.eq_intro (as_seq h1 full)
(let open Lib.Sequence in
as_seq h1 (gsub full 0ul (size_row al)) @|
as_seq h1 (gsub full (size_row al) (size_row al)));
let final = sub full (size 0) nn in
copy output final) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Spec.Blake2.max_output",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.Impl.Blake2.Core.state_p",
"Lib.Buffer.salloc1",
"Prims.unit",
"Lib.IntTypes.u8",
"FStar.Ghost.hide",
"LowStar.Monotonic.Buffer.loc",
"Lib.Buffer.loc",
"Lib.Buffer.MUT",
"Lib.Buffer.copy",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.Buffer.sub",
"Lib.IntTypes.size",
"Lib.Sequence.eq_intro",
"Lib.Buffer.as_seq",
"Lib.Sequence.op_At_Bar",
"Hacl.Impl.Blake2.Core.size_row",
"Lib.Buffer.gsub",
"FStar.UInt32.__uint_to_t",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Impl.Blake2.Core.store_row",
"Hacl.Impl.Blake2.Core.element_t",
"Hacl.Impl.Blake2.Core.row_len",
"Hacl.Impl.Blake2.Core.rowi",
"Hacl.Impl.Blake2.Core.row_p",
"Prims.logical",
"Prims.eq2",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint_t",
"Lib.Buffer.op_Brack_Lens_Access",
"Spec.Blake2.blake2_finish",
"Hacl.Impl.Blake2.Core.state_v",
"Lib.IntTypes.op_Star_Dot"
] | [] | 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 (v kk) (v nn)))
inline_for_extraction noextract
val blake2_init:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms
let blake2_init #al #ms hash kk nn =
let h0 = ST.get() 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 kk_shift_8 = shift_left (size_to_word al kk) (size 8) in
let iv0' = iv0 ^. (Spec.nat_to_word al 0x01010000) ^. kk_shift_8 ^. (size_to_word al nn) 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(modifies (loc hash) h0 h1);
Lib.Sequence.eq_intro (state_v h1 hash) (Spec.blake2_init_hash al (v kk) (v nn))
#push-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let _ : squash (inversion Spec.alg) = allow_inversion Spec.alg
inline_for_extraction noextract
val split_blocks: al:Spec.alg -> len:size_t -> r:(size_t & size_t){
let (x,y) = r in
let (sx,sy) = Spec.split al (v len) in
sx == v x /\
sy == v y}
let split_blocks al len =
let nb = len /. size_block al in
let rem = len %. size_block al in
if rem =. 0ul && nb >. 0ul then
let nb' = nb -! 1ul in
let rem' = size_block al in
(nb',rem')
else (nb,rem)
inline_for_extraction noextract
let blake2_update_multi_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}
-> blocks: lbuffer uint8 len
-> nb : size_t{length blocks >= v nb * v (size_block al) } ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h blocks /\
disjoint hash blocks /\ disjoint wv hash /\ disjoint wv blocks))
(ensures (fun h0 _ h1 ->
modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash == repeati (v nb) (Spec.blake2_update1 al (v prev) h0.[|blocks|])
(state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_multi (#al : Spec.alg) (#ms : m_spec) :
blake2_update_block:blake2_update_block_st al ms
-> blake2_update_multi_st al ms
let blake2_update_multi #al #ms blake2_update_block #len wv hash prev blocks nb =
let h0 = ST.get () in
[@inline_let]
let a_spec = Spec.state al in
[@inline_let]
let refl h = state_v h hash in
[@inline_let]
let footprint = Ghost.hide(loc hash |+| loc wv) in
[@inline_let]
let spec h = Spec.blake2_update1 al (v prev) h.[|blocks|] in
loop_refl h0 nb a_spec refl footprint spec
(fun i ->
Loops.unfold_repeati (v nb) (spec h0) (state_v h0 hash) (v i);
blake2_update1 #al #ms blake2_update_block #len wv hash prev blocks i)
inline_for_extraction noextract
let blake2_update_blocks_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}
-> blocks: lbuffer uint8 len ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h blocks /\ disjoint hash blocks /\ disjoint wv hash /\ disjoint wv blocks))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash ==
Spec.blake2_update_blocks al (v prev) h0.[|blocks|] (state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_blocks (#al : Spec.alg) (#ms : m_spec) :
blake2_update_multi_st al ms
-> blake2_update_last_st al ms
-> blake2_update_blocks_st al ms
let blake2_update_blocks #al #ms blake2_update_multi blake2_update_last #len wv hash prev blocks =
let (nb,rem) = split_blocks al len in
blake2_update_multi wv hash prev blocks nb;
blake2_update_last #len wv hash prev rem blocks
inline_for_extraction noextract
let blake2_finish_st (al:Spec.alg) (ms:m_spec) =
nn: size_t{1 <= v nn /\ v nn <= Spec.max_output al}
-> output: lbuffer uint8 nn
-> hash: state_p al ms ->
Stack unit
(requires (fun h -> live h hash /\ live h output /\ disjoint output hash))
(ensures (fun h0 _ h1 -> modifies (loc output) h0 h1
/\ h1.[|output|] == Spec.blake2_finish al (state_v h0 hash) (v nn)))
inline_for_extraction noextract
val blake2_finish:#al:Spec.alg -> #ms:m_spec -> blake2_finish_st al ms | false | false | Hacl.Impl.Blake2.Generic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val blake2_finish:#al:Spec.alg -> #ms:m_spec -> blake2_finish_st al ms | [] | Hacl.Impl.Blake2.Generic.blake2_finish | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Impl.Blake2.Generic.blake2_finish_st al ms | {
"end_col": 22,
"end_line": 695,
"start_col": 42,
"start_line": 676
} |
Prims.Tot | val blake2_update_multi (#al : Spec.alg) (#ms : m_spec) :
blake2_update_block:blake2_update_block_st al ms
-> blake2_update_multi_st al ms | [
{
"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
}
] | false | let blake2_update_multi #al #ms blake2_update_block #len wv hash prev blocks nb =
let h0 = ST.get () in
[@inline_let]
let a_spec = Spec.state al in
[@inline_let]
let refl h = state_v h hash in
[@inline_let]
let footprint = Ghost.hide(loc hash |+| loc wv) in
[@inline_let]
let spec h = Spec.blake2_update1 al (v prev) h.[|blocks|] in
loop_refl h0 nb a_spec refl footprint spec
(fun i ->
Loops.unfold_repeati (v nb) (spec h0) (state_v h0 hash) (v i);
blake2_update1 #al #ms blake2_update_block #len wv hash prev blocks i) | val blake2_update_multi (#al : Spec.alg) (#ms : m_spec) :
blake2_update_block:blake2_update_block_st al ms
-> blake2_update_multi_st al ms
let blake2_update_multi #al #ms blake2_update_block #len wv hash prev blocks nb = | false | null | false | let h0 = ST.get () in
[@@ inline_let ]let a_spec = Spec.state al in
[@@ inline_let ]let refl h = state_v h hash in
[@@ inline_let ]let footprint = Ghost.hide (loc hash |+| loc wv) in
[@@ inline_let ]let spec h = Spec.blake2_update1 al (v prev) h.[| blocks |] in
loop_refl h0
nb
a_spec
refl
footprint
spec
(fun i ->
Loops.unfold_repeati (v nb) (spec h0) (state_v h0 hash) (v i);
blake2_update1 #al #ms blake2_update_block #len wv hash prev blocks i) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Hacl.Impl.Blake2.Generic.blake2_update_block_st",
"Lib.IntTypes.size_t",
"Hacl.Impl.Blake2.Core.state_p",
"Spec.Blake2.limb_t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.v",
"Spec.Blake2.limb_inttype",
"Lib.IntTypes.SEC",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Spec.Blake2.max_limb",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Prims.op_GreaterThanOrEqual",
"Lib.Buffer.length",
"Lib.Buffer.MUT",
"FStar.Mul.op_Star",
"Hacl.Impl.Blake2.Core.size_block",
"Lib.Buffer.loop_refl",
"Prims.op_LessThan",
"Hacl.Impl.Blake2.Generic.blake2_update1",
"Prims.unit",
"Lib.LoopCombinators.unfold_repeati",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Spec.Blake2.wt",
"Hacl.Impl.Blake2.Core.state_v",
"FStar.Monotonic.HyperStack.mem",
"Prims.nat",
"Prims.l_and",
"Prims.op_Division",
"Lib.Sequence.length",
"Lib.IntTypes.U8",
"Lib.Buffer.op_Brack_Lens_Access",
"Spec.Blake2.size_block",
"Lib.IntTypes.U64",
"Lib.IntTypes.U128",
"Lib.IntTypes.inttype",
"Spec.Blake2.blake2_update1",
"FStar.Ghost.erased",
"LowStar.Monotonic.Buffer.loc",
"FStar.Ghost.hide",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.Buffer.loc",
"Hacl.Impl.Blake2.Core.element_t",
"Spec.Blake2.state",
"FStar.HyperStack.ST.get"
] | [] | 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 (v kk) (v nn)))
inline_for_extraction noextract
val blake2_init:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms
let blake2_init #al #ms hash kk nn =
let h0 = ST.get() 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 kk_shift_8 = shift_left (size_to_word al kk) (size 8) in
let iv0' = iv0 ^. (Spec.nat_to_word al 0x01010000) ^. kk_shift_8 ^. (size_to_word al nn) 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(modifies (loc hash) h0 h1);
Lib.Sequence.eq_intro (state_v h1 hash) (Spec.blake2_init_hash al (v kk) (v nn))
#push-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let _ : squash (inversion Spec.alg) = allow_inversion Spec.alg
inline_for_extraction noextract
val split_blocks: al:Spec.alg -> len:size_t -> r:(size_t & size_t){
let (x,y) = r in
let (sx,sy) = Spec.split al (v len) in
sx == v x /\
sy == v y}
let split_blocks al len =
let nb = len /. size_block al in
let rem = len %. size_block al in
if rem =. 0ul && nb >. 0ul then
let nb' = nb -! 1ul in
let rem' = size_block al in
(nb',rem')
else (nb,rem)
inline_for_extraction noextract
let blake2_update_multi_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}
-> blocks: lbuffer uint8 len
-> nb : size_t{length blocks >= v nb * v (size_block al) } ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h blocks /\
disjoint hash blocks /\ disjoint wv hash /\ disjoint wv blocks))
(ensures (fun h0 _ h1 ->
modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash == repeati (v nb) (Spec.blake2_update1 al (v prev) h0.[|blocks|])
(state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_multi (#al : Spec.alg) (#ms : m_spec) :
blake2_update_block:blake2_update_block_st al ms
-> blake2_update_multi_st al ms | false | false | Hacl.Impl.Blake2.Generic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val blake2_update_multi (#al : Spec.alg) (#ms : m_spec) :
blake2_update_block:blake2_update_block_st al ms
-> blake2_update_multi_st al ms | [] | Hacl.Impl.Blake2.Generic.blake2_update_multi | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | blake2_update_block: Hacl.Impl.Blake2.Generic.blake2_update_block_st al ms
-> Hacl.Impl.Blake2.Generic.blake2_update_multi_st al ms | {
"end_col": 74,
"end_line": 637,
"start_col": 81,
"start_line": 624
} |
Prims.Tot | val blake2_update_key:
#al:Spec.alg
-> #ms:m_spec
-> blake2_update_block_st al ms
-> blake2_update_key_st al ms | [
{
"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
}
] | false | let blake2_update_key #al #ms blake2_update_block wv hash kk k ll =
let lb = size_to_limb al (size_block al) in
assert (v lb = Spec.size_block al);
let h0 = ST.get () in
salloc1 h0 (size_block al) (u8 0) (Ghost.hide (loc hash |+| loc wv))
(fun _ h1 -> live h1 hash /\ state_v h1 hash == Spec.blake2_update_key al (v kk) h0.[|k|] (v ll) (state_v h0 hash))
(fun key_block ->
update_sub key_block 0ul kk k;
let h1 = ST.get() in
if ll =. 0ul then
blake2_update_block wv hash true lb key_block
else
blake2_update_block wv hash false lb key_block) | val blake2_update_key:
#al:Spec.alg
-> #ms:m_spec
-> blake2_update_block_st al ms
-> blake2_update_key_st al ms
let blake2_update_key #al #ms blake2_update_block wv hash kk k ll = | false | null | false | let lb = size_to_limb al (size_block al) in
assert (v lb = Spec.size_block al);
let h0 = ST.get () in
salloc1 h0
(size_block al)
(u8 0)
(Ghost.hide (loc hash |+| loc wv))
(fun _ h1 ->
live h1 hash /\
state_v h1 hash == Spec.blake2_update_key al (v kk) h0.[| k |] (v ll) (state_v h0 hash))
(fun key_block ->
update_sub key_block 0ul kk k;
let h1 = ST.get () in
if ll =. 0ul
then blake2_update_block wv hash true lb key_block
else blake2_update_block wv hash false lb key_block) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Hacl.Impl.Blake2.Generic.blake2_update_block_st",
"Hacl.Impl.Blake2.Core.state_p",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"Spec.Blake2.max_key",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Lib.Buffer.salloc1",
"Prims.unit",
"Hacl.Impl.Blake2.Core.size_block",
"Lib.IntTypes.u8",
"FStar.Ghost.hide",
"LowStar.Monotonic.Buffer.loc",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.Buffer.loc",
"Lib.Buffer.MUT",
"Hacl.Impl.Blake2.Core.element_t",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.live",
"Prims.eq2",
"Spec.Blake2.state",
"Hacl.Impl.Blake2.Core.state_v",
"Spec.Blake2.blake2_update_key",
"Lib.Buffer.op_Brack_Lens_Access",
"Lib.IntTypes.op_Equals_Dot",
"FStar.UInt32.__uint_to_t",
"Prims.bool",
"FStar.HyperStack.ST.get",
"Lib.Buffer.update_sub",
"Prims._assert",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Lib.IntTypes.range",
"Spec.Blake2.limb_inttype",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.max_size_t",
"Lib.IntTypes.SEC",
"Spec.Blake2.size_block",
"Spec.Blake2.limb_t",
"Spec.Blake2.nat_to_limb",
"Hacl.Impl.Blake2.Generic.size_to_limb"
] | [] | 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 (v kk) (v nn)))
inline_for_extraction noextract
val blake2_init:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms
let blake2_init #al #ms hash kk nn =
let h0 = ST.get() 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 kk_shift_8 = shift_left (size_to_word al kk) (size 8) in
let iv0' = iv0 ^. (Spec.nat_to_word al 0x01010000) ^. kk_shift_8 ^. (size_to_word al nn) 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(modifies (loc hash) h0 h1);
Lib.Sequence.eq_intro (state_v h1 hash) (Spec.blake2_init_hash al (v kk) (v nn))
#push-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let _ : squash (inversion Spec.alg) = allow_inversion Spec.alg
inline_for_extraction noextract
val split_blocks: al:Spec.alg -> len:size_t -> r:(size_t & size_t){
let (x,y) = r in
let (sx,sy) = Spec.split al (v len) in
sx == v x /\
sy == v y}
let split_blocks al len =
let nb = len /. size_block al in
let rem = len %. size_block al in
if rem =. 0ul && nb >. 0ul then
let nb' = nb -! 1ul in
let rem' = size_block al in
(nb',rem')
else (nb,rem)
inline_for_extraction noextract
let blake2_update_multi_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}
-> blocks: lbuffer uint8 len
-> nb : size_t{length blocks >= v nb * v (size_block al) } ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h blocks /\
disjoint hash blocks /\ disjoint wv hash /\ disjoint wv blocks))
(ensures (fun h0 _ h1 ->
modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash == repeati (v nb) (Spec.blake2_update1 al (v prev) h0.[|blocks|])
(state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_multi (#al : Spec.alg) (#ms : m_spec) :
blake2_update_block:blake2_update_block_st al ms
-> blake2_update_multi_st al ms
let blake2_update_multi #al #ms blake2_update_block #len wv hash prev blocks nb =
let h0 = ST.get () in
[@inline_let]
let a_spec = Spec.state al in
[@inline_let]
let refl h = state_v h hash in
[@inline_let]
let footprint = Ghost.hide(loc hash |+| loc wv) in
[@inline_let]
let spec h = Spec.blake2_update1 al (v prev) h.[|blocks|] in
loop_refl h0 nb a_spec refl footprint spec
(fun i ->
Loops.unfold_repeati (v nb) (spec h0) (state_v h0 hash) (v i);
blake2_update1 #al #ms blake2_update_block #len wv hash prev blocks i)
inline_for_extraction noextract
let blake2_update_blocks_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}
-> blocks: lbuffer uint8 len ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h blocks /\ disjoint hash blocks /\ disjoint wv hash /\ disjoint wv blocks))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash ==
Spec.blake2_update_blocks al (v prev) h0.[|blocks|] (state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_blocks (#al : Spec.alg) (#ms : m_spec) :
blake2_update_multi_st al ms
-> blake2_update_last_st al ms
-> blake2_update_blocks_st al ms
let blake2_update_blocks #al #ms blake2_update_multi blake2_update_last #len wv hash prev blocks =
let (nb,rem) = split_blocks al len in
blake2_update_multi wv hash prev blocks nb;
blake2_update_last #len wv hash prev rem blocks
inline_for_extraction noextract
let blake2_finish_st (al:Spec.alg) (ms:m_spec) =
nn: size_t{1 <= v nn /\ v nn <= Spec.max_output al}
-> output: lbuffer uint8 nn
-> hash: state_p al ms ->
Stack unit
(requires (fun h -> live h hash /\ live h output /\ disjoint output hash))
(ensures (fun h0 _ h1 -> modifies (loc output) h0 h1
/\ h1.[|output|] == Spec.blake2_finish al (state_v h0 hash) (v nn)))
inline_for_extraction noextract
val blake2_finish:#al:Spec.alg -> #ms:m_spec -> blake2_finish_st al ms
let blake2_finish #al #ms nn output hash =
let h0 = ST.get () in
[@inline_let]
let double_row = 2ul *. size_row al in
[@inline_let]
let spec _ h1 = h1.[|output|] == Spec.blake2_finish al (state_v h0 hash) (v nn) in
salloc1 h0 double_row (u8 0) (Ghost.hide (loc output)) spec
(fun full ->
let first = sub full 0ul (size_row al) in
let second = sub full (size_row al) (size_row al) in
let row0 = rowi hash 0ul in
let row1 = rowi hash 1ul in
store_row first row0;
store_row second row1;
let h1 = ST.get() in
Lib.Sequence.eq_intro (as_seq h1 full)
(Lib.Sequence.(as_seq h1 (gsub full 0ul (size_row al)) @|
as_seq h1 (gsub full (size_row al) (size_row al))));
let final = sub full (size 0) nn in
copy output final)
inline_for_extraction noextract
let blake2_update_key_st (al:Spec.alg) (ms:m_spec) =
wv:state_p al ms
-> hash: state_p al ms
-> kk: size_t{v kk > 0 /\ v kk <= Spec.max_key al}
-> k: lbuffer uint8 kk
-> ll: size_t ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h k /\
disjoint hash k /\ disjoint wv hash /\ disjoint wv k))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1
/\ state_v h1 hash == Spec.blake2_update_key al (v kk) h0.[|k|] (v ll) (state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_key:
#al:Spec.alg
-> #ms:m_spec
-> blake2_update_block_st al ms
-> blake2_update_key_st al ms | false | false | Hacl.Impl.Blake2.Generic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val blake2_update_key:
#al:Spec.alg
-> #ms:m_spec
-> blake2_update_block_st al ms
-> blake2_update_key_st al ms | [] | Hacl.Impl.Blake2.Generic.blake2_update_key | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | blake2_update_block: Hacl.Impl.Blake2.Generic.blake2_update_block_st al ms
-> Hacl.Impl.Blake2.Generic.blake2_update_key_st al ms | {
"end_col": 56,
"end_line": 731,
"start_col": 67,
"start_line": 719
} |
FStar.HyperStack.ST.Stack | 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))) | [
{
"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
}
] | false | 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)) | 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 = | true | null | false | 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)) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Hacl.Impl.Blake2.Core.state_p",
"Hacl.Impl.Blake2.Core.index_t",
"Hacl.Impl.Blake2.Core.row_p",
"Lib.Sequence.eq_intro",
"Spec.Blake2.row",
"Hacl.Impl.Blake2.Core.state_v",
"Spec.Blake2.g2",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Blake2.Core.row_v",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Impl.Blake2.Core.add_row",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Hacl.Impl.Blake2.Core.element_t",
"Hacl.Impl.Blake2.Core.row_len",
"Hacl.Impl.Blake2.Core.rowi"
] | [] | 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))) | false | false | Hacl.Impl.Blake2.Generic.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | 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))) | [] | Hacl.Impl.Blake2.Generic.g2 | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
wv: Hacl.Impl.Blake2.Core.state_p al m ->
a: Hacl.Impl.Blake2.Core.index_t ->
b: Hacl.Impl.Blake2.Core.index_t ->
x: Hacl.Impl.Blake2.Core.row_p al m
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 94,
"end_line": 129,
"start_col": 24,
"start_line": 122
} |
Prims.Tot | val blake2_compress: #al:Spec.alg -> #ms:m_spec -> compress_t al ms | [
{
"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
}
] | false | 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() | val blake2_compress: #al:Spec.alg -> #ms:m_spec -> compress_t al ms
let blake2_compress #al #ms wv s m offset flag = | false | null | false | 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 () | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Hacl.Impl.Blake2.Core.state_p",
"Hacl.Impl.Blake2.Core.block_p",
"Spec.Blake2.limb_t",
"Prims.bool",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Hacl.Impl.Blake2.Generic.blake2_compress3",
"Hacl.Impl.Blake2.Generic.blake2_compress2",
"Hacl.Impl.Blake2.Generic.blake2_compress1",
"Hacl.Impl.Blake2.Generic.blake2_compress0",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Hacl.Impl.Blake2.Core.word_t",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.create",
"FStar.UInt32.__uint_to_t",
"Spec.Blake2.zero",
"Lib.Buffer.lbuffer",
"FStar.HyperStack.ST.push_frame"
] | [] | 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 | false | false | Hacl.Impl.Blake2.Generic.fst | {
"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"
} | null | val blake2_compress: #al:Spec.alg -> #ms:m_spec -> compress_t al ms | [] | Hacl.Impl.Blake2.Generic.blake2_compress | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Impl.Blake2.Generic.compress_t al ms | {
"end_col": 13,
"end_line": 460,
"start_col": 2,
"start_line": 454
} |
Prims.Tot | val blake2_init:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms | [
{
"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
}
] | false | let blake2_init #al #ms hash kk nn =
let h0 = ST.get() 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 kk_shift_8 = shift_left (size_to_word al kk) (size 8) in
let iv0' = iv0 ^. (Spec.nat_to_word al 0x01010000) ^. kk_shift_8 ^. (size_to_word al nn) 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(modifies (loc hash) h0 h1);
Lib.Sequence.eq_intro (state_v h1 hash) (Spec.blake2_init_hash al (v kk) (v nn)) | val blake2_init:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms
let blake2_init #al #ms hash kk nn = | false | null | false | let h0 = ST.get () 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 kk_shift_8 = shift_left (size_to_word al kk) (size 8) in
let iv0' = iv0 ^. (Spec.nat_to_word al 0x01010000) ^. kk_shift_8 ^. (size_to_word al nn) 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 (modifies (loc hash) h0 h1);
Lib.Sequence.eq_intro (state_v h1 hash) (Spec.blake2_init_hash al (v kk) (v nn)) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.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.max_key",
"Prims.l_and",
"Spec.Blake2.max_output",
"Lib.Sequence.eq_intro",
"Spec.Blake2.row",
"Hacl.Impl.Blake2.Core.state_v",
"Spec.Blake2.blake2_init_hash",
"Prims.unit",
"Prims._assert",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Lib.Buffer.MUT",
"Hacl.Impl.Blake2.Core.element_t",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Impl.Blake2.Core.create_row",
"Lib.IntTypes.int_t",
"Spec.Blake2.wt",
"Lib.IntTypes.SEC",
"Lib.IntTypes.op_Hat_Dot",
"Spec.Blake2.nat_to_word",
"Hacl.Impl.Blake2.Generic.size_to_word",
"Lib.IntTypes.shift_left",
"Lib.IntTypes.size",
"Hacl.Impl.Blake2.Core.word_t",
"Hacl.Impl.Blake2.Generic.get_iv",
"FStar.UInt32.__uint_to_t",
"Lib.Buffer.lbuffer_t",
"Hacl.Impl.Blake2.Core.row_len",
"Hacl.Impl.Blake2.Core.rowi",
"Hacl.Impl.Blake2.Core.row_p"
] | [] | 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 (v kk) (v nn)))
inline_for_extraction noextract
val blake2_init:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms | false | false | Hacl.Impl.Blake2.Generic.fst | {
"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"
} | null | val blake2_init:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms | [] | Hacl.Impl.Blake2.Generic.blake2_init | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Impl.Blake2.Generic.blake2_init_st al ms | {
"end_col": 82,
"end_line": 582,
"start_col": 36,
"start_line": 560
} |
FStar.HyperStack.ST.Stack | 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))) | [
{
"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
}
] | false | 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)) | 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 = | true | null | false | 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)) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Hacl.Impl.Blake2.Core.state_p",
"Lib.Sequence.eq_intro",
"Spec.Blake2.row",
"Hacl.Impl.Blake2.Core.state_v",
"Spec.Blake2.blake2_compress3",
"Prims.unit",
"Lib.Sequence.op_String_Assignment",
"Hacl.Impl.Blake2.Core.row_v",
"Prims._assert",
"Prims.eq2",
"Spec.Blake2.op_Hat_Bar",
"Lib.Sequence.op_String_Access",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Lib.Buffer.MUT",
"Hacl.Impl.Blake2.Core.element_t",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Impl.Blake2.Core.xor_row",
"Lib.Buffer.disjoint",
"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"
] | [] | 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))) | false | false | Hacl.Impl.Blake2.Generic.fst | {
"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"
} | null | 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))) | [] | Hacl.Impl.Blake2.Generic.blake2_compress3 | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | s_iv: Hacl.Impl.Blake2.Core.state_p al ms -> wv: Hacl.Impl.Blake2.Core.state_p al ms
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 89,
"end_line": 433,
"start_col": 38,
"start_line": 401
} |
FStar.HyperStack.ST.Stack | 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))) | [
{
"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
}
] | false | 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)) | 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 = | true | null | false | 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)) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Hacl.Impl.Blake2.Core.state_p",
"Hacl.Impl.Blake2.Core.row_p",
"Lib.Sequence.eq_intro",
"Spec.Blake2.row",
"Hacl.Impl.Blake2.Core.state_v",
"Spec.Blake2.blake2_mixing",
"Hacl.Impl.Blake2.Core.row_v",
"Prims.unit",
"Prims._assert",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Lib.Buffer.MUT",
"Hacl.Impl.Blake2.Core.element_t",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"FStar.HyperStack.ST.pop_frame",
"Hacl.Impl.Blake2.Generic.g1",
"Hacl.Impl.Blake2.Generic.g2z",
"Hacl.Impl.Blake2.Generic.g2",
"FStar.Pervasives.normalize_term_spec",
"Lib.IntTypes.rotval",
"Spec.Blake2.wt",
"Prims.eq2",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Spec.Blake2.rTable",
"Lib.Sequence.index",
"FStar.Pervasives.normalize_term",
"FStar.UInt32.t",
"FStar.UInt32.__uint_to_t",
"FStar.HyperStack.ST.push_frame"
] | [] | 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))) | false | false | Hacl.Impl.Blake2.Generic.fst | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | 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))) | [] | Hacl.Impl.Blake2.Generic.blake2_mixing | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
wv: Hacl.Impl.Blake2.Core.state_p al m ->
x: Hacl.Impl.Blake2.Core.row_p al m ->
y: Hacl.Impl.Blake2.Core.row_p al m
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 105,
"end_line": 186,
"start_col": 33,
"start_line": 154
} |
Prims.Tot | val blake2_update1: #al:Spec.alg -> #ms:m_spec -> blake2_update_block: blake2_update_block_st al ms -> blake2_update1_st al ms | [
{
"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
}
] | false | 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 | 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 = | false | null | false | 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 | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Hacl.Impl.Blake2.Generic.blake2_update_block_st",
"Lib.IntTypes.size_t",
"Hacl.Impl.Blake2.Core.state_p",
"Spec.Blake2.limb_t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.v",
"Spec.Blake2.limb_inttype",
"Lib.IntTypes.SEC",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Spec.Blake2.max_limb",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Prims.op_LessThan",
"Prims.op_Division",
"Lib.Buffer.length",
"Lib.Buffer.MUT",
"Spec.Blake2.size_block",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Lib.Sequence.seq",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"Hacl.Impl.Blake2.Core.size_block",
"Lib.Buffer.as_seq",
"Spec.Blake2.get_blocki",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.Buffer.sub",
"Lib.IntTypes.op_Star_Dot",
"Prims.int",
"FStar.Mul.op_Star",
"Spec.Blake2.wt",
"Lib.IntTypes.U64",
"Lib.IntTypes.U128",
"Lib.IntTypes.op_Plus_Dot",
"Hacl.Impl.Blake2.Generic.size_to_limb",
"Lib.IntTypes.op_Star_Bang",
"Lib.IntTypes.op_Plus_Bang",
"FStar.UInt32.__uint_to_t"
] | [] | 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 | false | false | Hacl.Impl.Blake2.Generic.fst | {
"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"
} | null | val blake2_update1: #al:Spec.alg -> #ms:m_spec -> blake2_update_block: blake2_update_block_st al ms -> blake2_update1_st al ms | [] | Hacl.Impl.Blake2.Generic.blake2_update1 | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | blake2_update_block: Hacl.Impl.Blake2.Generic.blake2_update_block_st al ms
-> Hacl.Impl.Blake2.Generic.blake2_update1_st al ms | {
"end_col": 44,
"end_line": 502,
"start_col": 70,
"start_line": 496
} |
FStar.HyperStack.ST.Stack | 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)) | [
{
"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
}
] | false | 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) | 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 = | true | null | false | 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
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
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) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Hacl.Impl.Blake2.Core.state_p",
"Spec.Blake2.limb_t",
"Prims.bool",
"Lib.Sequence.eq_intro",
"Spec.Blake2.row",
"Hacl.Impl.Blake2.Core.state_v",
"Spec.Blake2.blake2_compress1",
"Prims.unit",
"Prims._assert",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Lib.Buffer.MUT",
"Hacl.Impl.Blake2.Core.element_t",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"FStar.HyperStack.ST.pop_frame",
"Hacl.Impl.Blake2.Core.xor_row",
"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.Core.copy_state",
"Hacl.Impl.Blake2.Core.create_row",
"Lib.IntTypes.int_t",
"Spec.Blake2.wt",
"Lib.IntTypes.SEC",
"Spec.Blake2.zero",
"Hacl.Impl.Blake2.Core.word_t",
"Lib.IntTypes.ones",
"Lib.IntTypes.inttype",
"FStar.Pervasives.normalize_term",
"FStar.Pervasives.normalize_term_spec",
"Prims.b2t",
"Lib.IntTypes.unsigned",
"Spec.Blake2.limb_to_word",
"Lib.IntTypes.op_Greater_Greater_Dot",
"Spec.Blake2.limb_inttype",
"Lib.IntTypes.size",
"Lib.IntTypes.bits",
"Hacl.Impl.Blake2.Core.alloc_row",
"FStar.HyperStack.ST.push_frame"
] | [] | 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)) | false | false | Hacl.Impl.Blake2.Generic.fst | {
"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"
} | null | 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)) | [] | Hacl.Impl.Blake2.Generic.blake2_compress1 | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
wv: Hacl.Impl.Blake2.Core.state_p al m ->
s_iv: Hacl.Impl.Blake2.Core.state_p al m ->
offset: Spec.Blake2.limb_t al ->
flag: Prims.bool
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 96,
"end_line": 360,
"start_col": 49,
"start_line": 332
} |
Prims.Tot | val blake2:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms
-> blake2_update_st al ms
-> blake2_finish_st al ms
-> blake2_st al ms | [
{
"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
}
] | false | let blake2 #al #ms blake2_init blake2_update blake2_finish nn output ll d kk k =
[@inline_let]
let stlen = le_sigh al ms in
[@inline_let]
let stzero = zero_element al ms in
let h0 = ST.get() in
[@inline_let]
let spec _ h1 = h1.[|output|] == Spec.blake2 al h0.[|d|] (v kk) h0.[|k|] (v nn) in
salloc1 h0 stlen stzero (Ghost.hide (loc output)) spec
(fun h ->
assert (max_size_t <= Spec.max_limb al);
let h1 = ST.get() in
salloc1 h1 stlen stzero (Ghost.hide (loc output |+| loc h)) spec
(fun wv ->
blake2_init h kk nn;
blake2_update wv h kk k ll d;
blake2_finish nn output h)) | val blake2:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms
-> blake2_update_st al ms
-> blake2_finish_st al ms
-> blake2_st al ms
let blake2 #al #ms blake2_init blake2_update blake2_finish nn output ll d kk k = | false | null | false | [@@ inline_let ]let stlen = le_sigh al ms in
[@@ inline_let ]let stzero = zero_element al ms in
let h0 = ST.get () in
[@@ inline_let ]let spec _ h1 =
h1.[| output |] == Spec.blake2 al h0.[| d |] (v kk) h0.[| k |] (v nn)
in
salloc1 h0
stlen
stzero
(Ghost.hide (loc output))
spec
(fun h ->
assert (max_size_t <= Spec.max_limb al);
let h1 = ST.get () in
salloc1 h1
stlen
stzero
(Ghost.hide (loc output |+| loc h))
spec
(fun wv ->
blake2_init h kk nn;
blake2_update wv h kk k ll d;
blake2_finish nn output h)) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Hacl.Impl.Blake2.Generic.blake2_init_st",
"Hacl.Impl.Blake2.Generic.blake2_update_st",
"Hacl.Impl.Blake2.Generic.blake2_finish_st",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Spec.Blake2.max_output",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Spec.Blake2.max_key",
"Lib.Buffer.salloc1",
"Hacl.Impl.Blake2.Core.element_t",
"Prims.unit",
"FStar.Ghost.hide",
"LowStar.Monotonic.Buffer.loc",
"Lib.Buffer.loc",
"Lib.Buffer.MUT",
"Lib.Buffer.op_Bar_Plus_Bar",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Prims._assert",
"Lib.IntTypes.max_size_t",
"Spec.Blake2.max_limb",
"Prims.logical",
"Prims.eq2",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.Buffer.op_Brack_Lens_Access",
"Spec.Blake2.blake2",
"Hacl.Impl.Blake2.Core.zero_element",
"Lib.IntTypes.int_t",
"Lib.IntTypes.mul_mod",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Hacl.Impl.Blake2.Core.row_len",
"Hacl.Impl.Blake2.Core.le_sigh"
] | [] | 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 (v kk) (v nn)))
inline_for_extraction noextract
val blake2_init:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms
let blake2_init #al #ms hash kk nn =
let h0 = ST.get() 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 kk_shift_8 = shift_left (size_to_word al kk) (size 8) in
let iv0' = iv0 ^. (Spec.nat_to_word al 0x01010000) ^. kk_shift_8 ^. (size_to_word al nn) 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(modifies (loc hash) h0 h1);
Lib.Sequence.eq_intro (state_v h1 hash) (Spec.blake2_init_hash al (v kk) (v nn))
#push-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0"
let _ : squash (inversion Spec.alg) = allow_inversion Spec.alg
inline_for_extraction noextract
val split_blocks: al:Spec.alg -> len:size_t -> r:(size_t & size_t){
let (x,y) = r in
let (sx,sy) = Spec.split al (v len) in
sx == v x /\
sy == v y}
let split_blocks al len =
let nb = len /. size_block al in
let rem = len %. size_block al in
if rem =. 0ul && nb >. 0ul then
let nb' = nb -! 1ul in
let rem' = size_block al in
(nb',rem')
else (nb,rem)
inline_for_extraction noextract
let blake2_update_multi_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}
-> blocks: lbuffer uint8 len
-> nb : size_t{length blocks >= v nb * v (size_block al) } ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h blocks /\
disjoint hash blocks /\ disjoint wv hash /\ disjoint wv blocks))
(ensures (fun h0 _ h1 ->
modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash == repeati (v nb) (Spec.blake2_update1 al (v prev) h0.[|blocks|])
(state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_multi (#al : Spec.alg) (#ms : m_spec) :
blake2_update_block:blake2_update_block_st al ms
-> blake2_update_multi_st al ms
let blake2_update_multi #al #ms blake2_update_block #len wv hash prev blocks nb =
let h0 = ST.get () in
[@inline_let]
let a_spec = Spec.state al in
[@inline_let]
let refl h = state_v h hash in
[@inline_let]
let footprint = Ghost.hide(loc hash |+| loc wv) in
[@inline_let]
let spec h = Spec.blake2_update1 al (v prev) h.[|blocks|] in
loop_refl h0 nb a_spec refl footprint spec
(fun i ->
Loops.unfold_repeati (v nb) (spec h0) (state_v h0 hash) (v i);
blake2_update1 #al #ms blake2_update_block #len wv hash prev blocks i)
inline_for_extraction noextract
let blake2_update_blocks_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}
-> blocks: lbuffer uint8 len ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h blocks /\ disjoint hash blocks /\ disjoint wv hash /\ disjoint wv blocks))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1 /\
state_v h1 hash ==
Spec.blake2_update_blocks al (v prev) h0.[|blocks|] (state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_blocks (#al : Spec.alg) (#ms : m_spec) :
blake2_update_multi_st al ms
-> blake2_update_last_st al ms
-> blake2_update_blocks_st al ms
let blake2_update_blocks #al #ms blake2_update_multi blake2_update_last #len wv hash prev blocks =
let (nb,rem) = split_blocks al len in
blake2_update_multi wv hash prev blocks nb;
blake2_update_last #len wv hash prev rem blocks
inline_for_extraction noextract
let blake2_finish_st (al:Spec.alg) (ms:m_spec) =
nn: size_t{1 <= v nn /\ v nn <= Spec.max_output al}
-> output: lbuffer uint8 nn
-> hash: state_p al ms ->
Stack unit
(requires (fun h -> live h hash /\ live h output /\ disjoint output hash))
(ensures (fun h0 _ h1 -> modifies (loc output) h0 h1
/\ h1.[|output|] == Spec.blake2_finish al (state_v h0 hash) (v nn)))
inline_for_extraction noextract
val blake2_finish:#al:Spec.alg -> #ms:m_spec -> blake2_finish_st al ms
let blake2_finish #al #ms nn output hash =
let h0 = ST.get () in
[@inline_let]
let double_row = 2ul *. size_row al in
[@inline_let]
let spec _ h1 = h1.[|output|] == Spec.blake2_finish al (state_v h0 hash) (v nn) in
salloc1 h0 double_row (u8 0) (Ghost.hide (loc output)) spec
(fun full ->
let first = sub full 0ul (size_row al) in
let second = sub full (size_row al) (size_row al) in
let row0 = rowi hash 0ul in
let row1 = rowi hash 1ul in
store_row first row0;
store_row second row1;
let h1 = ST.get() in
Lib.Sequence.eq_intro (as_seq h1 full)
(Lib.Sequence.(as_seq h1 (gsub full 0ul (size_row al)) @|
as_seq h1 (gsub full (size_row al) (size_row al))));
let final = sub full (size 0) nn in
copy output final)
inline_for_extraction noextract
let blake2_update_key_st (al:Spec.alg) (ms:m_spec) =
wv:state_p al ms
-> hash: state_p al ms
-> kk: size_t{v kk > 0 /\ v kk <= Spec.max_key al}
-> k: lbuffer uint8 kk
-> ll: size_t ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h k /\
disjoint hash k /\ disjoint wv hash /\ disjoint wv k))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1
/\ state_v h1 hash == Spec.blake2_update_key al (v kk) h0.[|k|] (v ll) (state_v h0 hash)))
inline_for_extraction noextract
val blake2_update_key:
#al:Spec.alg
-> #ms:m_spec
-> blake2_update_block_st al ms
-> blake2_update_key_st al ms
inline_for_extraction noextract
let blake2_update_key #al #ms blake2_update_block wv hash kk k ll =
let lb = size_to_limb al (size_block al) in
assert (v lb = Spec.size_block al);
let h0 = ST.get () in
salloc1 h0 (size_block al) (u8 0) (Ghost.hide (loc hash |+| loc wv))
(fun _ h1 -> live h1 hash /\ state_v h1 hash == Spec.blake2_update_key al (v kk) h0.[|k|] (v ll) (state_v h0 hash))
(fun key_block ->
update_sub key_block 0ul kk k;
let h1 = ST.get() in
if ll =. 0ul then
blake2_update_block wv hash true lb key_block
else
blake2_update_block wv hash false lb key_block)
inline_for_extraction noextract
let blake2_update_st (al:Spec.alg) (ms:m_spec) =
wv:state_p al ms
-> hash: state_p al ms
-> kk: size_t{v kk <= Spec.max_key al}
-> k: lbuffer uint8 kk
-> ll: size_t
-> d: lbuffer uint8 ll ->
Stack unit
(requires (fun h -> live h wv /\ live h hash /\ live h k /\ live h d /\
disjoint hash k /\ disjoint wv hash /\ disjoint wv k /\
disjoint hash d /\ disjoint wv d /\ disjoint d k))
(ensures (fun h0 _ h1 -> modifies (loc hash |+| loc wv) h0 h1
/\ state_v h1 hash == Spec.blake2_update al (v kk) h0.[|k|] h0.[|d|] (state_v h0 hash)))
inline_for_extraction noextract
val blake2_update:
#al:Spec.alg
-> #ms:m_spec
-> blake2_update_key_st al ms
-> blake2_update_blocks_st al ms
-> blake2_update_st al ms
inline_for_extraction noextract
let blake2_update #al #ms blake2_update_key blake2_update_blocks
wv hash kk k ll d =
let lb = size_to_limb al (size_block al) in
assert (v lb = Spec.size_block al);
if kk >. 0ul then (
blake2_update_key wv hash kk k ll;
if ll =. 0ul then ()
else blake2_update_blocks wv hash lb d)
else blake2_update_blocks wv hash (size_to_limb al 0ul) d
inline_for_extraction noextract
let blake2_st (al:Spec.alg) (ms:m_spec) =
nn:size_t{1 <= v nn /\ v nn <= Spec.max_output al}
-> output: lbuffer uint8 nn
-> ll: size_t
-> d: lbuffer uint8 ll
-> kk: size_t{v kk <= Spec.max_key al}
-> k: lbuffer uint8 kk ->
Stack unit
(requires (fun h -> live h output /\ live h d /\ live h k
/\ disjoint output d /\ disjoint output k /\ disjoint d k))
(ensures (fun h0 _ h1 -> modifies1 output h0 h1
/\ h1.[|output|] == Spec.blake2 al h0.[|d|] (v kk) h0.[|k|] (v nn)))
inline_for_extraction noextract
val blake2:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms
-> blake2_update_st al ms
-> blake2_finish_st al ms
-> blake2_st al ms
#push-options "--z3rlimit 100" | false | false | Hacl.Impl.Blake2.Generic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val blake2:
#al:Spec.alg
-> #ms:m_spec
-> blake2_init_st al ms
-> blake2_update_st al ms
-> blake2_finish_st al ms
-> blake2_st al ms | [] | Hacl.Impl.Blake2.Generic.blake2 | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
blake2_init: Hacl.Impl.Blake2.Generic.blake2_init_st al ms ->
blake2_update: Hacl.Impl.Blake2.Generic.blake2_update_st al ms ->
blake2_finish: Hacl.Impl.Blake2.Generic.blake2_finish_st al ms
-> Hacl.Impl.Blake2.Generic.blake2_st al ms | {
"end_col": 33,
"end_line": 809,
"start_col": 2,
"start_line": 794
} |
Prims.Tot | 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 | [
{
"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
}
] | false | 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))) | 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 = | false | null | false | 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))) | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [
"total"
] | [
"Spec.Blake2.alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Hacl.Impl.Blake2.Generic.blake2_update_block_st",
"Lib.IntTypes.size_t",
"Hacl.Impl.Blake2.Core.state_p",
"Spec.Blake2.limb_t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.v",
"Spec.Blake2.limb_inttype",
"Lib.IntTypes.SEC",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Spec.Blake2.max_limb",
"Prims.l_and",
"Spec.Blake2.size_block",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Lib.Buffer.salloc1",
"Prims.unit",
"Hacl.Impl.Blake2.Core.size_block",
"Lib.IntTypes.u8",
"FStar.Ghost.hide",
"LowStar.Monotonic.Buffer.loc",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.Buffer.loc",
"Lib.Buffer.MUT",
"Hacl.Impl.Blake2.Core.element_t",
"Prims._assert",
"Prims.eq2",
"Spec.Blake2.state",
"Hacl.Impl.Blake2.Core.state_v",
"Spec.Blake2.blake2_update_block",
"Lib.Buffer.as_seq",
"Prims.int",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Lib.IntTypes.int_t",
"Spec.Blake2.wt",
"Lib.IntTypes.U64",
"Lib.IntTypes.U128",
"Lib.IntTypes.op_Plus_Dot",
"Hacl.Impl.Blake2.Generic.size_to_limb",
"Lib.Sequence.seq",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"Spec.Blake2.get_last_padded_block",
"Prims.op_Subtraction",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.slice",
"Prims.l_Forall",
"Prims.op_LessThan",
"FStar.Seq.Base.index",
"Lib.Sequence.index",
"Lib.Sequence.slice",
"Lib.Sequence.lseq",
"Lib.Sequence.sub",
"Lib.Buffer.as_seq_gsub",
"Lib.IntTypes.op_Subtraction_Bang",
"Lib.Buffer.update_sub",
"FStar.UInt32.__uint_to_t",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.U8",
"Lib.Buffer.sub",
"Prims.logical",
"Spec.Blake2.blake2_update_last",
"Lib.Buffer.op_Brack_Lens_Access"
] | [] | 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 | false | false | Hacl.Impl.Blake2.Generic.fst | {
"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"
} | null | 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 | [] | Hacl.Impl.Blake2.Generic.blake2_update_last | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | blake2_update_block: Hacl.Impl.Blake2.Generic.blake2_update_block_st al ms
-> Hacl.Impl.Blake2.Generic.blake2_update_last_st al ms | {
"end_col": 117,
"end_line": 542,
"start_col": 76,
"start_line": 524
} |
FStar.HyperStack.ST.Stack | 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))) | [
{
"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
}
] | 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 () | 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 = | true | null | false | 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 () | {
"checked_file": "Hacl.Impl.Blake2.Generic.fst.checked",
"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.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.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Generic.fst"
} | [] | [
"Spec.Blake2.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"
] | [] | 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))) | false | false | Hacl.Impl.Blake2.Generic.fst | {
"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"
} | null | 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))) | [] | Hacl.Impl.Blake2.Generic.blake2_round | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Generic.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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 | {
"end_col": 14,
"end_line": 304,
"start_col": 2,
"start_line": 279
} |
Prims.GTot | val unconstrained_bounded_integer (sz: integer_size) (i: bounded_integer sz) : GTot bool | [
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let unconstrained_bounded_integer
(sz: integer_size)
(i: bounded_integer sz)
: GTot bool
= true | val unconstrained_bounded_integer (sz: integer_size) (i: bounded_integer sz) : GTot bool
let unconstrained_bounded_integer (sz: integer_size) (i: bounded_integer sz) : GTot bool = | false | null | false | true | {
"checked_file": "LowParse.Spec.VLData.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLData.fsti"
} | [
"sometrivial"
] | [
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.BoundedInt.bounded_integer",
"Prims.bool"
] | [] | module LowParse.Spec.VLData
include LowParse.Spec.FLData
include LowParse.Spec.AllIntegers // for bounded_integer, in_bounds, etc.
module Seq = FStar.Seq
module U32 = FStar.UInt32
module M = LowParse.Math
#reset-options "--z3rlimit 64 --max_fuel 64 --max_ifuel 64 --z3refresh --z3cliopt smt.arith.nl=false"
let parse_vldata_payload_size
(sz: integer_size)
: Pure nat
(requires True)
(ensures (fun y -> y == pow2 (FStar.Mul.op_Star 8 sz) - 1 ))
= match sz with
| 1 -> 255
| 2 -> 65535
| 3 -> 16777215
| 4 -> 4294967295
#reset-options
// unfold
let parse_vldata_payload_kind
(sz: integer_size)
(k: parser_kind)
: parser_kind
= strong_parser_kind 0 (parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_payload
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(i: bounded_integer sz { f i == true } )
: Tot (parser (parse_vldata_payload_kind sz k) t)
= weaken (parse_vldata_payload_kind sz k) (parse_fldata p (U32.v i))
#set-options "--z3rlimit 64"
let parse_fldata_and_then_cases_injective
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p))
= parser_kind_prop_equiv k p;
let g
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1 b2: bytes)
: Lemma
(requires (and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2))
(ensures (len1 == len2))
= assert (injective_precond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (injective_postcond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (len1 == len2)
in
let g'
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1: bytes)
: Lemma
(forall (b2: bytes) . and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2 ==> len1 == len2)
= Classical.forall_intro (Classical.move_requires (g len1 len2 b1))
in
Classical.forall_intro_3 g'
#reset-options
// unfold
let parse_vldata_gen_kind
(sz: integer_size)
(k: parser_kind)
: Tot parser_kind
= strong_parser_kind sz (sz + parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_gen_kind_correct
(sz: integer_size)
(k: parser_kind)
: Lemma
( (parse_vldata_gen_kind sz k) == (and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k)))
= let kl = parse_vldata_gen_kind sz k in
let kr = and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) in
assert_norm (kl == kr)
val parse_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_vldata_gen_kind sz k) t)
val parse_vldata_gen_eq_def
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p) /\
parse_vldata_gen_kind sz k == and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) /\
parse_vldata_gen sz f p ==
and_then
#_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t
(parse_vldata_payload sz f p))
let parse_vldata_gen_eq
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(let res = parse (parse_vldata_gen sz f p) input in
match parse (parse_bounded_integer sz) input with
| None -> res == None
| Some (len, consumed_len) ->
consumed_len == sz /\ (
if f len
then begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
else res == None
))
= parse_vldata_gen_eq_def sz f p;
and_then_eq #_ #(parse_filter_refine f) (parse_filter (parse_bounded_integer sz) f) #_ #t (parse_vldata_payload sz f p) input;
parse_filter_eq #_ #(bounded_integer sz) (parse_bounded_integer sz) f input;
parser_kind_prop_equiv (parse_bounded_integer_kind sz) (parse_bounded_integer sz);
()
let parse_vldata_gen_eq_some_elim
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(requires (Some? (parse (parse_vldata_gen sz f p) input)))
(ensures (
let pbi = parse (parse_bounded_integer sz) input in
Some? pbi /\ (
let Some (len, consumed_len) = pbi in
consumed_len == sz /\
f len /\
Seq.length input >= sz + U32.v len /\ (
let input' = Seq.slice input sz (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let Some (x, consumed_x) = pp in
consumed_x = U32.v len /\
parse (parse_vldata_gen sz f p) input == Some (x, sz + U32.v len)
)))))
= parse_vldata_gen_eq sz f p input
let unconstrained_bounded_integer
(sz: integer_size)
(i: bounded_integer sz) | false | false | LowParse.Spec.VLData.fsti | {
"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"
} | null | val unconstrained_bounded_integer (sz: integer_size) (i: bounded_integer sz) : GTot bool | [] | LowParse.Spec.VLData.unconstrained_bounded_integer | {
"file_name": "src/lowparse/LowParse.Spec.VLData.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | sz: LowParse.Spec.BoundedInt.integer_size -> i: LowParse.Spec.BoundedInt.bounded_integer sz
-> Prims.GTot Prims.bool | {
"end_col": 6,
"end_line": 186,
"start_col": 2,
"start_line": 186
} |
Prims.GTot | val parse_bounded_vldata_strong_pred
(min max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: GTot Type0 | [
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_bounded_vldata_strong_pred
(min: nat)
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: GTot Type0
= let reslen = Seq.length (s x) in
min <= reslen /\ reslen <= max | val parse_bounded_vldata_strong_pred
(min max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: GTot Type0
let parse_bounded_vldata_strong_pred
(min max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: GTot Type0 = | false | null | false | let reslen = Seq.length (s x) in
min <= reslen /\ reslen <= max | {
"checked_file": "LowParse.Spec.VLData.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLData.fsti"
} | [
"sometrivial"
] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte"
] | [] | module LowParse.Spec.VLData
include LowParse.Spec.FLData
include LowParse.Spec.AllIntegers // for bounded_integer, in_bounds, etc.
module Seq = FStar.Seq
module U32 = FStar.UInt32
module M = LowParse.Math
#reset-options "--z3rlimit 64 --max_fuel 64 --max_ifuel 64 --z3refresh --z3cliopt smt.arith.nl=false"
let parse_vldata_payload_size
(sz: integer_size)
: Pure nat
(requires True)
(ensures (fun y -> y == pow2 (FStar.Mul.op_Star 8 sz) - 1 ))
= match sz with
| 1 -> 255
| 2 -> 65535
| 3 -> 16777215
| 4 -> 4294967295
#reset-options
// unfold
let parse_vldata_payload_kind
(sz: integer_size)
(k: parser_kind)
: parser_kind
= strong_parser_kind 0 (parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_payload
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(i: bounded_integer sz { f i == true } )
: Tot (parser (parse_vldata_payload_kind sz k) t)
= weaken (parse_vldata_payload_kind sz k) (parse_fldata p (U32.v i))
#set-options "--z3rlimit 64"
let parse_fldata_and_then_cases_injective
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p))
= parser_kind_prop_equiv k p;
let g
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1 b2: bytes)
: Lemma
(requires (and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2))
(ensures (len1 == len2))
= assert (injective_precond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (injective_postcond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (len1 == len2)
in
let g'
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1: bytes)
: Lemma
(forall (b2: bytes) . and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2 ==> len1 == len2)
= Classical.forall_intro (Classical.move_requires (g len1 len2 b1))
in
Classical.forall_intro_3 g'
#reset-options
// unfold
let parse_vldata_gen_kind
(sz: integer_size)
(k: parser_kind)
: Tot parser_kind
= strong_parser_kind sz (sz + parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_gen_kind_correct
(sz: integer_size)
(k: parser_kind)
: Lemma
( (parse_vldata_gen_kind sz k) == (and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k)))
= let kl = parse_vldata_gen_kind sz k in
let kr = and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) in
assert_norm (kl == kr)
val parse_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_vldata_gen_kind sz k) t)
val parse_vldata_gen_eq_def
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p) /\
parse_vldata_gen_kind sz k == and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) /\
parse_vldata_gen sz f p ==
and_then
#_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t
(parse_vldata_payload sz f p))
let parse_vldata_gen_eq
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(let res = parse (parse_vldata_gen sz f p) input in
match parse (parse_bounded_integer sz) input with
| None -> res == None
| Some (len, consumed_len) ->
consumed_len == sz /\ (
if f len
then begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
else res == None
))
= parse_vldata_gen_eq_def sz f p;
and_then_eq #_ #(parse_filter_refine f) (parse_filter (parse_bounded_integer sz) f) #_ #t (parse_vldata_payload sz f p) input;
parse_filter_eq #_ #(bounded_integer sz) (parse_bounded_integer sz) f input;
parser_kind_prop_equiv (parse_bounded_integer_kind sz) (parse_bounded_integer sz);
()
let parse_vldata_gen_eq_some_elim
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(requires (Some? (parse (parse_vldata_gen sz f p) input)))
(ensures (
let pbi = parse (parse_bounded_integer sz) input in
Some? pbi /\ (
let Some (len, consumed_len) = pbi in
consumed_len == sz /\
f len /\
Seq.length input >= sz + U32.v len /\ (
let input' = Seq.slice input sz (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let Some (x, consumed_x) = pp in
consumed_x = U32.v len /\
parse (parse_vldata_gen sz f p) input == Some (x, sz + U32.v len)
)))))
= parse_vldata_gen_eq sz f p input
let unconstrained_bounded_integer
(sz: integer_size)
(i: bounded_integer sz)
: GTot bool
= true
let parse_vldata
(sz: integer_size)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser _ t)
= parse_vldata_gen sz (unconstrained_bounded_integer sz) p
let parse_vldata_eq
(sz: integer_size)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(parse (parse_vldata sz p) input == (match parse (parse_bounded_integer sz) input with
| None -> None
| Some (len, _) ->
begin
if Seq.length input < sz + U32.v len
then None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then Some (x, sz + U32.v len)
else None
| _ -> None
end
))
= parse_vldata_gen_eq sz (unconstrained_bounded_integer _) p input
(** Explicit bounds on size *)
#reset-options
inline_for_extraction
let parse_bounded_vldata_strong_kind
(min: nat)
(max: nat)
(l: nat)
(k: parser_kind)
: Pure parser_kind
(requires (min <= max /\ max > 0 /\ max < 4294967296 /\ l >= log256' max /\ l <= 4 ))
(ensures (fun _ -> True))
= [@inline_let]
let kmin = k.parser_kind_low in
[@inline_let]
let min' = if kmin > min then kmin else min in
[@inline_let]
let max' = match k.parser_kind_high with
| None -> max
| Some kmax -> if kmax < max then kmax else max
in
[@inline_let]
let max' = if max' < min' then min' else max' in
(* the size of the length prefix must conform to the max bound given by the user, not on the metadata *)
strong_parser_kind (l + min') (l + max') (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_bounded_vldata_elim'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(xbytes: bytes)
(x: t)
(consumed: consumed_length xbytes)
: Lemma
(requires (parse (parse_vldata_gen l (in_bounds min max) p) xbytes == Some (x, consumed)))
(ensures (
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
Some? plen /\ (
let (Some (len, consumed_len)) = plen in
(consumed_len <: nat) == (sz <: nat) /\
in_bounds min max len /\
U32.v len <= Seq.length xbytes - sz /\ (
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let (Some (x', consumed_p)) = pp in
x' == x /\
(consumed_p <: nat) == U32.v len /\
(consumed <: nat) == sz + U32.v len
)))))
= parse_vldata_gen_eq l (in_bounds min max) p xbytes;
parser_kind_prop_equiv (parse_bounded_integer_kind l) (parse_bounded_integer l)
let parse_bounded_vldata_correct
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(parser_kind_prop (parse_bounded_vldata_strong_kind min max l k) (parse_vldata_gen l (in_bounds min max) p))
= parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l k) (parse_vldata_gen l (in_bounds min max) p);
let sz : integer_size = l in
let p' = parse_vldata_gen sz (in_bounds min max) p in
parser_kind_prop_equiv (get_parser_kind p') p';
parser_kind_prop_equiv k p;
let k' = parse_bounded_vldata_strong_kind min max l k in
let prf
(input: bytes)
: Lemma
(requires (Some? (parse p' input)))
(ensures (
let pi = parse p' input in
Some? pi /\ (
let (Some (_, consumed)) = pi in
k'.parser_kind_low <= (consumed <: nat) /\
(consumed <: nat) <= Some?.v k'.parser_kind_high
)))
= let (Some (data, consumed)) = parse p' input in
parse_bounded_vldata_elim' min max l p input data consumed
in
Classical.forall_intro (Classical.move_requires prf)
let parse_bounded_vldata'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_bounded_vldata_strong_kind min max l k) t)
= parse_bounded_vldata_correct min max l p;
strengthen (parse_bounded_vldata_strong_kind min max l k) (parse_vldata_gen l (in_bounds min max) p)
let parse_bounded_vldata
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_bounded_vldata_strong_kind min max (log256' max) k) t)
= parse_bounded_vldata' min max (log256' max) p
let parse_bounded_vldata_elim
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(xbytes: bytes)
(x: t)
(consumed: consumed_length xbytes)
: Lemma
(requires (parse (parse_bounded_vldata' min max l p) xbytes == Some (x, consumed)))
(ensures (
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
Some? plen /\ (
let (Some (len, consumed_len)) = plen in
(consumed_len <: nat) == (sz <: nat) /\
in_bounds min max len /\
U32.v len <= Seq.length xbytes - sz /\ (
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let (Some (x', consumed_p)) = pp in
x' == x /\
(consumed_p <: nat) == U32.v len /\
(consumed <: nat) == sz + U32.v len
)))))
= parse_bounded_vldata_elim' min max l p xbytes x consumed
let parse_bounded_vldata_elim_forall
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(xbytes: bytes)
: Lemma
(requires (Some? (parse (parse_bounded_vldata' min max l p) xbytes)))
(ensures (
let (Some (x, consumed)) = parse (parse_bounded_vldata' min max l p) xbytes in
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
Some? plen /\ (
let (Some (len, consumed_len)) = plen in
(consumed_len <: nat) == (sz <: nat) /\
in_bounds min max len /\
U32.v len <= Seq.length xbytes - sz /\ (
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let (Some (x', consumed_p)) = pp in
x' == x /\
(consumed_p <: nat) == U32.v len /\
(consumed <: nat) == sz + U32.v len
)))))
= let (Some (x, consumed)) = parse (parse_bounded_vldata' min max l p) xbytes in
parse_bounded_vldata_elim min max l p xbytes x consumed
(* Serialization *)
let parse_bounded_vldata_strong_pred
(min: nat)
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t) | false | false | LowParse.Spec.VLData.fsti | {
"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"
} | null | val parse_bounded_vldata_strong_pred
(min max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: GTot Type0 | [] | LowParse.Spec.VLData.parse_bounded_vldata_strong_pred | {
"file_name": "src/lowparse/LowParse.Spec.VLData.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | min: Prims.nat -> max: Prims.nat -> s: LowParse.Spec.Base.serializer p -> x: t -> Prims.GTot Type0 | {
"end_col": 32,
"end_line": 406,
"start_col": 1,
"start_line": 405
} |
Prims.Tot | val parse_vldata_payload_kind (sz: integer_size) (k: parser_kind) : parser_kind | [
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_vldata_payload_kind
(sz: integer_size)
(k: parser_kind)
: parser_kind
= strong_parser_kind 0 (parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
) | val parse_vldata_payload_kind (sz: integer_size) (k: parser_kind) : parser_kind
let parse_vldata_payload_kind (sz: integer_size) (k: parser_kind) : parser_kind = | false | null | false | strong_parser_kind 0
(parse_vldata_payload_size sz)
(match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None) | {
"checked_file": "LowParse.Spec.VLData.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLData.fsti"
} | [
"total"
] | [
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.strong_parser_kind",
"LowParse.Spec.VLData.parse_vldata_payload_size",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_metadata",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.parser_kind_metadata_some",
"LowParse.Spec.Base.ParserKindMetadataFail",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.None",
"LowParse.Spec.Base.parser_kind_metadata_t"
] | [] | module LowParse.Spec.VLData
include LowParse.Spec.FLData
include LowParse.Spec.AllIntegers // for bounded_integer, in_bounds, etc.
module Seq = FStar.Seq
module U32 = FStar.UInt32
module M = LowParse.Math
#reset-options "--z3rlimit 64 --max_fuel 64 --max_ifuel 64 --z3refresh --z3cliopt smt.arith.nl=false"
let parse_vldata_payload_size
(sz: integer_size)
: Pure nat
(requires True)
(ensures (fun y -> y == pow2 (FStar.Mul.op_Star 8 sz) - 1 ))
= match sz with
| 1 -> 255
| 2 -> 65535
| 3 -> 16777215
| 4 -> 4294967295
#reset-options
// unfold
let parse_vldata_payload_kind
(sz: integer_size)
(k: parser_kind) | false | true | LowParse.Spec.VLData.fsti | {
"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"
} | null | val parse_vldata_payload_kind (sz: integer_size) (k: parser_kind) : parser_kind | [] | LowParse.Spec.VLData.parse_vldata_payload_kind | {
"file_name": "src/lowparse/LowParse.Spec.VLData.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | sz: LowParse.Spec.BoundedInt.integer_size -> k: LowParse.Spec.Base.parser_kind
-> LowParse.Spec.Base.parser_kind | {
"end_col": 3,
"end_line": 33,
"start_col": 2,
"start_line": 29
} |
Prims.Tot | val parse_vldata_gen_kind (sz: integer_size) (k: parser_kind) : Tot parser_kind | [
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_vldata_gen_kind
(sz: integer_size)
(k: parser_kind)
: Tot parser_kind
= strong_parser_kind sz (sz + parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
) | val parse_vldata_gen_kind (sz: integer_size) (k: parser_kind) : Tot parser_kind
let parse_vldata_gen_kind (sz: integer_size) (k: parser_kind) : Tot parser_kind = | false | null | false | strong_parser_kind sz
(sz + parse_vldata_payload_size sz)
(match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None) | {
"checked_file": "LowParse.Spec.VLData.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLData.fsti"
} | [
"total"
] | [
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.strong_parser_kind",
"Prims.op_Addition",
"LowParse.Spec.VLData.parse_vldata_payload_size",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_metadata",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.parser_kind_metadata_some",
"LowParse.Spec.Base.ParserKindMetadataFail",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.None",
"LowParse.Spec.Base.parser_kind_metadata_t"
] | [] | module LowParse.Spec.VLData
include LowParse.Spec.FLData
include LowParse.Spec.AllIntegers // for bounded_integer, in_bounds, etc.
module Seq = FStar.Seq
module U32 = FStar.UInt32
module M = LowParse.Math
#reset-options "--z3rlimit 64 --max_fuel 64 --max_ifuel 64 --z3refresh --z3cliopt smt.arith.nl=false"
let parse_vldata_payload_size
(sz: integer_size)
: Pure nat
(requires True)
(ensures (fun y -> y == pow2 (FStar.Mul.op_Star 8 sz) - 1 ))
= match sz with
| 1 -> 255
| 2 -> 65535
| 3 -> 16777215
| 4 -> 4294967295
#reset-options
// unfold
let parse_vldata_payload_kind
(sz: integer_size)
(k: parser_kind)
: parser_kind
= strong_parser_kind 0 (parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_payload
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(i: bounded_integer sz { f i == true } )
: Tot (parser (parse_vldata_payload_kind sz k) t)
= weaken (parse_vldata_payload_kind sz k) (parse_fldata p (U32.v i))
#set-options "--z3rlimit 64"
let parse_fldata_and_then_cases_injective
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p))
= parser_kind_prop_equiv k p;
let g
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1 b2: bytes)
: Lemma
(requires (and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2))
(ensures (len1 == len2))
= assert (injective_precond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (injective_postcond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (len1 == len2)
in
let g'
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1: bytes)
: Lemma
(forall (b2: bytes) . and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2 ==> len1 == len2)
= Classical.forall_intro (Classical.move_requires (g len1 len2 b1))
in
Classical.forall_intro_3 g'
#reset-options
// unfold
let parse_vldata_gen_kind
(sz: integer_size)
(k: parser_kind) | false | true | LowParse.Spec.VLData.fsti | {
"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"
} | null | val parse_vldata_gen_kind (sz: integer_size) (k: parser_kind) : Tot parser_kind | [] | LowParse.Spec.VLData.parse_vldata_gen_kind | {
"file_name": "src/lowparse/LowParse.Spec.VLData.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | sz: LowParse.Spec.BoundedInt.integer_size -> k: LowParse.Spec.Base.parser_kind
-> LowParse.Spec.Base.parser_kind | {
"end_col": 3,
"end_line": 86,
"start_col": 2,
"start_line": 82
} |
FStar.Pervasives.Lemma | val parse_vldata_gen_kind_correct (sz: integer_size) (k: parser_kind)
: Lemma
((parse_vldata_gen_kind sz k) ==
(and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz))
(parse_vldata_payload_kind sz k))) | [
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_vldata_gen_kind_correct
(sz: integer_size)
(k: parser_kind)
: Lemma
( (parse_vldata_gen_kind sz k) == (and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k)))
= let kl = parse_vldata_gen_kind sz k in
let kr = and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) in
assert_norm (kl == kr) | val parse_vldata_gen_kind_correct (sz: integer_size) (k: parser_kind)
: Lemma
((parse_vldata_gen_kind sz k) ==
(and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz))
(parse_vldata_payload_kind sz k)))
let parse_vldata_gen_kind_correct (sz: integer_size) (k: parser_kind)
: Lemma
((parse_vldata_gen_kind sz k) ==
(and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz))
(parse_vldata_payload_kind sz k))) = | false | null | true | let kl = parse_vldata_gen_kind sz k in
let kr =
and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k)
in
assert_norm (kl == kr) | {
"checked_file": "LowParse.Spec.VLData.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLData.fsti"
} | [
"lemma"
] | [
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.Base.parser_kind",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"LowParse.Spec.Combinators.and_then_kind",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.BoundedInt.parse_bounded_integer_kind",
"LowParse.Spec.VLData.parse_vldata_payload_kind",
"LowParse.Spec.VLData.parse_vldata_gen_kind",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.VLData
include LowParse.Spec.FLData
include LowParse.Spec.AllIntegers // for bounded_integer, in_bounds, etc.
module Seq = FStar.Seq
module U32 = FStar.UInt32
module M = LowParse.Math
#reset-options "--z3rlimit 64 --max_fuel 64 --max_ifuel 64 --z3refresh --z3cliopt smt.arith.nl=false"
let parse_vldata_payload_size
(sz: integer_size)
: Pure nat
(requires True)
(ensures (fun y -> y == pow2 (FStar.Mul.op_Star 8 sz) - 1 ))
= match sz with
| 1 -> 255
| 2 -> 65535
| 3 -> 16777215
| 4 -> 4294967295
#reset-options
// unfold
let parse_vldata_payload_kind
(sz: integer_size)
(k: parser_kind)
: parser_kind
= strong_parser_kind 0 (parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_payload
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(i: bounded_integer sz { f i == true } )
: Tot (parser (parse_vldata_payload_kind sz k) t)
= weaken (parse_vldata_payload_kind sz k) (parse_fldata p (U32.v i))
#set-options "--z3rlimit 64"
let parse_fldata_and_then_cases_injective
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p))
= parser_kind_prop_equiv k p;
let g
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1 b2: bytes)
: Lemma
(requires (and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2))
(ensures (len1 == len2))
= assert (injective_precond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (injective_postcond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (len1 == len2)
in
let g'
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1: bytes)
: Lemma
(forall (b2: bytes) . and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2 ==> len1 == len2)
= Classical.forall_intro (Classical.move_requires (g len1 len2 b1))
in
Classical.forall_intro_3 g'
#reset-options
// unfold
let parse_vldata_gen_kind
(sz: integer_size)
(k: parser_kind)
: Tot parser_kind
= strong_parser_kind sz (sz + parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_gen_kind_correct
(sz: integer_size)
(k: parser_kind)
: Lemma | false | false | LowParse.Spec.VLData.fsti | {
"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"
} | null | val parse_vldata_gen_kind_correct (sz: integer_size) (k: parser_kind)
: Lemma
((parse_vldata_gen_kind sz k) ==
(and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz))
(parse_vldata_payload_kind sz k))) | [] | LowParse.Spec.VLData.parse_vldata_gen_kind_correct | {
"file_name": "src/lowparse/LowParse.Spec.VLData.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | sz: LowParse.Spec.BoundedInt.integer_size -> k: LowParse.Spec.Base.parser_kind
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.VLData.parse_vldata_gen_kind sz k ==
LowParse.Spec.Combinators.and_then_kind (LowParse.Spec.Combinators.parse_filter_kind (LowParse.Spec.BoundedInt.parse_bounded_integer_kind
sz))
(LowParse.Spec.VLData.parse_vldata_payload_kind sz k)) | {
"end_col": 24,
"end_line": 95,
"start_col": 1,
"start_line": 93
} |
Prims.Tot | val parse_vldata_payload
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(i: bounded_integer sz {f i == true})
: Tot (parser (parse_vldata_payload_kind sz k) t) | [
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_vldata_payload
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(i: bounded_integer sz { f i == true } )
: Tot (parser (parse_vldata_payload_kind sz k) t)
= weaken (parse_vldata_payload_kind sz k) (parse_fldata p (U32.v i)) | val parse_vldata_payload
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(i: bounded_integer sz {f i == true})
: Tot (parser (parse_vldata_payload_kind sz k) t)
let parse_vldata_payload
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(i: bounded_integer sz {f i == true})
: Tot (parser (parse_vldata_payload_kind sz k) t) = | false | null | false | weaken (parse_vldata_payload_kind sz k) (parse_fldata p (U32.v i)) | {
"checked_file": "LowParse.Spec.VLData.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLData.fsti"
} | [
"total"
] | [
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.BoundedInt.bounded_integer",
"Prims.bool",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"Prims.eq2",
"LowParse.Spec.Base.weaken",
"LowParse.Spec.VLData.parse_vldata_payload_kind",
"LowParse.Spec.FLData.parse_fldata_kind",
"FStar.UInt32.v",
"LowParse.Spec.FLData.parse_fldata"
] | [] | module LowParse.Spec.VLData
include LowParse.Spec.FLData
include LowParse.Spec.AllIntegers // for bounded_integer, in_bounds, etc.
module Seq = FStar.Seq
module U32 = FStar.UInt32
module M = LowParse.Math
#reset-options "--z3rlimit 64 --max_fuel 64 --max_ifuel 64 --z3refresh --z3cliopt smt.arith.nl=false"
let parse_vldata_payload_size
(sz: integer_size)
: Pure nat
(requires True)
(ensures (fun y -> y == pow2 (FStar.Mul.op_Star 8 sz) - 1 ))
= match sz with
| 1 -> 255
| 2 -> 65535
| 3 -> 16777215
| 4 -> 4294967295
#reset-options
// unfold
let parse_vldata_payload_kind
(sz: integer_size)
(k: parser_kind)
: parser_kind
= strong_parser_kind 0 (parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_payload
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(i: bounded_integer sz { f i == true } ) | false | false | LowParse.Spec.VLData.fsti | {
"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"
} | null | val parse_vldata_payload
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(i: bounded_integer sz {f i == true})
: Tot (parser (parse_vldata_payload_kind sz k) t) | [] | LowParse.Spec.VLData.parse_vldata_payload | {
"file_name": "src/lowparse/LowParse.Spec.VLData.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
sz: LowParse.Spec.BoundedInt.integer_size ->
f: (_: LowParse.Spec.BoundedInt.bounded_integer sz -> Prims.GTot Prims.bool) ->
p: LowParse.Spec.Base.parser k t ->
i: LowParse.Spec.BoundedInt.bounded_integer sz {f i == true}
-> LowParse.Spec.Base.parser (LowParse.Spec.VLData.parse_vldata_payload_kind sz k) t | {
"end_col": 68,
"end_line": 43,
"start_col": 2,
"start_line": 43
} |
Prims.GTot | val serialize_bounded_vldata_precond
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(k: parser_kind)
: GTot bool | [
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialize_bounded_vldata_precond
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(k: parser_kind)
: GTot bool
= match k.parser_kind_high with
| None -> false
| Some max' -> min <= k.parser_kind_low && max' <= max | val serialize_bounded_vldata_precond
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(k: parser_kind)
: GTot bool
let serialize_bounded_vldata_precond
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(k: parser_kind)
: GTot bool = | false | null | false | match k.parser_kind_high with
| None -> false
| Some max' -> min <= k.parser_kind_low && max' <= max | {
"checked_file": "LowParse.Spec.VLData.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLData.fsti"
} | [
"sometrivial"
] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high",
"Prims.op_AmpAmp",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"Prims.bool"
] | [] | module LowParse.Spec.VLData
include LowParse.Spec.FLData
include LowParse.Spec.AllIntegers // for bounded_integer, in_bounds, etc.
module Seq = FStar.Seq
module U32 = FStar.UInt32
module M = LowParse.Math
#reset-options "--z3rlimit 64 --max_fuel 64 --max_ifuel 64 --z3refresh --z3cliopt smt.arith.nl=false"
let parse_vldata_payload_size
(sz: integer_size)
: Pure nat
(requires True)
(ensures (fun y -> y == pow2 (FStar.Mul.op_Star 8 sz) - 1 ))
= match sz with
| 1 -> 255
| 2 -> 65535
| 3 -> 16777215
| 4 -> 4294967295
#reset-options
// unfold
let parse_vldata_payload_kind
(sz: integer_size)
(k: parser_kind)
: parser_kind
= strong_parser_kind 0 (parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_payload
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(i: bounded_integer sz { f i == true } )
: Tot (parser (parse_vldata_payload_kind sz k) t)
= weaken (parse_vldata_payload_kind sz k) (parse_fldata p (U32.v i))
#set-options "--z3rlimit 64"
let parse_fldata_and_then_cases_injective
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p))
= parser_kind_prop_equiv k p;
let g
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1 b2: bytes)
: Lemma
(requires (and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2))
(ensures (len1 == len2))
= assert (injective_precond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (injective_postcond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (len1 == len2)
in
let g'
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1: bytes)
: Lemma
(forall (b2: bytes) . and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2 ==> len1 == len2)
= Classical.forall_intro (Classical.move_requires (g len1 len2 b1))
in
Classical.forall_intro_3 g'
#reset-options
// unfold
let parse_vldata_gen_kind
(sz: integer_size)
(k: parser_kind)
: Tot parser_kind
= strong_parser_kind sz (sz + parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_gen_kind_correct
(sz: integer_size)
(k: parser_kind)
: Lemma
( (parse_vldata_gen_kind sz k) == (and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k)))
= let kl = parse_vldata_gen_kind sz k in
let kr = and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) in
assert_norm (kl == kr)
val parse_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_vldata_gen_kind sz k) t)
val parse_vldata_gen_eq_def
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p) /\
parse_vldata_gen_kind sz k == and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) /\
parse_vldata_gen sz f p ==
and_then
#_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t
(parse_vldata_payload sz f p))
let parse_vldata_gen_eq
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(let res = parse (parse_vldata_gen sz f p) input in
match parse (parse_bounded_integer sz) input with
| None -> res == None
| Some (len, consumed_len) ->
consumed_len == sz /\ (
if f len
then begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
else res == None
))
= parse_vldata_gen_eq_def sz f p;
and_then_eq #_ #(parse_filter_refine f) (parse_filter (parse_bounded_integer sz) f) #_ #t (parse_vldata_payload sz f p) input;
parse_filter_eq #_ #(bounded_integer sz) (parse_bounded_integer sz) f input;
parser_kind_prop_equiv (parse_bounded_integer_kind sz) (parse_bounded_integer sz);
()
let parse_vldata_gen_eq_some_elim
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(requires (Some? (parse (parse_vldata_gen sz f p) input)))
(ensures (
let pbi = parse (parse_bounded_integer sz) input in
Some? pbi /\ (
let Some (len, consumed_len) = pbi in
consumed_len == sz /\
f len /\
Seq.length input >= sz + U32.v len /\ (
let input' = Seq.slice input sz (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let Some (x, consumed_x) = pp in
consumed_x = U32.v len /\
parse (parse_vldata_gen sz f p) input == Some (x, sz + U32.v len)
)))))
= parse_vldata_gen_eq sz f p input
let unconstrained_bounded_integer
(sz: integer_size)
(i: bounded_integer sz)
: GTot bool
= true
let parse_vldata
(sz: integer_size)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser _ t)
= parse_vldata_gen sz (unconstrained_bounded_integer sz) p
let parse_vldata_eq
(sz: integer_size)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(parse (parse_vldata sz p) input == (match parse (parse_bounded_integer sz) input with
| None -> None
| Some (len, _) ->
begin
if Seq.length input < sz + U32.v len
then None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then Some (x, sz + U32.v len)
else None
| _ -> None
end
))
= parse_vldata_gen_eq sz (unconstrained_bounded_integer _) p input
(** Explicit bounds on size *)
#reset-options
inline_for_extraction
let parse_bounded_vldata_strong_kind
(min: nat)
(max: nat)
(l: nat)
(k: parser_kind)
: Pure parser_kind
(requires (min <= max /\ max > 0 /\ max < 4294967296 /\ l >= log256' max /\ l <= 4 ))
(ensures (fun _ -> True))
= [@inline_let]
let kmin = k.parser_kind_low in
[@inline_let]
let min' = if kmin > min then kmin else min in
[@inline_let]
let max' = match k.parser_kind_high with
| None -> max
| Some kmax -> if kmax < max then kmax else max
in
[@inline_let]
let max' = if max' < min' then min' else max' in
(* the size of the length prefix must conform to the max bound given by the user, not on the metadata *)
strong_parser_kind (l + min') (l + max') (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_bounded_vldata_elim'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(xbytes: bytes)
(x: t)
(consumed: consumed_length xbytes)
: Lemma
(requires (parse (parse_vldata_gen l (in_bounds min max) p) xbytes == Some (x, consumed)))
(ensures (
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
Some? plen /\ (
let (Some (len, consumed_len)) = plen in
(consumed_len <: nat) == (sz <: nat) /\
in_bounds min max len /\
U32.v len <= Seq.length xbytes - sz /\ (
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let (Some (x', consumed_p)) = pp in
x' == x /\
(consumed_p <: nat) == U32.v len /\
(consumed <: nat) == sz + U32.v len
)))))
= parse_vldata_gen_eq l (in_bounds min max) p xbytes;
parser_kind_prop_equiv (parse_bounded_integer_kind l) (parse_bounded_integer l)
let parse_bounded_vldata_correct
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(parser_kind_prop (parse_bounded_vldata_strong_kind min max l k) (parse_vldata_gen l (in_bounds min max) p))
= parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l k) (parse_vldata_gen l (in_bounds min max) p);
let sz : integer_size = l in
let p' = parse_vldata_gen sz (in_bounds min max) p in
parser_kind_prop_equiv (get_parser_kind p') p';
parser_kind_prop_equiv k p;
let k' = parse_bounded_vldata_strong_kind min max l k in
let prf
(input: bytes)
: Lemma
(requires (Some? (parse p' input)))
(ensures (
let pi = parse p' input in
Some? pi /\ (
let (Some (_, consumed)) = pi in
k'.parser_kind_low <= (consumed <: nat) /\
(consumed <: nat) <= Some?.v k'.parser_kind_high
)))
= let (Some (data, consumed)) = parse p' input in
parse_bounded_vldata_elim' min max l p input data consumed
in
Classical.forall_intro (Classical.move_requires prf)
let parse_bounded_vldata'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_bounded_vldata_strong_kind min max l k) t)
= parse_bounded_vldata_correct min max l p;
strengthen (parse_bounded_vldata_strong_kind min max l k) (parse_vldata_gen l (in_bounds min max) p)
let parse_bounded_vldata
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_bounded_vldata_strong_kind min max (log256' max) k) t)
= parse_bounded_vldata' min max (log256' max) p
let parse_bounded_vldata_elim
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(xbytes: bytes)
(x: t)
(consumed: consumed_length xbytes)
: Lemma
(requires (parse (parse_bounded_vldata' min max l p) xbytes == Some (x, consumed)))
(ensures (
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
Some? plen /\ (
let (Some (len, consumed_len)) = plen in
(consumed_len <: nat) == (sz <: nat) /\
in_bounds min max len /\
U32.v len <= Seq.length xbytes - sz /\ (
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let (Some (x', consumed_p)) = pp in
x' == x /\
(consumed_p <: nat) == U32.v len /\
(consumed <: nat) == sz + U32.v len
)))))
= parse_bounded_vldata_elim' min max l p xbytes x consumed
let parse_bounded_vldata_elim_forall
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(xbytes: bytes)
: Lemma
(requires (Some? (parse (parse_bounded_vldata' min max l p) xbytes)))
(ensures (
let (Some (x, consumed)) = parse (parse_bounded_vldata' min max l p) xbytes in
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
Some? plen /\ (
let (Some (len, consumed_len)) = plen in
(consumed_len <: nat) == (sz <: nat) /\
in_bounds min max len /\
U32.v len <= Seq.length xbytes - sz /\ (
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let (Some (x', consumed_p)) = pp in
x' == x /\
(consumed_p <: nat) == U32.v len /\
(consumed <: nat) == sz + U32.v len
)))))
= let (Some (x, consumed)) = parse (parse_bounded_vldata' min max l p) xbytes in
parse_bounded_vldata_elim min max l p xbytes x consumed
(* Serialization *)
let parse_bounded_vldata_strong_pred
(min: nat)
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: GTot Type0
= let reslen = Seq.length (s x) in
min <= reslen /\ reslen <= max
let parse_bounded_vldata_strong_t
(min: nat)
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t { parse_bounded_vldata_strong_pred min max s x } )
let parse_bounded_vldata_strong_correct
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(xbytes: bytes)
(consumed: consumed_length xbytes)
(x: t)
: Lemma
(requires (parse (parse_bounded_vldata' min max l p) xbytes == Some (x, consumed)))
(ensures (parse_bounded_vldata_strong_pred min max s x))
= parse_bounded_vldata_elim min max l p xbytes x consumed;
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
let f () : Lemma (Some? plen) =
parse_bounded_vldata_elim min max l p xbytes x consumed
in
f ();
let (Some (len, _)) = plen in
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
assert (Seq.equal input' (Seq.slice input' 0 (U32.v len)));
serializer_correct_implies_complete p s;
assert (s x == input');
()
let parse_bounded_vldata_strong'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (parser (parse_bounded_vldata_strong_kind min max l k) (parse_bounded_vldata_strong_t min max s))
= // strengthen (parse_bounded_vldata_strong_kind min max k)
(
coerce_parser
(parse_bounded_vldata_strong_t min max s)
(parse_strengthen (parse_bounded_vldata' min max l p) (parse_bounded_vldata_strong_pred min max s) (parse_bounded_vldata_strong_correct min max l s))
)
let parse_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (parser (parse_bounded_vldata_strong_kind min max (log256' max) k) (parse_bounded_vldata_strong_t min max s))
= parse_bounded_vldata_strong' min max (log256' max) s
let serialize_bounded_vldata_strong_aux
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (bare_serializer (parse_bounded_vldata_strong_t min max s))
= (fun (x: parse_bounded_vldata_strong_t min max s) ->
let pl = s x in
let sz = l in
let nlen = Seq.length pl in
assert (min <= nlen /\ nlen <= max);
let len = U32.uint_to_t nlen in
let slen = serialize (serialize_bounded_integer sz) len in
seq_slice_append_l slen pl;
seq_slice_append_r slen pl;
Seq.append slen pl
)
let serialize_vldata_gen_correct_aux
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b b1 b2: bytes)
: Lemma
(requires (
Seq.length b1 == sz /\ (
let vlen = parse (parse_bounded_integer sz) b1 in
Some? vlen /\ (
let (Some (len, _)) = vlen in
f len == true /\
Seq.length b2 == U32.v len /\ (
let vv = parse p b2 in
Some? vv /\ (
let (Some (_, consumed)) = vv in
consumed == Seq.length b2 /\
Seq.length b1 <= Seq.length b /\
Seq.slice b 0 (Seq.length b1) == b1 /\
Seq.slice b (Seq.length b1) (Seq.length b) == b2
))))))
(ensures (
let vv = parse p b2 in
Some? vv /\ (
let (Some (v, consumed)) = vv in
let vv' = parse (parse_vldata_gen sz f p) b in
Some? vv' /\ (
let (Some (v', consumed')) = vv' in
v == v' /\
consumed == Seq.length b2 /\
consumed' == Seq.length b
)))) =
let (Some (len, consumed1)) = parse (parse_bounded_integer sz) b1 in
parser_kind_prop_equiv (parse_bounded_integer_kind sz) (parse_bounded_integer sz);
assert (consumed1 == sz);
assert (no_lookahead_on (parse_bounded_integer sz) b1 b);
assert (injective_postcond (parse_bounded_integer sz) b1 b);
assert (parse (parse_bounded_integer sz) b == Some (len, sz));
assert (sz + U32.v len == Seq.length b);
assert (b2 == Seq.slice b sz (sz + U32.v len));
parse_vldata_gen_eq sz f p b
let serialize_vldata_gen_correct
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b1 b2: bytes)
: Lemma
(requires (
Seq.length b1 == sz /\ (
let vlen = parse (parse_bounded_integer sz) b1 in
Some? vlen /\ (
let (Some (len, _)) = vlen in
f len == true /\
Seq.length b2 == U32.v len /\ (
let vv = parse p b2 in
Some? vv /\ (
let (Some (_, consumed)) = vv in
consumed == Seq.length b2
))))))
(ensures (
let vv = parse p b2 in
Some? vv /\ (
let (Some (v, consumed)) = vv in
let vv' = parse (parse_vldata_gen sz f p) (Seq.append b1 b2) in
Some? vv' /\ (
let (Some (v', consumed')) = vv' in
v == v' /\
consumed == Seq.length b2 /\
consumed' == sz + Seq.length b2
)))) =
seq_slice_append_l b1 b2;
seq_slice_append_r b1 b2;
serialize_vldata_gen_correct_aux sz f p (Seq.append b1 b2) b1 b2
let serialize_bounded_vldata_strong_correct
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: parse_bounded_vldata_strong_t min max s)
: Lemma
(let formatted = serialize_bounded_vldata_strong_aux min max l s input in
parse (parse_bounded_vldata_strong' min max l s) formatted == Some (input, Seq.length formatted))
= let sz = l in
let sp = serialize s input in
let nlen = Seq.length sp in
assert (min <= nlen /\ nlen <= max);
let len = U32.uint_to_t nlen in
M.pow2_le_compat (FStar.Mul.op_Star 8 sz) (FStar.Mul.op_Star 8 (log256' max));
assert (U32.v len < pow2 (FStar.Mul.op_Star 8 sz));
let (len: bounded_integer sz) = len in
let slen = serialize (serialize_bounded_integer sz) len in
assert (Seq.length slen == sz);
let pslen = parse (parse_bounded_integer sz) slen in
assert (Some? pslen);
let (Some (len', consumed_len')) = pslen in
assert (len == len');
assert (in_bounds min max len' == true);
assert (Seq.length sp == U32.v len);
let psp = parse p sp in
assert (Some? psp);
let (Some (_, consumed_p)) = psp in
assert ((consumed_p <: nat) == Seq.length sp);
serialize_vldata_gen_correct sz (in_bounds min max) p
slen
sp
;
()
let serialize_bounded_vldata_strong'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bounded_vldata_strong' min max l s))
= Classical.forall_intro (serialize_bounded_vldata_strong_correct min max l s);
serialize_bounded_vldata_strong_aux min max l s
let serialize_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bounded_vldata_strong min max s))
= serialize_bounded_vldata_strong' min max (log256' max) s
let serialize_bounded_vldata_precond
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(k: parser_kind) | false | false | LowParse.Spec.VLData.fsti | {
"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"
} | null | val serialize_bounded_vldata_precond
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(k: parser_kind)
: GTot bool | [] | LowParse.Spec.VLData.serialize_bounded_vldata_precond | {
"file_name": "src/lowparse/LowParse.Spec.VLData.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
k: LowParse.Spec.Base.parser_kind
-> Prims.GTot Prims.bool | {
"end_col": 56,
"end_line": 639,
"start_col": 2,
"start_line": 637
} |
Prims.GTot | val serialize_bounded_vldata'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {serialize_bounded_vldata_precond min max k})
(x: t)
: GTot (y: bytes{parse (parse_bounded_vldata min max p) y == Some (x, Seq.length y)}) | [
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialize_bounded_vldata'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { serialize_bounded_vldata_precond min max k } )
(x: t)
: GTot (y: bytes { parse (parse_bounded_vldata min max p) y == Some (x, Seq.length y) } )
= let Some (_, consumed) = parse p (serialize s x) in
serialize_bounded_vldata_correct min max s x;
serialize_bounded_vldata_strong_aux min max (log256' max) s x | val serialize_bounded_vldata'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {serialize_bounded_vldata_precond min max k})
(x: t)
: GTot (y: bytes{parse (parse_bounded_vldata min max p) y == Some (x, Seq.length y)})
let serialize_bounded_vldata'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {serialize_bounded_vldata_precond min max k})
(x: t)
: GTot (y: bytes{parse (parse_bounded_vldata min max p) y == Some (x, Seq.length y)}) = | false | null | false | let Some (_, consumed) = parse p (serialize s x) in
serialize_bounded_vldata_correct min max s x;
serialize_bounded_vldata_strong_aux min max (log256' max) s x | {
"checked_file": "LowParse.Spec.VLData.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLData.fsti"
} | [
"sometrivial"
] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Spec.VLData.serialize_bounded_vldata_precond",
"LowParse.Spec.Base.consumed_length",
"LowParse.Spec.Base.serialize",
"LowParse.Spec.VLData.serialize_bounded_vldata_strong_aux",
"LowParse.Spec.BoundedInt.log256'",
"Prims.unit",
"LowParse.Spec.VLData.serialize_bounded_vldata_correct",
"LowParse.Bytes.bytes",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.parse",
"LowParse.Spec.VLData.parse_bounded_vldata",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte"
] | [] | module LowParse.Spec.VLData
include LowParse.Spec.FLData
include LowParse.Spec.AllIntegers // for bounded_integer, in_bounds, etc.
module Seq = FStar.Seq
module U32 = FStar.UInt32
module M = LowParse.Math
#reset-options "--z3rlimit 64 --max_fuel 64 --max_ifuel 64 --z3refresh --z3cliopt smt.arith.nl=false"
let parse_vldata_payload_size
(sz: integer_size)
: Pure nat
(requires True)
(ensures (fun y -> y == pow2 (FStar.Mul.op_Star 8 sz) - 1 ))
= match sz with
| 1 -> 255
| 2 -> 65535
| 3 -> 16777215
| 4 -> 4294967295
#reset-options
// unfold
let parse_vldata_payload_kind
(sz: integer_size)
(k: parser_kind)
: parser_kind
= strong_parser_kind 0 (parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_payload
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(i: bounded_integer sz { f i == true } )
: Tot (parser (parse_vldata_payload_kind sz k) t)
= weaken (parse_vldata_payload_kind sz k) (parse_fldata p (U32.v i))
#set-options "--z3rlimit 64"
let parse_fldata_and_then_cases_injective
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p))
= parser_kind_prop_equiv k p;
let g
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1 b2: bytes)
: Lemma
(requires (and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2))
(ensures (len1 == len2))
= assert (injective_precond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (injective_postcond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (len1 == len2)
in
let g'
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1: bytes)
: Lemma
(forall (b2: bytes) . and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2 ==> len1 == len2)
= Classical.forall_intro (Classical.move_requires (g len1 len2 b1))
in
Classical.forall_intro_3 g'
#reset-options
// unfold
let parse_vldata_gen_kind
(sz: integer_size)
(k: parser_kind)
: Tot parser_kind
= strong_parser_kind sz (sz + parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_gen_kind_correct
(sz: integer_size)
(k: parser_kind)
: Lemma
( (parse_vldata_gen_kind sz k) == (and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k)))
= let kl = parse_vldata_gen_kind sz k in
let kr = and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) in
assert_norm (kl == kr)
val parse_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_vldata_gen_kind sz k) t)
val parse_vldata_gen_eq_def
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p) /\
parse_vldata_gen_kind sz k == and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) /\
parse_vldata_gen sz f p ==
and_then
#_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t
(parse_vldata_payload sz f p))
let parse_vldata_gen_eq
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(let res = parse (parse_vldata_gen sz f p) input in
match parse (parse_bounded_integer sz) input with
| None -> res == None
| Some (len, consumed_len) ->
consumed_len == sz /\ (
if f len
then begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
else res == None
))
= parse_vldata_gen_eq_def sz f p;
and_then_eq #_ #(parse_filter_refine f) (parse_filter (parse_bounded_integer sz) f) #_ #t (parse_vldata_payload sz f p) input;
parse_filter_eq #_ #(bounded_integer sz) (parse_bounded_integer sz) f input;
parser_kind_prop_equiv (parse_bounded_integer_kind sz) (parse_bounded_integer sz);
()
let parse_vldata_gen_eq_some_elim
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(requires (Some? (parse (parse_vldata_gen sz f p) input)))
(ensures (
let pbi = parse (parse_bounded_integer sz) input in
Some? pbi /\ (
let Some (len, consumed_len) = pbi in
consumed_len == sz /\
f len /\
Seq.length input >= sz + U32.v len /\ (
let input' = Seq.slice input sz (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let Some (x, consumed_x) = pp in
consumed_x = U32.v len /\
parse (parse_vldata_gen sz f p) input == Some (x, sz + U32.v len)
)))))
= parse_vldata_gen_eq sz f p input
let unconstrained_bounded_integer
(sz: integer_size)
(i: bounded_integer sz)
: GTot bool
= true
let parse_vldata
(sz: integer_size)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser _ t)
= parse_vldata_gen sz (unconstrained_bounded_integer sz) p
let parse_vldata_eq
(sz: integer_size)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(parse (parse_vldata sz p) input == (match parse (parse_bounded_integer sz) input with
| None -> None
| Some (len, _) ->
begin
if Seq.length input < sz + U32.v len
then None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then Some (x, sz + U32.v len)
else None
| _ -> None
end
))
= parse_vldata_gen_eq sz (unconstrained_bounded_integer _) p input
(** Explicit bounds on size *)
#reset-options
inline_for_extraction
let parse_bounded_vldata_strong_kind
(min: nat)
(max: nat)
(l: nat)
(k: parser_kind)
: Pure parser_kind
(requires (min <= max /\ max > 0 /\ max < 4294967296 /\ l >= log256' max /\ l <= 4 ))
(ensures (fun _ -> True))
= [@inline_let]
let kmin = k.parser_kind_low in
[@inline_let]
let min' = if kmin > min then kmin else min in
[@inline_let]
let max' = match k.parser_kind_high with
| None -> max
| Some kmax -> if kmax < max then kmax else max
in
[@inline_let]
let max' = if max' < min' then min' else max' in
(* the size of the length prefix must conform to the max bound given by the user, not on the metadata *)
strong_parser_kind (l + min') (l + max') (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_bounded_vldata_elim'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(xbytes: bytes)
(x: t)
(consumed: consumed_length xbytes)
: Lemma
(requires (parse (parse_vldata_gen l (in_bounds min max) p) xbytes == Some (x, consumed)))
(ensures (
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
Some? plen /\ (
let (Some (len, consumed_len)) = plen in
(consumed_len <: nat) == (sz <: nat) /\
in_bounds min max len /\
U32.v len <= Seq.length xbytes - sz /\ (
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let (Some (x', consumed_p)) = pp in
x' == x /\
(consumed_p <: nat) == U32.v len /\
(consumed <: nat) == sz + U32.v len
)))))
= parse_vldata_gen_eq l (in_bounds min max) p xbytes;
parser_kind_prop_equiv (parse_bounded_integer_kind l) (parse_bounded_integer l)
let parse_bounded_vldata_correct
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(parser_kind_prop (parse_bounded_vldata_strong_kind min max l k) (parse_vldata_gen l (in_bounds min max) p))
= parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l k) (parse_vldata_gen l (in_bounds min max) p);
let sz : integer_size = l in
let p' = parse_vldata_gen sz (in_bounds min max) p in
parser_kind_prop_equiv (get_parser_kind p') p';
parser_kind_prop_equiv k p;
let k' = parse_bounded_vldata_strong_kind min max l k in
let prf
(input: bytes)
: Lemma
(requires (Some? (parse p' input)))
(ensures (
let pi = parse p' input in
Some? pi /\ (
let (Some (_, consumed)) = pi in
k'.parser_kind_low <= (consumed <: nat) /\
(consumed <: nat) <= Some?.v k'.parser_kind_high
)))
= let (Some (data, consumed)) = parse p' input in
parse_bounded_vldata_elim' min max l p input data consumed
in
Classical.forall_intro (Classical.move_requires prf)
let parse_bounded_vldata'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_bounded_vldata_strong_kind min max l k) t)
= parse_bounded_vldata_correct min max l p;
strengthen (parse_bounded_vldata_strong_kind min max l k) (parse_vldata_gen l (in_bounds min max) p)
let parse_bounded_vldata
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_bounded_vldata_strong_kind min max (log256' max) k) t)
= parse_bounded_vldata' min max (log256' max) p
let parse_bounded_vldata_elim
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(xbytes: bytes)
(x: t)
(consumed: consumed_length xbytes)
: Lemma
(requires (parse (parse_bounded_vldata' min max l p) xbytes == Some (x, consumed)))
(ensures (
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
Some? plen /\ (
let (Some (len, consumed_len)) = plen in
(consumed_len <: nat) == (sz <: nat) /\
in_bounds min max len /\
U32.v len <= Seq.length xbytes - sz /\ (
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let (Some (x', consumed_p)) = pp in
x' == x /\
(consumed_p <: nat) == U32.v len /\
(consumed <: nat) == sz + U32.v len
)))))
= parse_bounded_vldata_elim' min max l p xbytes x consumed
let parse_bounded_vldata_elim_forall
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(xbytes: bytes)
: Lemma
(requires (Some? (parse (parse_bounded_vldata' min max l p) xbytes)))
(ensures (
let (Some (x, consumed)) = parse (parse_bounded_vldata' min max l p) xbytes in
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
Some? plen /\ (
let (Some (len, consumed_len)) = plen in
(consumed_len <: nat) == (sz <: nat) /\
in_bounds min max len /\
U32.v len <= Seq.length xbytes - sz /\ (
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let (Some (x', consumed_p)) = pp in
x' == x /\
(consumed_p <: nat) == U32.v len /\
(consumed <: nat) == sz + U32.v len
)))))
= let (Some (x, consumed)) = parse (parse_bounded_vldata' min max l p) xbytes in
parse_bounded_vldata_elim min max l p xbytes x consumed
(* Serialization *)
let parse_bounded_vldata_strong_pred
(min: nat)
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: GTot Type0
= let reslen = Seq.length (s x) in
min <= reslen /\ reslen <= max
let parse_bounded_vldata_strong_t
(min: nat)
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t { parse_bounded_vldata_strong_pred min max s x } )
let parse_bounded_vldata_strong_correct
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(xbytes: bytes)
(consumed: consumed_length xbytes)
(x: t)
: Lemma
(requires (parse (parse_bounded_vldata' min max l p) xbytes == Some (x, consumed)))
(ensures (parse_bounded_vldata_strong_pred min max s x))
= parse_bounded_vldata_elim min max l p xbytes x consumed;
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
let f () : Lemma (Some? plen) =
parse_bounded_vldata_elim min max l p xbytes x consumed
in
f ();
let (Some (len, _)) = plen in
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
assert (Seq.equal input' (Seq.slice input' 0 (U32.v len)));
serializer_correct_implies_complete p s;
assert (s x == input');
()
let parse_bounded_vldata_strong'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (parser (parse_bounded_vldata_strong_kind min max l k) (parse_bounded_vldata_strong_t min max s))
= // strengthen (parse_bounded_vldata_strong_kind min max k)
(
coerce_parser
(parse_bounded_vldata_strong_t min max s)
(parse_strengthen (parse_bounded_vldata' min max l p) (parse_bounded_vldata_strong_pred min max s) (parse_bounded_vldata_strong_correct min max l s))
)
let parse_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (parser (parse_bounded_vldata_strong_kind min max (log256' max) k) (parse_bounded_vldata_strong_t min max s))
= parse_bounded_vldata_strong' min max (log256' max) s
let serialize_bounded_vldata_strong_aux
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (bare_serializer (parse_bounded_vldata_strong_t min max s))
= (fun (x: parse_bounded_vldata_strong_t min max s) ->
let pl = s x in
let sz = l in
let nlen = Seq.length pl in
assert (min <= nlen /\ nlen <= max);
let len = U32.uint_to_t nlen in
let slen = serialize (serialize_bounded_integer sz) len in
seq_slice_append_l slen pl;
seq_slice_append_r slen pl;
Seq.append slen pl
)
let serialize_vldata_gen_correct_aux
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b b1 b2: bytes)
: Lemma
(requires (
Seq.length b1 == sz /\ (
let vlen = parse (parse_bounded_integer sz) b1 in
Some? vlen /\ (
let (Some (len, _)) = vlen in
f len == true /\
Seq.length b2 == U32.v len /\ (
let vv = parse p b2 in
Some? vv /\ (
let (Some (_, consumed)) = vv in
consumed == Seq.length b2 /\
Seq.length b1 <= Seq.length b /\
Seq.slice b 0 (Seq.length b1) == b1 /\
Seq.slice b (Seq.length b1) (Seq.length b) == b2
))))))
(ensures (
let vv = parse p b2 in
Some? vv /\ (
let (Some (v, consumed)) = vv in
let vv' = parse (parse_vldata_gen sz f p) b in
Some? vv' /\ (
let (Some (v', consumed')) = vv' in
v == v' /\
consumed == Seq.length b2 /\
consumed' == Seq.length b
)))) =
let (Some (len, consumed1)) = parse (parse_bounded_integer sz) b1 in
parser_kind_prop_equiv (parse_bounded_integer_kind sz) (parse_bounded_integer sz);
assert (consumed1 == sz);
assert (no_lookahead_on (parse_bounded_integer sz) b1 b);
assert (injective_postcond (parse_bounded_integer sz) b1 b);
assert (parse (parse_bounded_integer sz) b == Some (len, sz));
assert (sz + U32.v len == Seq.length b);
assert (b2 == Seq.slice b sz (sz + U32.v len));
parse_vldata_gen_eq sz f p b
let serialize_vldata_gen_correct
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b1 b2: bytes)
: Lemma
(requires (
Seq.length b1 == sz /\ (
let vlen = parse (parse_bounded_integer sz) b1 in
Some? vlen /\ (
let (Some (len, _)) = vlen in
f len == true /\
Seq.length b2 == U32.v len /\ (
let vv = parse p b2 in
Some? vv /\ (
let (Some (_, consumed)) = vv in
consumed == Seq.length b2
))))))
(ensures (
let vv = parse p b2 in
Some? vv /\ (
let (Some (v, consumed)) = vv in
let vv' = parse (parse_vldata_gen sz f p) (Seq.append b1 b2) in
Some? vv' /\ (
let (Some (v', consumed')) = vv' in
v == v' /\
consumed == Seq.length b2 /\
consumed' == sz + Seq.length b2
)))) =
seq_slice_append_l b1 b2;
seq_slice_append_r b1 b2;
serialize_vldata_gen_correct_aux sz f p (Seq.append b1 b2) b1 b2
let serialize_bounded_vldata_strong_correct
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: parse_bounded_vldata_strong_t min max s)
: Lemma
(let formatted = serialize_bounded_vldata_strong_aux min max l s input in
parse (parse_bounded_vldata_strong' min max l s) formatted == Some (input, Seq.length formatted))
= let sz = l in
let sp = serialize s input in
let nlen = Seq.length sp in
assert (min <= nlen /\ nlen <= max);
let len = U32.uint_to_t nlen in
M.pow2_le_compat (FStar.Mul.op_Star 8 sz) (FStar.Mul.op_Star 8 (log256' max));
assert (U32.v len < pow2 (FStar.Mul.op_Star 8 sz));
let (len: bounded_integer sz) = len in
let slen = serialize (serialize_bounded_integer sz) len in
assert (Seq.length slen == sz);
let pslen = parse (parse_bounded_integer sz) slen in
assert (Some? pslen);
let (Some (len', consumed_len')) = pslen in
assert (len == len');
assert (in_bounds min max len' == true);
assert (Seq.length sp == U32.v len);
let psp = parse p sp in
assert (Some? psp);
let (Some (_, consumed_p)) = psp in
assert ((consumed_p <: nat) == Seq.length sp);
serialize_vldata_gen_correct sz (in_bounds min max) p
slen
sp
;
()
let serialize_bounded_vldata_strong'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bounded_vldata_strong' min max l s))
= Classical.forall_intro (serialize_bounded_vldata_strong_correct min max l s);
serialize_bounded_vldata_strong_aux min max l s
let serialize_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bounded_vldata_strong min max s))
= serialize_bounded_vldata_strong' min max (log256' max) s
let serialize_bounded_vldata_precond
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(k: parser_kind)
: GTot bool
= match k.parser_kind_high with
| None -> false
| Some max' -> min <= k.parser_kind_low && max' <= max
let serialize_bounded_vldata_correct
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { serialize_bounded_vldata_precond min max k } )
(x: t)
: Lemma
( let Some (_, consumed) = parse p (serialize s x) in
let y = serialize_bounded_vldata_strong_aux min max (log256' max) s (x <: parse_bounded_vldata_strong_t min max s) in
parse (parse_bounded_vldata min max p) y == Some (x, Seq.length y))
= let Some (_, consumed) = parse p (serialize s x) in
serialize_bounded_vldata_strong_correct min max (log256' max) s x;
()
let serialize_bounded_vldata'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { serialize_bounded_vldata_precond min max k } )
(x: t) | false | false | LowParse.Spec.VLData.fsti | {
"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"
} | null | val serialize_bounded_vldata'
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {serialize_bounded_vldata_precond min max k})
(x: t)
: GTot (y: bytes{parse (parse_bounded_vldata min max p) y == Some (x, Seq.length y)}) | [] | LowParse.Spec.VLData.serialize_bounded_vldata' | {
"file_name": "src/lowparse/LowParse.Spec.VLData.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
s:
LowParse.Spec.Base.serializer p
{LowParse.Spec.VLData.serialize_bounded_vldata_precond min max k} ->
x: t
-> Prims.GTot
(y:
LowParse.Bytes.bytes
{ LowParse.Spec.Base.parse (LowParse.Spec.VLData.parse_bounded_vldata min max p) y ==
FStar.Pervasives.Native.Some (x, FStar.Seq.Base.length y) }) | {
"end_col": 63,
"end_line": 668,
"start_col": 1,
"start_line": 666
} |
FStar.Pervasives.Lemma | val serialize_vldata_gen_correct
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b1 b2: bytes)
: Lemma
(requires
(Seq.length b1 == sz /\
(let vlen = parse (parse_bounded_integer sz) b1 in
Some? vlen /\
(let Some (len, _) = vlen in
f len == true /\ Seq.length b2 == U32.v len /\
(let vv = parse p b2 in
Some? vv /\
(let Some (_, consumed) = vv in
consumed == Seq.length b2))))))
(ensures
(let vv = parse p b2 in
Some? vv /\
(let Some (v, consumed) = vv in
let vv' = parse (parse_vldata_gen sz f p) (Seq.append b1 b2) in
Some? vv' /\
(let Some (v', consumed') = vv' in
v == v' /\ consumed == Seq.length b2 /\ consumed' == sz + Seq.length b2)))) | [
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialize_vldata_gen_correct
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b1 b2: bytes)
: Lemma
(requires (
Seq.length b1 == sz /\ (
let vlen = parse (parse_bounded_integer sz) b1 in
Some? vlen /\ (
let (Some (len, _)) = vlen in
f len == true /\
Seq.length b2 == U32.v len /\ (
let vv = parse p b2 in
Some? vv /\ (
let (Some (_, consumed)) = vv in
consumed == Seq.length b2
))))))
(ensures (
let vv = parse p b2 in
Some? vv /\ (
let (Some (v, consumed)) = vv in
let vv' = parse (parse_vldata_gen sz f p) (Seq.append b1 b2) in
Some? vv' /\ (
let (Some (v', consumed')) = vv' in
v == v' /\
consumed == Seq.length b2 /\
consumed' == sz + Seq.length b2
)))) =
seq_slice_append_l b1 b2;
seq_slice_append_r b1 b2;
serialize_vldata_gen_correct_aux sz f p (Seq.append b1 b2) b1 b2 | val serialize_vldata_gen_correct
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b1 b2: bytes)
: Lemma
(requires
(Seq.length b1 == sz /\
(let vlen = parse (parse_bounded_integer sz) b1 in
Some? vlen /\
(let Some (len, _) = vlen in
f len == true /\ Seq.length b2 == U32.v len /\
(let vv = parse p b2 in
Some? vv /\
(let Some (_, consumed) = vv in
consumed == Seq.length b2))))))
(ensures
(let vv = parse p b2 in
Some? vv /\
(let Some (v, consumed) = vv in
let vv' = parse (parse_vldata_gen sz f p) (Seq.append b1 b2) in
Some? vv' /\
(let Some (v', consumed') = vv' in
v == v' /\ consumed == Seq.length b2 /\ consumed' == sz + Seq.length b2))))
let serialize_vldata_gen_correct
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b1 b2: bytes)
: Lemma
(requires
(Seq.length b1 == sz /\
(let vlen = parse (parse_bounded_integer sz) b1 in
Some? vlen /\
(let Some (len, _) = vlen in
f len == true /\ Seq.length b2 == U32.v len /\
(let vv = parse p b2 in
Some? vv /\
(let Some (_, consumed) = vv in
consumed == Seq.length b2))))))
(ensures
(let vv = parse p b2 in
Some? vv /\
(let Some (v, consumed) = vv in
let vv' = parse (parse_vldata_gen sz f p) (Seq.append b1 b2) in
Some? vv' /\
(let Some (v', consumed') = vv' in
v == v' /\ consumed == Seq.length b2 /\ consumed' == sz + Seq.length b2)))) = | false | null | true | seq_slice_append_l b1 b2;
seq_slice_append_r b1 b2;
serialize_vldata_gen_correct_aux sz f p (Seq.append b1 b2) b1 b2 | {
"checked_file": "LowParse.Spec.VLData.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLData.fsti"
} | [
"lemma"
] | [
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.BoundedInt.bounded_integer",
"Prims.bool",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Bytes.bytes",
"LowParse.Spec.VLData.serialize_vldata_gen_correct_aux",
"FStar.Seq.Base.append",
"LowParse.Bytes.byte",
"Prims.unit",
"LowParse.Spec.Combinators.seq_slice_append_r",
"LowParse.Spec.Combinators.seq_slice_append_l",
"Prims.l_and",
"Prims.eq2",
"Prims.nat",
"FStar.Seq.Base.length",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.consumed_length",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt32.v",
"Prims.logical",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parse",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"Prims.squash",
"Prims.op_Addition",
"LowParse.Spec.VLData.parse_vldata_gen",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.VLData
include LowParse.Spec.FLData
include LowParse.Spec.AllIntegers // for bounded_integer, in_bounds, etc.
module Seq = FStar.Seq
module U32 = FStar.UInt32
module M = LowParse.Math
#reset-options "--z3rlimit 64 --max_fuel 64 --max_ifuel 64 --z3refresh --z3cliopt smt.arith.nl=false"
let parse_vldata_payload_size
(sz: integer_size)
: Pure nat
(requires True)
(ensures (fun y -> y == pow2 (FStar.Mul.op_Star 8 sz) - 1 ))
= match sz with
| 1 -> 255
| 2 -> 65535
| 3 -> 16777215
| 4 -> 4294967295
#reset-options
// unfold
let parse_vldata_payload_kind
(sz: integer_size)
(k: parser_kind)
: parser_kind
= strong_parser_kind 0 (parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_payload
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(i: bounded_integer sz { f i == true } )
: Tot (parser (parse_vldata_payload_kind sz k) t)
= weaken (parse_vldata_payload_kind sz k) (parse_fldata p (U32.v i))
#set-options "--z3rlimit 64"
let parse_fldata_and_then_cases_injective
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p))
= parser_kind_prop_equiv k p;
let g
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1 b2: bytes)
: Lemma
(requires (and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2))
(ensures (len1 == len2))
= assert (injective_precond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (injective_postcond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (len1 == len2)
in
let g'
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1: bytes)
: Lemma
(forall (b2: bytes) . and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2 ==> len1 == len2)
= Classical.forall_intro (Classical.move_requires (g len1 len2 b1))
in
Classical.forall_intro_3 g'
#reset-options
// unfold
let parse_vldata_gen_kind
(sz: integer_size)
(k: parser_kind)
: Tot parser_kind
= strong_parser_kind sz (sz + parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_gen_kind_correct
(sz: integer_size)
(k: parser_kind)
: Lemma
( (parse_vldata_gen_kind sz k) == (and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k)))
= let kl = parse_vldata_gen_kind sz k in
let kr = and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) in
assert_norm (kl == kr)
val parse_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_vldata_gen_kind sz k) t)
val parse_vldata_gen_eq_def
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p) /\
parse_vldata_gen_kind sz k == and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) /\
parse_vldata_gen sz f p ==
and_then
#_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t
(parse_vldata_payload sz f p))
let parse_vldata_gen_eq
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(let res = parse (parse_vldata_gen sz f p) input in
match parse (parse_bounded_integer sz) input with
| None -> res == None
| Some (len, consumed_len) ->
consumed_len == sz /\ (
if f len
then begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
else res == None
))
= parse_vldata_gen_eq_def sz f p;
and_then_eq #_ #(parse_filter_refine f) (parse_filter (parse_bounded_integer sz) f) #_ #t (parse_vldata_payload sz f p) input;
parse_filter_eq #_ #(bounded_integer sz) (parse_bounded_integer sz) f input;
parser_kind_prop_equiv (parse_bounded_integer_kind sz) (parse_bounded_integer sz);
()
let parse_vldata_gen_eq_some_elim
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(requires (Some? (parse (parse_vldata_gen sz f p) input)))
(ensures (
let pbi = parse (parse_bounded_integer sz) input in
Some? pbi /\ (
let Some (len, consumed_len) = pbi in
consumed_len == sz /\
f len /\
Seq.length input >= sz + U32.v len /\ (
let input' = Seq.slice input sz (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let Some (x, consumed_x) = pp in
consumed_x = U32.v len /\
parse (parse_vldata_gen sz f p) input == Some (x, sz + U32.v len)
)))))
= parse_vldata_gen_eq sz f p input
let unconstrained_bounded_integer
(sz: integer_size)
(i: bounded_integer sz)
: GTot bool
= true
let parse_vldata
(sz: integer_size)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser _ t)
= parse_vldata_gen sz (unconstrained_bounded_integer sz) p
let parse_vldata_eq
(sz: integer_size)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(parse (parse_vldata sz p) input == (match parse (parse_bounded_integer sz) input with
| None -> None
| Some (len, _) ->
begin
if Seq.length input < sz + U32.v len
then None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then Some (x, sz + U32.v len)
else None
| _ -> None
end
))
= parse_vldata_gen_eq sz (unconstrained_bounded_integer _) p input
(** Explicit bounds on size *)
#reset-options
inline_for_extraction
let parse_bounded_vldata_strong_kind
(min: nat)
(max: nat)
(l: nat)
(k: parser_kind)
: Pure parser_kind
(requires (min <= max /\ max > 0 /\ max < 4294967296 /\ l >= log256' max /\ l <= 4 ))
(ensures (fun _ -> True))
= [@inline_let]
let kmin = k.parser_kind_low in
[@inline_let]
let min' = if kmin > min then kmin else min in
[@inline_let]
let max' = match k.parser_kind_high with
| None -> max
| Some kmax -> if kmax < max then kmax else max
in
[@inline_let]
let max' = if max' < min' then min' else max' in
(* the size of the length prefix must conform to the max bound given by the user, not on the metadata *)
strong_parser_kind (l + min') (l + max') (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_bounded_vldata_elim'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(xbytes: bytes)
(x: t)
(consumed: consumed_length xbytes)
: Lemma
(requires (parse (parse_vldata_gen l (in_bounds min max) p) xbytes == Some (x, consumed)))
(ensures (
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
Some? plen /\ (
let (Some (len, consumed_len)) = plen in
(consumed_len <: nat) == (sz <: nat) /\
in_bounds min max len /\
U32.v len <= Seq.length xbytes - sz /\ (
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let (Some (x', consumed_p)) = pp in
x' == x /\
(consumed_p <: nat) == U32.v len /\
(consumed <: nat) == sz + U32.v len
)))))
= parse_vldata_gen_eq l (in_bounds min max) p xbytes;
parser_kind_prop_equiv (parse_bounded_integer_kind l) (parse_bounded_integer l)
let parse_bounded_vldata_correct
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(parser_kind_prop (parse_bounded_vldata_strong_kind min max l k) (parse_vldata_gen l (in_bounds min max) p))
= parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l k) (parse_vldata_gen l (in_bounds min max) p);
let sz : integer_size = l in
let p' = parse_vldata_gen sz (in_bounds min max) p in
parser_kind_prop_equiv (get_parser_kind p') p';
parser_kind_prop_equiv k p;
let k' = parse_bounded_vldata_strong_kind min max l k in
let prf
(input: bytes)
: Lemma
(requires (Some? (parse p' input)))
(ensures (
let pi = parse p' input in
Some? pi /\ (
let (Some (_, consumed)) = pi in
k'.parser_kind_low <= (consumed <: nat) /\
(consumed <: nat) <= Some?.v k'.parser_kind_high
)))
= let (Some (data, consumed)) = parse p' input in
parse_bounded_vldata_elim' min max l p input data consumed
in
Classical.forall_intro (Classical.move_requires prf)
let parse_bounded_vldata'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_bounded_vldata_strong_kind min max l k) t)
= parse_bounded_vldata_correct min max l p;
strengthen (parse_bounded_vldata_strong_kind min max l k) (parse_vldata_gen l (in_bounds min max) p)
let parse_bounded_vldata
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_bounded_vldata_strong_kind min max (log256' max) k) t)
= parse_bounded_vldata' min max (log256' max) p
let parse_bounded_vldata_elim
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(xbytes: bytes)
(x: t)
(consumed: consumed_length xbytes)
: Lemma
(requires (parse (parse_bounded_vldata' min max l p) xbytes == Some (x, consumed)))
(ensures (
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
Some? plen /\ (
let (Some (len, consumed_len)) = plen in
(consumed_len <: nat) == (sz <: nat) /\
in_bounds min max len /\
U32.v len <= Seq.length xbytes - sz /\ (
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let (Some (x', consumed_p)) = pp in
x' == x /\
(consumed_p <: nat) == U32.v len /\
(consumed <: nat) == sz + U32.v len
)))))
= parse_bounded_vldata_elim' min max l p xbytes x consumed
let parse_bounded_vldata_elim_forall
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(xbytes: bytes)
: Lemma
(requires (Some? (parse (parse_bounded_vldata' min max l p) xbytes)))
(ensures (
let (Some (x, consumed)) = parse (parse_bounded_vldata' min max l p) xbytes in
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
Some? plen /\ (
let (Some (len, consumed_len)) = plen in
(consumed_len <: nat) == (sz <: nat) /\
in_bounds min max len /\
U32.v len <= Seq.length xbytes - sz /\ (
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let (Some (x', consumed_p)) = pp in
x' == x /\
(consumed_p <: nat) == U32.v len /\
(consumed <: nat) == sz + U32.v len
)))))
= let (Some (x, consumed)) = parse (parse_bounded_vldata' min max l p) xbytes in
parse_bounded_vldata_elim min max l p xbytes x consumed
(* Serialization *)
let parse_bounded_vldata_strong_pred
(min: nat)
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: GTot Type0
= let reslen = Seq.length (s x) in
min <= reslen /\ reslen <= max
let parse_bounded_vldata_strong_t
(min: nat)
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t { parse_bounded_vldata_strong_pred min max s x } )
let parse_bounded_vldata_strong_correct
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(xbytes: bytes)
(consumed: consumed_length xbytes)
(x: t)
: Lemma
(requires (parse (parse_bounded_vldata' min max l p) xbytes == Some (x, consumed)))
(ensures (parse_bounded_vldata_strong_pred min max s x))
= parse_bounded_vldata_elim min max l p xbytes x consumed;
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
let f () : Lemma (Some? plen) =
parse_bounded_vldata_elim min max l p xbytes x consumed
in
f ();
let (Some (len, _)) = plen in
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
assert (Seq.equal input' (Seq.slice input' 0 (U32.v len)));
serializer_correct_implies_complete p s;
assert (s x == input');
()
let parse_bounded_vldata_strong'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (parser (parse_bounded_vldata_strong_kind min max l k) (parse_bounded_vldata_strong_t min max s))
= // strengthen (parse_bounded_vldata_strong_kind min max k)
(
coerce_parser
(parse_bounded_vldata_strong_t min max s)
(parse_strengthen (parse_bounded_vldata' min max l p) (parse_bounded_vldata_strong_pred min max s) (parse_bounded_vldata_strong_correct min max l s))
)
let parse_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (parser (parse_bounded_vldata_strong_kind min max (log256' max) k) (parse_bounded_vldata_strong_t min max s))
= parse_bounded_vldata_strong' min max (log256' max) s
let serialize_bounded_vldata_strong_aux
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (bare_serializer (parse_bounded_vldata_strong_t min max s))
= (fun (x: parse_bounded_vldata_strong_t min max s) ->
let pl = s x in
let sz = l in
let nlen = Seq.length pl in
assert (min <= nlen /\ nlen <= max);
let len = U32.uint_to_t nlen in
let slen = serialize (serialize_bounded_integer sz) len in
seq_slice_append_l slen pl;
seq_slice_append_r slen pl;
Seq.append slen pl
)
let serialize_vldata_gen_correct_aux
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b b1 b2: bytes)
: Lemma
(requires (
Seq.length b1 == sz /\ (
let vlen = parse (parse_bounded_integer sz) b1 in
Some? vlen /\ (
let (Some (len, _)) = vlen in
f len == true /\
Seq.length b2 == U32.v len /\ (
let vv = parse p b2 in
Some? vv /\ (
let (Some (_, consumed)) = vv in
consumed == Seq.length b2 /\
Seq.length b1 <= Seq.length b /\
Seq.slice b 0 (Seq.length b1) == b1 /\
Seq.slice b (Seq.length b1) (Seq.length b) == b2
))))))
(ensures (
let vv = parse p b2 in
Some? vv /\ (
let (Some (v, consumed)) = vv in
let vv' = parse (parse_vldata_gen sz f p) b in
Some? vv' /\ (
let (Some (v', consumed')) = vv' in
v == v' /\
consumed == Seq.length b2 /\
consumed' == Seq.length b
)))) =
let (Some (len, consumed1)) = parse (parse_bounded_integer sz) b1 in
parser_kind_prop_equiv (parse_bounded_integer_kind sz) (parse_bounded_integer sz);
assert (consumed1 == sz);
assert (no_lookahead_on (parse_bounded_integer sz) b1 b);
assert (injective_postcond (parse_bounded_integer sz) b1 b);
assert (parse (parse_bounded_integer sz) b == Some (len, sz));
assert (sz + U32.v len == Seq.length b);
assert (b2 == Seq.slice b sz (sz + U32.v len));
parse_vldata_gen_eq sz f p b
let serialize_vldata_gen_correct
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b1 b2: bytes)
: Lemma
(requires (
Seq.length b1 == sz /\ (
let vlen = parse (parse_bounded_integer sz) b1 in
Some? vlen /\ (
let (Some (len, _)) = vlen in
f len == true /\
Seq.length b2 == U32.v len /\ (
let vv = parse p b2 in
Some? vv /\ (
let (Some (_, consumed)) = vv in
consumed == Seq.length b2
))))))
(ensures (
let vv = parse p b2 in
Some? vv /\ (
let (Some (v, consumed)) = vv in
let vv' = parse (parse_vldata_gen sz f p) (Seq.append b1 b2) in
Some? vv' /\ (
let (Some (v', consumed')) = vv' in
v == v' /\
consumed == Seq.length b2 /\
consumed' == sz + Seq.length b2 | false | false | LowParse.Spec.VLData.fsti | {
"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"
} | null | val serialize_vldata_gen_correct
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b1 b2: bytes)
: Lemma
(requires
(Seq.length b1 == sz /\
(let vlen = parse (parse_bounded_integer sz) b1 in
Some? vlen /\
(let Some (len, _) = vlen in
f len == true /\ Seq.length b2 == U32.v len /\
(let vv = parse p b2 in
Some? vv /\
(let Some (_, consumed) = vv in
consumed == Seq.length b2))))))
(ensures
(let vv = parse p b2 in
Some? vv /\
(let Some (v, consumed) = vv in
let vv' = parse (parse_vldata_gen sz f p) (Seq.append b1 b2) in
Some? vv' /\
(let Some (v', consumed') = vv' in
v == v' /\ consumed == Seq.length b2 /\ consumed' == sz + Seq.length b2)))) | [] | LowParse.Spec.VLData.serialize_vldata_gen_correct | {
"file_name": "src/lowparse/LowParse.Spec.VLData.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
sz: LowParse.Spec.BoundedInt.integer_size ->
f: (_: LowParse.Spec.BoundedInt.bounded_integer sz -> Prims.GTot Prims.bool) ->
p: LowParse.Spec.Base.parser k t ->
b1: LowParse.Bytes.bytes ->
b2: LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(requires
FStar.Seq.Base.length b1 == sz /\
(let vlen =
LowParse.Spec.Base.parse (LowParse.Spec.BoundedInt.parse_bounded_integer sz) b1
in
Some? vlen /\
(let _ = vlen in
(let FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ len _) =
_
in
f len == true /\ FStar.Seq.Base.length b2 == FStar.UInt32.v len /\
(let vv = LowParse.Spec.Base.parse p b2 in
Some? vv /\
(let _ = vv in
(let
FStar.Pervasives.Native.Some
#_
(FStar.Pervasives.Native.Mktuple2 #_ #_ _ consumed) =
_
in
consumed == FStar.Seq.Base.length b2)
<:
Prims.logical)))
<:
Prims.logical)))
(ensures
(let vv = LowParse.Spec.Base.parse p b2 in
Some? vv /\
(let _ = vv in
(let FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ v consumed)
=
_
in
let vv' =
LowParse.Spec.Base.parse (LowParse.Spec.VLData.parse_vldata_gen sz f p)
(FStar.Seq.Base.append b1 b2)
in
Some? vv' /\
(let _ = vv' in
(let
FStar.Pervasives.Native.Some
#_
(FStar.Pervasives.Native.Mktuple2 #_ #_ v' consumed') =
_
in
v == v' /\ consumed == FStar.Seq.Base.length b2 /\
consumed' == sz + FStar.Seq.Base.length b2)
<:
Prims.logical))
<:
Prims.logical))) | {
"end_col": 66,
"end_line": 570,
"start_col": 2,
"start_line": 568
} |
FStar.Pervasives.Lemma | val parse_fldata_and_then_cases_injective
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma (and_then_cases_injective (parse_vldata_payload sz f p)) | [
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_fldata_and_then_cases_injective
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p))
= parser_kind_prop_equiv k p;
let g
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1 b2: bytes)
: Lemma
(requires (and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2))
(ensures (len1 == len2))
= assert (injective_precond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (injective_postcond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (len1 == len2)
in
let g'
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1: bytes)
: Lemma
(forall (b2: bytes) . and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2 ==> len1 == len2)
= Classical.forall_intro (Classical.move_requires (g len1 len2 b1))
in
Classical.forall_intro_3 g' | val parse_fldata_and_then_cases_injective
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma (and_then_cases_injective (parse_vldata_payload sz f p))
let parse_fldata_and_then_cases_injective
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma (and_then_cases_injective (parse_vldata_payload sz f p)) = | false | null | true | parser_kind_prop_equiv k p;
let g (len1 len2: (len: bounded_integer sz {f len == true})) (b1 b2: bytes)
: Lemma
(requires (and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2))
(ensures (len1 == len2)) =
assert (injective_precond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (injective_postcond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (len1 == len2)
in
let g' (len1 len2: (len: bounded_integer sz {f len == true})) (b1: bytes)
: Lemma
(forall (b2: bytes).
and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2 ==>
len1 == len2) =
Classical.forall_intro (Classical.move_requires (g len1 len2 b1))
in
Classical.forall_intro_3 g' | {
"checked_file": "LowParse.Spec.VLData.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLData.fsti"
} | [
"lemma"
] | [
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.BoundedInt.bounded_integer",
"Prims.bool",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"FStar.Classical.forall_intro_3",
"Prims.eq2",
"LowParse.Bytes.bytes",
"Prims.l_Forall",
"Prims.l_imp",
"LowParse.Spec.Combinators.and_then_cases_injective_precond",
"LowParse.Spec.VLData.parse_vldata_payload",
"Prims.l_or",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"FStar.Classical.forall_intro",
"FStar.Classical.move_requires",
"Prims._assert",
"LowParse.Spec.Base.injective_postcond",
"FStar.Seq.Base.slice",
"LowParse.Bytes.byte",
"FStar.UInt32.v",
"LowParse.Spec.Base.injective_precond",
"LowParse.Spec.Base.parser_kind_prop_equiv",
"LowParse.Spec.Combinators.and_then_cases_injective"
] | [] | module LowParse.Spec.VLData
include LowParse.Spec.FLData
include LowParse.Spec.AllIntegers // for bounded_integer, in_bounds, etc.
module Seq = FStar.Seq
module U32 = FStar.UInt32
module M = LowParse.Math
#reset-options "--z3rlimit 64 --max_fuel 64 --max_ifuel 64 --z3refresh --z3cliopt smt.arith.nl=false"
let parse_vldata_payload_size
(sz: integer_size)
: Pure nat
(requires True)
(ensures (fun y -> y == pow2 (FStar.Mul.op_Star 8 sz) - 1 ))
= match sz with
| 1 -> 255
| 2 -> 65535
| 3 -> 16777215
| 4 -> 4294967295
#reset-options
// unfold
let parse_vldata_payload_kind
(sz: integer_size)
(k: parser_kind)
: parser_kind
= strong_parser_kind 0 (parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_payload
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(i: bounded_integer sz { f i == true } )
: Tot (parser (parse_vldata_payload_kind sz k) t)
= weaken (parse_vldata_payload_kind sz k) (parse_fldata p (U32.v i))
#set-options "--z3rlimit 64"
let parse_fldata_and_then_cases_injective
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma | false | false | LowParse.Spec.VLData.fsti | {
"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": 64,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val parse_fldata_and_then_cases_injective
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma (and_then_cases_injective (parse_vldata_payload sz f p)) | [] | LowParse.Spec.VLData.parse_fldata_and_then_cases_injective | {
"file_name": "src/lowparse/LowParse.Spec.VLData.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
sz: LowParse.Spec.BoundedInt.integer_size ->
f: (_: LowParse.Spec.BoundedInt.bounded_integer sz -> Prims.GTot Prims.bool) ->
p: LowParse.Spec.Base.parser k t
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.Combinators.and_then_cases_injective (LowParse.Spec.VLData.parse_vldata_payload sz
f
p)) | {
"end_col": 29,
"end_line": 73,
"start_col": 2,
"start_line": 55
} |
Prims.Tot | val serialize_bounded_vldata_strong
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bounded_vldata_strong min max s)) | [
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialize_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bounded_vldata_strong min max s))
= serialize_bounded_vldata_strong' min max (log256' max) s | val serialize_bounded_vldata_strong
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bounded_vldata_strong min max s))
let serialize_bounded_vldata_strong
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bounded_vldata_strong min max s)) = | false | null | false | serialize_bounded_vldata_strong' min max (log256' max) s | {
"checked_file": "LowParse.Spec.VLData.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLData.fsti"
} | [
"total"
] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Spec.VLData.serialize_bounded_vldata_strong'",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t",
"LowParse.Spec.VLData.parse_bounded_vldata_strong"
] | [] | module LowParse.Spec.VLData
include LowParse.Spec.FLData
include LowParse.Spec.AllIntegers // for bounded_integer, in_bounds, etc.
module Seq = FStar.Seq
module U32 = FStar.UInt32
module M = LowParse.Math
#reset-options "--z3rlimit 64 --max_fuel 64 --max_ifuel 64 --z3refresh --z3cliopt smt.arith.nl=false"
let parse_vldata_payload_size
(sz: integer_size)
: Pure nat
(requires True)
(ensures (fun y -> y == pow2 (FStar.Mul.op_Star 8 sz) - 1 ))
= match sz with
| 1 -> 255
| 2 -> 65535
| 3 -> 16777215
| 4 -> 4294967295
#reset-options
// unfold
let parse_vldata_payload_kind
(sz: integer_size)
(k: parser_kind)
: parser_kind
= strong_parser_kind 0 (parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_payload
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(i: bounded_integer sz { f i == true } )
: Tot (parser (parse_vldata_payload_kind sz k) t)
= weaken (parse_vldata_payload_kind sz k) (parse_fldata p (U32.v i))
#set-options "--z3rlimit 64"
let parse_fldata_and_then_cases_injective
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p))
= parser_kind_prop_equiv k p;
let g
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1 b2: bytes)
: Lemma
(requires (and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2))
(ensures (len1 == len2))
= assert (injective_precond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (injective_postcond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (len1 == len2)
in
let g'
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1: bytes)
: Lemma
(forall (b2: bytes) . and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2 ==> len1 == len2)
= Classical.forall_intro (Classical.move_requires (g len1 len2 b1))
in
Classical.forall_intro_3 g'
#reset-options
// unfold
let parse_vldata_gen_kind
(sz: integer_size)
(k: parser_kind)
: Tot parser_kind
= strong_parser_kind sz (sz + parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_gen_kind_correct
(sz: integer_size)
(k: parser_kind)
: Lemma
( (parse_vldata_gen_kind sz k) == (and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k)))
= let kl = parse_vldata_gen_kind sz k in
let kr = and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) in
assert_norm (kl == kr)
val parse_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_vldata_gen_kind sz k) t)
val parse_vldata_gen_eq_def
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p) /\
parse_vldata_gen_kind sz k == and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) /\
parse_vldata_gen sz f p ==
and_then
#_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t
(parse_vldata_payload sz f p))
let parse_vldata_gen_eq
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(let res = parse (parse_vldata_gen sz f p) input in
match parse (parse_bounded_integer sz) input with
| None -> res == None
| Some (len, consumed_len) ->
consumed_len == sz /\ (
if f len
then begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
else res == None
))
= parse_vldata_gen_eq_def sz f p;
and_then_eq #_ #(parse_filter_refine f) (parse_filter (parse_bounded_integer sz) f) #_ #t (parse_vldata_payload sz f p) input;
parse_filter_eq #_ #(bounded_integer sz) (parse_bounded_integer sz) f input;
parser_kind_prop_equiv (parse_bounded_integer_kind sz) (parse_bounded_integer sz);
()
let parse_vldata_gen_eq_some_elim
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(requires (Some? (parse (parse_vldata_gen sz f p) input)))
(ensures (
let pbi = parse (parse_bounded_integer sz) input in
Some? pbi /\ (
let Some (len, consumed_len) = pbi in
consumed_len == sz /\
f len /\
Seq.length input >= sz + U32.v len /\ (
let input' = Seq.slice input sz (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let Some (x, consumed_x) = pp in
consumed_x = U32.v len /\
parse (parse_vldata_gen sz f p) input == Some (x, sz + U32.v len)
)))))
= parse_vldata_gen_eq sz f p input
let unconstrained_bounded_integer
(sz: integer_size)
(i: bounded_integer sz)
: GTot bool
= true
let parse_vldata
(sz: integer_size)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser _ t)
= parse_vldata_gen sz (unconstrained_bounded_integer sz) p
let parse_vldata_eq
(sz: integer_size)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(parse (parse_vldata sz p) input == (match parse (parse_bounded_integer sz) input with
| None -> None
| Some (len, _) ->
begin
if Seq.length input < sz + U32.v len
then None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then Some (x, sz + U32.v len)
else None
| _ -> None
end
))
= parse_vldata_gen_eq sz (unconstrained_bounded_integer _) p input
(** Explicit bounds on size *)
#reset-options
inline_for_extraction
let parse_bounded_vldata_strong_kind
(min: nat)
(max: nat)
(l: nat)
(k: parser_kind)
: Pure parser_kind
(requires (min <= max /\ max > 0 /\ max < 4294967296 /\ l >= log256' max /\ l <= 4 ))
(ensures (fun _ -> True))
= [@inline_let]
let kmin = k.parser_kind_low in
[@inline_let]
let min' = if kmin > min then kmin else min in
[@inline_let]
let max' = match k.parser_kind_high with
| None -> max
| Some kmax -> if kmax < max then kmax else max
in
[@inline_let]
let max' = if max' < min' then min' else max' in
(* the size of the length prefix must conform to the max bound given by the user, not on the metadata *)
strong_parser_kind (l + min') (l + max') (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_bounded_vldata_elim'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(xbytes: bytes)
(x: t)
(consumed: consumed_length xbytes)
: Lemma
(requires (parse (parse_vldata_gen l (in_bounds min max) p) xbytes == Some (x, consumed)))
(ensures (
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
Some? plen /\ (
let (Some (len, consumed_len)) = plen in
(consumed_len <: nat) == (sz <: nat) /\
in_bounds min max len /\
U32.v len <= Seq.length xbytes - sz /\ (
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let (Some (x', consumed_p)) = pp in
x' == x /\
(consumed_p <: nat) == U32.v len /\
(consumed <: nat) == sz + U32.v len
)))))
= parse_vldata_gen_eq l (in_bounds min max) p xbytes;
parser_kind_prop_equiv (parse_bounded_integer_kind l) (parse_bounded_integer l)
let parse_bounded_vldata_correct
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(parser_kind_prop (parse_bounded_vldata_strong_kind min max l k) (parse_vldata_gen l (in_bounds min max) p))
= parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l k) (parse_vldata_gen l (in_bounds min max) p);
let sz : integer_size = l in
let p' = parse_vldata_gen sz (in_bounds min max) p in
parser_kind_prop_equiv (get_parser_kind p') p';
parser_kind_prop_equiv k p;
let k' = parse_bounded_vldata_strong_kind min max l k in
let prf
(input: bytes)
: Lemma
(requires (Some? (parse p' input)))
(ensures (
let pi = parse p' input in
Some? pi /\ (
let (Some (_, consumed)) = pi in
k'.parser_kind_low <= (consumed <: nat) /\
(consumed <: nat) <= Some?.v k'.parser_kind_high
)))
= let (Some (data, consumed)) = parse p' input in
parse_bounded_vldata_elim' min max l p input data consumed
in
Classical.forall_intro (Classical.move_requires prf)
let parse_bounded_vldata'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_bounded_vldata_strong_kind min max l k) t)
= parse_bounded_vldata_correct min max l p;
strengthen (parse_bounded_vldata_strong_kind min max l k) (parse_vldata_gen l (in_bounds min max) p)
let parse_bounded_vldata
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_bounded_vldata_strong_kind min max (log256' max) k) t)
= parse_bounded_vldata' min max (log256' max) p
let parse_bounded_vldata_elim
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(xbytes: bytes)
(x: t)
(consumed: consumed_length xbytes)
: Lemma
(requires (parse (parse_bounded_vldata' min max l p) xbytes == Some (x, consumed)))
(ensures (
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
Some? plen /\ (
let (Some (len, consumed_len)) = plen in
(consumed_len <: nat) == (sz <: nat) /\
in_bounds min max len /\
U32.v len <= Seq.length xbytes - sz /\ (
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let (Some (x', consumed_p)) = pp in
x' == x /\
(consumed_p <: nat) == U32.v len /\
(consumed <: nat) == sz + U32.v len
)))))
= parse_bounded_vldata_elim' min max l p xbytes x consumed
let parse_bounded_vldata_elim_forall
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(xbytes: bytes)
: Lemma
(requires (Some? (parse (parse_bounded_vldata' min max l p) xbytes)))
(ensures (
let (Some (x, consumed)) = parse (parse_bounded_vldata' min max l p) xbytes in
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
Some? plen /\ (
let (Some (len, consumed_len)) = plen in
(consumed_len <: nat) == (sz <: nat) /\
in_bounds min max len /\
U32.v len <= Seq.length xbytes - sz /\ (
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let (Some (x', consumed_p)) = pp in
x' == x /\
(consumed_p <: nat) == U32.v len /\
(consumed <: nat) == sz + U32.v len
)))))
= let (Some (x, consumed)) = parse (parse_bounded_vldata' min max l p) xbytes in
parse_bounded_vldata_elim min max l p xbytes x consumed
(* Serialization *)
let parse_bounded_vldata_strong_pred
(min: nat)
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: GTot Type0
= let reslen = Seq.length (s x) in
min <= reslen /\ reslen <= max
let parse_bounded_vldata_strong_t
(min: nat)
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t { parse_bounded_vldata_strong_pred min max s x } )
let parse_bounded_vldata_strong_correct
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(xbytes: bytes)
(consumed: consumed_length xbytes)
(x: t)
: Lemma
(requires (parse (parse_bounded_vldata' min max l p) xbytes == Some (x, consumed)))
(ensures (parse_bounded_vldata_strong_pred min max s x))
= parse_bounded_vldata_elim min max l p xbytes x consumed;
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
let f () : Lemma (Some? plen) =
parse_bounded_vldata_elim min max l p xbytes x consumed
in
f ();
let (Some (len, _)) = plen in
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
assert (Seq.equal input' (Seq.slice input' 0 (U32.v len)));
serializer_correct_implies_complete p s;
assert (s x == input');
()
let parse_bounded_vldata_strong'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (parser (parse_bounded_vldata_strong_kind min max l k) (parse_bounded_vldata_strong_t min max s))
= // strengthen (parse_bounded_vldata_strong_kind min max k)
(
coerce_parser
(parse_bounded_vldata_strong_t min max s)
(parse_strengthen (parse_bounded_vldata' min max l p) (parse_bounded_vldata_strong_pred min max s) (parse_bounded_vldata_strong_correct min max l s))
)
let parse_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (parser (parse_bounded_vldata_strong_kind min max (log256' max) k) (parse_bounded_vldata_strong_t min max s))
= parse_bounded_vldata_strong' min max (log256' max) s
let serialize_bounded_vldata_strong_aux
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (bare_serializer (parse_bounded_vldata_strong_t min max s))
= (fun (x: parse_bounded_vldata_strong_t min max s) ->
let pl = s x in
let sz = l in
let nlen = Seq.length pl in
assert (min <= nlen /\ nlen <= max);
let len = U32.uint_to_t nlen in
let slen = serialize (serialize_bounded_integer sz) len in
seq_slice_append_l slen pl;
seq_slice_append_r slen pl;
Seq.append slen pl
)
let serialize_vldata_gen_correct_aux
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b b1 b2: bytes)
: Lemma
(requires (
Seq.length b1 == sz /\ (
let vlen = parse (parse_bounded_integer sz) b1 in
Some? vlen /\ (
let (Some (len, _)) = vlen in
f len == true /\
Seq.length b2 == U32.v len /\ (
let vv = parse p b2 in
Some? vv /\ (
let (Some (_, consumed)) = vv in
consumed == Seq.length b2 /\
Seq.length b1 <= Seq.length b /\
Seq.slice b 0 (Seq.length b1) == b1 /\
Seq.slice b (Seq.length b1) (Seq.length b) == b2
))))))
(ensures (
let vv = parse p b2 in
Some? vv /\ (
let (Some (v, consumed)) = vv in
let vv' = parse (parse_vldata_gen sz f p) b in
Some? vv' /\ (
let (Some (v', consumed')) = vv' in
v == v' /\
consumed == Seq.length b2 /\
consumed' == Seq.length b
)))) =
let (Some (len, consumed1)) = parse (parse_bounded_integer sz) b1 in
parser_kind_prop_equiv (parse_bounded_integer_kind sz) (parse_bounded_integer sz);
assert (consumed1 == sz);
assert (no_lookahead_on (parse_bounded_integer sz) b1 b);
assert (injective_postcond (parse_bounded_integer sz) b1 b);
assert (parse (parse_bounded_integer sz) b == Some (len, sz));
assert (sz + U32.v len == Seq.length b);
assert (b2 == Seq.slice b sz (sz + U32.v len));
parse_vldata_gen_eq sz f p b
let serialize_vldata_gen_correct
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b1 b2: bytes)
: Lemma
(requires (
Seq.length b1 == sz /\ (
let vlen = parse (parse_bounded_integer sz) b1 in
Some? vlen /\ (
let (Some (len, _)) = vlen in
f len == true /\
Seq.length b2 == U32.v len /\ (
let vv = parse p b2 in
Some? vv /\ (
let (Some (_, consumed)) = vv in
consumed == Seq.length b2
))))))
(ensures (
let vv = parse p b2 in
Some? vv /\ (
let (Some (v, consumed)) = vv in
let vv' = parse (parse_vldata_gen sz f p) (Seq.append b1 b2) in
Some? vv' /\ (
let (Some (v', consumed')) = vv' in
v == v' /\
consumed == Seq.length b2 /\
consumed' == sz + Seq.length b2
)))) =
seq_slice_append_l b1 b2;
seq_slice_append_r b1 b2;
serialize_vldata_gen_correct_aux sz f p (Seq.append b1 b2) b1 b2
let serialize_bounded_vldata_strong_correct
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: parse_bounded_vldata_strong_t min max s)
: Lemma
(let formatted = serialize_bounded_vldata_strong_aux min max l s input in
parse (parse_bounded_vldata_strong' min max l s) formatted == Some (input, Seq.length formatted))
= let sz = l in
let sp = serialize s input in
let nlen = Seq.length sp in
assert (min <= nlen /\ nlen <= max);
let len = U32.uint_to_t nlen in
M.pow2_le_compat (FStar.Mul.op_Star 8 sz) (FStar.Mul.op_Star 8 (log256' max));
assert (U32.v len < pow2 (FStar.Mul.op_Star 8 sz));
let (len: bounded_integer sz) = len in
let slen = serialize (serialize_bounded_integer sz) len in
assert (Seq.length slen == sz);
let pslen = parse (parse_bounded_integer sz) slen in
assert (Some? pslen);
let (Some (len', consumed_len')) = pslen in
assert (len == len');
assert (in_bounds min max len' == true);
assert (Seq.length sp == U32.v len);
let psp = parse p sp in
assert (Some? psp);
let (Some (_, consumed_p)) = psp in
assert ((consumed_p <: nat) == Seq.length sp);
serialize_vldata_gen_correct sz (in_bounds min max) p
slen
sp
;
()
let serialize_bounded_vldata_strong'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bounded_vldata_strong' min max l s))
= Classical.forall_intro (serialize_bounded_vldata_strong_correct min max l s);
serialize_bounded_vldata_strong_aux min max l s
let serialize_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p) | false | false | LowParse.Spec.VLData.fsti | {
"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"
} | null | val serialize_bounded_vldata_strong
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bounded_vldata_strong min max s)) | [] | LowParse.Spec.VLData.serialize_bounded_vldata_strong | {
"file_name": "src/lowparse/LowParse.Spec.VLData.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
s: LowParse.Spec.Base.serializer p
-> LowParse.Spec.Base.serializer (LowParse.Spec.VLData.parse_bounded_vldata_strong min max s) | {
"end_col": 58,
"end_line": 630,
"start_col": 2,
"start_line": 630
} |
Prims.Tot | val parse_bounded_vldata_strong
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot
(parser (parse_bounded_vldata_strong_kind min max (log256' max) k)
(parse_bounded_vldata_strong_t min max s)) | [
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (parser (parse_bounded_vldata_strong_kind min max (log256' max) k) (parse_bounded_vldata_strong_t min max s))
= parse_bounded_vldata_strong' min max (log256' max) s | val parse_bounded_vldata_strong
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot
(parser (parse_bounded_vldata_strong_kind min max (log256' max) k)
(parse_bounded_vldata_strong_t min max s))
let parse_bounded_vldata_strong
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot
(parser (parse_bounded_vldata_strong_kind min max (log256' max) k)
(parse_bounded_vldata_strong_t min max s)) = | false | null | false | parse_bounded_vldata_strong' min max (log256' max) s | {
"checked_file": "LowParse.Spec.VLData.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLData.fsti"
} | [
"total"
] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Spec.VLData.parse_bounded_vldata_strong'",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_t"
] | [] | module LowParse.Spec.VLData
include LowParse.Spec.FLData
include LowParse.Spec.AllIntegers // for bounded_integer, in_bounds, etc.
module Seq = FStar.Seq
module U32 = FStar.UInt32
module M = LowParse.Math
#reset-options "--z3rlimit 64 --max_fuel 64 --max_ifuel 64 --z3refresh --z3cliopt smt.arith.nl=false"
let parse_vldata_payload_size
(sz: integer_size)
: Pure nat
(requires True)
(ensures (fun y -> y == pow2 (FStar.Mul.op_Star 8 sz) - 1 ))
= match sz with
| 1 -> 255
| 2 -> 65535
| 3 -> 16777215
| 4 -> 4294967295
#reset-options
// unfold
let parse_vldata_payload_kind
(sz: integer_size)
(k: parser_kind)
: parser_kind
= strong_parser_kind 0 (parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_payload
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(i: bounded_integer sz { f i == true } )
: Tot (parser (parse_vldata_payload_kind sz k) t)
= weaken (parse_vldata_payload_kind sz k) (parse_fldata p (U32.v i))
#set-options "--z3rlimit 64"
let parse_fldata_and_then_cases_injective
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p))
= parser_kind_prop_equiv k p;
let g
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1 b2: bytes)
: Lemma
(requires (and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2))
(ensures (len1 == len2))
= assert (injective_precond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (injective_postcond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (len1 == len2)
in
let g'
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1: bytes)
: Lemma
(forall (b2: bytes) . and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2 ==> len1 == len2)
= Classical.forall_intro (Classical.move_requires (g len1 len2 b1))
in
Classical.forall_intro_3 g'
#reset-options
// unfold
let parse_vldata_gen_kind
(sz: integer_size)
(k: parser_kind)
: Tot parser_kind
= strong_parser_kind sz (sz + parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_gen_kind_correct
(sz: integer_size)
(k: parser_kind)
: Lemma
( (parse_vldata_gen_kind sz k) == (and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k)))
= let kl = parse_vldata_gen_kind sz k in
let kr = and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) in
assert_norm (kl == kr)
val parse_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_vldata_gen_kind sz k) t)
val parse_vldata_gen_eq_def
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p) /\
parse_vldata_gen_kind sz k == and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) /\
parse_vldata_gen sz f p ==
and_then
#_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t
(parse_vldata_payload sz f p))
let parse_vldata_gen_eq
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(let res = parse (parse_vldata_gen sz f p) input in
match parse (parse_bounded_integer sz) input with
| None -> res == None
| Some (len, consumed_len) ->
consumed_len == sz /\ (
if f len
then begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
else res == None
))
= parse_vldata_gen_eq_def sz f p;
and_then_eq #_ #(parse_filter_refine f) (parse_filter (parse_bounded_integer sz) f) #_ #t (parse_vldata_payload sz f p) input;
parse_filter_eq #_ #(bounded_integer sz) (parse_bounded_integer sz) f input;
parser_kind_prop_equiv (parse_bounded_integer_kind sz) (parse_bounded_integer sz);
()
let parse_vldata_gen_eq_some_elim
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(requires (Some? (parse (parse_vldata_gen sz f p) input)))
(ensures (
let pbi = parse (parse_bounded_integer sz) input in
Some? pbi /\ (
let Some (len, consumed_len) = pbi in
consumed_len == sz /\
f len /\
Seq.length input >= sz + U32.v len /\ (
let input' = Seq.slice input sz (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let Some (x, consumed_x) = pp in
consumed_x = U32.v len /\
parse (parse_vldata_gen sz f p) input == Some (x, sz + U32.v len)
)))))
= parse_vldata_gen_eq sz f p input
let unconstrained_bounded_integer
(sz: integer_size)
(i: bounded_integer sz)
: GTot bool
= true
let parse_vldata
(sz: integer_size)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser _ t)
= parse_vldata_gen sz (unconstrained_bounded_integer sz) p
let parse_vldata_eq
(sz: integer_size)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(parse (parse_vldata sz p) input == (match parse (parse_bounded_integer sz) input with
| None -> None
| Some (len, _) ->
begin
if Seq.length input < sz + U32.v len
then None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then Some (x, sz + U32.v len)
else None
| _ -> None
end
))
= parse_vldata_gen_eq sz (unconstrained_bounded_integer _) p input
(** Explicit bounds on size *)
#reset-options
inline_for_extraction
let parse_bounded_vldata_strong_kind
(min: nat)
(max: nat)
(l: nat)
(k: parser_kind)
: Pure parser_kind
(requires (min <= max /\ max > 0 /\ max < 4294967296 /\ l >= log256' max /\ l <= 4 ))
(ensures (fun _ -> True))
= [@inline_let]
let kmin = k.parser_kind_low in
[@inline_let]
let min' = if kmin > min then kmin else min in
[@inline_let]
let max' = match k.parser_kind_high with
| None -> max
| Some kmax -> if kmax < max then kmax else max
in
[@inline_let]
let max' = if max' < min' then min' else max' in
(* the size of the length prefix must conform to the max bound given by the user, not on the metadata *)
strong_parser_kind (l + min') (l + max') (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_bounded_vldata_elim'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(xbytes: bytes)
(x: t)
(consumed: consumed_length xbytes)
: Lemma
(requires (parse (parse_vldata_gen l (in_bounds min max) p) xbytes == Some (x, consumed)))
(ensures (
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
Some? plen /\ (
let (Some (len, consumed_len)) = plen in
(consumed_len <: nat) == (sz <: nat) /\
in_bounds min max len /\
U32.v len <= Seq.length xbytes - sz /\ (
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let (Some (x', consumed_p)) = pp in
x' == x /\
(consumed_p <: nat) == U32.v len /\
(consumed <: nat) == sz + U32.v len
)))))
= parse_vldata_gen_eq l (in_bounds min max) p xbytes;
parser_kind_prop_equiv (parse_bounded_integer_kind l) (parse_bounded_integer l)
let parse_bounded_vldata_correct
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(parser_kind_prop (parse_bounded_vldata_strong_kind min max l k) (parse_vldata_gen l (in_bounds min max) p))
= parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l k) (parse_vldata_gen l (in_bounds min max) p);
let sz : integer_size = l in
let p' = parse_vldata_gen sz (in_bounds min max) p in
parser_kind_prop_equiv (get_parser_kind p') p';
parser_kind_prop_equiv k p;
let k' = parse_bounded_vldata_strong_kind min max l k in
let prf
(input: bytes)
: Lemma
(requires (Some? (parse p' input)))
(ensures (
let pi = parse p' input in
Some? pi /\ (
let (Some (_, consumed)) = pi in
k'.parser_kind_low <= (consumed <: nat) /\
(consumed <: nat) <= Some?.v k'.parser_kind_high
)))
= let (Some (data, consumed)) = parse p' input in
parse_bounded_vldata_elim' min max l p input data consumed
in
Classical.forall_intro (Classical.move_requires prf)
let parse_bounded_vldata'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_bounded_vldata_strong_kind min max l k) t)
= parse_bounded_vldata_correct min max l p;
strengthen (parse_bounded_vldata_strong_kind min max l k) (parse_vldata_gen l (in_bounds min max) p)
let parse_bounded_vldata
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_bounded_vldata_strong_kind min max (log256' max) k) t)
= parse_bounded_vldata' min max (log256' max) p
let parse_bounded_vldata_elim
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(xbytes: bytes)
(x: t)
(consumed: consumed_length xbytes)
: Lemma
(requires (parse (parse_bounded_vldata' min max l p) xbytes == Some (x, consumed)))
(ensures (
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
Some? plen /\ (
let (Some (len, consumed_len)) = plen in
(consumed_len <: nat) == (sz <: nat) /\
in_bounds min max len /\
U32.v len <= Seq.length xbytes - sz /\ (
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let (Some (x', consumed_p)) = pp in
x' == x /\
(consumed_p <: nat) == U32.v len /\
(consumed <: nat) == sz + U32.v len
)))))
= parse_bounded_vldata_elim' min max l p xbytes x consumed
let parse_bounded_vldata_elim_forall
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(xbytes: bytes)
: Lemma
(requires (Some? (parse (parse_bounded_vldata' min max l p) xbytes)))
(ensures (
let (Some (x, consumed)) = parse (parse_bounded_vldata' min max l p) xbytes in
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
Some? plen /\ (
let (Some (len, consumed_len)) = plen in
(consumed_len <: nat) == (sz <: nat) /\
in_bounds min max len /\
U32.v len <= Seq.length xbytes - sz /\ (
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let (Some (x', consumed_p)) = pp in
x' == x /\
(consumed_p <: nat) == U32.v len /\
(consumed <: nat) == sz + U32.v len
)))))
= let (Some (x, consumed)) = parse (parse_bounded_vldata' min max l p) xbytes in
parse_bounded_vldata_elim min max l p xbytes x consumed
(* Serialization *)
let parse_bounded_vldata_strong_pred
(min: nat)
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: GTot Type0
= let reslen = Seq.length (s x) in
min <= reslen /\ reslen <= max
let parse_bounded_vldata_strong_t
(min: nat)
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t { parse_bounded_vldata_strong_pred min max s x } )
let parse_bounded_vldata_strong_correct
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(xbytes: bytes)
(consumed: consumed_length xbytes)
(x: t)
: Lemma
(requires (parse (parse_bounded_vldata' min max l p) xbytes == Some (x, consumed)))
(ensures (parse_bounded_vldata_strong_pred min max s x))
= parse_bounded_vldata_elim min max l p xbytes x consumed;
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
let f () : Lemma (Some? plen) =
parse_bounded_vldata_elim min max l p xbytes x consumed
in
f ();
let (Some (len, _)) = plen in
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
assert (Seq.equal input' (Seq.slice input' 0 (U32.v len)));
serializer_correct_implies_complete p s;
assert (s x == input');
()
let parse_bounded_vldata_strong'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (parser (parse_bounded_vldata_strong_kind min max l k) (parse_bounded_vldata_strong_t min max s))
= // strengthen (parse_bounded_vldata_strong_kind min max k)
(
coerce_parser
(parse_bounded_vldata_strong_t min max s)
(parse_strengthen (parse_bounded_vldata' min max l p) (parse_bounded_vldata_strong_pred min max s) (parse_bounded_vldata_strong_correct min max l s))
)
let parse_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p) | false | false | LowParse.Spec.VLData.fsti | {
"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"
} | null | val parse_bounded_vldata_strong
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot
(parser (parse_bounded_vldata_strong_kind min max (log256' max) k)
(parse_bounded_vldata_strong_t min max s)) | [] | LowParse.Spec.VLData.parse_bounded_vldata_strong | {
"file_name": "src/lowparse/LowParse.Spec.VLData.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
s: LowParse.Spec.Base.serializer p
-> LowParse.Spec.Base.parser (LowParse.Spec.VLData.parse_bounded_vldata_strong_kind min
max
(LowParse.Spec.BoundedInt.log256' max)
k)
(LowParse.Spec.VLData.parse_bounded_vldata_strong_t min max s) | {
"end_col": 54,
"end_line": 470,
"start_col": 2,
"start_line": 470
} |
Prims.Tot | val parse_bounded_vldata
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_bounded_vldata_strong_kind min max (log256' max) k) t) | [
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_bounded_vldata
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_bounded_vldata_strong_kind min max (log256' max) k) t)
= parse_bounded_vldata' min max (log256' max) p | val parse_bounded_vldata
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_bounded_vldata_strong_kind min max (log256' max) k) t)
let parse_bounded_vldata
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_bounded_vldata_strong_kind min max (log256' max) k) t) = | false | null | false | parse_bounded_vldata' min max (log256' max) p | {
"checked_file": "LowParse.Spec.VLData.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLData.fsti"
} | [
"total"
] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.VLData.parse_bounded_vldata'",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind"
] | [] | module LowParse.Spec.VLData
include LowParse.Spec.FLData
include LowParse.Spec.AllIntegers // for bounded_integer, in_bounds, etc.
module Seq = FStar.Seq
module U32 = FStar.UInt32
module M = LowParse.Math
#reset-options "--z3rlimit 64 --max_fuel 64 --max_ifuel 64 --z3refresh --z3cliopt smt.arith.nl=false"
let parse_vldata_payload_size
(sz: integer_size)
: Pure nat
(requires True)
(ensures (fun y -> y == pow2 (FStar.Mul.op_Star 8 sz) - 1 ))
= match sz with
| 1 -> 255
| 2 -> 65535
| 3 -> 16777215
| 4 -> 4294967295
#reset-options
// unfold
let parse_vldata_payload_kind
(sz: integer_size)
(k: parser_kind)
: parser_kind
= strong_parser_kind 0 (parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_payload
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(i: bounded_integer sz { f i == true } )
: Tot (parser (parse_vldata_payload_kind sz k) t)
= weaken (parse_vldata_payload_kind sz k) (parse_fldata p (U32.v i))
#set-options "--z3rlimit 64"
let parse_fldata_and_then_cases_injective
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p))
= parser_kind_prop_equiv k p;
let g
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1 b2: bytes)
: Lemma
(requires (and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2))
(ensures (len1 == len2))
= assert (injective_precond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (injective_postcond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (len1 == len2)
in
let g'
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1: bytes)
: Lemma
(forall (b2: bytes) . and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2 ==> len1 == len2)
= Classical.forall_intro (Classical.move_requires (g len1 len2 b1))
in
Classical.forall_intro_3 g'
#reset-options
// unfold
let parse_vldata_gen_kind
(sz: integer_size)
(k: parser_kind)
: Tot parser_kind
= strong_parser_kind sz (sz + parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_gen_kind_correct
(sz: integer_size)
(k: parser_kind)
: Lemma
( (parse_vldata_gen_kind sz k) == (and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k)))
= let kl = parse_vldata_gen_kind sz k in
let kr = and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) in
assert_norm (kl == kr)
val parse_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_vldata_gen_kind sz k) t)
val parse_vldata_gen_eq_def
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p) /\
parse_vldata_gen_kind sz k == and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) /\
parse_vldata_gen sz f p ==
and_then
#_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t
(parse_vldata_payload sz f p))
let parse_vldata_gen_eq
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(let res = parse (parse_vldata_gen sz f p) input in
match parse (parse_bounded_integer sz) input with
| None -> res == None
| Some (len, consumed_len) ->
consumed_len == sz /\ (
if f len
then begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
else res == None
))
= parse_vldata_gen_eq_def sz f p;
and_then_eq #_ #(parse_filter_refine f) (parse_filter (parse_bounded_integer sz) f) #_ #t (parse_vldata_payload sz f p) input;
parse_filter_eq #_ #(bounded_integer sz) (parse_bounded_integer sz) f input;
parser_kind_prop_equiv (parse_bounded_integer_kind sz) (parse_bounded_integer sz);
()
let parse_vldata_gen_eq_some_elim
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(requires (Some? (parse (parse_vldata_gen sz f p) input)))
(ensures (
let pbi = parse (parse_bounded_integer sz) input in
Some? pbi /\ (
let Some (len, consumed_len) = pbi in
consumed_len == sz /\
f len /\
Seq.length input >= sz + U32.v len /\ (
let input' = Seq.slice input sz (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let Some (x, consumed_x) = pp in
consumed_x = U32.v len /\
parse (parse_vldata_gen sz f p) input == Some (x, sz + U32.v len)
)))))
= parse_vldata_gen_eq sz f p input
let unconstrained_bounded_integer
(sz: integer_size)
(i: bounded_integer sz)
: GTot bool
= true
let parse_vldata
(sz: integer_size)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser _ t)
= parse_vldata_gen sz (unconstrained_bounded_integer sz) p
let parse_vldata_eq
(sz: integer_size)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(parse (parse_vldata sz p) input == (match parse (parse_bounded_integer sz) input with
| None -> None
| Some (len, _) ->
begin
if Seq.length input < sz + U32.v len
then None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then Some (x, sz + U32.v len)
else None
| _ -> None
end
))
= parse_vldata_gen_eq sz (unconstrained_bounded_integer _) p input
(** Explicit bounds on size *)
#reset-options
inline_for_extraction
let parse_bounded_vldata_strong_kind
(min: nat)
(max: nat)
(l: nat)
(k: parser_kind)
: Pure parser_kind
(requires (min <= max /\ max > 0 /\ max < 4294967296 /\ l >= log256' max /\ l <= 4 ))
(ensures (fun _ -> True))
= [@inline_let]
let kmin = k.parser_kind_low in
[@inline_let]
let min' = if kmin > min then kmin else min in
[@inline_let]
let max' = match k.parser_kind_high with
| None -> max
| Some kmax -> if kmax < max then kmax else max
in
[@inline_let]
let max' = if max' < min' then min' else max' in
(* the size of the length prefix must conform to the max bound given by the user, not on the metadata *)
strong_parser_kind (l + min') (l + max') (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_bounded_vldata_elim'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(xbytes: bytes)
(x: t)
(consumed: consumed_length xbytes)
: Lemma
(requires (parse (parse_vldata_gen l (in_bounds min max) p) xbytes == Some (x, consumed)))
(ensures (
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
Some? plen /\ (
let (Some (len, consumed_len)) = plen in
(consumed_len <: nat) == (sz <: nat) /\
in_bounds min max len /\
U32.v len <= Seq.length xbytes - sz /\ (
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let (Some (x', consumed_p)) = pp in
x' == x /\
(consumed_p <: nat) == U32.v len /\
(consumed <: nat) == sz + U32.v len
)))))
= parse_vldata_gen_eq l (in_bounds min max) p xbytes;
parser_kind_prop_equiv (parse_bounded_integer_kind l) (parse_bounded_integer l)
let parse_bounded_vldata_correct
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(parser_kind_prop (parse_bounded_vldata_strong_kind min max l k) (parse_vldata_gen l (in_bounds min max) p))
= parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l k) (parse_vldata_gen l (in_bounds min max) p);
let sz : integer_size = l in
let p' = parse_vldata_gen sz (in_bounds min max) p in
parser_kind_prop_equiv (get_parser_kind p') p';
parser_kind_prop_equiv k p;
let k' = parse_bounded_vldata_strong_kind min max l k in
let prf
(input: bytes)
: Lemma
(requires (Some? (parse p' input)))
(ensures (
let pi = parse p' input in
Some? pi /\ (
let (Some (_, consumed)) = pi in
k'.parser_kind_low <= (consumed <: nat) /\
(consumed <: nat) <= Some?.v k'.parser_kind_high
)))
= let (Some (data, consumed)) = parse p' input in
parse_bounded_vldata_elim' min max l p input data consumed
in
Classical.forall_intro (Classical.move_requires prf)
let parse_bounded_vldata'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_bounded_vldata_strong_kind min max l k) t)
= parse_bounded_vldata_correct min max l p;
strengthen (parse_bounded_vldata_strong_kind min max l k) (parse_vldata_gen l (in_bounds min max) p)
let parse_bounded_vldata
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t) | false | false | LowParse.Spec.VLData.fsti | {
"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"
} | null | val parse_bounded_vldata
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_bounded_vldata_strong_kind min max (log256' max) k) t) | [] | LowParse.Spec.VLData.parse_bounded_vldata | {
"file_name": "src/lowparse/LowParse.Spec.VLData.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
p: LowParse.Spec.Base.parser k t
-> LowParse.Spec.Base.parser (LowParse.Spec.VLData.parse_bounded_vldata_strong_kind min
max
(LowParse.Spec.BoundedInt.log256' max)
k)
t | {
"end_col": 47,
"end_line": 332,
"start_col": 2,
"start_line": 332
} |
FStar.Pervasives.Lemma | val parse_vldata_gen_eq_some_elim
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma (requires (Some? (parse (parse_vldata_gen sz f p) input)))
(ensures
(let pbi = parse (parse_bounded_integer sz) input in
Some? pbi /\
(let Some (len, consumed_len) = pbi in
consumed_len == sz /\ f len /\ Seq.length input >= sz + U32.v len /\
(let input' = Seq.slice input sz (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\
(let Some (x, consumed_x) = pp in
consumed_x = U32.v len /\
parse (parse_vldata_gen sz f p) input == Some (x, sz + U32.v len)))))) | [
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_vldata_gen_eq_some_elim
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(requires (Some? (parse (parse_vldata_gen sz f p) input)))
(ensures (
let pbi = parse (parse_bounded_integer sz) input in
Some? pbi /\ (
let Some (len, consumed_len) = pbi in
consumed_len == sz /\
f len /\
Seq.length input >= sz + U32.v len /\ (
let input' = Seq.slice input sz (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let Some (x, consumed_x) = pp in
consumed_x = U32.v len /\
parse (parse_vldata_gen sz f p) input == Some (x, sz + U32.v len)
)))))
= parse_vldata_gen_eq sz f p input | val parse_vldata_gen_eq_some_elim
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma (requires (Some? (parse (parse_vldata_gen sz f p) input)))
(ensures
(let pbi = parse (parse_bounded_integer sz) input in
Some? pbi /\
(let Some (len, consumed_len) = pbi in
consumed_len == sz /\ f len /\ Seq.length input >= sz + U32.v len /\
(let input' = Seq.slice input sz (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\
(let Some (x, consumed_x) = pp in
consumed_x = U32.v len /\
parse (parse_vldata_gen sz f p) input == Some (x, sz + U32.v len))))))
let parse_vldata_gen_eq_some_elim
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma (requires (Some? (parse (parse_vldata_gen sz f p) input)))
(ensures
(let pbi = parse (parse_bounded_integer sz) input in
Some? pbi /\
(let Some (len, consumed_len) = pbi in
consumed_len == sz /\ f len /\ Seq.length input >= sz + U32.v len /\
(let input' = Seq.slice input sz (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\
(let Some (x, consumed_x) = pp in
consumed_x = U32.v len /\
parse (parse_vldata_gen sz f p) input == Some (x, sz + U32.v len)))))) = | false | null | true | parse_vldata_gen_eq sz f p input | {
"checked_file": "LowParse.Spec.VLData.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLData.fsti"
} | [
"lemma"
] | [
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.BoundedInt.bounded_integer",
"Prims.bool",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Bytes.bytes",
"LowParse.Spec.VLData.parse_vldata_gen_eq",
"Prims.unit",
"Prims.b2t",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.consumed_length",
"LowParse.Spec.Base.parse",
"LowParse.Spec.VLData.parse_vldata_gen",
"Prims.squash",
"Prims.l_and",
"Prims.eq2",
"Prims.nat",
"Prims.l_or",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"Prims.op_GreaterThanOrEqual",
"Prims.op_Addition",
"FStar.UInt32.v",
"Prims.op_Equality",
"Prims.int",
"FStar.UInt.size",
"FStar.UInt32.n",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.Mktuple2",
"Prims.logical",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.slice",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.VLData
include LowParse.Spec.FLData
include LowParse.Spec.AllIntegers // for bounded_integer, in_bounds, etc.
module Seq = FStar.Seq
module U32 = FStar.UInt32
module M = LowParse.Math
#reset-options "--z3rlimit 64 --max_fuel 64 --max_ifuel 64 --z3refresh --z3cliopt smt.arith.nl=false"
let parse_vldata_payload_size
(sz: integer_size)
: Pure nat
(requires True)
(ensures (fun y -> y == pow2 (FStar.Mul.op_Star 8 sz) - 1 ))
= match sz with
| 1 -> 255
| 2 -> 65535
| 3 -> 16777215
| 4 -> 4294967295
#reset-options
// unfold
let parse_vldata_payload_kind
(sz: integer_size)
(k: parser_kind)
: parser_kind
= strong_parser_kind 0 (parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_payload
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(i: bounded_integer sz { f i == true } )
: Tot (parser (parse_vldata_payload_kind sz k) t)
= weaken (parse_vldata_payload_kind sz k) (parse_fldata p (U32.v i))
#set-options "--z3rlimit 64"
let parse_fldata_and_then_cases_injective
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p))
= parser_kind_prop_equiv k p;
let g
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1 b2: bytes)
: Lemma
(requires (and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2))
(ensures (len1 == len2))
= assert (injective_precond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (injective_postcond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (len1 == len2)
in
let g'
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1: bytes)
: Lemma
(forall (b2: bytes) . and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2 ==> len1 == len2)
= Classical.forall_intro (Classical.move_requires (g len1 len2 b1))
in
Classical.forall_intro_3 g'
#reset-options
// unfold
let parse_vldata_gen_kind
(sz: integer_size)
(k: parser_kind)
: Tot parser_kind
= strong_parser_kind sz (sz + parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_gen_kind_correct
(sz: integer_size)
(k: parser_kind)
: Lemma
( (parse_vldata_gen_kind sz k) == (and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k)))
= let kl = parse_vldata_gen_kind sz k in
let kr = and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) in
assert_norm (kl == kr)
val parse_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_vldata_gen_kind sz k) t)
val parse_vldata_gen_eq_def
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p) /\
parse_vldata_gen_kind sz k == and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) /\
parse_vldata_gen sz f p ==
and_then
#_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t
(parse_vldata_payload sz f p))
let parse_vldata_gen_eq
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(let res = parse (parse_vldata_gen sz f p) input in
match parse (parse_bounded_integer sz) input with
| None -> res == None
| Some (len, consumed_len) ->
consumed_len == sz /\ (
if f len
then begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
else res == None
))
= parse_vldata_gen_eq_def sz f p;
and_then_eq #_ #(parse_filter_refine f) (parse_filter (parse_bounded_integer sz) f) #_ #t (parse_vldata_payload sz f p) input;
parse_filter_eq #_ #(bounded_integer sz) (parse_bounded_integer sz) f input;
parser_kind_prop_equiv (parse_bounded_integer_kind sz) (parse_bounded_integer sz);
()
let parse_vldata_gen_eq_some_elim
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(requires (Some? (parse (parse_vldata_gen sz f p) input)))
(ensures (
let pbi = parse (parse_bounded_integer sz) input in
Some? pbi /\ (
let Some (len, consumed_len) = pbi in
consumed_len == sz /\
f len /\
Seq.length input >= sz + U32.v len /\ (
let input' = Seq.slice input sz (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let Some (x, consumed_x) = pp in
consumed_x = U32.v len /\
parse (parse_vldata_gen sz f p) input == Some (x, sz + U32.v len) | false | false | LowParse.Spec.VLData.fsti | {
"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"
} | null | val parse_vldata_gen_eq_some_elim
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma (requires (Some? (parse (parse_vldata_gen sz f p) input)))
(ensures
(let pbi = parse (parse_bounded_integer sz) input in
Some? pbi /\
(let Some (len, consumed_len) = pbi in
consumed_len == sz /\ f len /\ Seq.length input >= sz + U32.v len /\
(let input' = Seq.slice input sz (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\
(let Some (x, consumed_x) = pp in
consumed_x = U32.v len /\
parse (parse_vldata_gen sz f p) input == Some (x, sz + U32.v len)))))) | [] | LowParse.Spec.VLData.parse_vldata_gen_eq_some_elim | {
"file_name": "src/lowparse/LowParse.Spec.VLData.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
sz: LowParse.Spec.BoundedInt.integer_size ->
f: (_: LowParse.Spec.BoundedInt.bounded_integer sz -> Prims.GTot Prims.bool) ->
p: LowParse.Spec.Base.parser k t ->
input: LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(requires
Some? (LowParse.Spec.Base.parse (LowParse.Spec.VLData.parse_vldata_gen sz f p) input))
(ensures
(let pbi =
LowParse.Spec.Base.parse (LowParse.Spec.BoundedInt.parse_bounded_integer sz) input
in
Some? pbi /\
(let _ = pbi in
(let
FStar.Pervasives.Native.Some
#_
(FStar.Pervasives.Native.Mktuple2 #_ #_ len consumed_len) =
_
in
consumed_len == sz /\ f len /\ FStar.Seq.Base.length input >= sz + FStar.UInt32.v len /\
(let input' = FStar.Seq.Base.slice input sz (sz + FStar.UInt32.v len) in
let pp = LowParse.Spec.Base.parse p input' in
Some? pp /\
(let _ = pp in
(let
FStar.Pervasives.Native.Some
#_
(FStar.Pervasives.Native.Mktuple2 #_ #_ x consumed_x) =
_
in
consumed_x = FStar.UInt32.v len /\
LowParse.Spec.Base.parse (LowParse.Spec.VLData.parse_vldata_gen sz f p) input ==
FStar.Pervasives.Native.Some (x, sz + FStar.UInt32.v len))
<:
Prims.logical)))
<:
Prims.logical))) | {
"end_col": 34,
"end_line": 180,
"start_col": 2,
"start_line": 180
} |
Prims.Tot | val serialize_bounded_vldata
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {serialize_bounded_vldata_precond min max k})
: Tot (serializer (parse_bounded_vldata min max p)) | [
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialize_bounded_vldata
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { serialize_bounded_vldata_precond min max k } )
: Tot (serializer (parse_bounded_vldata min max p))
= serialize_bounded_vldata' min max s | val serialize_bounded_vldata
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {serialize_bounded_vldata_precond min max k})
: Tot (serializer (parse_bounded_vldata min max p))
let serialize_bounded_vldata
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {serialize_bounded_vldata_precond min max k})
: Tot (serializer (parse_bounded_vldata min max p)) = | false | null | false | serialize_bounded_vldata' min max s | {
"checked_file": "LowParse.Spec.VLData.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLData.fsti"
} | [
"total"
] | [
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThan",
"Prims.op_LessThan",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Spec.VLData.serialize_bounded_vldata_precond",
"LowParse.Spec.VLData.serialize_bounded_vldata'",
"LowParse.Spec.VLData.parse_bounded_vldata_strong_kind",
"LowParse.Spec.BoundedInt.log256'",
"LowParse.Spec.VLData.parse_bounded_vldata"
] | [] | module LowParse.Spec.VLData
include LowParse.Spec.FLData
include LowParse.Spec.AllIntegers // for bounded_integer, in_bounds, etc.
module Seq = FStar.Seq
module U32 = FStar.UInt32
module M = LowParse.Math
#reset-options "--z3rlimit 64 --max_fuel 64 --max_ifuel 64 --z3refresh --z3cliopt smt.arith.nl=false"
let parse_vldata_payload_size
(sz: integer_size)
: Pure nat
(requires True)
(ensures (fun y -> y == pow2 (FStar.Mul.op_Star 8 sz) - 1 ))
= match sz with
| 1 -> 255
| 2 -> 65535
| 3 -> 16777215
| 4 -> 4294967295
#reset-options
// unfold
let parse_vldata_payload_kind
(sz: integer_size)
(k: parser_kind)
: parser_kind
= strong_parser_kind 0 (parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_payload
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(i: bounded_integer sz { f i == true } )
: Tot (parser (parse_vldata_payload_kind sz k) t)
= weaken (parse_vldata_payload_kind sz k) (parse_fldata p (U32.v i))
#set-options "--z3rlimit 64"
let parse_fldata_and_then_cases_injective
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p))
= parser_kind_prop_equiv k p;
let g
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1 b2: bytes)
: Lemma
(requires (and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2))
(ensures (len1 == len2))
= assert (injective_precond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (injective_postcond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (len1 == len2)
in
let g'
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1: bytes)
: Lemma
(forall (b2: bytes) . and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2 ==> len1 == len2)
= Classical.forall_intro (Classical.move_requires (g len1 len2 b1))
in
Classical.forall_intro_3 g'
#reset-options
// unfold
let parse_vldata_gen_kind
(sz: integer_size)
(k: parser_kind)
: Tot parser_kind
= strong_parser_kind sz (sz + parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_gen_kind_correct
(sz: integer_size)
(k: parser_kind)
: Lemma
( (parse_vldata_gen_kind sz k) == (and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k)))
= let kl = parse_vldata_gen_kind sz k in
let kr = and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) in
assert_norm (kl == kr)
val parse_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_vldata_gen_kind sz k) t)
val parse_vldata_gen_eq_def
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p) /\
parse_vldata_gen_kind sz k == and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) /\
parse_vldata_gen sz f p ==
and_then
#_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t
(parse_vldata_payload sz f p))
let parse_vldata_gen_eq
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(let res = parse (parse_vldata_gen sz f p) input in
match parse (parse_bounded_integer sz) input with
| None -> res == None
| Some (len, consumed_len) ->
consumed_len == sz /\ (
if f len
then begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
else res == None
))
= parse_vldata_gen_eq_def sz f p;
and_then_eq #_ #(parse_filter_refine f) (parse_filter (parse_bounded_integer sz) f) #_ #t (parse_vldata_payload sz f p) input;
parse_filter_eq #_ #(bounded_integer sz) (parse_bounded_integer sz) f input;
parser_kind_prop_equiv (parse_bounded_integer_kind sz) (parse_bounded_integer sz);
()
let parse_vldata_gen_eq_some_elim
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(requires (Some? (parse (parse_vldata_gen sz f p) input)))
(ensures (
let pbi = parse (parse_bounded_integer sz) input in
Some? pbi /\ (
let Some (len, consumed_len) = pbi in
consumed_len == sz /\
f len /\
Seq.length input >= sz + U32.v len /\ (
let input' = Seq.slice input sz (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let Some (x, consumed_x) = pp in
consumed_x = U32.v len /\
parse (parse_vldata_gen sz f p) input == Some (x, sz + U32.v len)
)))))
= parse_vldata_gen_eq sz f p input
let unconstrained_bounded_integer
(sz: integer_size)
(i: bounded_integer sz)
: GTot bool
= true
let parse_vldata
(sz: integer_size)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser _ t)
= parse_vldata_gen sz (unconstrained_bounded_integer sz) p
let parse_vldata_eq
(sz: integer_size)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(parse (parse_vldata sz p) input == (match parse (parse_bounded_integer sz) input with
| None -> None
| Some (len, _) ->
begin
if Seq.length input < sz + U32.v len
then None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then Some (x, sz + U32.v len)
else None
| _ -> None
end
))
= parse_vldata_gen_eq sz (unconstrained_bounded_integer _) p input
(** Explicit bounds on size *)
#reset-options
inline_for_extraction
let parse_bounded_vldata_strong_kind
(min: nat)
(max: nat)
(l: nat)
(k: parser_kind)
: Pure parser_kind
(requires (min <= max /\ max > 0 /\ max < 4294967296 /\ l >= log256' max /\ l <= 4 ))
(ensures (fun _ -> True))
= [@inline_let]
let kmin = k.parser_kind_low in
[@inline_let]
let min' = if kmin > min then kmin else min in
[@inline_let]
let max' = match k.parser_kind_high with
| None -> max
| Some kmax -> if kmax < max then kmax else max
in
[@inline_let]
let max' = if max' < min' then min' else max' in
(* the size of the length prefix must conform to the max bound given by the user, not on the metadata *)
strong_parser_kind (l + min') (l + max') (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_bounded_vldata_elim'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(xbytes: bytes)
(x: t)
(consumed: consumed_length xbytes)
: Lemma
(requires (parse (parse_vldata_gen l (in_bounds min max) p) xbytes == Some (x, consumed)))
(ensures (
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
Some? plen /\ (
let (Some (len, consumed_len)) = plen in
(consumed_len <: nat) == (sz <: nat) /\
in_bounds min max len /\
U32.v len <= Seq.length xbytes - sz /\ (
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let (Some (x', consumed_p)) = pp in
x' == x /\
(consumed_p <: nat) == U32.v len /\
(consumed <: nat) == sz + U32.v len
)))))
= parse_vldata_gen_eq l (in_bounds min max) p xbytes;
parser_kind_prop_equiv (parse_bounded_integer_kind l) (parse_bounded_integer l)
let parse_bounded_vldata_correct
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(parser_kind_prop (parse_bounded_vldata_strong_kind min max l k) (parse_vldata_gen l (in_bounds min max) p))
= parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l k) (parse_vldata_gen l (in_bounds min max) p);
let sz : integer_size = l in
let p' = parse_vldata_gen sz (in_bounds min max) p in
parser_kind_prop_equiv (get_parser_kind p') p';
parser_kind_prop_equiv k p;
let k' = parse_bounded_vldata_strong_kind min max l k in
let prf
(input: bytes)
: Lemma
(requires (Some? (parse p' input)))
(ensures (
let pi = parse p' input in
Some? pi /\ (
let (Some (_, consumed)) = pi in
k'.parser_kind_low <= (consumed <: nat) /\
(consumed <: nat) <= Some?.v k'.parser_kind_high
)))
= let (Some (data, consumed)) = parse p' input in
parse_bounded_vldata_elim' min max l p input data consumed
in
Classical.forall_intro (Classical.move_requires prf)
let parse_bounded_vldata'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_bounded_vldata_strong_kind min max l k) t)
= parse_bounded_vldata_correct min max l p;
strengthen (parse_bounded_vldata_strong_kind min max l k) (parse_vldata_gen l (in_bounds min max) p)
let parse_bounded_vldata
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_bounded_vldata_strong_kind min max (log256' max) k) t)
= parse_bounded_vldata' min max (log256' max) p
let parse_bounded_vldata_elim
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(xbytes: bytes)
(x: t)
(consumed: consumed_length xbytes)
: Lemma
(requires (parse (parse_bounded_vldata' min max l p) xbytes == Some (x, consumed)))
(ensures (
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
Some? plen /\ (
let (Some (len, consumed_len)) = plen in
(consumed_len <: nat) == (sz <: nat) /\
in_bounds min max len /\
U32.v len <= Seq.length xbytes - sz /\ (
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let (Some (x', consumed_p)) = pp in
x' == x /\
(consumed_p <: nat) == U32.v len /\
(consumed <: nat) == sz + U32.v len
)))))
= parse_bounded_vldata_elim' min max l p xbytes x consumed
let parse_bounded_vldata_elim_forall
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(xbytes: bytes)
: Lemma
(requires (Some? (parse (parse_bounded_vldata' min max l p) xbytes)))
(ensures (
let (Some (x, consumed)) = parse (parse_bounded_vldata' min max l p) xbytes in
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
Some? plen /\ (
let (Some (len, consumed_len)) = plen in
(consumed_len <: nat) == (sz <: nat) /\
in_bounds min max len /\
U32.v len <= Seq.length xbytes - sz /\ (
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let (Some (x', consumed_p)) = pp in
x' == x /\
(consumed_p <: nat) == U32.v len /\
(consumed <: nat) == sz + U32.v len
)))))
= let (Some (x, consumed)) = parse (parse_bounded_vldata' min max l p) xbytes in
parse_bounded_vldata_elim min max l p xbytes x consumed
(* Serialization *)
let parse_bounded_vldata_strong_pred
(min: nat)
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(x: t)
: GTot Type0
= let reslen = Seq.length (s x) in
min <= reslen /\ reslen <= max
let parse_bounded_vldata_strong_t
(min: nat)
(max: nat)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t { parse_bounded_vldata_strong_pred min max s x } )
let parse_bounded_vldata_strong_correct
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(xbytes: bytes)
(consumed: consumed_length xbytes)
(x: t)
: Lemma
(requires (parse (parse_bounded_vldata' min max l p) xbytes == Some (x, consumed)))
(ensures (parse_bounded_vldata_strong_pred min max s x))
= parse_bounded_vldata_elim min max l p xbytes x consumed;
let sz : integer_size = l in
let plen = parse (parse_bounded_integer sz) xbytes in
let f () : Lemma (Some? plen) =
parse_bounded_vldata_elim min max l p xbytes x consumed
in
f ();
let (Some (len, _)) = plen in
let input' = Seq.slice xbytes (sz <: nat) (sz + U32.v len) in
assert (Seq.equal input' (Seq.slice input' 0 (U32.v len)));
serializer_correct_implies_complete p s;
assert (s x == input');
()
let parse_bounded_vldata_strong'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (parser (parse_bounded_vldata_strong_kind min max l k) (parse_bounded_vldata_strong_t min max s))
= // strengthen (parse_bounded_vldata_strong_kind min max k)
(
coerce_parser
(parse_bounded_vldata_strong_t min max s)
(parse_strengthen (parse_bounded_vldata' min max l p) (parse_bounded_vldata_strong_pred min max s) (parse_bounded_vldata_strong_correct min max l s))
)
let parse_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (parser (parse_bounded_vldata_strong_kind min max (log256' max) k) (parse_bounded_vldata_strong_t min max s))
= parse_bounded_vldata_strong' min max (log256' max) s
let serialize_bounded_vldata_strong_aux
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (bare_serializer (parse_bounded_vldata_strong_t min max s))
= (fun (x: parse_bounded_vldata_strong_t min max s) ->
let pl = s x in
let sz = l in
let nlen = Seq.length pl in
assert (min <= nlen /\ nlen <= max);
let len = U32.uint_to_t nlen in
let slen = serialize (serialize_bounded_integer sz) len in
seq_slice_append_l slen pl;
seq_slice_append_r slen pl;
Seq.append slen pl
)
let serialize_vldata_gen_correct_aux
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b b1 b2: bytes)
: Lemma
(requires (
Seq.length b1 == sz /\ (
let vlen = parse (parse_bounded_integer sz) b1 in
Some? vlen /\ (
let (Some (len, _)) = vlen in
f len == true /\
Seq.length b2 == U32.v len /\ (
let vv = parse p b2 in
Some? vv /\ (
let (Some (_, consumed)) = vv in
consumed == Seq.length b2 /\
Seq.length b1 <= Seq.length b /\
Seq.slice b 0 (Seq.length b1) == b1 /\
Seq.slice b (Seq.length b1) (Seq.length b) == b2
))))))
(ensures (
let vv = parse p b2 in
Some? vv /\ (
let (Some (v, consumed)) = vv in
let vv' = parse (parse_vldata_gen sz f p) b in
Some? vv' /\ (
let (Some (v', consumed')) = vv' in
v == v' /\
consumed == Seq.length b2 /\
consumed' == Seq.length b
)))) =
let (Some (len, consumed1)) = parse (parse_bounded_integer sz) b1 in
parser_kind_prop_equiv (parse_bounded_integer_kind sz) (parse_bounded_integer sz);
assert (consumed1 == sz);
assert (no_lookahead_on (parse_bounded_integer sz) b1 b);
assert (injective_postcond (parse_bounded_integer sz) b1 b);
assert (parse (parse_bounded_integer sz) b == Some (len, sz));
assert (sz + U32.v len == Seq.length b);
assert (b2 == Seq.slice b sz (sz + U32.v len));
parse_vldata_gen_eq sz f p b
let serialize_vldata_gen_correct
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(b1 b2: bytes)
: Lemma
(requires (
Seq.length b1 == sz /\ (
let vlen = parse (parse_bounded_integer sz) b1 in
Some? vlen /\ (
let (Some (len, _)) = vlen in
f len == true /\
Seq.length b2 == U32.v len /\ (
let vv = parse p b2 in
Some? vv /\ (
let (Some (_, consumed)) = vv in
consumed == Seq.length b2
))))))
(ensures (
let vv = parse p b2 in
Some? vv /\ (
let (Some (v, consumed)) = vv in
let vv' = parse (parse_vldata_gen sz f p) (Seq.append b1 b2) in
Some? vv' /\ (
let (Some (v', consumed')) = vv' in
v == v' /\
consumed == Seq.length b2 /\
consumed' == sz + Seq.length b2
)))) =
seq_slice_append_l b1 b2;
seq_slice_append_r b1 b2;
serialize_vldata_gen_correct_aux sz f p (Seq.append b1 b2) b1 b2
let serialize_bounded_vldata_strong_correct
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
(input: parse_bounded_vldata_strong_t min max s)
: Lemma
(let formatted = serialize_bounded_vldata_strong_aux min max l s input in
parse (parse_bounded_vldata_strong' min max l s) formatted == Some (input, Seq.length formatted))
= let sz = l in
let sp = serialize s input in
let nlen = Seq.length sp in
assert (min <= nlen /\ nlen <= max);
let len = U32.uint_to_t nlen in
M.pow2_le_compat (FStar.Mul.op_Star 8 sz) (FStar.Mul.op_Star 8 (log256' max));
assert (U32.v len < pow2 (FStar.Mul.op_Star 8 sz));
let (len: bounded_integer sz) = len in
let slen = serialize (serialize_bounded_integer sz) len in
assert (Seq.length slen == sz);
let pslen = parse (parse_bounded_integer sz) slen in
assert (Some? pslen);
let (Some (len', consumed_len')) = pslen in
assert (len == len');
assert (in_bounds min max len' == true);
assert (Seq.length sp == U32.v len);
let psp = parse p sp in
assert (Some? psp);
let (Some (_, consumed_p)) = psp in
assert ((consumed_p <: nat) == Seq.length sp);
serialize_vldata_gen_correct sz (in_bounds min max) p
slen
sp
;
()
let serialize_bounded_vldata_strong'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(l: nat { l >= log256' max /\ l <= 4 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bounded_vldata_strong' min max l s))
= Classical.forall_intro (serialize_bounded_vldata_strong_correct min max l s);
serialize_bounded_vldata_strong_aux min max l s
let serialize_bounded_vldata_strong
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot (serializer (parse_bounded_vldata_strong min max s))
= serialize_bounded_vldata_strong' min max (log256' max) s
let serialize_bounded_vldata_precond
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(k: parser_kind)
: GTot bool
= match k.parser_kind_high with
| None -> false
| Some max' -> min <= k.parser_kind_low && max' <= max
let serialize_bounded_vldata_correct
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { serialize_bounded_vldata_precond min max k } )
(x: t)
: Lemma
( let Some (_, consumed) = parse p (serialize s x) in
let y = serialize_bounded_vldata_strong_aux min max (log256' max) s (x <: parse_bounded_vldata_strong_t min max s) in
parse (parse_bounded_vldata min max p) y == Some (x, Seq.length y))
= let Some (_, consumed) = parse p (serialize s x) in
serialize_bounded_vldata_strong_correct min max (log256' max) s x;
()
let serialize_bounded_vldata'
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { serialize_bounded_vldata_precond min max k } )
(x: t)
: GTot (y: bytes { parse (parse_bounded_vldata min max p) y == Some (x, Seq.length y) } )
= let Some (_, consumed) = parse p (serialize s x) in
serialize_bounded_vldata_correct min max s x;
serialize_bounded_vldata_strong_aux min max (log256' max) s x
let serialize_bounded_vldata
(min: nat)
(max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p { serialize_bounded_vldata_precond min max k } ) | false | false | LowParse.Spec.VLData.fsti | {
"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"
} | null | val serialize_bounded_vldata
(min: nat)
(max: nat{min <= max /\ max > 0 /\ max < 4294967296})
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p {serialize_bounded_vldata_precond min max k})
: Tot (serializer (parse_bounded_vldata min max p)) | [] | LowParse.Spec.VLData.serialize_bounded_vldata | {
"file_name": "src/lowparse/LowParse.Spec.VLData.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
min: Prims.nat ->
max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} ->
s:
LowParse.Spec.Base.serializer p
{LowParse.Spec.VLData.serialize_bounded_vldata_precond min max k}
-> LowParse.Spec.Base.serializer (LowParse.Spec.VLData.parse_bounded_vldata min max p) | {
"end_col": 37,
"end_line": 678,
"start_col": 2,
"start_line": 678
} |
FStar.Pervasives.Lemma | val parse_vldata_eq (sz: integer_size) (#k: parser_kind) (#t: Type) (p: parser k t) (input: bytes)
: Lemma
(parse (parse_vldata sz p) input ==
(match parse (parse_bounded_integer sz) input with
| None -> None
| Some (len, _) ->
if Seq.length input < sz + U32.v len
then None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len then Some (x, sz + U32.v len) else None
| _ -> None)) | [
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_vldata_eq
(sz: integer_size)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(parse (parse_vldata sz p) input == (match parse (parse_bounded_integer sz) input with
| None -> None
| Some (len, _) ->
begin
if Seq.length input < sz + U32.v len
then None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then Some (x, sz + U32.v len)
else None
| _ -> None
end
))
= parse_vldata_gen_eq sz (unconstrained_bounded_integer _) p input | val parse_vldata_eq (sz: integer_size) (#k: parser_kind) (#t: Type) (p: parser k t) (input: bytes)
: Lemma
(parse (parse_vldata sz p) input ==
(match parse (parse_bounded_integer sz) input with
| None -> None
| Some (len, _) ->
if Seq.length input < sz + U32.v len
then None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len then Some (x, sz + U32.v len) else None
| _ -> None))
let parse_vldata_eq (sz: integer_size) (#k: parser_kind) (#t: Type) (p: parser k t) (input: bytes)
: Lemma
(parse (parse_vldata sz p) input ==
(match parse (parse_bounded_integer sz) input with
| None -> None
| Some (len, _) ->
if Seq.length input < sz + U32.v len
then None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len then Some (x, sz + U32.v len) else None
| _ -> None)) = | false | null | true | parse_vldata_gen_eq sz (unconstrained_bounded_integer _) p input | {
"checked_file": "LowParse.Spec.VLData.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLData.fsti"
} | [
"lemma"
] | [
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Bytes.bytes",
"LowParse.Spec.VLData.parse_vldata_gen_eq",
"LowParse.Spec.VLData.unconstrained_bounded_integer",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.consumed_length",
"LowParse.Spec.Base.parse",
"LowParse.Spec.VLData.parse_vldata",
"LowParse.Spec.BoundedInt.bounded_integer",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"FStar.Pervasives.Native.None",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"Prims.op_Addition",
"FStar.UInt32.v",
"Prims.bool",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThanOrEqual",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.slice",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Spec.VLData
include LowParse.Spec.FLData
include LowParse.Spec.AllIntegers // for bounded_integer, in_bounds, etc.
module Seq = FStar.Seq
module U32 = FStar.UInt32
module M = LowParse.Math
#reset-options "--z3rlimit 64 --max_fuel 64 --max_ifuel 64 --z3refresh --z3cliopt smt.arith.nl=false"
let parse_vldata_payload_size
(sz: integer_size)
: Pure nat
(requires True)
(ensures (fun y -> y == pow2 (FStar.Mul.op_Star 8 sz) - 1 ))
= match sz with
| 1 -> 255
| 2 -> 65535
| 3 -> 16777215
| 4 -> 4294967295
#reset-options
// unfold
let parse_vldata_payload_kind
(sz: integer_size)
(k: parser_kind)
: parser_kind
= strong_parser_kind 0 (parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_payload
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(i: bounded_integer sz { f i == true } )
: Tot (parser (parse_vldata_payload_kind sz k) t)
= weaken (parse_vldata_payload_kind sz k) (parse_fldata p (U32.v i))
#set-options "--z3rlimit 64"
let parse_fldata_and_then_cases_injective
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p))
= parser_kind_prop_equiv k p;
let g
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1 b2: bytes)
: Lemma
(requires (and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2))
(ensures (len1 == len2))
= assert (injective_precond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (injective_postcond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (len1 == len2)
in
let g'
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1: bytes)
: Lemma
(forall (b2: bytes) . and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2 ==> len1 == len2)
= Classical.forall_intro (Classical.move_requires (g len1 len2 b1))
in
Classical.forall_intro_3 g'
#reset-options
// unfold
let parse_vldata_gen_kind
(sz: integer_size)
(k: parser_kind)
: Tot parser_kind
= strong_parser_kind sz (sz + parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_gen_kind_correct
(sz: integer_size)
(k: parser_kind)
: Lemma
( (parse_vldata_gen_kind sz k) == (and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k)))
= let kl = parse_vldata_gen_kind sz k in
let kr = and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) in
assert_norm (kl == kr)
val parse_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_vldata_gen_kind sz k) t)
val parse_vldata_gen_eq_def
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p) /\
parse_vldata_gen_kind sz k == and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) /\
parse_vldata_gen sz f p ==
and_then
#_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t
(parse_vldata_payload sz f p))
let parse_vldata_gen_eq
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(let res = parse (parse_vldata_gen sz f p) input in
match parse (parse_bounded_integer sz) input with
| None -> res == None
| Some (len, consumed_len) ->
consumed_len == sz /\ (
if f len
then begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
else res == None
))
= parse_vldata_gen_eq_def sz f p;
and_then_eq #_ #(parse_filter_refine f) (parse_filter (parse_bounded_integer sz) f) #_ #t (parse_vldata_payload sz f p) input;
parse_filter_eq #_ #(bounded_integer sz) (parse_bounded_integer sz) f input;
parser_kind_prop_equiv (parse_bounded_integer_kind sz) (parse_bounded_integer sz);
()
let parse_vldata_gen_eq_some_elim
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(requires (Some? (parse (parse_vldata_gen sz f p) input)))
(ensures (
let pbi = parse (parse_bounded_integer sz) input in
Some? pbi /\ (
let Some (len, consumed_len) = pbi in
consumed_len == sz /\
f len /\
Seq.length input >= sz + U32.v len /\ (
let input' = Seq.slice input sz (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let Some (x, consumed_x) = pp in
consumed_x = U32.v len /\
parse (parse_vldata_gen sz f p) input == Some (x, sz + U32.v len)
)))))
= parse_vldata_gen_eq sz f p input
let unconstrained_bounded_integer
(sz: integer_size)
(i: bounded_integer sz)
: GTot bool
= true
let parse_vldata
(sz: integer_size)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser _ t)
= parse_vldata_gen sz (unconstrained_bounded_integer sz) p
let parse_vldata_eq
(sz: integer_size)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(parse (parse_vldata sz p) input == (match parse (parse_bounded_integer sz) input with
| None -> None
| Some (len, _) ->
begin
if Seq.length input < sz + U32.v len
then None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then Some (x, sz + U32.v len)
else None
| _ -> None
end | false | false | LowParse.Spec.VLData.fsti | {
"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"
} | null | val parse_vldata_eq (sz: integer_size) (#k: parser_kind) (#t: Type) (p: parser k t) (input: bytes)
: Lemma
(parse (parse_vldata sz p) input ==
(match parse (parse_bounded_integer sz) input with
| None -> None
| Some (len, _) ->
if Seq.length input < sz + U32.v len
then None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len then Some (x, sz + U32.v len) else None
| _ -> None)) | [] | LowParse.Spec.VLData.parse_vldata_eq | {
"file_name": "src/lowparse/LowParse.Spec.VLData.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
sz: LowParse.Spec.BoundedInt.integer_size ->
p: LowParse.Spec.Base.parser k t ->
input: LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(ensures
LowParse.Spec.Base.parse (LowParse.Spec.VLData.parse_vldata sz p) input ==
(match LowParse.Spec.Base.parse (LowParse.Spec.BoundedInt.parse_bounded_integer sz) input with
| FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None
| FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ len _) ->
(match FStar.Seq.Base.length input < sz + FStar.UInt32.v len with
| true -> FStar.Pervasives.Native.None
| _ ->
let input' = FStar.Seq.Base.slice input sz (sz + FStar.UInt32.v len) in
(match LowParse.Spec.Base.parse p input' with
| FStar.Pervasives.Native.Some
#_
(FStar.Pervasives.Native.Mktuple2 #_ #_ x consumed_x) ->
(match consumed_x = FStar.UInt32.v len with
| true -> FStar.Pervasives.Native.Some (x, sz + FStar.UInt32.v len)
| _ -> FStar.Pervasives.Native.None)
<:
FStar.Pervasives.Native.option (t * LowParse.Spec.Base.consumed_length input)
| _ -> FStar.Pervasives.Native.None)
<:
FStar.Pervasives.Native.option (t * LowParse.Spec.Base.consumed_length input))
<:
FStar.Pervasives.Native.option (t * LowParse.Spec.Base.consumed_length input))) | {
"end_col": 66,
"end_line": 219,
"start_col": 2,
"start_line": 219
} |
Prims.Pure | val parse_bounded_vldata_strong_kind (min max l: nat) (k: parser_kind)
: Pure parser_kind
(requires (min <= max /\ max > 0 /\ max < 4294967296 /\ l >= log256' max /\ l <= 4))
(ensures (fun _ -> True)) | [
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.AllIntegers",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let parse_bounded_vldata_strong_kind
(min: nat)
(max: nat)
(l: nat)
(k: parser_kind)
: Pure parser_kind
(requires (min <= max /\ max > 0 /\ max < 4294967296 /\ l >= log256' max /\ l <= 4 ))
(ensures (fun _ -> True))
= [@inline_let]
let kmin = k.parser_kind_low in
[@inline_let]
let min' = if kmin > min then kmin else min in
[@inline_let]
let max' = match k.parser_kind_high with
| None -> max
| Some kmax -> if kmax < max then kmax else max
in
[@inline_let]
let max' = if max' < min' then min' else max' in
(* the size of the length prefix must conform to the max bound given by the user, not on the metadata *)
strong_parser_kind (l + min') (l + max') (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
) | val parse_bounded_vldata_strong_kind (min max l: nat) (k: parser_kind)
: Pure parser_kind
(requires (min <= max /\ max > 0 /\ max < 4294967296 /\ l >= log256' max /\ l <= 4))
(ensures (fun _ -> True))
let parse_bounded_vldata_strong_kind (min max l: nat) (k: parser_kind)
: Pure parser_kind
(requires (min <= max /\ max > 0 /\ max < 4294967296 /\ l >= log256' max /\ l <= 4))
(ensures (fun _ -> True)) = | false | null | false | [@@ inline_let ]let kmin = k.parser_kind_low in
[@@ inline_let ]let min' = if kmin > min then kmin else min in
[@@ inline_let ]let max' =
match k.parser_kind_high with
| None -> max
| Some kmax -> if kmax < max then kmax else max
in
[@@ inline_let ]let max' = if max' < min' then min' else max' in
strong_parser_kind (l + min')
(l + max')
(match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None) | {
"checked_file": "LowParse.Spec.VLData.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.AllIntegers.fst.checked",
"LowParse.Math.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Spec.VLData.fsti"
} | [] | [
"Prims.nat",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.strong_parser_kind",
"Prims.op_Addition",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_metadata",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.parser_kind_metadata_some",
"LowParse.Spec.Base.ParserKindMetadataFail",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.None",
"LowParse.Spec.Base.parser_kind_metadata_t",
"Prims.int",
"Prims.op_LessThan",
"Prims.bool",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high",
"Prims.op_GreaterThan",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThanOrEqual",
"LowParse.Spec.BoundedInt.log256'",
"Prims.l_True"
] | [] | module LowParse.Spec.VLData
include LowParse.Spec.FLData
include LowParse.Spec.AllIntegers // for bounded_integer, in_bounds, etc.
module Seq = FStar.Seq
module U32 = FStar.UInt32
module M = LowParse.Math
#reset-options "--z3rlimit 64 --max_fuel 64 --max_ifuel 64 --z3refresh --z3cliopt smt.arith.nl=false"
let parse_vldata_payload_size
(sz: integer_size)
: Pure nat
(requires True)
(ensures (fun y -> y == pow2 (FStar.Mul.op_Star 8 sz) - 1 ))
= match sz with
| 1 -> 255
| 2 -> 65535
| 3 -> 16777215
| 4 -> 4294967295
#reset-options
// unfold
let parse_vldata_payload_kind
(sz: integer_size)
(k: parser_kind)
: parser_kind
= strong_parser_kind 0 (parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_payload
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(i: bounded_integer sz { f i == true } )
: Tot (parser (parse_vldata_payload_kind sz k) t)
= weaken (parse_vldata_payload_kind sz k) (parse_fldata p (U32.v i))
#set-options "--z3rlimit 64"
let parse_fldata_and_then_cases_injective
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p))
= parser_kind_prop_equiv k p;
let g
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1 b2: bytes)
: Lemma
(requires (and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2))
(ensures (len1 == len2))
= assert (injective_precond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (injective_postcond p (Seq.slice b1 0 (U32.v len1)) (Seq.slice b2 0 (U32.v len2)));
assert (len1 == len2)
in
let g'
(len1 len2: (len: bounded_integer sz { f len == true } ))
(b1: bytes)
: Lemma
(forall (b2: bytes) . and_then_cases_injective_precond (parse_vldata_payload sz f p) len1 len2 b1 b2 ==> len1 == len2)
= Classical.forall_intro (Classical.move_requires (g len1 len2 b1))
in
Classical.forall_intro_3 g'
#reset-options
// unfold
let parse_vldata_gen_kind
(sz: integer_size)
(k: parser_kind)
: Tot parser_kind
= strong_parser_kind sz (sz + parse_vldata_payload_size sz) (
match k.parser_kind_metadata with
| Some ParserKindMetadataFail -> Some ParserKindMetadataFail
| _ -> None
)
let parse_vldata_gen_kind_correct
(sz: integer_size)
(k: parser_kind)
: Lemma
( (parse_vldata_gen_kind sz k) == (and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k)))
= let kl = parse_vldata_gen_kind sz k in
let kr = and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) in
assert_norm (kl == kr)
val parse_vldata_gen
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser (parse_vldata_gen_kind sz k) t)
val parse_vldata_gen_eq_def
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Lemma
(and_then_cases_injective (parse_vldata_payload sz f p) /\
parse_vldata_gen_kind sz k == and_then_kind (parse_filter_kind (parse_bounded_integer_kind sz)) (parse_vldata_payload_kind sz k) /\
parse_vldata_gen sz f p ==
and_then
#_
#(parse_filter_refine #(bounded_integer sz) f)
(parse_filter #_ #(bounded_integer sz) (parse_bounded_integer sz) f)
#_
#t
(parse_vldata_payload sz f p))
let parse_vldata_gen_eq
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(let res = parse (parse_vldata_gen sz f p) input in
match parse (parse_bounded_integer sz) input with
| None -> res == None
| Some (len, consumed_len) ->
consumed_len == sz /\ (
if f len
then begin
if Seq.length input < sz + U32.v len
then res == None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then res == Some (x, sz + U32.v len)
else res == None
| _ -> res == None
end
else res == None
))
= parse_vldata_gen_eq_def sz f p;
and_then_eq #_ #(parse_filter_refine f) (parse_filter (parse_bounded_integer sz) f) #_ #t (parse_vldata_payload sz f p) input;
parse_filter_eq #_ #(bounded_integer sz) (parse_bounded_integer sz) f input;
parser_kind_prop_equiv (parse_bounded_integer_kind sz) (parse_bounded_integer sz);
()
let parse_vldata_gen_eq_some_elim
(sz: integer_size)
(f: (bounded_integer sz -> GTot bool))
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(requires (Some? (parse (parse_vldata_gen sz f p) input)))
(ensures (
let pbi = parse (parse_bounded_integer sz) input in
Some? pbi /\ (
let Some (len, consumed_len) = pbi in
consumed_len == sz /\
f len /\
Seq.length input >= sz + U32.v len /\ (
let input' = Seq.slice input sz (sz + U32.v len) in
let pp = parse p input' in
Some? pp /\ (
let Some (x, consumed_x) = pp in
consumed_x = U32.v len /\
parse (parse_vldata_gen sz f p) input == Some (x, sz + U32.v len)
)))))
= parse_vldata_gen_eq sz f p input
let unconstrained_bounded_integer
(sz: integer_size)
(i: bounded_integer sz)
: GTot bool
= true
let parse_vldata
(sz: integer_size)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (parser _ t)
= parse_vldata_gen sz (unconstrained_bounded_integer sz) p
let parse_vldata_eq
(sz: integer_size)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(input: bytes)
: Lemma
(parse (parse_vldata sz p) input == (match parse (parse_bounded_integer sz) input with
| None -> None
| Some (len, _) ->
begin
if Seq.length input < sz + U32.v len
then None
else
let input' = Seq.slice input sz (sz + U32.v len) in
match parse p input' with
| Some (x, consumed_x) ->
if consumed_x = U32.v len
then Some (x, sz + U32.v len)
else None
| _ -> None
end
))
= parse_vldata_gen_eq sz (unconstrained_bounded_integer _) p input
(** Explicit bounds on size *)
#reset-options
inline_for_extraction
let parse_bounded_vldata_strong_kind
(min: nat)
(max: nat)
(l: nat)
(k: parser_kind)
: Pure parser_kind
(requires (min <= max /\ max > 0 /\ max < 4294967296 /\ l >= log256' max /\ l <= 4 )) | false | false | LowParse.Spec.VLData.fsti | {
"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"
} | null | val parse_bounded_vldata_strong_kind (min max l: nat) (k: parser_kind)
: Pure parser_kind
(requires (min <= max /\ max > 0 /\ max < 4294967296 /\ l >= log256' max /\ l <= 4))
(ensures (fun _ -> True)) | [] | LowParse.Spec.VLData.parse_bounded_vldata_strong_kind | {
"file_name": "src/lowparse/LowParse.Spec.VLData.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | min: Prims.nat -> max: Prims.nat -> l: Prims.nat -> k: LowParse.Spec.Base.parser_kind
-> Prims.Pure LowParse.Spec.Base.parser_kind | {
"end_col": 3,
"end_line": 250,
"start_col": 2,
"start_line": 234
} |
Subsets and Splits