file_name
stringlengths 5
52
| name
stringlengths 4
95
| original_source_type
stringlengths 0
23k
| source_type
stringlengths 9
23k
| source_definition
stringlengths 9
57.9k
| source
dict | source_range
dict | file_context
stringlengths 0
721k
| dependencies
dict | opens_and_abbrevs
listlengths 2
94
| vconfig
dict | interleaved
bool 1
class | verbose_type
stringlengths 1
7.42k
| effect
stringclasses 118
values | effect_flags
sequencelengths 0
2
| mutual_with
sequencelengths 0
11
| ideal_premises
sequencelengths 0
236
| proof_features
sequencelengths 0
1
| is_simple_lemma
bool 2
classes | is_div
bool 2
classes | is_proof
bool 2
classes | is_simply_typed
bool 2
classes | is_type
bool 2
classes | partial_definition
stringlengths 5
3.99k
| completed_definiton
stringlengths 1
1.63M
| isa_cross_project_example
bool 1
class |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
LowParse.Low.ErrorCode.fst | LowParse.Low.ErrorCode.max_uint32_as_uint64 | val max_uint32_as_uint64:U64.t | val max_uint32_as_uint64:U64.t | let max_uint32_as_uint64 : U64.t = _max_uint32_as_uint64 | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 56,
"end_line": 35,
"start_col": 0,
"start_line": 35
} | module LowParse.Low.ErrorCode
(*
Error codes for validators
TODO: replace with type classes
inline_for_extraction
let default_validator_cls : validator_cls = {
validator_max_length = 4294967279ul;
}
*)
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
[@ CMacro ]
let max_uint32 : U32.t = 4294967295ul
let max_uint32_correct
(x: U32.t)
: Lemma
(U32.v x <= U32.v max_uint32)
= ()
inline_for_extraction
noextract
let _max_uint32_as_uint64 : U64.t = 4294967295uL | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ErrorCode.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | FStar.UInt64.t | Prims.Tot | [
"total"
] | [] | [
"LowParse.Low.ErrorCode._max_uint32_as_uint64"
] | [] | false | false | false | true | false | let max_uint32_as_uint64:U64.t =
| _max_uint32_as_uint64 | false |
LowParse.Low.ErrorCode.fst | LowParse.Low.ErrorCode.is_success | val is_success (positionOrError: U64.t) : Tot bool | val is_success (positionOrError: U64.t) : Tot bool | let is_success (positionOrError: U64.t) : Tot bool = positionOrError `U64.lte` validator_max_length | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 99,
"end_line": 44,
"start_col": 0,
"start_line": 44
} | module LowParse.Low.ErrorCode
(*
Error codes for validators
TODO: replace with type classes
inline_for_extraction
let default_validator_cls : validator_cls = {
validator_max_length = 4294967279ul;
}
*)
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
[@ CMacro ]
let max_uint32 : U32.t = 4294967295ul
let max_uint32_correct
(x: U32.t)
: Lemma
(U32.v x <= U32.v max_uint32)
= ()
inline_for_extraction
noextract
let _max_uint32_as_uint64 : U64.t = 4294967295uL
[@ CMacro ]
let max_uint32_as_uint64 : U64.t = _max_uint32_as_uint64
[@ CMacro ]
let validator_max_length : (u: U64.t { 4 <= U64.v u /\ U64.v u <= U64.v max_uint32_as_uint64 } ) = _max_uint32_as_uint64
[@ CInline ]
let is_error (positionOrError: U64.t) : Tot bool = positionOrError `U64.gt` validator_max_length | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ErrorCode.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | positionOrError: FStar.UInt64.t -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt64.t",
"FStar.UInt64.lte",
"LowParse.Low.ErrorCode.validator_max_length",
"Prims.bool"
] | [] | false | false | false | true | false | let is_success (positionOrError: U64.t) : Tot bool =
| positionOrError `U64.lte` validator_max_length | false |
LowParse.Low.ErrorCode.fst | LowParse.Low.ErrorCode.is_error | val is_error (positionOrError: U64.t) : Tot bool | val is_error (positionOrError: U64.t) : Tot bool | let is_error (positionOrError: U64.t) : Tot bool = positionOrError `U64.gt` validator_max_length | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 96,
"end_line": 41,
"start_col": 0,
"start_line": 41
} | module LowParse.Low.ErrorCode
(*
Error codes for validators
TODO: replace with type classes
inline_for_extraction
let default_validator_cls : validator_cls = {
validator_max_length = 4294967279ul;
}
*)
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
[@ CMacro ]
let max_uint32 : U32.t = 4294967295ul
let max_uint32_correct
(x: U32.t)
: Lemma
(U32.v x <= U32.v max_uint32)
= ()
inline_for_extraction
noextract
let _max_uint32_as_uint64 : U64.t = 4294967295uL
[@ CMacro ]
let max_uint32_as_uint64 : U64.t = _max_uint32_as_uint64
[@ CMacro ]
let validator_max_length : (u: U64.t { 4 <= U64.v u /\ U64.v u <= U64.v max_uint32_as_uint64 } ) = _max_uint32_as_uint64 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ErrorCode.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | positionOrError: FStar.UInt64.t -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt64.t",
"FStar.UInt64.gt",
"LowParse.Low.ErrorCode.validator_max_length",
"Prims.bool"
] | [] | false | false | false | true | false | let is_error (positionOrError: U64.t) : Tot bool =
| positionOrError `U64.gt` validator_max_length | false |
FStar.PCM.fst | FStar.PCM.frame_preserving_subframe | val frame_preserving_subframe
(#a: Type u#a)
(p: pcm a)
(x y: a)
(subframe: a{composable p x subframe /\ composable p y subframe})
(f: frame_preserving_upd p x y)
: frame_preserving_upd p (op p x subframe) (op p y subframe) | val frame_preserving_subframe
(#a: Type u#a)
(p: pcm a)
(x y: a)
(subframe: a{composable p x subframe /\ composable p y subframe})
(f: frame_preserving_upd p x y)
: frame_preserving_upd p (op p x subframe) (op p y subframe) | let frame_preserving_subframe (#a:Type u#a) (p:pcm a) (x y:a)
(subframe:a{composable p x subframe /\ composable p y subframe})
(f:frame_preserving_upd p x y)
: frame_preserving_upd p (op p x subframe) (op p y subframe)
= fun v ->
compatible_elim p (op p x subframe) v (compatible p x v) (fun frame ->
p.comm x subframe;
p.assoc frame subframe x);
let w = f v in
let aux (frame: a{composable p (op p x subframe) frame}):
Lemma (composable p (op p y subframe) frame /\
(op p (op p x subframe) frame == v ==> op p (op p y subframe) frame == w))
[SMTPat (composable p (op p y subframe) frame)]
= p.assoc_r x subframe frame;
assert (composable p x (op p subframe frame));
assert (composable p y (op p subframe frame));
p.assoc y subframe frame
in
compatible_elim p (op p x subframe) v (compatible p (op p y subframe) w) (fun frame ->
aux frame;
p.comm frame (op p x subframe);
p.comm (op p y subframe) frame);
w | {
"file_name": "ulib/FStar.PCM.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 5,
"end_line": 231,
"start_col": 0,
"start_line": 209
} | (*
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 FStar.PCM
/// This module defines the partial commutative monoid (PCM) algebraic structure, as well as helper
/// predicates and functions to manipulate PCMs.
(**** Base definitions *)
(** A symmetric relation *)
let symrel (a: Type u#a) = c:(a -> a -> prop) { (forall x y. c x y <==> c y x) }
(** [pcm'] is a magma, the base for the partial commutative monoid *)
noeq
type pcm' (a:Type u#a) = {
composable: symrel a;
op: x:a -> y:a{composable x y} -> a;
one:a
}
(** The type of a commutativity property *)
let lem_commutative (#a: Type u#a) (p:pcm' a) =
x:a ->
y:a{p.composable x y} ->
Lemma (p.op x y == p.op y x)
(** The type of a left-associativity property *)
let lem_assoc_l (#a: Type u#a) (p:pcm' a) =
x:a ->
y:a ->
z:a{p.composable y z /\ p.composable x (p.op y z)} ->
Lemma (p.composable x y /\
p.composable (p.op x y) z /\
p.op x (p.op y z) == p.op (p.op x y) z)
(** The type of a right-associativity property *)
let lem_assoc_r (#a: Type u#a) (p:pcm' a) =
x:a ->
y:a ->
z:a {p.composable x y /\
p.composable (p.op x y) z} ->
Lemma
(p.composable y z /\
p.composable x (p.op y z) /\
p.op x (p.op y z) == p.op (p.op x y) z)
(** The type of the property characterizing the unit element of the monoid *)
let lem_is_unit (#a: Type u#a) (p:pcm' a) =
x:a ->
Lemma (p.composable x p.one /\
p.op x p.one == x)
(** Main type describing partial commutative monoids *)
noeq
type pcm (a:Type u#a) = {
p:pcm' a;
comm:lem_commutative p;
assoc: lem_assoc_l p;
assoc_r: lem_assoc_r p;
is_unit: lem_is_unit p;
refine: a -> prop
}
(**** Derived predicates *)
(** Returns the composable predicate of the PCM *)
let composable (#a: Type u#a) (p:pcm a) (x y:a) = p.p.composable x y
(** Calls the operation of the PCM *)
let op (#a: Type u#a) (p:pcm a) (x:a) (y:a{composable p x y}) = p.p.op x y
(**
Two elements [x] and [y] are compatible with respect to a PCM if their subtraction
is well-defined, e.g. if there exists an element [frame] such that [x * z = y]
*)
let compatible (#a: Type u#a) (pcm:pcm a) (x y:a) =
(exists (frame:a).
composable pcm x frame /\ op pcm frame x == y
)
(** Compatibility is reflexive *)
let compatible_refl
(#a: Type u#a) (pcm:pcm a) (x:a)
: Lemma (compatible pcm x x)
=
pcm.is_unit x;
pcm.comm x pcm.p.one;
assert (op pcm pcm.p.one x == x)
(** Compatibility is transitive *)
let compatible_trans
(#a: Type u#a) (pcm:pcm a) (x y z:a)
: Lemma (requires (compatible pcm x y /\ compatible pcm y z))
(ensures (compatible pcm x z))
= Classical.forall_intro_3 pcm.assoc
(**
Helper function to get access to the existentially quantified frame between two compatible
elements
*)
let compatible_elim
(#a: Type u#a) (pcm:pcm a) (x y:a)
(goal: Type)
(lemma: (frame: a{composable pcm x frame /\ op pcm frame x == y}) ->
Lemma (goal)
)
: Lemma (requires (compatible pcm x y)) (ensures (goal))
=
Classical.exists_elim
goal #a #(fun frame -> composable pcm x frame /\ op pcm frame x == y)
() (fun frame -> lemma frame)
let compatible_intro
(#a: Type u#a) (pcm:pcm a) (x y:a)
(frame: a)
: Lemma
(requires (composable pcm x frame /\ op pcm frame x == y))
(ensures (compatible pcm x y))
= ()
(** Two elements are joinable when they can evolve to a common point. *)
let joinable #a (p:pcm a) (x y : a) : prop =
exists z. compatible p x z /\ compatible p y z
let frame_compatible #a (p:pcm a) (x:FStar.Ghost.erased a) (v y:a) =
(forall (frame:a). {:pattern (composable p x frame)}
composable p x frame /\
v == op p x frame ==>
composable p y frame /\
v == op p y frame)
(*
* Frame preserving updates from x to y
* - should preserve all frames,
* - and a frame containing rest of the PCM value should continue to do so
*)
type frame_preserving_upd (#a:Type u#a) (p:pcm a) (x y:a) =
v:a{
p.refine v /\
compatible p x v
} ->
v_new:a{
p.refine v_new /\
compatible p y v_new /\
(forall (frame:a{composable p x frame}).{:pattern composable p x frame}
composable p y frame /\
(op p x frame == v ==> op p y frame == v_new))}
(*
* A specific case of frame preserving updates when y is a refined value
*
* All the frames of x should compose with--and the composition should result in--y
*)
let frame_preserving (#a: Type u#a) (pcm:pcm a) (x y: a) =
(forall frame. composable pcm frame x ==> composable pcm frame y) /\
(forall frame.{:pattern (composable pcm frame x)} composable pcm frame x ==> op pcm frame y == y)
(*
* As expected, given frame_preserving, we can construct a frame_preserving_update
*)
let frame_preserving_val_to_fp_upd (#a:Type u#a) (p:pcm a)
(x:Ghost.erased a) (v:a{frame_preserving p x v /\ p.refine v})
: frame_preserving_upd p x v
= Classical.forall_intro (p.comm v);
fun _ -> v
(** The PCM [p] is exclusive to element [x] if the only element composable with [x] is [p.one] *)
let exclusive (#a:Type u#a) (p:pcm a) (x:a) =
forall (frame:a). composable p x frame ==> frame == p.p.one
(** A mutation from [x] to [p.one] is frame preserving if [p] is exclusive to [x] *)
let exclusive_is_frame_preserving (#a: Type u#a) (p:pcm a) (x:a)
: Lemma (requires exclusive p x)
(ensures frame_preserving p x p.p.one)
= p.is_unit x;
p.is_unit p.p.one
(* Some sanity checks on the definition of frame preserving updates *)
let no_op_is_frame_preserving (#a:Type u#a) (p:pcm a)
(x:a)
: frame_preserving_upd p x x
= fun v -> v
let compose_frame_preserving_updates (#a:Type u#a) (p:pcm a)
(x y z:a)
(f:frame_preserving_upd p x y)
(g:frame_preserving_upd p y z)
: frame_preserving_upd p x z
= fun v -> g (f v) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.PCM.fst"
} | [
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: FStar.PCM.pcm a ->
x: a ->
y: a ->
subframe: a{FStar.PCM.composable p x subframe /\ FStar.PCM.composable p y subframe} ->
f: FStar.PCM.frame_preserving_upd p x y
-> FStar.PCM.frame_preserving_upd p (FStar.PCM.op p x subframe) (FStar.PCM.op p y subframe) | Prims.Tot | [
"total"
] | [] | [
"FStar.PCM.pcm",
"Prims.l_and",
"FStar.PCM.composable",
"FStar.PCM.frame_preserving_upd",
"FStar.PCM.__proj__Mkpcm__item__refine",
"FStar.PCM.compatible",
"FStar.PCM.op",
"Prims.unit",
"FStar.PCM.compatible_elim",
"Prims.eq2",
"FStar.PCM.__proj__Mkpcm__item__comm",
"Prims.l_True",
"Prims.squash",
"Prims.l_imp",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.prop",
"Prims.Nil",
"FStar.PCM.__proj__Mkpcm__item__assoc",
"Prims._assert",
"FStar.PCM.__proj__Mkpcm__item__assoc_r",
"Prims.l_Forall"
] | [] | false | false | false | false | false | let frame_preserving_subframe
(#a: Type u#a)
(p: pcm a)
(x y: a)
(subframe: a{composable p x subframe /\ composable p y subframe})
(f: frame_preserving_upd p x y)
: frame_preserving_upd p (op p x subframe) (op p y subframe) =
| fun v ->
compatible_elim p
(op p x subframe)
v
(compatible p x v)
(fun frame ->
p.comm x subframe;
p.assoc frame subframe x);
let w = f v in
let aux (frame: a{composable p (op p x subframe) frame})
: Lemma
(composable p (op p y subframe) frame /\
(op p (op p x subframe) frame == v ==> op p (op p y subframe) frame == w))
[SMTPat (composable p (op p y subframe) frame)] =
p.assoc_r x subframe frame;
assert (composable p x (op p subframe frame));
assert (composable p y (op p subframe frame));
p.assoc y subframe frame
in
compatible_elim p
(op p x subframe)
v
(compatible p (op p y subframe) w)
(fun frame ->
aux frame;
p.comm frame (op p x subframe);
p.comm (op p y subframe) frame);
w | false |
Hacl.Impl.Salsa20.fst | Hacl.Impl.Salsa20.salsa20_key_block0 | val salsa20_key_block0:
out:lbuffer uint8 64ul
-> key:lbuffer uint8 32ul
-> n:lbuffer uint8 8ul ->
Stack unit
(requires fun h -> live h key /\ live h n /\ live h out)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
as_seq h1 out == Spec.salsa20_key_block0 (as_seq h0 key) (as_seq h0 n)) | val salsa20_key_block0:
out:lbuffer uint8 64ul
-> key:lbuffer uint8 32ul
-> n:lbuffer uint8 8ul ->
Stack unit
(requires fun h -> live h key /\ live h n /\ live h out)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
as_seq h1 out == Spec.salsa20_key_block0 (as_seq h0 key) (as_seq h0 n)) | let salsa20_key_block0 out key n =
push_frame();
let ctx = create_state () in
let k = create_state() in
salsa20_init ctx key n 0ul;
salsa20_core k ctx 0ul;
store_state out k;
pop_frame() | {
"file_name": "code/salsa20/Hacl.Impl.Salsa20.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 13,
"end_line": 200,
"start_col": 0,
"start_line": 193
} | module Hacl.Impl.Salsa20
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Salsa20.Core32
module ST = FStar.HyperStack.ST
module Spec = Spec.Salsa20
module Loop = Lib.LoopCombinators
#set-options "--z3rlimit 100 --max_fuel 0"
val rounds: st:state ->
Stack unit
(requires fun h -> live h st)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Spec.rounds (as_seq h0 st))
[@ CInline]
let rounds st =
let h0 = ST.get () in
Loop.eq_repeat0 #Spec.state Spec.double_round (as_seq h0 st);
Loop.unfold_repeat 10 Spec.double_round (as_seq h0 st) 0;
Loop.unfold_repeat 10 Spec.double_round (as_seq h0 st) 1;
Loop.unfold_repeat 10 Spec.double_round (as_seq h0 st) 2;
Loop.unfold_repeat 10 Spec.double_round (as_seq h0 st) 3;
Loop.unfold_repeat 10 Spec.double_round (as_seq h0 st) 4;
Loop.unfold_repeat 10 Spec.double_round (as_seq h0 st) 5;
Loop.unfold_repeat 10 Spec.double_round (as_seq h0 st) 6;
Loop.unfold_repeat 10 Spec.double_round (as_seq h0 st) 7;
Loop.unfold_repeat 10 Spec.double_round (as_seq h0 st) 8;
Loop.unfold_repeat 10 Spec.double_round (as_seq h0 st) 9;
double_round st;
double_round st;
double_round st;
double_round st;
double_round st;
double_round st;
double_round st;
double_round st;
double_round st;
double_round st
val salsa20_core:
k:state
-> ctx0:state
-> ctr:size_t ->
Stack unit
(requires fun h -> live h ctx0 /\ live h k /\ disjoint ctx0 k)
(ensures fun h0 _ h1 -> modifies (loc k) h0 h1 /\
as_seq h1 k == Spec.salsa20_core (v ctr) (as_seq h0 ctx0))
[@ CInline ]
let salsa20_core k ctx ctr =
copy_state k ctx;
let ctr_u32 = size_to_uint32 ctr in
k.(8ul) <- k.(8ul) +. ctr_u32;
rounds k;
sum_state k ctx;
k.(8ul) <- k.(8ul) +. ctr_u32
#set-options "--z3rlimit 100 --max_fuel 2"
inline_for_extraction
val salsa20_init:
ctx:state
-> k:lbuffer uint8 32ul
-> n:lbuffer uint8 8ul
-> ctr0:size_t ->
Stack unit
(requires fun h ->
live h ctx /\ live h k /\ live h n /\
disjoint ctx k /\ disjoint ctx n /\
as_seq h ctx == Lib.Sequence.create 16 (u32 0))
(ensures fun h0 _ h1 -> modifies (loc ctx) h0 h1 /\
as_seq h1 ctx == Spec.salsa20_init (as_seq h0 k) (as_seq h0 n) (v ctr0))
let salsa20_init ctx k n ctr =
let h0 = ST.get() in
push_frame();
let k32 = create 8ul (u32 0) in
let n32 = create 2ul (u32 0) in
let h0' = ST.get() in
uints_from_bytes_le k32 k;
uints_from_bytes_le n32 n;
ctx.(0ul) <- Spec.constant0;
let k0 = sub k32 0ul 4ul in
let k1 = sub k32 4ul 4ul in
update_sub #MUT ctx 1ul 4ul k0;
ctx.(5ul) <- Spec.constant1;
update_sub #MUT ctx 6ul 2ul n32;
ctx.(8ul) <- secret ctr;
ctx.(9ul) <- u32 0;
ctx.(10ul) <- Spec.constant2;
update_sub #MUT ctx 11ul 4ul k1;
ctx.(15ul) <- Spec.constant3;
let h1' = ST.get() in
assert (modifies (loc ctx |+| loc k32 |+| loc n32) h0' h1');
pop_frame();
let h1 = ST.get() in
assert (modifies (loc ctx) h0 h1)
inline_for_extraction
val salsa20_encrypt_block:
ctx:state
-> out:lbuffer uint8 64ul
-> incr:size_t
-> text:lbuffer uint8 64ul ->
Stack unit
(requires fun h ->
live h ctx /\ live h text /\ live h out /\
disjoint out ctx /\ disjoint text ctx)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
as_seq h1 out == Spec.salsa20_encrypt_block (as_seq h0 ctx) (v incr) (as_seq h0 text))
let salsa20_encrypt_block ctx out incr text =
push_frame();
let k = create 16ul (u32 0) in
salsa20_core k ctx incr;
xor_block out k text;
pop_frame()
inline_for_extraction
val salsa20_encrypt_last:
ctx:state
-> len:size_t{v len < 64}
-> out:lbuffer uint8 len
-> incr:size_t
-> text:lbuffer uint8 len ->
Stack unit
(requires fun h ->
live h ctx /\ live h text /\ live h out /\
disjoint out ctx /\ disjoint text ctx)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
as_seq h1 out == Spec.salsa20_encrypt_last (as_seq h0 ctx) (v incr) (v len) (as_seq h0 text))
let salsa20_encrypt_last ctx len out incr text =
push_frame();
let plain = create (size 64) (u8 0) in
update_sub plain 0ul len text;
salsa20_encrypt_block ctx plain incr plain;
copy out (sub plain 0ul len);
pop_frame()
inline_for_extraction
val salsa20_update:
ctx:state
-> len:size_t
-> out:lbuffer uint8 len
-> text:lbuffer uint8 len ->
Stack unit
(requires fun h ->
live h ctx /\ live h text /\ live h out /\
eq_or_disjoint text out /\ disjoint text ctx /\ disjoint out ctx)
(ensures fun h0 _ h1 -> modifies (loc ctx |+| loc out) h0 h1 /\
as_seq h1 out == Spec.salsa20_update (as_seq h0 ctx) (as_seq h0 text))
let salsa20_update ctx len out text =
push_frame();
let k = create_state () in
let blocks = len /. size 64 in
let rem = len %. size 64 in
let h0 = ST.get() in
map_blocks h0 len 64ul text out
(fun h -> Spec.salsa20_encrypt_block (as_seq h0 ctx))
(fun h -> Spec.salsa20_encrypt_last (as_seq h0 ctx))
(fun i -> salsa20_encrypt_block ctx (sub out (i *! 64ul) 64ul) i (sub text (i *! 64ul) 64ul))
(fun i -> salsa20_encrypt_last ctx rem (sub out (i *! 64ul) rem) i (sub text (i *! 64ul) rem));
pop_frame()
val salsa20_key_block0:
out:lbuffer uint8 64ul
-> key:lbuffer uint8 32ul
-> n:lbuffer uint8 8ul ->
Stack unit
(requires fun h -> live h key /\ live h n /\ live h out)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
as_seq h1 out == Spec.salsa20_key_block0 (as_seq h0 key) (as_seq h0 n)) | {
"checked_file": "/",
"dependencies": [
"Spec.Salsa20.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Salsa20.Core32.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Salsa20.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loop"
},
{
"abbrev": true,
"full_module": "Spec.Salsa20",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Salsa20.Core32",
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 2,
"max_ifuel": 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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
out: Lib.Buffer.lbuffer Lib.IntTypes.uint8 64ul ->
key: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul ->
n: Lib.Buffer.lbuffer Lib.IntTypes.uint8 8ul
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Hacl.Impl.Salsa20.Core32.store_state",
"Hacl.Impl.Salsa20.salsa20_core",
"Hacl.Impl.Salsa20.salsa20_init",
"Hacl.Impl.Salsa20.Core32.state",
"Hacl.Impl.Salsa20.Core32.create_state",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let salsa20_key_block0 out key n =
| push_frame ();
let ctx = create_state () in
let k = create_state () in
salsa20_init ctx key n 0ul;
salsa20_core k ctx 0ul;
store_state out k;
pop_frame () | false |
LowParse.Low.ErrorCode.fst | LowParse.Low.ErrorCode.error_code | val error_code : Type0 | let error_code = (c: U64.t { 0 < U64.v c /\ U64.v c < 65536 }) | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 62,
"end_line": 122,
"start_col": 0,
"start_line": 122
} | module LowParse.Low.ErrorCode
(*
Error codes for validators
TODO: replace with type classes
inline_for_extraction
let default_validator_cls : validator_cls = {
validator_max_length = 4294967279ul;
}
*)
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
[@ CMacro ]
let max_uint32 : U32.t = 4294967295ul
let max_uint32_correct
(x: U32.t)
: Lemma
(U32.v x <= U32.v max_uint32)
= ()
inline_for_extraction
noextract
let _max_uint32_as_uint64 : U64.t = 4294967295uL
[@ CMacro ]
let max_uint32_as_uint64 : U64.t = _max_uint32_as_uint64
[@ CMacro ]
let validator_max_length : (u: U64.t { 4 <= U64.v u /\ U64.v u <= U64.v max_uint32_as_uint64 } ) = _max_uint32_as_uint64
[@ CInline ]
let is_error (positionOrError: U64.t) : Tot bool = positionOrError `U64.gt` validator_max_length
[@ CInline ]
let is_success (positionOrError: U64.t) : Tot bool = positionOrError `U64.lte` validator_max_length
[@ CMacro ]
type validator_error = (u: U64.t { is_error u } )
inline_for_extraction
let pos_t = (pos: U64.t {is_success pos})
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
inline_for_extraction
noextract
let get_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) : Tot (code: U64.t { 0 <= U64.v code /\ U64.v code < pow2 (hi - lo) }) =
[@inline_let]
let res =
BF.uint64.BF.get_bitfield x (32 + lo) (32 + hi)
in
res
inline_for_extraction
noextract
let set_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) (code: U64.t { 0 < U64.v code /\ U64.v code < pow2 (hi - lo) }) : Tot validator_error =
[@inline_let]
let res =
BF.uint64.BF.set_bitfield x (32 + lo) (32 + hi) code
in
[@inline_let]
let _ =
BF.get_bitfield_set_bitfield_same #64 (U64.v x) (32 + lo) (32 + hi) (U64.v code);
BF.get_bitfield_zero_inner (U64.v res) 32 64 (32 + lo) (32 + hi);
assert (BF.get_bitfield (U64.v res) 32 64 > 0);
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res
let get_validator_error_field_set_validator_error_field
(x: U64.t)
(lo: nat)
(hi: nat { lo < hi /\ hi <= 32 })
(code: U64.t { 0 < U64.v code /\ U64.v code < pow2 (hi - lo) })
: Lemma
(get_validator_error_field (set_validator_error_field x lo hi code) lo hi == code)
= ()
[@ CInline ]
let set_validator_error_pos (error: validator_error) (position: pos_t) : Tot validator_error =
[@inline_let]
let res =
BF.uint64.BF.set_bitfield error 0 32 position
in
[@inline_let]
let _ =
BF.get_bitfield_set_bitfield_other (U64.v error) 0 32 (U64.v position) 32 64;
assert (BF.get_bitfield (U64.v res) 32 64 == BF.get_bitfield (U64.v error) 32 64);
Classical.move_requires (BF.get_bitfield_hi_lt_pow2 (U64.v error)) 32;
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res
#pop-options
[@ CInline ]
let get_validator_error_pos (x: U64.t) : Tot pos_t =
(BF.uint64.BF.get_bitfield x 0 32)
[@ CInline ]
let set_validator_error_kind (error: U64.t) (code: U64.t { 0 < U64.v code /\ U64.v code < 16384 }) : Tot validator_error =
set_validator_error_field error 0 14 code
[@ CInline ]
let get_validator_error_kind (error: U64.t) : Tot (code: U64.t { 0 <= U64.v code /\ U64.v code < 16384 }) =
get_validator_error_field error 0 14 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ErrorCode.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt64.t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt64.v"
] | [] | false | false | false | true | true | let error_code =
| (c: U64.t{0 < U64.v c /\ U64.v c < 65536}) | false |
|
LowParse.Low.ErrorCode.fst | LowParse.Low.ErrorCode.validator_max_length | val validator_max_length:(u: U64.t{4 <= U64.v u /\ U64.v u <= U64.v max_uint32_as_uint64}) | val validator_max_length:(u: U64.t{4 <= U64.v u /\ U64.v u <= U64.v max_uint32_as_uint64}) | let validator_max_length : (u: U64.t { 4 <= U64.v u /\ U64.v u <= U64.v max_uint32_as_uint64 } ) = _max_uint32_as_uint64 | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 120,
"end_line": 38,
"start_col": 0,
"start_line": 38
} | module LowParse.Low.ErrorCode
(*
Error codes for validators
TODO: replace with type classes
inline_for_extraction
let default_validator_cls : validator_cls = {
validator_max_length = 4294967279ul;
}
*)
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
[@ CMacro ]
let max_uint32 : U32.t = 4294967295ul
let max_uint32_correct
(x: U32.t)
: Lemma
(U32.v x <= U32.v max_uint32)
= ()
inline_for_extraction
noextract
let _max_uint32_as_uint64 : U64.t = 4294967295uL
[@ CMacro ]
let max_uint32_as_uint64 : U64.t = _max_uint32_as_uint64 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ErrorCode.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | u3:
FStar.UInt64.t
{ 4 <= FStar.UInt64.v u3 /\
FStar.UInt64.v u3 <= FStar.UInt64.v LowParse.Low.ErrorCode.max_uint32_as_uint64 } | Prims.Tot | [
"total"
] | [] | [
"LowParse.Low.ErrorCode._max_uint32_as_uint64"
] | [] | false | false | false | false | false | let validator_max_length:(u: U64.t{4 <= U64.v u /\ U64.v u <= U64.v max_uint32_as_uint64}) =
| _max_uint32_as_uint64 | false |
LowParse.Low.ErrorCode.fst | LowParse.Low.ErrorCode.validator_error_generic | val validator_error_generic:validator_error | val validator_error_generic:validator_error | let validator_error_generic : validator_error = normalize_term (set_validator_error_kind 0uL 1uL) | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 97,
"end_line": 133,
"start_col": 0,
"start_line": 133
} | module LowParse.Low.ErrorCode
(*
Error codes for validators
TODO: replace with type classes
inline_for_extraction
let default_validator_cls : validator_cls = {
validator_max_length = 4294967279ul;
}
*)
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
[@ CMacro ]
let max_uint32 : U32.t = 4294967295ul
let max_uint32_correct
(x: U32.t)
: Lemma
(U32.v x <= U32.v max_uint32)
= ()
inline_for_extraction
noextract
let _max_uint32_as_uint64 : U64.t = 4294967295uL
[@ CMacro ]
let max_uint32_as_uint64 : U64.t = _max_uint32_as_uint64
[@ CMacro ]
let validator_max_length : (u: U64.t { 4 <= U64.v u /\ U64.v u <= U64.v max_uint32_as_uint64 } ) = _max_uint32_as_uint64
[@ CInline ]
let is_error (positionOrError: U64.t) : Tot bool = positionOrError `U64.gt` validator_max_length
[@ CInline ]
let is_success (positionOrError: U64.t) : Tot bool = positionOrError `U64.lte` validator_max_length
[@ CMacro ]
type validator_error = (u: U64.t { is_error u } )
inline_for_extraction
let pos_t = (pos: U64.t {is_success pos})
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
inline_for_extraction
noextract
let get_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) : Tot (code: U64.t { 0 <= U64.v code /\ U64.v code < pow2 (hi - lo) }) =
[@inline_let]
let res =
BF.uint64.BF.get_bitfield x (32 + lo) (32 + hi)
in
res
inline_for_extraction
noextract
let set_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) (code: U64.t { 0 < U64.v code /\ U64.v code < pow2 (hi - lo) }) : Tot validator_error =
[@inline_let]
let res =
BF.uint64.BF.set_bitfield x (32 + lo) (32 + hi) code
in
[@inline_let]
let _ =
BF.get_bitfield_set_bitfield_same #64 (U64.v x) (32 + lo) (32 + hi) (U64.v code);
BF.get_bitfield_zero_inner (U64.v res) 32 64 (32 + lo) (32 + hi);
assert (BF.get_bitfield (U64.v res) 32 64 > 0);
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res
let get_validator_error_field_set_validator_error_field
(x: U64.t)
(lo: nat)
(hi: nat { lo < hi /\ hi <= 32 })
(code: U64.t { 0 < U64.v code /\ U64.v code < pow2 (hi - lo) })
: Lemma
(get_validator_error_field (set_validator_error_field x lo hi code) lo hi == code)
= ()
[@ CInline ]
let set_validator_error_pos (error: validator_error) (position: pos_t) : Tot validator_error =
[@inline_let]
let res =
BF.uint64.BF.set_bitfield error 0 32 position
in
[@inline_let]
let _ =
BF.get_bitfield_set_bitfield_other (U64.v error) 0 32 (U64.v position) 32 64;
assert (BF.get_bitfield (U64.v res) 32 64 == BF.get_bitfield (U64.v error) 32 64);
Classical.move_requires (BF.get_bitfield_hi_lt_pow2 (U64.v error)) 32;
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res
#pop-options
[@ CInline ]
let get_validator_error_pos (x: U64.t) : Tot pos_t =
(BF.uint64.BF.get_bitfield x 0 32)
[@ CInline ]
let set_validator_error_kind (error: U64.t) (code: U64.t { 0 < U64.v code /\ U64.v code < 16384 }) : Tot validator_error =
set_validator_error_field error 0 14 code
[@ CInline ]
let get_validator_error_kind (error: U64.t) : Tot (code: U64.t { 0 <= U64.v code /\ U64.v code < 16384 }) =
get_validator_error_field error 0 14
inline_for_extraction
let error_code = (c: U64.t { 0 < U64.v c /\ U64.v c < 65536 })
[@ CInline ]
let set_validator_error_code (error: U64.t) (code: error_code) : Tot validator_error =
set_validator_error_field error 16 32 code
[@ CInline ]
let get_validator_error_code (error: U64.t) : Tot (code: U64.t { U64.v code < 65536 }) =
get_validator_error_field error 16 32 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ErrorCode.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | LowParse.Low.ErrorCode.validator_error | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.normalize_term",
"LowParse.Low.ErrorCode.validator_error",
"LowParse.Low.ErrorCode.set_validator_error_kind",
"FStar.UInt64.__uint_to_t"
] | [] | false | false | false | true | false | let validator_error_generic:validator_error =
| normalize_term (set_validator_error_kind 0uL 1uL) | false |
LowParse.Low.ErrorCode.fst | LowParse.Low.ErrorCode.set_validator_error_pos_and_code | val set_validator_error_pos_and_code (error: validator_error) (position: pos_t) (code: error_code)
: Tot validator_error | val set_validator_error_pos_and_code (error: validator_error) (position: pos_t) (code: error_code)
: Tot validator_error | let set_validator_error_pos_and_code
(error: validator_error)
(position: pos_t)
(code: error_code)
: Tot validator_error
= set_validator_error_pos (set_validator_error_code error code) position | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 72,
"end_line": 159,
"start_col": 0,
"start_line": 154
} | module LowParse.Low.ErrorCode
(*
Error codes for validators
TODO: replace with type classes
inline_for_extraction
let default_validator_cls : validator_cls = {
validator_max_length = 4294967279ul;
}
*)
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
[@ CMacro ]
let max_uint32 : U32.t = 4294967295ul
let max_uint32_correct
(x: U32.t)
: Lemma
(U32.v x <= U32.v max_uint32)
= ()
inline_for_extraction
noextract
let _max_uint32_as_uint64 : U64.t = 4294967295uL
[@ CMacro ]
let max_uint32_as_uint64 : U64.t = _max_uint32_as_uint64
[@ CMacro ]
let validator_max_length : (u: U64.t { 4 <= U64.v u /\ U64.v u <= U64.v max_uint32_as_uint64 } ) = _max_uint32_as_uint64
[@ CInline ]
let is_error (positionOrError: U64.t) : Tot bool = positionOrError `U64.gt` validator_max_length
[@ CInline ]
let is_success (positionOrError: U64.t) : Tot bool = positionOrError `U64.lte` validator_max_length
[@ CMacro ]
type validator_error = (u: U64.t { is_error u } )
inline_for_extraction
let pos_t = (pos: U64.t {is_success pos})
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
inline_for_extraction
noextract
let get_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) : Tot (code: U64.t { 0 <= U64.v code /\ U64.v code < pow2 (hi - lo) }) =
[@inline_let]
let res =
BF.uint64.BF.get_bitfield x (32 + lo) (32 + hi)
in
res
inline_for_extraction
noextract
let set_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) (code: U64.t { 0 < U64.v code /\ U64.v code < pow2 (hi - lo) }) : Tot validator_error =
[@inline_let]
let res =
BF.uint64.BF.set_bitfield x (32 + lo) (32 + hi) code
in
[@inline_let]
let _ =
BF.get_bitfield_set_bitfield_same #64 (U64.v x) (32 + lo) (32 + hi) (U64.v code);
BF.get_bitfield_zero_inner (U64.v res) 32 64 (32 + lo) (32 + hi);
assert (BF.get_bitfield (U64.v res) 32 64 > 0);
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res
let get_validator_error_field_set_validator_error_field
(x: U64.t)
(lo: nat)
(hi: nat { lo < hi /\ hi <= 32 })
(code: U64.t { 0 < U64.v code /\ U64.v code < pow2 (hi - lo) })
: Lemma
(get_validator_error_field (set_validator_error_field x lo hi code) lo hi == code)
= ()
[@ CInline ]
let set_validator_error_pos (error: validator_error) (position: pos_t) : Tot validator_error =
[@inline_let]
let res =
BF.uint64.BF.set_bitfield error 0 32 position
in
[@inline_let]
let _ =
BF.get_bitfield_set_bitfield_other (U64.v error) 0 32 (U64.v position) 32 64;
assert (BF.get_bitfield (U64.v res) 32 64 == BF.get_bitfield (U64.v error) 32 64);
Classical.move_requires (BF.get_bitfield_hi_lt_pow2 (U64.v error)) 32;
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res
#pop-options
[@ CInline ]
let get_validator_error_pos (x: U64.t) : Tot pos_t =
(BF.uint64.BF.get_bitfield x 0 32)
[@ CInline ]
let set_validator_error_kind (error: U64.t) (code: U64.t { 0 < U64.v code /\ U64.v code < 16384 }) : Tot validator_error =
set_validator_error_field error 0 14 code
[@ CInline ]
let get_validator_error_kind (error: U64.t) : Tot (code: U64.t { 0 <= U64.v code /\ U64.v code < 16384 }) =
get_validator_error_field error 0 14
inline_for_extraction
let error_code = (c: U64.t { 0 < U64.v c /\ U64.v c < 65536 })
[@ CInline ]
let set_validator_error_code (error: U64.t) (code: error_code) : Tot validator_error =
set_validator_error_field error 16 32 code
[@ CInline ]
let get_validator_error_code (error: U64.t) : Tot (code: U64.t { U64.v code < 65536 }) =
get_validator_error_field error 16 32
[@ CMacro ]
let validator_error_generic : validator_error = normalize_term (set_validator_error_kind 0uL 1uL)
[@ CMacro ]
let validator_error_not_enough_data : validator_error = normalize_term (set_validator_error_kind 0uL 2uL)
[@"opaque_to_smt"] // to hide the modulo operation
inline_for_extraction
noextract
let uint64_to_uint32
(x: pos_t)
: Tot (y: U32.t { U32.v y == U64.v x })
= Cast.uint64_to_uint32 x
// [@ CInline ]
// let maybe_set_error_code (res:U64.t) (pos:pos_t) (c:U64.t { 0 < U64.v c /\ U64.v c < 65536 })
// : Tot U64.t
// = if is_error res && get_validator_error_code res = 0uL
// then set_validator_error_pos (set_validator_error_code res c) pos
// else res | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ErrorCode.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
error: LowParse.Low.ErrorCode.validator_error ->
position: LowParse.Low.ErrorCode.pos_t ->
code: LowParse.Low.ErrorCode.error_code
-> LowParse.Low.ErrorCode.validator_error | Prims.Tot | [
"total"
] | [] | [
"LowParse.Low.ErrorCode.validator_error",
"LowParse.Low.ErrorCode.pos_t",
"LowParse.Low.ErrorCode.error_code",
"LowParse.Low.ErrorCode.set_validator_error_pos",
"LowParse.Low.ErrorCode.set_validator_error_code"
] | [] | false | false | false | true | false | let set_validator_error_pos_and_code (error: validator_error) (position: pos_t) (code: error_code)
: Tot validator_error =
| set_validator_error_pos (set_validator_error_code error code) position | false |
LowParse.Low.ErrorCode.fst | LowParse.Low.ErrorCode.validator_error_not_enough_data | val validator_error_not_enough_data:validator_error | val validator_error_not_enough_data:validator_error | let validator_error_not_enough_data : validator_error = normalize_term (set_validator_error_kind 0uL 2uL) | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 105,
"end_line": 136,
"start_col": 0,
"start_line": 136
} | module LowParse.Low.ErrorCode
(*
Error codes for validators
TODO: replace with type classes
inline_for_extraction
let default_validator_cls : validator_cls = {
validator_max_length = 4294967279ul;
}
*)
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
[@ CMacro ]
let max_uint32 : U32.t = 4294967295ul
let max_uint32_correct
(x: U32.t)
: Lemma
(U32.v x <= U32.v max_uint32)
= ()
inline_for_extraction
noextract
let _max_uint32_as_uint64 : U64.t = 4294967295uL
[@ CMacro ]
let max_uint32_as_uint64 : U64.t = _max_uint32_as_uint64
[@ CMacro ]
let validator_max_length : (u: U64.t { 4 <= U64.v u /\ U64.v u <= U64.v max_uint32_as_uint64 } ) = _max_uint32_as_uint64
[@ CInline ]
let is_error (positionOrError: U64.t) : Tot bool = positionOrError `U64.gt` validator_max_length
[@ CInline ]
let is_success (positionOrError: U64.t) : Tot bool = positionOrError `U64.lte` validator_max_length
[@ CMacro ]
type validator_error = (u: U64.t { is_error u } )
inline_for_extraction
let pos_t = (pos: U64.t {is_success pos})
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
inline_for_extraction
noextract
let get_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) : Tot (code: U64.t { 0 <= U64.v code /\ U64.v code < pow2 (hi - lo) }) =
[@inline_let]
let res =
BF.uint64.BF.get_bitfield x (32 + lo) (32 + hi)
in
res
inline_for_extraction
noextract
let set_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) (code: U64.t { 0 < U64.v code /\ U64.v code < pow2 (hi - lo) }) : Tot validator_error =
[@inline_let]
let res =
BF.uint64.BF.set_bitfield x (32 + lo) (32 + hi) code
in
[@inline_let]
let _ =
BF.get_bitfield_set_bitfield_same #64 (U64.v x) (32 + lo) (32 + hi) (U64.v code);
BF.get_bitfield_zero_inner (U64.v res) 32 64 (32 + lo) (32 + hi);
assert (BF.get_bitfield (U64.v res) 32 64 > 0);
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res
let get_validator_error_field_set_validator_error_field
(x: U64.t)
(lo: nat)
(hi: nat { lo < hi /\ hi <= 32 })
(code: U64.t { 0 < U64.v code /\ U64.v code < pow2 (hi - lo) })
: Lemma
(get_validator_error_field (set_validator_error_field x lo hi code) lo hi == code)
= ()
[@ CInline ]
let set_validator_error_pos (error: validator_error) (position: pos_t) : Tot validator_error =
[@inline_let]
let res =
BF.uint64.BF.set_bitfield error 0 32 position
in
[@inline_let]
let _ =
BF.get_bitfield_set_bitfield_other (U64.v error) 0 32 (U64.v position) 32 64;
assert (BF.get_bitfield (U64.v res) 32 64 == BF.get_bitfield (U64.v error) 32 64);
Classical.move_requires (BF.get_bitfield_hi_lt_pow2 (U64.v error)) 32;
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res
#pop-options
[@ CInline ]
let get_validator_error_pos (x: U64.t) : Tot pos_t =
(BF.uint64.BF.get_bitfield x 0 32)
[@ CInline ]
let set_validator_error_kind (error: U64.t) (code: U64.t { 0 < U64.v code /\ U64.v code < 16384 }) : Tot validator_error =
set_validator_error_field error 0 14 code
[@ CInline ]
let get_validator_error_kind (error: U64.t) : Tot (code: U64.t { 0 <= U64.v code /\ U64.v code < 16384 }) =
get_validator_error_field error 0 14
inline_for_extraction
let error_code = (c: U64.t { 0 < U64.v c /\ U64.v c < 65536 })
[@ CInline ]
let set_validator_error_code (error: U64.t) (code: error_code) : Tot validator_error =
set_validator_error_field error 16 32 code
[@ CInline ]
let get_validator_error_code (error: U64.t) : Tot (code: U64.t { U64.v code < 65536 }) =
get_validator_error_field error 16 32
[@ CMacro ]
let validator_error_generic : validator_error = normalize_term (set_validator_error_kind 0uL 1uL) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ErrorCode.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | LowParse.Low.ErrorCode.validator_error | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.normalize_term",
"LowParse.Low.ErrorCode.validator_error",
"LowParse.Low.ErrorCode.set_validator_error_kind",
"FStar.UInt64.__uint_to_t"
] | [] | false | false | false | true | false | let validator_error_not_enough_data:validator_error =
| normalize_term (set_validator_error_kind 0uL 2uL) | false |
LowParse.Low.ErrorCode.fst | LowParse.Low.ErrorCode.get_validator_error_field | val get_validator_error_field (x: U64.t) (lo: nat) (hi: nat{lo < hi /\ hi <= 32})
: Tot (code: U64.t{0 <= U64.v code /\ U64.v code < pow2 (hi - lo)}) | val get_validator_error_field (x: U64.t) (lo: nat) (hi: nat{lo < hi /\ hi <= 32})
: Tot (code: U64.t{0 <= U64.v code /\ U64.v code < pow2 (hi - lo)}) | let get_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) : Tot (code: U64.t { 0 <= U64.v code /\ U64.v code < pow2 (hi - lo) }) =
[@inline_let]
let res =
BF.uint64.BF.get_bitfield x (32 + lo) (32 + hi)
in
res | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 63,
"start_col": 0,
"start_line": 58
} | module LowParse.Low.ErrorCode
(*
Error codes for validators
TODO: replace with type classes
inline_for_extraction
let default_validator_cls : validator_cls = {
validator_max_length = 4294967279ul;
}
*)
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
[@ CMacro ]
let max_uint32 : U32.t = 4294967295ul
let max_uint32_correct
(x: U32.t)
: Lemma
(U32.v x <= U32.v max_uint32)
= ()
inline_for_extraction
noextract
let _max_uint32_as_uint64 : U64.t = 4294967295uL
[@ CMacro ]
let max_uint32_as_uint64 : U64.t = _max_uint32_as_uint64
[@ CMacro ]
let validator_max_length : (u: U64.t { 4 <= U64.v u /\ U64.v u <= U64.v max_uint32_as_uint64 } ) = _max_uint32_as_uint64
[@ CInline ]
let is_error (positionOrError: U64.t) : Tot bool = positionOrError `U64.gt` validator_max_length
[@ CInline ]
let is_success (positionOrError: U64.t) : Tot bool = positionOrError `U64.lte` validator_max_length
[@ CMacro ]
type validator_error = (u: U64.t { is_error u } )
inline_for_extraction
let pos_t = (pos: U64.t {is_success pos})
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ErrorCode.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt64.t -> lo: Prims.nat -> hi: Prims.nat{lo < hi /\ hi <= 32}
-> code: FStar.UInt64.t{0 <= FStar.UInt64.v code /\ FStar.UInt64.v code < Prims.pow2 (hi - lo)} | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt64.t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_LessThanOrEqual",
"Prims.eq2",
"FStar.UInt.uint_t",
"LowParse.BitFields.__proj__Mkuint_t__item__v",
"LowParse.BitFields.uint64",
"LowParse.BitFields.get_bitfield",
"Prims.op_Addition",
"LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield",
"FStar.UInt64.v",
"Prims.pow2",
"Prims.op_Subtraction"
] | [] | false | false | false | false | false | let get_validator_error_field (x: U64.t) (lo: nat) (hi: nat{lo < hi /\ hi <= 32})
: Tot (code: U64.t{0 <= U64.v code /\ U64.v code < pow2 (hi - lo)}) =
| [@@ inline_let ]let res = BF.uint64.BF.get_bitfield x (32 + lo) (32 + hi) in
res | false |
LowParse.Low.ErrorCode.fst | LowParse.Low.ErrorCode.maybe_set_validator_error_pos_and_code | val maybe_set_validator_error_pos_and_code (error: validator_error) (pos: pos_t) (c: error_code)
: Tot validator_error | val maybe_set_validator_error_pos_and_code (error: validator_error) (pos: pos_t) (c: error_code)
: Tot validator_error | let maybe_set_validator_error_pos_and_code
(error: validator_error)
(pos: pos_t)
(c: error_code)
: Tot validator_error
= if get_validator_error_code error = 0uL
then set_validator_error_pos_and_code error pos c
else error | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 12,
"end_line": 169,
"start_col": 0,
"start_line": 162
} | module LowParse.Low.ErrorCode
(*
Error codes for validators
TODO: replace with type classes
inline_for_extraction
let default_validator_cls : validator_cls = {
validator_max_length = 4294967279ul;
}
*)
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
[@ CMacro ]
let max_uint32 : U32.t = 4294967295ul
let max_uint32_correct
(x: U32.t)
: Lemma
(U32.v x <= U32.v max_uint32)
= ()
inline_for_extraction
noextract
let _max_uint32_as_uint64 : U64.t = 4294967295uL
[@ CMacro ]
let max_uint32_as_uint64 : U64.t = _max_uint32_as_uint64
[@ CMacro ]
let validator_max_length : (u: U64.t { 4 <= U64.v u /\ U64.v u <= U64.v max_uint32_as_uint64 } ) = _max_uint32_as_uint64
[@ CInline ]
let is_error (positionOrError: U64.t) : Tot bool = positionOrError `U64.gt` validator_max_length
[@ CInline ]
let is_success (positionOrError: U64.t) : Tot bool = positionOrError `U64.lte` validator_max_length
[@ CMacro ]
type validator_error = (u: U64.t { is_error u } )
inline_for_extraction
let pos_t = (pos: U64.t {is_success pos})
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
inline_for_extraction
noextract
let get_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) : Tot (code: U64.t { 0 <= U64.v code /\ U64.v code < pow2 (hi - lo) }) =
[@inline_let]
let res =
BF.uint64.BF.get_bitfield x (32 + lo) (32 + hi)
in
res
inline_for_extraction
noextract
let set_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) (code: U64.t { 0 < U64.v code /\ U64.v code < pow2 (hi - lo) }) : Tot validator_error =
[@inline_let]
let res =
BF.uint64.BF.set_bitfield x (32 + lo) (32 + hi) code
in
[@inline_let]
let _ =
BF.get_bitfield_set_bitfield_same #64 (U64.v x) (32 + lo) (32 + hi) (U64.v code);
BF.get_bitfield_zero_inner (U64.v res) 32 64 (32 + lo) (32 + hi);
assert (BF.get_bitfield (U64.v res) 32 64 > 0);
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res
let get_validator_error_field_set_validator_error_field
(x: U64.t)
(lo: nat)
(hi: nat { lo < hi /\ hi <= 32 })
(code: U64.t { 0 < U64.v code /\ U64.v code < pow2 (hi - lo) })
: Lemma
(get_validator_error_field (set_validator_error_field x lo hi code) lo hi == code)
= ()
[@ CInline ]
let set_validator_error_pos (error: validator_error) (position: pos_t) : Tot validator_error =
[@inline_let]
let res =
BF.uint64.BF.set_bitfield error 0 32 position
in
[@inline_let]
let _ =
BF.get_bitfield_set_bitfield_other (U64.v error) 0 32 (U64.v position) 32 64;
assert (BF.get_bitfield (U64.v res) 32 64 == BF.get_bitfield (U64.v error) 32 64);
Classical.move_requires (BF.get_bitfield_hi_lt_pow2 (U64.v error)) 32;
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res
#pop-options
[@ CInline ]
let get_validator_error_pos (x: U64.t) : Tot pos_t =
(BF.uint64.BF.get_bitfield x 0 32)
[@ CInline ]
let set_validator_error_kind (error: U64.t) (code: U64.t { 0 < U64.v code /\ U64.v code < 16384 }) : Tot validator_error =
set_validator_error_field error 0 14 code
[@ CInline ]
let get_validator_error_kind (error: U64.t) : Tot (code: U64.t { 0 <= U64.v code /\ U64.v code < 16384 }) =
get_validator_error_field error 0 14
inline_for_extraction
let error_code = (c: U64.t { 0 < U64.v c /\ U64.v c < 65536 })
[@ CInline ]
let set_validator_error_code (error: U64.t) (code: error_code) : Tot validator_error =
set_validator_error_field error 16 32 code
[@ CInline ]
let get_validator_error_code (error: U64.t) : Tot (code: U64.t { U64.v code < 65536 }) =
get_validator_error_field error 16 32
[@ CMacro ]
let validator_error_generic : validator_error = normalize_term (set_validator_error_kind 0uL 1uL)
[@ CMacro ]
let validator_error_not_enough_data : validator_error = normalize_term (set_validator_error_kind 0uL 2uL)
[@"opaque_to_smt"] // to hide the modulo operation
inline_for_extraction
noextract
let uint64_to_uint32
(x: pos_t)
: Tot (y: U32.t { U32.v y == U64.v x })
= Cast.uint64_to_uint32 x
// [@ CInline ]
// let maybe_set_error_code (res:U64.t) (pos:pos_t) (c:U64.t { 0 < U64.v c /\ U64.v c < 65536 })
// : Tot U64.t
// = if is_error res && get_validator_error_code res = 0uL
// then set_validator_error_pos (set_validator_error_code res c) pos
// else res
[@ CInline ]
let set_validator_error_pos_and_code
(error: validator_error)
(position: pos_t)
(code: error_code)
: Tot validator_error
= set_validator_error_pos (set_validator_error_code error code) position | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ErrorCode.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
error: LowParse.Low.ErrorCode.validator_error ->
pos: LowParse.Low.ErrorCode.pos_t ->
c: LowParse.Low.ErrorCode.error_code
-> LowParse.Low.ErrorCode.validator_error | Prims.Tot | [
"total"
] | [] | [
"LowParse.Low.ErrorCode.validator_error",
"LowParse.Low.ErrorCode.pos_t",
"LowParse.Low.ErrorCode.error_code",
"Prims.op_Equality",
"FStar.UInt64.t",
"LowParse.Low.ErrorCode.get_validator_error_code",
"FStar.UInt64.__uint_to_t",
"LowParse.Low.ErrorCode.set_validator_error_pos_and_code",
"Prims.bool"
] | [] | false | false | false | true | false | let maybe_set_validator_error_pos_and_code (error: validator_error) (pos: pos_t) (c: error_code)
: Tot validator_error =
| if get_validator_error_code error = 0uL then set_validator_error_pos_and_code error pos c else error | false |
LowParse.Low.ErrorCode.fst | LowParse.Low.ErrorCode.get_validator_error_pos | val get_validator_error_pos (x: U64.t) : Tot pos_t | val get_validator_error_pos (x: U64.t) : Tot pos_t | let get_validator_error_pos (x: U64.t) : Tot pos_t =
(BF.uint64.BF.get_bitfield x 0 32) | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 36,
"end_line": 111,
"start_col": 0,
"start_line": 110
} | module LowParse.Low.ErrorCode
(*
Error codes for validators
TODO: replace with type classes
inline_for_extraction
let default_validator_cls : validator_cls = {
validator_max_length = 4294967279ul;
}
*)
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
[@ CMacro ]
let max_uint32 : U32.t = 4294967295ul
let max_uint32_correct
(x: U32.t)
: Lemma
(U32.v x <= U32.v max_uint32)
= ()
inline_for_extraction
noextract
let _max_uint32_as_uint64 : U64.t = 4294967295uL
[@ CMacro ]
let max_uint32_as_uint64 : U64.t = _max_uint32_as_uint64
[@ CMacro ]
let validator_max_length : (u: U64.t { 4 <= U64.v u /\ U64.v u <= U64.v max_uint32_as_uint64 } ) = _max_uint32_as_uint64
[@ CInline ]
let is_error (positionOrError: U64.t) : Tot bool = positionOrError `U64.gt` validator_max_length
[@ CInline ]
let is_success (positionOrError: U64.t) : Tot bool = positionOrError `U64.lte` validator_max_length
[@ CMacro ]
type validator_error = (u: U64.t { is_error u } )
inline_for_extraction
let pos_t = (pos: U64.t {is_success pos})
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
inline_for_extraction
noextract
let get_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) : Tot (code: U64.t { 0 <= U64.v code /\ U64.v code < pow2 (hi - lo) }) =
[@inline_let]
let res =
BF.uint64.BF.get_bitfield x (32 + lo) (32 + hi)
in
res
inline_for_extraction
noextract
let set_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) (code: U64.t { 0 < U64.v code /\ U64.v code < pow2 (hi - lo) }) : Tot validator_error =
[@inline_let]
let res =
BF.uint64.BF.set_bitfield x (32 + lo) (32 + hi) code
in
[@inline_let]
let _ =
BF.get_bitfield_set_bitfield_same #64 (U64.v x) (32 + lo) (32 + hi) (U64.v code);
BF.get_bitfield_zero_inner (U64.v res) 32 64 (32 + lo) (32 + hi);
assert (BF.get_bitfield (U64.v res) 32 64 > 0);
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res
let get_validator_error_field_set_validator_error_field
(x: U64.t)
(lo: nat)
(hi: nat { lo < hi /\ hi <= 32 })
(code: U64.t { 0 < U64.v code /\ U64.v code < pow2 (hi - lo) })
: Lemma
(get_validator_error_field (set_validator_error_field x lo hi code) lo hi == code)
= ()
[@ CInline ]
let set_validator_error_pos (error: validator_error) (position: pos_t) : Tot validator_error =
[@inline_let]
let res =
BF.uint64.BF.set_bitfield error 0 32 position
in
[@inline_let]
let _ =
BF.get_bitfield_set_bitfield_other (U64.v error) 0 32 (U64.v position) 32 64;
assert (BF.get_bitfield (U64.v res) 32 64 == BF.get_bitfield (U64.v error) 32 64);
Classical.move_requires (BF.get_bitfield_hi_lt_pow2 (U64.v error)) 32;
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res
#pop-options | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ErrorCode.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt64.t -> LowParse.Low.ErrorCode.pos_t | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt64.t",
"LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield",
"LowParse.BitFields.uint64",
"LowParse.Low.ErrorCode.pos_t"
] | [] | false | false | false | true | false | let get_validator_error_pos (x: U64.t) : Tot pos_t =
| (BF.uint64.BF.get_bitfield x 0 32) | false |
LowParse.Low.ErrorCode.fst | LowParse.Low.ErrorCode.set_validator_error_code | val set_validator_error_code (error: U64.t) (code: error_code) : Tot validator_error | val set_validator_error_code (error: U64.t) (code: error_code) : Tot validator_error | let set_validator_error_code (error: U64.t) (code: error_code) : Tot validator_error =
set_validator_error_field error 16 32 code | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 44,
"end_line": 126,
"start_col": 0,
"start_line": 125
} | module LowParse.Low.ErrorCode
(*
Error codes for validators
TODO: replace with type classes
inline_for_extraction
let default_validator_cls : validator_cls = {
validator_max_length = 4294967279ul;
}
*)
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
[@ CMacro ]
let max_uint32 : U32.t = 4294967295ul
let max_uint32_correct
(x: U32.t)
: Lemma
(U32.v x <= U32.v max_uint32)
= ()
inline_for_extraction
noextract
let _max_uint32_as_uint64 : U64.t = 4294967295uL
[@ CMacro ]
let max_uint32_as_uint64 : U64.t = _max_uint32_as_uint64
[@ CMacro ]
let validator_max_length : (u: U64.t { 4 <= U64.v u /\ U64.v u <= U64.v max_uint32_as_uint64 } ) = _max_uint32_as_uint64
[@ CInline ]
let is_error (positionOrError: U64.t) : Tot bool = positionOrError `U64.gt` validator_max_length
[@ CInline ]
let is_success (positionOrError: U64.t) : Tot bool = positionOrError `U64.lte` validator_max_length
[@ CMacro ]
type validator_error = (u: U64.t { is_error u } )
inline_for_extraction
let pos_t = (pos: U64.t {is_success pos})
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
inline_for_extraction
noextract
let get_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) : Tot (code: U64.t { 0 <= U64.v code /\ U64.v code < pow2 (hi - lo) }) =
[@inline_let]
let res =
BF.uint64.BF.get_bitfield x (32 + lo) (32 + hi)
in
res
inline_for_extraction
noextract
let set_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) (code: U64.t { 0 < U64.v code /\ U64.v code < pow2 (hi - lo) }) : Tot validator_error =
[@inline_let]
let res =
BF.uint64.BF.set_bitfield x (32 + lo) (32 + hi) code
in
[@inline_let]
let _ =
BF.get_bitfield_set_bitfield_same #64 (U64.v x) (32 + lo) (32 + hi) (U64.v code);
BF.get_bitfield_zero_inner (U64.v res) 32 64 (32 + lo) (32 + hi);
assert (BF.get_bitfield (U64.v res) 32 64 > 0);
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res
let get_validator_error_field_set_validator_error_field
(x: U64.t)
(lo: nat)
(hi: nat { lo < hi /\ hi <= 32 })
(code: U64.t { 0 < U64.v code /\ U64.v code < pow2 (hi - lo) })
: Lemma
(get_validator_error_field (set_validator_error_field x lo hi code) lo hi == code)
= ()
[@ CInline ]
let set_validator_error_pos (error: validator_error) (position: pos_t) : Tot validator_error =
[@inline_let]
let res =
BF.uint64.BF.set_bitfield error 0 32 position
in
[@inline_let]
let _ =
BF.get_bitfield_set_bitfield_other (U64.v error) 0 32 (U64.v position) 32 64;
assert (BF.get_bitfield (U64.v res) 32 64 == BF.get_bitfield (U64.v error) 32 64);
Classical.move_requires (BF.get_bitfield_hi_lt_pow2 (U64.v error)) 32;
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res
#pop-options
[@ CInline ]
let get_validator_error_pos (x: U64.t) : Tot pos_t =
(BF.uint64.BF.get_bitfield x 0 32)
[@ CInline ]
let set_validator_error_kind (error: U64.t) (code: U64.t { 0 < U64.v code /\ U64.v code < 16384 }) : Tot validator_error =
set_validator_error_field error 0 14 code
[@ CInline ]
let get_validator_error_kind (error: U64.t) : Tot (code: U64.t { 0 <= U64.v code /\ U64.v code < 16384 }) =
get_validator_error_field error 0 14
inline_for_extraction
let error_code = (c: U64.t { 0 < U64.v c /\ U64.v c < 65536 }) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ErrorCode.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | error: FStar.UInt64.t -> code: LowParse.Low.ErrorCode.error_code
-> LowParse.Low.ErrorCode.validator_error | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt64.t",
"LowParse.Low.ErrorCode.error_code",
"LowParse.Low.ErrorCode.set_validator_error_field",
"LowParse.Low.ErrorCode.validator_error"
] | [] | false | false | false | true | false | let set_validator_error_code (error: U64.t) (code: error_code) : Tot validator_error =
| set_validator_error_field error 16 32 code | false |
LowParse.Low.ErrorCode.fst | LowParse.Low.ErrorCode.set_validator_error_field | val set_validator_error_field
(x: U64.t)
(lo: nat)
(hi: nat{lo < hi /\ hi <= 32})
(code: U64.t{0 < U64.v code /\ U64.v code < pow2 (hi - lo)})
: Tot validator_error | val set_validator_error_field
(x: U64.t)
(lo: nat)
(hi: nat{lo < hi /\ hi <= 32})
(code: U64.t{0 < U64.v code /\ U64.v code < pow2 (hi - lo)})
: Tot validator_error | let set_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) (code: U64.t { 0 < U64.v code /\ U64.v code < pow2 (hi - lo) }) : Tot validator_error =
[@inline_let]
let res =
BF.uint64.BF.set_bitfield x (32 + lo) (32 + hi) code
in
[@inline_let]
let _ =
BF.get_bitfield_set_bitfield_same #64 (U64.v x) (32 + lo) (32 + hi) (U64.v code);
BF.get_bitfield_zero_inner (U64.v res) 32 64 (32 + lo) (32 + hi);
assert (BF.get_bitfield (U64.v res) 32 64 > 0);
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 80,
"start_col": 0,
"start_line": 67
} | module LowParse.Low.ErrorCode
(*
Error codes for validators
TODO: replace with type classes
inline_for_extraction
let default_validator_cls : validator_cls = {
validator_max_length = 4294967279ul;
}
*)
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
[@ CMacro ]
let max_uint32 : U32.t = 4294967295ul
let max_uint32_correct
(x: U32.t)
: Lemma
(U32.v x <= U32.v max_uint32)
= ()
inline_for_extraction
noextract
let _max_uint32_as_uint64 : U64.t = 4294967295uL
[@ CMacro ]
let max_uint32_as_uint64 : U64.t = _max_uint32_as_uint64
[@ CMacro ]
let validator_max_length : (u: U64.t { 4 <= U64.v u /\ U64.v u <= U64.v max_uint32_as_uint64 } ) = _max_uint32_as_uint64
[@ CInline ]
let is_error (positionOrError: U64.t) : Tot bool = positionOrError `U64.gt` validator_max_length
[@ CInline ]
let is_success (positionOrError: U64.t) : Tot bool = positionOrError `U64.lte` validator_max_length
[@ CMacro ]
type validator_error = (u: U64.t { is_error u } )
inline_for_extraction
let pos_t = (pos: U64.t {is_success pos})
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
inline_for_extraction
noextract
let get_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) : Tot (code: U64.t { 0 <= U64.v code /\ U64.v code < pow2 (hi - lo) }) =
[@inline_let]
let res =
BF.uint64.BF.get_bitfield x (32 + lo) (32 + hi)
in
res
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ErrorCode.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
x: FStar.UInt64.t ->
lo: Prims.nat ->
hi: Prims.nat{lo < hi /\ hi <= 32} ->
code: FStar.UInt64.t{0 < FStar.UInt64.v code /\ FStar.UInt64.v code < Prims.pow2 (hi - lo)}
-> LowParse.Low.ErrorCode.validator_error | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt64.t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_LessThanOrEqual",
"FStar.UInt64.v",
"Prims.pow2",
"Prims.op_Subtraction",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"Prims.op_Addition",
"LowParse.Low.ErrorCode.validator_max_length",
"FStar.Classical.move_requires",
"FStar.UInt64.n",
"LowParse.BitFields.get_bitfield",
"LowParse.BitFields.lt_pow2_get_bitfield_hi",
"Prims._assert",
"Prims.op_GreaterThan",
"LowParse.BitFields.get_bitfield_zero_inner",
"LowParse.BitFields.get_bitfield_set_bitfield_same",
"FStar.UInt.uint_t",
"LowParse.BitFields.__proj__Mkuint_t__item__v",
"LowParse.BitFields.uint64",
"LowParse.BitFields.set_bitfield",
"LowParse.BitFields.__proj__Mkuint_t__item__set_bitfield",
"LowParse.Low.ErrorCode.validator_error"
] | [] | false | false | false | false | false | let set_validator_error_field
(x: U64.t)
(lo: nat)
(hi: nat{lo < hi /\ hi <= 32})
(code: U64.t{0 < U64.v code /\ U64.v code < pow2 (hi - lo)})
: Tot validator_error =
| [@@ inline_let ]let res = BF.uint64.BF.set_bitfield x (32 + lo) (32 + hi) code in
[@@ inline_let ]let _ =
BF.get_bitfield_set_bitfield_same #64 (U64.v x) (32 + lo) (32 + hi) (U64.v code);
BF.get_bitfield_zero_inner (U64.v res) 32 64 (32 + lo) (32 + hi);
assert (BF.get_bitfield (U64.v res) 32 64 > 0);
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res | false |
LowParse.Low.ErrorCode.fst | LowParse.Low.ErrorCode.get_validator_error_code | val get_validator_error_code (error: U64.t) : Tot (code: U64.t{U64.v code < 65536}) | val get_validator_error_code (error: U64.t) : Tot (code: U64.t{U64.v code < 65536}) | let get_validator_error_code (error: U64.t) : Tot (code: U64.t { U64.v code < 65536 }) =
get_validator_error_field error 16 32 | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 39,
"end_line": 130,
"start_col": 0,
"start_line": 129
} | module LowParse.Low.ErrorCode
(*
Error codes for validators
TODO: replace with type classes
inline_for_extraction
let default_validator_cls : validator_cls = {
validator_max_length = 4294967279ul;
}
*)
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
[@ CMacro ]
let max_uint32 : U32.t = 4294967295ul
let max_uint32_correct
(x: U32.t)
: Lemma
(U32.v x <= U32.v max_uint32)
= ()
inline_for_extraction
noextract
let _max_uint32_as_uint64 : U64.t = 4294967295uL
[@ CMacro ]
let max_uint32_as_uint64 : U64.t = _max_uint32_as_uint64
[@ CMacro ]
let validator_max_length : (u: U64.t { 4 <= U64.v u /\ U64.v u <= U64.v max_uint32_as_uint64 } ) = _max_uint32_as_uint64
[@ CInline ]
let is_error (positionOrError: U64.t) : Tot bool = positionOrError `U64.gt` validator_max_length
[@ CInline ]
let is_success (positionOrError: U64.t) : Tot bool = positionOrError `U64.lte` validator_max_length
[@ CMacro ]
type validator_error = (u: U64.t { is_error u } )
inline_for_extraction
let pos_t = (pos: U64.t {is_success pos})
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
inline_for_extraction
noextract
let get_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) : Tot (code: U64.t { 0 <= U64.v code /\ U64.v code < pow2 (hi - lo) }) =
[@inline_let]
let res =
BF.uint64.BF.get_bitfield x (32 + lo) (32 + hi)
in
res
inline_for_extraction
noextract
let set_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) (code: U64.t { 0 < U64.v code /\ U64.v code < pow2 (hi - lo) }) : Tot validator_error =
[@inline_let]
let res =
BF.uint64.BF.set_bitfield x (32 + lo) (32 + hi) code
in
[@inline_let]
let _ =
BF.get_bitfield_set_bitfield_same #64 (U64.v x) (32 + lo) (32 + hi) (U64.v code);
BF.get_bitfield_zero_inner (U64.v res) 32 64 (32 + lo) (32 + hi);
assert (BF.get_bitfield (U64.v res) 32 64 > 0);
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res
let get_validator_error_field_set_validator_error_field
(x: U64.t)
(lo: nat)
(hi: nat { lo < hi /\ hi <= 32 })
(code: U64.t { 0 < U64.v code /\ U64.v code < pow2 (hi - lo) })
: Lemma
(get_validator_error_field (set_validator_error_field x lo hi code) lo hi == code)
= ()
[@ CInline ]
let set_validator_error_pos (error: validator_error) (position: pos_t) : Tot validator_error =
[@inline_let]
let res =
BF.uint64.BF.set_bitfield error 0 32 position
in
[@inline_let]
let _ =
BF.get_bitfield_set_bitfield_other (U64.v error) 0 32 (U64.v position) 32 64;
assert (BF.get_bitfield (U64.v res) 32 64 == BF.get_bitfield (U64.v error) 32 64);
Classical.move_requires (BF.get_bitfield_hi_lt_pow2 (U64.v error)) 32;
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res
#pop-options
[@ CInline ]
let get_validator_error_pos (x: U64.t) : Tot pos_t =
(BF.uint64.BF.get_bitfield x 0 32)
[@ CInline ]
let set_validator_error_kind (error: U64.t) (code: U64.t { 0 < U64.v code /\ U64.v code < 16384 }) : Tot validator_error =
set_validator_error_field error 0 14 code
[@ CInline ]
let get_validator_error_kind (error: U64.t) : Tot (code: U64.t { 0 <= U64.v code /\ U64.v code < 16384 }) =
get_validator_error_field error 0 14
inline_for_extraction
let error_code = (c: U64.t { 0 < U64.v c /\ U64.v c < 65536 })
[@ CInline ]
let set_validator_error_code (error: U64.t) (code: error_code) : Tot validator_error =
set_validator_error_field error 16 32 code | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ErrorCode.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | error: FStar.UInt64.t -> code: FStar.UInt64.t{FStar.UInt64.v code < 65536} | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt64.t",
"LowParse.Low.ErrorCode.get_validator_error_field",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt64.v"
] | [] | false | false | false | false | false | let get_validator_error_code (error: U64.t) : Tot (code: U64.t{U64.v code < 65536}) =
| get_validator_error_field error 16 32 | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.lanes | val lanes (a: sha2_alg) (m: m_spec) : lanes_t | val lanes (a: sha2_alg) (m: m_spec) : lanes_t | let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 39,
"start_col": 0,
"start_line": 29
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8} | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec -> Hacl.Spec.SHA2.Vec.lanes_t | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"FStar.Pervasives.Native.Mktuple2",
"Spec.Hash.Definitions.hash_alg",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.SHA2.Vec.lanes_t"
] | [] | false | false | false | true | false | let lanes (a: sha2_alg) (m: m_spec) : lanes_t =
| match a, m with
| SHA2_224, M128 | SHA2_256, M128 -> 4
| SHA2_224, M256 | SHA2_256, M256 -> 8
| SHA2_384, M128 | SHA2_512, M128 -> 2
| SHA2_384, M256 | SHA2_512, M256 -> 4
| _ -> 1 | false |
LowParse.Low.ErrorCode.fst | LowParse.Low.ErrorCode.set_validator_error_pos | val set_validator_error_pos (error: validator_error) (position: pos_t) : Tot validator_error | val set_validator_error_pos (error: validator_error) (position: pos_t) : Tot validator_error | let set_validator_error_pos (error: validator_error) (position: pos_t) : Tot validator_error =
[@inline_let]
let res =
BF.uint64.BF.set_bitfield error 0 32 position
in
[@inline_let]
let _ =
BF.get_bitfield_set_bitfield_other (U64.v error) 0 32 (U64.v position) 32 64;
assert (BF.get_bitfield (U64.v res) 32 64 == BF.get_bitfield (U64.v error) 32 64);
Classical.move_requires (BF.get_bitfield_hi_lt_pow2 (U64.v error)) 32;
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 105,
"start_col": 0,
"start_line": 92
} | module LowParse.Low.ErrorCode
(*
Error codes for validators
TODO: replace with type classes
inline_for_extraction
let default_validator_cls : validator_cls = {
validator_max_length = 4294967279ul;
}
*)
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
[@ CMacro ]
let max_uint32 : U32.t = 4294967295ul
let max_uint32_correct
(x: U32.t)
: Lemma
(U32.v x <= U32.v max_uint32)
= ()
inline_for_extraction
noextract
let _max_uint32_as_uint64 : U64.t = 4294967295uL
[@ CMacro ]
let max_uint32_as_uint64 : U64.t = _max_uint32_as_uint64
[@ CMacro ]
let validator_max_length : (u: U64.t { 4 <= U64.v u /\ U64.v u <= U64.v max_uint32_as_uint64 } ) = _max_uint32_as_uint64
[@ CInline ]
let is_error (positionOrError: U64.t) : Tot bool = positionOrError `U64.gt` validator_max_length
[@ CInline ]
let is_success (positionOrError: U64.t) : Tot bool = positionOrError `U64.lte` validator_max_length
[@ CMacro ]
type validator_error = (u: U64.t { is_error u } )
inline_for_extraction
let pos_t = (pos: U64.t {is_success pos})
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
inline_for_extraction
noextract
let get_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) : Tot (code: U64.t { 0 <= U64.v code /\ U64.v code < pow2 (hi - lo) }) =
[@inline_let]
let res =
BF.uint64.BF.get_bitfield x (32 + lo) (32 + hi)
in
res
inline_for_extraction
noextract
let set_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) (code: U64.t { 0 < U64.v code /\ U64.v code < pow2 (hi - lo) }) : Tot validator_error =
[@inline_let]
let res =
BF.uint64.BF.set_bitfield x (32 + lo) (32 + hi) code
in
[@inline_let]
let _ =
BF.get_bitfield_set_bitfield_same #64 (U64.v x) (32 + lo) (32 + hi) (U64.v code);
BF.get_bitfield_zero_inner (U64.v res) 32 64 (32 + lo) (32 + hi);
assert (BF.get_bitfield (U64.v res) 32 64 > 0);
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res
let get_validator_error_field_set_validator_error_field
(x: U64.t)
(lo: nat)
(hi: nat { lo < hi /\ hi <= 32 })
(code: U64.t { 0 < U64.v code /\ U64.v code < pow2 (hi - lo) })
: Lemma
(get_validator_error_field (set_validator_error_field x lo hi code) lo hi == code)
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ErrorCode.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | error: LowParse.Low.ErrorCode.validator_error -> position: LowParse.Low.ErrorCode.pos_t
-> LowParse.Low.ErrorCode.validator_error | Prims.Tot | [
"total"
] | [] | [
"LowParse.Low.ErrorCode.validator_error",
"LowParse.Low.ErrorCode.pos_t",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"Prims.pow2",
"Prims.op_Addition",
"FStar.UInt64.v",
"LowParse.Low.ErrorCode.validator_max_length",
"FStar.Classical.move_requires",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt64.n",
"Prims.op_LessThan",
"LowParse.BitFields.get_bitfield",
"LowParse.BitFields.lt_pow2_get_bitfield_hi",
"LowParse.BitFields.get_bitfield_hi_lt_pow2",
"Prims._assert",
"LowParse.BitFields.ubitfield",
"Prims.op_Subtraction",
"LowParse.BitFields.get_bitfield_set_bitfield_other",
"FStar.UInt64.t",
"FStar.UInt.uint_t",
"LowParse.BitFields.__proj__Mkuint_t__item__v",
"LowParse.BitFields.uint64",
"LowParse.BitFields.set_bitfield",
"LowParse.BitFields.__proj__Mkuint_t__item__set_bitfield"
] | [] | false | false | false | true | false | let set_validator_error_pos (error: validator_error) (position: pos_t) : Tot validator_error =
| [@@ inline_let ]let res = BF.uint64.BF.set_bitfield error 0 32 position in
[@@ inline_let ]let _ =
BF.get_bitfield_set_bitfield_other (U64.v error) 0 32 (U64.v position) 32 64;
assert (BF.get_bitfield (U64.v res) 32 64 == BF.get_bitfield (U64.v error) 32 64);
Classical.move_requires (BF.get_bitfield_hi_lt_pow2 (U64.v error)) 32;
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res | false |
LowParse.Low.ErrorCode.fst | LowParse.Low.ErrorCode.maybe_set_error_code | val maybe_set_error_code (positionOrError: U64.t) (positionAtError: pos_t) (code: error_code)
: Tot U64.t | val maybe_set_error_code (positionOrError: U64.t) (positionAtError: pos_t) (code: error_code)
: Tot U64.t | let maybe_set_error_code
(positionOrError: U64.t)
(positionAtError: pos_t)
(code: error_code)
: Tot U64.t
= if is_error positionOrError
&& get_validator_error_code positionOrError = 0uL
then set_validator_error_pos_and_code positionOrError positionAtError code
else positionOrError | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 24,
"end_line": 180,
"start_col": 0,
"start_line": 172
} | module LowParse.Low.ErrorCode
(*
Error codes for validators
TODO: replace with type classes
inline_for_extraction
let default_validator_cls : validator_cls = {
validator_max_length = 4294967279ul;
}
*)
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
[@ CMacro ]
let max_uint32 : U32.t = 4294967295ul
let max_uint32_correct
(x: U32.t)
: Lemma
(U32.v x <= U32.v max_uint32)
= ()
inline_for_extraction
noextract
let _max_uint32_as_uint64 : U64.t = 4294967295uL
[@ CMacro ]
let max_uint32_as_uint64 : U64.t = _max_uint32_as_uint64
[@ CMacro ]
let validator_max_length : (u: U64.t { 4 <= U64.v u /\ U64.v u <= U64.v max_uint32_as_uint64 } ) = _max_uint32_as_uint64
[@ CInline ]
let is_error (positionOrError: U64.t) : Tot bool = positionOrError `U64.gt` validator_max_length
[@ CInline ]
let is_success (positionOrError: U64.t) : Tot bool = positionOrError `U64.lte` validator_max_length
[@ CMacro ]
type validator_error = (u: U64.t { is_error u } )
inline_for_extraction
let pos_t = (pos: U64.t {is_success pos})
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
inline_for_extraction
noextract
let get_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) : Tot (code: U64.t { 0 <= U64.v code /\ U64.v code < pow2 (hi - lo) }) =
[@inline_let]
let res =
BF.uint64.BF.get_bitfield x (32 + lo) (32 + hi)
in
res
inline_for_extraction
noextract
let set_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) (code: U64.t { 0 < U64.v code /\ U64.v code < pow2 (hi - lo) }) : Tot validator_error =
[@inline_let]
let res =
BF.uint64.BF.set_bitfield x (32 + lo) (32 + hi) code
in
[@inline_let]
let _ =
BF.get_bitfield_set_bitfield_same #64 (U64.v x) (32 + lo) (32 + hi) (U64.v code);
BF.get_bitfield_zero_inner (U64.v res) 32 64 (32 + lo) (32 + hi);
assert (BF.get_bitfield (U64.v res) 32 64 > 0);
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res
let get_validator_error_field_set_validator_error_field
(x: U64.t)
(lo: nat)
(hi: nat { lo < hi /\ hi <= 32 })
(code: U64.t { 0 < U64.v code /\ U64.v code < pow2 (hi - lo) })
: Lemma
(get_validator_error_field (set_validator_error_field x lo hi code) lo hi == code)
= ()
[@ CInline ]
let set_validator_error_pos (error: validator_error) (position: pos_t) : Tot validator_error =
[@inline_let]
let res =
BF.uint64.BF.set_bitfield error 0 32 position
in
[@inline_let]
let _ =
BF.get_bitfield_set_bitfield_other (U64.v error) 0 32 (U64.v position) 32 64;
assert (BF.get_bitfield (U64.v res) 32 64 == BF.get_bitfield (U64.v error) 32 64);
Classical.move_requires (BF.get_bitfield_hi_lt_pow2 (U64.v error)) 32;
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res
#pop-options
[@ CInline ]
let get_validator_error_pos (x: U64.t) : Tot pos_t =
(BF.uint64.BF.get_bitfield x 0 32)
[@ CInline ]
let set_validator_error_kind (error: U64.t) (code: U64.t { 0 < U64.v code /\ U64.v code < 16384 }) : Tot validator_error =
set_validator_error_field error 0 14 code
[@ CInline ]
let get_validator_error_kind (error: U64.t) : Tot (code: U64.t { 0 <= U64.v code /\ U64.v code < 16384 }) =
get_validator_error_field error 0 14
inline_for_extraction
let error_code = (c: U64.t { 0 < U64.v c /\ U64.v c < 65536 })
[@ CInline ]
let set_validator_error_code (error: U64.t) (code: error_code) : Tot validator_error =
set_validator_error_field error 16 32 code
[@ CInline ]
let get_validator_error_code (error: U64.t) : Tot (code: U64.t { U64.v code < 65536 }) =
get_validator_error_field error 16 32
[@ CMacro ]
let validator_error_generic : validator_error = normalize_term (set_validator_error_kind 0uL 1uL)
[@ CMacro ]
let validator_error_not_enough_data : validator_error = normalize_term (set_validator_error_kind 0uL 2uL)
[@"opaque_to_smt"] // to hide the modulo operation
inline_for_extraction
noextract
let uint64_to_uint32
(x: pos_t)
: Tot (y: U32.t { U32.v y == U64.v x })
= Cast.uint64_to_uint32 x
// [@ CInline ]
// let maybe_set_error_code (res:U64.t) (pos:pos_t) (c:U64.t { 0 < U64.v c /\ U64.v c < 65536 })
// : Tot U64.t
// = if is_error res && get_validator_error_code res = 0uL
// then set_validator_error_pos (set_validator_error_code res c) pos
// else res
[@ CInline ]
let set_validator_error_pos_and_code
(error: validator_error)
(position: pos_t)
(code: error_code)
: Tot validator_error
= set_validator_error_pos (set_validator_error_code error code) position
[@ CInline ]
let maybe_set_validator_error_pos_and_code
(error: validator_error)
(pos: pos_t)
(c: error_code)
: Tot validator_error
= if get_validator_error_code error = 0uL
then set_validator_error_pos_and_code error pos c
else error | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ErrorCode.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
positionOrError: FStar.UInt64.t ->
positionAtError: LowParse.Low.ErrorCode.pos_t ->
code: LowParse.Low.ErrorCode.error_code
-> FStar.UInt64.t | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt64.t",
"LowParse.Low.ErrorCode.pos_t",
"LowParse.Low.ErrorCode.error_code",
"Prims.op_AmpAmp",
"LowParse.Low.ErrorCode.is_error",
"Prims.op_Equality",
"LowParse.Low.ErrorCode.get_validator_error_code",
"FStar.UInt64.__uint_to_t",
"LowParse.Low.ErrorCode.set_validator_error_pos_and_code",
"Prims.bool"
] | [] | false | false | false | true | false | let maybe_set_error_code (positionOrError: U64.t) (positionAtError: pos_t) (code: error_code)
: Tot U64.t =
| if is_error positionOrError && get_validator_error_code positionOrError = 0uL
then set_validator_error_pos_and_code positionOrError positionAtError code
else positionOrError | false |
LowParse.Low.ErrorCode.fst | LowParse.Low.ErrorCode.set_validator_error_kind | val set_validator_error_kind (error: U64.t) (code: U64.t{0 < U64.v code /\ U64.v code < 16384})
: Tot validator_error | val set_validator_error_kind (error: U64.t) (code: U64.t{0 < U64.v code /\ U64.v code < 16384})
: Tot validator_error | let set_validator_error_kind (error: U64.t) (code: U64.t { 0 < U64.v code /\ U64.v code < 16384 }) : Tot validator_error =
set_validator_error_field error 0 14 code | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 43,
"end_line": 115,
"start_col": 0,
"start_line": 114
} | module LowParse.Low.ErrorCode
(*
Error codes for validators
TODO: replace with type classes
inline_for_extraction
let default_validator_cls : validator_cls = {
validator_max_length = 4294967279ul;
}
*)
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
[@ CMacro ]
let max_uint32 : U32.t = 4294967295ul
let max_uint32_correct
(x: U32.t)
: Lemma
(U32.v x <= U32.v max_uint32)
= ()
inline_for_extraction
noextract
let _max_uint32_as_uint64 : U64.t = 4294967295uL
[@ CMacro ]
let max_uint32_as_uint64 : U64.t = _max_uint32_as_uint64
[@ CMacro ]
let validator_max_length : (u: U64.t { 4 <= U64.v u /\ U64.v u <= U64.v max_uint32_as_uint64 } ) = _max_uint32_as_uint64
[@ CInline ]
let is_error (positionOrError: U64.t) : Tot bool = positionOrError `U64.gt` validator_max_length
[@ CInline ]
let is_success (positionOrError: U64.t) : Tot bool = positionOrError `U64.lte` validator_max_length
[@ CMacro ]
type validator_error = (u: U64.t { is_error u } )
inline_for_extraction
let pos_t = (pos: U64.t {is_success pos})
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
inline_for_extraction
noextract
let get_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) : Tot (code: U64.t { 0 <= U64.v code /\ U64.v code < pow2 (hi - lo) }) =
[@inline_let]
let res =
BF.uint64.BF.get_bitfield x (32 + lo) (32 + hi)
in
res
inline_for_extraction
noextract
let set_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) (code: U64.t { 0 < U64.v code /\ U64.v code < pow2 (hi - lo) }) : Tot validator_error =
[@inline_let]
let res =
BF.uint64.BF.set_bitfield x (32 + lo) (32 + hi) code
in
[@inline_let]
let _ =
BF.get_bitfield_set_bitfield_same #64 (U64.v x) (32 + lo) (32 + hi) (U64.v code);
BF.get_bitfield_zero_inner (U64.v res) 32 64 (32 + lo) (32 + hi);
assert (BF.get_bitfield (U64.v res) 32 64 > 0);
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res
let get_validator_error_field_set_validator_error_field
(x: U64.t)
(lo: nat)
(hi: nat { lo < hi /\ hi <= 32 })
(code: U64.t { 0 < U64.v code /\ U64.v code < pow2 (hi - lo) })
: Lemma
(get_validator_error_field (set_validator_error_field x lo hi code) lo hi == code)
= ()
[@ CInline ]
let set_validator_error_pos (error: validator_error) (position: pos_t) : Tot validator_error =
[@inline_let]
let res =
BF.uint64.BF.set_bitfield error 0 32 position
in
[@inline_let]
let _ =
BF.get_bitfield_set_bitfield_other (U64.v error) 0 32 (U64.v position) 32 64;
assert (BF.get_bitfield (U64.v res) 32 64 == BF.get_bitfield (U64.v error) 32 64);
Classical.move_requires (BF.get_bitfield_hi_lt_pow2 (U64.v error)) 32;
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res
#pop-options
[@ CInline ]
let get_validator_error_pos (x: U64.t) : Tot pos_t =
(BF.uint64.BF.get_bitfield x 0 32) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ErrorCode.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
error: FStar.UInt64.t ->
code: FStar.UInt64.t{0 < FStar.UInt64.v code /\ FStar.UInt64.v code < 16384}
-> LowParse.Low.ErrorCode.validator_error | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt64.t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt64.v",
"LowParse.Low.ErrorCode.set_validator_error_field",
"LowParse.Low.ErrorCode.validator_error"
] | [] | false | false | false | false | false | let set_validator_error_kind (error: U64.t) (code: U64.t{0 < U64.v code /\ U64.v code < 16384})
: Tot validator_error =
| set_validator_error_field error 0 14 code | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.lanes_t | val lanes_t : Type0 | let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8} | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 57,
"end_line": 26,
"start_col": 0,
"start_line": 26
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256 | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.l_or",
"Prims.eq2",
"Prims.int"
] | [] | false | false | false | true | true | let lanes_t =
| n: nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8} | false |
|
LowParse.Low.ErrorCode.fst | LowParse.Low.ErrorCode.get_validator_error_kind | val get_validator_error_kind (error: U64.t)
: Tot (code: U64.t{0 <= U64.v code /\ U64.v code < 16384}) | val get_validator_error_kind (error: U64.t)
: Tot (code: U64.t{0 <= U64.v code /\ U64.v code < 16384}) | let get_validator_error_kind (error: U64.t) : Tot (code: U64.t { 0 <= U64.v code /\ U64.v code < 16384 }) =
get_validator_error_field error 0 14 | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 38,
"end_line": 119,
"start_col": 0,
"start_line": 118
} | module LowParse.Low.ErrorCode
(*
Error codes for validators
TODO: replace with type classes
inline_for_extraction
let default_validator_cls : validator_cls = {
validator_max_length = 4294967279ul;
}
*)
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
[@ CMacro ]
let max_uint32 : U32.t = 4294967295ul
let max_uint32_correct
(x: U32.t)
: Lemma
(U32.v x <= U32.v max_uint32)
= ()
inline_for_extraction
noextract
let _max_uint32_as_uint64 : U64.t = 4294967295uL
[@ CMacro ]
let max_uint32_as_uint64 : U64.t = _max_uint32_as_uint64
[@ CMacro ]
let validator_max_length : (u: U64.t { 4 <= U64.v u /\ U64.v u <= U64.v max_uint32_as_uint64 } ) = _max_uint32_as_uint64
[@ CInline ]
let is_error (positionOrError: U64.t) : Tot bool = positionOrError `U64.gt` validator_max_length
[@ CInline ]
let is_success (positionOrError: U64.t) : Tot bool = positionOrError `U64.lte` validator_max_length
[@ CMacro ]
type validator_error = (u: U64.t { is_error u } )
inline_for_extraction
let pos_t = (pos: U64.t {is_success pos})
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
inline_for_extraction
noextract
let get_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) : Tot (code: U64.t { 0 <= U64.v code /\ U64.v code < pow2 (hi - lo) }) =
[@inline_let]
let res =
BF.uint64.BF.get_bitfield x (32 + lo) (32 + hi)
in
res
inline_for_extraction
noextract
let set_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) (code: U64.t { 0 < U64.v code /\ U64.v code < pow2 (hi - lo) }) : Tot validator_error =
[@inline_let]
let res =
BF.uint64.BF.set_bitfield x (32 + lo) (32 + hi) code
in
[@inline_let]
let _ =
BF.get_bitfield_set_bitfield_same #64 (U64.v x) (32 + lo) (32 + hi) (U64.v code);
BF.get_bitfield_zero_inner (U64.v res) 32 64 (32 + lo) (32 + hi);
assert (BF.get_bitfield (U64.v res) 32 64 > 0);
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res
let get_validator_error_field_set_validator_error_field
(x: U64.t)
(lo: nat)
(hi: nat { lo < hi /\ hi <= 32 })
(code: U64.t { 0 < U64.v code /\ U64.v code < pow2 (hi - lo) })
: Lemma
(get_validator_error_field (set_validator_error_field x lo hi code) lo hi == code)
= ()
[@ CInline ]
let set_validator_error_pos (error: validator_error) (position: pos_t) : Tot validator_error =
[@inline_let]
let res =
BF.uint64.BF.set_bitfield error 0 32 position
in
[@inline_let]
let _ =
BF.get_bitfield_set_bitfield_other (U64.v error) 0 32 (U64.v position) 32 64;
assert (BF.get_bitfield (U64.v res) 32 64 == BF.get_bitfield (U64.v error) 32 64);
Classical.move_requires (BF.get_bitfield_hi_lt_pow2 (U64.v error)) 32;
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res
#pop-options
[@ CInline ]
let get_validator_error_pos (x: U64.t) : Tot pos_t =
(BF.uint64.BF.get_bitfield x 0 32)
[@ CInline ]
let set_validator_error_kind (error: U64.t) (code: U64.t { 0 < U64.v code /\ U64.v code < 16384 }) : Tot validator_error =
set_validator_error_field error 0 14 code | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ErrorCode.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | error: FStar.UInt64.t
-> code: FStar.UInt64.t{0 <= FStar.UInt64.v code /\ FStar.UInt64.v code < 16384} | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt64.t",
"LowParse.Low.ErrorCode.get_validator_error_field",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt64.v",
"Prims.op_LessThan"
] | [] | false | false | false | false | false | let get_validator_error_kind (error: U64.t)
: Tot (code: U64.t{0 <= U64.v code /\ U64.v code < 16384}) =
| get_validator_error_field error 0 14 | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.words_state' | val words_state' : a: Spec.Hash.Definitions.hash_alg -> Type0 | let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a} | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 76,
"end_line": 58,
"start_col": 0,
"start_line": 58
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.hash_alg -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.hash_alg",
"FStar.Seq.Base.seq",
"Hacl.Spec.SHA2.Vec.word",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"Spec.Hash.Definitions.state_word_length"
] | [] | false | false | false | true | true | let words_state' a =
| m: Seq.seq (word a) {Seq.length m = state_word_length a} | false |
|
LowParse.Low.ErrorCode.fst | LowParse.Low.ErrorCode.uint64_to_uint32 | val uint64_to_uint32 (x: pos_t) : Tot (y: U32.t{U32.v y == U64.v x}) | val uint64_to_uint32 (x: pos_t) : Tot (y: U32.t{U32.v y == U64.v x}) | let uint64_to_uint32
(x: pos_t)
: Tot (y: U32.t { U32.v y == U64.v x })
= Cast.uint64_to_uint32 x | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 25,
"end_line": 144,
"start_col": 0,
"start_line": 141
} | module LowParse.Low.ErrorCode
(*
Error codes for validators
TODO: replace with type classes
inline_for_extraction
let default_validator_cls : validator_cls = {
validator_max_length = 4294967279ul;
}
*)
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module Cast = FStar.Int.Cast
[@ CMacro ]
let max_uint32 : U32.t = 4294967295ul
let max_uint32_correct
(x: U32.t)
: Lemma
(U32.v x <= U32.v max_uint32)
= ()
inline_for_extraction
noextract
let _max_uint32_as_uint64 : U64.t = 4294967295uL
[@ CMacro ]
let max_uint32_as_uint64 : U64.t = _max_uint32_as_uint64
[@ CMacro ]
let validator_max_length : (u: U64.t { 4 <= U64.v u /\ U64.v u <= U64.v max_uint32_as_uint64 } ) = _max_uint32_as_uint64
[@ CInline ]
let is_error (positionOrError: U64.t) : Tot bool = positionOrError `U64.gt` validator_max_length
[@ CInline ]
let is_success (positionOrError: U64.t) : Tot bool = positionOrError `U64.lte` validator_max_length
[@ CMacro ]
type validator_error = (u: U64.t { is_error u } )
inline_for_extraction
let pos_t = (pos: U64.t {is_success pos})
module BF = LowParse.BitFields
#push-options "--z3rlimit 16"
inline_for_extraction
noextract
let get_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) : Tot (code: U64.t { 0 <= U64.v code /\ U64.v code < pow2 (hi - lo) }) =
[@inline_let]
let res =
BF.uint64.BF.get_bitfield x (32 + lo) (32 + hi)
in
res
inline_for_extraction
noextract
let set_validator_error_field (x: U64.t) (lo: nat) (hi: nat { lo < hi /\ hi <= 32 }) (code: U64.t { 0 < U64.v code /\ U64.v code < pow2 (hi - lo) }) : Tot validator_error =
[@inline_let]
let res =
BF.uint64.BF.set_bitfield x (32 + lo) (32 + hi) code
in
[@inline_let]
let _ =
BF.get_bitfield_set_bitfield_same #64 (U64.v x) (32 + lo) (32 + hi) (U64.v code);
BF.get_bitfield_zero_inner (U64.v res) 32 64 (32 + lo) (32 + hi);
assert (BF.get_bitfield (U64.v res) 32 64 > 0);
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res
let get_validator_error_field_set_validator_error_field
(x: U64.t)
(lo: nat)
(hi: nat { lo < hi /\ hi <= 32 })
(code: U64.t { 0 < U64.v code /\ U64.v code < pow2 (hi - lo) })
: Lemma
(get_validator_error_field (set_validator_error_field x lo hi code) lo hi == code)
= ()
[@ CInline ]
let set_validator_error_pos (error: validator_error) (position: pos_t) : Tot validator_error =
[@inline_let]
let res =
BF.uint64.BF.set_bitfield error 0 32 position
in
[@inline_let]
let _ =
BF.get_bitfield_set_bitfield_other (U64.v error) 0 32 (U64.v position) 32 64;
assert (BF.get_bitfield (U64.v res) 32 64 == BF.get_bitfield (U64.v error) 32 64);
Classical.move_requires (BF.get_bitfield_hi_lt_pow2 (U64.v error)) 32;
Classical.move_requires (BF.lt_pow2_get_bitfield_hi (U64.v res)) 32;
assert_norm (pow2 32 == U64.v validator_max_length + 1)
in
res
#pop-options
[@ CInline ]
let get_validator_error_pos (x: U64.t) : Tot pos_t =
(BF.uint64.BF.get_bitfield x 0 32)
[@ CInline ]
let set_validator_error_kind (error: U64.t) (code: U64.t { 0 < U64.v code /\ U64.v code < 16384 }) : Tot validator_error =
set_validator_error_field error 0 14 code
[@ CInline ]
let get_validator_error_kind (error: U64.t) : Tot (code: U64.t { 0 <= U64.v code /\ U64.v code < 16384 }) =
get_validator_error_field error 0 14
inline_for_extraction
let error_code = (c: U64.t { 0 < U64.v c /\ U64.v c < 65536 })
[@ CInline ]
let set_validator_error_code (error: U64.t) (code: error_code) : Tot validator_error =
set_validator_error_field error 16 32 code
[@ CInline ]
let get_validator_error_code (error: U64.t) : Tot (code: U64.t { U64.v code < 65536 }) =
get_validator_error_field error 16 32
[@ CMacro ]
let validator_error_generic : validator_error = normalize_term (set_validator_error_kind 0uL 1uL)
[@ CMacro ]
let validator_error_not_enough_data : validator_error = normalize_term (set_validator_error_kind 0uL 2uL)
[@"opaque_to_smt"] // to hide the modulo operation
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.BitFields.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.ErrorCode.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.BitFields",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: LowParse.Low.ErrorCode.pos_t -> y: FStar.UInt32.t{FStar.UInt32.v y == FStar.UInt64.v x} | Prims.Tot | [
"total"
] | [] | [
"LowParse.Low.ErrorCode.pos_t",
"FStar.Int.Cast.uint64_to_uint32",
"FStar.UInt32.t",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"FStar.UInt64.n",
"FStar.UInt32.v",
"FStar.UInt64.v"
] | [] | false | false | false | false | false | let uint64_to_uint32 (x: pos_t) : Tot (y: U32.t{U32.v y == U64.v x}) =
| Cast.uint64_to_uint32 x | false |
Vale.Wrapper.X64.GCMencryptOpt256.fsti | Vale.Wrapper.X64.GCMencryptOpt256.length_aux4 | val length_aux4 (b: uint8_p)
: Lemma (requires B.length b = 16) (ensures DV.length (get_downview b) % 16 = 0) | val length_aux4 (b: uint8_p)
: Lemma (requires B.length b = 16) (ensures DV.length (get_downview b) % 16 = 0) | let length_aux4 (b:uint8_p) : Lemma
(requires B.length b = 16)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db | {
"file_name": "vale/code/arch/x64/interop/Vale.Wrapper.X64.GCMencryptOpt256.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 19,
"end_line": 52,
"start_col": 0,
"start_line": 48
} | module Vale.Wrapper.X64.GCMencryptOpt256
open Vale.X64.CPU_Features_s
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
open Vale.AsLowStar.MemoryHelpers
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.AES.GCM_helpers
open Vale.AES.AES_s
open Vale.AES.GCM_s
open Vale.AES.GHash_s
open Vale.AES.GCTR_s
open Vale.AES.GCTR
open Vale.Interop.Base
open Vale.Arch.Types
open Vale.AES.OptPublic
let uint8_p = B.buffer UInt8.t
let uint64 = UInt64.t
let disjoint_or_eq (b1 b2:uint8_p) = B.disjoint b1 b2 \/ b1 == b2
let length_aux (b:uint8_p) : Lemma
(requires B.length b = 176)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db
let length_aux2 (b:uint8_p) : Lemma
(requires B.length b = 240)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db
let length_aux3 (b:uint8_p) (n:nat) : Lemma
(requires B.length b = 16 * n)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db;
FStar.Math.Lemmas.cancel_mul_mod n 16 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GHash_s.fst.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.GCTR.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.GCM_helpers.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Wrapper.X64.GCMencryptOpt256.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Vale.Wrapper.X64.GCMencryptOpt256.uint8_p
-> FStar.Pervasives.Lemma (requires LowStar.Monotonic.Buffer.length b = 16)
(ensures LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview b) % 16 = 0) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Wrapper.X64.GCMencryptOpt256.uint8_p",
"LowStar.BufferView.Down.length_eq",
"FStar.UInt8.t",
"LowStar.BufferView.Down.buffer",
"Vale.Interop.Types.get_downview",
"Vale.Arch.HeapTypes_s.TUInt8",
"LowStar.Buffer.trivial_preorder",
"Prims.unit",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"LowStar.Monotonic.Buffer.length",
"Prims.squash",
"Prims.op_Modulus",
"LowStar.BufferView.Down.length",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let length_aux4 (b: uint8_p)
: Lemma (requires B.length b = 16) (ensures DV.length (get_downview b) % 16 = 0) =
| let db = get_downview b in
DV.length_eq db | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec._Maj | val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m | val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m | let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 57,
"end_line": 107,
"start_col": 0,
"start_line": 107
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
x: Hacl.Spec.SHA2.Vec.element_t a m ->
y: Hacl.Spec.SHA2.Vec.element_t a m ->
z: Hacl.Spec.SHA2.Vec.element_t a m
-> Hacl.Spec.SHA2.Vec.element_t a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.element_t",
"Hacl.Spec.SHA2.Vec.op_Hat_Bar",
"Hacl.Spec.SHA2.Vec.op_Amp_Bar"
] | [] | false | false | false | false | false | let _Maj #a #m x y z =
| (x &| y) ^| ((x &| z) ^| (y &| z)) | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec._Ch | val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m | val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m | let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 102,
"start_col": 0,
"start_line": 102
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
x: Hacl.Spec.SHA2.Vec.element_t a m ->
y: Hacl.Spec.SHA2.Vec.element_t a m ->
z: Hacl.Spec.SHA2.Vec.element_t a m
-> Hacl.Spec.SHA2.Vec.element_t a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.element_t",
"Hacl.Spec.SHA2.Vec.op_Hat_Bar",
"Hacl.Spec.SHA2.Vec.op_Amp_Bar",
"Hacl.Spec.SHA2.Vec.op_Tilde_Bar"
] | [] | false | false | false | false | false | let _Ch #a #m x y z =
| (x &| y) ^| (~|x &| z) | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.is_supported | val is_supported : a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec -> Prims.logical | let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 49,
"end_line": 43,
"start_col": 0,
"start_line": 42
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1 | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Prims.l_or",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Hacl.Spec.SHA2.Vec.lanes",
"Prims.logical"
] | [] | false | false | false | true | true | let is_supported (a: sha2_alg) (m: m_spec) =
| lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8 | false |
|
Vale.Wrapper.X64.GCMencryptOpt256.fsti | Vale.Wrapper.X64.GCMencryptOpt256.length_aux3 | val length_aux3 (b: uint8_p) (n: nat)
: Lemma (requires B.length b = 16 * n) (ensures DV.length (get_downview b) % 16 = 0) | val length_aux3 (b: uint8_p) (n: nat)
: Lemma (requires B.length b = 16 * n) (ensures DV.length (get_downview b) % 16 = 0) | let length_aux3 (b:uint8_p) (n:nat) : Lemma
(requires B.length b = 16 * n)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db;
FStar.Math.Lemmas.cancel_mul_mod n 16 | {
"file_name": "vale/code/arch/x64/interop/Vale.Wrapper.X64.GCMencryptOpt256.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 41,
"end_line": 46,
"start_col": 0,
"start_line": 41
} | module Vale.Wrapper.X64.GCMencryptOpt256
open Vale.X64.CPU_Features_s
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
open Vale.AsLowStar.MemoryHelpers
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.AES.GCM_helpers
open Vale.AES.AES_s
open Vale.AES.GCM_s
open Vale.AES.GHash_s
open Vale.AES.GCTR_s
open Vale.AES.GCTR
open Vale.Interop.Base
open Vale.Arch.Types
open Vale.AES.OptPublic
let uint8_p = B.buffer UInt8.t
let uint64 = UInt64.t
let disjoint_or_eq (b1 b2:uint8_p) = B.disjoint b1 b2 \/ b1 == b2
let length_aux (b:uint8_p) : Lemma
(requires B.length b = 176)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db
let length_aux2 (b:uint8_p) : Lemma
(requires B.length b = 240)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GHash_s.fst.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.GCTR.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.GCM_helpers.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Wrapper.X64.GCMencryptOpt256.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Vale.Wrapper.X64.GCMencryptOpt256.uint8_p -> n: Prims.nat
-> FStar.Pervasives.Lemma (requires LowStar.Monotonic.Buffer.length b = 16 * n)
(ensures LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview b) % 16 = 0) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Wrapper.X64.GCMencryptOpt256.uint8_p",
"Prims.nat",
"FStar.Math.Lemmas.cancel_mul_mod",
"Prims.unit",
"LowStar.BufferView.Down.length_eq",
"FStar.UInt8.t",
"LowStar.BufferView.Down.buffer",
"Vale.Interop.Types.get_downview",
"Vale.Arch.HeapTypes_s.TUInt8",
"LowStar.Buffer.trivial_preorder",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"LowStar.Monotonic.Buffer.length",
"FStar.Mul.op_Star",
"Prims.squash",
"Prims.op_Modulus",
"LowStar.BufferView.Down.length",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let length_aux3 (b: uint8_p) (n: nat)
: Lemma (requires B.length b = 16 * n) (ensures DV.length (get_downview b) % 16 = 0) =
| let db = get_downview b in
DV.length_eq db;
FStar.Math.Lemmas.cancel_mul_mod n 16 | false |
Vale.Wrapper.X64.GCMencryptOpt256.fsti | Vale.Wrapper.X64.GCMencryptOpt256.length_aux2 | val length_aux2 (b: uint8_p)
: Lemma (requires B.length b = 240) (ensures DV.length (get_downview b) % 16 = 0) | val length_aux2 (b: uint8_p)
: Lemma (requires B.length b = 240) (ensures DV.length (get_downview b) % 16 = 0) | let length_aux2 (b:uint8_p) : Lemma
(requires B.length b = 240)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db | {
"file_name": "vale/code/arch/x64/interop/Vale.Wrapper.X64.GCMencryptOpt256.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 19,
"end_line": 39,
"start_col": 0,
"start_line": 35
} | module Vale.Wrapper.X64.GCMencryptOpt256
open Vale.X64.CPU_Features_s
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
open Vale.AsLowStar.MemoryHelpers
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.AES.GCM_helpers
open Vale.AES.AES_s
open Vale.AES.GCM_s
open Vale.AES.GHash_s
open Vale.AES.GCTR_s
open Vale.AES.GCTR
open Vale.Interop.Base
open Vale.Arch.Types
open Vale.AES.OptPublic
let uint8_p = B.buffer UInt8.t
let uint64 = UInt64.t
let disjoint_or_eq (b1 b2:uint8_p) = B.disjoint b1 b2 \/ b1 == b2
let length_aux (b:uint8_p) : Lemma
(requires B.length b = 176)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GHash_s.fst.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.GCTR.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.GCM_helpers.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Wrapper.X64.GCMencryptOpt256.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Vale.Wrapper.X64.GCMencryptOpt256.uint8_p
-> FStar.Pervasives.Lemma (requires LowStar.Monotonic.Buffer.length b = 240)
(ensures LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview b) % 16 = 0) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Wrapper.X64.GCMencryptOpt256.uint8_p",
"LowStar.BufferView.Down.length_eq",
"FStar.UInt8.t",
"LowStar.BufferView.Down.buffer",
"Vale.Interop.Types.get_downview",
"Vale.Arch.HeapTypes_s.TUInt8",
"LowStar.Buffer.trivial_preorder",
"Prims.unit",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"LowStar.Monotonic.Buffer.length",
"Prims.squash",
"Prims.op_Modulus",
"LowStar.BufferView.Down.length",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let length_aux2 (b: uint8_p)
: Lemma (requires B.length b = 240) (ensures DV.length (get_downview b) % 16 = 0) =
| let db = get_downview b in
DV.length_eq db | false |
Vale.Wrapper.X64.GCMencryptOpt256.fsti | Vale.Wrapper.X64.GCMencryptOpt256.length_aux | val length_aux (b: uint8_p)
: Lemma (requires B.length b = 176) (ensures DV.length (get_downview b) % 16 = 0) | val length_aux (b: uint8_p)
: Lemma (requires B.length b = 176) (ensures DV.length (get_downview b) % 16 = 0) | let length_aux (b:uint8_p) : Lemma
(requires B.length b = 176)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db | {
"file_name": "vale/code/arch/x64/interop/Vale.Wrapper.X64.GCMencryptOpt256.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 19,
"end_line": 33,
"start_col": 0,
"start_line": 29
} | module Vale.Wrapper.X64.GCMencryptOpt256
open Vale.X64.CPU_Features_s
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
open Vale.AsLowStar.MemoryHelpers
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.AES.GCM_helpers
open Vale.AES.AES_s
open Vale.AES.GCM_s
open Vale.AES.GHash_s
open Vale.AES.GCTR_s
open Vale.AES.GCTR
open Vale.Interop.Base
open Vale.Arch.Types
open Vale.AES.OptPublic
let uint8_p = B.buffer UInt8.t
let uint64 = UInt64.t
let disjoint_or_eq (b1 b2:uint8_p) = B.disjoint b1 b2 \/ b1 == b2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GHash_s.fst.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.GCTR.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.GCM_helpers.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Wrapper.X64.GCMencryptOpt256.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Vale.Wrapper.X64.GCMencryptOpt256.uint8_p
-> FStar.Pervasives.Lemma (requires LowStar.Monotonic.Buffer.length b = 176)
(ensures LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview b) % 16 = 0) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Wrapper.X64.GCMencryptOpt256.uint8_p",
"LowStar.BufferView.Down.length_eq",
"FStar.UInt8.t",
"LowStar.BufferView.Down.buffer",
"Vale.Interop.Types.get_downview",
"Vale.Arch.HeapTypes_s.TUInt8",
"LowStar.Buffer.trivial_preorder",
"Prims.unit",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"LowStar.Monotonic.Buffer.length",
"Prims.squash",
"Prims.op_Modulus",
"LowStar.BufferView.Down.length",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let length_aux (b: uint8_p)
: Lemma (requires B.length b = 176) (ensures DV.length (get_downview b) % 16 = 0) =
| let db = get_downview b in
DV.length_eq db | false |
Vale.Wrapper.X64.GCMencryptOpt256.fsti | Vale.Wrapper.X64.GCMencryptOpt256.length_aux5 | val length_aux5 (b: uint8_p)
: Lemma (requires B.length b = 128) (ensures DV.length (get_downview b) % 16 = 0) | val length_aux5 (b: uint8_p)
: Lemma (requires B.length b = 128) (ensures DV.length (get_downview b) % 16 = 0) | let length_aux5 (b:uint8_p) : Lemma
(requires B.length b = 128)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db | {
"file_name": "vale/code/arch/x64/interop/Vale.Wrapper.X64.GCMencryptOpt256.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 19,
"end_line": 58,
"start_col": 0,
"start_line": 54
} | module Vale.Wrapper.X64.GCMencryptOpt256
open Vale.X64.CPU_Features_s
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
open Vale.AsLowStar.MemoryHelpers
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.AES.GCM_helpers
open Vale.AES.AES_s
open Vale.AES.GCM_s
open Vale.AES.GHash_s
open Vale.AES.GCTR_s
open Vale.AES.GCTR
open Vale.Interop.Base
open Vale.Arch.Types
open Vale.AES.OptPublic
let uint8_p = B.buffer UInt8.t
let uint64 = UInt64.t
let disjoint_or_eq (b1 b2:uint8_p) = B.disjoint b1 b2 \/ b1 == b2
let length_aux (b:uint8_p) : Lemma
(requires B.length b = 176)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db
let length_aux2 (b:uint8_p) : Lemma
(requires B.length b = 240)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db
let length_aux3 (b:uint8_p) (n:nat) : Lemma
(requires B.length b = 16 * n)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db;
FStar.Math.Lemmas.cancel_mul_mod n 16
let length_aux4 (b:uint8_p) : Lemma
(requires B.length b = 16)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Wrapper.X64.GCMencryptOpt.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GHash_s.fst.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.GCTR.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.GCM_helpers.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Wrapper.X64.GCMencryptOpt256.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Vale.Wrapper.X64.GCMencryptOpt256.uint8_p
-> FStar.Pervasives.Lemma (requires LowStar.Monotonic.Buffer.length b = 128)
(ensures LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview b) % 16 = 0) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Wrapper.X64.GCMencryptOpt256.uint8_p",
"LowStar.BufferView.Down.length_eq",
"FStar.UInt8.t",
"LowStar.BufferView.Down.buffer",
"Vale.Interop.Types.get_downview",
"Vale.Arch.HeapTypes_s.TUInt8",
"LowStar.Buffer.trivial_preorder",
"Prims.unit",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"LowStar.Monotonic.Buffer.length",
"Prims.squash",
"Prims.op_Modulus",
"LowStar.BufferView.Down.length",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let length_aux5 (b: uint8_p)
: Lemma (requires B.length b = 128) (ensures DV.length (get_downview b) % 16 = 0) =
| let db = get_downview b in
DV.length_eq db | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.transpose_ws1 | val transpose_ws1 (#a: sha2_alg) (#m: m_spec{lanes a m == 1}) (ws: ws_spec a m) : ws_spec a m | val transpose_ws1 (#a: sha2_alg) (#m: m_spec{lanes a m == 1}) (ws: ws_spec a m) : ws_spec a m | let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 95,
"end_line": 207,
"start_col": 0,
"start_line": 207
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b) | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ws: Hacl.Spec.SHA2.Vec.ws_spec a m -> Hacl.Spec.SHA2.Vec.ws_spec a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Prims.eq2",
"Prims.int",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Vec.ws_spec"
] | [] | false | false | false | false | false | let transpose_ws1 (#a: sha2_alg) (#m: m_spec{lanes a m == 1}) (ws: ws_spec a m) : ws_spec a m =
| ws | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.load_ws | val load_ws (#a: sha2_alg) (#m: m_spec{is_supported a m}) (b: multiblock_spec a m) : ws_spec a m | val load_ws (#a: sha2_alg) (#m: m_spec{is_supported a m}) (b: multiblock_spec a m) : ws_spec a m | let load_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) : ws_spec a m =
let ws = load_blocks #a #m b in
transpose_ws #a #m ws | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 23,
"end_line": 234,
"start_col": 0,
"start_line": 232
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (ws:ws_spec a m) : ws_spec a m =
match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Hacl.Spec.SHA2.Vec.multiblock_spec a m -> Hacl.Spec.SHA2.Vec.ws_spec a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Hacl.Spec.SHA2.Vec.multiblock_spec",
"Hacl.Spec.SHA2.Vec.transpose_ws",
"Hacl.Spec.SHA2.Vec.ws_spec",
"Hacl.Spec.SHA2.Vec.load_blocks"
] | [] | false | false | false | false | false | let load_ws (#a: sha2_alg) (#m: m_spec{is_supported a m}) (b: multiblock_spec a m) : ws_spec a m =
| let ws = load_blocks #a #m b in
transpose_ws #a #m ws | false |
Hacl.Impl.Curve25519.Field64.Vale.fsti | Hacl.Impl.Curve25519.Field64.Vale.p | val p : Prims.logical | let p = Vale.X64.CPU_Features_s.(adx_enabled /\ bmi2_enabled) | {
"file_name": "code/curve25519/Hacl.Impl.Curve25519.Field64.Vale.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 61,
"end_line": 5,
"start_col": 0,
"start_line": 5
} | module Hacl.Impl.Curve25519.Field64.Vale
open Hacl.Impl.Curve25519.Fields.Core | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"prims.fst.checked",
"Hacl.Impl.Curve25519.Fields.Core.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Curve25519.Field64.Vale.fsti"
} | [
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields.Core",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Prims.l_and",
"Prims.b2t",
"Vale.X64.CPU_Features_s.adx_enabled",
"Vale.X64.CPU_Features_s.bmi2_enabled"
] | [] | false | false | false | true | true | let p =
| let open Vale.X64.CPU_Features_s in adx_enabled /\ bmi2_enabled | false |
|
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.shuffle_inner_loop | val shuffle_inner_loop
(#a: sha2_alg)
(#m: m_spec)
(i: nat{i < v (num_rounds16 a)})
(ws_st: ws_spec a m & state_spec a m)
: ws_spec a m & state_spec a m | val shuffle_inner_loop
(#a: sha2_alg)
(#m: m_spec)
(i: nat{i < v (num_rounds16 a)})
(ws_st: ws_spec a m & state_spec a m)
: ws_spec a m & state_spec a m | let shuffle_inner_loop (#a:sha2_alg) (#m:m_spec) (i:nat{i < v (num_rounds16 a)})
(ws_st:ws_spec a m & state_spec a m) : ws_spec a m & state_spec a m =
let (ws,st) = ws_st in
let st' = repeati 16 (shuffle_inner ws i) st in
let ws' = if i < v (num_rounds16 a) - 1 then ws_next ws else ws in
(ws',st') | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 265,
"start_col": 0,
"start_line": 260
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (ws:ws_spec a m) : ws_spec a m =
match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws
noextract
let load_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) : ws_spec a m =
let ws = load_blocks #a #m b in
transpose_ws #a #m ws
noextract
let ws_next_inner (#a:sha2_alg) (#m:m_spec)
(i:nat{i < 16})
(ws:ws_spec a m) : ws_spec a m =
let t16 = ws.[i] in
let t15 = ws.[(i+1) % 16] in
let t7 = ws.[(i+9) % 16] in
let t2 = ws.[(i+14) % 16] in
let s1 = _sigma1 t2 in
let s0 = _sigma0 t15 in
ws.[i] <- (s1 +| t7 +| s0 +| t16)
noextract
let ws_next (#a:sha2_alg) (#m:m_spec)
(ws:ws_spec a m) : ws_spec a m =
repeati 16 (ws_next_inner #a #m) ws
noextract
let shuffle_inner (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (i:nat{i < v (num_rounds16 a)}) (j:nat{j < 16}) (st:state_spec a m) : state_spec a m =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec k_t ws_t st | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
i: Prims.nat{i < Lib.IntTypes.v (Hacl.Spec.SHA2.Vec.num_rounds16 a)} ->
ws_st: (Hacl.Spec.SHA2.Vec.ws_spec a m * Hacl.Spec.SHA2.Vec.state_spec a m)
-> Hacl.Spec.SHA2.Vec.ws_spec a m * Hacl.Spec.SHA2.Vec.state_spec a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Spec.SHA2.Vec.num_rounds16",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.SHA2.Vec.ws_spec",
"Hacl.Spec.SHA2.Vec.state_spec",
"FStar.Pervasives.Native.Mktuple2",
"Prims.op_Subtraction",
"Hacl.Spec.SHA2.Vec.ws_next",
"Prims.bool",
"Lib.LoopCombinators.repeati",
"Hacl.Spec.SHA2.Vec.shuffle_inner"
] | [] | false | false | false | false | false | let shuffle_inner_loop
(#a: sha2_alg)
(#m: m_spec)
(i: nat{i < v (num_rounds16 a)})
(ws_st: ws_spec a m & state_spec a m)
: ws_spec a m & state_spec a m =
| let ws, st = ws_st in
let st' = repeati 16 (shuffle_inner ws i) st in
let ws' = if i < v (num_rounds16 a) - 1 then ws_next ws else ws in
(ws', st') | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.ws_next | val ws_next (#a: sha2_alg) (#m: m_spec) (ws: ws_spec a m) : ws_spec a m | val ws_next (#a: sha2_alg) (#m: m_spec) (ws: ws_spec a m) : ws_spec a m | let ws_next (#a:sha2_alg) (#m:m_spec)
(ws:ws_spec a m) : ws_spec a m =
repeati 16 (ws_next_inner #a #m) ws | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 251,
"start_col": 0,
"start_line": 249
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (ws:ws_spec a m) : ws_spec a m =
match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws
noextract
let load_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) : ws_spec a m =
let ws = load_blocks #a #m b in
transpose_ws #a #m ws
noextract
let ws_next_inner (#a:sha2_alg) (#m:m_spec)
(i:nat{i < 16})
(ws:ws_spec a m) : ws_spec a m =
let t16 = ws.[i] in
let t15 = ws.[(i+1) % 16] in
let t7 = ws.[(i+9) % 16] in
let t2 = ws.[(i+14) % 16] in
let s1 = _sigma1 t2 in
let s0 = _sigma0 t15 in
ws.[i] <- (s1 +| t7 +| s0 +| t16) | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ws: Hacl.Spec.SHA2.Vec.ws_spec a m -> Hacl.Spec.SHA2.Vec.ws_spec a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.ws_spec",
"Lib.LoopCombinators.repeati",
"Hacl.Spec.SHA2.Vec.ws_next_inner"
] | [] | false | false | false | false | false | let ws_next (#a: sha2_alg) (#m: m_spec) (ws: ws_spec a m) : ws_spec a m =
| repeati 16 (ws_next_inner #a #m) ws | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.zero_element | val zero_element: a:sha2_alg -> m:m_spec -> element_t a m | val zero_element: a:sha2_alg -> m:m_spec -> element_t a m | let zero_element a m = vec_zero (word_t a) (lanes a m) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 54,
"end_line": 50,
"start_col": 0,
"start_line": 50
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec
-> Hacl.Spec.SHA2.Vec.element_t a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Lib.IntVector.vec_zero",
"Spec.Hash.Definitions.word_t",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Vec.element_t"
] | [] | false | false | false | false | false | let zero_element a m =
| vec_zero (word_t a) (lanes a m) | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.load_element | val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m | val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m | let load_element a m x = vec_load x (lanes a m) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 62,
"start_col": 0,
"start_line": 62
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec -> x: Hacl.Spec.SHA2.Vec.word a
-> Hacl.Spec.SHA2.Vec.element_t a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.word",
"Lib.IntVector.vec_load",
"Spec.Hash.Definitions.word_t",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Vec.element_t"
] | [] | false | false | false | false | false | let load_element a m x =
| vec_load x (lanes a m) | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.word | val word : a: Spec.Hash.Definitions.hash_alg -> Type0 | let word (a:hash_alg) = uint_t (word_t a) SEC | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 54,
"start_col": 0,
"start_line": 54
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.hash_alg -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.hash_alg",
"Lib.IntTypes.uint_t",
"Spec.Hash.Definitions.word_t",
"Lib.IntTypes.SEC"
] | [] | false | false | false | true | true | let word (a: hash_alg) =
| uint_t (word_t a) SEC | false |
|
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.state_spec | val state_spec : a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec -> Type0 | let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 63,
"end_line": 126,
"start_col": 0,
"start_line": 126
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5)) | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Lib.Sequence.lseq",
"Hacl.Spec.SHA2.Vec.element_t"
] | [] | false | false | false | true | true | let state_spec (a: sha2_alg) (m: m_spec) =
| lseq (element_t a m) 8 | false |
|
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.multiseq | val multiseq : lanes: Hacl.Spec.SHA2.Vec.lanes_t -> len: Prims.nat -> Type0 | let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 185,
"start_col": 0,
"start_line": 184
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | lanes: Hacl.Spec.SHA2.Vec.lanes_t -> len: Prims.nat -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.SHA2.Vec.lanes_t",
"Prims.nat",
"Lib.NTuple.ntuple",
"FStar.Seq.Properties.lseq",
"Lib.IntTypes.uint8"
] | [] | false | false | false | true | true | let multiseq (lanes: lanes_t) (len: nat) =
| ntuple (Seq.lseq uint8 len) lanes | false |
|
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.ws_spec | val ws_spec : a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec -> Type0 | let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 61,
"end_line": 129,
"start_col": 0,
"start_line": 129
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8 | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Lib.Sequence.lseq",
"Hacl.Spec.SHA2.Vec.element_t"
] | [] | false | false | false | true | true | let ws_spec (a: sha2_alg) (m: m_spec) =
| lseq (element_t a m) 16 | false |
|
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.element_t | val element_t : a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec -> Type0 | let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 68,
"end_line": 46,
"start_col": 0,
"start_line": 46
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8 | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Lib.IntVector.vec_t",
"Spec.Hash.Definitions.word_t",
"Hacl.Spec.SHA2.Vec.lanes"
] | [] | false | false | false | true | true | let element_t (a: sha2_alg) (m: m_spec) =
| vec_t (word_t a) (lanes a m) | false |
|
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec._Sigma1 | val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m | val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m | let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5)) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 94,
"end_line": 115,
"start_col": 0,
"start_line": 115
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Hacl.Spec.SHA2.Vec.element_t a m -> Hacl.Spec.SHA2.Vec.element_t a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.element_t",
"Hacl.Spec.SHA2.Vec.op_Hat_Bar",
"Hacl.Spec.SHA2.Vec.op_Greater_Greater_Greater_Bar",
"Hacl.Spec.SHA2.__proj__Mkops__item__c3",
"Hacl.Spec.SHA2.op0",
"Hacl.Spec.SHA2.__proj__Mkops__item__c4",
"Hacl.Spec.SHA2.__proj__Mkops__item__c5"
] | [] | false | false | false | false | false | let _Sigma1 #a #m x =
| let open Spec in (x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5) | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec._Sigma0 | val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m | val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m | let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2)) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 94,
"end_line": 111,
"start_col": 0,
"start_line": 111
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Hacl.Spec.SHA2.Vec.element_t a m -> Hacl.Spec.SHA2.Vec.element_t a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.element_t",
"Hacl.Spec.SHA2.Vec.op_Hat_Bar",
"Hacl.Spec.SHA2.Vec.op_Greater_Greater_Greater_Bar",
"Hacl.Spec.SHA2.__proj__Mkops__item__c0",
"Hacl.Spec.SHA2.op0",
"Hacl.Spec.SHA2.__proj__Mkops__item__c1",
"Hacl.Spec.SHA2.__proj__Mkops__item__c2"
] | [] | false | false | false | false | false | let _Sigma0 #a #m x =
| let open Spec in (x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2) | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.shuffle | val shuffle (#a: sha2_alg) (#m: m_spec) (ws: ws_spec a m) (st: state_spec a m) : state_spec a m | val shuffle (#a: sha2_alg) (#m: m_spec) (ws: ws_spec a m) (st: state_spec a m) : state_spec a m | let shuffle (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (st:state_spec a m) : state_spec a m =
let (ws,st) = repeati (v(num_rounds16 a)) (shuffle_inner_loop #a #m) (ws,st) in
st | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 270,
"start_col": 0,
"start_line": 268
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (ws:ws_spec a m) : ws_spec a m =
match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws
noextract
let load_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) : ws_spec a m =
let ws = load_blocks #a #m b in
transpose_ws #a #m ws
noextract
let ws_next_inner (#a:sha2_alg) (#m:m_spec)
(i:nat{i < 16})
(ws:ws_spec a m) : ws_spec a m =
let t16 = ws.[i] in
let t15 = ws.[(i+1) % 16] in
let t7 = ws.[(i+9) % 16] in
let t2 = ws.[(i+14) % 16] in
let s1 = _sigma1 t2 in
let s0 = _sigma0 t15 in
ws.[i] <- (s1 +| t7 +| s0 +| t16)
noextract
let ws_next (#a:sha2_alg) (#m:m_spec)
(ws:ws_spec a m) : ws_spec a m =
repeati 16 (ws_next_inner #a #m) ws
noextract
let shuffle_inner (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (i:nat{i < v (num_rounds16 a)}) (j:nat{j < 16}) (st:state_spec a m) : state_spec a m =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec k_t ws_t st
noextract
let shuffle_inner_loop (#a:sha2_alg) (#m:m_spec) (i:nat{i < v (num_rounds16 a)})
(ws_st:ws_spec a m & state_spec a m) : ws_spec a m & state_spec a m =
let (ws,st) = ws_st in
let st' = repeati 16 (shuffle_inner ws i) st in
let ws' = if i < v (num_rounds16 a) - 1 then ws_next ws else ws in
(ws',st') | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ws: Hacl.Spec.SHA2.Vec.ws_spec a m -> st: Hacl.Spec.SHA2.Vec.state_spec a m
-> Hacl.Spec.SHA2.Vec.state_spec a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.ws_spec",
"Hacl.Spec.SHA2.Vec.state_spec",
"FStar.Pervasives.Native.tuple2",
"Lib.LoopCombinators.repeati",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Spec.SHA2.Vec.num_rounds16",
"Hacl.Spec.SHA2.Vec.shuffle_inner_loop",
"FStar.Pervasives.Native.Mktuple2"
] | [] | false | false | false | false | false | let shuffle (#a: sha2_alg) (#m: m_spec) (ws: ws_spec a m) (st: state_spec a m) : state_spec a m =
| let ws, st = repeati (v (num_rounds16 a)) (shuffle_inner_loop #a #m) (ws, st) in
st | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.load_blocks | val load_blocks (#a: sha2_alg) (#m: m_spec) (b: multiblock_spec a m) : ws_spec a m | val load_blocks (#a: sha2_alg) (#m: m_spec) (b: multiblock_spec a m) : ws_spec a m | let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 30,
"end_line": 204,
"start_col": 0,
"start_line": 203
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Hacl.Spec.SHA2.Vec.multiblock_spec a m -> Hacl.Spec.SHA2.Vec.ws_spec a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.multiblock_spec",
"Lib.Sequence.createi",
"Hacl.Spec.SHA2.Vec.element_t",
"Hacl.Spec.SHA2.Vec.get_wsi",
"Hacl.Spec.SHA2.Vec.ws_spec"
] | [] | false | false | false | false | false | let load_blocks (#a: sha2_alg) (#m: m_spec) (b: multiblock_spec a m) : ws_spec a m =
| createi 16 (get_wsi #a #m b) | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.multiblock_spec | val multiblock_spec : a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec -> Type0 | let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 188,
"start_col": 7,
"start_line": 187
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.multiseq",
"Hacl.Spec.SHA2.Vec.lanes",
"Spec.Hash.Definitions.block_length"
] | [] | false | false | false | true | true | let multiblock_spec (a: sha2_alg) (m: m_spec) =
| multiseq (lanes a m) (block_length a) | false |
|
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec._sigma0 | val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m | val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m | let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2)) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 93,
"end_line": 119,
"start_col": 0,
"start_line": 119
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Hacl.Spec.SHA2.Vec.element_t a m -> Hacl.Spec.SHA2.Vec.element_t a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.element_t",
"Hacl.Spec.SHA2.Vec.op_Hat_Bar",
"Hacl.Spec.SHA2.Vec.op_Greater_Greater_Greater_Bar",
"Hacl.Spec.SHA2.__proj__Mkops__item__e0",
"Hacl.Spec.SHA2.op0",
"Hacl.Spec.SHA2.__proj__Mkops__item__e1",
"Hacl.Spec.SHA2.Vec.op_Greater_Greater_Bar",
"Hacl.Spec.SHA2.__proj__Mkops__item__e2"
] | [] | false | false | false | false | false | let _sigma0 #a #m x =
| let open Spec in (x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2) | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.transpose_ws | val transpose_ws (#a: sha2_alg) (#m: m_spec{is_supported a m}) (ws: ws_spec a m) : ws_spec a m | val transpose_ws (#a: sha2_alg) (#m: m_spec{is_supported a m}) (ws: ws_spec a m) : ws_spec a m | let transpose_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (ws:ws_spec a m) : ws_spec a m =
match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 31,
"end_line": 228,
"start_col": 0,
"start_line": 224
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15 | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ws: Hacl.Spec.SHA2.Vec.ws_spec a m -> Hacl.Spec.SHA2.Vec.ws_spec a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Hacl.Spec.SHA2.Vec.ws_spec",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Vec.transpose_ws1",
"Hacl.Spec.SHA2.Vec.transpose_ws4",
"Hacl.Spec.SHA2.Vec.transpose_ws8"
] | [] | false | false | false | false | false | let transpose_ws (#a: sha2_alg) (#m: m_spec{is_supported a m}) (ws: ws_spec a m) : ws_spec a m =
| match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.num_rounds16 | val num_rounds16 (a: sha2_alg) : n: size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} | val num_rounds16 (a: sha2_alg) : n: size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} | let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 30,
"end_line": 181,
"start_col": 0,
"start_line": 178
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1 | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.sha2_alg
-> n:
Lib.IntTypes.size_t{Lib.IntTypes.v n > 0 /\ 16 * Lib.IntTypes.v n == Hacl.Spec.SHA2.size_k_w a} | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.eq2",
"Prims.int",
"FStar.Mul.op_Star",
"Hacl.Spec.SHA2.size_k_w"
] | [] | false | false | false | false | false | let num_rounds16 (a: sha2_alg) : n: size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
| match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul | false |
FStar.Reflection.V1.Derived.Lemmas.fst | FStar.Reflection.V1.Derived.Lemmas.collect_app_order' | val collect_app_order' : (args:list argv) -> (tt:term) -> (t:term) ->
Lemma (requires args <<: tt /\ t << tt)
(ensures (let fn, args' = collect_app_ln' args t in
args' <<: tt /\ fn << tt))
(decreases t) | val collect_app_order' : (args:list argv) -> (tt:term) -> (t:term) ->
Lemma (requires args <<: tt /\ t << tt)
(ensures (let fn, args' = collect_app_ln' args t in
args' <<: tt /\ fn << tt))
(decreases t) | let rec collect_app_order' args tt t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' (r::args) tt l
| _ -> () | {
"file_name": "ulib/FStar.Reflection.V1.Derived.Lemmas.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 13,
"end_line": 53,
"start_col": 0,
"start_line": 50
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.V1.Derived.Lemmas
open FStar.Stubs.Reflection.Types
open FStar.Stubs.Reflection.V1.Builtins
open FStar.Stubs.Reflection.V1.Data
open FStar.Reflection.V1.Derived
open FStar.List.Tot
let rec forall_list (p:'a -> Type) (l:list 'a) : Type =
match l with
| [] -> True
| x::xs -> p x /\ forall_list p xs
let forallP (p: 'a -> Type) (l: list 'a): Type
= forall (x: 'a). memP x l ==> p x
// Precedence relation on the element of a list
unfold let (<<:) (l: list 'a) (r: 'r)
= forallP (fun x -> x << r) l
// A glorified `id`
val list_ref : (#a:Type) -> (#p:(a -> Type)) -> (l:list a) ->
Pure (list (x:a{p x}))
(requires (forallP p l))
(ensures (fun _ -> True))
let rec list_ref #a #p l =
match l with
| [] -> []
| x::xs -> x :: list_ref #a #p xs
val collect_app_order' : (args:list argv) -> (tt:term) -> (t:term) ->
Lemma (requires args <<: tt /\ t << tt)
(ensures (let fn, args' = collect_app_ln' args t in
args' <<: tt /\ fn << tt)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Stubs.Reflection.V1.Data.fsti.checked",
"FStar.Stubs.Reflection.V1.Builtins.fsti.checked",
"FStar.Stubs.Reflection.Types.fsti.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V1.Derived.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
args: Prims.list FStar.Stubs.Reflection.V1.Data.argv ->
tt: FStar.Stubs.Reflection.Types.term ->
t: FStar.Stubs.Reflection.Types.term
-> FStar.Pervasives.Lemma (requires args <<: tt /\ t << tt)
(ensures
(let _ = FStar.Reflection.V1.Derived.collect_app_ln' args t in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ fn args' = _ in
args' <<: tt /\ fn << tt)
<:
Type0))
(decreases t) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.list",
"FStar.Stubs.Reflection.V1.Data.argv",
"FStar.Stubs.Reflection.Types.term",
"FStar.Reflection.V1.Derived.inspect_ln_unascribe",
"FStar.Reflection.V1.Derived.Lemmas.collect_app_order'",
"Prims.Cons",
"FStar.Stubs.Reflection.V1.Data.term_view",
"Prims.unit"
] | [
"recursion"
] | false | false | true | false | false | let rec collect_app_order' args tt t =
| match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' (r :: args) tt l
| _ -> () | false |
Spec.Frodo.KEM.KeyGen.fst | Spec.Frodo.KEM.KeyGen.frodo_shake_r | val frodo_shake_r:
a:frodo_alg
-> c:uint8
-> seed_se:lbytes (crypto_bytes a)
-> output_len:size_nat
-> lbytes output_len | val frodo_shake_r:
a:frodo_alg
-> c:uint8
-> seed_se:lbytes (crypto_bytes a)
-> output_len:size_nat
-> lbytes output_len | let frodo_shake_r a c seed_se output_len =
let tmp = LSeq.create 1 c in
let shake_input_seed_se = LSeq.concat tmp seed_se in
frodo_shake a (1 + crypto_bytes a) shake_input_seed_se output_len | {
"file_name": "specs/frodo/Spec.Frodo.KEM.KeyGen.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 67,
"end_line": 29,
"start_col": 0,
"start_line": 26
} | module Spec.Frodo.KEM.KeyGen
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Matrix
open Spec.Frodo.Params
open Spec.Frodo.Pack
open Spec.Frodo.Sample
module LSeq = Lib.Sequence
module Matrix = Spec.Matrix
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val frodo_shake_r:
a:frodo_alg
-> c:uint8
-> seed_se:lbytes (crypto_bytes a)
-> output_len:size_nat
-> lbytes output_len | {
"checked_file": "/",
"dependencies": [
"Spec.Matrix.fst.checked",
"Spec.Frodo.Sample.fst.checked",
"Spec.Frodo.Random.fst.checked",
"Spec.Frodo.Params.fst.checked",
"Spec.Frodo.Pack.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Frodo.KEM.KeyGen.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Matrix",
"short_module": "Matrix"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": false,
"full_module": "Spec.Frodo.Sample",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.Pack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.Params",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Frodo.Params.frodo_alg ->
c: Lib.IntTypes.uint8 ->
seed_se: Lib.ByteSequence.lbytes (Spec.Frodo.Params.crypto_bytes a) ->
output_len: Lib.IntTypes.size_nat
-> Lib.ByteSequence.lbytes output_len | Prims.Tot | [
"total"
] | [] | [
"Spec.Frodo.Params.frodo_alg",
"Lib.IntTypes.uint8",
"Lib.ByteSequence.lbytes",
"Spec.Frodo.Params.crypto_bytes",
"Lib.IntTypes.size_nat",
"Spec.Frodo.Params.frodo_shake",
"Prims.op_Addition",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.append",
"Lib.Sequence.concat",
"Lib.IntTypes.uint_t",
"Prims.l_and",
"FStar.Seq.Base.create",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.Sequence.index",
"Lib.Sequence.create"
] | [] | false | false | false | false | false | let frodo_shake_r a c seed_se output_len =
| let tmp = LSeq.create 1 c in
let shake_input_seed_se = LSeq.concat tmp seed_se in
frodo_shake a (1 + crypto_bytes a) shake_input_seed_se output_len | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.transpose_state | val transpose_state (#a: sha2_alg) (#m: m_spec{is_supported a m}) (st: state_spec a m)
: state_spec a m | val transpose_state (#a: sha2_alg) (#m: m_spec{is_supported a m}) (st: state_spec a m)
: state_spec a m | let transpose_state (#a:sha2_alg) (#m:m_spec{is_supported a m}) (st:state_spec a m) : state_spec a m =
match lanes a m with
| 1 -> st
| 4 -> transpose_state4 #a #m st
| 8 -> transpose_state8 #a #m st | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 34,
"end_line": 420,
"start_col": 0,
"start_line": 416
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (ws:ws_spec a m) : ws_spec a m =
match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws
noextract
let load_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) : ws_spec a m =
let ws = load_blocks #a #m b in
transpose_ws #a #m ws
noextract
let ws_next_inner (#a:sha2_alg) (#m:m_spec)
(i:nat{i < 16})
(ws:ws_spec a m) : ws_spec a m =
let t16 = ws.[i] in
let t15 = ws.[(i+1) % 16] in
let t7 = ws.[(i+9) % 16] in
let t2 = ws.[(i+14) % 16] in
let s1 = _sigma1 t2 in
let s0 = _sigma0 t15 in
ws.[i] <- (s1 +| t7 +| s0 +| t16)
noextract
let ws_next (#a:sha2_alg) (#m:m_spec)
(ws:ws_spec a m) : ws_spec a m =
repeati 16 (ws_next_inner #a #m) ws
noextract
let shuffle_inner (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (i:nat{i < v (num_rounds16 a)}) (j:nat{j < 16}) (st:state_spec a m) : state_spec a m =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec k_t ws_t st
noextract
let shuffle_inner_loop (#a:sha2_alg) (#m:m_spec) (i:nat{i < v (num_rounds16 a)})
(ws_st:ws_spec a m & state_spec a m) : ws_spec a m & state_spec a m =
let (ws,st) = ws_st in
let st' = repeati 16 (shuffle_inner ws i) st in
let ws' = if i < v (num_rounds16 a) - 1 then ws_next ws else ws in
(ws',st')
noextract
let shuffle (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (st:state_spec a m) : state_spec a m =
let (ws,st) = repeati (v(num_rounds16 a)) (shuffle_inner_loop #a #m) (ws,st) in
st
noextract
let init (a:sha2_alg) (m:m_spec) : state_spec a m =
createi 8 (fun i -> load_element a m (Seq.index (Spec.h0 a) i))
[@"opaque_to_smt"]
noextract
let update (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) (st:state_spec a m): state_spec a m =
let st_old = st in
let ws = load_ws b in
let st_new = shuffle ws st_old in
map2 (+|) st_new st_old
noextract
let padded_blocks (a:sha2_alg) (len:nat{len <= block_length a}) : n:nat{n <= 2} =
if (len + len_length a + 1 <= block_length a) then 1 else 2
noextract
let load_last_blocks (#a:sha2_alg)
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a})
(b:lseq uint8 len) :
lseq uint8 (block_length a) & lseq uint8 (block_length a) =
let last = create (2 * block_length a) (u8 0) in
let last = update_sub last 0 len b in
let last = last.[len] <- u8 0x80 in
let last = update_sub last (fin - len_length a) (len_length a) totlen_seq in
let l0 : lseq uint8 (block_length a) = sub last 0 (block_length a) in
let l1 : lseq uint8 (block_length a) = sub last (block_length a) (block_length a) in
(l0, l1)
noextract
let load_last1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b = b.(|0|) in
let (l0,l1) = load_last_blocks #a totlen_seq fin len b in
let lb0 : multiseq (lanes a m) (block_length a) = ntup1 l0 in
let lb1 : multiseq (lanes a m) (block_length a) = ntup1 l1 in
(lb0, lb1)
#push-options "--z3rlimit 100"
noextract
let load_last4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let mb0 = ntup4 (l00, (l10, (l20, l30))) in
let mb1 = ntup4 (l01, (l11, (l21, l31))) in
(mb0, mb1)
noextract
let load_last8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let b4 = b.(|4|) in
let b5 = b.(|5|) in
let b6 = b.(|6|) in
let b7 = b.(|7|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let (l40,l41) = load_last_blocks #a totlen_seq fin len b4 in
let (l50,l51) = load_last_blocks #a totlen_seq fin len b5 in
let (l60,l61) = load_last_blocks #a totlen_seq fin len b6 in
let (l70,l71) = load_last_blocks #a totlen_seq fin len b7 in
let mb0 = ntup8 (l00, (l10, (l20, (l30, (l40, (l50, (l60, l70))))))) in
let mb1 = ntup8 (l01, (l11, (l21, (l31, (l41, (l51, (l61, l71))))))) in
(mb0, mb1)
#pop-options
[@"opaque_to_smt"]
noextract
let load_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
match lanes a m with
| 1 -> load_last1 #a #m totlen_seq fin len b
| 4 -> load_last4 #a #m totlen_seq fin len b
| 8 -> load_last8 #a #m totlen_seq fin len b
noextract
let update_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen:len_t a)
(len:nat{len <= block_length a})
(b:multiseq (lanes a m) len) (st:state_spec a m): state_spec a m =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
let st = update b0 st in
if blocks > 1 then
update b1 st
else st
noextract
let transpose_state4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(st:state_spec a m) : state_spec a m =
let st0 = st.[0] in
let st1 = st.[1] in
let st2 = st.[2] in
let st3 = st.[3] in
let st4 = st.[4] in
let st5 = st.[5] in
let st6 = st.[6] in
let st7 = st.[7] in
let (st0,st1,st2,st3) = VecTranspose.transpose4x4 (st0,st1,st2,st3) in
let (st4,st5,st6,st7) = VecTranspose.transpose4x4 (st4,st5,st6,st7) in
create8 st0 st4 st1 st5 st2 st6 st3 st7
noextract
let transpose_state8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8})
(st:state_spec a m) : state_spec a m =
let st0 = st.[0] in
let st1 = st.[1] in
let st2 = st.[2] in
let st3 = st.[3] in
let st4 = st.[4] in
let st5 = st.[5] in
let st6 = st.[6] in
let st7 = st.[7] in
let (st0,st1,st2,st3,st4,st5,st6,st7) = VecTranspose.transpose8x8 (st0,st1,st2,st3,st4,st5,st6,st7) in
create8 st0 st1 st2 st3 st4 st5 st6 st7 | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | st: Hacl.Spec.SHA2.Vec.state_spec a m -> Hacl.Spec.SHA2.Vec.state_spec a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Hacl.Spec.SHA2.Vec.state_spec",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Vec.transpose_state4",
"Hacl.Spec.SHA2.Vec.transpose_state8"
] | [] | false | false | false | false | false | let transpose_state (#a: sha2_alg) (#m: m_spec{is_supported a m}) (st: state_spec a m)
: state_spec a m =
| match lanes a m with
| 1 -> st
| 4 -> transpose_state4 #a #m st
| 8 -> transpose_state8 #a #m st | false |
FStar.Reflection.V1.Derived.Lemmas.fst | FStar.Reflection.V1.Derived.Lemmas.collect_app_ref | val collect_app_ref : (t:term) -> (h:term{h == t \/ h << t}) * list (a:argv{fst a << t}) | val collect_app_ref : (t:term) -> (h:term{h == t \/ h << t}) * list (a:argv{fst a << t}) | let collect_app_ref t =
let h, a = collect_app_ln t in
collect_app_order t;
h, list_ref a | {
"file_name": "ulib/FStar.Reflection.V1.Derived.Lemmas.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 17,
"end_line": 68,
"start_col": 0,
"start_line": 65
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.V1.Derived.Lemmas
open FStar.Stubs.Reflection.Types
open FStar.Stubs.Reflection.V1.Builtins
open FStar.Stubs.Reflection.V1.Data
open FStar.Reflection.V1.Derived
open FStar.List.Tot
let rec forall_list (p:'a -> Type) (l:list 'a) : Type =
match l with
| [] -> True
| x::xs -> p x /\ forall_list p xs
let forallP (p: 'a -> Type) (l: list 'a): Type
= forall (x: 'a). memP x l ==> p x
// Precedence relation on the element of a list
unfold let (<<:) (l: list 'a) (r: 'r)
= forallP (fun x -> x << r) l
// A glorified `id`
val list_ref : (#a:Type) -> (#p:(a -> Type)) -> (l:list a) ->
Pure (list (x:a{p x}))
(requires (forallP p l))
(ensures (fun _ -> True))
let rec list_ref #a #p l =
match l with
| [] -> []
| x::xs -> x :: list_ref #a #p xs
val collect_app_order' : (args:list argv) -> (tt:term) -> (t:term) ->
Lemma (requires args <<: tt /\ t << tt)
(ensures (let fn, args' = collect_app_ln' args t in
args' <<: tt /\ fn << tt))
(decreases t)
let rec collect_app_order' args tt t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' (r::args) tt l
| _ -> ()
val collect_app_order : (t:term) ->
Lemma (ensures (forall (f:term). forall (s:list argv). (f,s) == collect_app_ln t ==>
(f << t /\ s <<: t)
\/ (f == t /\ s == [])))
let collect_app_order t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' [r] t l
| _ -> () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Stubs.Reflection.V1.Data.fsti.checked",
"FStar.Stubs.Reflection.V1.Builtins.fsti.checked",
"FStar.Stubs.Reflection.Types.fsti.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V1.Derived.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: FStar.Stubs.Reflection.Types.term
-> h:
FStar.Stubs.Reflection.Types.term{h == t \/ h << t} *
Prims.list (a: FStar.Stubs.Reflection.V1.Data.argv{FStar.Pervasives.Native.fst a << t}) | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.term",
"Prims.list",
"FStar.Stubs.Reflection.V1.Data.argv",
"FStar.Pervasives.Native.Mktuple2",
"Prims.l_or",
"Prims.eq2",
"Prims.precedes",
"FStar.Pervasives.Native.fst",
"FStar.Stubs.Reflection.V1.Data.aqualv",
"FStar.Reflection.V1.Derived.Lemmas.list_ref",
"Prims.unit",
"FStar.Reflection.V1.Derived.Lemmas.collect_app_order",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.V1.Derived.collect_app_ln"
] | [] | false | false | false | false | false | let collect_app_ref t =
| let h, a = collect_app_ln t in
collect_app_order t;
h, list_ref a | false |
FStar.Reflection.V1.Derived.Lemmas.fst | FStar.Reflection.V1.Derived.Lemmas.collect_app_order | val collect_app_order : (t:term) ->
Lemma (ensures (forall (f:term). forall (s:list argv). (f,s) == collect_app_ln t ==>
(f << t /\ s <<: t)
\/ (f == t /\ s == []))) | val collect_app_order : (t:term) ->
Lemma (ensures (forall (f:term). forall (s:list argv). (f,s) == collect_app_ln t ==>
(f << t /\ s <<: t)
\/ (f == t /\ s == []))) | let collect_app_order t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' [r] t l
| _ -> () | {
"file_name": "ulib/FStar.Reflection.V1.Derived.Lemmas.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 13,
"end_line": 62,
"start_col": 0,
"start_line": 59
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.V1.Derived.Lemmas
open FStar.Stubs.Reflection.Types
open FStar.Stubs.Reflection.V1.Builtins
open FStar.Stubs.Reflection.V1.Data
open FStar.Reflection.V1.Derived
open FStar.List.Tot
let rec forall_list (p:'a -> Type) (l:list 'a) : Type =
match l with
| [] -> True
| x::xs -> p x /\ forall_list p xs
let forallP (p: 'a -> Type) (l: list 'a): Type
= forall (x: 'a). memP x l ==> p x
// Precedence relation on the element of a list
unfold let (<<:) (l: list 'a) (r: 'r)
= forallP (fun x -> x << r) l
// A glorified `id`
val list_ref : (#a:Type) -> (#p:(a -> Type)) -> (l:list a) ->
Pure (list (x:a{p x}))
(requires (forallP p l))
(ensures (fun _ -> True))
let rec list_ref #a #p l =
match l with
| [] -> []
| x::xs -> x :: list_ref #a #p xs
val collect_app_order' : (args:list argv) -> (tt:term) -> (t:term) ->
Lemma (requires args <<: tt /\ t << tt)
(ensures (let fn, args' = collect_app_ln' args t in
args' <<: tt /\ fn << tt))
(decreases t)
let rec collect_app_order' args tt t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' (r::args) tt l
| _ -> ()
val collect_app_order : (t:term) ->
Lemma (ensures (forall (f:term). forall (s:list argv). (f,s) == collect_app_ln t ==>
(f << t /\ s <<: t) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Stubs.Reflection.V1.Data.fsti.checked",
"FStar.Stubs.Reflection.V1.Builtins.fsti.checked",
"FStar.Stubs.Reflection.Types.fsti.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V1.Derived.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: FStar.Stubs.Reflection.Types.term
-> FStar.Pervasives.Lemma
(ensures
forall (f: FStar.Stubs.Reflection.Types.term)
(s: Prims.list FStar.Stubs.Reflection.V1.Data.argv).
(f, s) == FStar.Reflection.V1.Derived.collect_app_ln t ==>
f << t /\ s <<: t \/ f == t /\ s == []) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Stubs.Reflection.Types.term",
"FStar.Reflection.V1.Derived.inspect_ln_unascribe",
"FStar.Stubs.Reflection.V1.Data.argv",
"FStar.Reflection.V1.Derived.Lemmas.collect_app_order'",
"Prims.Cons",
"Prims.Nil",
"FStar.Stubs.Reflection.V1.Data.term_view",
"Prims.unit"
] | [] | false | false | true | false | false | let collect_app_order t =
| match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' [r] t l
| _ -> () | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.shuffle_core_spec | val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m | val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m | let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 33,
"end_line": 174,
"start_col": 0,
"start_line": 154
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m -> | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k_t: Hacl.Spec.SHA2.Vec.word a ->
ws_t: Hacl.Spec.SHA2.Vec.element_t a m ->
st: Hacl.Spec.SHA2.Vec.state_spec a m
-> Hacl.Spec.SHA2.Vec.state_spec a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.word",
"Hacl.Spec.SHA2.Vec.element_t",
"Hacl.Spec.SHA2.Vec.state_spec",
"Lib.Sequence.create8",
"Prims.eq2",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Hacl.Spec.SHA2.Vec.op_Plus_Bar",
"Hacl.Spec.SHA2.Vec._Sigma0",
"Hacl.Spec.SHA2.Vec._Maj",
"Hacl.Spec.SHA2.Vec._Sigma1",
"Hacl.Spec.SHA2.Vec._Ch",
"Hacl.Spec.SHA2.Vec.load_element",
"Lib.Sequence.op_String_Access"
] | [] | false | false | false | false | false | let shuffle_core_spec #a #m k_t ws_t st =
| let a0 = st.[ 0 ] in
let b0 = st.[ 1 ] in
let c0 = st.[ 2 ] in
let d0 = st.[ 3 ] in
let e0 = st.[ 4 ] in
let f0 = st.[ 5 ] in
let g0 = st.[ 6 ] in
let h0 = st.[ 7 ] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1 | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec._sigma1 | val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m | val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m | let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5)) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 93,
"end_line": 123,
"start_col": 0,
"start_line": 123
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Hacl.Spec.SHA2.Vec.element_t a m -> Hacl.Spec.SHA2.Vec.element_t a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.element_t",
"Hacl.Spec.SHA2.Vec.op_Hat_Bar",
"Hacl.Spec.SHA2.Vec.op_Greater_Greater_Greater_Bar",
"Hacl.Spec.SHA2.__proj__Mkops__item__e3",
"Hacl.Spec.SHA2.op0",
"Hacl.Spec.SHA2.__proj__Mkops__item__e4",
"Hacl.Spec.SHA2.Vec.op_Greater_Greater_Bar",
"Hacl.Spec.SHA2.__proj__Mkops__item__e5"
] | [] | false | false | false | false | false | let _sigma1 #a #m x =
| let open Spec in (x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5) | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.update | val update
(#a: sha2_alg)
(#m: m_spec{is_supported a m})
(b: multiblock_spec a m)
(st: state_spec a m)
: state_spec a m | val update
(#a: sha2_alg)
(#m: m_spec{is_supported a m})
(b: multiblock_spec a m)
(st: state_spec a m)
: state_spec a m | let update (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) (st:state_spec a m): state_spec a m =
let st_old = st in
let ws = load_ws b in
let st_new = shuffle ws st_old in
map2 (+|) st_new st_old | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 25,
"end_line": 282,
"start_col": 0,
"start_line": 278
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (ws:ws_spec a m) : ws_spec a m =
match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws
noextract
let load_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) : ws_spec a m =
let ws = load_blocks #a #m b in
transpose_ws #a #m ws
noextract
let ws_next_inner (#a:sha2_alg) (#m:m_spec)
(i:nat{i < 16})
(ws:ws_spec a m) : ws_spec a m =
let t16 = ws.[i] in
let t15 = ws.[(i+1) % 16] in
let t7 = ws.[(i+9) % 16] in
let t2 = ws.[(i+14) % 16] in
let s1 = _sigma1 t2 in
let s0 = _sigma0 t15 in
ws.[i] <- (s1 +| t7 +| s0 +| t16)
noextract
let ws_next (#a:sha2_alg) (#m:m_spec)
(ws:ws_spec a m) : ws_spec a m =
repeati 16 (ws_next_inner #a #m) ws
noextract
let shuffle_inner (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (i:nat{i < v (num_rounds16 a)}) (j:nat{j < 16}) (st:state_spec a m) : state_spec a m =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec k_t ws_t st
noextract
let shuffle_inner_loop (#a:sha2_alg) (#m:m_spec) (i:nat{i < v (num_rounds16 a)})
(ws_st:ws_spec a m & state_spec a m) : ws_spec a m & state_spec a m =
let (ws,st) = ws_st in
let st' = repeati 16 (shuffle_inner ws i) st in
let ws' = if i < v (num_rounds16 a) - 1 then ws_next ws else ws in
(ws',st')
noextract
let shuffle (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (st:state_spec a m) : state_spec a m =
let (ws,st) = repeati (v(num_rounds16 a)) (shuffle_inner_loop #a #m) (ws,st) in
st
noextract
let init (a:sha2_alg) (m:m_spec) : state_spec a m =
createi 8 (fun i -> load_element a m (Seq.index (Spec.h0 a) i))
[@"opaque_to_smt"] | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Hacl.Spec.SHA2.Vec.multiblock_spec a m -> st: Hacl.Spec.SHA2.Vec.state_spec a m
-> Hacl.Spec.SHA2.Vec.state_spec a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Hacl.Spec.SHA2.Vec.multiblock_spec",
"Hacl.Spec.SHA2.Vec.state_spec",
"Lib.Sequence.map2",
"Hacl.Spec.SHA2.Vec.element_t",
"Hacl.Spec.SHA2.Vec.op_Plus_Bar",
"Hacl.Spec.SHA2.Vec.shuffle",
"Hacl.Spec.SHA2.Vec.ws_spec",
"Hacl.Spec.SHA2.Vec.load_ws"
] | [] | false | false | false | false | false | let update
(#a: sha2_alg)
(#m: m_spec{is_supported a m})
(b: multiblock_spec a m)
(st: state_spec a m)
: state_spec a m =
| let st_old = st in
let ws = load_ws b in
let st_new = shuffle ws st_old in
map2 ( +| ) st_new st_old | false |
FStar.Reflection.V1.Derived.Lemmas.fst | FStar.Reflection.V1.Derived.Lemmas.list_ref | val list_ref : (#a:Type) -> (#p:(a -> Type)) -> (l:list a) ->
Pure (list (x:a{p x}))
(requires (forallP p l))
(ensures (fun _ -> True)) | val list_ref : (#a:Type) -> (#p:(a -> Type)) -> (l:list a) ->
Pure (list (x:a{p x}))
(requires (forallP p l))
(ensures (fun _ -> True)) | let rec list_ref #a #p l =
match l with
| [] -> []
| x::xs -> x :: list_ref #a #p xs | {
"file_name": "ulib/FStar.Reflection.V1.Derived.Lemmas.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 37,
"end_line": 43,
"start_col": 0,
"start_line": 40
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.V1.Derived.Lemmas
open FStar.Stubs.Reflection.Types
open FStar.Stubs.Reflection.V1.Builtins
open FStar.Stubs.Reflection.V1.Data
open FStar.Reflection.V1.Derived
open FStar.List.Tot
let rec forall_list (p:'a -> Type) (l:list 'a) : Type =
match l with
| [] -> True
| x::xs -> p x /\ forall_list p xs
let forallP (p: 'a -> Type) (l: list 'a): Type
= forall (x: 'a). memP x l ==> p x
// Precedence relation on the element of a list
unfold let (<<:) (l: list 'a) (r: 'r)
= forallP (fun x -> x << r) l
// A glorified `id`
val list_ref : (#a:Type) -> (#p:(a -> Type)) -> (l:list a) ->
Pure (list (x:a{p x}))
(requires (forallP p l)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Stubs.Reflection.V1.Data.fsti.checked",
"FStar.Stubs.Reflection.V1.Builtins.fsti.checked",
"FStar.Stubs.Reflection.Types.fsti.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V1.Derived.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | l: Prims.list a -> Prims.Pure (Prims.list (x: a{p x})) | Prims.Pure | [] | [] | [
"Prims.list",
"Prims.Nil",
"Prims.Cons",
"FStar.Reflection.V1.Derived.Lemmas.list_ref"
] | [
"recursion"
] | false | false | false | false | false | let rec list_ref #a #p l =
| match l with
| [] -> []
| x :: xs -> x :: list_ref #a #p xs | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.padded_blocks | val padded_blocks (a: sha2_alg) (len: nat{len <= block_length a}) : n: nat{n <= 2} | val padded_blocks (a: sha2_alg) (len: nat{len <= block_length a}) : n: nat{n <= 2} | let padded_blocks (a:sha2_alg) (len:nat{len <= block_length a}) : n:nat{n <= 2} =
if (len + len_length a + 1 <= block_length a) then 1 else 2 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 61,
"end_line": 286,
"start_col": 0,
"start_line": 285
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (ws:ws_spec a m) : ws_spec a m =
match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws
noextract
let load_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) : ws_spec a m =
let ws = load_blocks #a #m b in
transpose_ws #a #m ws
noextract
let ws_next_inner (#a:sha2_alg) (#m:m_spec)
(i:nat{i < 16})
(ws:ws_spec a m) : ws_spec a m =
let t16 = ws.[i] in
let t15 = ws.[(i+1) % 16] in
let t7 = ws.[(i+9) % 16] in
let t2 = ws.[(i+14) % 16] in
let s1 = _sigma1 t2 in
let s0 = _sigma0 t15 in
ws.[i] <- (s1 +| t7 +| s0 +| t16)
noextract
let ws_next (#a:sha2_alg) (#m:m_spec)
(ws:ws_spec a m) : ws_spec a m =
repeati 16 (ws_next_inner #a #m) ws
noextract
let shuffle_inner (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (i:nat{i < v (num_rounds16 a)}) (j:nat{j < 16}) (st:state_spec a m) : state_spec a m =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec k_t ws_t st
noextract
let shuffle_inner_loop (#a:sha2_alg) (#m:m_spec) (i:nat{i < v (num_rounds16 a)})
(ws_st:ws_spec a m & state_spec a m) : ws_spec a m & state_spec a m =
let (ws,st) = ws_st in
let st' = repeati 16 (shuffle_inner ws i) st in
let ws' = if i < v (num_rounds16 a) - 1 then ws_next ws else ws in
(ws',st')
noextract
let shuffle (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (st:state_spec a m) : state_spec a m =
let (ws,st) = repeati (v(num_rounds16 a)) (shuffle_inner_loop #a #m) (ws,st) in
st
noextract
let init (a:sha2_alg) (m:m_spec) : state_spec a m =
createi 8 (fun i -> load_element a m (Seq.index (Spec.h0 a) i))
[@"opaque_to_smt"]
noextract
let update (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) (st:state_spec a m): state_spec a m =
let st_old = st in
let ws = load_ws b in
let st_new = shuffle ws st_old in
map2 (+|) st_new st_old | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.sha2_alg -> len: Prims.nat{len <= Spec.Hash.Definitions.block_length a}
-> n: Prims.nat{n <= 2} | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Spec.Hash.Definitions.block_length",
"Prims.op_Addition",
"Spec.Hash.Definitions.len_length",
"Prims.bool"
] | [] | false | false | false | false | false | let padded_blocks (a: sha2_alg) (len: nat{len <= block_length a}) : n: nat{n <= 2} =
| if (len + len_length a + 1 <= block_length a) then 1 else 2 | false |
FStar.Reflection.V1.Derived.Lemmas.fst | FStar.Reflection.V1.Derived.Lemmas.collect_abs_order' | val collect_abs_order' (bds: binders) (tt t: term)
: Lemma (requires t << tt /\ bds <<: tt)
(ensures
(let bds', body = collect_abs' bds t in
(bds' <<: tt /\ body << tt)))
(decreases t) | val collect_abs_order' (bds: binders) (tt t: term)
: Lemma (requires t << tt /\ bds <<: tt)
(ensures
(let bds', body = collect_abs' bds t in
(bds' <<: tt /\ body << tt)))
(decreases t) | let rec collect_abs_order' (bds: binders) (tt t: term)
: Lemma (requires t << tt /\ bds <<: tt)
(ensures (let bds', body = collect_abs' bds t in
(bds' <<: tt /\ body << tt)))
(decreases t)
= match inspect_ln_unascribe t with
| Tv_Abs b body -> collect_abs_order' (b::bds) tt body
| _ -> () | {
"file_name": "ulib/FStar.Reflection.V1.Derived.Lemmas.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 13,
"end_line": 78,
"start_col": 0,
"start_line": 71
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.V1.Derived.Lemmas
open FStar.Stubs.Reflection.Types
open FStar.Stubs.Reflection.V1.Builtins
open FStar.Stubs.Reflection.V1.Data
open FStar.Reflection.V1.Derived
open FStar.List.Tot
let rec forall_list (p:'a -> Type) (l:list 'a) : Type =
match l with
| [] -> True
| x::xs -> p x /\ forall_list p xs
let forallP (p: 'a -> Type) (l: list 'a): Type
= forall (x: 'a). memP x l ==> p x
// Precedence relation on the element of a list
unfold let (<<:) (l: list 'a) (r: 'r)
= forallP (fun x -> x << r) l
// A glorified `id`
val list_ref : (#a:Type) -> (#p:(a -> Type)) -> (l:list a) ->
Pure (list (x:a{p x}))
(requires (forallP p l))
(ensures (fun _ -> True))
let rec list_ref #a #p l =
match l with
| [] -> []
| x::xs -> x :: list_ref #a #p xs
val collect_app_order' : (args:list argv) -> (tt:term) -> (t:term) ->
Lemma (requires args <<: tt /\ t << tt)
(ensures (let fn, args' = collect_app_ln' args t in
args' <<: tt /\ fn << tt))
(decreases t)
let rec collect_app_order' args tt t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' (r::args) tt l
| _ -> ()
val collect_app_order : (t:term) ->
Lemma (ensures (forall (f:term). forall (s:list argv). (f,s) == collect_app_ln t ==>
(f << t /\ s <<: t)
\/ (f == t /\ s == [])))
let collect_app_order t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' [r] t l
| _ -> ()
val collect_app_ref : (t:term) -> (h:term{h == t \/ h << t}) * list (a:argv{fst a << t})
let collect_app_ref t =
let h, a = collect_app_ln t in
collect_app_order t;
h, list_ref a | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Stubs.Reflection.V1.Data.fsti.checked",
"FStar.Stubs.Reflection.V1.Builtins.fsti.checked",
"FStar.Stubs.Reflection.Types.fsti.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V1.Derived.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
bds: FStar.Stubs.Reflection.Types.binders ->
tt: FStar.Stubs.Reflection.Types.term ->
t: FStar.Stubs.Reflection.Types.term
-> FStar.Pervasives.Lemma (requires t << tt /\ bds <<: tt)
(ensures
(let _ = FStar.Reflection.V1.Derived.collect_abs' bds t in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ bds' body = _ in
bds' <<: tt /\ body << tt)
<:
Type0))
(decreases t) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"FStar.Stubs.Reflection.Types.binders",
"FStar.Stubs.Reflection.Types.term",
"FStar.Reflection.V1.Derived.inspect_ln_unascribe",
"FStar.Stubs.Reflection.Types.binder",
"FStar.Reflection.V1.Derived.Lemmas.collect_abs_order'",
"Prims.Cons",
"FStar.Stubs.Reflection.V1.Data.term_view",
"Prims.unit",
"Prims.l_and",
"Prims.precedes",
"FStar.Reflection.V1.Derived.Lemmas.op_Less_Less_Colon",
"Prims.squash",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.V1.Derived.collect_abs'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec collect_abs_order' (bds: binders) (tt t: term)
: Lemma (requires t << tt /\ bds <<: tt)
(ensures
(let bds', body = collect_abs' bds t in
(bds' <<: tt /\ body << tt)))
(decreases t) =
| match inspect_ln_unascribe t with
| Tv_Abs b body -> collect_abs_order' (b :: bds) tt body
| _ -> () | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.sha512_4 | val sha512_4 : len: Hacl.Spec.SHA2.len_lt_max_a_t Spec.Hash.Definitions.SHA2_512 ->
b: Hacl.Spec.SHA2.Vec.multiseq 4 len
-> Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes Spec.Hash.Definitions.SHA2_512
Hacl.Spec.SHA2.Vec.M256)
(Spec.Hash.Definitions.hash_length Spec.Hash.Definitions.SHA2_512) | let sha512_4 (len:Spec.len_lt_max_a_t SHA2_512) (b:multiseq 4 len) =
hash #SHA2_512 #M256 len b | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 28,
"end_line": 494,
"start_col": 0,
"start_line": 493
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (ws:ws_spec a m) : ws_spec a m =
match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws
noextract
let load_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) : ws_spec a m =
let ws = load_blocks #a #m b in
transpose_ws #a #m ws
noextract
let ws_next_inner (#a:sha2_alg) (#m:m_spec)
(i:nat{i < 16})
(ws:ws_spec a m) : ws_spec a m =
let t16 = ws.[i] in
let t15 = ws.[(i+1) % 16] in
let t7 = ws.[(i+9) % 16] in
let t2 = ws.[(i+14) % 16] in
let s1 = _sigma1 t2 in
let s0 = _sigma0 t15 in
ws.[i] <- (s1 +| t7 +| s0 +| t16)
noextract
let ws_next (#a:sha2_alg) (#m:m_spec)
(ws:ws_spec a m) : ws_spec a m =
repeati 16 (ws_next_inner #a #m) ws
noextract
let shuffle_inner (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (i:nat{i < v (num_rounds16 a)}) (j:nat{j < 16}) (st:state_spec a m) : state_spec a m =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec k_t ws_t st
noextract
let shuffle_inner_loop (#a:sha2_alg) (#m:m_spec) (i:nat{i < v (num_rounds16 a)})
(ws_st:ws_spec a m & state_spec a m) : ws_spec a m & state_spec a m =
let (ws,st) = ws_st in
let st' = repeati 16 (shuffle_inner ws i) st in
let ws' = if i < v (num_rounds16 a) - 1 then ws_next ws else ws in
(ws',st')
noextract
let shuffle (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (st:state_spec a m) : state_spec a m =
let (ws,st) = repeati (v(num_rounds16 a)) (shuffle_inner_loop #a #m) (ws,st) in
st
noextract
let init (a:sha2_alg) (m:m_spec) : state_spec a m =
createi 8 (fun i -> load_element a m (Seq.index (Spec.h0 a) i))
[@"opaque_to_smt"]
noextract
let update (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) (st:state_spec a m): state_spec a m =
let st_old = st in
let ws = load_ws b in
let st_new = shuffle ws st_old in
map2 (+|) st_new st_old
noextract
let padded_blocks (a:sha2_alg) (len:nat{len <= block_length a}) : n:nat{n <= 2} =
if (len + len_length a + 1 <= block_length a) then 1 else 2
noextract
let load_last_blocks (#a:sha2_alg)
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a})
(b:lseq uint8 len) :
lseq uint8 (block_length a) & lseq uint8 (block_length a) =
let last = create (2 * block_length a) (u8 0) in
let last = update_sub last 0 len b in
let last = last.[len] <- u8 0x80 in
let last = update_sub last (fin - len_length a) (len_length a) totlen_seq in
let l0 : lseq uint8 (block_length a) = sub last 0 (block_length a) in
let l1 : lseq uint8 (block_length a) = sub last (block_length a) (block_length a) in
(l0, l1)
noextract
let load_last1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b = b.(|0|) in
let (l0,l1) = load_last_blocks #a totlen_seq fin len b in
let lb0 : multiseq (lanes a m) (block_length a) = ntup1 l0 in
let lb1 : multiseq (lanes a m) (block_length a) = ntup1 l1 in
(lb0, lb1)
#push-options "--z3rlimit 100"
noextract
let load_last4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let mb0 = ntup4 (l00, (l10, (l20, l30))) in
let mb1 = ntup4 (l01, (l11, (l21, l31))) in
(mb0, mb1)
noextract
let load_last8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let b4 = b.(|4|) in
let b5 = b.(|5|) in
let b6 = b.(|6|) in
let b7 = b.(|7|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let (l40,l41) = load_last_blocks #a totlen_seq fin len b4 in
let (l50,l51) = load_last_blocks #a totlen_seq fin len b5 in
let (l60,l61) = load_last_blocks #a totlen_seq fin len b6 in
let (l70,l71) = load_last_blocks #a totlen_seq fin len b7 in
let mb0 = ntup8 (l00, (l10, (l20, (l30, (l40, (l50, (l60, l70))))))) in
let mb1 = ntup8 (l01, (l11, (l21, (l31, (l41, (l51, (l61, l71))))))) in
(mb0, mb1)
#pop-options
[@"opaque_to_smt"]
noextract
let load_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
match lanes a m with
| 1 -> load_last1 #a #m totlen_seq fin len b
| 4 -> load_last4 #a #m totlen_seq fin len b
| 8 -> load_last8 #a #m totlen_seq fin len b
noextract
let update_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen:len_t a)
(len:nat{len <= block_length a})
(b:multiseq (lanes a m) len) (st:state_spec a m): state_spec a m =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
let st = update b0 st in
if blocks > 1 then
update b1 st
else st
noextract
let transpose_state4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(st:state_spec a m) : state_spec a m =
let st0 = st.[0] in
let st1 = st.[1] in
let st2 = st.[2] in
let st3 = st.[3] in
let st4 = st.[4] in
let st5 = st.[5] in
let st6 = st.[6] in
let st7 = st.[7] in
let (st0,st1,st2,st3) = VecTranspose.transpose4x4 (st0,st1,st2,st3) in
let (st4,st5,st6,st7) = VecTranspose.transpose4x4 (st4,st5,st6,st7) in
create8 st0 st4 st1 st5 st2 st6 st3 st7
noextract
let transpose_state8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8})
(st:state_spec a m) : state_spec a m =
let st0 = st.[0] in
let st1 = st.[1] in
let st2 = st.[2] in
let st3 = st.[3] in
let st4 = st.[4] in
let st5 = st.[5] in
let st6 = st.[6] in
let st7 = st.[7] in
let (st0,st1,st2,st3,st4,st5,st6,st7) = VecTranspose.transpose8x8 (st0,st1,st2,st3,st4,st5,st6,st7) in
create8 st0 st1 st2 st3 st4 st5 st6 st7
noextract
let transpose_state (#a:sha2_alg) (#m:m_spec{is_supported a m}) (st:state_spec a m) : state_spec a m =
match lanes a m with
| 1 -> st
| 4 -> transpose_state4 #a #m st
| 8 -> transpose_state8 #a #m st
noextract
let store_state (#a:sha2_alg) (#m:m_spec{is_supported a m}) (st:state_spec a m) :
lseq uint8 (lanes a m * 8 * word_length a) =
let st = transpose_state st in
Lib.IntVector.Serialize.vecs_to_bytes_be st
noextract
let emit (#a:sha2_alg) (#m:m_spec)
(hseq:lseq uint8 (lanes a m * 8 * word_length a)):
multiseq (lanes a m) (hash_length a) =
Lib.NTuple.createi #(Seq.lseq uint8 (hash_length a)) (lanes a m)
(fun i -> sub hseq (i * 8 * word_length a) (hash_length a))
noextract
let get_multiblock_spec (#a:sha2_alg) (#m:m_spec)
(len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len)
(i:nat{i < len / block_length a})
: multiseq (lanes a m) (block_length a) =
Lib.NTuple.createi #(Seq.lseq uint8 (block_length a)) (lanes a m)
(fun j -> Seq.slice b.(|j|) (i * block_length a) (i * block_length a + block_length a))
noextract
let get_multilast_spec (#a:sha2_alg) (#m:m_spec)
(len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len)
: multiseq (lanes a m) (len % block_length a) =
let rem = len % block_length a in
Lib.NTuple.createi #(Seq.lseq uint8 rem) (lanes a m)
(fun j -> Seq.slice b.(|j|) (len - rem) len)
noextract
let update_block (#a:sha2_alg) (#m:m_spec{is_supported a m}) (len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len)
(i:nat{i < len / block_length a}) (st:state_spec a m) : state_spec a m =
let mb = get_multiblock_spec len b i in
update mb st
noextract
let update_nblocks (#a:sha2_alg) (#m:m_spec{is_supported a m}) (len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len) (st:state_spec a m) : state_spec a m =
let blocks = len / block_length a in
let st = repeati blocks (update_block #a #m len b) st in
st
noextract
let finish (#a:sha2_alg) (#m:m_spec{is_supported a m}) (st:state_spec a m) :
multiseq (lanes a m) (hash_length a) =
let hseq = store_state st in
emit hseq
noextract
let hash (#a:sha2_alg) (#m:m_spec{is_supported a m}) (len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len) =
let len' : len_t a = Spec.mk_len_t a len in
let st = init a m in
let st = update_nblocks #a #m len b st in
let rem = len % block_length a in
let mb = get_multilast_spec #a #m len b in
let st = update_last len' rem mb st in
finish st
noextract
let sha256 (len:Spec.len_lt_max_a_t SHA2_256) (b:seq uint8{length b = len}) =
hash #SHA2_256 #M32 len b
noextract
let sha256_4 (len:Spec.len_lt_max_a_t SHA2_256) (b:multiseq 4 len) =
hash #SHA2_256 #M128 len b
noextract
let sha512 (len:Spec.len_lt_max_a_t SHA2_512) (b:seq uint8{length b = len}) =
hash #SHA2_512 #M32 len b | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Hacl.Spec.SHA2.len_lt_max_a_t Spec.Hash.Definitions.SHA2_512 ->
b: Hacl.Spec.SHA2.Vec.multiseq 4 len
-> Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes Spec.Hash.Definitions.SHA2_512
Hacl.Spec.SHA2.Vec.M256)
(Spec.Hash.Definitions.hash_length Spec.Hash.Definitions.SHA2_512) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.SHA2.len_lt_max_a_t",
"Spec.Hash.Definitions.SHA2_512",
"Hacl.Spec.SHA2.Vec.multiseq",
"Hacl.Spec.SHA2.Vec.hash",
"Hacl.Spec.SHA2.Vec.M256",
"Hacl.Spec.SHA2.Vec.lanes",
"Spec.Hash.Definitions.hash_length"
] | [] | false | false | false | false | false | let sha512_4 (len: Spec.len_lt_max_a_t SHA2_512) (b: multiseq 4 len) =
| hash #SHA2_512 #M256 len b | false |
|
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.ws_next_inner | val ws_next_inner (#a: sha2_alg) (#m: m_spec) (i: nat{i < 16}) (ws: ws_spec a m) : ws_spec a m | val ws_next_inner (#a: sha2_alg) (#m: m_spec) (i: nat{i < 16}) (ws: ws_spec a m) : ws_spec a m | let ws_next_inner (#a:sha2_alg) (#m:m_spec)
(i:nat{i < 16})
(ws:ws_spec a m) : ws_spec a m =
let t16 = ws.[i] in
let t15 = ws.[(i+1) % 16] in
let t7 = ws.[(i+9) % 16] in
let t2 = ws.[(i+14) % 16] in
let s1 = _sigma1 t2 in
let s0 = _sigma0 t15 in
ws.[i] <- (s1 +| t7 +| s0 +| t16) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 246,
"start_col": 0,
"start_line": 237
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (ws:ws_spec a m) : ws_spec a m =
match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws
noextract
let load_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) : ws_spec a m =
let ws = load_blocks #a #m b in
transpose_ws #a #m ws | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Prims.nat{i < 16} -> ws: Hacl.Spec.SHA2.Vec.ws_spec a m -> Hacl.Spec.SHA2.Vec.ws_spec a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.ws_spec",
"Lib.Sequence.op_String_Assignment",
"Hacl.Spec.SHA2.Vec.element_t",
"Hacl.Spec.SHA2.Vec.op_Plus_Bar",
"Hacl.Spec.SHA2.Vec._sigma0",
"Hacl.Spec.SHA2.Vec._sigma1",
"Prims.eq2",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Prims.op_Modulus",
"Prims.op_Addition",
"Lib.Sequence.op_String_Access"
] | [] | false | false | false | false | false | let ws_next_inner (#a: sha2_alg) (#m: m_spec) (i: nat{i < 16}) (ws: ws_spec a m) : ws_spec a m =
| let t16 = ws.[ i ] in
let t15 = ws.[ (i + 1) % 16 ] in
let t7 = ws.[ (i + 9) % 16 ] in
let t2 = ws.[ (i + 14) % 16 ] in
let s1 = _sigma1 t2 in
let s0 = _sigma0 t15 in
ws.[ i ] <- (s1 +| t7 +| s0 +| t16) | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.shuffle_inner | val shuffle_inner
(#a: sha2_alg)
(#m: m_spec)
(ws: ws_spec a m)
(i: nat{i < v (num_rounds16 a)})
(j: nat{j < 16})
(st: state_spec a m)
: state_spec a m | val shuffle_inner
(#a: sha2_alg)
(#m: m_spec)
(ws: ws_spec a m)
(i: nat{i < v (num_rounds16 a)})
(j: nat{j < 16})
(st: state_spec a m)
: state_spec a m | let shuffle_inner (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (i:nat{i < v (num_rounds16 a)}) (j:nat{j < 16}) (st:state_spec a m) : state_spec a m =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec k_t ws_t st | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 31,
"end_line": 257,
"start_col": 0,
"start_line": 254
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (ws:ws_spec a m) : ws_spec a m =
match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws
noextract
let load_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) : ws_spec a m =
let ws = load_blocks #a #m b in
transpose_ws #a #m ws
noextract
let ws_next_inner (#a:sha2_alg) (#m:m_spec)
(i:nat{i < 16})
(ws:ws_spec a m) : ws_spec a m =
let t16 = ws.[i] in
let t15 = ws.[(i+1) % 16] in
let t7 = ws.[(i+9) % 16] in
let t2 = ws.[(i+14) % 16] in
let s1 = _sigma1 t2 in
let s0 = _sigma0 t15 in
ws.[i] <- (s1 +| t7 +| s0 +| t16)
noextract
let ws_next (#a:sha2_alg) (#m:m_spec)
(ws:ws_spec a m) : ws_spec a m =
repeati 16 (ws_next_inner #a #m) ws | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ws: Hacl.Spec.SHA2.Vec.ws_spec a m ->
i: Prims.nat{i < Lib.IntTypes.v (Hacl.Spec.SHA2.Vec.num_rounds16 a)} ->
j: Prims.nat{j < 16} ->
st: Hacl.Spec.SHA2.Vec.state_spec a m
-> Hacl.Spec.SHA2.Vec.state_spec a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.ws_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Spec.SHA2.Vec.num_rounds16",
"Hacl.Spec.SHA2.Vec.state_spec",
"Hacl.Spec.SHA2.Vec.shuffle_core_spec",
"Hacl.Spec.SHA2.Vec.element_t",
"Prims.eq2",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Lib.Sequence.op_String_Access",
"Spec.Hash.Definitions.word",
"Hacl.Spec.SHA2.k0",
"Prims.op_Addition",
"FStar.Mul.op_Star"
] | [] | false | false | false | false | false | let shuffle_inner
(#a: sha2_alg)
(#m: m_spec)
(ws: ws_spec a m)
(i: nat{i < v (num_rounds16 a)})
(j: nat{j < 16})
(st: state_spec a m)
: state_spec a m =
| let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[ j ] in
shuffle_core_spec k_t ws_t st | false |
FStar.Reflection.V1.Derived.Lemmas.fst | FStar.Reflection.V1.Derived.Lemmas.collect_abs_ln_ref | val collect_abs_ln_ref : (t:term) -> list (bd:binder{bd << t}) * (body:term{body == t \/ body << t}) | val collect_abs_ln_ref : (t:term) -> list (bd:binder{bd << t}) * (body:term{body == t \/ body << t}) | let collect_abs_ln_ref t =
let bds, body = collect_abs_ln t in
collect_abs_ln_order t;
list_ref bds, body | {
"file_name": "ulib/FStar.Reflection.V1.Derived.Lemmas.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 22,
"end_line": 97,
"start_col": 0,
"start_line": 94
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.V1.Derived.Lemmas
open FStar.Stubs.Reflection.Types
open FStar.Stubs.Reflection.V1.Builtins
open FStar.Stubs.Reflection.V1.Data
open FStar.Reflection.V1.Derived
open FStar.List.Tot
let rec forall_list (p:'a -> Type) (l:list 'a) : Type =
match l with
| [] -> True
| x::xs -> p x /\ forall_list p xs
let forallP (p: 'a -> Type) (l: list 'a): Type
= forall (x: 'a). memP x l ==> p x
// Precedence relation on the element of a list
unfold let (<<:) (l: list 'a) (r: 'r)
= forallP (fun x -> x << r) l
// A glorified `id`
val list_ref : (#a:Type) -> (#p:(a -> Type)) -> (l:list a) ->
Pure (list (x:a{p x}))
(requires (forallP p l))
(ensures (fun _ -> True))
let rec list_ref #a #p l =
match l with
| [] -> []
| x::xs -> x :: list_ref #a #p xs
val collect_app_order' : (args:list argv) -> (tt:term) -> (t:term) ->
Lemma (requires args <<: tt /\ t << tt)
(ensures (let fn, args' = collect_app_ln' args t in
args' <<: tt /\ fn << tt))
(decreases t)
let rec collect_app_order' args tt t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' (r::args) tt l
| _ -> ()
val collect_app_order : (t:term) ->
Lemma (ensures (forall (f:term). forall (s:list argv). (f,s) == collect_app_ln t ==>
(f << t /\ s <<: t)
\/ (f == t /\ s == [])))
let collect_app_order t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' [r] t l
| _ -> ()
val collect_app_ref : (t:term) -> (h:term{h == t \/ h << t}) * list (a:argv{fst a << t})
let collect_app_ref t =
let h, a = collect_app_ln t in
collect_app_order t;
h, list_ref a
(**** [collect_abs_ln t] is smaller than [t] *)
let rec collect_abs_order' (bds: binders) (tt t: term)
: Lemma (requires t << tt /\ bds <<: tt)
(ensures (let bds', body = collect_abs' bds t in
(bds' <<: tt /\ body << tt)))
(decreases t)
= match inspect_ln_unascribe t with
| Tv_Abs b body -> collect_abs_order' (b::bds) tt body
| _ -> ()
val collect_abs_ln_order : (t:term) ->
Lemma (ensures forall bds body.
(bds, body) == collect_abs_ln t ==>
(body << t /\ bds <<: t)
\/ (body == t /\ bds == [])
)
let collect_abs_ln_order t =
match inspect_ln_unascribe t with
| Tv_Abs b body -> collect_abs_order' [b] t body;
let bds, body = collect_abs' [] t in
Classical.forall_intro (rev_memP bds)
| _ -> () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Stubs.Reflection.V1.Data.fsti.checked",
"FStar.Stubs.Reflection.V1.Builtins.fsti.checked",
"FStar.Stubs.Reflection.Types.fsti.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V1.Derived.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: FStar.Stubs.Reflection.Types.term
-> Prims.list (bd: FStar.Stubs.Reflection.Types.binder{bd << t}) *
body:
FStar.Stubs.Reflection.Types.term{body == t \/ body << t} | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.term",
"Prims.list",
"FStar.Stubs.Reflection.Types.binder",
"FStar.Pervasives.Native.Mktuple2",
"Prims.precedes",
"Prims.l_or",
"Prims.eq2",
"FStar.Reflection.V1.Derived.Lemmas.list_ref",
"Prims.unit",
"FStar.Reflection.V1.Derived.Lemmas.collect_abs_ln_order",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.V1.Derived.collect_abs_ln"
] | [] | false | false | false | false | false | let collect_abs_ln_ref t =
| let bds, body = collect_abs_ln t in
collect_abs_ln_order t;
list_ref bds, body | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.init | val init (a: sha2_alg) (m: m_spec) : state_spec a m | val init (a: sha2_alg) (m: m_spec) : state_spec a m | let init (a:sha2_alg) (m:m_spec) : state_spec a m =
createi 8 (fun i -> load_element a m (Seq.index (Spec.h0 a) i)) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 65,
"end_line": 274,
"start_col": 0,
"start_line": 273
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (ws:ws_spec a m) : ws_spec a m =
match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws
noextract
let load_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) : ws_spec a m =
let ws = load_blocks #a #m b in
transpose_ws #a #m ws
noextract
let ws_next_inner (#a:sha2_alg) (#m:m_spec)
(i:nat{i < 16})
(ws:ws_spec a m) : ws_spec a m =
let t16 = ws.[i] in
let t15 = ws.[(i+1) % 16] in
let t7 = ws.[(i+9) % 16] in
let t2 = ws.[(i+14) % 16] in
let s1 = _sigma1 t2 in
let s0 = _sigma0 t15 in
ws.[i] <- (s1 +| t7 +| s0 +| t16)
noextract
let ws_next (#a:sha2_alg) (#m:m_spec)
(ws:ws_spec a m) : ws_spec a m =
repeati 16 (ws_next_inner #a #m) ws
noextract
let shuffle_inner (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (i:nat{i < v (num_rounds16 a)}) (j:nat{j < 16}) (st:state_spec a m) : state_spec a m =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec k_t ws_t st
noextract
let shuffle_inner_loop (#a:sha2_alg) (#m:m_spec) (i:nat{i < v (num_rounds16 a)})
(ws_st:ws_spec a m & state_spec a m) : ws_spec a m & state_spec a m =
let (ws,st) = ws_st in
let st' = repeati 16 (shuffle_inner ws i) st in
let ws' = if i < v (num_rounds16 a) - 1 then ws_next ws else ws in
(ws',st')
noextract
let shuffle (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (st:state_spec a m) : state_spec a m =
let (ws,st) = repeati (v(num_rounds16 a)) (shuffle_inner_loop #a #m) (ws,st) in
st | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec
-> Hacl.Spec.SHA2.Vec.state_spec a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Lib.Sequence.createi",
"Hacl.Spec.SHA2.Vec.element_t",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.load_element",
"FStar.Seq.Base.index",
"Spec.Hash.Definitions.word",
"Hacl.Spec.SHA2.h0",
"Hacl.Spec.SHA2.Vec.state_spec"
] | [] | false | false | false | false | false | let init (a: sha2_alg) (m: m_spec) : state_spec a m =
| createi 8 (fun i -> load_element a m (Seq.index (Spec.h0 a) i)) | false |
FStar.Reflection.V1.Derived.Lemmas.fst | FStar.Reflection.V1.Derived.Lemmas.collect_abs_ln_order | val collect_abs_ln_order : (t:term) ->
Lemma (ensures forall bds body.
(bds, body) == collect_abs_ln t ==>
(body << t /\ bds <<: t)
\/ (body == t /\ bds == [])
) | val collect_abs_ln_order : (t:term) ->
Lemma (ensures forall bds body.
(bds, body) == collect_abs_ln t ==>
(body << t /\ bds <<: t)
\/ (body == t /\ bds == [])
) | let collect_abs_ln_order t =
match inspect_ln_unascribe t with
| Tv_Abs b body -> collect_abs_order' [b] t body;
let bds, body = collect_abs' [] t in
Classical.forall_intro (rev_memP bds)
| _ -> () | {
"file_name": "ulib/FStar.Reflection.V1.Derived.Lemmas.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 13,
"end_line": 91,
"start_col": 0,
"start_line": 86
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.V1.Derived.Lemmas
open FStar.Stubs.Reflection.Types
open FStar.Stubs.Reflection.V1.Builtins
open FStar.Stubs.Reflection.V1.Data
open FStar.Reflection.V1.Derived
open FStar.List.Tot
let rec forall_list (p:'a -> Type) (l:list 'a) : Type =
match l with
| [] -> True
| x::xs -> p x /\ forall_list p xs
let forallP (p: 'a -> Type) (l: list 'a): Type
= forall (x: 'a). memP x l ==> p x
// Precedence relation on the element of a list
unfold let (<<:) (l: list 'a) (r: 'r)
= forallP (fun x -> x << r) l
// A glorified `id`
val list_ref : (#a:Type) -> (#p:(a -> Type)) -> (l:list a) ->
Pure (list (x:a{p x}))
(requires (forallP p l))
(ensures (fun _ -> True))
let rec list_ref #a #p l =
match l with
| [] -> []
| x::xs -> x :: list_ref #a #p xs
val collect_app_order' : (args:list argv) -> (tt:term) -> (t:term) ->
Lemma (requires args <<: tt /\ t << tt)
(ensures (let fn, args' = collect_app_ln' args t in
args' <<: tt /\ fn << tt))
(decreases t)
let rec collect_app_order' args tt t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' (r::args) tt l
| _ -> ()
val collect_app_order : (t:term) ->
Lemma (ensures (forall (f:term). forall (s:list argv). (f,s) == collect_app_ln t ==>
(f << t /\ s <<: t)
\/ (f == t /\ s == [])))
let collect_app_order t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' [r] t l
| _ -> ()
val collect_app_ref : (t:term) -> (h:term{h == t \/ h << t}) * list (a:argv{fst a << t})
let collect_app_ref t =
let h, a = collect_app_ln t in
collect_app_order t;
h, list_ref a
(**** [collect_abs_ln t] is smaller than [t] *)
let rec collect_abs_order' (bds: binders) (tt t: term)
: Lemma (requires t << tt /\ bds <<: tt)
(ensures (let bds', body = collect_abs' bds t in
(bds' <<: tt /\ body << tt)))
(decreases t)
= match inspect_ln_unascribe t with
| Tv_Abs b body -> collect_abs_order' (b::bds) tt body
| _ -> ()
val collect_abs_ln_order : (t:term) ->
Lemma (ensures forall bds body.
(bds, body) == collect_abs_ln t ==>
(body << t /\ bds <<: t)
\/ (body == t /\ bds == []) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Stubs.Reflection.V1.Data.fsti.checked",
"FStar.Stubs.Reflection.V1.Builtins.fsti.checked",
"FStar.Stubs.Reflection.Types.fsti.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V1.Derived.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: FStar.Stubs.Reflection.Types.term
-> FStar.Pervasives.Lemma
(ensures
forall (bds: Prims.list FStar.Stubs.Reflection.Types.binder)
(body: FStar.Stubs.Reflection.Types.term).
(bds, body) == FStar.Reflection.V1.Derived.collect_abs_ln t ==>
body << t /\ bds <<: t \/ body == t /\ bds == []) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Stubs.Reflection.Types.term",
"FStar.Reflection.V1.Derived.inspect_ln_unascribe",
"FStar.Stubs.Reflection.Types.binder",
"Prims.list",
"FStar.Classical.forall_intro",
"Prims.l_iff",
"FStar.List.Tot.Base.memP",
"FStar.List.Tot.Base.rev",
"FStar.List.Tot.Properties.rev_memP",
"Prims.unit",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.V1.Derived.collect_abs'",
"Prims.Nil",
"FStar.Reflection.V1.Derived.Lemmas.collect_abs_order'",
"Prims.Cons",
"FStar.Stubs.Reflection.V1.Data.term_view"
] | [] | false | false | true | false | false | let collect_abs_ln_order t =
| match inspect_ln_unascribe t with
| Tv_Abs b body ->
collect_abs_order' [b] t body;
let bds, body = collect_abs' [] t in
Classical.forall_intro (rev_memP bds)
| _ -> () | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.get_wsi | val get_wsi (#a: sha2_alg) (#m: m_spec) (b: multiblock_spec a m) (i: nat{i < 16}) : element_t a m | val get_wsi (#a: sha2_alg) (#m: m_spec) (b: multiblock_spec a m) (i: nat{i < 16}) : element_t a m | let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 200,
"start_col": 0,
"start_line": 196
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a)) | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Hacl.Spec.SHA2.Vec.multiblock_spec a m -> i: Prims.nat{i < 16}
-> Hacl.Spec.SHA2.Vec.element_t a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.multiblock_spec",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.SHA2.Vec.load_elementi",
"Lib.NTuple.op_Lens_Access",
"FStar.Seq.Properties.lseq",
"Lib.IntTypes.uint8",
"Spec.Hash.Definitions.block_length",
"Hacl.Spec.SHA2.Vec.lanes",
"Prims.int",
"Prims.op_Division",
"Prims.op_Modulus",
"Hacl.Spec.SHA2.Vec.lanes_t",
"Hacl.Spec.SHA2.Vec.element_t"
] | [] | false | false | false | false | false | let get_wsi (#a: sha2_alg) (#m: m_spec) (b: multiblock_spec a m) (i: nat{i < 16}) : element_t a m =
| let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(| idx_i |) idx_j | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.update_block | val update_block
(#a: sha2_alg)
(#m: m_spec{is_supported a m})
(len: Spec.len_lt_max_a_t a)
(b: multiseq (lanes a m) len)
(i: nat{i < len / block_length a})
(st: state_spec a m)
: state_spec a m | val update_block
(#a: sha2_alg)
(#m: m_spec{is_supported a m})
(len: Spec.len_lt_max_a_t a)
(b: multiseq (lanes a m) len)
(i: nat{i < len / block_length a})
(st: state_spec a m)
: state_spec a m | let update_block (#a:sha2_alg) (#m:m_spec{is_supported a m}) (len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len)
(i:nat{i < len / block_length a}) (st:state_spec a m) : state_spec a m =
let mb = get_multiblock_spec len b i in
update mb st | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 14,
"end_line": 456,
"start_col": 0,
"start_line": 453
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (ws:ws_spec a m) : ws_spec a m =
match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws
noextract
let load_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) : ws_spec a m =
let ws = load_blocks #a #m b in
transpose_ws #a #m ws
noextract
let ws_next_inner (#a:sha2_alg) (#m:m_spec)
(i:nat{i < 16})
(ws:ws_spec a m) : ws_spec a m =
let t16 = ws.[i] in
let t15 = ws.[(i+1) % 16] in
let t7 = ws.[(i+9) % 16] in
let t2 = ws.[(i+14) % 16] in
let s1 = _sigma1 t2 in
let s0 = _sigma0 t15 in
ws.[i] <- (s1 +| t7 +| s0 +| t16)
noextract
let ws_next (#a:sha2_alg) (#m:m_spec)
(ws:ws_spec a m) : ws_spec a m =
repeati 16 (ws_next_inner #a #m) ws
noextract
let shuffle_inner (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (i:nat{i < v (num_rounds16 a)}) (j:nat{j < 16}) (st:state_spec a m) : state_spec a m =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec k_t ws_t st
noextract
let shuffle_inner_loop (#a:sha2_alg) (#m:m_spec) (i:nat{i < v (num_rounds16 a)})
(ws_st:ws_spec a m & state_spec a m) : ws_spec a m & state_spec a m =
let (ws,st) = ws_st in
let st' = repeati 16 (shuffle_inner ws i) st in
let ws' = if i < v (num_rounds16 a) - 1 then ws_next ws else ws in
(ws',st')
noextract
let shuffle (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (st:state_spec a m) : state_spec a m =
let (ws,st) = repeati (v(num_rounds16 a)) (shuffle_inner_loop #a #m) (ws,st) in
st
noextract
let init (a:sha2_alg) (m:m_spec) : state_spec a m =
createi 8 (fun i -> load_element a m (Seq.index (Spec.h0 a) i))
[@"opaque_to_smt"]
noextract
let update (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) (st:state_spec a m): state_spec a m =
let st_old = st in
let ws = load_ws b in
let st_new = shuffle ws st_old in
map2 (+|) st_new st_old
noextract
let padded_blocks (a:sha2_alg) (len:nat{len <= block_length a}) : n:nat{n <= 2} =
if (len + len_length a + 1 <= block_length a) then 1 else 2
noextract
let load_last_blocks (#a:sha2_alg)
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a})
(b:lseq uint8 len) :
lseq uint8 (block_length a) & lseq uint8 (block_length a) =
let last = create (2 * block_length a) (u8 0) in
let last = update_sub last 0 len b in
let last = last.[len] <- u8 0x80 in
let last = update_sub last (fin - len_length a) (len_length a) totlen_seq in
let l0 : lseq uint8 (block_length a) = sub last 0 (block_length a) in
let l1 : lseq uint8 (block_length a) = sub last (block_length a) (block_length a) in
(l0, l1)
noextract
let load_last1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b = b.(|0|) in
let (l0,l1) = load_last_blocks #a totlen_seq fin len b in
let lb0 : multiseq (lanes a m) (block_length a) = ntup1 l0 in
let lb1 : multiseq (lanes a m) (block_length a) = ntup1 l1 in
(lb0, lb1)
#push-options "--z3rlimit 100"
noextract
let load_last4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let mb0 = ntup4 (l00, (l10, (l20, l30))) in
let mb1 = ntup4 (l01, (l11, (l21, l31))) in
(mb0, mb1)
noextract
let load_last8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let b4 = b.(|4|) in
let b5 = b.(|5|) in
let b6 = b.(|6|) in
let b7 = b.(|7|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let (l40,l41) = load_last_blocks #a totlen_seq fin len b4 in
let (l50,l51) = load_last_blocks #a totlen_seq fin len b5 in
let (l60,l61) = load_last_blocks #a totlen_seq fin len b6 in
let (l70,l71) = load_last_blocks #a totlen_seq fin len b7 in
let mb0 = ntup8 (l00, (l10, (l20, (l30, (l40, (l50, (l60, l70))))))) in
let mb1 = ntup8 (l01, (l11, (l21, (l31, (l41, (l51, (l61, l71))))))) in
(mb0, mb1)
#pop-options
[@"opaque_to_smt"]
noextract
let load_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
match lanes a m with
| 1 -> load_last1 #a #m totlen_seq fin len b
| 4 -> load_last4 #a #m totlen_seq fin len b
| 8 -> load_last8 #a #m totlen_seq fin len b
noextract
let update_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen:len_t a)
(len:nat{len <= block_length a})
(b:multiseq (lanes a m) len) (st:state_spec a m): state_spec a m =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
let st = update b0 st in
if blocks > 1 then
update b1 st
else st
noextract
let transpose_state4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(st:state_spec a m) : state_spec a m =
let st0 = st.[0] in
let st1 = st.[1] in
let st2 = st.[2] in
let st3 = st.[3] in
let st4 = st.[4] in
let st5 = st.[5] in
let st6 = st.[6] in
let st7 = st.[7] in
let (st0,st1,st2,st3) = VecTranspose.transpose4x4 (st0,st1,st2,st3) in
let (st4,st5,st6,st7) = VecTranspose.transpose4x4 (st4,st5,st6,st7) in
create8 st0 st4 st1 st5 st2 st6 st3 st7
noextract
let transpose_state8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8})
(st:state_spec a m) : state_spec a m =
let st0 = st.[0] in
let st1 = st.[1] in
let st2 = st.[2] in
let st3 = st.[3] in
let st4 = st.[4] in
let st5 = st.[5] in
let st6 = st.[6] in
let st7 = st.[7] in
let (st0,st1,st2,st3,st4,st5,st6,st7) = VecTranspose.transpose8x8 (st0,st1,st2,st3,st4,st5,st6,st7) in
create8 st0 st1 st2 st3 st4 st5 st6 st7
noextract
let transpose_state (#a:sha2_alg) (#m:m_spec{is_supported a m}) (st:state_spec a m) : state_spec a m =
match lanes a m with
| 1 -> st
| 4 -> transpose_state4 #a #m st
| 8 -> transpose_state8 #a #m st
noextract
let store_state (#a:sha2_alg) (#m:m_spec{is_supported a m}) (st:state_spec a m) :
lseq uint8 (lanes a m * 8 * word_length a) =
let st = transpose_state st in
Lib.IntVector.Serialize.vecs_to_bytes_be st
noextract
let emit (#a:sha2_alg) (#m:m_spec)
(hseq:lseq uint8 (lanes a m * 8 * word_length a)):
multiseq (lanes a m) (hash_length a) =
Lib.NTuple.createi #(Seq.lseq uint8 (hash_length a)) (lanes a m)
(fun i -> sub hseq (i * 8 * word_length a) (hash_length a))
noextract
let get_multiblock_spec (#a:sha2_alg) (#m:m_spec)
(len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len)
(i:nat{i < len / block_length a})
: multiseq (lanes a m) (block_length a) =
Lib.NTuple.createi #(Seq.lseq uint8 (block_length a)) (lanes a m)
(fun j -> Seq.slice b.(|j|) (i * block_length a) (i * block_length a + block_length a))
noextract
let get_multilast_spec (#a:sha2_alg) (#m:m_spec)
(len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len)
: multiseq (lanes a m) (len % block_length a) =
let rem = len % block_length a in
Lib.NTuple.createi #(Seq.lseq uint8 rem) (lanes a m)
(fun j -> Seq.slice b.(|j|) (len - rem) len) | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Hacl.Spec.SHA2.len_lt_max_a_t a ->
b: Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m) len ->
i: Prims.nat{i < len / Spec.Hash.Definitions.block_length a} ->
st: Hacl.Spec.SHA2.Vec.state_spec a m
-> Hacl.Spec.SHA2.Vec.state_spec a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Hacl.Spec.SHA2.len_lt_max_a_t",
"Hacl.Spec.SHA2.Vec.multiseq",
"Hacl.Spec.SHA2.Vec.lanes",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Division",
"Spec.Hash.Definitions.block_length",
"Hacl.Spec.SHA2.Vec.state_spec",
"Hacl.Spec.SHA2.Vec.update",
"Hacl.Spec.SHA2.Vec.get_multiblock_spec"
] | [] | false | false | false | false | false | let update_block
(#a: sha2_alg)
(#m: m_spec{is_supported a m})
(len: Spec.len_lt_max_a_t a)
(b: multiseq (lanes a m) len)
(i: nat{i < len / block_length a})
(st: state_spec a m)
: state_spec a m =
| let mb = get_multiblock_spec len b i in
update mb st | false |
FStar.Reflection.V1.Derived.Lemmas.fst | FStar.Reflection.V1.Derived.Lemmas.collect_arr_order' | val collect_arr_order' (bds: binders) (tt: term) (c: comp)
: Lemma (requires c << tt /\ bds <<: tt)
(ensures
(let bds', c' = collect_arr' bds c in
bds' <<: tt /\ c' << tt))
(decreases c) | val collect_arr_order' (bds: binders) (tt: term) (c: comp)
: Lemma (requires c << tt /\ bds <<: tt)
(ensures
(let bds', c' = collect_arr' bds c in
bds' <<: tt /\ c' << tt))
(decreases c) | let rec collect_arr_order' (bds: binders) (tt: term) (c: comp)
: Lemma (requires c << tt /\ bds <<: tt)
(ensures (let bds', c' = collect_arr' bds c in
bds' <<: tt /\ c' << tt))
(decreases c)
= match inspect_comp c with
| C_Total ret ->
( match inspect_ln_unascribe ret with
| Tv_Arrow b c -> collect_arr_order' (b::bds) tt c
| _ -> ())
| _ -> () | {
"file_name": "ulib/FStar.Reflection.V1.Derived.Lemmas.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 13,
"end_line": 112,
"start_col": 0,
"start_line": 102
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.V1.Derived.Lemmas
open FStar.Stubs.Reflection.Types
open FStar.Stubs.Reflection.V1.Builtins
open FStar.Stubs.Reflection.V1.Data
open FStar.Reflection.V1.Derived
open FStar.List.Tot
let rec forall_list (p:'a -> Type) (l:list 'a) : Type =
match l with
| [] -> True
| x::xs -> p x /\ forall_list p xs
let forallP (p: 'a -> Type) (l: list 'a): Type
= forall (x: 'a). memP x l ==> p x
// Precedence relation on the element of a list
unfold let (<<:) (l: list 'a) (r: 'r)
= forallP (fun x -> x << r) l
// A glorified `id`
val list_ref : (#a:Type) -> (#p:(a -> Type)) -> (l:list a) ->
Pure (list (x:a{p x}))
(requires (forallP p l))
(ensures (fun _ -> True))
let rec list_ref #a #p l =
match l with
| [] -> []
| x::xs -> x :: list_ref #a #p xs
val collect_app_order' : (args:list argv) -> (tt:term) -> (t:term) ->
Lemma (requires args <<: tt /\ t << tt)
(ensures (let fn, args' = collect_app_ln' args t in
args' <<: tt /\ fn << tt))
(decreases t)
let rec collect_app_order' args tt t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' (r::args) tt l
| _ -> ()
val collect_app_order : (t:term) ->
Lemma (ensures (forall (f:term). forall (s:list argv). (f,s) == collect_app_ln t ==>
(f << t /\ s <<: t)
\/ (f == t /\ s == [])))
let collect_app_order t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' [r] t l
| _ -> ()
val collect_app_ref : (t:term) -> (h:term{h == t \/ h << t}) * list (a:argv{fst a << t})
let collect_app_ref t =
let h, a = collect_app_ln t in
collect_app_order t;
h, list_ref a
(**** [collect_abs_ln t] is smaller than [t] *)
let rec collect_abs_order' (bds: binders) (tt t: term)
: Lemma (requires t << tt /\ bds <<: tt)
(ensures (let bds', body = collect_abs' bds t in
(bds' <<: tt /\ body << tt)))
(decreases t)
= match inspect_ln_unascribe t with
| Tv_Abs b body -> collect_abs_order' (b::bds) tt body
| _ -> ()
val collect_abs_ln_order : (t:term) ->
Lemma (ensures forall bds body.
(bds, body) == collect_abs_ln t ==>
(body << t /\ bds <<: t)
\/ (body == t /\ bds == [])
)
let collect_abs_ln_order t =
match inspect_ln_unascribe t with
| Tv_Abs b body -> collect_abs_order' [b] t body;
let bds, body = collect_abs' [] t in
Classical.forall_intro (rev_memP bds)
| _ -> ()
val collect_abs_ln_ref : (t:term) -> list (bd:binder{bd << t}) * (body:term{body == t \/ body << t})
let collect_abs_ln_ref t =
let bds, body = collect_abs_ln t in
collect_abs_ln_order t;
list_ref bds, body | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Stubs.Reflection.V1.Data.fsti.checked",
"FStar.Stubs.Reflection.V1.Builtins.fsti.checked",
"FStar.Stubs.Reflection.Types.fsti.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V1.Derived.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
bds: FStar.Stubs.Reflection.Types.binders ->
tt: FStar.Stubs.Reflection.Types.term ->
c: FStar.Stubs.Reflection.Types.comp
-> FStar.Pervasives.Lemma (requires c << tt /\ bds <<: tt)
(ensures
(let _ = FStar.Reflection.V1.Derived.collect_arr' bds c in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ bds' c' = _ in
bds' <<: tt /\ c' << tt)
<:
Type0))
(decreases c) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"FStar.Stubs.Reflection.Types.binders",
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.Types.comp",
"FStar.Stubs.Reflection.V1.Builtins.inspect_comp",
"FStar.Stubs.Reflection.Types.typ",
"FStar.Reflection.V1.Derived.inspect_ln_unascribe",
"FStar.Stubs.Reflection.Types.binder",
"FStar.Reflection.V1.Derived.Lemmas.collect_arr_order'",
"Prims.Cons",
"FStar.Stubs.Reflection.V1.Data.term_view",
"Prims.unit",
"FStar.Stubs.Reflection.V1.Data.comp_view",
"Prims.l_and",
"Prims.precedes",
"FStar.Reflection.V1.Derived.Lemmas.op_Less_Less_Colon",
"Prims.squash",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.V1.Derived.collect_arr'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec collect_arr_order' (bds: binders) (tt: term) (c: comp)
: Lemma (requires c << tt /\ bds <<: tt)
(ensures
(let bds', c' = collect_arr' bds c in
bds' <<: tt /\ c' << tt))
(decreases c) =
| match inspect_comp c with
| C_Total ret ->
(match inspect_ln_unascribe ret with
| Tv_Arrow b c -> collect_arr_order' (b :: bds) tt c
| _ -> ())
| _ -> () | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.update_last | val update_last
(#a: sha2_alg)
(#m: m_spec{is_supported a m})
(totlen: len_t a)
(len: nat{len <= block_length a})
(b: multiseq (lanes a m) len)
(st: state_spec a m)
: state_spec a m | val update_last
(#a: sha2_alg)
(#m: m_spec{is_supported a m})
(totlen: len_t a)
(len: nat{len <= block_length a})
(b: multiseq (lanes a m) len)
(st: state_spec a m)
: state_spec a m | let update_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen:len_t a)
(len:nat{len <= block_length a})
(b:multiseq (lanes a m) len) (st:state_spec a m): state_spec a m =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
let st = update b0 st in
if blocks > 1 then
update b1 st
else st | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 9,
"end_line": 384,
"start_col": 0,
"start_line": 373
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (ws:ws_spec a m) : ws_spec a m =
match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws
noextract
let load_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) : ws_spec a m =
let ws = load_blocks #a #m b in
transpose_ws #a #m ws
noextract
let ws_next_inner (#a:sha2_alg) (#m:m_spec)
(i:nat{i < 16})
(ws:ws_spec a m) : ws_spec a m =
let t16 = ws.[i] in
let t15 = ws.[(i+1) % 16] in
let t7 = ws.[(i+9) % 16] in
let t2 = ws.[(i+14) % 16] in
let s1 = _sigma1 t2 in
let s0 = _sigma0 t15 in
ws.[i] <- (s1 +| t7 +| s0 +| t16)
noextract
let ws_next (#a:sha2_alg) (#m:m_spec)
(ws:ws_spec a m) : ws_spec a m =
repeati 16 (ws_next_inner #a #m) ws
noextract
let shuffle_inner (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (i:nat{i < v (num_rounds16 a)}) (j:nat{j < 16}) (st:state_spec a m) : state_spec a m =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec k_t ws_t st
noextract
let shuffle_inner_loop (#a:sha2_alg) (#m:m_spec) (i:nat{i < v (num_rounds16 a)})
(ws_st:ws_spec a m & state_spec a m) : ws_spec a m & state_spec a m =
let (ws,st) = ws_st in
let st' = repeati 16 (shuffle_inner ws i) st in
let ws' = if i < v (num_rounds16 a) - 1 then ws_next ws else ws in
(ws',st')
noextract
let shuffle (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (st:state_spec a m) : state_spec a m =
let (ws,st) = repeati (v(num_rounds16 a)) (shuffle_inner_loop #a #m) (ws,st) in
st
noextract
let init (a:sha2_alg) (m:m_spec) : state_spec a m =
createi 8 (fun i -> load_element a m (Seq.index (Spec.h0 a) i))
[@"opaque_to_smt"]
noextract
let update (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) (st:state_spec a m): state_spec a m =
let st_old = st in
let ws = load_ws b in
let st_new = shuffle ws st_old in
map2 (+|) st_new st_old
noextract
let padded_blocks (a:sha2_alg) (len:nat{len <= block_length a}) : n:nat{n <= 2} =
if (len + len_length a + 1 <= block_length a) then 1 else 2
noextract
let load_last_blocks (#a:sha2_alg)
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a})
(b:lseq uint8 len) :
lseq uint8 (block_length a) & lseq uint8 (block_length a) =
let last = create (2 * block_length a) (u8 0) in
let last = update_sub last 0 len b in
let last = last.[len] <- u8 0x80 in
let last = update_sub last (fin - len_length a) (len_length a) totlen_seq in
let l0 : lseq uint8 (block_length a) = sub last 0 (block_length a) in
let l1 : lseq uint8 (block_length a) = sub last (block_length a) (block_length a) in
(l0, l1)
noextract
let load_last1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b = b.(|0|) in
let (l0,l1) = load_last_blocks #a totlen_seq fin len b in
let lb0 : multiseq (lanes a m) (block_length a) = ntup1 l0 in
let lb1 : multiseq (lanes a m) (block_length a) = ntup1 l1 in
(lb0, lb1)
#push-options "--z3rlimit 100"
noextract
let load_last4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let mb0 = ntup4 (l00, (l10, (l20, l30))) in
let mb1 = ntup4 (l01, (l11, (l21, l31))) in
(mb0, mb1)
noextract
let load_last8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let b4 = b.(|4|) in
let b5 = b.(|5|) in
let b6 = b.(|6|) in
let b7 = b.(|7|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let (l40,l41) = load_last_blocks #a totlen_seq fin len b4 in
let (l50,l51) = load_last_blocks #a totlen_seq fin len b5 in
let (l60,l61) = load_last_blocks #a totlen_seq fin len b6 in
let (l70,l71) = load_last_blocks #a totlen_seq fin len b7 in
let mb0 = ntup8 (l00, (l10, (l20, (l30, (l40, (l50, (l60, l70))))))) in
let mb1 = ntup8 (l01, (l11, (l21, (l31, (l41, (l51, (l61, l71))))))) in
(mb0, mb1)
#pop-options
[@"opaque_to_smt"]
noextract
let load_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
match lanes a m with
| 1 -> load_last1 #a #m totlen_seq fin len b
| 4 -> load_last4 #a #m totlen_seq fin len b
| 8 -> load_last8 #a #m totlen_seq fin len b | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
totlen: Spec.Hash.Definitions.len_t a ->
len: Prims.nat{len <= Spec.Hash.Definitions.block_length a} ->
b: Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m) len ->
st: Hacl.Spec.SHA2.Vec.state_spec a m
-> Hacl.Spec.SHA2.Vec.state_spec a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Spec.Hash.Definitions.len_t",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Spec.Hash.Definitions.block_length",
"Hacl.Spec.SHA2.Vec.multiseq",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Vec.state_spec",
"Prims.op_GreaterThan",
"Hacl.Spec.SHA2.Vec.update",
"Prims.bool",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.SHA2.Vec.load_last",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.IntTypes.numbytes",
"Spec.Hash.Definitions.len_int_type",
"Lib.ByteSequence.uint_to_bytes_be",
"Prims.eq2",
"Prims.int",
"Lib.IntTypes.range",
"Lib.IntTypes.v",
"Lib.IntTypes.PUB",
"Lib.IntTypes.shift_left",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.IntTypes.secret",
"FStar.UInt32.__uint_to_t",
"FStar.Mul.op_Star",
"Hacl.Spec.SHA2.Vec.padded_blocks"
] | [] | false | false | false | false | false | let update_last
(#a: sha2_alg)
(#m: m_spec{is_supported a m})
(totlen: len_t a)
(len: nat{len <= block_length a})
(b: multiseq (lanes a m) len)
(st: state_spec a m)
: state_spec a m =
| let blocks = padded_blocks a len in
let fin:nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let b0, b1 = load_last #a #m totlen_seq fin len b in
let st = update b0 st in
if blocks > 1 then update b1 st else st | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.transpose_ws4 | val transpose_ws4 (#a: sha2_alg) (#m: m_spec{lanes a m == 4}) (ws: ws_spec a m) : ws_spec a m | val transpose_ws4 (#a: sha2_alg) (#m: m_spec{lanes a m == 4}) (ws: ws_spec a m) : ws_spec a m | let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 82,
"end_line": 215,
"start_col": 0,
"start_line": 210
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ws: Hacl.Spec.SHA2.Vec.ws_spec a m -> Hacl.Spec.SHA2.Vec.ws_spec a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Prims.eq2",
"Prims.int",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Vec.ws_spec",
"Lib.IntVector.vec_t",
"Spec.Hash.Definitions.word_t",
"Lib.Sequence.create16",
"Hacl.Spec.SHA2.Vec.element_t",
"Lib.IntVector.Transpose.vec_t4",
"Lib.IntVector.Transpose.transpose4x4",
"FStar.Pervasives.Native.Mktuple4",
"Lib.Sequence.op_String_Access"
] | [] | false | false | false | false | false | let transpose_ws4 (#a: sha2_alg) (#m: m_spec{lanes a m == 4}) (ws: ws_spec a m) : ws_spec a m =
| let ws0, ws1, ws2, ws3 = VecTranspose.transpose4x4 (ws.[ 0 ], ws.[ 1 ], ws.[ 2 ], ws.[ 3 ]) in
let ws4, ws5, ws6, ws7 = VecTranspose.transpose4x4 (ws.[ 4 ], ws.[ 5 ], ws.[ 6 ], ws.[ 7 ]) in
let ws8, ws9, ws10, ws11 = VecTranspose.transpose4x4 (ws.[ 8 ], ws.[ 9 ], ws.[ 10 ], ws.[ 11 ]) in
let ws12, ws13, ws14, ws15 =
VecTranspose.transpose4x4 (ws.[ 12 ], ws.[ 13 ], ws.[ 14 ], ws.[ 15 ])
in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15 | false |
Spec.Frodo.KEM.KeyGen.fst | Spec.Frodo.KEM.KeyGen.crypto_kem_keypair | val crypto_kem_keypair:
a:frodo_alg
-> gen_a:frodo_gen_a
-> state:Spec.Frodo.Random.state_t
-> tuple2 (lbytes (crypto_publickeybytes a)) (lbytes (crypto_secretkeybytes a)) | val crypto_kem_keypair:
a:frodo_alg
-> gen_a:frodo_gen_a
-> state:Spec.Frodo.Random.state_t
-> tuple2 (lbytes (crypto_publickeybytes a)) (lbytes (crypto_secretkeybytes a)) | let crypto_kem_keypair a gen_a state =
let coins, _ = Spec.Frodo.Random.randombytes_ state (2 * crypto_bytes a + bytes_seed_a) in
crypto_kem_keypair_ a gen_a coins | {
"file_name": "specs/frodo/Spec.Frodo.KEM.KeyGen.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 130,
"start_col": 0,
"start_line": 128
} | module Spec.Frodo.KEM.KeyGen
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Matrix
open Spec.Frodo.Params
open Spec.Frodo.Pack
open Spec.Frodo.Sample
module LSeq = Lib.Sequence
module Matrix = Spec.Matrix
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val frodo_shake_r:
a:frodo_alg
-> c:uint8
-> seed_se:lbytes (crypto_bytes a)
-> output_len:size_nat
-> lbytes output_len
let frodo_shake_r a c seed_se output_len =
let tmp = LSeq.create 1 c in
let shake_input_seed_se = LSeq.concat tmp seed_se in
frodo_shake a (1 + crypto_bytes a) shake_input_seed_se output_len
val frodo_mul_add_as_plus_e:
a:frodo_alg
-> gen_a:frodo_gen_a
-> seed_a:lbytes bytes_seed_a
-> s_matrix:matrix (params_n a) params_nbar
-> e_matrix:matrix (params_n a) params_nbar
-> matrix (params_n a) params_nbar
let frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix =
params_n_sqr a;
let a_matrix = frodo_gen_matrix gen_a (params_n a) seed_a in
let b_matrix = Matrix.add (Matrix.mul_s a_matrix s_matrix) e_matrix in
b_matrix
val frodo_mul_add_as_plus_e_pack:
a:frodo_alg
-> gen_a:frodo_gen_a
-> seed_a:lbytes bytes_seed_a
-> s_matrix:matrix (params_n a) params_nbar
-> e_matrix:matrix (params_n a) params_nbar
-> lbytes (publicmatrixbytes_len a)
let frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix =
let b_matrix = frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix in
frodo_pack (params_logq a) b_matrix
val get_s_e_matrices:
a:frodo_alg
-> seed_se:lbytes (crypto_bytes a)
-> matrix (params_n a) params_nbar & matrix (params_n a) params_nbar
let get_s_e_matrices a seed_se =
let s_bytes_len = secretmatrixbytes_len a in
let r = frodo_shake_r a (u8 0x5f) seed_se (2 * s_bytes_len) in
let s_matrix = frodo_sample_matrix a (params_n a) params_nbar (LSeq.sub r 0 s_bytes_len) in
let e_matrix = frodo_sample_matrix a (params_n a) params_nbar (LSeq.sub r s_bytes_len s_bytes_len) in
s_matrix, e_matrix
val frodo_mul_add_as_plus_e_pack_shake:
a:frodo_alg
-> gen_a:frodo_gen_a
-> seed_a:lbytes bytes_seed_a
-> seed_se:lbytes (crypto_bytes a)
-> tuple2 (lbytes (publicmatrixbytes_len a)) (lbytes (secretmatrixbytes_len a))
let frodo_mul_add_as_plus_e_pack_shake a gen_a seed_a seed_se =
let s_matrix, e_matrix = get_s_e_matrices a seed_se in
let b_bytes = frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix in
let s_bytes = matrix_to_lbytes s_matrix in
b_bytes, s_bytes
val crypto_kem_sk:
a:frodo_alg
-> s:lbytes (crypto_bytes a)
-> pk:lbytes (crypto_publickeybytes a)
-> s_bytes:lbytes (secretmatrixbytes_len a)
-> lbytes (crypto_secretkeybytes a)
let crypto_kem_sk a s pk s_bytes =
let sk = concat (concat s pk) s_bytes in
let pkh = frodo_shake a (crypto_publickeybytes a) pk (bytes_pkhash a) in
let sk_pkh = concat sk pkh in
sk_pkh
val crypto_kem_keypair_:
a:frodo_alg
-> gen_a:frodo_gen_a
-> coins:lbytes (2 * crypto_bytes a + bytes_seed_a)
-> tuple2 (lbytes (crypto_publickeybytes a)) (lbytes (crypto_secretkeybytes a))
let crypto_kem_keypair_ a gen_a coins =
expand_crypto_publickeybytes a;
expand_crypto_secretkeybytes a;
let s = LSeq.sub coins 0 (crypto_bytes a) in
let seed_se = LSeq.sub coins (crypto_bytes a) (crypto_bytes a) in
let z = LSeq.sub coins (2 * crypto_bytes a) bytes_seed_a in
let seed_a = frodo_shake a bytes_seed_a z bytes_seed_a in
let b_bytes, s_bytes = frodo_mul_add_as_plus_e_pack_shake a gen_a seed_a seed_se in
let pk = concat seed_a b_bytes in
let sk = crypto_kem_sk a s pk s_bytes in
pk, sk
val crypto_kem_keypair:
a:frodo_alg
-> gen_a:frodo_gen_a
-> state:Spec.Frodo.Random.state_t
-> tuple2 (lbytes (crypto_publickeybytes a)) (lbytes (crypto_secretkeybytes a)) | {
"checked_file": "/",
"dependencies": [
"Spec.Matrix.fst.checked",
"Spec.Frodo.Sample.fst.checked",
"Spec.Frodo.Random.fst.checked",
"Spec.Frodo.Params.fst.checked",
"Spec.Frodo.Pack.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Frodo.KEM.KeyGen.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Matrix",
"short_module": "Matrix"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": false,
"full_module": "Spec.Frodo.Sample",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.Pack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.Params",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Frodo.Params.frodo_alg ->
gen_a: Spec.Frodo.Params.frodo_gen_a ->
state: Spec.Frodo.Random.state_t
-> Lib.ByteSequence.lbytes (Spec.Frodo.Params.crypto_publickeybytes a) *
Lib.ByteSequence.lbytes (Spec.Frodo.Params.crypto_secretkeybytes a) | Prims.Tot | [
"total"
] | [] | [
"Spec.Frodo.Params.frodo_alg",
"Spec.Frodo.Params.frodo_gen_a",
"Spec.Frodo.Random.state_t",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint8",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Spec.Frodo.Params.crypto_bytes",
"Spec.Frodo.Params.bytes_seed_a",
"Spec.Frodo.KEM.KeyGen.crypto_kem_keypair_",
"FStar.Pervasives.Native.tuple2",
"Lib.ByteSequence.lbytes",
"Spec.Frodo.Params.crypto_publickeybytes",
"Spec.Frodo.Params.crypto_secretkeybytes",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.op_Multiply",
"Spec.Frodo.Random.randombytes_"
] | [] | false | false | false | false | false | let crypto_kem_keypair a gen_a state =
| let coins, _ = Spec.Frodo.Random.randombytes_ state (2 * crypto_bytes a + bytes_seed_a) in
crypto_kem_keypair_ a gen_a coins | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.ws_spec_v | val ws_spec_v (#a: sha2_alg) (#m: m_spec) (st: ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) | val ws_spec_v (#a: sha2_alg) (#m: m_spec) (st: ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) | let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i]) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 86,
"end_line": 145,
"start_col": 0,
"start_line": 139
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]) | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | st: Hacl.Spec.SHA2.Vec.ws_spec a m
-> Lib.Sequence.lseq (Lib.Sequence.lseq (Hacl.Spec.SHA2.Vec.word a) 16)
(Hacl.Spec.SHA2.Vec.lanes a m) | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.ws_spec",
"Lib.Sequence.createi",
"Lib.Sequence.lseq",
"Hacl.Spec.SHA2.Vec.word",
"Hacl.Spec.SHA2.Vec.lanes",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.Sequence.create16",
"Lib.Sequence.op_String_Access",
"Lib.IntTypes.uint_t",
"Spec.Hash.Definitions.word_t",
"Lib.IntTypes.SEC",
"Lib.IntVector.vec_v",
"Hacl.Spec.SHA2.Vec.element_t"
] | [] | false | false | false | false | false | let ws_spec_v (#a: sha2_alg) (#m: m_spec) (st: ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
| createi #(lseq (word a) 16)
(lanes a m)
(fun i ->
create16 (vec_v st.[ 0 ]).[ i ] (vec_v st.[ 1 ]).[ i ] (vec_v st.[ 2 ]).[ i ]
(vec_v st.[ 3 ]).[ i ] (vec_v st.[ 4 ]).[ i ] (vec_v st.[ 5 ]).[ i ] (vec_v st.[ 6 ]).[ i ]
(vec_v st.[ 7 ]).[ i ] (vec_v st.[ 8 ]).[ i ] (vec_v st.[ 9 ]).[ i ] (vec_v st.[ 10 ]).[ i ]
(vec_v st.[ 11 ]).[ i ] (vec_v st.[ 12 ]).[ i ] (vec_v st.[ 13 ]).[ i ]
(vec_v st.[ 14 ]).[ i ] (vec_v st.[ 15 ]).[ i ]) | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.transpose_ws8 | val transpose_ws8 (#a: sha2_alg) (#m: m_spec{lanes a m == 8}) (ws: ws_spec a m) : ws_spec a m | val transpose_ws8 (#a: sha2_alg) (#m: m_spec{lanes a m == 8}) (ws: ws_spec a m) : ws_spec a m | let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 82,
"end_line": 221,
"start_col": 0,
"start_line": 218
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15 | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ws: Hacl.Spec.SHA2.Vec.ws_spec a m -> Hacl.Spec.SHA2.Vec.ws_spec a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Prims.eq2",
"Prims.int",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Vec.ws_spec",
"Lib.IntVector.vec_t",
"Spec.Hash.Definitions.word_t",
"Lib.Sequence.create16",
"Hacl.Spec.SHA2.Vec.element_t",
"Lib.IntVector.Transpose.vec_t8",
"Lib.IntVector.Transpose.transpose8x8",
"FStar.Pervasives.Native.Mktuple8",
"Lib.Sequence.op_String_Access"
] | [] | false | false | false | false | false | let transpose_ws8 (#a: sha2_alg) (#m: m_spec{lanes a m == 8}) (ws: ws_spec a m) : ws_spec a m =
| let ws0, ws1, ws2, ws3, ws4, ws5, ws6, ws7 =
VecTranspose.transpose8x8 (ws.[ 0 ],
ws.[ 1 ],
ws.[ 2 ],
ws.[ 3 ],
ws.[ 4 ],
ws.[ 5 ],
ws.[ 6 ],
ws.[ 7 ])
in
let ws8, ws9, ws10, ws11, ws12, ws13, ws14, ws15 =
VecTranspose.transpose8x8 (ws.[ 8 ],
ws.[ 9 ],
ws.[ 10 ],
ws.[ 11 ],
ws.[ 12 ],
ws.[ 13 ],
ws.[ 14 ],
ws.[ 15 ])
in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15 | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.update_nblocks | val update_nblocks
(#a: sha2_alg)
(#m: m_spec{is_supported a m})
(len: Spec.len_lt_max_a_t a)
(b: multiseq (lanes a m) len)
(st: state_spec a m)
: state_spec a m | val update_nblocks
(#a: sha2_alg)
(#m: m_spec{is_supported a m})
(len: Spec.len_lt_max_a_t a)
(b: multiseq (lanes a m) len)
(st: state_spec a m)
: state_spec a m | let update_nblocks (#a:sha2_alg) (#m:m_spec{is_supported a m}) (len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len) (st:state_spec a m) : state_spec a m =
let blocks = len / block_length a in
let st = repeati blocks (update_block #a #m len b) st in
st | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 6,
"end_line": 462,
"start_col": 0,
"start_line": 459
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (ws:ws_spec a m) : ws_spec a m =
match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws
noextract
let load_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) : ws_spec a m =
let ws = load_blocks #a #m b in
transpose_ws #a #m ws
noextract
let ws_next_inner (#a:sha2_alg) (#m:m_spec)
(i:nat{i < 16})
(ws:ws_spec a m) : ws_spec a m =
let t16 = ws.[i] in
let t15 = ws.[(i+1) % 16] in
let t7 = ws.[(i+9) % 16] in
let t2 = ws.[(i+14) % 16] in
let s1 = _sigma1 t2 in
let s0 = _sigma0 t15 in
ws.[i] <- (s1 +| t7 +| s0 +| t16)
noextract
let ws_next (#a:sha2_alg) (#m:m_spec)
(ws:ws_spec a m) : ws_spec a m =
repeati 16 (ws_next_inner #a #m) ws
noextract
let shuffle_inner (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (i:nat{i < v (num_rounds16 a)}) (j:nat{j < 16}) (st:state_spec a m) : state_spec a m =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec k_t ws_t st
noextract
let shuffle_inner_loop (#a:sha2_alg) (#m:m_spec) (i:nat{i < v (num_rounds16 a)})
(ws_st:ws_spec a m & state_spec a m) : ws_spec a m & state_spec a m =
let (ws,st) = ws_st in
let st' = repeati 16 (shuffle_inner ws i) st in
let ws' = if i < v (num_rounds16 a) - 1 then ws_next ws else ws in
(ws',st')
noextract
let shuffle (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (st:state_spec a m) : state_spec a m =
let (ws,st) = repeati (v(num_rounds16 a)) (shuffle_inner_loop #a #m) (ws,st) in
st
noextract
let init (a:sha2_alg) (m:m_spec) : state_spec a m =
createi 8 (fun i -> load_element a m (Seq.index (Spec.h0 a) i))
[@"opaque_to_smt"]
noextract
let update (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) (st:state_spec a m): state_spec a m =
let st_old = st in
let ws = load_ws b in
let st_new = shuffle ws st_old in
map2 (+|) st_new st_old
noextract
let padded_blocks (a:sha2_alg) (len:nat{len <= block_length a}) : n:nat{n <= 2} =
if (len + len_length a + 1 <= block_length a) then 1 else 2
noextract
let load_last_blocks (#a:sha2_alg)
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a})
(b:lseq uint8 len) :
lseq uint8 (block_length a) & lseq uint8 (block_length a) =
let last = create (2 * block_length a) (u8 0) in
let last = update_sub last 0 len b in
let last = last.[len] <- u8 0x80 in
let last = update_sub last (fin - len_length a) (len_length a) totlen_seq in
let l0 : lseq uint8 (block_length a) = sub last 0 (block_length a) in
let l1 : lseq uint8 (block_length a) = sub last (block_length a) (block_length a) in
(l0, l1)
noextract
let load_last1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b = b.(|0|) in
let (l0,l1) = load_last_blocks #a totlen_seq fin len b in
let lb0 : multiseq (lanes a m) (block_length a) = ntup1 l0 in
let lb1 : multiseq (lanes a m) (block_length a) = ntup1 l1 in
(lb0, lb1)
#push-options "--z3rlimit 100"
noextract
let load_last4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let mb0 = ntup4 (l00, (l10, (l20, l30))) in
let mb1 = ntup4 (l01, (l11, (l21, l31))) in
(mb0, mb1)
noextract
let load_last8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let b4 = b.(|4|) in
let b5 = b.(|5|) in
let b6 = b.(|6|) in
let b7 = b.(|7|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let (l40,l41) = load_last_blocks #a totlen_seq fin len b4 in
let (l50,l51) = load_last_blocks #a totlen_seq fin len b5 in
let (l60,l61) = load_last_blocks #a totlen_seq fin len b6 in
let (l70,l71) = load_last_blocks #a totlen_seq fin len b7 in
let mb0 = ntup8 (l00, (l10, (l20, (l30, (l40, (l50, (l60, l70))))))) in
let mb1 = ntup8 (l01, (l11, (l21, (l31, (l41, (l51, (l61, l71))))))) in
(mb0, mb1)
#pop-options
[@"opaque_to_smt"]
noextract
let load_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
match lanes a m with
| 1 -> load_last1 #a #m totlen_seq fin len b
| 4 -> load_last4 #a #m totlen_seq fin len b
| 8 -> load_last8 #a #m totlen_seq fin len b
noextract
let update_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen:len_t a)
(len:nat{len <= block_length a})
(b:multiseq (lanes a m) len) (st:state_spec a m): state_spec a m =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
let st = update b0 st in
if blocks > 1 then
update b1 st
else st
noextract
let transpose_state4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(st:state_spec a m) : state_spec a m =
let st0 = st.[0] in
let st1 = st.[1] in
let st2 = st.[2] in
let st3 = st.[3] in
let st4 = st.[4] in
let st5 = st.[5] in
let st6 = st.[6] in
let st7 = st.[7] in
let (st0,st1,st2,st3) = VecTranspose.transpose4x4 (st0,st1,st2,st3) in
let (st4,st5,st6,st7) = VecTranspose.transpose4x4 (st4,st5,st6,st7) in
create8 st0 st4 st1 st5 st2 st6 st3 st7
noextract
let transpose_state8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8})
(st:state_spec a m) : state_spec a m =
let st0 = st.[0] in
let st1 = st.[1] in
let st2 = st.[2] in
let st3 = st.[3] in
let st4 = st.[4] in
let st5 = st.[5] in
let st6 = st.[6] in
let st7 = st.[7] in
let (st0,st1,st2,st3,st4,st5,st6,st7) = VecTranspose.transpose8x8 (st0,st1,st2,st3,st4,st5,st6,st7) in
create8 st0 st1 st2 st3 st4 st5 st6 st7
noextract
let transpose_state (#a:sha2_alg) (#m:m_spec{is_supported a m}) (st:state_spec a m) : state_spec a m =
match lanes a m with
| 1 -> st
| 4 -> transpose_state4 #a #m st
| 8 -> transpose_state8 #a #m st
noextract
let store_state (#a:sha2_alg) (#m:m_spec{is_supported a m}) (st:state_spec a m) :
lseq uint8 (lanes a m * 8 * word_length a) =
let st = transpose_state st in
Lib.IntVector.Serialize.vecs_to_bytes_be st
noextract
let emit (#a:sha2_alg) (#m:m_spec)
(hseq:lseq uint8 (lanes a m * 8 * word_length a)):
multiseq (lanes a m) (hash_length a) =
Lib.NTuple.createi #(Seq.lseq uint8 (hash_length a)) (lanes a m)
(fun i -> sub hseq (i * 8 * word_length a) (hash_length a))
noextract
let get_multiblock_spec (#a:sha2_alg) (#m:m_spec)
(len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len)
(i:nat{i < len / block_length a})
: multiseq (lanes a m) (block_length a) =
Lib.NTuple.createi #(Seq.lseq uint8 (block_length a)) (lanes a m)
(fun j -> Seq.slice b.(|j|) (i * block_length a) (i * block_length a + block_length a))
noextract
let get_multilast_spec (#a:sha2_alg) (#m:m_spec)
(len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len)
: multiseq (lanes a m) (len % block_length a) =
let rem = len % block_length a in
Lib.NTuple.createi #(Seq.lseq uint8 rem) (lanes a m)
(fun j -> Seq.slice b.(|j|) (len - rem) len)
noextract
let update_block (#a:sha2_alg) (#m:m_spec{is_supported a m}) (len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len)
(i:nat{i < len / block_length a}) (st:state_spec a m) : state_spec a m =
let mb = get_multiblock_spec len b i in
update mb st | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Hacl.Spec.SHA2.len_lt_max_a_t a ->
b: Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m) len ->
st: Hacl.Spec.SHA2.Vec.state_spec a m
-> Hacl.Spec.SHA2.Vec.state_spec a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Hacl.Spec.SHA2.len_lt_max_a_t",
"Hacl.Spec.SHA2.Vec.multiseq",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Vec.state_spec",
"Lib.LoopCombinators.repeati",
"Hacl.Spec.SHA2.Vec.update_block",
"Prims.int",
"Prims.op_Division",
"Spec.Hash.Definitions.block_length"
] | [] | false | false | false | false | false | let update_nblocks
(#a: sha2_alg)
(#m: m_spec{is_supported a m})
(len: Spec.len_lt_max_a_t a)
(b: multiseq (lanes a m) len)
(st: state_spec a m)
: state_spec a m =
| let blocks = len / block_length a in
let st = repeati blocks (update_block #a #m len b) st in
st | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.transpose_state8 | val transpose_state8 (#a: sha2_alg) (#m: m_spec{lanes a m == 8}) (st: state_spec a m)
: state_spec a m | val transpose_state8 (#a: sha2_alg) (#m: m_spec{lanes a m == 8}) (st: state_spec a m)
: state_spec a m | let transpose_state8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8})
(st:state_spec a m) : state_spec a m =
let st0 = st.[0] in
let st1 = st.[1] in
let st2 = st.[2] in
let st3 = st.[3] in
let st4 = st.[4] in
let st5 = st.[5] in
let st6 = st.[6] in
let st7 = st.[7] in
let (st0,st1,st2,st3,st4,st5,st6,st7) = VecTranspose.transpose8x8 (st0,st1,st2,st3,st4,st5,st6,st7) in
create8 st0 st1 st2 st3 st4 st5 st6 st7 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 43,
"end_line": 413,
"start_col": 0,
"start_line": 402
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (ws:ws_spec a m) : ws_spec a m =
match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws
noextract
let load_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) : ws_spec a m =
let ws = load_blocks #a #m b in
transpose_ws #a #m ws
noextract
let ws_next_inner (#a:sha2_alg) (#m:m_spec)
(i:nat{i < 16})
(ws:ws_spec a m) : ws_spec a m =
let t16 = ws.[i] in
let t15 = ws.[(i+1) % 16] in
let t7 = ws.[(i+9) % 16] in
let t2 = ws.[(i+14) % 16] in
let s1 = _sigma1 t2 in
let s0 = _sigma0 t15 in
ws.[i] <- (s1 +| t7 +| s0 +| t16)
noextract
let ws_next (#a:sha2_alg) (#m:m_spec)
(ws:ws_spec a m) : ws_spec a m =
repeati 16 (ws_next_inner #a #m) ws
noextract
let shuffle_inner (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (i:nat{i < v (num_rounds16 a)}) (j:nat{j < 16}) (st:state_spec a m) : state_spec a m =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec k_t ws_t st
noextract
let shuffle_inner_loop (#a:sha2_alg) (#m:m_spec) (i:nat{i < v (num_rounds16 a)})
(ws_st:ws_spec a m & state_spec a m) : ws_spec a m & state_spec a m =
let (ws,st) = ws_st in
let st' = repeati 16 (shuffle_inner ws i) st in
let ws' = if i < v (num_rounds16 a) - 1 then ws_next ws else ws in
(ws',st')
noextract
let shuffle (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (st:state_spec a m) : state_spec a m =
let (ws,st) = repeati (v(num_rounds16 a)) (shuffle_inner_loop #a #m) (ws,st) in
st
noextract
let init (a:sha2_alg) (m:m_spec) : state_spec a m =
createi 8 (fun i -> load_element a m (Seq.index (Spec.h0 a) i))
[@"opaque_to_smt"]
noextract
let update (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) (st:state_spec a m): state_spec a m =
let st_old = st in
let ws = load_ws b in
let st_new = shuffle ws st_old in
map2 (+|) st_new st_old
noextract
let padded_blocks (a:sha2_alg) (len:nat{len <= block_length a}) : n:nat{n <= 2} =
if (len + len_length a + 1 <= block_length a) then 1 else 2
noextract
let load_last_blocks (#a:sha2_alg)
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a})
(b:lseq uint8 len) :
lseq uint8 (block_length a) & lseq uint8 (block_length a) =
let last = create (2 * block_length a) (u8 0) in
let last = update_sub last 0 len b in
let last = last.[len] <- u8 0x80 in
let last = update_sub last (fin - len_length a) (len_length a) totlen_seq in
let l0 : lseq uint8 (block_length a) = sub last 0 (block_length a) in
let l1 : lseq uint8 (block_length a) = sub last (block_length a) (block_length a) in
(l0, l1)
noextract
let load_last1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b = b.(|0|) in
let (l0,l1) = load_last_blocks #a totlen_seq fin len b in
let lb0 : multiseq (lanes a m) (block_length a) = ntup1 l0 in
let lb1 : multiseq (lanes a m) (block_length a) = ntup1 l1 in
(lb0, lb1)
#push-options "--z3rlimit 100"
noextract
let load_last4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let mb0 = ntup4 (l00, (l10, (l20, l30))) in
let mb1 = ntup4 (l01, (l11, (l21, l31))) in
(mb0, mb1)
noextract
let load_last8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let b4 = b.(|4|) in
let b5 = b.(|5|) in
let b6 = b.(|6|) in
let b7 = b.(|7|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let (l40,l41) = load_last_blocks #a totlen_seq fin len b4 in
let (l50,l51) = load_last_blocks #a totlen_seq fin len b5 in
let (l60,l61) = load_last_blocks #a totlen_seq fin len b6 in
let (l70,l71) = load_last_blocks #a totlen_seq fin len b7 in
let mb0 = ntup8 (l00, (l10, (l20, (l30, (l40, (l50, (l60, l70))))))) in
let mb1 = ntup8 (l01, (l11, (l21, (l31, (l41, (l51, (l61, l71))))))) in
(mb0, mb1)
#pop-options
[@"opaque_to_smt"]
noextract
let load_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
match lanes a m with
| 1 -> load_last1 #a #m totlen_seq fin len b
| 4 -> load_last4 #a #m totlen_seq fin len b
| 8 -> load_last8 #a #m totlen_seq fin len b
noextract
let update_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen:len_t a)
(len:nat{len <= block_length a})
(b:multiseq (lanes a m) len) (st:state_spec a m): state_spec a m =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
let st = update b0 st in
if blocks > 1 then
update b1 st
else st
noextract
let transpose_state4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(st:state_spec a m) : state_spec a m =
let st0 = st.[0] in
let st1 = st.[1] in
let st2 = st.[2] in
let st3 = st.[3] in
let st4 = st.[4] in
let st5 = st.[5] in
let st6 = st.[6] in
let st7 = st.[7] in
let (st0,st1,st2,st3) = VecTranspose.transpose4x4 (st0,st1,st2,st3) in
let (st4,st5,st6,st7) = VecTranspose.transpose4x4 (st4,st5,st6,st7) in
create8 st0 st4 st1 st5 st2 st6 st3 st7 | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | st: Hacl.Spec.SHA2.Vec.state_spec a m -> Hacl.Spec.SHA2.Vec.state_spec a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Prims.eq2",
"Prims.int",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Vec.state_spec",
"Lib.IntVector.vec_t",
"Spec.Hash.Definitions.word_t",
"Lib.Sequence.create8",
"Hacl.Spec.SHA2.Vec.element_t",
"Lib.IntVector.Transpose.vec_t8",
"Lib.IntVector.Transpose.transpose8x8",
"FStar.Pervasives.Native.Mktuple8",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Lib.Sequence.op_String_Access"
] | [] | false | false | false | false | false | let transpose_state8 (#a: sha2_alg) (#m: m_spec{lanes a m == 8}) (st: state_spec a m)
: state_spec a m =
| let st0 = st.[ 0 ] in
let st1 = st.[ 1 ] in
let st2 = st.[ 2 ] in
let st3 = st.[ 3 ] in
let st4 = st.[ 4 ] in
let st5 = st.[ 5 ] in
let st6 = st.[ 6 ] in
let st7 = st.[ 7 ] in
let st0, st1, st2, st3, st4, st5, st6, st7 =
VecTranspose.transpose8x8 (st0, st1, st2, st3, st4, st5, st6, st7)
in
create8 st0 st1 st2 st3 st4 st5 st6 st7 | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.state_spec_v | val state_spec_v (#a: sha2_alg) (#m: m_spec) (st: state_spec a m)
: lseq (words_state' a) (lanes a m) | val state_spec_v (#a: sha2_alg) (#m: m_spec) (st: state_spec a m)
: lseq (words_state' a) (lanes a m) | let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 82,
"end_line": 136,
"start_col": 0,
"start_line": 132
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16 | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | st: Hacl.Spec.SHA2.Vec.state_spec a m
-> Lib.Sequence.lseq (Hacl.Spec.SHA2.Vec.words_state' a) (Hacl.Spec.SHA2.Vec.lanes a m) | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.state_spec",
"Lib.Sequence.createi",
"Hacl.Spec.SHA2.Vec.words_state'",
"Hacl.Spec.SHA2.Vec.lanes",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.Sequence.create8",
"Hacl.Spec.SHA2.Vec.word",
"Lib.Sequence.op_String_Access",
"Lib.IntTypes.uint_t",
"Spec.Hash.Definitions.word_t",
"Lib.IntTypes.SEC",
"Lib.IntVector.vec_v",
"Hacl.Spec.SHA2.Vec.element_t",
"Lib.Sequence.lseq"
] | [] | false | false | false | false | false | let state_spec_v (#a: sha2_alg) (#m: m_spec) (st: state_spec a m)
: lseq (words_state' a) (lanes a m) =
| createi #(words_state' a)
(lanes a m)
(fun i ->
create8 (vec_v st.[ 0 ]).[ i ]
(vec_v st.[ 1 ]).[ i ]
(vec_v st.[ 2 ]).[ i ]
(vec_v st.[ 3 ]).[ i ]
(vec_v st.[ 4 ]).[ i ]
(vec_v st.[ 5 ]).[ i ]
(vec_v st.[ 6 ]).[ i ]
(vec_v st.[ 7 ]).[ i ]) | false |
Spec.Frodo.KEM.KeyGen.fst | Spec.Frodo.KEM.KeyGen.frodo_mul_add_as_plus_e | val frodo_mul_add_as_plus_e:
a:frodo_alg
-> gen_a:frodo_gen_a
-> seed_a:lbytes bytes_seed_a
-> s_matrix:matrix (params_n a) params_nbar
-> e_matrix:matrix (params_n a) params_nbar
-> matrix (params_n a) params_nbar | val frodo_mul_add_as_plus_e:
a:frodo_alg
-> gen_a:frodo_gen_a
-> seed_a:lbytes bytes_seed_a
-> s_matrix:matrix (params_n a) params_nbar
-> e_matrix:matrix (params_n a) params_nbar
-> matrix (params_n a) params_nbar | let frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix =
params_n_sqr a;
let a_matrix = frodo_gen_matrix gen_a (params_n a) seed_a in
let b_matrix = Matrix.add (Matrix.mul_s a_matrix s_matrix) e_matrix in
b_matrix | {
"file_name": "specs/frodo/Spec.Frodo.KEM.KeyGen.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 44,
"start_col": 0,
"start_line": 40
} | module Spec.Frodo.KEM.KeyGen
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Matrix
open Spec.Frodo.Params
open Spec.Frodo.Pack
open Spec.Frodo.Sample
module LSeq = Lib.Sequence
module Matrix = Spec.Matrix
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val frodo_shake_r:
a:frodo_alg
-> c:uint8
-> seed_se:lbytes (crypto_bytes a)
-> output_len:size_nat
-> lbytes output_len
let frodo_shake_r a c seed_se output_len =
let tmp = LSeq.create 1 c in
let shake_input_seed_se = LSeq.concat tmp seed_se in
frodo_shake a (1 + crypto_bytes a) shake_input_seed_se output_len
val frodo_mul_add_as_plus_e:
a:frodo_alg
-> gen_a:frodo_gen_a
-> seed_a:lbytes bytes_seed_a
-> s_matrix:matrix (params_n a) params_nbar
-> e_matrix:matrix (params_n a) params_nbar
-> matrix (params_n a) params_nbar | {
"checked_file": "/",
"dependencies": [
"Spec.Matrix.fst.checked",
"Spec.Frodo.Sample.fst.checked",
"Spec.Frodo.Random.fst.checked",
"Spec.Frodo.Params.fst.checked",
"Spec.Frodo.Pack.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Frodo.KEM.KeyGen.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Matrix",
"short_module": "Matrix"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": false,
"full_module": "Spec.Frodo.Sample",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.Pack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.Params",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Frodo.Params.frodo_alg ->
gen_a: Spec.Frodo.Params.frodo_gen_a ->
seed_a: Lib.ByteSequence.lbytes Spec.Frodo.Params.bytes_seed_a ->
s_matrix: Spec.Matrix.matrix (Spec.Frodo.Params.params_n a) Spec.Frodo.Params.params_nbar ->
e_matrix: Spec.Matrix.matrix (Spec.Frodo.Params.params_n a) Spec.Frodo.Params.params_nbar
-> Spec.Matrix.matrix (Spec.Frodo.Params.params_n a) Spec.Frodo.Params.params_nbar | Prims.Tot | [
"total"
] | [] | [
"Spec.Frodo.Params.frodo_alg",
"Spec.Frodo.Params.frodo_gen_a",
"Lib.ByteSequence.lbytes",
"Spec.Frodo.Params.bytes_seed_a",
"Spec.Matrix.matrix",
"Spec.Frodo.Params.params_n",
"Spec.Frodo.Params.params_nbar",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U16",
"Lib.IntTypes.SEC",
"Prims.op_Multiply",
"Prims.l_Forall",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.pow2",
"Prims.l_and",
"Prims.op_LessThan",
"Prims.eq2",
"Spec.Matrix.mget",
"Lib.IntTypes.add_mod",
"Spec.Matrix.mul_s",
"Spec.Matrix.add",
"Spec.Frodo.Params.frodo_gen_matrix",
"Prims.unit",
"Spec.Frodo.Params.params_n_sqr"
] | [] | false | false | false | false | false | let frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix =
| params_n_sqr a;
let a_matrix = frodo_gen_matrix gen_a (params_n a) seed_a in
let b_matrix = Matrix.add (Matrix.mul_s a_matrix s_matrix) e_matrix in
b_matrix | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.hash | val hash : len: Hacl.Spec.SHA2.len_lt_max_a_t a ->
b: Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m) len
-> Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m)
(Spec.Hash.Definitions.hash_length a) | let hash (#a:sha2_alg) (#m:m_spec{is_supported a m}) (len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len) =
let len' : len_t a = Spec.mk_len_t a len in
let st = init a m in
let st = update_nblocks #a #m len b st in
let rem = len % block_length a in
let mb = get_multilast_spec #a #m len b in
let st = update_last len' rem mb st in
finish st | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 13,
"end_line": 478,
"start_col": 0,
"start_line": 471
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (ws:ws_spec a m) : ws_spec a m =
match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws
noextract
let load_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) : ws_spec a m =
let ws = load_blocks #a #m b in
transpose_ws #a #m ws
noextract
let ws_next_inner (#a:sha2_alg) (#m:m_spec)
(i:nat{i < 16})
(ws:ws_spec a m) : ws_spec a m =
let t16 = ws.[i] in
let t15 = ws.[(i+1) % 16] in
let t7 = ws.[(i+9) % 16] in
let t2 = ws.[(i+14) % 16] in
let s1 = _sigma1 t2 in
let s0 = _sigma0 t15 in
ws.[i] <- (s1 +| t7 +| s0 +| t16)
noextract
let ws_next (#a:sha2_alg) (#m:m_spec)
(ws:ws_spec a m) : ws_spec a m =
repeati 16 (ws_next_inner #a #m) ws
noextract
let shuffle_inner (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (i:nat{i < v (num_rounds16 a)}) (j:nat{j < 16}) (st:state_spec a m) : state_spec a m =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec k_t ws_t st
noextract
let shuffle_inner_loop (#a:sha2_alg) (#m:m_spec) (i:nat{i < v (num_rounds16 a)})
(ws_st:ws_spec a m & state_spec a m) : ws_spec a m & state_spec a m =
let (ws,st) = ws_st in
let st' = repeati 16 (shuffle_inner ws i) st in
let ws' = if i < v (num_rounds16 a) - 1 then ws_next ws else ws in
(ws',st')
noextract
let shuffle (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (st:state_spec a m) : state_spec a m =
let (ws,st) = repeati (v(num_rounds16 a)) (shuffle_inner_loop #a #m) (ws,st) in
st
noextract
let init (a:sha2_alg) (m:m_spec) : state_spec a m =
createi 8 (fun i -> load_element a m (Seq.index (Spec.h0 a) i))
[@"opaque_to_smt"]
noextract
let update (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) (st:state_spec a m): state_spec a m =
let st_old = st in
let ws = load_ws b in
let st_new = shuffle ws st_old in
map2 (+|) st_new st_old
noextract
let padded_blocks (a:sha2_alg) (len:nat{len <= block_length a}) : n:nat{n <= 2} =
if (len + len_length a + 1 <= block_length a) then 1 else 2
noextract
let load_last_blocks (#a:sha2_alg)
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a})
(b:lseq uint8 len) :
lseq uint8 (block_length a) & lseq uint8 (block_length a) =
let last = create (2 * block_length a) (u8 0) in
let last = update_sub last 0 len b in
let last = last.[len] <- u8 0x80 in
let last = update_sub last (fin - len_length a) (len_length a) totlen_seq in
let l0 : lseq uint8 (block_length a) = sub last 0 (block_length a) in
let l1 : lseq uint8 (block_length a) = sub last (block_length a) (block_length a) in
(l0, l1)
noextract
let load_last1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b = b.(|0|) in
let (l0,l1) = load_last_blocks #a totlen_seq fin len b in
let lb0 : multiseq (lanes a m) (block_length a) = ntup1 l0 in
let lb1 : multiseq (lanes a m) (block_length a) = ntup1 l1 in
(lb0, lb1)
#push-options "--z3rlimit 100"
noextract
let load_last4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let mb0 = ntup4 (l00, (l10, (l20, l30))) in
let mb1 = ntup4 (l01, (l11, (l21, l31))) in
(mb0, mb1)
noextract
let load_last8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let b4 = b.(|4|) in
let b5 = b.(|5|) in
let b6 = b.(|6|) in
let b7 = b.(|7|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let (l40,l41) = load_last_blocks #a totlen_seq fin len b4 in
let (l50,l51) = load_last_blocks #a totlen_seq fin len b5 in
let (l60,l61) = load_last_blocks #a totlen_seq fin len b6 in
let (l70,l71) = load_last_blocks #a totlen_seq fin len b7 in
let mb0 = ntup8 (l00, (l10, (l20, (l30, (l40, (l50, (l60, l70))))))) in
let mb1 = ntup8 (l01, (l11, (l21, (l31, (l41, (l51, (l61, l71))))))) in
(mb0, mb1)
#pop-options
[@"opaque_to_smt"]
noextract
let load_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
match lanes a m with
| 1 -> load_last1 #a #m totlen_seq fin len b
| 4 -> load_last4 #a #m totlen_seq fin len b
| 8 -> load_last8 #a #m totlen_seq fin len b
noextract
let update_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen:len_t a)
(len:nat{len <= block_length a})
(b:multiseq (lanes a m) len) (st:state_spec a m): state_spec a m =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
let st = update b0 st in
if blocks > 1 then
update b1 st
else st
noextract
let transpose_state4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(st:state_spec a m) : state_spec a m =
let st0 = st.[0] in
let st1 = st.[1] in
let st2 = st.[2] in
let st3 = st.[3] in
let st4 = st.[4] in
let st5 = st.[5] in
let st6 = st.[6] in
let st7 = st.[7] in
let (st0,st1,st2,st3) = VecTranspose.transpose4x4 (st0,st1,st2,st3) in
let (st4,st5,st6,st7) = VecTranspose.transpose4x4 (st4,st5,st6,st7) in
create8 st0 st4 st1 st5 st2 st6 st3 st7
noextract
let transpose_state8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8})
(st:state_spec a m) : state_spec a m =
let st0 = st.[0] in
let st1 = st.[1] in
let st2 = st.[2] in
let st3 = st.[3] in
let st4 = st.[4] in
let st5 = st.[5] in
let st6 = st.[6] in
let st7 = st.[7] in
let (st0,st1,st2,st3,st4,st5,st6,st7) = VecTranspose.transpose8x8 (st0,st1,st2,st3,st4,st5,st6,st7) in
create8 st0 st1 st2 st3 st4 st5 st6 st7
noextract
let transpose_state (#a:sha2_alg) (#m:m_spec{is_supported a m}) (st:state_spec a m) : state_spec a m =
match lanes a m with
| 1 -> st
| 4 -> transpose_state4 #a #m st
| 8 -> transpose_state8 #a #m st
noextract
let store_state (#a:sha2_alg) (#m:m_spec{is_supported a m}) (st:state_spec a m) :
lseq uint8 (lanes a m * 8 * word_length a) =
let st = transpose_state st in
Lib.IntVector.Serialize.vecs_to_bytes_be st
noextract
let emit (#a:sha2_alg) (#m:m_spec)
(hseq:lseq uint8 (lanes a m * 8 * word_length a)):
multiseq (lanes a m) (hash_length a) =
Lib.NTuple.createi #(Seq.lseq uint8 (hash_length a)) (lanes a m)
(fun i -> sub hseq (i * 8 * word_length a) (hash_length a))
noextract
let get_multiblock_spec (#a:sha2_alg) (#m:m_spec)
(len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len)
(i:nat{i < len / block_length a})
: multiseq (lanes a m) (block_length a) =
Lib.NTuple.createi #(Seq.lseq uint8 (block_length a)) (lanes a m)
(fun j -> Seq.slice b.(|j|) (i * block_length a) (i * block_length a + block_length a))
noextract
let get_multilast_spec (#a:sha2_alg) (#m:m_spec)
(len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len)
: multiseq (lanes a m) (len % block_length a) =
let rem = len % block_length a in
Lib.NTuple.createi #(Seq.lseq uint8 rem) (lanes a m)
(fun j -> Seq.slice b.(|j|) (len - rem) len)
noextract
let update_block (#a:sha2_alg) (#m:m_spec{is_supported a m}) (len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len)
(i:nat{i < len / block_length a}) (st:state_spec a m) : state_spec a m =
let mb = get_multiblock_spec len b i in
update mb st
noextract
let update_nblocks (#a:sha2_alg) (#m:m_spec{is_supported a m}) (len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len) (st:state_spec a m) : state_spec a m =
let blocks = len / block_length a in
let st = repeati blocks (update_block #a #m len b) st in
st
noextract
let finish (#a:sha2_alg) (#m:m_spec{is_supported a m}) (st:state_spec a m) :
multiseq (lanes a m) (hash_length a) =
let hseq = store_state st in
emit hseq | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Hacl.Spec.SHA2.len_lt_max_a_t a ->
b: Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m) len
-> Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m)
(Spec.Hash.Definitions.hash_length a) | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Hacl.Spec.SHA2.len_lt_max_a_t",
"Hacl.Spec.SHA2.Vec.multiseq",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Vec.finish",
"Hacl.Spec.SHA2.Vec.state_spec",
"Hacl.Spec.SHA2.Vec.update_last",
"Prims.op_Modulus",
"Spec.Hash.Definitions.block_length",
"Hacl.Spec.SHA2.Vec.get_multilast_spec",
"Prims.int",
"Hacl.Spec.SHA2.Vec.update_nblocks",
"Hacl.Spec.SHA2.Vec.init",
"Spec.Hash.Definitions.len_t",
"Hacl.Spec.SHA2.mk_len_t",
"Spec.Hash.Definitions.hash_length"
] | [] | false | false | false | false | false | let hash
(#a: sha2_alg)
(#m: m_spec{is_supported a m})
(len: Spec.len_lt_max_a_t a)
(b: multiseq (lanes a m) len)
=
| let len':len_t a = Spec.mk_len_t a len in
let st = init a m in
let st = update_nblocks #a #m len b st in
let rem = len % block_length a in
let mb = get_multilast_spec #a #m len b in
let st = update_last len' rem mb st in
finish st | false |
|
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.store_state | val store_state (#a: sha2_alg) (#m: m_spec{is_supported a m}) (st: state_spec a m)
: lseq uint8 (lanes a m * 8 * word_length a) | val store_state (#a: sha2_alg) (#m: m_spec{is_supported a m}) (st: state_spec a m)
: lseq uint8 (lanes a m * 8 * word_length a) | let store_state (#a:sha2_alg) (#m:m_spec{is_supported a m}) (st:state_spec a m) :
lseq uint8 (lanes a m * 8 * word_length a) =
let st = transpose_state st in
Lib.IntVector.Serialize.vecs_to_bytes_be st | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 426,
"start_col": 0,
"start_line": 423
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (ws:ws_spec a m) : ws_spec a m =
match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws
noextract
let load_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) : ws_spec a m =
let ws = load_blocks #a #m b in
transpose_ws #a #m ws
noextract
let ws_next_inner (#a:sha2_alg) (#m:m_spec)
(i:nat{i < 16})
(ws:ws_spec a m) : ws_spec a m =
let t16 = ws.[i] in
let t15 = ws.[(i+1) % 16] in
let t7 = ws.[(i+9) % 16] in
let t2 = ws.[(i+14) % 16] in
let s1 = _sigma1 t2 in
let s0 = _sigma0 t15 in
ws.[i] <- (s1 +| t7 +| s0 +| t16)
noextract
let ws_next (#a:sha2_alg) (#m:m_spec)
(ws:ws_spec a m) : ws_spec a m =
repeati 16 (ws_next_inner #a #m) ws
noextract
let shuffle_inner (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (i:nat{i < v (num_rounds16 a)}) (j:nat{j < 16}) (st:state_spec a m) : state_spec a m =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec k_t ws_t st
noextract
let shuffle_inner_loop (#a:sha2_alg) (#m:m_spec) (i:nat{i < v (num_rounds16 a)})
(ws_st:ws_spec a m & state_spec a m) : ws_spec a m & state_spec a m =
let (ws,st) = ws_st in
let st' = repeati 16 (shuffle_inner ws i) st in
let ws' = if i < v (num_rounds16 a) - 1 then ws_next ws else ws in
(ws',st')
noextract
let shuffle (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (st:state_spec a m) : state_spec a m =
let (ws,st) = repeati (v(num_rounds16 a)) (shuffle_inner_loop #a #m) (ws,st) in
st
noextract
let init (a:sha2_alg) (m:m_spec) : state_spec a m =
createi 8 (fun i -> load_element a m (Seq.index (Spec.h0 a) i))
[@"opaque_to_smt"]
noextract
let update (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) (st:state_spec a m): state_spec a m =
let st_old = st in
let ws = load_ws b in
let st_new = shuffle ws st_old in
map2 (+|) st_new st_old
noextract
let padded_blocks (a:sha2_alg) (len:nat{len <= block_length a}) : n:nat{n <= 2} =
if (len + len_length a + 1 <= block_length a) then 1 else 2
noextract
let load_last_blocks (#a:sha2_alg)
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a})
(b:lseq uint8 len) :
lseq uint8 (block_length a) & lseq uint8 (block_length a) =
let last = create (2 * block_length a) (u8 0) in
let last = update_sub last 0 len b in
let last = last.[len] <- u8 0x80 in
let last = update_sub last (fin - len_length a) (len_length a) totlen_seq in
let l0 : lseq uint8 (block_length a) = sub last 0 (block_length a) in
let l1 : lseq uint8 (block_length a) = sub last (block_length a) (block_length a) in
(l0, l1)
noextract
let load_last1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b = b.(|0|) in
let (l0,l1) = load_last_blocks #a totlen_seq fin len b in
let lb0 : multiseq (lanes a m) (block_length a) = ntup1 l0 in
let lb1 : multiseq (lanes a m) (block_length a) = ntup1 l1 in
(lb0, lb1)
#push-options "--z3rlimit 100"
noextract
let load_last4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let mb0 = ntup4 (l00, (l10, (l20, l30))) in
let mb1 = ntup4 (l01, (l11, (l21, l31))) in
(mb0, mb1)
noextract
let load_last8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let b4 = b.(|4|) in
let b5 = b.(|5|) in
let b6 = b.(|6|) in
let b7 = b.(|7|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let (l40,l41) = load_last_blocks #a totlen_seq fin len b4 in
let (l50,l51) = load_last_blocks #a totlen_seq fin len b5 in
let (l60,l61) = load_last_blocks #a totlen_seq fin len b6 in
let (l70,l71) = load_last_blocks #a totlen_seq fin len b7 in
let mb0 = ntup8 (l00, (l10, (l20, (l30, (l40, (l50, (l60, l70))))))) in
let mb1 = ntup8 (l01, (l11, (l21, (l31, (l41, (l51, (l61, l71))))))) in
(mb0, mb1)
#pop-options
[@"opaque_to_smt"]
noextract
let load_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
match lanes a m with
| 1 -> load_last1 #a #m totlen_seq fin len b
| 4 -> load_last4 #a #m totlen_seq fin len b
| 8 -> load_last8 #a #m totlen_seq fin len b
noextract
let update_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen:len_t a)
(len:nat{len <= block_length a})
(b:multiseq (lanes a m) len) (st:state_spec a m): state_spec a m =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
let st = update b0 st in
if blocks > 1 then
update b1 st
else st
noextract
let transpose_state4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(st:state_spec a m) : state_spec a m =
let st0 = st.[0] in
let st1 = st.[1] in
let st2 = st.[2] in
let st3 = st.[3] in
let st4 = st.[4] in
let st5 = st.[5] in
let st6 = st.[6] in
let st7 = st.[7] in
let (st0,st1,st2,st3) = VecTranspose.transpose4x4 (st0,st1,st2,st3) in
let (st4,st5,st6,st7) = VecTranspose.transpose4x4 (st4,st5,st6,st7) in
create8 st0 st4 st1 st5 st2 st6 st3 st7
noextract
let transpose_state8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8})
(st:state_spec a m) : state_spec a m =
let st0 = st.[0] in
let st1 = st.[1] in
let st2 = st.[2] in
let st3 = st.[3] in
let st4 = st.[4] in
let st5 = st.[5] in
let st6 = st.[6] in
let st7 = st.[7] in
let (st0,st1,st2,st3,st4,st5,st6,st7) = VecTranspose.transpose8x8 (st0,st1,st2,st3,st4,st5,st6,st7) in
create8 st0 st1 st2 st3 st4 st5 st6 st7
noextract
let transpose_state (#a:sha2_alg) (#m:m_spec{is_supported a m}) (st:state_spec a m) : state_spec a m =
match lanes a m with
| 1 -> st
| 4 -> transpose_state4 #a #m st
| 8 -> transpose_state8 #a #m st | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | st: Hacl.Spec.SHA2.Vec.state_spec a m
-> Lib.Sequence.lseq Lib.IntTypes.uint8
((Hacl.Spec.SHA2.Vec.lanes a m * 8) * Spec.Hash.Definitions.word_length a) | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Hacl.Spec.SHA2.Vec.state_spec",
"Lib.IntVector.Serialize.vecs_to_bytes_be",
"Spec.Hash.Definitions.word_t",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Vec.transpose_state",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint8",
"FStar.Mul.op_Star",
"Spec.Hash.Definitions.word_length"
] | [] | false | false | false | false | false | let store_state (#a: sha2_alg) (#m: m_spec{is_supported a m}) (st: state_spec a m)
: lseq uint8 (lanes a m * 8 * word_length a) =
| let st = transpose_state st in
Lib.IntVector.Serialize.vecs_to_bytes_be st | false |
Spec.Frodo.KEM.KeyGen.fst | Spec.Frodo.KEM.KeyGen.get_s_e_matrices | val get_s_e_matrices:
a:frodo_alg
-> seed_se:lbytes (crypto_bytes a)
-> matrix (params_n a) params_nbar & matrix (params_n a) params_nbar | val get_s_e_matrices:
a:frodo_alg
-> seed_se:lbytes (crypto_bytes a)
-> matrix (params_n a) params_nbar & matrix (params_n a) params_nbar | let get_s_e_matrices a seed_se =
let s_bytes_len = secretmatrixbytes_len a in
let r = frodo_shake_r a (u8 0x5f) seed_se (2 * s_bytes_len) in
let s_matrix = frodo_sample_matrix a (params_n a) params_nbar (LSeq.sub r 0 s_bytes_len) in
let e_matrix = frodo_sample_matrix a (params_n a) params_nbar (LSeq.sub r s_bytes_len s_bytes_len) in
s_matrix, e_matrix | {
"file_name": "specs/frodo/Spec.Frodo.KEM.KeyGen.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 20,
"end_line": 70,
"start_col": 0,
"start_line": 65
} | module Spec.Frodo.KEM.KeyGen
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Matrix
open Spec.Frodo.Params
open Spec.Frodo.Pack
open Spec.Frodo.Sample
module LSeq = Lib.Sequence
module Matrix = Spec.Matrix
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val frodo_shake_r:
a:frodo_alg
-> c:uint8
-> seed_se:lbytes (crypto_bytes a)
-> output_len:size_nat
-> lbytes output_len
let frodo_shake_r a c seed_se output_len =
let tmp = LSeq.create 1 c in
let shake_input_seed_se = LSeq.concat tmp seed_se in
frodo_shake a (1 + crypto_bytes a) shake_input_seed_se output_len
val frodo_mul_add_as_plus_e:
a:frodo_alg
-> gen_a:frodo_gen_a
-> seed_a:lbytes bytes_seed_a
-> s_matrix:matrix (params_n a) params_nbar
-> e_matrix:matrix (params_n a) params_nbar
-> matrix (params_n a) params_nbar
let frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix =
params_n_sqr a;
let a_matrix = frodo_gen_matrix gen_a (params_n a) seed_a in
let b_matrix = Matrix.add (Matrix.mul_s a_matrix s_matrix) e_matrix in
b_matrix
val frodo_mul_add_as_plus_e_pack:
a:frodo_alg
-> gen_a:frodo_gen_a
-> seed_a:lbytes bytes_seed_a
-> s_matrix:matrix (params_n a) params_nbar
-> e_matrix:matrix (params_n a) params_nbar
-> lbytes (publicmatrixbytes_len a)
let frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix =
let b_matrix = frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix in
frodo_pack (params_logq a) b_matrix
val get_s_e_matrices:
a:frodo_alg
-> seed_se:lbytes (crypto_bytes a)
-> matrix (params_n a) params_nbar & matrix (params_n a) params_nbar | {
"checked_file": "/",
"dependencies": [
"Spec.Matrix.fst.checked",
"Spec.Frodo.Sample.fst.checked",
"Spec.Frodo.Random.fst.checked",
"Spec.Frodo.Params.fst.checked",
"Spec.Frodo.Pack.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Frodo.KEM.KeyGen.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Matrix",
"short_module": "Matrix"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": false,
"full_module": "Spec.Frodo.Sample",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.Pack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.Params",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Frodo.Params.frodo_alg ->
seed_se: Lib.ByteSequence.lbytes (Spec.Frodo.Params.crypto_bytes a)
-> Spec.Matrix.matrix (Spec.Frodo.Params.params_n a) Spec.Frodo.Params.params_nbar *
Spec.Matrix.matrix (Spec.Frodo.Params.params_n a) Spec.Frodo.Params.params_nbar | Prims.Tot | [
"total"
] | [] | [
"Spec.Frodo.Params.frodo_alg",
"Lib.ByteSequence.lbytes",
"Spec.Frodo.Params.crypto_bytes",
"FStar.Pervasives.Native.Mktuple2",
"Spec.Matrix.matrix",
"Spec.Frodo.Params.params_n",
"Spec.Frodo.Params.params_nbar",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U16",
"Lib.IntTypes.SEC",
"Prims.op_Multiply",
"Spec.Frodo.Sample.frodo_sample_matrix",
"Lib.Sequence.sub",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"FStar.Mul.op_Star",
"Spec.Frodo.KEM.KeyGen.frodo_shake_r",
"Lib.IntTypes.u8",
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.pow2",
"Spec.Frodo.Params.secretmatrixbytes_len",
"FStar.Pervasives.Native.tuple2"
] | [] | false | false | false | false | false | let get_s_e_matrices a seed_se =
| let s_bytes_len = secretmatrixbytes_len a in
let r = frodo_shake_r a (u8 0x5f) seed_se (2 * s_bytes_len) in
let s_matrix = frodo_sample_matrix a (params_n a) params_nbar (LSeq.sub r 0 s_bytes_len) in
let e_matrix =
frodo_sample_matrix a (params_n a) params_nbar (LSeq.sub r s_bytes_len s_bytes_len)
in
s_matrix, e_matrix | false |
Spec.Frodo.KEM.KeyGen.fst | Spec.Frodo.KEM.KeyGen.crypto_kem_sk | val crypto_kem_sk:
a:frodo_alg
-> s:lbytes (crypto_bytes a)
-> pk:lbytes (crypto_publickeybytes a)
-> s_bytes:lbytes (secretmatrixbytes_len a)
-> lbytes (crypto_secretkeybytes a) | val crypto_kem_sk:
a:frodo_alg
-> s:lbytes (crypto_bytes a)
-> pk:lbytes (crypto_publickeybytes a)
-> s_bytes:lbytes (secretmatrixbytes_len a)
-> lbytes (crypto_secretkeybytes a) | let crypto_kem_sk a s pk s_bytes =
let sk = concat (concat s pk) s_bytes in
let pkh = frodo_shake a (crypto_publickeybytes a) pk (bytes_pkhash a) in
let sk_pkh = concat sk pkh in
sk_pkh | {
"file_name": "specs/frodo/Spec.Frodo.KEM.KeyGen.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 8,
"end_line": 98,
"start_col": 0,
"start_line": 94
} | module Spec.Frodo.KEM.KeyGen
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Matrix
open Spec.Frodo.Params
open Spec.Frodo.Pack
open Spec.Frodo.Sample
module LSeq = Lib.Sequence
module Matrix = Spec.Matrix
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val frodo_shake_r:
a:frodo_alg
-> c:uint8
-> seed_se:lbytes (crypto_bytes a)
-> output_len:size_nat
-> lbytes output_len
let frodo_shake_r a c seed_se output_len =
let tmp = LSeq.create 1 c in
let shake_input_seed_se = LSeq.concat tmp seed_se in
frodo_shake a (1 + crypto_bytes a) shake_input_seed_se output_len
val frodo_mul_add_as_plus_e:
a:frodo_alg
-> gen_a:frodo_gen_a
-> seed_a:lbytes bytes_seed_a
-> s_matrix:matrix (params_n a) params_nbar
-> e_matrix:matrix (params_n a) params_nbar
-> matrix (params_n a) params_nbar
let frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix =
params_n_sqr a;
let a_matrix = frodo_gen_matrix gen_a (params_n a) seed_a in
let b_matrix = Matrix.add (Matrix.mul_s a_matrix s_matrix) e_matrix in
b_matrix
val frodo_mul_add_as_plus_e_pack:
a:frodo_alg
-> gen_a:frodo_gen_a
-> seed_a:lbytes bytes_seed_a
-> s_matrix:matrix (params_n a) params_nbar
-> e_matrix:matrix (params_n a) params_nbar
-> lbytes (publicmatrixbytes_len a)
let frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix =
let b_matrix = frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix in
frodo_pack (params_logq a) b_matrix
val get_s_e_matrices:
a:frodo_alg
-> seed_se:lbytes (crypto_bytes a)
-> matrix (params_n a) params_nbar & matrix (params_n a) params_nbar
let get_s_e_matrices a seed_se =
let s_bytes_len = secretmatrixbytes_len a in
let r = frodo_shake_r a (u8 0x5f) seed_se (2 * s_bytes_len) in
let s_matrix = frodo_sample_matrix a (params_n a) params_nbar (LSeq.sub r 0 s_bytes_len) in
let e_matrix = frodo_sample_matrix a (params_n a) params_nbar (LSeq.sub r s_bytes_len s_bytes_len) in
s_matrix, e_matrix
val frodo_mul_add_as_plus_e_pack_shake:
a:frodo_alg
-> gen_a:frodo_gen_a
-> seed_a:lbytes bytes_seed_a
-> seed_se:lbytes (crypto_bytes a)
-> tuple2 (lbytes (publicmatrixbytes_len a)) (lbytes (secretmatrixbytes_len a))
let frodo_mul_add_as_plus_e_pack_shake a gen_a seed_a seed_se =
let s_matrix, e_matrix = get_s_e_matrices a seed_se in
let b_bytes = frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix in
let s_bytes = matrix_to_lbytes s_matrix in
b_bytes, s_bytes
val crypto_kem_sk:
a:frodo_alg
-> s:lbytes (crypto_bytes a)
-> pk:lbytes (crypto_publickeybytes a)
-> s_bytes:lbytes (secretmatrixbytes_len a)
-> lbytes (crypto_secretkeybytes a) | {
"checked_file": "/",
"dependencies": [
"Spec.Matrix.fst.checked",
"Spec.Frodo.Sample.fst.checked",
"Spec.Frodo.Random.fst.checked",
"Spec.Frodo.Params.fst.checked",
"Spec.Frodo.Pack.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Frodo.KEM.KeyGen.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Matrix",
"short_module": "Matrix"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": false,
"full_module": "Spec.Frodo.Sample",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.Pack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.Params",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Frodo.Params.frodo_alg ->
s: Lib.ByteSequence.lbytes (Spec.Frodo.Params.crypto_bytes a) ->
pk: Lib.ByteSequence.lbytes (Spec.Frodo.Params.crypto_publickeybytes a) ->
s_bytes: Lib.ByteSequence.lbytes (Spec.Frodo.Params.secretmatrixbytes_len a)
-> Lib.ByteSequence.lbytes (Spec.Frodo.Params.crypto_secretkeybytes a) | Prims.Tot | [
"total"
] | [] | [
"Spec.Frodo.Params.frodo_alg",
"Lib.ByteSequence.lbytes",
"Spec.Frodo.Params.crypto_bytes",
"Spec.Frodo.Params.crypto_publickeybytes",
"Spec.Frodo.Params.secretmatrixbytes_len",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.op_Addition",
"Spec.Frodo.Params.bytes_pkhash",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.append",
"Lib.Sequence.concat",
"Lib.IntTypes.uint_t",
"Spec.Frodo.Params.frodo_shake",
"Spec.Frodo.Params.crypto_secretkeybytes"
] | [] | false | false | false | false | false | let crypto_kem_sk a s pk s_bytes =
| let sk = concat (concat s pk) s_bytes in
let pkh = frodo_shake a (crypto_publickeybytes a) pk (bytes_pkhash a) in
let sk_pkh = concat sk pkh in
sk_pkh | false |
Spec.Frodo.KEM.KeyGen.fst | Spec.Frodo.KEM.KeyGen.frodo_mul_add_as_plus_e_pack_shake | val frodo_mul_add_as_plus_e_pack_shake:
a:frodo_alg
-> gen_a:frodo_gen_a
-> seed_a:lbytes bytes_seed_a
-> seed_se:lbytes (crypto_bytes a)
-> tuple2 (lbytes (publicmatrixbytes_len a)) (lbytes (secretmatrixbytes_len a)) | val frodo_mul_add_as_plus_e_pack_shake:
a:frodo_alg
-> gen_a:frodo_gen_a
-> seed_a:lbytes bytes_seed_a
-> seed_se:lbytes (crypto_bytes a)
-> tuple2 (lbytes (publicmatrixbytes_len a)) (lbytes (secretmatrixbytes_len a)) | let frodo_mul_add_as_plus_e_pack_shake a gen_a seed_a seed_se =
let s_matrix, e_matrix = get_s_e_matrices a seed_se in
let b_bytes = frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix in
let s_bytes = matrix_to_lbytes s_matrix in
b_bytes, s_bytes | {
"file_name": "specs/frodo/Spec.Frodo.KEM.KeyGen.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 18,
"end_line": 84,
"start_col": 0,
"start_line": 80
} | module Spec.Frodo.KEM.KeyGen
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Matrix
open Spec.Frodo.Params
open Spec.Frodo.Pack
open Spec.Frodo.Sample
module LSeq = Lib.Sequence
module Matrix = Spec.Matrix
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val frodo_shake_r:
a:frodo_alg
-> c:uint8
-> seed_se:lbytes (crypto_bytes a)
-> output_len:size_nat
-> lbytes output_len
let frodo_shake_r a c seed_se output_len =
let tmp = LSeq.create 1 c in
let shake_input_seed_se = LSeq.concat tmp seed_se in
frodo_shake a (1 + crypto_bytes a) shake_input_seed_se output_len
val frodo_mul_add_as_plus_e:
a:frodo_alg
-> gen_a:frodo_gen_a
-> seed_a:lbytes bytes_seed_a
-> s_matrix:matrix (params_n a) params_nbar
-> e_matrix:matrix (params_n a) params_nbar
-> matrix (params_n a) params_nbar
let frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix =
params_n_sqr a;
let a_matrix = frodo_gen_matrix gen_a (params_n a) seed_a in
let b_matrix = Matrix.add (Matrix.mul_s a_matrix s_matrix) e_matrix in
b_matrix
val frodo_mul_add_as_plus_e_pack:
a:frodo_alg
-> gen_a:frodo_gen_a
-> seed_a:lbytes bytes_seed_a
-> s_matrix:matrix (params_n a) params_nbar
-> e_matrix:matrix (params_n a) params_nbar
-> lbytes (publicmatrixbytes_len a)
let frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix =
let b_matrix = frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix in
frodo_pack (params_logq a) b_matrix
val get_s_e_matrices:
a:frodo_alg
-> seed_se:lbytes (crypto_bytes a)
-> matrix (params_n a) params_nbar & matrix (params_n a) params_nbar
let get_s_e_matrices a seed_se =
let s_bytes_len = secretmatrixbytes_len a in
let r = frodo_shake_r a (u8 0x5f) seed_se (2 * s_bytes_len) in
let s_matrix = frodo_sample_matrix a (params_n a) params_nbar (LSeq.sub r 0 s_bytes_len) in
let e_matrix = frodo_sample_matrix a (params_n a) params_nbar (LSeq.sub r s_bytes_len s_bytes_len) in
s_matrix, e_matrix
val frodo_mul_add_as_plus_e_pack_shake:
a:frodo_alg
-> gen_a:frodo_gen_a
-> seed_a:lbytes bytes_seed_a
-> seed_se:lbytes (crypto_bytes a)
-> tuple2 (lbytes (publicmatrixbytes_len a)) (lbytes (secretmatrixbytes_len a)) | {
"checked_file": "/",
"dependencies": [
"Spec.Matrix.fst.checked",
"Spec.Frodo.Sample.fst.checked",
"Spec.Frodo.Random.fst.checked",
"Spec.Frodo.Params.fst.checked",
"Spec.Frodo.Pack.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Frodo.KEM.KeyGen.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Matrix",
"short_module": "Matrix"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": false,
"full_module": "Spec.Frodo.Sample",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.Pack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.Params",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Frodo.Params.frodo_alg ->
gen_a: Spec.Frodo.Params.frodo_gen_a ->
seed_a: Lib.ByteSequence.lbytes Spec.Frodo.Params.bytes_seed_a ->
seed_se: Lib.ByteSequence.lbytes (Spec.Frodo.Params.crypto_bytes a)
-> Lib.ByteSequence.lbytes (Spec.Frodo.Params.publicmatrixbytes_len a) *
Lib.ByteSequence.lbytes (Spec.Frodo.Params.secretmatrixbytes_len a) | Prims.Tot | [
"total"
] | [] | [
"Spec.Frodo.Params.frodo_alg",
"Spec.Frodo.Params.frodo_gen_a",
"Lib.ByteSequence.lbytes",
"Spec.Frodo.Params.bytes_seed_a",
"Spec.Frodo.Params.crypto_bytes",
"Spec.Matrix.matrix",
"Spec.Frodo.Params.params_n",
"Spec.Frodo.Params.params_nbar",
"FStar.Pervasives.Native.Mktuple2",
"Spec.Frodo.Params.publicmatrixbytes_len",
"Spec.Frodo.Params.secretmatrixbytes_len",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.op_Multiply",
"Spec.Matrix.matrix_to_lbytes",
"Spec.Frodo.KEM.KeyGen.frodo_mul_add_as_plus_e_pack",
"FStar.Pervasives.Native.tuple2",
"Lib.IntTypes.U16",
"Spec.Frodo.KEM.KeyGen.get_s_e_matrices"
] | [] | false | false | false | false | false | let frodo_mul_add_as_plus_e_pack_shake a gen_a seed_a seed_se =
| let s_matrix, e_matrix = get_s_e_matrices a seed_se in
let b_bytes = frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix in
let s_bytes = matrix_to_lbytes s_matrix in
b_bytes, s_bytes | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.sha256_4 | val sha256_4 : len: Hacl.Spec.SHA2.len_lt_max_a_t Spec.Hash.Definitions.SHA2_256 ->
b: Hacl.Spec.SHA2.Vec.multiseq 4 len
-> Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes Spec.Hash.Definitions.SHA2_256
Hacl.Spec.SHA2.Vec.M128)
(Spec.Hash.Definitions.hash_length Spec.Hash.Definitions.SHA2_256) | let sha256_4 (len:Spec.len_lt_max_a_t SHA2_256) (b:multiseq 4 len) =
hash #SHA2_256 #M128 len b | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 28,
"end_line": 486,
"start_col": 0,
"start_line": 485
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (ws:ws_spec a m) : ws_spec a m =
match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws
noextract
let load_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) : ws_spec a m =
let ws = load_blocks #a #m b in
transpose_ws #a #m ws
noextract
let ws_next_inner (#a:sha2_alg) (#m:m_spec)
(i:nat{i < 16})
(ws:ws_spec a m) : ws_spec a m =
let t16 = ws.[i] in
let t15 = ws.[(i+1) % 16] in
let t7 = ws.[(i+9) % 16] in
let t2 = ws.[(i+14) % 16] in
let s1 = _sigma1 t2 in
let s0 = _sigma0 t15 in
ws.[i] <- (s1 +| t7 +| s0 +| t16)
noextract
let ws_next (#a:sha2_alg) (#m:m_spec)
(ws:ws_spec a m) : ws_spec a m =
repeati 16 (ws_next_inner #a #m) ws
noextract
let shuffle_inner (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (i:nat{i < v (num_rounds16 a)}) (j:nat{j < 16}) (st:state_spec a m) : state_spec a m =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec k_t ws_t st
noextract
let shuffle_inner_loop (#a:sha2_alg) (#m:m_spec) (i:nat{i < v (num_rounds16 a)})
(ws_st:ws_spec a m & state_spec a m) : ws_spec a m & state_spec a m =
let (ws,st) = ws_st in
let st' = repeati 16 (shuffle_inner ws i) st in
let ws' = if i < v (num_rounds16 a) - 1 then ws_next ws else ws in
(ws',st')
noextract
let shuffle (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (st:state_spec a m) : state_spec a m =
let (ws,st) = repeati (v(num_rounds16 a)) (shuffle_inner_loop #a #m) (ws,st) in
st
noextract
let init (a:sha2_alg) (m:m_spec) : state_spec a m =
createi 8 (fun i -> load_element a m (Seq.index (Spec.h0 a) i))
[@"opaque_to_smt"]
noextract
let update (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) (st:state_spec a m): state_spec a m =
let st_old = st in
let ws = load_ws b in
let st_new = shuffle ws st_old in
map2 (+|) st_new st_old
noextract
let padded_blocks (a:sha2_alg) (len:nat{len <= block_length a}) : n:nat{n <= 2} =
if (len + len_length a + 1 <= block_length a) then 1 else 2
noextract
let load_last_blocks (#a:sha2_alg)
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a})
(b:lseq uint8 len) :
lseq uint8 (block_length a) & lseq uint8 (block_length a) =
let last = create (2 * block_length a) (u8 0) in
let last = update_sub last 0 len b in
let last = last.[len] <- u8 0x80 in
let last = update_sub last (fin - len_length a) (len_length a) totlen_seq in
let l0 : lseq uint8 (block_length a) = sub last 0 (block_length a) in
let l1 : lseq uint8 (block_length a) = sub last (block_length a) (block_length a) in
(l0, l1)
noextract
let load_last1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b = b.(|0|) in
let (l0,l1) = load_last_blocks #a totlen_seq fin len b in
let lb0 : multiseq (lanes a m) (block_length a) = ntup1 l0 in
let lb1 : multiseq (lanes a m) (block_length a) = ntup1 l1 in
(lb0, lb1)
#push-options "--z3rlimit 100"
noextract
let load_last4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let mb0 = ntup4 (l00, (l10, (l20, l30))) in
let mb1 = ntup4 (l01, (l11, (l21, l31))) in
(mb0, mb1)
noextract
let load_last8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let b4 = b.(|4|) in
let b5 = b.(|5|) in
let b6 = b.(|6|) in
let b7 = b.(|7|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let (l40,l41) = load_last_blocks #a totlen_seq fin len b4 in
let (l50,l51) = load_last_blocks #a totlen_seq fin len b5 in
let (l60,l61) = load_last_blocks #a totlen_seq fin len b6 in
let (l70,l71) = load_last_blocks #a totlen_seq fin len b7 in
let mb0 = ntup8 (l00, (l10, (l20, (l30, (l40, (l50, (l60, l70))))))) in
let mb1 = ntup8 (l01, (l11, (l21, (l31, (l41, (l51, (l61, l71))))))) in
(mb0, mb1)
#pop-options
[@"opaque_to_smt"]
noextract
let load_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
match lanes a m with
| 1 -> load_last1 #a #m totlen_seq fin len b
| 4 -> load_last4 #a #m totlen_seq fin len b
| 8 -> load_last8 #a #m totlen_seq fin len b
noextract
let update_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen:len_t a)
(len:nat{len <= block_length a})
(b:multiseq (lanes a m) len) (st:state_spec a m): state_spec a m =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
let st = update b0 st in
if blocks > 1 then
update b1 st
else st
noextract
let transpose_state4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(st:state_spec a m) : state_spec a m =
let st0 = st.[0] in
let st1 = st.[1] in
let st2 = st.[2] in
let st3 = st.[3] in
let st4 = st.[4] in
let st5 = st.[5] in
let st6 = st.[6] in
let st7 = st.[7] in
let (st0,st1,st2,st3) = VecTranspose.transpose4x4 (st0,st1,st2,st3) in
let (st4,st5,st6,st7) = VecTranspose.transpose4x4 (st4,st5,st6,st7) in
create8 st0 st4 st1 st5 st2 st6 st3 st7
noextract
let transpose_state8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8})
(st:state_spec a m) : state_spec a m =
let st0 = st.[0] in
let st1 = st.[1] in
let st2 = st.[2] in
let st3 = st.[3] in
let st4 = st.[4] in
let st5 = st.[5] in
let st6 = st.[6] in
let st7 = st.[7] in
let (st0,st1,st2,st3,st4,st5,st6,st7) = VecTranspose.transpose8x8 (st0,st1,st2,st3,st4,st5,st6,st7) in
create8 st0 st1 st2 st3 st4 st5 st6 st7
noextract
let transpose_state (#a:sha2_alg) (#m:m_spec{is_supported a m}) (st:state_spec a m) : state_spec a m =
match lanes a m with
| 1 -> st
| 4 -> transpose_state4 #a #m st
| 8 -> transpose_state8 #a #m st
noextract
let store_state (#a:sha2_alg) (#m:m_spec{is_supported a m}) (st:state_spec a m) :
lseq uint8 (lanes a m * 8 * word_length a) =
let st = transpose_state st in
Lib.IntVector.Serialize.vecs_to_bytes_be st
noextract
let emit (#a:sha2_alg) (#m:m_spec)
(hseq:lseq uint8 (lanes a m * 8 * word_length a)):
multiseq (lanes a m) (hash_length a) =
Lib.NTuple.createi #(Seq.lseq uint8 (hash_length a)) (lanes a m)
(fun i -> sub hseq (i * 8 * word_length a) (hash_length a))
noextract
let get_multiblock_spec (#a:sha2_alg) (#m:m_spec)
(len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len)
(i:nat{i < len / block_length a})
: multiseq (lanes a m) (block_length a) =
Lib.NTuple.createi #(Seq.lseq uint8 (block_length a)) (lanes a m)
(fun j -> Seq.slice b.(|j|) (i * block_length a) (i * block_length a + block_length a))
noextract
let get_multilast_spec (#a:sha2_alg) (#m:m_spec)
(len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len)
: multiseq (lanes a m) (len % block_length a) =
let rem = len % block_length a in
Lib.NTuple.createi #(Seq.lseq uint8 rem) (lanes a m)
(fun j -> Seq.slice b.(|j|) (len - rem) len)
noextract
let update_block (#a:sha2_alg) (#m:m_spec{is_supported a m}) (len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len)
(i:nat{i < len / block_length a}) (st:state_spec a m) : state_spec a m =
let mb = get_multiblock_spec len b i in
update mb st
noextract
let update_nblocks (#a:sha2_alg) (#m:m_spec{is_supported a m}) (len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len) (st:state_spec a m) : state_spec a m =
let blocks = len / block_length a in
let st = repeati blocks (update_block #a #m len b) st in
st
noextract
let finish (#a:sha2_alg) (#m:m_spec{is_supported a m}) (st:state_spec a m) :
multiseq (lanes a m) (hash_length a) =
let hseq = store_state st in
emit hseq
noextract
let hash (#a:sha2_alg) (#m:m_spec{is_supported a m}) (len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len) =
let len' : len_t a = Spec.mk_len_t a len in
let st = init a m in
let st = update_nblocks #a #m len b st in
let rem = len % block_length a in
let mb = get_multilast_spec #a #m len b in
let st = update_last len' rem mb st in
finish st
noextract
let sha256 (len:Spec.len_lt_max_a_t SHA2_256) (b:seq uint8{length b = len}) =
hash #SHA2_256 #M32 len b | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Hacl.Spec.SHA2.len_lt_max_a_t Spec.Hash.Definitions.SHA2_256 ->
b: Hacl.Spec.SHA2.Vec.multiseq 4 len
-> Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes Spec.Hash.Definitions.SHA2_256
Hacl.Spec.SHA2.Vec.M128)
(Spec.Hash.Definitions.hash_length Spec.Hash.Definitions.SHA2_256) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.SHA2.len_lt_max_a_t",
"Spec.Hash.Definitions.SHA2_256",
"Hacl.Spec.SHA2.Vec.multiseq",
"Hacl.Spec.SHA2.Vec.hash",
"Hacl.Spec.SHA2.Vec.M128",
"Hacl.Spec.SHA2.Vec.lanes",
"Spec.Hash.Definitions.hash_length"
] | [] | false | false | false | false | false | let sha256_4 (len: Spec.len_lt_max_a_t SHA2_256) (b: multiseq 4 len) =
| hash #SHA2_256 #M128 len b | false |
|
FStar.Reflection.V1.Derived.Lemmas.fst | FStar.Reflection.V1.Derived.Lemmas.collect_arr_ln_bs_ref | val collect_arr_ln_bs_ref : (t:term) -> list (bd:binder{bd << t})
* (c:comp{ c == pack_comp (C_Total t) \/ c << t}) | val collect_arr_ln_bs_ref : (t:term) -> list (bd:binder{bd << t})
* (c:comp{ c == pack_comp (C_Total t) \/ c << t}) | let collect_arr_ln_bs_ref t =
let bds, c = collect_arr_ln_bs t in
collect_arr_ln_bs_order t;
list_ref bds, c | {
"file_name": "ulib/FStar.Reflection.V1.Derived.Lemmas.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 19,
"end_line": 132,
"start_col": 0,
"start_line": 129
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.V1.Derived.Lemmas
open FStar.Stubs.Reflection.Types
open FStar.Stubs.Reflection.V1.Builtins
open FStar.Stubs.Reflection.V1.Data
open FStar.Reflection.V1.Derived
open FStar.List.Tot
let rec forall_list (p:'a -> Type) (l:list 'a) : Type =
match l with
| [] -> True
| x::xs -> p x /\ forall_list p xs
let forallP (p: 'a -> Type) (l: list 'a): Type
= forall (x: 'a). memP x l ==> p x
// Precedence relation on the element of a list
unfold let (<<:) (l: list 'a) (r: 'r)
= forallP (fun x -> x << r) l
// A glorified `id`
val list_ref : (#a:Type) -> (#p:(a -> Type)) -> (l:list a) ->
Pure (list (x:a{p x}))
(requires (forallP p l))
(ensures (fun _ -> True))
let rec list_ref #a #p l =
match l with
| [] -> []
| x::xs -> x :: list_ref #a #p xs
val collect_app_order' : (args:list argv) -> (tt:term) -> (t:term) ->
Lemma (requires args <<: tt /\ t << tt)
(ensures (let fn, args' = collect_app_ln' args t in
args' <<: tt /\ fn << tt))
(decreases t)
let rec collect_app_order' args tt t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' (r::args) tt l
| _ -> ()
val collect_app_order : (t:term) ->
Lemma (ensures (forall (f:term). forall (s:list argv). (f,s) == collect_app_ln t ==>
(f << t /\ s <<: t)
\/ (f == t /\ s == [])))
let collect_app_order t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' [r] t l
| _ -> ()
val collect_app_ref : (t:term) -> (h:term{h == t \/ h << t}) * list (a:argv{fst a << t})
let collect_app_ref t =
let h, a = collect_app_ln t in
collect_app_order t;
h, list_ref a
(**** [collect_abs_ln t] is smaller than [t] *)
let rec collect_abs_order' (bds: binders) (tt t: term)
: Lemma (requires t << tt /\ bds <<: tt)
(ensures (let bds', body = collect_abs' bds t in
(bds' <<: tt /\ body << tt)))
(decreases t)
= match inspect_ln_unascribe t with
| Tv_Abs b body -> collect_abs_order' (b::bds) tt body
| _ -> ()
val collect_abs_ln_order : (t:term) ->
Lemma (ensures forall bds body.
(bds, body) == collect_abs_ln t ==>
(body << t /\ bds <<: t)
\/ (body == t /\ bds == [])
)
let collect_abs_ln_order t =
match inspect_ln_unascribe t with
| Tv_Abs b body -> collect_abs_order' [b] t body;
let bds, body = collect_abs' [] t in
Classical.forall_intro (rev_memP bds)
| _ -> ()
val collect_abs_ln_ref : (t:term) -> list (bd:binder{bd << t}) * (body:term{body == t \/ body << t})
let collect_abs_ln_ref t =
let bds, body = collect_abs_ln t in
collect_abs_ln_order t;
list_ref bds, body
(**** [collect_arr_ln_bs t] is smaller than [t] *)
let rec collect_arr_order' (bds: binders) (tt: term) (c: comp)
: Lemma (requires c << tt /\ bds <<: tt)
(ensures (let bds', c' = collect_arr' bds c in
bds' <<: tt /\ c' << tt))
(decreases c)
= match inspect_comp c with
| C_Total ret ->
( match inspect_ln_unascribe ret with
| Tv_Arrow b c -> collect_arr_order' (b::bds) tt c
| _ -> ())
| _ -> ()
val collect_arr_ln_bs_order : (t:term) ->
Lemma (ensures forall bds c.
(bds, c) == collect_arr_ln_bs t ==>
(c << t /\ bds <<: t)
\/ (c == pack_comp (C_Total t) /\ bds == [])
)
let collect_arr_ln_bs_order t =
match inspect_ln_unascribe t with
| Tv_Arrow b c -> collect_arr_order' [b] t c;
Classical.forall_intro_2 (rev_memP #binder);
inspect_pack_comp_inv (C_Total t)
| _ -> inspect_pack_comp_inv (C_Total t)
val collect_arr_ln_bs_ref : (t:term) -> list (bd:binder{bd << t}) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Stubs.Reflection.V1.Data.fsti.checked",
"FStar.Stubs.Reflection.V1.Builtins.fsti.checked",
"FStar.Stubs.Reflection.Types.fsti.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V1.Derived.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: FStar.Stubs.Reflection.Types.term
-> Prims.list (bd: FStar.Stubs.Reflection.Types.binder{bd << t}) *
c:
FStar.Stubs.Reflection.Types.comp
{ c == FStar.Stubs.Reflection.V1.Builtins.pack_comp (FStar.Stubs.Reflection.V1.Data.C_Total t) \/
c << t } | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.term",
"Prims.list",
"FStar.Stubs.Reflection.Types.binder",
"FStar.Stubs.Reflection.Types.comp",
"FStar.Pervasives.Native.Mktuple2",
"Prims.precedes",
"Prims.l_or",
"Prims.eq2",
"FStar.Stubs.Reflection.V1.Builtins.pack_comp",
"FStar.Stubs.Reflection.V1.Data.C_Total",
"FStar.Reflection.V1.Derived.Lemmas.list_ref",
"Prims.unit",
"FStar.Reflection.V1.Derived.Lemmas.collect_arr_ln_bs_order",
"FStar.Pervasives.Native.tuple2",
"FStar.Reflection.V1.Derived.collect_arr_ln_bs"
] | [] | false | false | false | false | false | let collect_arr_ln_bs_ref t =
| let bds, c = collect_arr_ln_bs t in
collect_arr_ln_bs_order t;
list_ref bds, c | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.sha256 | val sha256 : len: Hacl.Spec.SHA2.len_lt_max_a_t Spec.Hash.Definitions.SHA2_256 ->
b: Lib.Sequence.seq Lib.IntTypes.uint8 {Lib.Sequence.length b = len}
-> Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes Spec.Hash.Definitions.SHA2_256
Hacl.Spec.SHA2.Vec.M32)
(Spec.Hash.Definitions.hash_length Spec.Hash.Definitions.SHA2_256) | let sha256 (len:Spec.len_lt_max_a_t SHA2_256) (b:seq uint8{length b = len}) =
hash #SHA2_256 #M32 len b | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 27,
"end_line": 482,
"start_col": 0,
"start_line": 481
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (ws:ws_spec a m) : ws_spec a m =
match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws
noextract
let load_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) : ws_spec a m =
let ws = load_blocks #a #m b in
transpose_ws #a #m ws
noextract
let ws_next_inner (#a:sha2_alg) (#m:m_spec)
(i:nat{i < 16})
(ws:ws_spec a m) : ws_spec a m =
let t16 = ws.[i] in
let t15 = ws.[(i+1) % 16] in
let t7 = ws.[(i+9) % 16] in
let t2 = ws.[(i+14) % 16] in
let s1 = _sigma1 t2 in
let s0 = _sigma0 t15 in
ws.[i] <- (s1 +| t7 +| s0 +| t16)
noextract
let ws_next (#a:sha2_alg) (#m:m_spec)
(ws:ws_spec a m) : ws_spec a m =
repeati 16 (ws_next_inner #a #m) ws
noextract
let shuffle_inner (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (i:nat{i < v (num_rounds16 a)}) (j:nat{j < 16}) (st:state_spec a m) : state_spec a m =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec k_t ws_t st
noextract
let shuffle_inner_loop (#a:sha2_alg) (#m:m_spec) (i:nat{i < v (num_rounds16 a)})
(ws_st:ws_spec a m & state_spec a m) : ws_spec a m & state_spec a m =
let (ws,st) = ws_st in
let st' = repeati 16 (shuffle_inner ws i) st in
let ws' = if i < v (num_rounds16 a) - 1 then ws_next ws else ws in
(ws',st')
noextract
let shuffle (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (st:state_spec a m) : state_spec a m =
let (ws,st) = repeati (v(num_rounds16 a)) (shuffle_inner_loop #a #m) (ws,st) in
st
noextract
let init (a:sha2_alg) (m:m_spec) : state_spec a m =
createi 8 (fun i -> load_element a m (Seq.index (Spec.h0 a) i))
[@"opaque_to_smt"]
noextract
let update (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) (st:state_spec a m): state_spec a m =
let st_old = st in
let ws = load_ws b in
let st_new = shuffle ws st_old in
map2 (+|) st_new st_old
noextract
let padded_blocks (a:sha2_alg) (len:nat{len <= block_length a}) : n:nat{n <= 2} =
if (len + len_length a + 1 <= block_length a) then 1 else 2
noextract
let load_last_blocks (#a:sha2_alg)
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a})
(b:lseq uint8 len) :
lseq uint8 (block_length a) & lseq uint8 (block_length a) =
let last = create (2 * block_length a) (u8 0) in
let last = update_sub last 0 len b in
let last = last.[len] <- u8 0x80 in
let last = update_sub last (fin - len_length a) (len_length a) totlen_seq in
let l0 : lseq uint8 (block_length a) = sub last 0 (block_length a) in
let l1 : lseq uint8 (block_length a) = sub last (block_length a) (block_length a) in
(l0, l1)
noextract
let load_last1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b = b.(|0|) in
let (l0,l1) = load_last_blocks #a totlen_seq fin len b in
let lb0 : multiseq (lanes a m) (block_length a) = ntup1 l0 in
let lb1 : multiseq (lanes a m) (block_length a) = ntup1 l1 in
(lb0, lb1)
#push-options "--z3rlimit 100"
noextract
let load_last4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let mb0 = ntup4 (l00, (l10, (l20, l30))) in
let mb1 = ntup4 (l01, (l11, (l21, l31))) in
(mb0, mb1)
noextract
let load_last8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let b4 = b.(|4|) in
let b5 = b.(|5|) in
let b6 = b.(|6|) in
let b7 = b.(|7|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let (l40,l41) = load_last_blocks #a totlen_seq fin len b4 in
let (l50,l51) = load_last_blocks #a totlen_seq fin len b5 in
let (l60,l61) = load_last_blocks #a totlen_seq fin len b6 in
let (l70,l71) = load_last_blocks #a totlen_seq fin len b7 in
let mb0 = ntup8 (l00, (l10, (l20, (l30, (l40, (l50, (l60, l70))))))) in
let mb1 = ntup8 (l01, (l11, (l21, (l31, (l41, (l51, (l61, l71))))))) in
(mb0, mb1)
#pop-options
[@"opaque_to_smt"]
noextract
let load_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
match lanes a m with
| 1 -> load_last1 #a #m totlen_seq fin len b
| 4 -> load_last4 #a #m totlen_seq fin len b
| 8 -> load_last8 #a #m totlen_seq fin len b
noextract
let update_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen:len_t a)
(len:nat{len <= block_length a})
(b:multiseq (lanes a m) len) (st:state_spec a m): state_spec a m =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
let st = update b0 st in
if blocks > 1 then
update b1 st
else st
noextract
let transpose_state4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(st:state_spec a m) : state_spec a m =
let st0 = st.[0] in
let st1 = st.[1] in
let st2 = st.[2] in
let st3 = st.[3] in
let st4 = st.[4] in
let st5 = st.[5] in
let st6 = st.[6] in
let st7 = st.[7] in
let (st0,st1,st2,st3) = VecTranspose.transpose4x4 (st0,st1,st2,st3) in
let (st4,st5,st6,st7) = VecTranspose.transpose4x4 (st4,st5,st6,st7) in
create8 st0 st4 st1 st5 st2 st6 st3 st7
noextract
let transpose_state8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8})
(st:state_spec a m) : state_spec a m =
let st0 = st.[0] in
let st1 = st.[1] in
let st2 = st.[2] in
let st3 = st.[3] in
let st4 = st.[4] in
let st5 = st.[5] in
let st6 = st.[6] in
let st7 = st.[7] in
let (st0,st1,st2,st3,st4,st5,st6,st7) = VecTranspose.transpose8x8 (st0,st1,st2,st3,st4,st5,st6,st7) in
create8 st0 st1 st2 st3 st4 st5 st6 st7
noextract
let transpose_state (#a:sha2_alg) (#m:m_spec{is_supported a m}) (st:state_spec a m) : state_spec a m =
match lanes a m with
| 1 -> st
| 4 -> transpose_state4 #a #m st
| 8 -> transpose_state8 #a #m st
noextract
let store_state (#a:sha2_alg) (#m:m_spec{is_supported a m}) (st:state_spec a m) :
lseq uint8 (lanes a m * 8 * word_length a) =
let st = transpose_state st in
Lib.IntVector.Serialize.vecs_to_bytes_be st
noextract
let emit (#a:sha2_alg) (#m:m_spec)
(hseq:lseq uint8 (lanes a m * 8 * word_length a)):
multiseq (lanes a m) (hash_length a) =
Lib.NTuple.createi #(Seq.lseq uint8 (hash_length a)) (lanes a m)
(fun i -> sub hseq (i * 8 * word_length a) (hash_length a))
noextract
let get_multiblock_spec (#a:sha2_alg) (#m:m_spec)
(len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len)
(i:nat{i < len / block_length a})
: multiseq (lanes a m) (block_length a) =
Lib.NTuple.createi #(Seq.lseq uint8 (block_length a)) (lanes a m)
(fun j -> Seq.slice b.(|j|) (i * block_length a) (i * block_length a + block_length a))
noextract
let get_multilast_spec (#a:sha2_alg) (#m:m_spec)
(len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len)
: multiseq (lanes a m) (len % block_length a) =
let rem = len % block_length a in
Lib.NTuple.createi #(Seq.lseq uint8 rem) (lanes a m)
(fun j -> Seq.slice b.(|j|) (len - rem) len)
noextract
let update_block (#a:sha2_alg) (#m:m_spec{is_supported a m}) (len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len)
(i:nat{i < len / block_length a}) (st:state_spec a m) : state_spec a m =
let mb = get_multiblock_spec len b i in
update mb st
noextract
let update_nblocks (#a:sha2_alg) (#m:m_spec{is_supported a m}) (len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len) (st:state_spec a m) : state_spec a m =
let blocks = len / block_length a in
let st = repeati blocks (update_block #a #m len b) st in
st
noextract
let finish (#a:sha2_alg) (#m:m_spec{is_supported a m}) (st:state_spec a m) :
multiseq (lanes a m) (hash_length a) =
let hseq = store_state st in
emit hseq
noextract
let hash (#a:sha2_alg) (#m:m_spec{is_supported a m}) (len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len) =
let len' : len_t a = Spec.mk_len_t a len in
let st = init a m in
let st = update_nblocks #a #m len b st in
let rem = len % block_length a in
let mb = get_multilast_spec #a #m len b in
let st = update_last len' rem mb st in
finish st | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Hacl.Spec.SHA2.len_lt_max_a_t Spec.Hash.Definitions.SHA2_256 ->
b: Lib.Sequence.seq Lib.IntTypes.uint8 {Lib.Sequence.length b = len}
-> Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes Spec.Hash.Definitions.SHA2_256
Hacl.Spec.SHA2.Vec.M32)
(Spec.Hash.Definitions.hash_length Spec.Hash.Definitions.SHA2_256) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.SHA2.len_lt_max_a_t",
"Spec.Hash.Definitions.SHA2_256",
"Lib.Sequence.seq",
"Lib.IntTypes.uint8",
"Prims.b2t",
"Prims.op_Equality",
"Prims.nat",
"Lib.Sequence.length",
"Hacl.Spec.SHA2.Vec.hash",
"Hacl.Spec.SHA2.Vec.M32",
"Hacl.Spec.SHA2.Vec.multiseq",
"Hacl.Spec.SHA2.Vec.lanes",
"Spec.Hash.Definitions.hash_length"
] | [] | false | false | false | false | false | let sha256 (len: Spec.len_lt_max_a_t SHA2_256) (b: seq uint8 {length b = len}) =
| hash #SHA2_256 #M32 len b | false |
|
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.get_multilast_spec | val get_multilast_spec
(#a: sha2_alg)
(#m: m_spec)
(len: Spec.len_lt_max_a_t a)
(b: multiseq (lanes a m) len)
: multiseq (lanes a m) (len % block_length a) | val get_multilast_spec
(#a: sha2_alg)
(#m: m_spec)
(len: Spec.len_lt_max_a_t a)
(b: multiseq (lanes a m) len)
: multiseq (lanes a m) (len % block_length a) | let get_multilast_spec (#a:sha2_alg) (#m:m_spec)
(len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len)
: multiseq (lanes a m) (len % block_length a) =
let rem = len % block_length a in
Lib.NTuple.createi #(Seq.lseq uint8 rem) (lanes a m)
(fun j -> Seq.slice b.(|j|) (len - rem) len) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 450,
"start_col": 0,
"start_line": 445
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (ws:ws_spec a m) : ws_spec a m =
match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws
noextract
let load_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) : ws_spec a m =
let ws = load_blocks #a #m b in
transpose_ws #a #m ws
noextract
let ws_next_inner (#a:sha2_alg) (#m:m_spec)
(i:nat{i < 16})
(ws:ws_spec a m) : ws_spec a m =
let t16 = ws.[i] in
let t15 = ws.[(i+1) % 16] in
let t7 = ws.[(i+9) % 16] in
let t2 = ws.[(i+14) % 16] in
let s1 = _sigma1 t2 in
let s0 = _sigma0 t15 in
ws.[i] <- (s1 +| t7 +| s0 +| t16)
noextract
let ws_next (#a:sha2_alg) (#m:m_spec)
(ws:ws_spec a m) : ws_spec a m =
repeati 16 (ws_next_inner #a #m) ws
noextract
let shuffle_inner (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (i:nat{i < v (num_rounds16 a)}) (j:nat{j < 16}) (st:state_spec a m) : state_spec a m =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec k_t ws_t st
noextract
let shuffle_inner_loop (#a:sha2_alg) (#m:m_spec) (i:nat{i < v (num_rounds16 a)})
(ws_st:ws_spec a m & state_spec a m) : ws_spec a m & state_spec a m =
let (ws,st) = ws_st in
let st' = repeati 16 (shuffle_inner ws i) st in
let ws' = if i < v (num_rounds16 a) - 1 then ws_next ws else ws in
(ws',st')
noextract
let shuffle (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (st:state_spec a m) : state_spec a m =
let (ws,st) = repeati (v(num_rounds16 a)) (shuffle_inner_loop #a #m) (ws,st) in
st
noextract
let init (a:sha2_alg) (m:m_spec) : state_spec a m =
createi 8 (fun i -> load_element a m (Seq.index (Spec.h0 a) i))
[@"opaque_to_smt"]
noextract
let update (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) (st:state_spec a m): state_spec a m =
let st_old = st in
let ws = load_ws b in
let st_new = shuffle ws st_old in
map2 (+|) st_new st_old
noextract
let padded_blocks (a:sha2_alg) (len:nat{len <= block_length a}) : n:nat{n <= 2} =
if (len + len_length a + 1 <= block_length a) then 1 else 2
noextract
let load_last_blocks (#a:sha2_alg)
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a})
(b:lseq uint8 len) :
lseq uint8 (block_length a) & lseq uint8 (block_length a) =
let last = create (2 * block_length a) (u8 0) in
let last = update_sub last 0 len b in
let last = last.[len] <- u8 0x80 in
let last = update_sub last (fin - len_length a) (len_length a) totlen_seq in
let l0 : lseq uint8 (block_length a) = sub last 0 (block_length a) in
let l1 : lseq uint8 (block_length a) = sub last (block_length a) (block_length a) in
(l0, l1)
noextract
let load_last1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b = b.(|0|) in
let (l0,l1) = load_last_blocks #a totlen_seq fin len b in
let lb0 : multiseq (lanes a m) (block_length a) = ntup1 l0 in
let lb1 : multiseq (lanes a m) (block_length a) = ntup1 l1 in
(lb0, lb1)
#push-options "--z3rlimit 100"
noextract
let load_last4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let mb0 = ntup4 (l00, (l10, (l20, l30))) in
let mb1 = ntup4 (l01, (l11, (l21, l31))) in
(mb0, mb1)
noextract
let load_last8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let b4 = b.(|4|) in
let b5 = b.(|5|) in
let b6 = b.(|6|) in
let b7 = b.(|7|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let (l40,l41) = load_last_blocks #a totlen_seq fin len b4 in
let (l50,l51) = load_last_blocks #a totlen_seq fin len b5 in
let (l60,l61) = load_last_blocks #a totlen_seq fin len b6 in
let (l70,l71) = load_last_blocks #a totlen_seq fin len b7 in
let mb0 = ntup8 (l00, (l10, (l20, (l30, (l40, (l50, (l60, l70))))))) in
let mb1 = ntup8 (l01, (l11, (l21, (l31, (l41, (l51, (l61, l71))))))) in
(mb0, mb1)
#pop-options
[@"opaque_to_smt"]
noextract
let load_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
match lanes a m with
| 1 -> load_last1 #a #m totlen_seq fin len b
| 4 -> load_last4 #a #m totlen_seq fin len b
| 8 -> load_last8 #a #m totlen_seq fin len b
noextract
let update_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen:len_t a)
(len:nat{len <= block_length a})
(b:multiseq (lanes a m) len) (st:state_spec a m): state_spec a m =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
let st = update b0 st in
if blocks > 1 then
update b1 st
else st
noextract
let transpose_state4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(st:state_spec a m) : state_spec a m =
let st0 = st.[0] in
let st1 = st.[1] in
let st2 = st.[2] in
let st3 = st.[3] in
let st4 = st.[4] in
let st5 = st.[5] in
let st6 = st.[6] in
let st7 = st.[7] in
let (st0,st1,st2,st3) = VecTranspose.transpose4x4 (st0,st1,st2,st3) in
let (st4,st5,st6,st7) = VecTranspose.transpose4x4 (st4,st5,st6,st7) in
create8 st0 st4 st1 st5 st2 st6 st3 st7
noextract
let transpose_state8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8})
(st:state_spec a m) : state_spec a m =
let st0 = st.[0] in
let st1 = st.[1] in
let st2 = st.[2] in
let st3 = st.[3] in
let st4 = st.[4] in
let st5 = st.[5] in
let st6 = st.[6] in
let st7 = st.[7] in
let (st0,st1,st2,st3,st4,st5,st6,st7) = VecTranspose.transpose8x8 (st0,st1,st2,st3,st4,st5,st6,st7) in
create8 st0 st1 st2 st3 st4 st5 st6 st7
noextract
let transpose_state (#a:sha2_alg) (#m:m_spec{is_supported a m}) (st:state_spec a m) : state_spec a m =
match lanes a m with
| 1 -> st
| 4 -> transpose_state4 #a #m st
| 8 -> transpose_state8 #a #m st
noextract
let store_state (#a:sha2_alg) (#m:m_spec{is_supported a m}) (st:state_spec a m) :
lseq uint8 (lanes a m * 8 * word_length a) =
let st = transpose_state st in
Lib.IntVector.Serialize.vecs_to_bytes_be st
noextract
let emit (#a:sha2_alg) (#m:m_spec)
(hseq:lseq uint8 (lanes a m * 8 * word_length a)):
multiseq (lanes a m) (hash_length a) =
Lib.NTuple.createi #(Seq.lseq uint8 (hash_length a)) (lanes a m)
(fun i -> sub hseq (i * 8 * word_length a) (hash_length a))
noextract
let get_multiblock_spec (#a:sha2_alg) (#m:m_spec)
(len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len)
(i:nat{i < len / block_length a})
: multiseq (lanes a m) (block_length a) =
Lib.NTuple.createi #(Seq.lseq uint8 (block_length a)) (lanes a m)
(fun j -> Seq.slice b.(|j|) (i * block_length a) (i * block_length a + block_length a)) | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Hacl.Spec.SHA2.len_lt_max_a_t a ->
b: Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m) len
-> Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m)
(len % Spec.Hash.Definitions.block_length a) | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.len_lt_max_a_t",
"Hacl.Spec.SHA2.Vec.multiseq",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.NTuple.createi",
"FStar.Seq.Properties.lseq",
"Lib.IntTypes.uint8",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.slice",
"Lib.NTuple.op_Lens_Access",
"Prims.op_Subtraction",
"Prims.int",
"Prims.op_Modulus",
"Spec.Hash.Definitions.block_length"
] | [] | false | false | false | false | false | let get_multilast_spec
(#a: sha2_alg)
(#m: m_spec)
(len: Spec.len_lt_max_a_t a)
(b: multiseq (lanes a m) len)
: multiseq (lanes a m) (len % block_length a) =
| let rem = len % block_length a in
Lib.NTuple.createi #(Seq.lseq uint8 rem) (lanes a m) (fun j -> Seq.slice b.(| j |) (len - rem) len) | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.load_last | val load_last
(#a: sha2_alg)
(#m: m_spec{is_supported a m})
(totlen_seq: lseq uint8 (len_length a))
(fin: nat{fin == block_length a \/ fin == 2 * block_length a})
(len: nat{len <= block_length a})
(b: multiseq (lanes a m) len)
: multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) | val load_last
(#a: sha2_alg)
(#m: m_spec{is_supported a m})
(totlen_seq: lseq uint8 (len_length a))
(fin: nat{fin == block_length a \/ fin == 2 * block_length a})
(len: nat{len <= block_length a})
(b: multiseq (lanes a m) len)
: multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) | let load_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
match lanes a m with
| 1 -> load_last1 #a #m totlen_seq fin len b
| 4 -> load_last4 #a #m totlen_seq fin len b
| 8 -> load_last8 #a #m totlen_seq fin len b | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 48,
"end_line": 370,
"start_col": 0,
"start_line": 363
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (ws:ws_spec a m) : ws_spec a m =
match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws
noextract
let load_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) : ws_spec a m =
let ws = load_blocks #a #m b in
transpose_ws #a #m ws
noextract
let ws_next_inner (#a:sha2_alg) (#m:m_spec)
(i:nat{i < 16})
(ws:ws_spec a m) : ws_spec a m =
let t16 = ws.[i] in
let t15 = ws.[(i+1) % 16] in
let t7 = ws.[(i+9) % 16] in
let t2 = ws.[(i+14) % 16] in
let s1 = _sigma1 t2 in
let s0 = _sigma0 t15 in
ws.[i] <- (s1 +| t7 +| s0 +| t16)
noextract
let ws_next (#a:sha2_alg) (#m:m_spec)
(ws:ws_spec a m) : ws_spec a m =
repeati 16 (ws_next_inner #a #m) ws
noextract
let shuffle_inner (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (i:nat{i < v (num_rounds16 a)}) (j:nat{j < 16}) (st:state_spec a m) : state_spec a m =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec k_t ws_t st
noextract
let shuffle_inner_loop (#a:sha2_alg) (#m:m_spec) (i:nat{i < v (num_rounds16 a)})
(ws_st:ws_spec a m & state_spec a m) : ws_spec a m & state_spec a m =
let (ws,st) = ws_st in
let st' = repeati 16 (shuffle_inner ws i) st in
let ws' = if i < v (num_rounds16 a) - 1 then ws_next ws else ws in
(ws',st')
noextract
let shuffle (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (st:state_spec a m) : state_spec a m =
let (ws,st) = repeati (v(num_rounds16 a)) (shuffle_inner_loop #a #m) (ws,st) in
st
noextract
let init (a:sha2_alg) (m:m_spec) : state_spec a m =
createi 8 (fun i -> load_element a m (Seq.index (Spec.h0 a) i))
[@"opaque_to_smt"]
noextract
let update (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) (st:state_spec a m): state_spec a m =
let st_old = st in
let ws = load_ws b in
let st_new = shuffle ws st_old in
map2 (+|) st_new st_old
noextract
let padded_blocks (a:sha2_alg) (len:nat{len <= block_length a}) : n:nat{n <= 2} =
if (len + len_length a + 1 <= block_length a) then 1 else 2
noextract
let load_last_blocks (#a:sha2_alg)
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a})
(b:lseq uint8 len) :
lseq uint8 (block_length a) & lseq uint8 (block_length a) =
let last = create (2 * block_length a) (u8 0) in
let last = update_sub last 0 len b in
let last = last.[len] <- u8 0x80 in
let last = update_sub last (fin - len_length a) (len_length a) totlen_seq in
let l0 : lseq uint8 (block_length a) = sub last 0 (block_length a) in
let l1 : lseq uint8 (block_length a) = sub last (block_length a) (block_length a) in
(l0, l1)
noextract
let load_last1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b = b.(|0|) in
let (l0,l1) = load_last_blocks #a totlen_seq fin len b in
let lb0 : multiseq (lanes a m) (block_length a) = ntup1 l0 in
let lb1 : multiseq (lanes a m) (block_length a) = ntup1 l1 in
(lb0, lb1)
#push-options "--z3rlimit 100"
noextract
let load_last4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let mb0 = ntup4 (l00, (l10, (l20, l30))) in
let mb1 = ntup4 (l01, (l11, (l21, l31))) in
(mb0, mb1)
noextract
let load_last8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let b4 = b.(|4|) in
let b5 = b.(|5|) in
let b6 = b.(|6|) in
let b7 = b.(|7|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let (l40,l41) = load_last_blocks #a totlen_seq fin len b4 in
let (l50,l51) = load_last_blocks #a totlen_seq fin len b5 in
let (l60,l61) = load_last_blocks #a totlen_seq fin len b6 in
let (l70,l71) = load_last_blocks #a totlen_seq fin len b7 in
let mb0 = ntup8 (l00, (l10, (l20, (l30, (l40, (l50, (l60, l70))))))) in
let mb1 = ntup8 (l01, (l11, (l21, (l31, (l41, (l51, (l61, l71))))))) in
(mb0, mb1)
#pop-options
[@"opaque_to_smt"] | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
totlen_seq: Lib.Sequence.lseq Lib.IntTypes.uint8 (Spec.Hash.Definitions.len_length a) ->
fin:
Prims.nat
{ fin == Spec.Hash.Definitions.block_length a \/
fin == 2 * Spec.Hash.Definitions.block_length a } ->
len: Prims.nat{len <= Spec.Hash.Definitions.block_length a} ->
b: Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m) len
-> Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m)
(Spec.Hash.Definitions.block_length a) *
Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m)
(Spec.Hash.Definitions.block_length a) | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint8",
"Spec.Hash.Definitions.len_length",
"Prims.nat",
"Prims.l_or",
"Prims.eq2",
"Prims.int",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_disEquality",
"Spec.Hash.Definitions.block_length",
"FStar.Mul.op_Star",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.SHA2.Vec.multiseq",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Vec.load_last1",
"Hacl.Spec.SHA2.Vec.load_last4",
"Hacl.Spec.SHA2.Vec.load_last8",
"FStar.Pervasives.Native.tuple2"
] | [] | false | false | false | false | false | let load_last
(#a: sha2_alg)
(#m: m_spec{is_supported a m})
(totlen_seq: lseq uint8 (len_length a))
(fin: nat{fin == block_length a \/ fin == 2 * block_length a})
(len: nat{len <= block_length a})
(b: multiseq (lanes a m) len)
: multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
| match lanes a m with
| 1 -> load_last1 #a #m totlen_seq fin len b
| 4 -> load_last4 #a #m totlen_seq fin len b
| 8 -> load_last8 #a #m totlen_seq fin len b | false |
FStar.Reflection.V1.Derived.Lemmas.fst | FStar.Reflection.V1.Derived.Lemmas.collect_arr_ln_bs_order | val collect_arr_ln_bs_order : (t:term) ->
Lemma (ensures forall bds c.
(bds, c) == collect_arr_ln_bs t ==>
(c << t /\ bds <<: t)
\/ (c == pack_comp (C_Total t) /\ bds == [])
) | val collect_arr_ln_bs_order : (t:term) ->
Lemma (ensures forall bds c.
(bds, c) == collect_arr_ln_bs t ==>
(c << t /\ bds <<: t)
\/ (c == pack_comp (C_Total t) /\ bds == [])
) | let collect_arr_ln_bs_order t =
match inspect_ln_unascribe t with
| Tv_Arrow b c -> collect_arr_order' [b] t c;
Classical.forall_intro_2 (rev_memP #binder);
inspect_pack_comp_inv (C_Total t)
| _ -> inspect_pack_comp_inv (C_Total t) | {
"file_name": "ulib/FStar.Reflection.V1.Derived.Lemmas.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 42,
"end_line": 125,
"start_col": 0,
"start_line": 120
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Reflection.V1.Derived.Lemmas
open FStar.Stubs.Reflection.Types
open FStar.Stubs.Reflection.V1.Builtins
open FStar.Stubs.Reflection.V1.Data
open FStar.Reflection.V1.Derived
open FStar.List.Tot
let rec forall_list (p:'a -> Type) (l:list 'a) : Type =
match l with
| [] -> True
| x::xs -> p x /\ forall_list p xs
let forallP (p: 'a -> Type) (l: list 'a): Type
= forall (x: 'a). memP x l ==> p x
// Precedence relation on the element of a list
unfold let (<<:) (l: list 'a) (r: 'r)
= forallP (fun x -> x << r) l
// A glorified `id`
val list_ref : (#a:Type) -> (#p:(a -> Type)) -> (l:list a) ->
Pure (list (x:a{p x}))
(requires (forallP p l))
(ensures (fun _ -> True))
let rec list_ref #a #p l =
match l with
| [] -> []
| x::xs -> x :: list_ref #a #p xs
val collect_app_order' : (args:list argv) -> (tt:term) -> (t:term) ->
Lemma (requires args <<: tt /\ t << tt)
(ensures (let fn, args' = collect_app_ln' args t in
args' <<: tt /\ fn << tt))
(decreases t)
let rec collect_app_order' args tt t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' (r::args) tt l
| _ -> ()
val collect_app_order : (t:term) ->
Lemma (ensures (forall (f:term). forall (s:list argv). (f,s) == collect_app_ln t ==>
(f << t /\ s <<: t)
\/ (f == t /\ s == [])))
let collect_app_order t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' [r] t l
| _ -> ()
val collect_app_ref : (t:term) -> (h:term{h == t \/ h << t}) * list (a:argv{fst a << t})
let collect_app_ref t =
let h, a = collect_app_ln t in
collect_app_order t;
h, list_ref a
(**** [collect_abs_ln t] is smaller than [t] *)
let rec collect_abs_order' (bds: binders) (tt t: term)
: Lemma (requires t << tt /\ bds <<: tt)
(ensures (let bds', body = collect_abs' bds t in
(bds' <<: tt /\ body << tt)))
(decreases t)
= match inspect_ln_unascribe t with
| Tv_Abs b body -> collect_abs_order' (b::bds) tt body
| _ -> ()
val collect_abs_ln_order : (t:term) ->
Lemma (ensures forall bds body.
(bds, body) == collect_abs_ln t ==>
(body << t /\ bds <<: t)
\/ (body == t /\ bds == [])
)
let collect_abs_ln_order t =
match inspect_ln_unascribe t with
| Tv_Abs b body -> collect_abs_order' [b] t body;
let bds, body = collect_abs' [] t in
Classical.forall_intro (rev_memP bds)
| _ -> ()
val collect_abs_ln_ref : (t:term) -> list (bd:binder{bd << t}) * (body:term{body == t \/ body << t})
let collect_abs_ln_ref t =
let bds, body = collect_abs_ln t in
collect_abs_ln_order t;
list_ref bds, body
(**** [collect_arr_ln_bs t] is smaller than [t] *)
let rec collect_arr_order' (bds: binders) (tt: term) (c: comp)
: Lemma (requires c << tt /\ bds <<: tt)
(ensures (let bds', c' = collect_arr' bds c in
bds' <<: tt /\ c' << tt))
(decreases c)
= match inspect_comp c with
| C_Total ret ->
( match inspect_ln_unascribe ret with
| Tv_Arrow b c -> collect_arr_order' (b::bds) tt c
| _ -> ())
| _ -> ()
val collect_arr_ln_bs_order : (t:term) ->
Lemma (ensures forall bds c.
(bds, c) == collect_arr_ln_bs t ==>
(c << t /\ bds <<: t)
\/ (c == pack_comp (C_Total t) /\ bds == []) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Stubs.Reflection.V1.Data.fsti.checked",
"FStar.Stubs.Reflection.V1.Builtins.fsti.checked",
"FStar.Stubs.Reflection.Types.fsti.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Reflection.V1.Derived.Lemmas.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: FStar.Stubs.Reflection.Types.term
-> FStar.Pervasives.Lemma
(ensures
forall (bds: Prims.list FStar.Stubs.Reflection.Types.binder)
(c: FStar.Stubs.Reflection.Types.comp).
(bds, c) == FStar.Reflection.V1.Derived.collect_arr_ln_bs t ==>
c << t /\ bds <<: t \/
c == FStar.Stubs.Reflection.V1.Builtins.pack_comp (FStar.Stubs.Reflection.V1.Data.C_Total t) /\
bds == []) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Stubs.Reflection.Types.term",
"FStar.Reflection.V1.Derived.inspect_ln_unascribe",
"FStar.Stubs.Reflection.Types.binder",
"FStar.Stubs.Reflection.Types.comp",
"FStar.Stubs.Reflection.V1.Builtins.inspect_pack_comp_inv",
"FStar.Stubs.Reflection.V1.Data.C_Total",
"Prims.unit",
"FStar.Classical.forall_intro_2",
"Prims.list",
"Prims.l_iff",
"FStar.List.Tot.Base.memP",
"FStar.List.Tot.Base.rev",
"FStar.List.Tot.Properties.rev_memP",
"FStar.Reflection.V1.Derived.Lemmas.collect_arr_order'",
"Prims.Cons",
"Prims.Nil",
"FStar.Stubs.Reflection.V1.Data.term_view"
] | [] | false | false | true | false | false | let collect_arr_ln_bs_order t =
| match inspect_ln_unascribe t with
| Tv_Arrow b c ->
collect_arr_order' [b] t c;
Classical.forall_intro_2 (rev_memP #binder);
inspect_pack_comp_inv (C_Total t)
| _ -> inspect_pack_comp_inv (C_Total t) | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.load_elementi | val load_elementi
(#a: sha2_alg)
(#m: m_spec)
(b: lseq uint8 (block_length a))
(bi: nat{bi < 16 / lanes a m})
: element_t a m | val load_elementi
(#a: sha2_alg)
(#m: m_spec)
(b: lseq uint8 (block_length a))
(bi: nat{bi < 16 / lanes a m})
: element_t a m | let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a)) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 85,
"end_line": 193,
"start_col": 0,
"start_line": 191
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a) | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Lib.Sequence.lseq Lib.IntTypes.uint8 (Spec.Hash.Definitions.block_length a) ->
bi: Prims.nat{bi < 16 / Hacl.Spec.SHA2.Vec.lanes a m}
-> Hacl.Spec.SHA2.Vec.element_t a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint8",
"Spec.Hash.Definitions.block_length",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Division",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.IntVector.vec_from_bytes_be",
"Spec.Hash.Definitions.word_t",
"Lib.Sequence.sub",
"FStar.Mul.op_Star",
"Spec.Hash.Definitions.word_length",
"Hacl.Spec.SHA2.Vec.lanes_t",
"Hacl.Spec.SHA2.Vec.element_t"
] | [] | false | false | false | false | false | let load_elementi
(#a: sha2_alg)
(#m: m_spec)
(b: lseq uint8 (block_length a))
(bi: nat{bi < 16 / lanes a m})
: element_t a m =
| let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b ((bi * l) * word_length a) (l * word_length a)) | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.finish | val finish (#a: sha2_alg) (#m: m_spec{is_supported a m}) (st: state_spec a m)
: multiseq (lanes a m) (hash_length a) | val finish (#a: sha2_alg) (#m: m_spec{is_supported a m}) (st: state_spec a m)
: multiseq (lanes a m) (hash_length a) | let finish (#a:sha2_alg) (#m:m_spec{is_supported a m}) (st:state_spec a m) :
multiseq (lanes a m) (hash_length a) =
let hseq = store_state st in
emit hseq | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 13,
"end_line": 468,
"start_col": 0,
"start_line": 465
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (ws:ws_spec a m) : ws_spec a m =
match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws
noextract
let load_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) : ws_spec a m =
let ws = load_blocks #a #m b in
transpose_ws #a #m ws
noextract
let ws_next_inner (#a:sha2_alg) (#m:m_spec)
(i:nat{i < 16})
(ws:ws_spec a m) : ws_spec a m =
let t16 = ws.[i] in
let t15 = ws.[(i+1) % 16] in
let t7 = ws.[(i+9) % 16] in
let t2 = ws.[(i+14) % 16] in
let s1 = _sigma1 t2 in
let s0 = _sigma0 t15 in
ws.[i] <- (s1 +| t7 +| s0 +| t16)
noextract
let ws_next (#a:sha2_alg) (#m:m_spec)
(ws:ws_spec a m) : ws_spec a m =
repeati 16 (ws_next_inner #a #m) ws
noextract
let shuffle_inner (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (i:nat{i < v (num_rounds16 a)}) (j:nat{j < 16}) (st:state_spec a m) : state_spec a m =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec k_t ws_t st
noextract
let shuffle_inner_loop (#a:sha2_alg) (#m:m_spec) (i:nat{i < v (num_rounds16 a)})
(ws_st:ws_spec a m & state_spec a m) : ws_spec a m & state_spec a m =
let (ws,st) = ws_st in
let st' = repeati 16 (shuffle_inner ws i) st in
let ws' = if i < v (num_rounds16 a) - 1 then ws_next ws else ws in
(ws',st')
noextract
let shuffle (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (st:state_spec a m) : state_spec a m =
let (ws,st) = repeati (v(num_rounds16 a)) (shuffle_inner_loop #a #m) (ws,st) in
st
noextract
let init (a:sha2_alg) (m:m_spec) : state_spec a m =
createi 8 (fun i -> load_element a m (Seq.index (Spec.h0 a) i))
[@"opaque_to_smt"]
noextract
let update (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) (st:state_spec a m): state_spec a m =
let st_old = st in
let ws = load_ws b in
let st_new = shuffle ws st_old in
map2 (+|) st_new st_old
noextract
let padded_blocks (a:sha2_alg) (len:nat{len <= block_length a}) : n:nat{n <= 2} =
if (len + len_length a + 1 <= block_length a) then 1 else 2
noextract
let load_last_blocks (#a:sha2_alg)
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a})
(b:lseq uint8 len) :
lseq uint8 (block_length a) & lseq uint8 (block_length a) =
let last = create (2 * block_length a) (u8 0) in
let last = update_sub last 0 len b in
let last = last.[len] <- u8 0x80 in
let last = update_sub last (fin - len_length a) (len_length a) totlen_seq in
let l0 : lseq uint8 (block_length a) = sub last 0 (block_length a) in
let l1 : lseq uint8 (block_length a) = sub last (block_length a) (block_length a) in
(l0, l1)
noextract
let load_last1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b = b.(|0|) in
let (l0,l1) = load_last_blocks #a totlen_seq fin len b in
let lb0 : multiseq (lanes a m) (block_length a) = ntup1 l0 in
let lb1 : multiseq (lanes a m) (block_length a) = ntup1 l1 in
(lb0, lb1)
#push-options "--z3rlimit 100"
noextract
let load_last4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let mb0 = ntup4 (l00, (l10, (l20, l30))) in
let mb1 = ntup4 (l01, (l11, (l21, l31))) in
(mb0, mb1)
noextract
let load_last8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let b4 = b.(|4|) in
let b5 = b.(|5|) in
let b6 = b.(|6|) in
let b7 = b.(|7|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let (l40,l41) = load_last_blocks #a totlen_seq fin len b4 in
let (l50,l51) = load_last_blocks #a totlen_seq fin len b5 in
let (l60,l61) = load_last_blocks #a totlen_seq fin len b6 in
let (l70,l71) = load_last_blocks #a totlen_seq fin len b7 in
let mb0 = ntup8 (l00, (l10, (l20, (l30, (l40, (l50, (l60, l70))))))) in
let mb1 = ntup8 (l01, (l11, (l21, (l31, (l41, (l51, (l61, l71))))))) in
(mb0, mb1)
#pop-options
[@"opaque_to_smt"]
noextract
let load_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
match lanes a m with
| 1 -> load_last1 #a #m totlen_seq fin len b
| 4 -> load_last4 #a #m totlen_seq fin len b
| 8 -> load_last8 #a #m totlen_seq fin len b
noextract
let update_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen:len_t a)
(len:nat{len <= block_length a})
(b:multiseq (lanes a m) len) (st:state_spec a m): state_spec a m =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
let st = update b0 st in
if blocks > 1 then
update b1 st
else st
noextract
let transpose_state4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(st:state_spec a m) : state_spec a m =
let st0 = st.[0] in
let st1 = st.[1] in
let st2 = st.[2] in
let st3 = st.[3] in
let st4 = st.[4] in
let st5 = st.[5] in
let st6 = st.[6] in
let st7 = st.[7] in
let (st0,st1,st2,st3) = VecTranspose.transpose4x4 (st0,st1,st2,st3) in
let (st4,st5,st6,st7) = VecTranspose.transpose4x4 (st4,st5,st6,st7) in
create8 st0 st4 st1 st5 st2 st6 st3 st7
noextract
let transpose_state8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8})
(st:state_spec a m) : state_spec a m =
let st0 = st.[0] in
let st1 = st.[1] in
let st2 = st.[2] in
let st3 = st.[3] in
let st4 = st.[4] in
let st5 = st.[5] in
let st6 = st.[6] in
let st7 = st.[7] in
let (st0,st1,st2,st3,st4,st5,st6,st7) = VecTranspose.transpose8x8 (st0,st1,st2,st3,st4,st5,st6,st7) in
create8 st0 st1 st2 st3 st4 st5 st6 st7
noextract
let transpose_state (#a:sha2_alg) (#m:m_spec{is_supported a m}) (st:state_spec a m) : state_spec a m =
match lanes a m with
| 1 -> st
| 4 -> transpose_state4 #a #m st
| 8 -> transpose_state8 #a #m st
noextract
let store_state (#a:sha2_alg) (#m:m_spec{is_supported a m}) (st:state_spec a m) :
lseq uint8 (lanes a m * 8 * word_length a) =
let st = transpose_state st in
Lib.IntVector.Serialize.vecs_to_bytes_be st
noextract
let emit (#a:sha2_alg) (#m:m_spec)
(hseq:lseq uint8 (lanes a m * 8 * word_length a)):
multiseq (lanes a m) (hash_length a) =
Lib.NTuple.createi #(Seq.lseq uint8 (hash_length a)) (lanes a m)
(fun i -> sub hseq (i * 8 * word_length a) (hash_length a))
noextract
let get_multiblock_spec (#a:sha2_alg) (#m:m_spec)
(len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len)
(i:nat{i < len / block_length a})
: multiseq (lanes a m) (block_length a) =
Lib.NTuple.createi #(Seq.lseq uint8 (block_length a)) (lanes a m)
(fun j -> Seq.slice b.(|j|) (i * block_length a) (i * block_length a + block_length a))
noextract
let get_multilast_spec (#a:sha2_alg) (#m:m_spec)
(len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len)
: multiseq (lanes a m) (len % block_length a) =
let rem = len % block_length a in
Lib.NTuple.createi #(Seq.lseq uint8 rem) (lanes a m)
(fun j -> Seq.slice b.(|j|) (len - rem) len)
noextract
let update_block (#a:sha2_alg) (#m:m_spec{is_supported a m}) (len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len)
(i:nat{i < len / block_length a}) (st:state_spec a m) : state_spec a m =
let mb = get_multiblock_spec len b i in
update mb st
noextract
let update_nblocks (#a:sha2_alg) (#m:m_spec{is_supported a m}) (len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len) (st:state_spec a m) : state_spec a m =
let blocks = len / block_length a in
let st = repeati blocks (update_block #a #m len b) st in
st | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | st: Hacl.Spec.SHA2.Vec.state_spec a m
-> Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m)
(Spec.Hash.Definitions.hash_length a) | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Hacl.Spec.SHA2.Vec.state_spec",
"Hacl.Spec.SHA2.Vec.emit",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.op_Multiply",
"Hacl.Spec.SHA2.Vec.lanes",
"Spec.Hash.Definitions.word_length",
"Hacl.Spec.SHA2.Vec.store_state",
"Hacl.Spec.SHA2.Vec.multiseq",
"Spec.Hash.Definitions.hash_length"
] | [] | false | false | false | false | false | let finish (#a: sha2_alg) (#m: m_spec{is_supported a m}) (st: state_spec a m)
: multiseq (lanes a m) (hash_length a) =
| let hseq = store_state st in
emit hseq | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.transpose_state4 | val transpose_state4 (#a: sha2_alg) (#m: m_spec{lanes a m == 4}) (st: state_spec a m)
: state_spec a m | val transpose_state4 (#a: sha2_alg) (#m: m_spec{lanes a m == 4}) (st: state_spec a m)
: state_spec a m | let transpose_state4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(st:state_spec a m) : state_spec a m =
let st0 = st.[0] in
let st1 = st.[1] in
let st2 = st.[2] in
let st3 = st.[3] in
let st4 = st.[4] in
let st5 = st.[5] in
let st6 = st.[6] in
let st7 = st.[7] in
let (st0,st1,st2,st3) = VecTranspose.transpose4x4 (st0,st1,st2,st3) in
let (st4,st5,st6,st7) = VecTranspose.transpose4x4 (st4,st5,st6,st7) in
create8 st0 st4 st1 st5 st2 st6 st3 st7 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 43,
"end_line": 399,
"start_col": 0,
"start_line": 387
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (ws:ws_spec a m) : ws_spec a m =
match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws
noextract
let load_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) : ws_spec a m =
let ws = load_blocks #a #m b in
transpose_ws #a #m ws
noextract
let ws_next_inner (#a:sha2_alg) (#m:m_spec)
(i:nat{i < 16})
(ws:ws_spec a m) : ws_spec a m =
let t16 = ws.[i] in
let t15 = ws.[(i+1) % 16] in
let t7 = ws.[(i+9) % 16] in
let t2 = ws.[(i+14) % 16] in
let s1 = _sigma1 t2 in
let s0 = _sigma0 t15 in
ws.[i] <- (s1 +| t7 +| s0 +| t16)
noextract
let ws_next (#a:sha2_alg) (#m:m_spec)
(ws:ws_spec a m) : ws_spec a m =
repeati 16 (ws_next_inner #a #m) ws
noextract
let shuffle_inner (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (i:nat{i < v (num_rounds16 a)}) (j:nat{j < 16}) (st:state_spec a m) : state_spec a m =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec k_t ws_t st
noextract
let shuffle_inner_loop (#a:sha2_alg) (#m:m_spec) (i:nat{i < v (num_rounds16 a)})
(ws_st:ws_spec a m & state_spec a m) : ws_spec a m & state_spec a m =
let (ws,st) = ws_st in
let st' = repeati 16 (shuffle_inner ws i) st in
let ws' = if i < v (num_rounds16 a) - 1 then ws_next ws else ws in
(ws',st')
noextract
let shuffle (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (st:state_spec a m) : state_spec a m =
let (ws,st) = repeati (v(num_rounds16 a)) (shuffle_inner_loop #a #m) (ws,st) in
st
noextract
let init (a:sha2_alg) (m:m_spec) : state_spec a m =
createi 8 (fun i -> load_element a m (Seq.index (Spec.h0 a) i))
[@"opaque_to_smt"]
noextract
let update (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) (st:state_spec a m): state_spec a m =
let st_old = st in
let ws = load_ws b in
let st_new = shuffle ws st_old in
map2 (+|) st_new st_old
noextract
let padded_blocks (a:sha2_alg) (len:nat{len <= block_length a}) : n:nat{n <= 2} =
if (len + len_length a + 1 <= block_length a) then 1 else 2
noextract
let load_last_blocks (#a:sha2_alg)
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a})
(b:lseq uint8 len) :
lseq uint8 (block_length a) & lseq uint8 (block_length a) =
let last = create (2 * block_length a) (u8 0) in
let last = update_sub last 0 len b in
let last = last.[len] <- u8 0x80 in
let last = update_sub last (fin - len_length a) (len_length a) totlen_seq in
let l0 : lseq uint8 (block_length a) = sub last 0 (block_length a) in
let l1 : lseq uint8 (block_length a) = sub last (block_length a) (block_length a) in
(l0, l1)
noextract
let load_last1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b = b.(|0|) in
let (l0,l1) = load_last_blocks #a totlen_seq fin len b in
let lb0 : multiseq (lanes a m) (block_length a) = ntup1 l0 in
let lb1 : multiseq (lanes a m) (block_length a) = ntup1 l1 in
(lb0, lb1)
#push-options "--z3rlimit 100"
noextract
let load_last4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let mb0 = ntup4 (l00, (l10, (l20, l30))) in
let mb1 = ntup4 (l01, (l11, (l21, l31))) in
(mb0, mb1)
noextract
let load_last8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let b4 = b.(|4|) in
let b5 = b.(|5|) in
let b6 = b.(|6|) in
let b7 = b.(|7|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let (l40,l41) = load_last_blocks #a totlen_seq fin len b4 in
let (l50,l51) = load_last_blocks #a totlen_seq fin len b5 in
let (l60,l61) = load_last_blocks #a totlen_seq fin len b6 in
let (l70,l71) = load_last_blocks #a totlen_seq fin len b7 in
let mb0 = ntup8 (l00, (l10, (l20, (l30, (l40, (l50, (l60, l70))))))) in
let mb1 = ntup8 (l01, (l11, (l21, (l31, (l41, (l51, (l61, l71))))))) in
(mb0, mb1)
#pop-options
[@"opaque_to_smt"]
noextract
let load_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
match lanes a m with
| 1 -> load_last1 #a #m totlen_seq fin len b
| 4 -> load_last4 #a #m totlen_seq fin len b
| 8 -> load_last8 #a #m totlen_seq fin len b
noextract
let update_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen:len_t a)
(len:nat{len <= block_length a})
(b:multiseq (lanes a m) len) (st:state_spec a m): state_spec a m =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
let st = update b0 st in
if blocks > 1 then
update b1 st
else st | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | st: Hacl.Spec.SHA2.Vec.state_spec a m -> Hacl.Spec.SHA2.Vec.state_spec a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Prims.eq2",
"Prims.int",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Spec.SHA2.Vec.state_spec",
"Lib.IntVector.vec_t",
"Spec.Hash.Definitions.word_t",
"Lib.Sequence.create8",
"Hacl.Spec.SHA2.Vec.element_t",
"Lib.IntVector.Transpose.vec_t4",
"Lib.IntVector.Transpose.transpose4x4",
"FStar.Pervasives.Native.Mktuple4",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Lib.Sequence.op_String_Access"
] | [] | false | false | false | false | false | let transpose_state4 (#a: sha2_alg) (#m: m_spec{lanes a m == 4}) (st: state_spec a m)
: state_spec a m =
| let st0 = st.[ 0 ] in
let st1 = st.[ 1 ] in
let st2 = st.[ 2 ] in
let st3 = st.[ 3 ] in
let st4 = st.[ 4 ] in
let st5 = st.[ 5 ] in
let st6 = st.[ 6 ] in
let st7 = st.[ 7 ] in
let st0, st1, st2, st3 = VecTranspose.transpose4x4 (st0, st1, st2, st3) in
let st4, st5, st6, st7 = VecTranspose.transpose4x4 (st4, st5, st6, st7) in
create8 st0 st4 st1 st5 st2 st6 st3 st7 | false |
Spec.Frodo.KEM.KeyGen.fst | Spec.Frodo.KEM.KeyGen.crypto_kem_keypair_ | val crypto_kem_keypair_:
a:frodo_alg
-> gen_a:frodo_gen_a
-> coins:lbytes (2 * crypto_bytes a + bytes_seed_a)
-> tuple2 (lbytes (crypto_publickeybytes a)) (lbytes (crypto_secretkeybytes a)) | val crypto_kem_keypair_:
a:frodo_alg
-> gen_a:frodo_gen_a
-> coins:lbytes (2 * crypto_bytes a + bytes_seed_a)
-> tuple2 (lbytes (crypto_publickeybytes a)) (lbytes (crypto_secretkeybytes a)) | let crypto_kem_keypair_ a gen_a coins =
expand_crypto_publickeybytes a;
expand_crypto_secretkeybytes a;
let s = LSeq.sub coins 0 (crypto_bytes a) in
let seed_se = LSeq.sub coins (crypto_bytes a) (crypto_bytes a) in
let z = LSeq.sub coins (2 * crypto_bytes a) bytes_seed_a in
let seed_a = frodo_shake a bytes_seed_a z bytes_seed_a in
let b_bytes, s_bytes = frodo_mul_add_as_plus_e_pack_shake a gen_a seed_a seed_se in
let pk = concat seed_a b_bytes in
let sk = crypto_kem_sk a s pk s_bytes in
pk, sk | {
"file_name": "specs/frodo/Spec.Frodo.KEM.KeyGen.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 8,
"end_line": 119,
"start_col": 0,
"start_line": 107
} | module Spec.Frodo.KEM.KeyGen
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Matrix
open Spec.Frodo.Params
open Spec.Frodo.Pack
open Spec.Frodo.Sample
module LSeq = Lib.Sequence
module Matrix = Spec.Matrix
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val frodo_shake_r:
a:frodo_alg
-> c:uint8
-> seed_se:lbytes (crypto_bytes a)
-> output_len:size_nat
-> lbytes output_len
let frodo_shake_r a c seed_se output_len =
let tmp = LSeq.create 1 c in
let shake_input_seed_se = LSeq.concat tmp seed_se in
frodo_shake a (1 + crypto_bytes a) shake_input_seed_se output_len
val frodo_mul_add_as_plus_e:
a:frodo_alg
-> gen_a:frodo_gen_a
-> seed_a:lbytes bytes_seed_a
-> s_matrix:matrix (params_n a) params_nbar
-> e_matrix:matrix (params_n a) params_nbar
-> matrix (params_n a) params_nbar
let frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix =
params_n_sqr a;
let a_matrix = frodo_gen_matrix gen_a (params_n a) seed_a in
let b_matrix = Matrix.add (Matrix.mul_s a_matrix s_matrix) e_matrix in
b_matrix
val frodo_mul_add_as_plus_e_pack:
a:frodo_alg
-> gen_a:frodo_gen_a
-> seed_a:lbytes bytes_seed_a
-> s_matrix:matrix (params_n a) params_nbar
-> e_matrix:matrix (params_n a) params_nbar
-> lbytes (publicmatrixbytes_len a)
let frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix =
let b_matrix = frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix in
frodo_pack (params_logq a) b_matrix
val get_s_e_matrices:
a:frodo_alg
-> seed_se:lbytes (crypto_bytes a)
-> matrix (params_n a) params_nbar & matrix (params_n a) params_nbar
let get_s_e_matrices a seed_se =
let s_bytes_len = secretmatrixbytes_len a in
let r = frodo_shake_r a (u8 0x5f) seed_se (2 * s_bytes_len) in
let s_matrix = frodo_sample_matrix a (params_n a) params_nbar (LSeq.sub r 0 s_bytes_len) in
let e_matrix = frodo_sample_matrix a (params_n a) params_nbar (LSeq.sub r s_bytes_len s_bytes_len) in
s_matrix, e_matrix
val frodo_mul_add_as_plus_e_pack_shake:
a:frodo_alg
-> gen_a:frodo_gen_a
-> seed_a:lbytes bytes_seed_a
-> seed_se:lbytes (crypto_bytes a)
-> tuple2 (lbytes (publicmatrixbytes_len a)) (lbytes (secretmatrixbytes_len a))
let frodo_mul_add_as_plus_e_pack_shake a gen_a seed_a seed_se =
let s_matrix, e_matrix = get_s_e_matrices a seed_se in
let b_bytes = frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix in
let s_bytes = matrix_to_lbytes s_matrix in
b_bytes, s_bytes
val crypto_kem_sk:
a:frodo_alg
-> s:lbytes (crypto_bytes a)
-> pk:lbytes (crypto_publickeybytes a)
-> s_bytes:lbytes (secretmatrixbytes_len a)
-> lbytes (crypto_secretkeybytes a)
let crypto_kem_sk a s pk s_bytes =
let sk = concat (concat s pk) s_bytes in
let pkh = frodo_shake a (crypto_publickeybytes a) pk (bytes_pkhash a) in
let sk_pkh = concat sk pkh in
sk_pkh
val crypto_kem_keypair_:
a:frodo_alg
-> gen_a:frodo_gen_a
-> coins:lbytes (2 * crypto_bytes a + bytes_seed_a)
-> tuple2 (lbytes (crypto_publickeybytes a)) (lbytes (crypto_secretkeybytes a)) | {
"checked_file": "/",
"dependencies": [
"Spec.Matrix.fst.checked",
"Spec.Frodo.Sample.fst.checked",
"Spec.Frodo.Random.fst.checked",
"Spec.Frodo.Params.fst.checked",
"Spec.Frodo.Pack.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Frodo.KEM.KeyGen.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Matrix",
"short_module": "Matrix"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": false,
"full_module": "Spec.Frodo.Sample",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.Pack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.Params",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Frodo.Params.frodo_alg ->
gen_a: Spec.Frodo.Params.frodo_gen_a ->
coins:
Lib.ByteSequence.lbytes (2 * Spec.Frodo.Params.crypto_bytes a + Spec.Frodo.Params.bytes_seed_a
)
-> Lib.ByteSequence.lbytes (Spec.Frodo.Params.crypto_publickeybytes a) *
Lib.ByteSequence.lbytes (Spec.Frodo.Params.crypto_secretkeybytes a) | Prims.Tot | [
"total"
] | [] | [
"Spec.Frodo.Params.frodo_alg",
"Spec.Frodo.Params.frodo_gen_a",
"Lib.ByteSequence.lbytes",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Spec.Frodo.Params.crypto_bytes",
"Spec.Frodo.Params.bytes_seed_a",
"Spec.Frodo.Params.publicmatrixbytes_len",
"Spec.Frodo.Params.secretmatrixbytes_len",
"FStar.Pervasives.Native.Mktuple2",
"Spec.Frodo.Params.crypto_publickeybytes",
"Spec.Frodo.Params.crypto_secretkeybytes",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Spec.Frodo.KEM.KeyGen.crypto_kem_sk",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.append",
"Lib.Sequence.concat",
"Lib.IntTypes.uint_t",
"FStar.Pervasives.Native.tuple2",
"Spec.Frodo.KEM.KeyGen.frodo_mul_add_as_plus_e_pack_shake",
"Spec.Frodo.Params.frodo_shake",
"Prims.l_and",
"FStar.Seq.Base.slice",
"Prims.op_Multiply",
"Prims.l_Forall",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.index",
"Lib.Sequence.sub",
"Prims.unit",
"Spec.Frodo.Params.expand_crypto_secretkeybytes",
"Spec.Frodo.Params.expand_crypto_publickeybytes"
] | [] | false | false | false | false | false | let crypto_kem_keypair_ a gen_a coins =
| expand_crypto_publickeybytes a;
expand_crypto_secretkeybytes a;
let s = LSeq.sub coins 0 (crypto_bytes a) in
let seed_se = LSeq.sub coins (crypto_bytes a) (crypto_bytes a) in
let z = LSeq.sub coins (2 * crypto_bytes a) bytes_seed_a in
let seed_a = frodo_shake a bytes_seed_a z bytes_seed_a in
let b_bytes, s_bytes = frodo_mul_add_as_plus_e_pack_shake a gen_a seed_a seed_se in
let pk = concat seed_a b_bytes in
let sk = crypto_kem_sk a s pk s_bytes in
pk, sk | false |
Spec.Frodo.KEM.KeyGen.fst | Spec.Frodo.KEM.KeyGen.frodo_mul_add_as_plus_e_pack | val frodo_mul_add_as_plus_e_pack:
a:frodo_alg
-> gen_a:frodo_gen_a
-> seed_a:lbytes bytes_seed_a
-> s_matrix:matrix (params_n a) params_nbar
-> e_matrix:matrix (params_n a) params_nbar
-> lbytes (publicmatrixbytes_len a) | val frodo_mul_add_as_plus_e_pack:
a:frodo_alg
-> gen_a:frodo_gen_a
-> seed_a:lbytes bytes_seed_a
-> s_matrix:matrix (params_n a) params_nbar
-> e_matrix:matrix (params_n a) params_nbar
-> lbytes (publicmatrixbytes_len a) | let frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix =
let b_matrix = frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix in
frodo_pack (params_logq a) b_matrix | {
"file_name": "specs/frodo/Spec.Frodo.KEM.KeyGen.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 37,
"end_line": 57,
"start_col": 0,
"start_line": 55
} | module Spec.Frodo.KEM.KeyGen
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
open Spec.Matrix
open Spec.Frodo.Params
open Spec.Frodo.Pack
open Spec.Frodo.Sample
module LSeq = Lib.Sequence
module Matrix = Spec.Matrix
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val frodo_shake_r:
a:frodo_alg
-> c:uint8
-> seed_se:lbytes (crypto_bytes a)
-> output_len:size_nat
-> lbytes output_len
let frodo_shake_r a c seed_se output_len =
let tmp = LSeq.create 1 c in
let shake_input_seed_se = LSeq.concat tmp seed_se in
frodo_shake a (1 + crypto_bytes a) shake_input_seed_se output_len
val frodo_mul_add_as_plus_e:
a:frodo_alg
-> gen_a:frodo_gen_a
-> seed_a:lbytes bytes_seed_a
-> s_matrix:matrix (params_n a) params_nbar
-> e_matrix:matrix (params_n a) params_nbar
-> matrix (params_n a) params_nbar
let frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix =
params_n_sqr a;
let a_matrix = frodo_gen_matrix gen_a (params_n a) seed_a in
let b_matrix = Matrix.add (Matrix.mul_s a_matrix s_matrix) e_matrix in
b_matrix
val frodo_mul_add_as_plus_e_pack:
a:frodo_alg
-> gen_a:frodo_gen_a
-> seed_a:lbytes bytes_seed_a
-> s_matrix:matrix (params_n a) params_nbar
-> e_matrix:matrix (params_n a) params_nbar
-> lbytes (publicmatrixbytes_len a) | {
"checked_file": "/",
"dependencies": [
"Spec.Matrix.fst.checked",
"Spec.Frodo.Sample.fst.checked",
"Spec.Frodo.Random.fst.checked",
"Spec.Frodo.Params.fst.checked",
"Spec.Frodo.Pack.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Frodo.KEM.KeyGen.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Matrix",
"short_module": "Matrix"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": false,
"full_module": "Spec.Frodo.Sample",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.Pack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.Params",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Frodo.KEM",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Frodo.Params.frodo_alg ->
gen_a: Spec.Frodo.Params.frodo_gen_a ->
seed_a: Lib.ByteSequence.lbytes Spec.Frodo.Params.bytes_seed_a ->
s_matrix: Spec.Matrix.matrix (Spec.Frodo.Params.params_n a) Spec.Frodo.Params.params_nbar ->
e_matrix: Spec.Matrix.matrix (Spec.Frodo.Params.params_n a) Spec.Frodo.Params.params_nbar
-> Lib.ByteSequence.lbytes (Spec.Frodo.Params.publicmatrixbytes_len a) | Prims.Tot | [
"total"
] | [] | [
"Spec.Frodo.Params.frodo_alg",
"Spec.Frodo.Params.frodo_gen_a",
"Lib.ByteSequence.lbytes",
"Spec.Frodo.Params.bytes_seed_a",
"Spec.Matrix.matrix",
"Spec.Frodo.Params.params_n",
"Spec.Frodo.Params.params_nbar",
"Spec.Frodo.Pack.frodo_pack",
"Spec.Frodo.Params.params_logq",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U16",
"Lib.IntTypes.SEC",
"Prims.op_Multiply",
"Spec.Frodo.KEM.KeyGen.frodo_mul_add_as_plus_e",
"Spec.Frodo.Params.publicmatrixbytes_len"
] | [] | false | false | false | false | false | let frodo_mul_add_as_plus_e_pack a gen_a seed_a s_matrix e_matrix =
| let b_matrix = frodo_mul_add_as_plus_e a gen_a seed_a s_matrix e_matrix in
frodo_pack (params_logq a) b_matrix | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.load_last4 | val load_last4
(#a: sha2_alg)
(#m: m_spec{lanes a m == 4})
(totlen_seq: lseq uint8 (len_length a))
(fin: nat{fin == block_length a \/ fin == 2 * block_length a})
(len: nat{len <= block_length a})
(b: multiseq (lanes a m) len)
: multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) | val load_last4
(#a: sha2_alg)
(#m: m_spec{lanes a m == 4})
(totlen_seq: lseq uint8 (len_length a))
(fin: nat{fin == block_length a \/ fin == 2 * block_length a})
(len: nat{len <= block_length a})
(b: multiseq (lanes a m) len)
: multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) | let load_last4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let mb0 = ntup4 (l00, (l10, (l20, l30))) in
let mb1 = ntup4 (l01, (l11, (l21, l31))) in
(mb0, mb1) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 14,
"end_line": 332,
"start_col": 0,
"start_line": 317
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (ws:ws_spec a m) : ws_spec a m =
match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws
noextract
let load_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) : ws_spec a m =
let ws = load_blocks #a #m b in
transpose_ws #a #m ws
noextract
let ws_next_inner (#a:sha2_alg) (#m:m_spec)
(i:nat{i < 16})
(ws:ws_spec a m) : ws_spec a m =
let t16 = ws.[i] in
let t15 = ws.[(i+1) % 16] in
let t7 = ws.[(i+9) % 16] in
let t2 = ws.[(i+14) % 16] in
let s1 = _sigma1 t2 in
let s0 = _sigma0 t15 in
ws.[i] <- (s1 +| t7 +| s0 +| t16)
noextract
let ws_next (#a:sha2_alg) (#m:m_spec)
(ws:ws_spec a m) : ws_spec a m =
repeati 16 (ws_next_inner #a #m) ws
noextract
let shuffle_inner (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (i:nat{i < v (num_rounds16 a)}) (j:nat{j < 16}) (st:state_spec a m) : state_spec a m =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec k_t ws_t st
noextract
let shuffle_inner_loop (#a:sha2_alg) (#m:m_spec) (i:nat{i < v (num_rounds16 a)})
(ws_st:ws_spec a m & state_spec a m) : ws_spec a m & state_spec a m =
let (ws,st) = ws_st in
let st' = repeati 16 (shuffle_inner ws i) st in
let ws' = if i < v (num_rounds16 a) - 1 then ws_next ws else ws in
(ws',st')
noextract
let shuffle (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (st:state_spec a m) : state_spec a m =
let (ws,st) = repeati (v(num_rounds16 a)) (shuffle_inner_loop #a #m) (ws,st) in
st
noextract
let init (a:sha2_alg) (m:m_spec) : state_spec a m =
createi 8 (fun i -> load_element a m (Seq.index (Spec.h0 a) i))
[@"opaque_to_smt"]
noextract
let update (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) (st:state_spec a m): state_spec a m =
let st_old = st in
let ws = load_ws b in
let st_new = shuffle ws st_old in
map2 (+|) st_new st_old
noextract
let padded_blocks (a:sha2_alg) (len:nat{len <= block_length a}) : n:nat{n <= 2} =
if (len + len_length a + 1 <= block_length a) then 1 else 2
noextract
let load_last_blocks (#a:sha2_alg)
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a})
(b:lseq uint8 len) :
lseq uint8 (block_length a) & lseq uint8 (block_length a) =
let last = create (2 * block_length a) (u8 0) in
let last = update_sub last 0 len b in
let last = last.[len] <- u8 0x80 in
let last = update_sub last (fin - len_length a) (len_length a) totlen_seq in
let l0 : lseq uint8 (block_length a) = sub last 0 (block_length a) in
let l1 : lseq uint8 (block_length a) = sub last (block_length a) (block_length a) in
(l0, l1)
noextract
let load_last1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b = b.(|0|) in
let (l0,l1) = load_last_blocks #a totlen_seq fin len b in
let lb0 : multiseq (lanes a m) (block_length a) = ntup1 l0 in
let lb1 : multiseq (lanes a m) (block_length a) = ntup1 l1 in
(lb0, lb1)
#push-options "--z3rlimit 100" | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
totlen_seq: Lib.Sequence.lseq Lib.IntTypes.uint8 (Spec.Hash.Definitions.len_length a) ->
fin:
Prims.nat
{ fin == Spec.Hash.Definitions.block_length a \/
fin == 2 * Spec.Hash.Definitions.block_length a } ->
len: Prims.nat{len <= Spec.Hash.Definitions.block_length a} ->
b: Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m) len
-> Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m)
(Spec.Hash.Definitions.block_length a) *
Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m)
(Spec.Hash.Definitions.block_length a) | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Prims.eq2",
"Prims.int",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint8",
"Spec.Hash.Definitions.len_length",
"Prims.nat",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_disEquality",
"Spec.Hash.Definitions.block_length",
"FStar.Mul.op_Star",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.SHA2.Vec.multiseq",
"FStar.Pervasives.Native.Mktuple2",
"Lib.NTuple.ntuple",
"FStar.Seq.Properties.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.NTuple.ntup4",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.SHA2.Vec.load_last_blocks",
"Lib.NTuple.op_Lens_Access"
] | [] | false | false | false | false | false | let load_last4
(#a: sha2_alg)
(#m: m_spec{lanes a m == 4})
(totlen_seq: lseq uint8 (len_length a))
(fin: nat{fin == block_length a \/ fin == 2 * block_length a})
(len: nat{len <= block_length a})
(b: multiseq (lanes a m) len)
: multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
| let b0 = b.(| 0 |) in
let b1 = b.(| 1 |) in
let b2 = b.(| 2 |) in
let b3 = b.(| 3 |) in
let l00, l01 = load_last_blocks #a totlen_seq fin len b0 in
let l10, l11 = load_last_blocks #a totlen_seq fin len b1 in
let l20, l21 = load_last_blocks #a totlen_seq fin len b2 in
let l30, l31 = load_last_blocks #a totlen_seq fin len b3 in
let mb0 = ntup4 (l00, (l10, (l20, l30))) in
let mb1 = ntup4 (l01, (l11, (l21, l31))) in
(mb0, mb1) | false |
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.sha512 | val sha512 : len: Hacl.Spec.SHA2.len_lt_max_a_t Spec.Hash.Definitions.SHA2_512 ->
b: Lib.Sequence.seq Lib.IntTypes.uint8 {Lib.Sequence.length b = len}
-> Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes Spec.Hash.Definitions.SHA2_512
Hacl.Spec.SHA2.Vec.M32)
(Spec.Hash.Definitions.hash_length Spec.Hash.Definitions.SHA2_512) | let sha512 (len:Spec.len_lt_max_a_t SHA2_512) (b:seq uint8{length b = len}) =
hash #SHA2_512 #M32 len b | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 27,
"end_line": 490,
"start_col": 0,
"start_line": 489
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (ws:ws_spec a m) : ws_spec a m =
match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws
noextract
let load_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) : ws_spec a m =
let ws = load_blocks #a #m b in
transpose_ws #a #m ws
noextract
let ws_next_inner (#a:sha2_alg) (#m:m_spec)
(i:nat{i < 16})
(ws:ws_spec a m) : ws_spec a m =
let t16 = ws.[i] in
let t15 = ws.[(i+1) % 16] in
let t7 = ws.[(i+9) % 16] in
let t2 = ws.[(i+14) % 16] in
let s1 = _sigma1 t2 in
let s0 = _sigma0 t15 in
ws.[i] <- (s1 +| t7 +| s0 +| t16)
noextract
let ws_next (#a:sha2_alg) (#m:m_spec)
(ws:ws_spec a m) : ws_spec a m =
repeati 16 (ws_next_inner #a #m) ws
noextract
let shuffle_inner (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (i:nat{i < v (num_rounds16 a)}) (j:nat{j < 16}) (st:state_spec a m) : state_spec a m =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec k_t ws_t st
noextract
let shuffle_inner_loop (#a:sha2_alg) (#m:m_spec) (i:nat{i < v (num_rounds16 a)})
(ws_st:ws_spec a m & state_spec a m) : ws_spec a m & state_spec a m =
let (ws,st) = ws_st in
let st' = repeati 16 (shuffle_inner ws i) st in
let ws' = if i < v (num_rounds16 a) - 1 then ws_next ws else ws in
(ws',st')
noextract
let shuffle (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (st:state_spec a m) : state_spec a m =
let (ws,st) = repeati (v(num_rounds16 a)) (shuffle_inner_loop #a #m) (ws,st) in
st
noextract
let init (a:sha2_alg) (m:m_spec) : state_spec a m =
createi 8 (fun i -> load_element a m (Seq.index (Spec.h0 a) i))
[@"opaque_to_smt"]
noextract
let update (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) (st:state_spec a m): state_spec a m =
let st_old = st in
let ws = load_ws b in
let st_new = shuffle ws st_old in
map2 (+|) st_new st_old
noextract
let padded_blocks (a:sha2_alg) (len:nat{len <= block_length a}) : n:nat{n <= 2} =
if (len + len_length a + 1 <= block_length a) then 1 else 2
noextract
let load_last_blocks (#a:sha2_alg)
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a})
(b:lseq uint8 len) :
lseq uint8 (block_length a) & lseq uint8 (block_length a) =
let last = create (2 * block_length a) (u8 0) in
let last = update_sub last 0 len b in
let last = last.[len] <- u8 0x80 in
let last = update_sub last (fin - len_length a) (len_length a) totlen_seq in
let l0 : lseq uint8 (block_length a) = sub last 0 (block_length a) in
let l1 : lseq uint8 (block_length a) = sub last (block_length a) (block_length a) in
(l0, l1)
noextract
let load_last1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b = b.(|0|) in
let (l0,l1) = load_last_blocks #a totlen_seq fin len b in
let lb0 : multiseq (lanes a m) (block_length a) = ntup1 l0 in
let lb1 : multiseq (lanes a m) (block_length a) = ntup1 l1 in
(lb0, lb1)
#push-options "--z3rlimit 100"
noextract
let load_last4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let mb0 = ntup4 (l00, (l10, (l20, l30))) in
let mb1 = ntup4 (l01, (l11, (l21, l31))) in
(mb0, mb1)
noextract
let load_last8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b0 = b.(|0|) in
let b1 = b.(|1|) in
let b2 = b.(|2|) in
let b3 = b.(|3|) in
let b4 = b.(|4|) in
let b5 = b.(|5|) in
let b6 = b.(|6|) in
let b7 = b.(|7|) in
let (l00,l01) = load_last_blocks #a totlen_seq fin len b0 in
let (l10,l11) = load_last_blocks #a totlen_seq fin len b1 in
let (l20,l21) = load_last_blocks #a totlen_seq fin len b2 in
let (l30,l31) = load_last_blocks #a totlen_seq fin len b3 in
let (l40,l41) = load_last_blocks #a totlen_seq fin len b4 in
let (l50,l51) = load_last_blocks #a totlen_seq fin len b5 in
let (l60,l61) = load_last_blocks #a totlen_seq fin len b6 in
let (l70,l71) = load_last_blocks #a totlen_seq fin len b7 in
let mb0 = ntup8 (l00, (l10, (l20, (l30, (l40, (l50, (l60, l70))))))) in
let mb1 = ntup8 (l01, (l11, (l21, (l31, (l41, (l51, (l61, l71))))))) in
(mb0, mb1)
#pop-options
[@"opaque_to_smt"]
noextract
let load_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
match lanes a m with
| 1 -> load_last1 #a #m totlen_seq fin len b
| 4 -> load_last4 #a #m totlen_seq fin len b
| 8 -> load_last8 #a #m totlen_seq fin len b
noextract
let update_last (#a:sha2_alg) (#m:m_spec{is_supported a m}) (totlen:len_t a)
(len:nat{len <= block_length a})
(b:multiseq (lanes a m) len) (st:state_spec a m): state_spec a m =
let blocks = padded_blocks a len in
let fin : nat = blocks * block_length a in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
let totlen_seq = Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits in
let (b0,b1) = load_last #a #m totlen_seq fin len b in
let st = update b0 st in
if blocks > 1 then
update b1 st
else st
noextract
let transpose_state4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4})
(st:state_spec a m) : state_spec a m =
let st0 = st.[0] in
let st1 = st.[1] in
let st2 = st.[2] in
let st3 = st.[3] in
let st4 = st.[4] in
let st5 = st.[5] in
let st6 = st.[6] in
let st7 = st.[7] in
let (st0,st1,st2,st3) = VecTranspose.transpose4x4 (st0,st1,st2,st3) in
let (st4,st5,st6,st7) = VecTranspose.transpose4x4 (st4,st5,st6,st7) in
create8 st0 st4 st1 st5 st2 st6 st3 st7
noextract
let transpose_state8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8})
(st:state_spec a m) : state_spec a m =
let st0 = st.[0] in
let st1 = st.[1] in
let st2 = st.[2] in
let st3 = st.[3] in
let st4 = st.[4] in
let st5 = st.[5] in
let st6 = st.[6] in
let st7 = st.[7] in
let (st0,st1,st2,st3,st4,st5,st6,st7) = VecTranspose.transpose8x8 (st0,st1,st2,st3,st4,st5,st6,st7) in
create8 st0 st1 st2 st3 st4 st5 st6 st7
noextract
let transpose_state (#a:sha2_alg) (#m:m_spec{is_supported a m}) (st:state_spec a m) : state_spec a m =
match lanes a m with
| 1 -> st
| 4 -> transpose_state4 #a #m st
| 8 -> transpose_state8 #a #m st
noextract
let store_state (#a:sha2_alg) (#m:m_spec{is_supported a m}) (st:state_spec a m) :
lseq uint8 (lanes a m * 8 * word_length a) =
let st = transpose_state st in
Lib.IntVector.Serialize.vecs_to_bytes_be st
noextract
let emit (#a:sha2_alg) (#m:m_spec)
(hseq:lseq uint8 (lanes a m * 8 * word_length a)):
multiseq (lanes a m) (hash_length a) =
Lib.NTuple.createi #(Seq.lseq uint8 (hash_length a)) (lanes a m)
(fun i -> sub hseq (i * 8 * word_length a) (hash_length a))
noextract
let get_multiblock_spec (#a:sha2_alg) (#m:m_spec)
(len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len)
(i:nat{i < len / block_length a})
: multiseq (lanes a m) (block_length a) =
Lib.NTuple.createi #(Seq.lseq uint8 (block_length a)) (lanes a m)
(fun j -> Seq.slice b.(|j|) (i * block_length a) (i * block_length a + block_length a))
noextract
let get_multilast_spec (#a:sha2_alg) (#m:m_spec)
(len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len)
: multiseq (lanes a m) (len % block_length a) =
let rem = len % block_length a in
Lib.NTuple.createi #(Seq.lseq uint8 rem) (lanes a m)
(fun j -> Seq.slice b.(|j|) (len - rem) len)
noextract
let update_block (#a:sha2_alg) (#m:m_spec{is_supported a m}) (len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len)
(i:nat{i < len / block_length a}) (st:state_spec a m) : state_spec a m =
let mb = get_multiblock_spec len b i in
update mb st
noextract
let update_nblocks (#a:sha2_alg) (#m:m_spec{is_supported a m}) (len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len) (st:state_spec a m) : state_spec a m =
let blocks = len / block_length a in
let st = repeati blocks (update_block #a #m len b) st in
st
noextract
let finish (#a:sha2_alg) (#m:m_spec{is_supported a m}) (st:state_spec a m) :
multiseq (lanes a m) (hash_length a) =
let hseq = store_state st in
emit hseq
noextract
let hash (#a:sha2_alg) (#m:m_spec{is_supported a m}) (len:Spec.len_lt_max_a_t a) (b:multiseq (lanes a m) len) =
let len' : len_t a = Spec.mk_len_t a len in
let st = init a m in
let st = update_nblocks #a #m len b st in
let rem = len % block_length a in
let mb = get_multilast_spec #a #m len b in
let st = update_last len' rem mb st in
finish st
noextract
let sha256 (len:Spec.len_lt_max_a_t SHA2_256) (b:seq uint8{length b = len}) =
hash #SHA2_256 #M32 len b
noextract
let sha256_4 (len:Spec.len_lt_max_a_t SHA2_256) (b:multiseq 4 len) =
hash #SHA2_256 #M128 len b | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Hacl.Spec.SHA2.len_lt_max_a_t Spec.Hash.Definitions.SHA2_512 ->
b: Lib.Sequence.seq Lib.IntTypes.uint8 {Lib.Sequence.length b = len}
-> Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes Spec.Hash.Definitions.SHA2_512
Hacl.Spec.SHA2.Vec.M32)
(Spec.Hash.Definitions.hash_length Spec.Hash.Definitions.SHA2_512) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.SHA2.len_lt_max_a_t",
"Spec.Hash.Definitions.SHA2_512",
"Lib.Sequence.seq",
"Lib.IntTypes.uint8",
"Prims.b2t",
"Prims.op_Equality",
"Prims.nat",
"Lib.Sequence.length",
"Hacl.Spec.SHA2.Vec.hash",
"Hacl.Spec.SHA2.Vec.M32",
"Hacl.Spec.SHA2.Vec.multiseq",
"Hacl.Spec.SHA2.Vec.lanes",
"Spec.Hash.Definitions.hash_length"
] | [] | false | false | false | false | false | let sha512 (len: Spec.len_lt_max_a_t SHA2_512) (b: seq uint8 {length b = len}) =
| hash #SHA2_512 #M32 len b | false |
|
Hacl.Spec.SHA2.Vec.fst | Hacl.Spec.SHA2.Vec.load_last1 | val load_last1
(#a: sha2_alg)
(#m: m_spec{lanes a m == 1})
(totlen_seq: lseq uint8 (len_length a))
(fin: nat{fin == block_length a \/ fin == 2 * block_length a})
(len: nat{len <= block_length a})
(b: multiseq (lanes a m) len)
: multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) | val load_last1
(#a: sha2_alg)
(#m: m_spec{lanes a m == 1})
(totlen_seq: lseq uint8 (len_length a))
(fin: nat{fin == block_length a \/ fin == 2 * block_length a})
(len: nat{len <= block_length a})
(b: multiseq (lanes a m) len)
: multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) | let load_last1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1})
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a}) (b:multiseq (lanes a m) len) :
multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
let b = b.(|0|) in
let (l0,l1) = load_last_blocks #a totlen_seq fin len b in
let lb0 : multiseq (lanes a m) (block_length a) = ntup1 l0 in
let lb1 : multiseq (lanes a m) (block_length a) = ntup1 l1 in
(lb0, lb1) | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 14,
"end_line": 313,
"start_col": 0,
"start_line": 304
} | module Hacl.Spec.SHA2.Vec
open FStar.Mul
open Lib.IntTypes
open Lib.NTuple
open Lib.Sequence
open Lib.IntVector
open Lib.LoopCombinators
open Spec.Hash.Definitions
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module LSeq = Lib.Sequence
module VecTranspose = Lib.IntVector.Transpose
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
noextract
type m_spec =
| M32
| M128
| M256
inline_for_extraction
let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8}
inline_for_extraction
let lanes (a:sha2_alg) (m:m_spec) : lanes_t =
match a,m with
| SHA2_224,M128
| SHA2_256,M128 -> 4
| SHA2_224,M256
| SHA2_256,M256 -> 8
| SHA2_384,M128
| SHA2_512,M128 -> 2
| SHA2_384,M256
| SHA2_512,M256 -> 4
| _ -> 1
noextract
let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8
inline_for_extraction
let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m)
inline_for_extraction
val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = vec_zero (word_t a) (lanes a m)
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let word (a:hash_alg) = uint_t (word_t a) SEC
//TODO: remove when Spec.Hash.Definitions.word is fixed
inline_for_extraction
let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a}
inline_for_extraction
val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = vec_load x (lanes a m)
inline_for_extraction
let ( +| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m)
inline_for_extraction
let ( ^| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m)
inline_for_extraction
let ( &| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m)
inline_for_extraction
let ( ~| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> rotval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m)
inline_for_extraction
let ( >>| ) (#a:sha2_alg) (#m:m_spec): element_t a m -> shiftval (word_t a) -> element_t a m =
match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m)
inline_for_extraction
val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) //Alternative: Ch(e,f,g)=((f^g)&e)^g - does not appear to make a perf diff
inline_for_extraction
val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m
let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) // Alternative: Maj(a,b,c) = Ch(a^b,c,b) - does not appear to make a perf diff
inline_for_extraction
val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2))
inline_for_extraction
val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5))
inline_for_extraction
val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2))
inline_for_extraction
val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5))
noextract
let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8
noextract
let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16
noextract
let state_spec_v (#a:sha2_alg) (#m:m_spec) (st:state_spec a m) : lseq (words_state' a) (lanes a m) =
createi #(words_state' a) (lanes a m) (fun i ->
create8
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i])
noextract
let ws_spec_v (#a:sha2_alg) (#m:m_spec) (st:ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) =
createi #(lseq (word a) 16) (lanes a m) (fun i ->
create16
(vec_v st.[0]).[i] (vec_v st.[1]).[i] (vec_v st.[2]).[i] (vec_v st.[3]).[i]
(vec_v st.[4]).[i] (vec_v st.[5]).[i] (vec_v st.[6]).[i] (vec_v st.[7]).[i]
(vec_v st.[8]).[i] (vec_v st.[9]).[i] (vec_v st.[10]).[i] (vec_v st.[11]).[i]
(vec_v st.[12]).[i] (vec_v st.[13]).[i] (vec_v st.[14]).[i] (vec_v st.[15]).[i])
noextract
val shuffle_core_spec: #a: sha2_alg -> #m:m_spec ->
k_t: word a ->
ws_t: element_t a m ->
st: state_spec a m ->
state_spec a m
let shuffle_core_spec #a #m k_t ws_t st =
let a0 = st.[0] in
let b0 = st.[1] in
let c0 = st.[2] in
let d0 = st.[3] in
let e0 = st.[4] in
let f0 = st.[5] in
let g0 = st.[6] in
let h0 = st.[7] in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 a1 b1 c1 d1 e1 f1 g1 h1
inline_for_extraction
let num_rounds16 (a:sha2_alg) : n:size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} =
match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul
noextract
let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes
unfold let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a)
noextract
let load_elementi (#a:sha2_alg) (#m:m_spec) (b:lseq uint8 (block_length a)) (bi:nat{bi < 16 / lanes a m}) : element_t a m =
let l = lanes a m in
vec_from_bytes_be (word_t a) l (sub b (bi * l * word_length a) (l * word_length a))
noextract
let get_wsi (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) (i:nat{i < 16}) : element_t a m =
let l = lanes a m in
let idx_i = i % l in
let idx_j = i / l in
load_elementi #a #m b.(|idx_i|) idx_j
noextract
let load_blocks (#a:sha2_alg) (#m:m_spec) (b:multiblock_spec a m) : ws_spec a m =
createi 16 (get_wsi #a #m b)
noextract
let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws
noextract
let transpose_ws4 (#a:sha2_alg) (#m:m_spec{lanes a m == 4}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3) = VecTranspose.transpose4x4 (ws.[0], ws.[1], ws.[2], ws.[3]) in
let (ws4,ws5,ws6,ws7) = VecTranspose.transpose4x4 (ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11) = VecTranspose.transpose4x4 (ws.[8], ws.[9], ws.[10], ws.[11]) in
let (ws12,ws13,ws14,ws15) = VecTranspose.transpose4x4 (ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws8 (#a:sha2_alg) (#m:m_spec{lanes a m == 8}) (ws:ws_spec a m) : ws_spec a m =
let (ws0,ws1,ws2,ws3,ws4,ws5,ws6,ws7) = VecTranspose.transpose8x8 (ws.[0], ws.[1], ws.[2], ws.[3], ws.[4], ws.[5], ws.[6], ws.[7]) in
let (ws8,ws9,ws10,ws11,ws12,ws13,ws14,ws15) = VecTranspose.transpose8x8 (ws.[8], ws.[9], ws.[10], ws.[11], ws.[12], ws.[13], ws.[14], ws.[15]) in
create16 ws0 ws1 ws2 ws3 ws4 ws5 ws6 ws7 ws8 ws9 ws10 ws11 ws12 ws13 ws14 ws15
noextract
let transpose_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (ws:ws_spec a m) : ws_spec a m =
match lanes a m with
| 1 -> transpose_ws1 #a #m ws
| 4 -> transpose_ws4 #a #m ws
| 8 -> transpose_ws8 #a #m ws
noextract
let load_ws (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) : ws_spec a m =
let ws = load_blocks #a #m b in
transpose_ws #a #m ws
noextract
let ws_next_inner (#a:sha2_alg) (#m:m_spec)
(i:nat{i < 16})
(ws:ws_spec a m) : ws_spec a m =
let t16 = ws.[i] in
let t15 = ws.[(i+1) % 16] in
let t7 = ws.[(i+9) % 16] in
let t2 = ws.[(i+14) % 16] in
let s1 = _sigma1 t2 in
let s0 = _sigma0 t15 in
ws.[i] <- (s1 +| t7 +| s0 +| t16)
noextract
let ws_next (#a:sha2_alg) (#m:m_spec)
(ws:ws_spec a m) : ws_spec a m =
repeati 16 (ws_next_inner #a #m) ws
noextract
let shuffle_inner (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (i:nat{i < v (num_rounds16 a)}) (j:nat{j < 16}) (st:state_spec a m) : state_spec a m =
let k_t = Seq.index (Spec.k0 a) (16 * i + j) in
let ws_t = ws.[j] in
shuffle_core_spec k_t ws_t st
noextract
let shuffle_inner_loop (#a:sha2_alg) (#m:m_spec) (i:nat{i < v (num_rounds16 a)})
(ws_st:ws_spec a m & state_spec a m) : ws_spec a m & state_spec a m =
let (ws,st) = ws_st in
let st' = repeati 16 (shuffle_inner ws i) st in
let ws' = if i < v (num_rounds16 a) - 1 then ws_next ws else ws in
(ws',st')
noextract
let shuffle (#a:sha2_alg) (#m:m_spec) (ws:ws_spec a m) (st:state_spec a m) : state_spec a m =
let (ws,st) = repeati (v(num_rounds16 a)) (shuffle_inner_loop #a #m) (ws,st) in
st
noextract
let init (a:sha2_alg) (m:m_spec) : state_spec a m =
createi 8 (fun i -> load_element a m (Seq.index (Spec.h0 a) i))
[@"opaque_to_smt"]
noextract
let update (#a:sha2_alg) (#m:m_spec{is_supported a m}) (b:multiblock_spec a m) (st:state_spec a m): state_spec a m =
let st_old = st in
let ws = load_ws b in
let st_new = shuffle ws st_old in
map2 (+|) st_new st_old
noextract
let padded_blocks (a:sha2_alg) (len:nat{len <= block_length a}) : n:nat{n <= 2} =
if (len + len_length a + 1 <= block_length a) then 1 else 2
noextract
let load_last_blocks (#a:sha2_alg)
(totlen_seq:lseq uint8 (len_length a))
(fin:nat{fin == block_length a \/ fin == 2 * block_length a})
(len:nat{len <= block_length a})
(b:lseq uint8 len) :
lseq uint8 (block_length a) & lseq uint8 (block_length a) =
let last = create (2 * block_length a) (u8 0) in
let last = update_sub last 0 len b in
let last = last.[len] <- u8 0x80 in
let last = update_sub last (fin - len_length a) (len_length a) totlen_seq in
let l0 : lseq uint8 (block_length a) = sub last 0 (block_length a) in
let l1 : lseq uint8 (block_length a) = sub last (block_length a) (block_length a) in
(l0, l1) | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.Serialize.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.SHA2.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.SHA2.Vec.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
totlen_seq: Lib.Sequence.lseq Lib.IntTypes.uint8 (Spec.Hash.Definitions.len_length a) ->
fin:
Prims.nat
{ fin == Spec.Hash.Definitions.block_length a \/
fin == 2 * Spec.Hash.Definitions.block_length a } ->
len: Prims.nat{len <= Spec.Hash.Definitions.block_length a} ->
b: Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m) len
-> Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m)
(Spec.Hash.Definitions.block_length a) *
Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m)
(Spec.Hash.Definitions.block_length a) | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Prims.eq2",
"Prims.int",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint8",
"Spec.Hash.Definitions.len_length",
"Prims.nat",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_disEquality",
"Spec.Hash.Definitions.block_length",
"FStar.Mul.op_Star",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.SHA2.Vec.multiseq",
"FStar.Pervasives.Native.Mktuple2",
"Lib.NTuple.ntup1",
"FStar.Seq.Properties.lseq",
"FStar.Pervasives.Native.tuple2",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Hacl.Spec.SHA2.Vec.load_last_blocks",
"Lib.NTuple.op_Lens_Access"
] | [] | false | false | false | false | false | let load_last1
(#a: sha2_alg)
(#m: m_spec{lanes a m == 1})
(totlen_seq: lseq uint8 (len_length a))
(fin: nat{fin == block_length a \/ fin == 2 * block_length a})
(len: nat{len <= block_length a})
(b: multiseq (lanes a m) len)
: multiseq (lanes a m) (block_length a) & multiseq (lanes a m) (block_length a) =
| let b = b.(| 0 |) in
let l0, l1 = load_last_blocks #a totlen_seq fin len b in
let lb0:multiseq (lanes a m) (block_length a) = ntup1 l0 in
let lb1:multiseq (lanes a m) (block_length a) = ntup1 l1 in
(lb0, lb1) | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.