effect
stringclasses 48
values | original_source_type
stringlengths 0
23k
| opens_and_abbrevs
listlengths 2
92
| isa_cross_project_example
bool 1
class | source_definition
stringlengths 9
57.9k
| partial_definition
stringlengths 7
23.3k
| is_div
bool 2
classes | is_type
null | is_proof
bool 2
classes | completed_definiton
stringlengths 1
250k
| dependencies
dict | effect_flags
sequencelengths 0
2
| ideal_premises
sequencelengths 0
236
| mutual_with
sequencelengths 0
11
| file_context
stringlengths 0
407k
| interleaved
bool 1
class | is_simply_typed
bool 2
classes | file_name
stringlengths 5
48
| vconfig
dict | is_simple_lemma
null | source_type
stringlengths 10
23k
| proof_features
sequencelengths 0
1
| name
stringlengths 8
95
| source
dict | verbose_type
stringlengths 1
7.42k
| source_range
dict |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Prims.Tot | val maybe_set_validator_error_pos_and_code (error: validator_error) (pos: pos_t) (c: error_code)
: Tot validator_error | [
{
"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
}
] | 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 | 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 = | false | null | false | if get_validator_error_code error = 0uL then set_validator_error_pos_and_code error pos c else error | {
"checked_file": "LowParse.Low.ErrorCode.fst.checked",
"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"
} | [
"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"
] | [] | 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) | false | true | LowParse.Low.ErrorCode.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val maybe_set_validator_error_pos_and_code (error: validator_error) (pos: pos_t) (c: error_code)
: Tot validator_error | [] | LowParse.Low.ErrorCode.maybe_set_validator_error_pos_and_code | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
error: LowParse.Low.ErrorCode.validator_error ->
pos: LowParse.Low.ErrorCode.pos_t ->
c: LowParse.Low.ErrorCode.error_code
-> LowParse.Low.ErrorCode.validator_error | {
"end_col": 12,
"end_line": 169,
"start_col": 2,
"start_line": 167
} |
Prims.Tot | val get_validator_error_code (error: U64.t) : Tot (code: U64.t{U64.v code < 65536}) | [
{
"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
}
] | false | let get_validator_error_code (error: U64.t) : Tot (code: U64.t { U64.v code < 65536 }) =
get_validator_error_field error 16 32 | 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}) = | false | null | false | get_validator_error_field error 16 32 | {
"checked_file": "LowParse.Low.ErrorCode.fst.checked",
"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"
} | [
"total"
] | [
"FStar.UInt64.t",
"LowParse.Low.ErrorCode.get_validator_error_field",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt64.v"
] | [] | 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 ] | false | false | LowParse.Low.ErrorCode.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val get_validator_error_code (error: U64.t) : Tot (code: U64.t{U64.v code < 65536}) | [] | LowParse.Low.ErrorCode.get_validator_error_code | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | error: FStar.UInt64.t -> code: FStar.UInt64.t{FStar.UInt64.v code < 65536} | {
"end_col": 39,
"end_line": 130,
"start_col": 2,
"start_line": 130
} |
Prims.Tot | val set_validator_error_code (error: U64.t) (code: error_code) : Tot validator_error | [
{
"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
}
] | false | let set_validator_error_code (error: U64.t) (code: error_code) : Tot validator_error =
set_validator_error_field error 16 32 code | 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 = | false | null | false | set_validator_error_field error 16 32 code | {
"checked_file": "LowParse.Low.ErrorCode.fst.checked",
"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"
} | [
"total"
] | [
"FStar.UInt64.t",
"LowParse.Low.ErrorCode.error_code",
"LowParse.Low.ErrorCode.set_validator_error_field",
"LowParse.Low.ErrorCode.validator_error"
] | [] | 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 ] | false | true | LowParse.Low.ErrorCode.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val set_validator_error_code (error: U64.t) (code: error_code) : Tot validator_error | [] | LowParse.Low.ErrorCode.set_validator_error_code | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | error: FStar.UInt64.t -> code: LowParse.Low.ErrorCode.error_code
-> LowParse.Low.ErrorCode.validator_error | {
"end_col": 44,
"end_line": 126,
"start_col": 2,
"start_line": 126
} |
Prims.Tot | val validator_max_length:(u: U64.t{4 <= U64.v u /\ U64.v u <= U64.v max_uint32_as_uint64}) | [
{
"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
}
] | 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 | 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}) = | false | null | false | _max_uint32_as_uint64 | {
"checked_file": "LowParse.Low.ErrorCode.fst.checked",
"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"
} | [
"total"
] | [
"LowParse.Low.ErrorCode._max_uint32_as_uint64"
] | [] | 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 | false | false | LowParse.Low.ErrorCode.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val validator_max_length:(u: U64.t{4 <= U64.v u /\ U64.v u <= U64.v max_uint32_as_uint64}) | [] | LowParse.Low.ErrorCode.validator_max_length | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | u1:
FStar.UInt64.t
{ 4 <= FStar.UInt64.v u1 /\
FStar.UInt64.v u1 <= FStar.UInt64.v LowParse.Low.ErrorCode.max_uint32_as_uint64 } | {
"end_col": 120,
"end_line": 38,
"start_col": 99,
"start_line": 38
} |
Prims.Tot | val get_validator_error_pos (x: U64.t) : Tot pos_t | [
{
"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
}
] | false | let get_validator_error_pos (x: U64.t) : Tot pos_t =
(BF.uint64.BF.get_bitfield x 0 32) | val get_validator_error_pos (x: U64.t) : Tot pos_t
let get_validator_error_pos (x: U64.t) : Tot pos_t = | false | null | false | (BF.uint64.BF.get_bitfield x 0 32) | {
"checked_file": "LowParse.Low.ErrorCode.fst.checked",
"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"
} | [
"total"
] | [
"FStar.UInt64.t",
"LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield",
"LowParse.BitFields.uint64",
"LowParse.Low.ErrorCode.pos_t"
] | [] | 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 ] | false | true | LowParse.Low.ErrorCode.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val get_validator_error_pos (x: U64.t) : Tot pos_t | [] | LowParse.Low.ErrorCode.get_validator_error_pos | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | x: FStar.UInt64.t -> LowParse.Low.ErrorCode.pos_t | {
"end_col": 36,
"end_line": 111,
"start_col": 2,
"start_line": 111
} |
Prims.Tot | 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)}) | [
{
"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
}
] | 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 | 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)}) = | false | null | false | [@@ inline_let ]let res = BF.uint64.BF.get_bitfield x (32 + lo) (32 + hi) in
res | {
"checked_file": "LowParse.Low.ErrorCode.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | LowParse.Low.ErrorCode.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | 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)}) | [] | LowParse.Low.ErrorCode.get_validator_error_field | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | 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)} | {
"end_col": 5,
"end_line": 63,
"start_col": 2,
"start_line": 59
} |
Prims.Tot | val set_validator_error_pos (error: validator_error) (position: pos_t) : Tot validator_error | [
{
"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
}
] | 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 | 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 = | false | null | false | [@@ 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 | {
"checked_file": "LowParse.Low.ErrorCode.fst.checked",
"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"
} | [
"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"
] | [] | 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 ] | false | true | LowParse.Low.ErrorCode.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val set_validator_error_pos (error: validator_error) (position: pos_t) : Tot validator_error | [] | LowParse.Low.ErrorCode.set_validator_error_pos | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | error: LowParse.Low.ErrorCode.validator_error -> position: LowParse.Low.ErrorCode.pos_t
-> LowParse.Low.ErrorCode.validator_error | {
"end_col": 5,
"end_line": 105,
"start_col": 2,
"start_line": 93
} |
Prims.Tot | val maybe_set_error_code (positionOrError: U64.t) (positionAtError: pos_t) (code: error_code)
: Tot U64.t | [
{
"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
}
] | 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 | 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 = | false | null | false | if is_error positionOrError && get_validator_error_code positionOrError = 0uL
then set_validator_error_pos_and_code positionOrError positionAtError code
else positionOrError | {
"checked_file": "LowParse.Low.ErrorCode.fst.checked",
"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"
} | [
"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"
] | [] | 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
[@ CInline ]
let maybe_set_error_code
(positionOrError: U64.t)
(positionAtError: pos_t)
(code: error_code) | false | true | LowParse.Low.ErrorCode.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val maybe_set_error_code (positionOrError: U64.t) (positionAtError: pos_t) (code: error_code)
: Tot U64.t | [] | LowParse.Low.ErrorCode.maybe_set_error_code | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
positionOrError: FStar.UInt64.t ->
positionAtError: LowParse.Low.ErrorCode.pos_t ->
code: LowParse.Low.ErrorCode.error_code
-> FStar.UInt64.t | {
"end_col": 24,
"end_line": 180,
"start_col": 4,
"start_line": 177
} |
Prims.Tot | val uint64_to_uint32 (x: pos_t) : Tot (y: U32.t{U32.v y == U64.v x}) | [
{
"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
}
] | false | let uint64_to_uint32
(x: pos_t)
: Tot (y: U32.t { U32.v y == U64.v x })
= Cast.uint64_to_uint32 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}) = | false | null | false | Cast.uint64_to_uint32 x | {
"checked_file": "LowParse.Low.ErrorCode.fst.checked",
"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"
} | [
"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"
] | [] | 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) | false | false | LowParse.Low.ErrorCode.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val uint64_to_uint32 (x: pos_t) : Tot (y: U32.t{U32.v y == U64.v x}) | [] | LowParse.Low.ErrorCode.uint64_to_uint32 | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | x: LowParse.Low.ErrorCode.pos_t -> y: FStar.UInt32.t{FStar.UInt32.v y == FStar.UInt64.v x} | {
"end_col": 25,
"end_line": 144,
"start_col": 2,
"start_line": 144
} |
Prims.Tot | 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 | [
{
"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
}
] | 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 | 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 = | false | null | false | [@@ 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 | {
"checked_file": "LowParse.Low.ErrorCode.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | LowParse.Low.ErrorCode.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | 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 | [] | LowParse.Low.ErrorCode.set_validator_error_field | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
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 | {
"end_col": 5,
"end_line": 80,
"start_col": 2,
"start_line": 68
} |
Prims.Tot | val set_validator_error_kind (error: U64.t) (code: U64.t{0 < U64.v code /\ U64.v code < 16384})
: Tot validator_error | [
{
"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
}
] | 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 | 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 = | false | null | false | set_validator_error_field error 0 14 code | {
"checked_file": "LowParse.Low.ErrorCode.fst.checked",
"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"
} | [
"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"
] | [] | 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 ] | false | false | LowParse.Low.ErrorCode.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val set_validator_error_kind (error: U64.t) (code: U64.t{0 < U64.v code /\ U64.v code < 16384})
: Tot validator_error | [] | LowParse.Low.ErrorCode.set_validator_error_kind | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
error: FStar.UInt64.t ->
code: FStar.UInt64.t{0 < FStar.UInt64.v code /\ FStar.UInt64.v code < 16384}
-> LowParse.Low.ErrorCode.validator_error | {
"end_col": 43,
"end_line": 115,
"start_col": 2,
"start_line": 115
} |
Prims.Tot | val get_validator_error_kind (error: U64.t)
: Tot (code: U64.t{0 <= U64.v code /\ U64.v code < 16384}) | [
{
"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
}
] | 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 | 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}) = | false | null | false | get_validator_error_field error 0 14 | {
"checked_file": "LowParse.Low.ErrorCode.fst.checked",
"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"
} | [
"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"
] | [] | 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 ] | false | false | LowParse.Low.ErrorCode.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val get_validator_error_kind (error: U64.t)
: Tot (code: U64.t{0 <= U64.v code /\ U64.v code < 16384}) | [] | LowParse.Low.ErrorCode.get_validator_error_kind | {
"file_name": "src/lowparse/LowParse.Low.ErrorCode.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | error: FStar.UInt64.t
-> code: FStar.UInt64.t{0 <= FStar.UInt64.v code /\ FStar.UInt64.v code < 16384} | {
"end_col": 38,
"end_line": 119,
"start_col": 2,
"start_line": 119
} |
Prims.Tot | [
{
"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
}
] | false | let p = Vale.X64.CPU_Features_s.(adx_enabled /\ bmi2_enabled) | let p = | false | null | false | let open Vale.X64.CPU_Features_s in adx_enabled /\ bmi2_enabled | {
"checked_file": "Hacl.Impl.Curve25519.Field64.Vale.fsti.checked",
"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"
} | [
"total"
] | [
"Prims.l_and",
"Prims.b2t",
"Vale.X64.CPU_Features_s.adx_enabled",
"Vale.X64.CPU_Features_s.bmi2_enabled"
] | [] | module Hacl.Impl.Curve25519.Field64.Vale
open Hacl.Impl.Curve25519.Fields.Core | false | true | Hacl.Impl.Curve25519.Field64.Vale.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val p : Prims.logical | [] | Hacl.Impl.Curve25519.Field64.Vale.p | {
"file_name": "code/curve25519/Hacl.Impl.Curve25519.Field64.Vale.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Prims.logical | {
"end_col": 60,
"end_line": 5,
"start_col": 33,
"start_line": 5
} |
|
Prims.Tot | val lanes (a: sha2_alg) (m: m_spec) : lanes_t | [
{
"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
}
] | 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 | val lanes (a: sha2_alg) (m: m_spec) : lanes_t
let lanes (a: sha2_alg) (m: m_spec) : lanes_t = | false | null | false | 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": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | true | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val lanes (a: sha2_alg) (m: m_spec) : lanes_t | [] | Hacl.Spec.SHA2.Vec.lanes | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec -> Hacl.Spec.SHA2.Vec.lanes_t | {
"end_col": 10,
"end_line": 39,
"start_col": 2,
"start_line": 30
} |
Prims.Tot | val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m | [
{
"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
}
] | false | let _Ch #a #m x y z = (x &| y) ^| (~| x &| z) | 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 = | false | null | false | (x &| y) ^| (~|x &| z) | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val _Ch: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m | [] | Hacl.Spec.SHA2.Vec._Ch | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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 | {
"end_col": 45,
"end_line": 102,
"start_col": 22,
"start_line": 102
} |
Prims.Tot | [
{
"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
}
] | false | let lanes_t = n:nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8} | let lanes_t = | false | null | false | n: nat{n == 1 \/ n == 2 \/ n == 4 \/ n == 8} | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"total"
] | [
"Prims.nat",
"Prims.l_or",
"Prims.eq2",
"Prims.int"
] | [] | 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 | false | true | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val lanes_t : Type0 | [] | Hacl.Spec.SHA2.Vec.lanes_t | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Type0 | {
"end_col": 57,
"end_line": 26,
"start_col": 14,
"start_line": 26
} |
|
Prims.Tot | [
{
"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
}
] | false | let is_supported (a:sha2_alg) (m:m_spec) =
lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8 | let is_supported (a: sha2_alg) (m: m_spec) = | false | null | false | lanes a m = 1 \/ lanes a m = 4 \/ lanes a m = 8 | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | true | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val is_supported : a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec -> Prims.logical | [] | Hacl.Spec.SHA2.Vec.is_supported | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec -> Prims.logical | {
"end_col": 49,
"end_line": 43,
"start_col": 2,
"start_line": 43
} |
|
Prims.Tot | val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m | [
{
"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
}
] | false | let _Maj #a #m x y z = (x &| y) ^| ((x &| z) ^| (y &| z)) | 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 = | false | null | false | (x &| y) ^| ((x &| z) ^| (y &| z)) | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val _Maj: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m -> element_t a m -> element_t a m | [] | Hacl.Spec.SHA2.Vec._Maj | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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 | {
"end_col": 57,
"end_line": 107,
"start_col": 23,
"start_line": 107
} |
Prims.Tot | val load_ws (#a: sha2_alg) (#m: m_spec{is_supported a m}) (b: multiblock_spec a m) : ws_spec a m | [
{
"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
}
] | 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 | 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 = | false | null | false | let ws = load_blocks #a #m b in
transpose_ws #a #m ws | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val load_ws (#a: sha2_alg) (#m: m_spec{is_supported a m}) (b: multiblock_spec a m) : ws_spec a m | [] | Hacl.Spec.SHA2.Vec.load_ws | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | b: Hacl.Spec.SHA2.Vec.multiblock_spec a m -> Hacl.Spec.SHA2.Vec.ws_spec a m | {
"end_col": 23,
"end_line": 234,
"start_col": 95,
"start_line": 232
} |
Prims.Tot | val ws_next (#a: sha2_alg) (#m: m_spec) (ws: ws_spec a m) : ws_spec a m | [
{
"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
}
] | 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 | 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 = | false | null | false | repeati 16 (ws_next_inner #a #m) ws | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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) | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val ws_next (#a: sha2_alg) (#m: m_spec) (ws: ws_spec a m) : ws_spec a m | [] | Hacl.Spec.SHA2.Vec.ws_next | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ws: Hacl.Spec.SHA2.Vec.ws_spec a m -> Hacl.Spec.SHA2.Vec.ws_spec a m | {
"end_col": 39,
"end_line": 251,
"start_col": 4,
"start_line": 251
} |
Prims.Tot | 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 | [
{
"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
}
] | 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') | 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 = | false | null | false | 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": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | 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 | [] | Hacl.Spec.SHA2.Vec.shuffle_inner_loop | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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 | {
"end_col": 11,
"end_line": 265,
"start_col": 92,
"start_line": 261
} |
Prims.Tot | [
{
"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
}
] | false | let words_state' a = m:Seq.seq (word a) {Seq.length m = state_word_length a} | let words_state' a = | false | null | false | m: Seq.seq (word a) {Seq.length m = state_word_length a} | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | true | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val words_state' : a: Spec.Hash.Definitions.hash_alg -> Type0 | [] | Hacl.Spec.SHA2.Vec.words_state' | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Hash.Definitions.hash_alg -> Type0 | {
"end_col": 76,
"end_line": 58,
"start_col": 21,
"start_line": 58
} |
|
Prims.Tot | val zero_element: a:sha2_alg -> m:m_spec -> element_t a m | [
{
"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
}
] | false | let zero_element a m = vec_zero (word_t a) (lanes a m) | val zero_element: a:sha2_alg -> m:m_spec -> element_t a m
let zero_element a m = | false | null | false | vec_zero (word_t a) (lanes a m) | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val zero_element: a:sha2_alg -> m:m_spec -> element_t a m | [] | Hacl.Spec.SHA2.Vec.zero_element | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec
-> Hacl.Spec.SHA2.Vec.element_t a m | {
"end_col": 54,
"end_line": 50,
"start_col": 23,
"start_line": 50
} |
Prims.Tot | val shuffle (#a: sha2_alg) (#m: m_spec) (ws: ws_spec a m) (st: state_spec a m) : state_spec a m | [
{
"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
}
] | 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 | 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 = | false | null | false | let ws, st = repeati (v (num_rounds16 a)) (shuffle_inner_loop #a #m) (ws, st) in
st | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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') | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val shuffle (#a: sha2_alg) (#m: m_spec) (ws: ws_spec a m) (st: state_spec a m) : state_spec a m | [] | Hacl.Spec.SHA2.Vec.shuffle | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | 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 | {
"end_col": 4,
"end_line": 270,
"start_col": 93,
"start_line": 268
} |
Prims.Tot | val transpose_ws (#a: sha2_alg) (#m: m_spec{is_supported a m}) (ws: ws_spec a m) : ws_spec a m | [
{
"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
}
] | 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 | 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 = | false | null | false | 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": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val transpose_ws (#a: sha2_alg) (#m: m_spec{is_supported a m}) (ws: ws_spec a m) : ws_spec a m | [] | Hacl.Spec.SHA2.Vec.transpose_ws | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ws: Hacl.Spec.SHA2.Vec.ws_spec a m -> Hacl.Spec.SHA2.Vec.ws_spec a m | {
"end_col": 31,
"end_line": 228,
"start_col": 2,
"start_line": 225
} |
Prims.Tot | val transpose_state (#a: sha2_alg) (#m: m_spec{is_supported a m}) (st: state_spec a m)
: state_spec a m | [
{
"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
}
] | 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 | 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 = | false | null | false | match lanes a m with
| 1 -> st
| 4 -> transpose_state4 #a #m st
| 8 -> transpose_state8 #a #m st | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val transpose_state (#a: sha2_alg) (#m: m_spec{is_supported a m}) (st: state_spec a m)
: state_spec a m | [] | Hacl.Spec.SHA2.Vec.transpose_state | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | st: Hacl.Spec.SHA2.Vec.state_spec a m -> Hacl.Spec.SHA2.Vec.state_spec a m | {
"end_col": 34,
"end_line": 420,
"start_col": 2,
"start_line": 417
} |
Prims.Tot | val padded_blocks (a: sha2_alg) (len: nat{len <= block_length a}) : n: nat{n <= 2} | [
{
"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
}
] | 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 | 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} = | false | null | false | if (len + len_length a + 1 <= block_length a) then 1 else 2 | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val padded_blocks (a: sha2_alg) (len: nat{len <= block_length a}) : n: nat{n <= 2} | [] | Hacl.Spec.SHA2.Vec.padded_blocks | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Hash.Definitions.sha2_alg -> len: Prims.nat{len <= Spec.Hash.Definitions.block_length a}
-> n: Prims.nat{n <= 2} | {
"end_col": 61,
"end_line": 286,
"start_col": 2,
"start_line": 286
} |
Prims.Tot | [
{
"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
}
] | false | let element_t (a:sha2_alg) (m:m_spec) = vec_t (word_t a) (lanes a m) | let element_t (a: sha2_alg) (m: m_spec) = | false | null | false | vec_t (word_t a) (lanes a m) | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | true | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val element_t : a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec -> Type0 | [] | Hacl.Spec.SHA2.Vec.element_t | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec -> Type0 | {
"end_col": 68,
"end_line": 46,
"start_col": 40,
"start_line": 46
} |
|
Prims.Tot | val op_Greater_Greater_Greater_Bar: #a: sha2_alg -> #m: m_spec -> element_t a m -> rotval (word_t a)
-> element_t a m | [
{
"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
}
] | false | 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) | val op_Greater_Greater_Greater_Bar: #a: sha2_alg -> #m: m_spec -> element_t a m -> rotval (word_t a)
-> element_t a m
let op_Greater_Greater_Greater_Bar (#a: sha2_alg) (#m: m_spec)
: element_t a m -> rotval (word_t a) -> element_t a m = | false | null | false | match a with
| SHA2_224 | SHA2_256 -> ( >>>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>>| ) #U64 #(lanes a m) | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"total"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Lib.IntVector.op_Greater_Greater_Greater_Bar",
"Lib.IntTypes.U32",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.IntTypes.U64",
"Hacl.Spec.SHA2.Vec.element_t",
"Lib.IntTypes.rotval",
"Spec.Hash.Definitions.word_t"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val op_Greater_Greater_Greater_Bar: #a: sha2_alg -> #m: m_spec -> element_t a m -> rotval (word_t a)
-> element_t a m | [] | Hacl.Spec.SHA2.Vec.op_Greater_Greater_Greater_Bar | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: Hacl.Spec.SHA2.Vec.element_t a m -> _: Lib.IntTypes.rotval (Spec.Hash.Definitions.word_t a)
-> Hacl.Spec.SHA2.Vec.element_t a m | {
"end_col": 53,
"end_line": 92,
"start_col": 2,
"start_line": 90
} |
Prims.Tot | [
{
"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
}
] | false | let state_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 8 | let state_spec (a: sha2_alg) (m: m_spec) = | false | null | false | lseq (element_t a m) 8 | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"total"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Lib.Sequence.lseq",
"Hacl.Spec.SHA2.Vec.element_t"
] | [] | 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)) | false | true | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val state_spec : a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec -> Type0 | [] | Hacl.Spec.SHA2.Vec.state_spec | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec -> Type0 | {
"end_col": 63,
"end_line": 126,
"start_col": 41,
"start_line": 126
} |
|
Prims.Tot | val op_Tilde_Bar: #a: sha2_alg -> #m: m_spec -> element_t a m -> element_t a m | [
{
"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
}
] | false | 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) | val op_Tilde_Bar: #a: sha2_alg -> #m: m_spec -> element_t a m -> element_t a m
let op_Tilde_Bar (#a: sha2_alg) (#m: m_spec) : element_t a m -> element_t a m = | false | null | false | match a with
| SHA2_224 | SHA2_256 -> ( ~| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ~| ) #U64 #(lanes a m) | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"total"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Lib.IntVector.op_Tilde_Bar",
"Lib.IntTypes.U32",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.IntTypes.U64",
"Hacl.Spec.SHA2.Vec.element_t"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val op_Tilde_Bar: #a: sha2_alg -> #m: m_spec -> element_t a m -> element_t a m | [] | Hacl.Spec.SHA2.Vec.op_Tilde_Bar | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: Hacl.Spec.SHA2.Vec.element_t a m -> Hacl.Spec.SHA2.Vec.element_t a m | {
"end_col": 51,
"end_line": 86,
"start_col": 2,
"start_line": 84
} |
Prims.Tot | val op_Greater_Greater_Bar: #a: sha2_alg -> #m: m_spec -> element_t a m -> shiftval (word_t a)
-> element_t a m | [
{
"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
}
] | false | 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) | val op_Greater_Greater_Bar: #a: sha2_alg -> #m: m_spec -> element_t a m -> shiftval (word_t a)
-> element_t a m
let op_Greater_Greater_Bar (#a: sha2_alg) (#m: m_spec)
: element_t a m -> shiftval (word_t a) -> element_t a m = | false | null | false | match a with
| SHA2_224 | SHA2_256 -> ( >>| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( >>| ) #U64 #(lanes a m) | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"total"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Lib.IntVector.op_Greater_Greater_Bar",
"Lib.IntTypes.U32",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.IntTypes.U64",
"Hacl.Spec.SHA2.Vec.element_t",
"Lib.IntTypes.shiftval",
"Spec.Hash.Definitions.word_t"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val op_Greater_Greater_Bar: #a: sha2_alg -> #m: m_spec -> element_t a m -> shiftval (word_t a)
-> element_t a m | [] | Hacl.Spec.SHA2.Vec.op_Greater_Greater_Bar | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: Hacl.Spec.SHA2.Vec.element_t a m -> _: Lib.IntTypes.shiftval (Spec.Hash.Definitions.word_t a)
-> Hacl.Spec.SHA2.Vec.element_t a m | {
"end_col": 52,
"end_line": 98,
"start_col": 2,
"start_line": 96
} |
Prims.Tot | val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m | [
{
"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
}
] | false | let load_element a m x = vec_load x (lanes a m) | val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m
let load_element a m x = | false | null | false | vec_load x (lanes a m) | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val load_element: a:sha2_alg -> m:m_spec -> word a -> element_t a m | [] | Hacl.Spec.SHA2.Vec.load_element | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | 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 | {
"end_col": 47,
"end_line": 62,
"start_col": 25,
"start_line": 62
} |
Prims.Tot | val op_Hat_Bar: #a: sha2_alg -> #m: m_spec -> element_t a m -> element_t a m -> element_t a m | [
{
"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
}
] | false | 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) | val op_Hat_Bar: #a: sha2_alg -> #m: m_spec -> element_t a m -> element_t a m -> element_t a m
let op_Hat_Bar (#a: sha2_alg) (#m: m_spec) : element_t a m -> element_t a m -> element_t a m = | false | null | false | match a with
| SHA2_224 | SHA2_256 -> ( ^| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( ^| ) #U64 #(lanes a m) | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"total"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Lib.IntVector.op_Hat_Bar",
"Lib.IntTypes.U32",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.IntTypes.U64",
"Hacl.Spec.SHA2.Vec.element_t"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val op_Hat_Bar: #a: sha2_alg -> #m: m_spec -> element_t a m -> element_t a m -> element_t a m | [] | Hacl.Spec.SHA2.Vec.op_Hat_Bar | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: Hacl.Spec.SHA2.Vec.element_t a m -> _: Hacl.Spec.SHA2.Vec.element_t a m
-> Hacl.Spec.SHA2.Vec.element_t a m | {
"end_col": 51,
"end_line": 74,
"start_col": 2,
"start_line": 72
} |
Prims.Tot | val load_blocks (#a: sha2_alg) (#m: m_spec) (b: multiblock_spec a m) : ws_spec a m | [
{
"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
}
] | 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) | 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 = | false | null | false | createi 16 (get_wsi #a #m b) | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val load_blocks (#a: sha2_alg) (#m: m_spec) (b: multiblock_spec a m) : ws_spec a m | [] | Hacl.Spec.SHA2.Vec.load_blocks | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | b: Hacl.Spec.SHA2.Vec.multiblock_spec a m -> Hacl.Spec.SHA2.Vec.ws_spec a m | {
"end_col": 30,
"end_line": 204,
"start_col": 2,
"start_line": 204
} |
Prims.Tot | val init (a: sha2_alg) (m: m_spec) : state_spec a m | [
{
"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
}
] | 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)) | val init (a: sha2_alg) (m: m_spec) : state_spec a m
let init (a: sha2_alg) (m: m_spec) : state_spec a m = | false | null | false | createi 8 (fun i -> load_element a m (Seq.index (Spec.h0 a) i)) | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val init (a: sha2_alg) (m: m_spec) : state_spec a m | [] | Hacl.Spec.SHA2.Vec.init | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec
-> Hacl.Spec.SHA2.Vec.state_spec a m | {
"end_col": 65,
"end_line": 274,
"start_col": 2,
"start_line": 274
} |
Prims.Tot | val op_Plus_Bar: #a: sha2_alg -> #m: m_spec -> element_t a m -> element_t a m -> element_t a m | [
{
"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
}
] | false | 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) | val op_Plus_Bar: #a: sha2_alg -> #m: m_spec -> element_t a m -> element_t a m -> element_t a m
let op_Plus_Bar (#a: sha2_alg) (#m: m_spec) : element_t a m -> element_t a m -> element_t a m = | false | null | false | match a with
| SHA2_224 | SHA2_256 -> ( +| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( +| ) #U64 #(lanes a m) | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"total"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Lib.IntVector.op_Plus_Bar",
"Lib.IntTypes.U32",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.IntTypes.U64",
"Hacl.Spec.SHA2.Vec.element_t"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val op_Plus_Bar: #a: sha2_alg -> #m: m_spec -> element_t a m -> element_t a m -> element_t a m | [] | Hacl.Spec.SHA2.Vec.op_Plus_Bar | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: Hacl.Spec.SHA2.Vec.element_t a m -> _: Hacl.Spec.SHA2.Vec.element_t a m
-> Hacl.Spec.SHA2.Vec.element_t a m | {
"end_col": 51,
"end_line": 68,
"start_col": 2,
"start_line": 66
} |
Prims.Tot | [
{
"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
}
] | false | let multiseq (lanes:lanes_t) (len:nat) =
ntuple (Seq.lseq uint8 len) lanes | let multiseq (lanes: lanes_t) (len: nat) = | false | null | false | ntuple (Seq.lseq uint8 len) lanes | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"total"
] | [
"Hacl.Spec.SHA2.Vec.lanes_t",
"Prims.nat",
"Lib.NTuple.ntuple",
"FStar.Seq.Properties.lseq",
"Lib.IntTypes.uint8"
] | [] | 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 | false | true | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val multiseq : lanes: Hacl.Spec.SHA2.Vec.lanes_t -> len: Prims.nat -> Type0 | [] | Hacl.Spec.SHA2.Vec.multiseq | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | lanes: Hacl.Spec.SHA2.Vec.lanes_t -> len: Prims.nat -> Type0 | {
"end_col": 35,
"end_line": 185,
"start_col": 2,
"start_line": 185
} |
|
Prims.Tot | [
{
"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
}
] | 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 | 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)
= | false | null | false | 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": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | 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) | [] | Hacl.Spec.SHA2.Vec.hash | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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) | {
"end_col": 13,
"end_line": 478,
"start_col": 111,
"start_line": 471
} |
|
Prims.Tot | [
{
"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
}
] | false | let sha256_4 (len:Spec.len_lt_max_a_t SHA2_256) (b:multiseq 4 len) =
hash #SHA2_256 #M128 len b | let sha256_4 (len: Spec.len_lt_max_a_t SHA2_256) (b: multiseq 4 len) = | false | null | false | hash #SHA2_256 #M128 len b | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | 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) | [] | Hacl.Spec.SHA2.Vec.sha256_4 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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) | {
"end_col": 28,
"end_line": 486,
"start_col": 2,
"start_line": 486
} |
|
Prims.Tot | val ws_next_inner (#a: sha2_alg) (#m: m_spec) (i: nat{i < 16}) (ws: ws_spec a m) : ws_spec a m | [
{
"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
}
] | 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) | 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 = | false | null | false | 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": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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) | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val ws_next_inner (#a: sha2_alg) (#m: m_spec) (i: nat{i < 16}) (ws: ws_spec a m) : ws_spec a m | [] | Hacl.Spec.SHA2.Vec.ws_next_inner | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | i: Prims.nat{i < 16} -> ws: Hacl.Spec.SHA2.Vec.ws_spec a m -> Hacl.Spec.SHA2.Vec.ws_spec a m | {
"end_col": 39,
"end_line": 246,
"start_col": 50,
"start_line": 239
} |
Prims.Tot | val get_wsi (#a: sha2_alg) (#m: m_spec) (b: multiblock_spec a m) (i: nat{i < 16}) : element_t a m | [
{
"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
}
] | 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 | 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 = | false | null | false | 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": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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)) | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val get_wsi (#a: sha2_alg) (#m: m_spec) (b: multiblock_spec a m) (i: nat{i < 16}) : element_t a m | [] | Hacl.Spec.SHA2.Vec.get_wsi | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | b: Hacl.Spec.SHA2.Vec.multiblock_spec a m -> i: Prims.nat{i < 16}
-> Hacl.Spec.SHA2.Vec.element_t a m | {
"end_col": 39,
"end_line": 200,
"start_col": 95,
"start_line": 196
} |
Prims.Tot | val transpose_state8 (#a: sha2_alg) (#m: m_spec{lanes a m == 8}) (st: state_spec a m)
: state_spec a m | [
{
"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
}
] | 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 | 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 = | false | null | false | 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": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val transpose_state8 (#a: sha2_alg) (#m: m_spec{lanes a m == 8}) (st: state_spec a m)
: state_spec a m | [] | Hacl.Spec.SHA2.Vec.transpose_state8 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | st: Hacl.Spec.SHA2.Vec.state_spec a m -> Hacl.Spec.SHA2.Vec.state_spec a m | {
"end_col": 43,
"end_line": 413,
"start_col": 58,
"start_line": 403
} |
Prims.Tot | 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 | [
{
"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
}
] | 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 | 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 = | false | null | false | 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": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | 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 | [] | Hacl.Spec.SHA2.Vec.shuffle_inner | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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 | {
"end_col": 31,
"end_line": 257,
"start_col": 147,
"start_line": 254
} |
Prims.Tot | 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 | [
{
"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
}
] | 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 | 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 = | false | null | false | let mb = get_multiblock_spec len b i in
update mb st | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | 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 | [] | Hacl.Spec.SHA2.Vec.update_block | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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 | {
"end_col": 14,
"end_line": 456,
"start_col": 89,
"start_line": 454
} |
Prims.Tot | val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m | [
{
"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
}
] | false | let _sigma1 #a #m x = Spec.((x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5)) | val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma1 #a #m x = | false | null | false | let open Spec in (x >>>| (op0 a).e3) ^| (x >>>| (op0 a).e4) ^| (x >>| (op0 a).e5) | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val _sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m | [] | Hacl.Spec.SHA2.Vec._sigma1 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Hacl.Spec.SHA2.Vec.element_t a m -> Hacl.Spec.SHA2.Vec.element_t a m | {
"end_col": 93,
"end_line": 123,
"start_col": 22,
"start_line": 123
} |
Prims.Tot | val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m | [
{
"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
}
] | false | let _Sigma0 #a #m x = Spec.((x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2)) | val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma0 #a #m x = | false | null | false | let open Spec in (x >>>| (op0 a).c0) ^| (x >>>| (op0 a).c1) ^| (x >>>| (op0 a).c2) | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val _Sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m | [] | Hacl.Spec.SHA2.Vec._Sigma0 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Hacl.Spec.SHA2.Vec.element_t a m -> Hacl.Spec.SHA2.Vec.element_t a m | {
"end_col": 94,
"end_line": 111,
"start_col": 22,
"start_line": 111
} |
Prims.Tot | val transpose_ws8 (#a: sha2_alg) (#m: m_spec{lanes a m == 8}) (ws: ws_spec a m) : ws_spec a m | [
{
"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
}
] | 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 | 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 = | false | null | false | 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": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val transpose_ws8 (#a: sha2_alg) (#m: m_spec{lanes a m == 8}) (ws: ws_spec a m) : ws_spec a m | [] | Hacl.Spec.SHA2.Vec.transpose_ws8 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ws: Hacl.Spec.SHA2.Vec.ws_spec a m -> Hacl.Spec.SHA2.Vec.ws_spec a m | {
"end_col": 82,
"end_line": 221,
"start_col": 92,
"start_line": 218
} |
Prims.Tot | 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 | [
{
"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
}
] | 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 | 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 = | false | null | false | let blocks = len / block_length a in
let st = repeati blocks (update_block #a #m len b) st in
st | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | 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 | [] | Hacl.Spec.SHA2.Vec.update_nblocks | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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 | {
"end_col": 6,
"end_line": 462,
"start_col": 158,
"start_line": 459
} |
Prims.Tot | val transpose_ws4 (#a: sha2_alg) (#m: m_spec{lanes a m == 4}) (ws: ws_spec a m) : ws_spec a m | [
{
"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
}
] | 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 | 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 = | false | null | false | 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": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val transpose_ws4 (#a: sha2_alg) (#m: m_spec{lanes a m == 4}) (ws: ws_spec a m) : ws_spec a m | [] | Hacl.Spec.SHA2.Vec.transpose_ws4 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ws: Hacl.Spec.SHA2.Vec.ws_spec a m -> Hacl.Spec.SHA2.Vec.ws_spec a m | {
"end_col": 82,
"end_line": 215,
"start_col": 92,
"start_line": 210
} |
Prims.Tot | 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 | [
{
"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
}
] | 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 | 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 = | false | null | false | 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": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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) | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | 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 | [] | Hacl.Spec.SHA2.Vec.update_last | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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 | {
"end_col": 9,
"end_line": 384,
"start_col": 82,
"start_line": 375
} |
Prims.Tot | [
{
"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
}
] | false | let sha512_4 (len:Spec.len_lt_max_a_t SHA2_512) (b:multiseq 4 len) =
hash #SHA2_512 #M256 len b | let sha512_4 (len: Spec.len_lt_max_a_t SHA2_512) (b: multiseq 4 len) = | false | null | false | hash #SHA2_512 #M256 len b | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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
noextract | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | 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) | [] | Hacl.Spec.SHA2.Vec.sha512_4 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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) | {
"end_col": 28,
"end_line": 494,
"start_col": 2,
"start_line": 494
} |
|
Prims.Tot | val transpose_state4 (#a: sha2_alg) (#m: m_spec{lanes a m == 4}) (st: state_spec a m)
: state_spec a m | [
{
"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
}
] | 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 | 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 = | false | null | false | 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": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val transpose_state4 (#a: sha2_alg) (#m: m_spec{lanes a m == 4}) (st: state_spec a m)
: state_spec a m | [] | Hacl.Spec.SHA2.Vec.transpose_state4 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | st: Hacl.Spec.SHA2.Vec.state_spec a m -> Hacl.Spec.SHA2.Vec.state_spec a m | {
"end_col": 43,
"end_line": 399,
"start_col": 58,
"start_line": 388
} |
Prims.Tot | val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m | [
{
"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
}
] | false | let _sigma0 #a #m x = Spec.((x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2)) | val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _sigma0 #a #m x = | false | null | false | let open Spec in (x >>>| (op0 a).e0) ^| (x >>>| (op0 a).e1) ^| (x >>| (op0 a).e2) | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val _sigma0: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m | [] | Hacl.Spec.SHA2.Vec._sigma0 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Hacl.Spec.SHA2.Vec.element_t a m -> Hacl.Spec.SHA2.Vec.element_t a m | {
"end_col": 93,
"end_line": 119,
"start_col": 22,
"start_line": 119
} |
Prims.Tot | val finish (#a: sha2_alg) (#m: m_spec{is_supported a m}) (st: state_spec a m)
: multiseq (lanes a m) (hash_length a) | [
{
"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
}
] | 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 | 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) = | false | null | false | let hseq = store_state st in
emit hseq | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val finish (#a: sha2_alg) (#m: m_spec{is_supported a m}) (st: state_spec a m)
: multiseq (lanes a m) (hash_length a) | [] | Hacl.Spec.SHA2.Vec.finish | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | 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) | {
"end_col": 13,
"end_line": 468,
"start_col": 47,
"start_line": 466
} |
Prims.Tot | 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) | [
{
"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
}
] | 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) | 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) = | false | null | false | 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": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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) | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | 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) | [] | Hacl.Spec.SHA2.Vec.get_multilast_spec | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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) | {
"end_col": 50,
"end_line": 450,
"start_col": 71,
"start_line": 447
} |
Prims.Tot | [
{
"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
}
] | false | let word (a:hash_alg) = uint_t (word_t a) SEC | let word (a: hash_alg) = | false | null | false | uint_t (word_t a) SEC | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"total"
] | [
"Spec.Hash.Definitions.hash_alg",
"Lib.IntTypes.uint_t",
"Spec.Hash.Definitions.word_t",
"Lib.IntTypes.SEC"
] | [] | 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 | false | true | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val word : a: Spec.Hash.Definitions.hash_alg -> Type0 | [] | Hacl.Spec.SHA2.Vec.word | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Hash.Definitions.hash_alg -> Type0 | {
"end_col": 45,
"end_line": 54,
"start_col": 24,
"start_line": 54
} |
|
Prims.Tot | 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) | [
{
"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
}
] | 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 | 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) = | false | null | false | 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": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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) : | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | 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) | [] | Hacl.Spec.SHA2.Vec.load_last | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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) | {
"end_col": 48,
"end_line": 370,
"start_col": 4,
"start_line": 367
} |
Prims.Tot | [
{
"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
}
] | false | let ws_spec (a:sha2_alg) (m:m_spec) = lseq (element_t a m) 16 | let ws_spec (a: sha2_alg) (m: m_spec) = | false | null | false | lseq (element_t a m) 16 | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"total"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Lib.Sequence.lseq",
"Hacl.Spec.SHA2.Vec.element_t"
] | [] | 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 | false | true | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val ws_spec : a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec -> Type0 | [] | Hacl.Spec.SHA2.Vec.ws_spec | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec -> Type0 | {
"end_col": 61,
"end_line": 129,
"start_col": 38,
"start_line": 129
} |
|
Prims.Tot | 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) | [
{
"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
}
] | 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) | 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) = | false | null | false | 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) | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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}) | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | 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) | [] | Hacl.Spec.SHA2.Vec.load_last1 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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) | {
"end_col": 14,
"end_line": 313,
"start_col": 94,
"start_line": 308
} |
Prims.Tot | val 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) | [
{
"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
}
] | false | 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)) | val 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)
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) = | false | null | false | 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": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Division",
"Spec.Hash.Definitions.block_length",
"Lib.NTuple.createi",
"FStar.Seq.Properties.lseq",
"Lib.IntTypes.uint8",
"FStar.Seq.Base.slice",
"Lib.NTuple.op_Lens_Access",
"FStar.Mul.op_Star",
"Prims.op_Addition"
] | [] | 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) = | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val 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) | [] | Hacl.Spec.SHA2.Vec.get_multiblock_spec | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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}
-> Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m)
(Spec.Hash.Definitions.block_length a) | {
"end_col": 93,
"end_line": 442,
"start_col": 4,
"start_line": 441
} |
Prims.Tot | val op_Amp_Bar: #a: sha2_alg -> #m: m_spec -> element_t a m -> element_t a m -> element_t a m | [
{
"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
}
] | false | 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) | val op_Amp_Bar: #a: sha2_alg -> #m: m_spec -> element_t a m -> element_t a m -> element_t a m
let op_Amp_Bar (#a: sha2_alg) (#m: m_spec) : element_t a m -> element_t a m -> element_t a m = | false | null | false | match a with
| SHA2_224 | SHA2_256 -> ( &| ) #U32 #(lanes a m)
| SHA2_384 | SHA2_512 -> ( &| ) #U64 #(lanes a m) | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"total"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Lib.IntVector.op_Amp_Bar",
"Lib.IntTypes.U32",
"Hacl.Spec.SHA2.Vec.lanes",
"Lib.IntTypes.U64",
"Hacl.Spec.SHA2.Vec.element_t"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val op_Amp_Bar: #a: sha2_alg -> #m: m_spec -> element_t a m -> element_t a m -> element_t a m | [] | Hacl.Spec.SHA2.Vec.op_Amp_Bar | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: Hacl.Spec.SHA2.Vec.element_t a m -> _: Hacl.Spec.SHA2.Vec.element_t a m
-> Hacl.Spec.SHA2.Vec.element_t a m | {
"end_col": 51,
"end_line": 80,
"start_col": 2,
"start_line": 78
} |
Prims.Tot | val transpose_ws1 (#a: sha2_alg) (#m: m_spec{lanes a m == 1}) (ws: ws_spec a m) : ws_spec a m | [
{
"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
}
] | false | let transpose_ws1 (#a:sha2_alg) (#m:m_spec{lanes a m == 1}) (ws:ws_spec a m) : ws_spec a m = ws | 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 = | false | null | false | ws | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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) | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val transpose_ws1 (#a: sha2_alg) (#m: m_spec{lanes a m == 1}) (ws: ws_spec a m) : ws_spec a m | [] | Hacl.Spec.SHA2.Vec.transpose_ws1 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | ws: Hacl.Spec.SHA2.Vec.ws_spec a m -> Hacl.Spec.SHA2.Vec.ws_spec a m | {
"end_col": 95,
"end_line": 207,
"start_col": 93,
"start_line": 207
} |
Prims.Tot | val emit (#a: sha2_alg) (#m: m_spec) (hseq: lseq uint8 (lanes a m * 8 * word_length a))
: multiseq (lanes a m) (hash_length a) | [
{
"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
}
] | false | 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)) | val emit (#a: sha2_alg) (#m: m_spec) (hseq: lseq uint8 (lanes a m * 8 * word_length a))
: multiseq (lanes a m) (hash_length a)
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) = | false | null | false | Lib.NTuple.createi #(Seq.lseq uint8 (hash_length a))
(lanes a m)
(fun i -> sub hseq ((i * 8) * word_length a) (hash_length a)) | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"total"
] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint8",
"FStar.Mul.op_Star",
"Hacl.Spec.SHA2.Vec.lanes",
"Spec.Hash.Definitions.word_length",
"Lib.NTuple.createi",
"FStar.Seq.Properties.lseq",
"Spec.Hash.Definitions.hash_length",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.Sequence.sub",
"Hacl.Spec.SHA2.Vec.multiseq"
] | [] | 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)): | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val emit (#a: sha2_alg) (#m: m_spec) (hseq: lseq uint8 (lanes a m * 8 * word_length a))
: multiseq (lanes a m) (hash_length a) | [] | Hacl.Spec.SHA2.Vec.emit | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
hseq:
Lib.Sequence.lseq Lib.IntTypes.uint8
((Hacl.Spec.SHA2.Vec.lanes a m * 8) * Spec.Hash.Definitions.word_length a)
-> Hacl.Spec.SHA2.Vec.multiseq (Hacl.Spec.SHA2.Vec.lanes a m)
(Spec.Hash.Definitions.hash_length a) | {
"end_col": 65,
"end_line": 433,
"start_col": 4,
"start_line": 432
} |
Prims.Tot | val num_rounds16 (a: sha2_alg) : n: size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} | [
{
"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
}
] | 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 | 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} = | false | null | false | match a with
| SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 5ul | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val num_rounds16 (a: sha2_alg) : n: size_t{v n > 0 /\ 16 * v n == Spec.size_k_w a} | [] | Hacl.Spec.SHA2.Vec.num_rounds16 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | 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} | {
"end_col": 30,
"end_line": 181,
"start_col": 2,
"start_line": 179
} |
Prims.Tot | val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m | [
{
"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
}
] | false | let _Sigma1 #a #m x = Spec.((x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5)) | val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m
let _Sigma1 #a #m x = | false | null | false | let open Spec in (x >>>| (op0 a).c3) ^| (x >>>| (op0 a).c4) ^| (x >>>| (op0 a).c5) | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val _Sigma1: #a:sha2_alg -> #m:m_spec -> element_t a m -> element_t a m | [] | Hacl.Spec.SHA2.Vec._Sigma1 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Hacl.Spec.SHA2.Vec.element_t a m -> Hacl.Spec.SHA2.Vec.element_t a m | {
"end_col": 94,
"end_line": 115,
"start_col": 22,
"start_line": 115
} |
Prims.Tot | 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 | [
{
"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
}
] | 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 | 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 = | false | null | false | 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": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 -> | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | 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 | [] | Hacl.Spec.SHA2.Vec.shuffle_core_spec | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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 | {
"end_col": 33,
"end_line": 174,
"start_col": 41,
"start_line": 154
} |
Prims.Tot | 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) | [
{
"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
}
] | 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) | 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) = | false | null | false | 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) | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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}) | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | 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) | [] | Hacl.Spec.SHA2.Vec.load_last4 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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) | {
"end_col": 14,
"end_line": 332,
"start_col": 94,
"start_line": 321
} |
Prims.Tot | val ws_spec_v (#a: sha2_alg) (#m: m_spec) (st: ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) | [
{
"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
}
] | 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]) | 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) = | false | null | false | 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 ]) | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val ws_spec_v (#a: sha2_alg) (#m: m_spec) (st: ws_spec a m) : lseq (lseq (word a) 16) (lanes a m) | [] | Hacl.Spec.SHA2.Vec.ws_spec_v | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | 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) | {
"end_col": 86,
"end_line": 145,
"start_col": 2,
"start_line": 140
} |
Prims.Tot | val state_spec_v (#a: sha2_alg) (#m: m_spec) (st: state_spec a m)
: lseq (words_state' a) (lanes a m) | [
{
"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
}
] | 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]) | 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) = | false | null | false | 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": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val state_spec_v (#a: sha2_alg) (#m: m_spec) (st: state_spec a m)
: lseq (words_state' a) (lanes a m) | [] | Hacl.Spec.SHA2.Vec.state_spec_v | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | 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) | {
"end_col": 82,
"end_line": 136,
"start_col": 2,
"start_line": 133
} |
Prims.Tot | val 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) | [
{
"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
}
] | false | 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) | val 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 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) = | false | null | false | 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": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"total"
] | [
"Spec.Hash.Definitions.sha2_alg",
"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",
"FStar.Pervasives.Native.Mktuple2",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.Sequence.sub",
"Prims.op_Multiply",
"Prims.l_and",
"Prims.op_Subtraction",
"Prims.l_Forall",
"Prims.op_LessThan",
"Prims.op_Addition",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Lib.Sequence.index",
"Lib.Sequence.update_sub",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.upd",
"Lib.IntTypes.mk_int",
"Prims.pow2",
"Prims.l_imp",
"Lib.Sequence.op_String_Assignment",
"Lib.IntTypes.u8",
"FStar.Seq.Base.create",
"Lib.Sequence.create",
"FStar.Pervasives.Native.tuple2"
] | [] | 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}) | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val 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) | [] | Hacl.Spec.SHA2.Vec.load_last_blocks | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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: Lib.Sequence.lseq Lib.IntTypes.uint8 len
-> Lib.Sequence.lseq Lib.IntTypes.uint8 (Spec.Hash.Definitions.block_length a) *
Lib.Sequence.lseq Lib.IntTypes.uint8 (Spec.Hash.Definitions.block_length a) | {
"end_col": 12,
"end_line": 301,
"start_col": 80,
"start_line": 294
} |
Prims.Tot | [
{
"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
}
] | false | let multiblock_spec (a:sha2_alg) (m:m_spec) =
multiseq (lanes a m) (block_length a) | let multiblock_spec (a: sha2_alg) (m: m_spec) = | false | null | false | multiseq (lanes a m) (block_length a) | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | true | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val multiblock_spec : a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec -> Type0 | [] | Hacl.Spec.SHA2.Vec.multiblock_spec | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Hash.Definitions.sha2_alg -> m: Hacl.Spec.SHA2.Vec.m_spec -> Type0 | {
"end_col": 39,
"end_line": 188,
"start_col": 2,
"start_line": 188
} |
|
Prims.Tot | val 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) | [
{
"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
}
] | false | 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) | val 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 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) = | false | null | false | 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) | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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.ntup8",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.SHA2.Vec.load_last_blocks",
"Lib.NTuple.op_Lens_Access"
] | [] | 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}) | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | val 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) | [] | Hacl.Spec.SHA2.Vec.load_last8 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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) | {
"end_col": 14,
"end_line": 358,
"start_col": 94,
"start_line": 339
} |
Prims.Tot | 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 | [
{
"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
}
] | 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 | 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 = | false | null | false | 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": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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"] | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | 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 | [] | Hacl.Spec.SHA2.Vec.update | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | 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 | {
"end_col": 25,
"end_line": 282,
"start_col": 116,
"start_line": 278
} |
Prims.Tot | [
{
"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
}
] | false | let sha512 (len:Spec.len_lt_max_a_t SHA2_512) (b:seq uint8{length b = len}) =
hash #SHA2_512 #M32 len b | let sha512 (len: Spec.len_lt_max_a_t SHA2_512) (b: seq uint8 {length b = len}) = | false | null | false | hash #SHA2_512 #M32 len b | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | 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) | [] | Hacl.Spec.SHA2.Vec.sha512 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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) | {
"end_col": 27,
"end_line": 490,
"start_col": 2,
"start_line": 490
} |
|
Prims.Tot | [
{
"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
}
] | false | let sha256 (len:Spec.len_lt_max_a_t SHA2_256) (b:seq uint8{length b = len}) =
hash #SHA2_256 #M32 len b | let sha256 (len: Spec.len_lt_max_a_t SHA2_256) (b: seq uint8 {length b = len}) = | false | null | false | hash #SHA2_256 #M32 len b | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | 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) | [] | Hacl.Spec.SHA2.Vec.sha256 | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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) | {
"end_col": 27,
"end_line": 482,
"start_col": 2,
"start_line": 482
} |
|
Prims.Tot | 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) | [
{
"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
}
] | 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 | 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) = | false | null | false | let st = transpose_state st in
Lib.IntVector.Serialize.vecs_to_bytes_be st | {
"checked_file": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | 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) | [] | Hacl.Spec.SHA2.Vec.store_state | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | 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) | {
"end_col": 47,
"end_line": 426,
"start_col": 60,
"start_line": 424
} |
Prims.Tot | 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 | [
{
"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
}
] | 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)) | 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 = | false | null | false | 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": "Hacl.Spec.SHA2.Vec.fst.checked",
"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"
} | [
"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"
] | [] | 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) | false | false | Hacl.Spec.SHA2.Vec.fst | {
"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"
} | null | 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 | [] | Hacl.Spec.SHA2.Vec.load_elementi | {
"file_name": "code/sha2-mb/Hacl.Spec.SHA2.Vec.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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 | {
"end_col": 85,
"end_line": 193,
"start_col": 123,
"start_line": 191
} |
Prims.Tot | val frodo_shake_r:
a:frodo_alg
-> c:uint8
-> seed_se:lbytes (crypto_bytes a)
-> output_len:size_nat
-> lbytes output_len | [
{
"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
}
] | 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 | 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 = | false | null | false | 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 | {
"checked_file": "Spec.Frodo.KEM.KeyGen.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Spec.Frodo.KEM.KeyGen.fst | {
"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"
} | null | val frodo_shake_r:
a:frodo_alg
-> c:uint8
-> seed_se:lbytes (crypto_bytes a)
-> output_len:size_nat
-> lbytes output_len | [] | Spec.Frodo.KEM.KeyGen.frodo_shake_r | {
"file_name": "specs/frodo/Spec.Frodo.KEM.KeyGen.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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 | {
"end_col": 67,
"end_line": 29,
"start_col": 42,
"start_line": 26
} |
Prims.Tot | 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)) | [
{
"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
}
] | 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 | 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 = | false | null | false | let coins, _ = Spec.Frodo.Random.randombytes_ state (2 * crypto_bytes a + bytes_seed_a) in
crypto_kem_keypair_ a gen_a coins | {
"checked_file": "Spec.Frodo.KEM.KeyGen.fst.checked",
"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"
} | [
"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_"
] | [] | 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)) | false | false | Spec.Frodo.KEM.KeyGen.fst | {
"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"
} | null | 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)) | [] | Spec.Frodo.KEM.KeyGen.crypto_kem_keypair | {
"file_name": "specs/frodo/Spec.Frodo.KEM.KeyGen.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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) | {
"end_col": 35,
"end_line": 130,
"start_col": 38,
"start_line": 128
} |
Prims.Tot | 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 | [
{
"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
}
] | 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 | 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 = | false | null | false | 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 | {
"checked_file": "Spec.Frodo.KEM.KeyGen.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Spec.Frodo.KEM.KeyGen.fst | {
"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"
} | null | 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 | [] | Spec.Frodo.KEM.KeyGen.get_s_e_matrices | {
"file_name": "specs/frodo/Spec.Frodo.KEM.KeyGen.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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 | {
"end_col": 20,
"end_line": 70,
"start_col": 32,
"start_line": 65
} |
Prims.Tot | 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) | [
{
"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
}
] | 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 | 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 = | false | null | false | 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 | {
"checked_file": "Spec.Frodo.KEM.KeyGen.fst.checked",
"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"
} | [
"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"
] | [] | 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) | false | false | Spec.Frodo.KEM.KeyGen.fst | {
"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"
} | null | 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) | [] | Spec.Frodo.KEM.KeyGen.crypto_kem_sk | {
"file_name": "specs/frodo/Spec.Frodo.KEM.KeyGen.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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) | {
"end_col": 8,
"end_line": 98,
"start_col": 34,
"start_line": 94
} |
Prims.Tot | 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)) | [
{
"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
}
] | 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 | 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 = | false | null | false | 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 | {
"checked_file": "Spec.Frodo.KEM.KeyGen.fst.checked",
"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"
} | [
"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"
] | [] | 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)) | false | false | Spec.Frodo.KEM.KeyGen.fst | {
"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"
} | null | 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)) | [] | Spec.Frodo.KEM.KeyGen.frodo_mul_add_as_plus_e_pack_shake | {
"file_name": "specs/frodo/Spec.Frodo.KEM.KeyGen.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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) | {
"end_col": 18,
"end_line": 84,
"start_col": 63,
"start_line": 80
} |
Prims.Tot | 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 | [
{
"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
}
] | 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 | 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 = | false | null | false | 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 | {
"checked_file": "Spec.Frodo.KEM.KeyGen.fst.checked",
"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"
} | [
"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"
] | [] | 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 | false | false | Spec.Frodo.KEM.KeyGen.fst | {
"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"
} | null | 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 | [] | Spec.Frodo.KEM.KeyGen.frodo_mul_add_as_plus_e | {
"file_name": "specs/frodo/Spec.Frodo.KEM.KeyGen.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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 | {
"end_col": 10,
"end_line": 44,
"start_col": 2,
"start_line": 41
} |
Prims.Tot | 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)) | [
{
"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
}
] | 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 | 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 = | false | null | false | 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 | {
"checked_file": "Spec.Frodo.KEM.KeyGen.fst.checked",
"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"
} | [
"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"
] | [] | 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)) | false | false | Spec.Frodo.KEM.KeyGen.fst | {
"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"
} | null | 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)) | [] | Spec.Frodo.KEM.KeyGen.crypto_kem_keypair_ | {
"file_name": "specs/frodo/Spec.Frodo.KEM.KeyGen.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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) | {
"end_col": 8,
"end_line": 119,
"start_col": 2,
"start_line": 108
} |
Prims.Tot | 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) | [
{
"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
}
] | 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 | 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 = | false | null | false | 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 | {
"checked_file": "Spec.Frodo.KEM.KeyGen.fst.checked",
"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"
} | [
"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"
] | [] | 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) | false | false | Spec.Frodo.KEM.KeyGen.fst | {
"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"
} | null | 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) | [] | Spec.Frodo.KEM.KeyGen.frodo_mul_add_as_plus_e_pack | {
"file_name": "specs/frodo/Spec.Frodo.KEM.KeyGen.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
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) | {
"end_col": 37,
"end_line": 57,
"start_col": 67,
"start_line": 55
} |
Prims.Tot | [
{
"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.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.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
}
] | false | let (<<:) (l: list 'a) (r: 'r)
= forallP (fun x -> x << r) l | let op_Less_Less_Colon (l: list 'a) (r: 'r) = | false | null | false | forallP (fun x -> x << r) l | {
"checked_file": "FStar.Reflection.V1.Derived.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Reflection.V1.Data.fsti.checked",
"FStar.Reflection.V1.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.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"
} | [
"total"
] | [
"Prims.list",
"FStar.Reflection.V1.Derived.Lemmas.forallP",
"Prims.precedes"
] | [] | (*
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.Reflection.Types
open FStar.Reflection.V1.Builtins
open FStar.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 | false | false | FStar.Reflection.V1.Derived.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val op_Less_Less_Colon : l: Prims.list 'a -> r: 'r -> Type0 | [] | FStar.Reflection.V1.Derived.Lemmas.op_Less_Less_Colon | {
"file_name": "ulib/FStar.Reflection.V1.Derived.Lemmas.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | l: Prims.list 'a -> r: 'r -> Type0 | {
"end_col": 31,
"end_line": 33,
"start_col": 4,
"start_line": 33
} |
|
Prims.Tot | val collect_abs_ln_ref : (t:term) -> list (bd:binder{bd << t}) * (body:term{body == t \/ body << t}) | [
{
"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.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.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
}
] | false | let collect_abs_ln_ref t =
let bds, body = collect_abs_ln t in
collect_abs_ln_order t;
list_ref bds, body | val collect_abs_ln_ref : (t:term) -> list (bd:binder{bd << t}) * (body:term{body == t \/ body << t})
let collect_abs_ln_ref t = | false | null | false | let bds, body = collect_abs_ln t in
collect_abs_ln_order t;
list_ref bds, body | {
"checked_file": "FStar.Reflection.V1.Derived.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Reflection.V1.Data.fsti.checked",
"FStar.Reflection.V1.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.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"
} | [
"total"
] | [
"FStar.Reflection.Types.term",
"Prims.list",
"FStar.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"
] | [] | (*
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.Reflection.Types
open FStar.Reflection.V1.Builtins
open FStar.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)
| _ -> () | false | false | FStar.Reflection.V1.Derived.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val collect_abs_ln_ref : (t:term) -> list (bd:binder{bd << t}) * (body:term{body == t \/ body << t}) | [] | FStar.Reflection.V1.Derived.Lemmas.collect_abs_ln_ref | {
"file_name": "ulib/FStar.Reflection.V1.Derived.Lemmas.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Reflection.Types.term
-> Prims.list (bd: FStar.Reflection.Types.binder{bd << t}) *
body:
FStar.Reflection.Types.term{body == t \/ body << t} | {
"end_col": 22,
"end_line": 97,
"start_col": 26,
"start_line": 94
} |
Prims.Pure | val list_ref : (#a:Type) -> (#p:(a -> Type)) -> (l:list a) ->
Pure (list (x:a{p x}))
(requires (forallP p l))
(ensures (fun _ -> True)) | [
{
"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.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.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
}
] | false | let rec list_ref #a #p l =
match l with
| [] -> []
| x::xs -> x :: list_ref #a #p xs | 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 = | false | null | false | match l with
| [] -> []
| x :: xs -> x :: list_ref #a #p xs | {
"checked_file": "FStar.Reflection.V1.Derived.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Reflection.V1.Data.fsti.checked",
"FStar.Reflection.V1.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.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"
} | [] | [
"Prims.list",
"Prims.Nil",
"Prims.Cons",
"FStar.Reflection.V1.Derived.Lemmas.list_ref"
] | [] | (*
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.Reflection.Types
open FStar.Reflection.V1.Builtins
open FStar.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)) | false | false | FStar.Reflection.V1.Derived.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val list_ref : (#a:Type) -> (#p:(a -> Type)) -> (l:list a) ->
Pure (list (x:a{p x}))
(requires (forallP p l))
(ensures (fun _ -> True)) | [
"recursion"
] | FStar.Reflection.V1.Derived.Lemmas.list_ref | {
"file_name": "ulib/FStar.Reflection.V1.Derived.Lemmas.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | l: Prims.list a -> Prims.Pure (Prims.list (x: a{p x})) | {
"end_col": 37,
"end_line": 43,
"start_col": 4,
"start_line": 41
} |
FStar.Pervasives.Lemma | 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 == [])
) | [
{
"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.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.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
}
] | 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) | 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 = | false | null | true | 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) | {
"checked_file": "FStar.Reflection.V1.Derived.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Reflection.V1.Data.fsti.checked",
"FStar.Reflection.V1.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.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"
} | [
"lemma"
] | [
"FStar.Reflection.Types.term",
"FStar.Reflection.V1.Derived.inspect_ln_unascribe",
"FStar.Reflection.Types.binder",
"FStar.Reflection.Types.comp",
"FStar.Reflection.V1.Builtins.inspect_pack_comp_inv",
"FStar.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.Reflection.V1.Data.term_view"
] | [] | (*
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.Reflection.Types
open FStar.Reflection.V1.Builtins
open FStar.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 == [])
) | false | false | FStar.Reflection.V1.Derived.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val 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 == [])
) | [] | FStar.Reflection.V1.Derived.Lemmas.collect_arr_ln_bs_order | {
"file_name": "ulib/FStar.Reflection.V1.Derived.Lemmas.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Reflection.Types.term
-> FStar.Pervasives.Lemma
(ensures
forall (bds: Prims.list FStar.Reflection.Types.binder) (c: FStar.Reflection.Types.comp).
FStar.Pervasives.Native.Mktuple2 bds c == FStar.Reflection.V1.Derived.collect_arr_ln_bs t ==>
c << t /\ bds <<: t \/
c == FStar.Reflection.V1.Builtins.pack_comp (FStar.Reflection.V1.Data.C_Total t) /\
bds == []) | {
"end_col": 42,
"end_line": 125,
"start_col": 2,
"start_line": 121
} |
Prims.Tot | val collect_arr_ln_bs_ref : (t:term) -> list (bd:binder{bd << t})
* (c:comp{ c == pack_comp (C_Total t) \/ c << t}) | [
{
"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.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.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
}
] | 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 | 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 = | false | null | false | let bds, c = collect_arr_ln_bs t in
collect_arr_ln_bs_order t;
list_ref bds, c | {
"checked_file": "FStar.Reflection.V1.Derived.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Reflection.V1.Data.fsti.checked",
"FStar.Reflection.V1.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.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"
} | [
"total"
] | [
"FStar.Reflection.Types.term",
"Prims.list",
"FStar.Reflection.Types.binder",
"FStar.Reflection.Types.comp",
"FStar.Pervasives.Native.Mktuple2",
"Prims.precedes",
"Prims.l_or",
"Prims.eq2",
"FStar.Reflection.V1.Builtins.pack_comp",
"FStar.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"
] | [] | (*
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.Reflection.Types
open FStar.Reflection.V1.Builtins
open FStar.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}) | false | false | FStar.Reflection.V1.Derived.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val collect_arr_ln_bs_ref : (t:term) -> list (bd:binder{bd << t})
* (c:comp{ c == pack_comp (C_Total t) \/ c << t}) | [] | FStar.Reflection.V1.Derived.Lemmas.collect_arr_ln_bs_ref | {
"file_name": "ulib/FStar.Reflection.V1.Derived.Lemmas.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Reflection.Types.term
-> Prims.list (bd: FStar.Reflection.Types.binder{bd << t}) *
c:
FStar.Reflection.Types.comp
{c == FStar.Reflection.V1.Builtins.pack_comp (FStar.Reflection.V1.Data.C_Total t) \/ c << t} | {
"end_col": 19,
"end_line": 132,
"start_col": 29,
"start_line": 129
} |
Prims.Tot | val collect_app_ref : (t:term) -> (h:term{h == t \/ h << t}) * list (a:argv{fst a << t}) | [
{
"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.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.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
}
] | false | let collect_app_ref t =
let h, a = collect_app_ln t in
collect_app_order t;
h, list_ref a | val collect_app_ref : (t:term) -> (h:term{h == t \/ h << t}) * list (a:argv{fst a << t})
let collect_app_ref t = | false | null | false | let h, a = collect_app_ln t in
collect_app_order t;
h, list_ref a | {
"checked_file": "FStar.Reflection.V1.Derived.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Reflection.V1.Data.fsti.checked",
"FStar.Reflection.V1.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.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"
} | [
"total"
] | [
"FStar.Reflection.Types.term",
"Prims.list",
"FStar.Reflection.V1.Data.argv",
"FStar.Pervasives.Native.Mktuple2",
"Prims.l_or",
"Prims.eq2",
"Prims.precedes",
"FStar.Pervasives.Native.fst",
"FStar.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"
] | [] | (*
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.Reflection.Types
open FStar.Reflection.V1.Builtins
open FStar.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
| _ -> () | false | false | FStar.Reflection.V1.Derived.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val collect_app_ref : (t:term) -> (h:term{h == t \/ h << t}) * list (a:argv{fst a << t}) | [] | FStar.Reflection.V1.Derived.Lemmas.collect_app_ref | {
"file_name": "ulib/FStar.Reflection.V1.Derived.Lemmas.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Reflection.Types.term
-> h:
FStar.Reflection.Types.term{h == t \/ h << t} *
Prims.list (a: FStar.Reflection.V1.Data.argv{FStar.Pervasives.Native.fst a << t}) | {
"end_col": 17,
"end_line": 68,
"start_col": 23,
"start_line": 65
} |
FStar.Pervasives.Lemma | 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 == [])
) | [
{
"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.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.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
}
] | 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)
| _ -> () | 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 = | false | null | true | 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": "FStar.Reflection.V1.Derived.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Reflection.V1.Data.fsti.checked",
"FStar.Reflection.V1.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.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"
} | [
"lemma"
] | [
"FStar.Reflection.Types.term",
"FStar.Reflection.V1.Derived.inspect_ln_unascribe",
"FStar.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.Reflection.V1.Data.term_view"
] | [] | (*
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.Reflection.Types
open FStar.Reflection.V1.Builtins
open FStar.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 == [])
) | false | false | FStar.Reflection.V1.Derived.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val collect_abs_ln_order : (t:term) ->
Lemma (ensures forall bds body.
(bds, body) == collect_abs_ln t ==>
(body << t /\ bds <<: t)
\/ (body == t /\ bds == [])
) | [] | FStar.Reflection.V1.Derived.Lemmas.collect_abs_ln_order | {
"file_name": "ulib/FStar.Reflection.V1.Derived.Lemmas.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Reflection.Types.term
-> FStar.Pervasives.Lemma
(ensures
forall (bds: Prims.list FStar.Reflection.Types.binder) (body: FStar.Reflection.Types.term).
FStar.Pervasives.Native.Mktuple2 bds body == FStar.Reflection.V1.Derived.collect_abs_ln t ==>
body << t /\ bds <<: t \/ body == t /\ bds == []) | {
"end_col": 13,
"end_line": 91,
"start_col": 4,
"start_line": 87
} |
FStar.Pervasives.Lemma | 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) | [
{
"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.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.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
}
] | 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
| _ -> () | 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) = | false | null | true | match inspect_ln_unascribe t with
| Tv_Abs b body -> collect_abs_order' (b :: bds) tt body
| _ -> () | {
"checked_file": "FStar.Reflection.V1.Derived.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Reflection.V1.Data.fsti.checked",
"FStar.Reflection.V1.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.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"
} | [
"lemma",
""
] | [
"FStar.Reflection.Types.binders",
"FStar.Reflection.Types.term",
"FStar.Reflection.V1.Derived.inspect_ln_unascribe",
"FStar.Reflection.Types.binder",
"FStar.Reflection.V1.Derived.Lemmas.collect_abs_order'",
"Prims.Cons",
"FStar.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"
] | [] | (*
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.Reflection.Types
open FStar.Reflection.V1.Builtins
open FStar.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))) | false | false | FStar.Reflection.V1.Derived.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val 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) | [
"recursion"
] | FStar.Reflection.V1.Derived.Lemmas.collect_abs_order' | {
"file_name": "ulib/FStar.Reflection.V1.Derived.Lemmas.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
bds: FStar.Reflection.Types.binders ->
tt: FStar.Reflection.Types.term ->
t: FStar.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) | {
"end_col": 13,
"end_line": 78,
"start_col": 4,
"start_line": 76
} |
FStar.Pervasives.Lemma | 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) | [
{
"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.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.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
}
] | 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
| _ -> ())
| _ -> () | 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) = | false | null | true | 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
| _ -> ())
| _ -> () | {
"checked_file": "FStar.Reflection.V1.Derived.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Reflection.V1.Data.fsti.checked",
"FStar.Reflection.V1.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.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"
} | [
"lemma",
""
] | [
"FStar.Reflection.Types.binders",
"FStar.Reflection.Types.term",
"FStar.Reflection.Types.comp",
"FStar.Reflection.V1.Builtins.inspect_comp",
"FStar.Reflection.Types.typ",
"FStar.Reflection.V1.Derived.inspect_ln_unascribe",
"FStar.Reflection.Types.binder",
"FStar.Reflection.V1.Derived.Lemmas.collect_arr_order'",
"Prims.Cons",
"FStar.Reflection.V1.Data.term_view",
"Prims.unit",
"FStar.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"
] | [] | (*
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.Reflection.Types
open FStar.Reflection.V1.Builtins
open FStar.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)) | false | false | FStar.Reflection.V1.Derived.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val 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) | [
"recursion"
] | FStar.Reflection.V1.Derived.Lemmas.collect_arr_order' | {
"file_name": "ulib/FStar.Reflection.V1.Derived.Lemmas.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
bds: FStar.Reflection.Types.binders ->
tt: FStar.Reflection.Types.term ->
c: FStar.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) | {
"end_col": 13,
"end_line": 112,
"start_col": 4,
"start_line": 107
} |
FStar.Pervasives.Lemma | 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 == []))) | [
{
"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.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.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
}
] | false | let collect_app_order t =
match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' [r] t 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 = | false | null | true | match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' [r] t l
| _ -> () | {
"checked_file": "FStar.Reflection.V1.Derived.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Reflection.V1.Data.fsti.checked",
"FStar.Reflection.V1.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.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"
} | [
"lemma"
] | [
"FStar.Reflection.Types.term",
"FStar.Reflection.V1.Derived.inspect_ln_unascribe",
"FStar.Reflection.V1.Data.argv",
"FStar.Reflection.V1.Derived.Lemmas.collect_app_order'",
"Prims.Cons",
"Prims.Nil",
"FStar.Reflection.V1.Data.term_view",
"Prims.unit"
] | [] | (*
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.Reflection.Types
open FStar.Reflection.V1.Builtins
open FStar.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 == []))) | false | false | FStar.Reflection.V1.Derived.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val 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 == []))) | [] | FStar.Reflection.V1.Derived.Lemmas.collect_app_order | {
"file_name": "ulib/FStar.Reflection.V1.Derived.Lemmas.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Reflection.Types.term
-> FStar.Pervasives.Lemma
(ensures
forall (f: FStar.Reflection.Types.term) (s: Prims.list FStar.Reflection.V1.Data.argv).
FStar.Pervasives.Native.Mktuple2 f s == FStar.Reflection.V1.Derived.collect_app_ln t ==>
f << t /\ s <<: t \/ f == t /\ s == []) | {
"end_col": 13,
"end_line": 62,
"start_col": 4,
"start_line": 60
} |
FStar.Pervasives.Lemma | 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) | [
{
"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.Reflection.V1.Data",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.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
}
] | 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
| _ -> () | 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 = | false | null | true | match inspect_ln_unascribe t with
| Tv_App l r -> collect_app_order' (r :: args) tt l
| _ -> () | {
"checked_file": "FStar.Reflection.V1.Derived.Lemmas.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Reflection.V1.Derived.fst.checked",
"FStar.Reflection.V1.Data.fsti.checked",
"FStar.Reflection.V1.Builtins.fsti.checked",
"FStar.Reflection.Types.fsti.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"
} | [
"lemma",
""
] | [
"Prims.list",
"FStar.Reflection.V1.Data.argv",
"FStar.Reflection.Types.term",
"FStar.Reflection.V1.Derived.inspect_ln_unascribe",
"FStar.Reflection.V1.Derived.Lemmas.collect_app_order'",
"Prims.Cons",
"FStar.Reflection.V1.Data.term_view",
"Prims.unit"
] | [] | (*
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.Reflection.Types
open FStar.Reflection.V1.Builtins
open FStar.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) | false | false | FStar.Reflection.V1.Derived.Lemmas.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val 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) | [
"recursion"
] | FStar.Reflection.V1.Derived.Lemmas.collect_app_order' | {
"file_name": "ulib/FStar.Reflection.V1.Derived.Lemmas.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} |
args: Prims.list FStar.Reflection.V1.Data.argv ->
tt: FStar.Reflection.Types.term ->
t: FStar.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) | {
"end_col": 13,
"end_line": 53,
"start_col": 4,
"start_line": 51
} |
Prims.Tot | val poly1305_update1: poly1305_update1_st M256 | [
{
"abbrev": false,
"full_module": "Hacl.Meta.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let poly1305_update1 = poly1305_update1 #M256 | val poly1305_update1: poly1305_update1_st M256
let poly1305_update1 = | false | null | false | poly1305_update1 #M256 | {
"checked_file": "Hacl.Poly1305_256.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Meta.Poly1305.fst.checked",
"Hacl.Meta.Poly1305.fst.checked",
"Hacl.Impl.Poly1305.Fields.fst.checked",
"Hacl.Impl.Poly1305.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Poly1305_256.fst"
} | [
"total"
] | [
"Hacl.Impl.Poly1305.poly1305_update1",
"Hacl.Impl.Poly1305.Fields.M256"
] | [] | module Hacl.Poly1305_256
open FStar.HyperStack
open FStar.HyperStack.All
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.Poly1305.Fields
open Hacl.Impl.Poly1305
open Hacl.Meta.Poly1305
friend Hacl.Meta.Poly1305
let poly1305_init = poly1305_init #M256 | false | true | Hacl.Poly1305_256.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val poly1305_update1: poly1305_update1_st M256 | [] | Hacl.Poly1305_256.poly1305_update1 | {
"file_name": "code/poly1305/Hacl.Poly1305_256.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Impl.Poly1305.poly1305_update1_st Hacl.Impl.Poly1305.Fields.M256 | {
"end_col": 45,
"end_line": 17,
"start_col": 23,
"start_line": 17
} |
Prims.Tot | val poly1305_init: poly1305_init_st M256 | [
{
"abbrev": false,
"full_module": "Hacl.Meta.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let poly1305_init = poly1305_init #M256 | val poly1305_init: poly1305_init_st M256
let poly1305_init = | false | null | false | poly1305_init #M256 | {
"checked_file": "Hacl.Poly1305_256.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Meta.Poly1305.fst.checked",
"Hacl.Meta.Poly1305.fst.checked",
"Hacl.Impl.Poly1305.Fields.fst.checked",
"Hacl.Impl.Poly1305.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Poly1305_256.fst"
} | [
"total"
] | [
"Hacl.Impl.Poly1305.poly1305_init",
"Hacl.Impl.Poly1305.Fields.M256"
] | [] | module Hacl.Poly1305_256
open FStar.HyperStack
open FStar.HyperStack.All
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.Poly1305.Fields
open Hacl.Impl.Poly1305
open Hacl.Meta.Poly1305
friend Hacl.Meta.Poly1305 | false | true | Hacl.Poly1305_256.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val poly1305_init: poly1305_init_st M256 | [] | Hacl.Poly1305_256.poly1305_init | {
"file_name": "code/poly1305/Hacl.Poly1305_256.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Impl.Poly1305.poly1305_init_st Hacl.Impl.Poly1305.Fields.M256 | {
"end_col": 39,
"end_line": 15,
"start_col": 20,
"start_line": 15
} |
Prims.Tot | val poly1305_update: poly1305_update_st M256 | [
{
"abbrev": false,
"full_module": "Hacl.Meta.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let poly1305_update = poly1305_update #M256 | val poly1305_update: poly1305_update_st M256
let poly1305_update = | false | null | false | poly1305_update #M256 | {
"checked_file": "Hacl.Poly1305_256.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Meta.Poly1305.fst.checked",
"Hacl.Meta.Poly1305.fst.checked",
"Hacl.Impl.Poly1305.Fields.fst.checked",
"Hacl.Impl.Poly1305.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Poly1305_256.fst"
} | [
"total"
] | [
"Hacl.Impl.Poly1305.poly1305_update",
"Hacl.Impl.Poly1305.Fields.M256"
] | [] | module Hacl.Poly1305_256
open FStar.HyperStack
open FStar.HyperStack.All
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.Poly1305.Fields
open Hacl.Impl.Poly1305
open Hacl.Meta.Poly1305
friend Hacl.Meta.Poly1305
let poly1305_init = poly1305_init #M256
let poly1305_update1 = poly1305_update1 #M256 | false | true | Hacl.Poly1305_256.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val poly1305_update: poly1305_update_st M256 | [] | Hacl.Poly1305_256.poly1305_update | {
"file_name": "code/poly1305/Hacl.Poly1305_256.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Impl.Poly1305.poly1305_update_st Hacl.Impl.Poly1305.Fields.M256 | {
"end_col": 43,
"end_line": 19,
"start_col": 22,
"start_line": 19
} |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.