file_name
stringlengths 5
52
| name
stringlengths 4
95
| original_source_type
stringlengths 0
23k
| source_type
stringlengths 9
23k
| source_definition
stringlengths 9
57.9k
| source
dict | source_range
dict | file_context
stringlengths 0
721k
| dependencies
dict | opens_and_abbrevs
listlengths 2
94
| vconfig
dict | interleaved
bool 1
class | verbose_type
stringlengths 1
7.42k
| effect
stringclasses 118
values | effect_flags
sequencelengths 0
2
| mutual_with
sequencelengths 0
11
| ideal_premises
sequencelengths 0
236
| proof_features
sequencelengths 0
1
| is_simple_lemma
bool 2
classes | is_div
bool 2
classes | is_proof
bool 2
classes | is_simply_typed
bool 2
classes | is_type
bool 2
classes | partial_definition
stringlengths 5
3.99k
| completed_definiton
stringlengths 1
1.63M
| isa_cross_project_example
bool 1
class |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Pulse.Checker.Prover.fst | Pulse.Checker.Prover.canon_post | val canon_post (c: comp_st) : comp_st | val canon_post (c: comp_st) : comp_st | let canon_post (c:comp_st) : comp_st =
let canon_st_comp_post (c:st_comp) : st_comp =
match Pulse.Readback.readback_ty (elab_term c.post) with
| None -> c
| Some post -> { c with post }
in
match c with
| C_ST s -> C_ST (canon_st_comp_post s)
| C_STAtomic i obs s -> C_STAtomic i obs (canon_st_comp_post s)
| C_STGhost s -> C_STGhost (canon_st_comp_post s) | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 51,
"end_line": 294,
"start_col": 0,
"start_line": 285
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Prover
open FStar.List.Tot
open Pulse.Syntax
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Checker.Base
module RU = Pulse.RuntimeUtils
module L = FStar.List.Tot
module T = FStar.Tactics.V2
module P = Pulse.Syntax.Printer
module Pprint = FStar.Stubs.Pprint
module Metatheory = Pulse.Typing.Metatheory
module PS = Pulse.Checker.Prover.Substs
module ElimExists = Pulse.Checker.Prover.ElimExists
module ElimPure = Pulse.Checker.Prover.ElimPure
module Match = Pulse.Checker.Prover.Match
module IntroExists = Pulse.Checker.Prover.IntroExists
module IntroPure = Pulse.Checker.Prover.IntroPure
let coerce_eq (#a #b:Type) (x:a) (_:squash (a == b)) : y:b{y == x} = x
let elim_exists_and_pure (#g:env) (#ctxt:vprop)
(ctxt_typing:tot_typing g ctxt tm_vprop)
: T.Tac (g':env { env_extends g' g } &
ctxt':term &
tot_typing g' ctxt' tm_vprop &
continuation_elaborator g ctxt g' ctxt') =
let (| g1, ctxt1, d1, k1 |) = ElimExists.elim_exists ctxt_typing in
let (| g2, ctxt2, d2, k2 |) = ElimPure.elim_pure d1 in
(| g2, ctxt2, d2, k_elab_trans k1 k2 |)
let unsolved_equiv_pst (#preamble:_) (pst:prover_state preamble) (unsolved':list vprop)
(d:vprop_equiv (push_env pst.pg pst.uvs) (list_as_vprop pst.unsolved) (list_as_vprop unsolved'))
: prover_state preamble =
{ pst with unsolved = unsolved'; goals_inv = RU.magic () }
let rec collect_exists (g:env) (l:list vprop)
: exs:list vprop &
rest:list vprop &
vprop_equiv g (list_as_vprop l) (list_as_vprop (exs @ rest)) =
match l with
| [] -> (| [], [], VE_Refl _ _ |)
| hd::tl ->
let (| exs, rest, _ |) = collect_exists g tl in
match hd.t with
| Tm_ExistsSL _ _ _ ->
(| hd::exs, rest, RU.magic #(vprop_equiv _ _ _) () |)
| _ -> (| exs, hd::rest, RU.magic #(vprop_equiv _ _ _) () |)
let rec collect_pures (g:env) (l:list vprop)
: pures:list vprop &
rest:list vprop &
vprop_equiv g (list_as_vprop l) (list_as_vprop (rest @ pures)) =
match l with
| [] -> (| [], [], VE_Refl _ _ |)
| hd::tl ->
let (| pures, rest, _ |) = collect_pures g tl in
match hd.t with
| Tm_Pure _ -> (| hd::pures, rest, RU.magic #(vprop_equiv _ _ _) () |)
| _ -> (| pures, hd::rest, RU.magic #(vprop_equiv _ _ _) () |)
let rec prove_pures #preamble (pst:prover_state preamble)
: T.Tac (pst':prover_state preamble { pst' `pst_extends` pst /\
is_terminal pst' }) =
match pst.unsolved with
| [] -> pst
| {t=Tm_Pure p}::unsolved' ->
let pst_opt = IntroPure.intro_pure pst p unsolved' () in
(match pst_opt with
| None ->
let open Pulse.PP in
fail_doc pst.pg None [
text "Cannot prove pure proposition" ^/^
pp p
]
| Some pst1 ->
let pst2 = prove_pures pst1 in
assert (pst1 `pst_extends` pst);
assert (pst2 `pst_extends` pst1);
assert (pst2 `pst_extends` pst);
pst2)
| _ ->
fail pst.pg None
(Printf.sprintf "Impossible! prover.prove_pures: %s is not a pure, please file a bug-report"
(P.term_to_string (L.hd pst.unsolved)))
#push-options "--z3rlimit_factor 4"
let rec prover
(#preamble:_)
(pst0:prover_state preamble)
: T.Tac (pst':prover_state preamble { pst' `pst_extends` pst0 /\
is_terminal pst' }) =
debug_prover pst0.pg (fun _ ->
Printf.sprintf "At the prover top-level with remaining_ctxt: %s\nunsolved: %s"
(P.term_to_string (list_as_vprop pst0.remaining_ctxt))
(P.term_to_string (list_as_vprop pst0.unsolved)));
match pst0.unsolved with
| [] -> pst0
| _ ->
let pst = ElimExists.elim_exists_pst pst0 in
debug_prover pst.pg (fun _ ->
Printf.sprintf "prover: remaining_ctxt after elim exists: %s\n"
(P.term_to_string (list_as_vprop pst.remaining_ctxt)));
let pst = ElimPure.elim_pure_pst pst in
debug_prover pst.pg (fun _ ->
Printf.sprintf "prover: remaining_ctxt after elim pure: %s\n"
(P.term_to_string (list_as_vprop pst.remaining_ctxt)));
let (| exs, rest, d |) = collect_exists (push_env pst.pg pst.uvs) pst.unsolved in
debug_prover pst.pg (fun _ ->
Printf.sprintf "prover: tried to pull exists: exs: %s and rest: %s\n"
(P.term_to_string (list_as_vprop exs)) (P.term_to_string (list_as_vprop rest)));
let pst = unsolved_equiv_pst pst (exs@rest) d in
debug_prover pst.pg (fun _ ->
Printf.sprintf "prover: unsolved after pulling exists at the top: %s\n"
(P.term_to_string (list_as_vprop pst.unsolved)));
match pst.unsolved with
| {t=Tm_ExistsSL u b body}::unsolved' ->
IntroExists.intro_exists pst u b body unsolved' () prover
| _ ->
let (| pures, rest, d |) = collect_pures (push_env pst.pg pst.uvs) pst.unsolved in
let pst = unsolved_equiv_pst pst (rest@pures) d in
match pst.unsolved with
| {t=Tm_Pure _}::tl -> prove_pures pst
| q::tl ->
let pst_opt = Match.match_q pst q tl () prover in
match pst_opt with
| None ->
let open Pprint in
let open Pulse.PP in
let msg = [
text "Cannot prove:" ^^
indent (pp q);
text "In the context:" ^^
indent (pp (list_as_vprop pst.remaining_ctxt))
] @ (if Pulse.Config.debug_flag "initial_solver_state" then [
text "The prover was started with goal:" ^^
indent (pp preamble.goals);
text "and initial context:" ^^
indent (pp preamble.ctxt);
] else [])
in
// GM: I feel I should use (Some q.range) instead of None, but that makes
// several error locations worse.
fail_doc pst.pg None msg
| Some pst -> prover pst // a little wasteful?
#pop-options
let rec get_q_at_hd (g:env) (l:list vprop) (q:vprop { L.existsb (fun v -> eq_tm v q) l })
: l':list vprop &
vprop_equiv g (list_as_vprop l) (q * list_as_vprop l') =
match l with
| hd::tl ->
if eq_tm hd q then (| tl, RU.magic #(vprop_equiv _ _ _) () |)
else let (| tl', _ |) = get_q_at_hd g tl q in
(| hd::tl', RU.magic #(vprop_equiv _ _ _) () |)
#push-options "--z3rlimit_factor 4"
let prove
(#g:env) (#ctxt:vprop) (ctxt_typing:vprop_typing g ctxt)
(uvs:env { disjoint g uvs })
(#goals:vprop) (goals_typing:vprop_typing (push_env g uvs) goals)
: T.Tac (g1 : env { g1 `env_extends` g /\ disjoint g1 uvs } &
nts : PS.nt_substs &
effect_labels:list T.tot_or_ghost { PS.well_typed_nt_substs g1 uvs nts effect_labels } &
remaining_ctxt : vprop &
continuation_elaborator g ctxt g1 ((PS.nt_subst_term goals nts) * remaining_ctxt)) =
debug_prover g (fun _ ->
Printf.sprintf "\nEnter top-level prove with ctxt: %s\ngoals: %s\n"
(P.term_to_string ctxt) (P.term_to_string goals));
let ctxt_l = vprop_as_list ctxt in
if false && Nil? (bindings uvs) && L.existsb (fun v -> eq_tm v goals) ctxt_l
then begin
let (| l', d_eq |) = get_q_at_hd g ctxt_l goals in
let g1 = g in
let nts : PS.nt_substs = [] in
let remaining_ctxt = list_as_vprop l' in
let k : continuation_elaborator g ctxt g1 ctxt = k_elab_unit g ctxt in
assume (list_as_vprop (vprop_as_list ctxt) == ctxt);
let d_eq
: vprop_equiv g ctxt ((PS.nt_subst_term goals nts) * remaining_ctxt) = coerce_eq d_eq () in
(| g1, nts, [], remaining_ctxt, k_elab_equiv k (VE_Refl _ _) d_eq |)
end
else
let ctxt_frame_typing : vprop_typing g (ctxt * tm_emp) = RU.magic () in
let preamble = {
g0 = g;
ctxt;
frame = tm_emp;
ctxt_frame_typing;
goals;
} in
assume (list_as_vprop (vprop_as_list ctxt) == ctxt);
assume ((PS.empty).(tm_emp) == tm_emp);
let pst0 : prover_state preamble = {
pg = g;
remaining_ctxt = vprop_as_list ctxt;
remaining_ctxt_frame_typing = ctxt_frame_typing;
uvs = uvs;
ss = PS.empty;
nts = None;
solved = tm_emp;
unsolved = vprop_as_list goals;
k = k_elab_equiv (k_elab_unit g ctxt) (RU.magic ()) (RU.magic ());
goals_inv = RU.magic ();
solved_inv = ()
} in
let pst = prover pst0 in
let (| nts, effect_labels |)
: nts:PS.nt_substs &
effect_labels:list T.tot_or_ghost {
PS.well_typed_nt_substs pst.pg pst.uvs nts effect_labels /\
PS.is_permutation nts pst.ss
} =
match pst.nts with
| Some nts -> nts
| None ->
let r = PS.ss_to_nt_substs pst.pg pst.uvs pst.ss in
match r with
| Inr msg ->
fail pst.pg None
(Printf.sprintf "prover error: ill-typed substitutions (%s)" msg)
| Inl nts -> nts in
let nts_uvs, nts_uvs_effect_labels =
PS.well_typed_nt_substs_prefix pst.pg pst.uvs nts effect_labels uvs in
let k
: continuation_elaborator
g (ctxt * tm_emp)
pst.pg ((list_as_vprop pst.remaining_ctxt * tm_emp) * (PS.nt_subst_term pst.solved nts)) = pst.k in
// admit ()
let goals_inv
: vprop_equiv (push_env pst.pg pst.uvs) goals (list_as_vprop [] * pst.solved) = pst.goals_inv in
let goals_inv
: vprop_equiv pst.pg (PS.nt_subst_term goals nts) (PS.nt_subst_term (list_as_vprop [] * pst.solved) nts) =
PS.vprop_equiv_nt_substs_derived pst.pg pst.uvs goals_inv nts effect_labels in
// goals is well-typed in initial g + uvs
// so any of the remaining uvs in pst.uvs should not be in goals
// so we can drop their substitutions from the tail of nts
assume (PS.nt_subst_term goals nts == PS.nt_subst_term goals nts_uvs);
(| pst.pg, nts_uvs, nts_uvs_effect_labels, list_as_vprop pst.remaining_ctxt, k_elab_equiv k (RU.magic ()) (RU.magic ()) |)
#pop-options | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Readback.fsti.checked",
"Pulse.PP.fst.checked",
"Pulse.Config.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.Match.fsti.checked",
"Pulse.Checker.Prover.IntroPure.fsti.checked",
"Pulse.Checker.Prover.IntroExists.fsti.checked",
"Pulse.Checker.Prover.ElimPure.fsti.checked",
"Pulse.Checker.Prover.ElimExists.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Pprint.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.IntroPure",
"short_module": "IntroPure"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.IntroExists",
"short_module": "IntroExists"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Match",
"short_module": "Match"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.ElimPure",
"short_module": "ElimPure"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.ElimExists",
"short_module": "ElimExists"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "FStar.Stubs.Pprint",
"short_module": "Pprint"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | c: Pulse.Syntax.Base.comp_st -> Pulse.Syntax.Base.comp_st | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.comp_st",
"Pulse.Syntax.Base.st_comp",
"Pulse.Syntax.Base.C_ST",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.observability",
"Pulse.Syntax.Base.C_STAtomic",
"Pulse.Syntax.Base.C_STGhost",
"Pulse.Readback.readback_ty",
"Pulse.Elaborate.Pure.elab_term",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__post",
"Prims.eq2",
"FStar.Stubs.Reflection.Types.term",
"Pulse.Syntax.Base.Mkst_comp",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__u",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__res",
"Pulse.Syntax.Base.__proj__Mkst_comp__item__pre"
] | [] | false | false | false | true | false | let canon_post (c: comp_st) : comp_st =
| let canon_st_comp_post (c: st_comp) : st_comp =
match Pulse.Readback.readback_ty (elab_term c.post) with
| None -> c
| Some post -> { c with post = post }
in
match c with
| C_ST s -> C_ST (canon_st_comp_post s)
| C_STAtomic i obs s -> C_STAtomic i obs (canon_st_comp_post s)
| C_STGhost s -> C_STGhost (canon_st_comp_post s) | false |
Hacl.Impl.Frodo.Params.fst | Hacl.Impl.Frodo.Params.cdf_table976 | val cdf_table976:x: glbuffer uint16 11ul {witnessed x (S.cdf_table S.Frodo976) /\ recallable x} | val cdf_table976:x: glbuffer uint16 11ul {witnessed x (S.cdf_table S.Frodo976) /\ recallable x} | let cdf_table976 :x:glbuffer uint16 11ul{witnessed x (S.cdf_table S.Frodo976) /\ recallable x} =
createL_global S.cdf_list_976 | {
"file_name": "code/frodo/Hacl.Impl.Frodo.Params.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 31,
"end_line": 141,
"start_col": 0,
"start_line": 140
} | module Hacl.Impl.Frodo.Params
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.Matrix
module S = Spec.Frodo.Params
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let params_n (a:S.frodo_alg) : x:size_t{v x == S.params_n a} =
match a with
| S.Frodo64 -> 64ul
| S.Frodo640 -> 640ul
| S.Frodo976 -> 976ul
| S.Frodo1344 -> 1344ul
inline_for_extraction noextract
let params_logq (a:S.frodo_alg) : x:size_t{v x == S.params_logq a} =
match a with
| S.Frodo64 | S.Frodo640 -> 15ul
| S.Frodo976 | S.Frodo1344 -> 16ul
inline_for_extraction noextract
let params_extracted_bits (a:S.frodo_alg) : x:size_t{v x == S.params_extracted_bits a} =
match a with
| S.Frodo64 | S.Frodo640 -> 2ul
| S.Frodo976 -> 3ul
| S.Frodo1344 -> 4ul
inline_for_extraction noextract
let crypto_bytes (a:S.frodo_alg) : x:size_t{v x == S.crypto_bytes a} =
match a with
| S.Frodo64 | S.Frodo640 -> 16ul
| S.Frodo976 -> 24ul
| S.Frodo1344 -> 32ul
inline_for_extraction noextract
let params_nbar = 8ul
inline_for_extraction noextract
let bytes_seed_a = 16ul
inline_for_extraction noextract
let bytes_pkhash (a:S.frodo_alg) =
crypto_bytes a
inline_for_extraction noextract
let bytes_mu (a:S.frodo_alg) : x:size_t{v x == S.bytes_mu a} =
params_extracted_bits a *! params_nbar *! params_nbar /. 8ul
inline_for_extraction noextract
let publicmatrixbytes_len (a:S.frodo_alg) =
params_logq a *! (params_n a *! params_nbar /. 8ul)
inline_for_extraction noextract
let secretmatrixbytes_len (a:S.frodo_alg) =
2ul *! params_n a *! params_nbar
inline_for_extraction noextract
let ct1bytes_len (a:S.frodo_alg) =
params_logq a *! (params_nbar *! params_n a /. 8ul)
inline_for_extraction noextract
let ct2bytes_len (a:S.frodo_alg) =
params_logq a *! (params_nbar *! params_nbar /. 8ul)
inline_for_extraction noextract
let crypto_publickeybytes (a:S.frodo_alg) =
bytes_seed_a +! publicmatrixbytes_len a
inline_for_extraction noextract
let crypto_secretkeybytes (a:S.frodo_alg) =
crypto_bytes a +! crypto_publickeybytes a +! secretmatrixbytes_len a +! bytes_pkhash a
inline_for_extraction noextract
let crypto_ciphertextbytes (a:S.frodo_alg) =
ct1bytes_len a +! ct2bytes_len a
inline_for_extraction noextract
let frodo_shake_st (a:S.frodo_alg) =
inputByteLen:size_t
-> input:lbuffer uint8 inputByteLen
-> outputByteLen:size_t
-> output:lbuffer uint8 outputByteLen
-> Stack unit
(requires fun h ->
live h input /\ live h output /\ disjoint input output)
(ensures fun h0 _ h1 -> modifies (loc output) h0 h1 /\
as_seq h1 output == S.frodo_shake a (v inputByteLen) (as_seq h0 input) (v outputByteLen))
inline_for_extraction noextract
let frodo_shake (a:S.frodo_alg) : frodo_shake_st a =
match a with
| S.Frodo64 | S.Frodo640 -> Hacl.SHA3.shake128_hacl
| S.Frodo976 | S.Frodo1344 -> Hacl.SHA3.shake256_hacl
inline_for_extraction noextract
let is_supported (a:S.frodo_gen_a) =
match a with
| S.SHAKE128 -> true
| S.AES128 -> false (* unfortunately, we don't have a verified impl of aes128 in Low* *)
val frodo_gen_matrix:
a:S.frodo_gen_a{is_supported a}
-> n:size_t{0 < v n /\ v n * v n <= max_size_t /\ v n <= maxint U16 /\ v n % 4 = 0}
-> seed:lbuffer uint8 16ul
-> a_matrix:matrix_t n n
-> Stack unit
(requires fun h ->
live h seed /\ live h a_matrix /\ disjoint seed a_matrix)
(ensures fun h0 _ h1 -> modifies1 a_matrix h0 h1 /\
as_matrix h1 a_matrix == S.frodo_gen_matrix a (v n) (as_seq h0 seed))
[@CInline]
let frodo_gen_matrix a n seed a_matrix =
match a with
| S.SHAKE128 -> Hacl.Impl.Frodo.Gen.frodo_gen_matrix_shake_4x n seed a_matrix
(* | S.AES128 -> Hacl.Impl.Frodo.Gen.frodo_gen_matrix_aes n seed a_matrix *)
(** CDF tables *)
let cdf_table640 :x:glbuffer uint16 13ul{witnessed x (S.cdf_table S.Frodo640) /\ recallable x} =
createL_global S.cdf_list_640 | {
"checked_file": "/",
"dependencies": [
"Spec.Frodo.Params.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.SHA3.fst.checked",
"Hacl.Impl.Matrix.fst.checked",
"Hacl.Impl.Frodo.Gen.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Frodo.Params.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Frodo.Params",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x:
(c:
Lib.Buffer.lbuffer_t Lib.Buffer.CONST
(Lib.IntTypes.int_t Lib.IntTypes.U16 Lib.IntTypes.SEC)
(11ul <: FStar.UInt32.t) {LowStar.ConstBuffer.qual_of c == LowStar.ConstBuffer.IMMUTABLE})
{ Lib.Buffer.witnessed x (Spec.Frodo.Params.cdf_table Spec.Frodo.Params.Frodo976) /\
Lib.Buffer.recallable x } | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.createL_global",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U16",
"Lib.IntTypes.SEC",
"Spec.Frodo.Params.cdf_list_976",
"Lib.Buffer.glbuffer",
"Lib.IntTypes.size",
"FStar.Pervasives.normalize_term",
"Lib.IntTypes.size_nat",
"FStar.List.Tot.Base.length"
] | [] | false | false | false | false | false | let cdf_table976:x: glbuffer uint16 11ul {witnessed x (S.cdf_table S.Frodo976) /\ recallable x} =
| createL_global S.cdf_list_976 | false |
Hacl.Spec.K256.Finv.fst | Hacl.Spec.K256.Finv.nat_mod_comm_monoid | val nat_mod_comm_monoid : Lib.Exponentiation.Definition.comm_monoid (Lib.NatMod.nat_mod Spec.K256.PointOps.prime) | let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.prime | {
"file_name": "code/k256/Hacl.Spec.K256.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 58,
"end_line": 12,
"start_col": 0,
"start_line": 12
} | module Hacl.Spec.K256.Finv
open FStar.Mul
module SE = Spec.Exponentiation
module LE = Lib.Exponentiation
module M = Lib.NatMod
module S = Spec.K256
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0" | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Lib.Exponentiation.Definition.comm_monoid (Lib.NatMod.nat_mod Spec.K256.PointOps.prime) | Prims.Tot | [
"total"
] | [] | [
"Lib.NatMod.mk_nat_mod_comm_monoid",
"Spec.K256.PointOps.prime"
] | [] | false | false | false | true | false | let nat_mod_comm_monoid =
| M.mk_nat_mod_comm_monoid S.prime | false |
|
Hacl.Spec.K256.Finv.fst | Hacl.Spec.K256.Finv.fsquare_times | val fsquare_times (a: S.felem) (b: nat) : S.felem | val fsquare_times (a: S.felem) (b: nat) : S.felem | let fsquare_times (a:S.felem) (b:nat) : S.felem =
SE.exp_pow2 mk_nat_mod_concrete_ops a b | {
"file_name": "code/k256/Hacl.Spec.K256.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 41,
"end_line": 37,
"start_col": 0,
"start_line": 36
} | module Hacl.Spec.K256.Finv
open FStar.Mul
module SE = Spec.Exponentiation
module LE = Lib.Exponentiation
module M = Lib.NatMod
module S = Spec.K256
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.prime
let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.felem = {
SE.a_spec = S.felem;
SE.comm_monoid = nat_mod_comm_monoid;
SE.refl = (fun (x:S.felem) -> x);
}
val one_mod : SE.one_st S.felem mk_to_nat_mod_comm_monoid
let one_mod _ = S.one
val mul_mod : SE.mul_st S.felem mk_to_nat_mod_comm_monoid
let mul_mod x y = S.fmul x y
val sqr_mod : SE.sqr_st S.felem mk_to_nat_mod_comm_monoid
let sqr_mod x = S.fmul x x
let mk_nat_mod_concrete_ops : SE.concrete_ops S.felem = {
SE.to = mk_to_nat_mod_comm_monoid;
SE.one = one_mod;
SE.mul = mul_mod;
SE.sqr = sqr_mod;
} | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.K256.PointOps.felem -> b: Prims.nat -> Spec.K256.PointOps.felem | Prims.Tot | [
"total"
] | [] | [
"Spec.K256.PointOps.felem",
"Prims.nat",
"Spec.Exponentiation.exp_pow2",
"Hacl.Spec.K256.Finv.mk_nat_mod_concrete_ops"
] | [] | false | false | false | true | false | let fsquare_times (a: S.felem) (b: nat) : S.felem =
| SE.exp_pow2 mk_nat_mod_concrete_ops a b | false |
Pulse.Checker.Prover.fst | Pulse.Checker.Prover.try_frame_pre | val try_frame_pre (#g:env) (#ctxt:vprop) (ctxt_typing:tot_typing g ctxt tm_vprop)
(d:(t:st_term & c:comp_st & st_typing g t c))
(res_ppname:ppname)
: T.Tac (checker_result_t g ctxt None) | val try_frame_pre (#g:env) (#ctxt:vprop) (ctxt_typing:tot_typing g ctxt tm_vprop)
(d:(t:st_term & c:comp_st & st_typing g t c))
(res_ppname:ppname)
: T.Tac (checker_result_t g ctxt None) | let try_frame_pre (#g:env) (#ctxt:vprop) (ctxt_typing:tot_typing g ctxt tm_vprop)
(d:(t:st_term & c:comp_st & st_typing g t c))
(res_ppname:ppname)
: T.Tac (checker_result_t g ctxt None) =
let uvs = mk_env (fstar_env g) in
assert (equal g (push_env g uvs));
try_frame_pre_uvs ctxt_typing uvs d res_ppname | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 48,
"end_line": 391,
"start_col": 0,
"start_line": 383
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Prover
open FStar.List.Tot
open Pulse.Syntax
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Checker.Base
module RU = Pulse.RuntimeUtils
module L = FStar.List.Tot
module T = FStar.Tactics.V2
module P = Pulse.Syntax.Printer
module Pprint = FStar.Stubs.Pprint
module Metatheory = Pulse.Typing.Metatheory
module PS = Pulse.Checker.Prover.Substs
module ElimExists = Pulse.Checker.Prover.ElimExists
module ElimPure = Pulse.Checker.Prover.ElimPure
module Match = Pulse.Checker.Prover.Match
module IntroExists = Pulse.Checker.Prover.IntroExists
module IntroPure = Pulse.Checker.Prover.IntroPure
let coerce_eq (#a #b:Type) (x:a) (_:squash (a == b)) : y:b{y == x} = x
let elim_exists_and_pure (#g:env) (#ctxt:vprop)
(ctxt_typing:tot_typing g ctxt tm_vprop)
: T.Tac (g':env { env_extends g' g } &
ctxt':term &
tot_typing g' ctxt' tm_vprop &
continuation_elaborator g ctxt g' ctxt') =
let (| g1, ctxt1, d1, k1 |) = ElimExists.elim_exists ctxt_typing in
let (| g2, ctxt2, d2, k2 |) = ElimPure.elim_pure d1 in
(| g2, ctxt2, d2, k_elab_trans k1 k2 |)
let unsolved_equiv_pst (#preamble:_) (pst:prover_state preamble) (unsolved':list vprop)
(d:vprop_equiv (push_env pst.pg pst.uvs) (list_as_vprop pst.unsolved) (list_as_vprop unsolved'))
: prover_state preamble =
{ pst with unsolved = unsolved'; goals_inv = RU.magic () }
let rec collect_exists (g:env) (l:list vprop)
: exs:list vprop &
rest:list vprop &
vprop_equiv g (list_as_vprop l) (list_as_vprop (exs @ rest)) =
match l with
| [] -> (| [], [], VE_Refl _ _ |)
| hd::tl ->
let (| exs, rest, _ |) = collect_exists g tl in
match hd.t with
| Tm_ExistsSL _ _ _ ->
(| hd::exs, rest, RU.magic #(vprop_equiv _ _ _) () |)
| _ -> (| exs, hd::rest, RU.magic #(vprop_equiv _ _ _) () |)
let rec collect_pures (g:env) (l:list vprop)
: pures:list vprop &
rest:list vprop &
vprop_equiv g (list_as_vprop l) (list_as_vprop (rest @ pures)) =
match l with
| [] -> (| [], [], VE_Refl _ _ |)
| hd::tl ->
let (| pures, rest, _ |) = collect_pures g tl in
match hd.t with
| Tm_Pure _ -> (| hd::pures, rest, RU.magic #(vprop_equiv _ _ _) () |)
| _ -> (| pures, hd::rest, RU.magic #(vprop_equiv _ _ _) () |)
let rec prove_pures #preamble (pst:prover_state preamble)
: T.Tac (pst':prover_state preamble { pst' `pst_extends` pst /\
is_terminal pst' }) =
match pst.unsolved with
| [] -> pst
| {t=Tm_Pure p}::unsolved' ->
let pst_opt = IntroPure.intro_pure pst p unsolved' () in
(match pst_opt with
| None ->
let open Pulse.PP in
fail_doc pst.pg None [
text "Cannot prove pure proposition" ^/^
pp p
]
| Some pst1 ->
let pst2 = prove_pures pst1 in
assert (pst1 `pst_extends` pst);
assert (pst2 `pst_extends` pst1);
assert (pst2 `pst_extends` pst);
pst2)
| _ ->
fail pst.pg None
(Printf.sprintf "Impossible! prover.prove_pures: %s is not a pure, please file a bug-report"
(P.term_to_string (L.hd pst.unsolved)))
#push-options "--z3rlimit_factor 4"
let rec prover
(#preamble:_)
(pst0:prover_state preamble)
: T.Tac (pst':prover_state preamble { pst' `pst_extends` pst0 /\
is_terminal pst' }) =
debug_prover pst0.pg (fun _ ->
Printf.sprintf "At the prover top-level with remaining_ctxt: %s\nunsolved: %s"
(P.term_to_string (list_as_vprop pst0.remaining_ctxt))
(P.term_to_string (list_as_vprop pst0.unsolved)));
match pst0.unsolved with
| [] -> pst0
| _ ->
let pst = ElimExists.elim_exists_pst pst0 in
debug_prover pst.pg (fun _ ->
Printf.sprintf "prover: remaining_ctxt after elim exists: %s\n"
(P.term_to_string (list_as_vprop pst.remaining_ctxt)));
let pst = ElimPure.elim_pure_pst pst in
debug_prover pst.pg (fun _ ->
Printf.sprintf "prover: remaining_ctxt after elim pure: %s\n"
(P.term_to_string (list_as_vprop pst.remaining_ctxt)));
let (| exs, rest, d |) = collect_exists (push_env pst.pg pst.uvs) pst.unsolved in
debug_prover pst.pg (fun _ ->
Printf.sprintf "prover: tried to pull exists: exs: %s and rest: %s\n"
(P.term_to_string (list_as_vprop exs)) (P.term_to_string (list_as_vprop rest)));
let pst = unsolved_equiv_pst pst (exs@rest) d in
debug_prover pst.pg (fun _ ->
Printf.sprintf "prover: unsolved after pulling exists at the top: %s\n"
(P.term_to_string (list_as_vprop pst.unsolved)));
match pst.unsolved with
| {t=Tm_ExistsSL u b body}::unsolved' ->
IntroExists.intro_exists pst u b body unsolved' () prover
| _ ->
let (| pures, rest, d |) = collect_pures (push_env pst.pg pst.uvs) pst.unsolved in
let pst = unsolved_equiv_pst pst (rest@pures) d in
match pst.unsolved with
| {t=Tm_Pure _}::tl -> prove_pures pst
| q::tl ->
let pst_opt = Match.match_q pst q tl () prover in
match pst_opt with
| None ->
let open Pprint in
let open Pulse.PP in
let msg = [
text "Cannot prove:" ^^
indent (pp q);
text "In the context:" ^^
indent (pp (list_as_vprop pst.remaining_ctxt))
] @ (if Pulse.Config.debug_flag "initial_solver_state" then [
text "The prover was started with goal:" ^^
indent (pp preamble.goals);
text "and initial context:" ^^
indent (pp preamble.ctxt);
] else [])
in
// GM: I feel I should use (Some q.range) instead of None, but that makes
// several error locations worse.
fail_doc pst.pg None msg
| Some pst -> prover pst // a little wasteful?
#pop-options
let rec get_q_at_hd (g:env) (l:list vprop) (q:vprop { L.existsb (fun v -> eq_tm v q) l })
: l':list vprop &
vprop_equiv g (list_as_vprop l) (q * list_as_vprop l') =
match l with
| hd::tl ->
if eq_tm hd q then (| tl, RU.magic #(vprop_equiv _ _ _) () |)
else let (| tl', _ |) = get_q_at_hd g tl q in
(| hd::tl', RU.magic #(vprop_equiv _ _ _) () |)
#push-options "--z3rlimit_factor 4"
let prove
(#g:env) (#ctxt:vprop) (ctxt_typing:vprop_typing g ctxt)
(uvs:env { disjoint g uvs })
(#goals:vprop) (goals_typing:vprop_typing (push_env g uvs) goals)
: T.Tac (g1 : env { g1 `env_extends` g /\ disjoint g1 uvs } &
nts : PS.nt_substs &
effect_labels:list T.tot_or_ghost { PS.well_typed_nt_substs g1 uvs nts effect_labels } &
remaining_ctxt : vprop &
continuation_elaborator g ctxt g1 ((PS.nt_subst_term goals nts) * remaining_ctxt)) =
debug_prover g (fun _ ->
Printf.sprintf "\nEnter top-level prove with ctxt: %s\ngoals: %s\n"
(P.term_to_string ctxt) (P.term_to_string goals));
let ctxt_l = vprop_as_list ctxt in
if false && Nil? (bindings uvs) && L.existsb (fun v -> eq_tm v goals) ctxt_l
then begin
let (| l', d_eq |) = get_q_at_hd g ctxt_l goals in
let g1 = g in
let nts : PS.nt_substs = [] in
let remaining_ctxt = list_as_vprop l' in
let k : continuation_elaborator g ctxt g1 ctxt = k_elab_unit g ctxt in
assume (list_as_vprop (vprop_as_list ctxt) == ctxt);
let d_eq
: vprop_equiv g ctxt ((PS.nt_subst_term goals nts) * remaining_ctxt) = coerce_eq d_eq () in
(| g1, nts, [], remaining_ctxt, k_elab_equiv k (VE_Refl _ _) d_eq |)
end
else
let ctxt_frame_typing : vprop_typing g (ctxt * tm_emp) = RU.magic () in
let preamble = {
g0 = g;
ctxt;
frame = tm_emp;
ctxt_frame_typing;
goals;
} in
assume (list_as_vprop (vprop_as_list ctxt) == ctxt);
assume ((PS.empty).(tm_emp) == tm_emp);
let pst0 : prover_state preamble = {
pg = g;
remaining_ctxt = vprop_as_list ctxt;
remaining_ctxt_frame_typing = ctxt_frame_typing;
uvs = uvs;
ss = PS.empty;
nts = None;
solved = tm_emp;
unsolved = vprop_as_list goals;
k = k_elab_equiv (k_elab_unit g ctxt) (RU.magic ()) (RU.magic ());
goals_inv = RU.magic ();
solved_inv = ()
} in
let pst = prover pst0 in
let (| nts, effect_labels |)
: nts:PS.nt_substs &
effect_labels:list T.tot_or_ghost {
PS.well_typed_nt_substs pst.pg pst.uvs nts effect_labels /\
PS.is_permutation nts pst.ss
} =
match pst.nts with
| Some nts -> nts
| None ->
let r = PS.ss_to_nt_substs pst.pg pst.uvs pst.ss in
match r with
| Inr msg ->
fail pst.pg None
(Printf.sprintf "prover error: ill-typed substitutions (%s)" msg)
| Inl nts -> nts in
let nts_uvs, nts_uvs_effect_labels =
PS.well_typed_nt_substs_prefix pst.pg pst.uvs nts effect_labels uvs in
let k
: continuation_elaborator
g (ctxt * tm_emp)
pst.pg ((list_as_vprop pst.remaining_ctxt * tm_emp) * (PS.nt_subst_term pst.solved nts)) = pst.k in
// admit ()
let goals_inv
: vprop_equiv (push_env pst.pg pst.uvs) goals (list_as_vprop [] * pst.solved) = pst.goals_inv in
let goals_inv
: vprop_equiv pst.pg (PS.nt_subst_term goals nts) (PS.nt_subst_term (list_as_vprop [] * pst.solved) nts) =
PS.vprop_equiv_nt_substs_derived pst.pg pst.uvs goals_inv nts effect_labels in
// goals is well-typed in initial g + uvs
// so any of the remaining uvs in pst.uvs should not be in goals
// so we can drop their substitutions from the tail of nts
assume (PS.nt_subst_term goals nts == PS.nt_subst_term goals nts_uvs);
(| pst.pg, nts_uvs, nts_uvs_effect_labels, list_as_vprop pst.remaining_ctxt, k_elab_equiv k (RU.magic ()) (RU.magic ()) |)
#pop-options
let canon_post (c:comp_st) : comp_st =
let canon_st_comp_post (c:st_comp) : st_comp =
match Pulse.Readback.readback_ty (elab_term c.post) with
| None -> c
| Some post -> { c with post }
in
match c with
| C_ST s -> C_ST (canon_st_comp_post s)
| C_STAtomic i obs s -> C_STAtomic i obs (canon_st_comp_post s)
| C_STGhost s -> C_STGhost (canon_st_comp_post s)
irreducible
let typing_canon #g #t (#c:comp_st) (d:st_typing g t c) : st_typing g t (canon_post c) =
assume false;
d
#push-options "--z3rlimit_factor 8 --fuel 0 --ifuel 1 --retry 5"
let try_frame_pre_uvs (#g:env) (#ctxt:vprop) (ctxt_typing:tot_typing g ctxt tm_vprop)
(uvs:env { disjoint g uvs })
(d:(t:st_term & c:comp_st & st_typing (push_env g uvs) t c))
(res_ppname:ppname)
: T.Tac (checker_result_t g ctxt None) =
let (| t, c, d |) = d in
let g = push_context g "try_frame_pre" t.range in
let (| g1, nts, effect_labels, remaining_ctxt, k_frame |) =
prove #g #_ ctxt_typing uvs #(comp_pre c) (RU.magic ()) in
// assert (nts == []);
let d : st_typing (push_env g1 uvs) t c =
Metatheory.st_typing_weakening g uvs t c d g1 in
assert (comp_pre (PS.nt_subst_comp c nts) == PS.nt_subst_term (comp_pre c) nts);
let t = PS.nt_subst_st_term t nts in
let c = PS.nt_subst_comp c nts in
let d : st_typing g1 t c =
let r = PS.st_typing_nt_substs_derived g1 uvs d nts effect_labels in
match r with
| Inr (x, x_t) ->
fail g1 (Some t.range)
(Printf.sprintf "prover error: for term %s, implicit solution %s has ghost effect"
(P.st_term_to_string t)
(P.term_to_string x_t))
| Inl d -> d in
(* shouldn't need this once term becomes a view; currently we sometimes end up with a computation
type whose postcondition is Tm_FStar (`(p1 ** p2))) rather than a Tm_Star p1 p2;
canon_post normalizes that *)
let c = canon_post c in
let d = typing_canon d in
let k_frame : continuation_elaborator g ctxt g1 (comp_pre c * remaining_ctxt) = coerce_eq k_frame () in
let x = fresh g1 in
let ty = comp_res c in
let g2 = push_binding g1 x res_ppname ty in
assert (g2 `env_extends` g1);
let ctxt' = (open_term_nv (comp_post c) (res_ppname, x) * remaining_ctxt) in
let d : st_typing g1 t c = Metatheory.st_typing_weakening_standard d g1 in
let k
: continuation_elaborator g1 (remaining_ctxt * comp_pre c)
g2 ctxt' =
continuation_elaborator_with_bind remaining_ctxt d (RU.magic #(tot_typing _ _ _) ()) (res_ppname, x) in
let k
: continuation_elaborator g1 (comp_pre c * remaining_ctxt)
g2 ctxt' =
k_elab_equiv k (VE_Comm _ _ _) (VE_Refl _ _) in
let k = k_elab_trans k_frame k in
let comp_res_typing_in_g1, _, f =
Metatheory.st_comp_typing_inversion_cofinite
(fst <| Metatheory.comp_typing_inversion (Metatheory.st_typing_correctness d)) in
let d_ty
: universe_of g2 ty (comp_u c) =
Metatheory.tot_typing_weakening_single comp_res_typing_in_g1 x (comp_res c) in
assume (~ (x `Set.mem` freevars (comp_post c)));
let d_post
: vprop_typing g2 (open_term_nv (comp_post c) (res_ppname, x)) =
f x in
// the RU.magic is for the ctxt' typing
// see d_post for post typing
// then the remaining_ctxt typing should come from the prover state
// TODO: add it there
// and then ctxt' is just their `*`
(| x, g2, (| comp_u c, ty, d_ty |), (| ctxt', RU.magic #(tot_typing _ _ _) () |), k |)
#pop-options | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Readback.fsti.checked",
"Pulse.PP.fst.checked",
"Pulse.Config.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.Match.fsti.checked",
"Pulse.Checker.Prover.IntroPure.fsti.checked",
"Pulse.Checker.Prover.IntroExists.fsti.checked",
"Pulse.Checker.Prover.ElimPure.fsti.checked",
"Pulse.Checker.Prover.ElimExists.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Pprint.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.IntroPure",
"short_module": "IntroPure"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.IntroExists",
"short_module": "IntroExists"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Match",
"short_module": "Match"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.ElimPure",
"short_module": "ElimPure"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.ElimExists",
"short_module": "ElimExists"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "FStar.Stubs.Pprint",
"short_module": "Pprint"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ctxt_typing: Pulse.Typing.tot_typing g ctxt Pulse.Syntax.Base.tm_vprop ->
d:
FStar.Pervasives.dtuple3 Pulse.Syntax.Base.st_term
(fun _ -> Pulse.Syntax.Base.comp_st)
(fun t c -> Pulse.Typing.st_typing g t c) ->
res_ppname: Pulse.Syntax.Base.ppname
-> FStar.Tactics.Effect.Tac
(Pulse.Checker.Base.checker_result_t g ctxt FStar.Pervasives.Native.None) | FStar.Tactics.Effect.Tac | [] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.vprop",
"Pulse.Typing.tot_typing",
"Pulse.Syntax.Base.tm_vprop",
"FStar.Pervasives.dtuple3",
"Pulse.Syntax.Base.st_term",
"Pulse.Syntax.Base.comp_st",
"Pulse.Typing.st_typing",
"Pulse.Syntax.Base.ppname",
"Pulse.Checker.Prover.try_frame_pre_uvs",
"Pulse.Checker.Base.checker_result_t",
"FStar.Pervasives.Native.None",
"Pulse.Typing.post_hint_t",
"Prims.unit",
"Prims._assert",
"Pulse.Typing.Env.equal",
"Pulse.Typing.Env.push_env",
"Prims.eq2",
"FStar.Reflection.Typing.fstar_top_env",
"Pulse.Typing.Env.fstar_env",
"Pulse.Typing.Env.mk_env"
] | [] | false | true | false | false | false | let try_frame_pre
(#g: env)
(#ctxt: vprop)
(ctxt_typing: tot_typing g ctxt tm_vprop)
(d: (t: st_term & c: comp_st & st_typing g t c))
(res_ppname: ppname)
: T.Tac (checker_result_t g ctxt None) =
| let uvs = mk_env (fstar_env g) in
assert (equal g (push_env g uvs));
try_frame_pre_uvs ctxt_typing uvs d res_ppname | false |
Hacl.Spec.K256.Finv.fst | Hacl.Spec.K256.Finv.fsqrt | val fsqrt: f:S.felem -> S.felem | val fsqrt: f:S.felem -> S.felem | let fsqrt f =
let r, x2 = fexp_223_23 f in
let r = S.fmul (fsquare_times r 6) x2 in
let r = fsquare_times r 2 in
r | {
"file_name": "code/k256/Hacl.Spec.K256.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 84,
"start_col": 0,
"start_line": 80
} | module Hacl.Spec.K256.Finv
open FStar.Mul
module SE = Spec.Exponentiation
module LE = Lib.Exponentiation
module M = Lib.NatMod
module S = Spec.K256
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.prime
let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.felem = {
SE.a_spec = S.felem;
SE.comm_monoid = nat_mod_comm_monoid;
SE.refl = (fun (x:S.felem) -> x);
}
val one_mod : SE.one_st S.felem mk_to_nat_mod_comm_monoid
let one_mod _ = S.one
val mul_mod : SE.mul_st S.felem mk_to_nat_mod_comm_monoid
let mul_mod x y = S.fmul x y
val sqr_mod : SE.sqr_st S.felem mk_to_nat_mod_comm_monoid
let sqr_mod x = S.fmul x x
let mk_nat_mod_concrete_ops : SE.concrete_ops S.felem = {
SE.to = mk_to_nat_mod_comm_monoid;
SE.one = one_mod;
SE.mul = mul_mod;
SE.sqr = sqr_mod;
}
let fsquare_times (a:S.felem) (b:nat) : S.felem =
SE.exp_pow2 mk_nat_mod_concrete_ops a b
val fsquare_times_lemma: a:S.felem -> b:nat ->
Lemma (fsquare_times a b == M.pow a (pow2 b) % S.prime)
let fsquare_times_lemma a b =
SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b;
LE.exp_pow2_lemma nat_mod_comm_monoid a b;
assert (fsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b));
M.lemma_pow_nat_mod_is_pow #S.prime a (pow2 b)
val fexp_223_23: f:S.felem -> tuple2 S.felem S.felem
let fexp_223_23 f =
let x2 = S.fmul (fsquare_times f 1) f in
let x3 = S.fmul (fsquare_times x2 1) f in
let x6 = S.fmul (fsquare_times x3 3) x3 in
let x9 = S.fmul (fsquare_times x6 3) x3 in
let x11 = S.fmul (fsquare_times x9 2) x2 in
let x22 = S.fmul (fsquare_times x11 11) x11 in
let x44 = S.fmul (fsquare_times x22 22) x22 in
let x88 = S.fmul (fsquare_times x44 44) x44 in
let x176 = S.fmul (fsquare_times x88 88) x88 in
let x220 = S.fmul (fsquare_times x176 44) x44 in
let x223 = S.fmul (fsquare_times x220 3) x3 in
let r = S.fmul (fsquare_times x223 23) x22 in
r, x2
(**
The algorithm is taken from
https://briansmith.org/ecc-inversion-addition-chains-01
*)
val finv: f:S.felem -> S.felem
let finv f =
let r, x2 = fexp_223_23 f in
let r = S.fmul (fsquare_times r 5) f in
let r = S.fmul (fsquare_times r 3) x2 in
let r = S.fmul (fsquare_times r 2) f in
r | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Spec.K256.PointOps.felem -> Spec.K256.PointOps.felem | Prims.Tot | [
"total"
] | [] | [
"Spec.K256.PointOps.felem",
"Hacl.Spec.K256.Finv.fsquare_times",
"Spec.K256.PointOps.fmul",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.K256.Finv.fexp_223_23"
] | [] | false | false | false | true | false | let fsqrt f =
| let r, x2 = fexp_223_23 f in
let r = S.fmul (fsquare_times r 6) x2 in
let r = fsquare_times r 2 in
r | false |
Hacl.Spec.K256.Finv.fst | Hacl.Spec.K256.Finv.finv | val finv: f:S.felem -> S.felem | val finv: f:S.felem -> S.felem | let finv f =
let r, x2 = fexp_223_23 f in
let r = S.fmul (fsquare_times r 5) f in
let r = S.fmul (fsquare_times r 3) x2 in
let r = S.fmul (fsquare_times r 2) f in
r | {
"file_name": "code/k256/Hacl.Spec.K256.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 76,
"start_col": 0,
"start_line": 71
} | module Hacl.Spec.K256.Finv
open FStar.Mul
module SE = Spec.Exponentiation
module LE = Lib.Exponentiation
module M = Lib.NatMod
module S = Spec.K256
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.prime
let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.felem = {
SE.a_spec = S.felem;
SE.comm_monoid = nat_mod_comm_monoid;
SE.refl = (fun (x:S.felem) -> x);
}
val one_mod : SE.one_st S.felem mk_to_nat_mod_comm_monoid
let one_mod _ = S.one
val mul_mod : SE.mul_st S.felem mk_to_nat_mod_comm_monoid
let mul_mod x y = S.fmul x y
val sqr_mod : SE.sqr_st S.felem mk_to_nat_mod_comm_monoid
let sqr_mod x = S.fmul x x
let mk_nat_mod_concrete_ops : SE.concrete_ops S.felem = {
SE.to = mk_to_nat_mod_comm_monoid;
SE.one = one_mod;
SE.mul = mul_mod;
SE.sqr = sqr_mod;
}
let fsquare_times (a:S.felem) (b:nat) : S.felem =
SE.exp_pow2 mk_nat_mod_concrete_ops a b
val fsquare_times_lemma: a:S.felem -> b:nat ->
Lemma (fsquare_times a b == M.pow a (pow2 b) % S.prime)
let fsquare_times_lemma a b =
SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b;
LE.exp_pow2_lemma nat_mod_comm_monoid a b;
assert (fsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b));
M.lemma_pow_nat_mod_is_pow #S.prime a (pow2 b)
val fexp_223_23: f:S.felem -> tuple2 S.felem S.felem
let fexp_223_23 f =
let x2 = S.fmul (fsquare_times f 1) f in
let x3 = S.fmul (fsquare_times x2 1) f in
let x6 = S.fmul (fsquare_times x3 3) x3 in
let x9 = S.fmul (fsquare_times x6 3) x3 in
let x11 = S.fmul (fsquare_times x9 2) x2 in
let x22 = S.fmul (fsquare_times x11 11) x11 in
let x44 = S.fmul (fsquare_times x22 22) x22 in
let x88 = S.fmul (fsquare_times x44 44) x44 in
let x176 = S.fmul (fsquare_times x88 88) x88 in
let x220 = S.fmul (fsquare_times x176 44) x44 in
let x223 = S.fmul (fsquare_times x220 3) x3 in
let r = S.fmul (fsquare_times x223 23) x22 in
r, x2
(**
The algorithm is taken from
https://briansmith.org/ecc-inversion-addition-chains-01
*) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Spec.K256.PointOps.felem -> Spec.K256.PointOps.felem | Prims.Tot | [
"total"
] | [] | [
"Spec.K256.PointOps.felem",
"Spec.K256.PointOps.fmul",
"Hacl.Spec.K256.Finv.fsquare_times",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.K256.Finv.fexp_223_23"
] | [] | false | false | false | true | false | let finv f =
| let r, x2 = fexp_223_23 f in
let r = S.fmul (fsquare_times r 5) f in
let r = S.fmul (fsquare_times r 3) x2 in
let r = S.fmul (fsquare_times r 2) f in
r | false |
Hacl.Spec.K256.Finv.fst | Hacl.Spec.K256.Finv.fexp_223_23 | val fexp_223_23: f:S.felem -> tuple2 S.felem S.felem | val fexp_223_23: f:S.felem -> tuple2 S.felem S.felem | let fexp_223_23 f =
let x2 = S.fmul (fsquare_times f 1) f in
let x3 = S.fmul (fsquare_times x2 1) f in
let x6 = S.fmul (fsquare_times x3 3) x3 in
let x9 = S.fmul (fsquare_times x6 3) x3 in
let x11 = S.fmul (fsquare_times x9 2) x2 in
let x22 = S.fmul (fsquare_times x11 11) x11 in
let x44 = S.fmul (fsquare_times x22 22) x22 in
let x88 = S.fmul (fsquare_times x44 44) x44 in
let x176 = S.fmul (fsquare_times x88 88) x88 in
let x220 = S.fmul (fsquare_times x176 44) x44 in
let x223 = S.fmul (fsquare_times x220 3) x3 in
let r = S.fmul (fsquare_times x223 23) x22 in
r, x2 | {
"file_name": "code/k256/Hacl.Spec.K256.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 7,
"end_line": 62,
"start_col": 0,
"start_line": 49
} | module Hacl.Spec.K256.Finv
open FStar.Mul
module SE = Spec.Exponentiation
module LE = Lib.Exponentiation
module M = Lib.NatMod
module S = Spec.K256
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.prime
let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.felem = {
SE.a_spec = S.felem;
SE.comm_monoid = nat_mod_comm_monoid;
SE.refl = (fun (x:S.felem) -> x);
}
val one_mod : SE.one_st S.felem mk_to_nat_mod_comm_monoid
let one_mod _ = S.one
val mul_mod : SE.mul_st S.felem mk_to_nat_mod_comm_monoid
let mul_mod x y = S.fmul x y
val sqr_mod : SE.sqr_st S.felem mk_to_nat_mod_comm_monoid
let sqr_mod x = S.fmul x x
let mk_nat_mod_concrete_ops : SE.concrete_ops S.felem = {
SE.to = mk_to_nat_mod_comm_monoid;
SE.one = one_mod;
SE.mul = mul_mod;
SE.sqr = sqr_mod;
}
let fsquare_times (a:S.felem) (b:nat) : S.felem =
SE.exp_pow2 mk_nat_mod_concrete_ops a b
val fsquare_times_lemma: a:S.felem -> b:nat ->
Lemma (fsquare_times a b == M.pow a (pow2 b) % S.prime)
let fsquare_times_lemma a b =
SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b;
LE.exp_pow2_lemma nat_mod_comm_monoid a b;
assert (fsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b));
M.lemma_pow_nat_mod_is_pow #S.prime a (pow2 b) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Spec.K256.PointOps.felem -> Spec.K256.PointOps.felem * Spec.K256.PointOps.felem | Prims.Tot | [
"total"
] | [] | [
"Spec.K256.PointOps.felem",
"FStar.Pervasives.Native.Mktuple2",
"Spec.K256.PointOps.fmul",
"Hacl.Spec.K256.Finv.fsquare_times",
"FStar.Pervasives.Native.tuple2"
] | [] | false | false | false | true | false | let fexp_223_23 f =
| let x2 = S.fmul (fsquare_times f 1) f in
let x3 = S.fmul (fsquare_times x2 1) f in
let x6 = S.fmul (fsquare_times x3 3) x3 in
let x9 = S.fmul (fsquare_times x6 3) x3 in
let x11 = S.fmul (fsquare_times x9 2) x2 in
let x22 = S.fmul (fsquare_times x11 11) x11 in
let x44 = S.fmul (fsquare_times x22 22) x22 in
let x88 = S.fmul (fsquare_times x44 44) x44 in
let x176 = S.fmul (fsquare_times x88 88) x88 in
let x220 = S.fmul (fsquare_times x176 44) x44 in
let x223 = S.fmul (fsquare_times x220 3) x3 in
let r = S.fmul (fsquare_times x223 23) x22 in
r, x2 | false |
Hacl.Impl.Frodo.Params.fst | Hacl.Impl.Frodo.Params.cdf_table | val cdf_table (a: S.frodo_alg)
: x: glbuffer uint16 (cdf_table_len a) {witnessed x (S.cdf_table a) /\ recallable x} | val cdf_table (a: S.frodo_alg)
: x: glbuffer uint16 (cdf_table_len a) {witnessed x (S.cdf_table a) /\ recallable x} | let cdf_table (a:S.frodo_alg) :x:glbuffer uint16 (cdf_table_len a)
{witnessed x (S.cdf_table a) /\ recallable x}
=
allow_inversion S.frodo_alg;
match a with
| S.Frodo64 | S.Frodo640 -> cdf_table640
| S.Frodo976 -> cdf_table976
| S.Frodo1344 -> cdf_table1344 | {
"file_name": "code/frodo/Hacl.Impl.Frodo.Params.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 164,
"start_col": 0,
"start_line": 157
} | module Hacl.Impl.Frodo.Params
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.Matrix
module S = Spec.Frodo.Params
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let params_n (a:S.frodo_alg) : x:size_t{v x == S.params_n a} =
match a with
| S.Frodo64 -> 64ul
| S.Frodo640 -> 640ul
| S.Frodo976 -> 976ul
| S.Frodo1344 -> 1344ul
inline_for_extraction noextract
let params_logq (a:S.frodo_alg) : x:size_t{v x == S.params_logq a} =
match a with
| S.Frodo64 | S.Frodo640 -> 15ul
| S.Frodo976 | S.Frodo1344 -> 16ul
inline_for_extraction noextract
let params_extracted_bits (a:S.frodo_alg) : x:size_t{v x == S.params_extracted_bits a} =
match a with
| S.Frodo64 | S.Frodo640 -> 2ul
| S.Frodo976 -> 3ul
| S.Frodo1344 -> 4ul
inline_for_extraction noextract
let crypto_bytes (a:S.frodo_alg) : x:size_t{v x == S.crypto_bytes a} =
match a with
| S.Frodo64 | S.Frodo640 -> 16ul
| S.Frodo976 -> 24ul
| S.Frodo1344 -> 32ul
inline_for_extraction noextract
let params_nbar = 8ul
inline_for_extraction noextract
let bytes_seed_a = 16ul
inline_for_extraction noextract
let bytes_pkhash (a:S.frodo_alg) =
crypto_bytes a
inline_for_extraction noextract
let bytes_mu (a:S.frodo_alg) : x:size_t{v x == S.bytes_mu a} =
params_extracted_bits a *! params_nbar *! params_nbar /. 8ul
inline_for_extraction noextract
let publicmatrixbytes_len (a:S.frodo_alg) =
params_logq a *! (params_n a *! params_nbar /. 8ul)
inline_for_extraction noextract
let secretmatrixbytes_len (a:S.frodo_alg) =
2ul *! params_n a *! params_nbar
inline_for_extraction noextract
let ct1bytes_len (a:S.frodo_alg) =
params_logq a *! (params_nbar *! params_n a /. 8ul)
inline_for_extraction noextract
let ct2bytes_len (a:S.frodo_alg) =
params_logq a *! (params_nbar *! params_nbar /. 8ul)
inline_for_extraction noextract
let crypto_publickeybytes (a:S.frodo_alg) =
bytes_seed_a +! publicmatrixbytes_len a
inline_for_extraction noextract
let crypto_secretkeybytes (a:S.frodo_alg) =
crypto_bytes a +! crypto_publickeybytes a +! secretmatrixbytes_len a +! bytes_pkhash a
inline_for_extraction noextract
let crypto_ciphertextbytes (a:S.frodo_alg) =
ct1bytes_len a +! ct2bytes_len a
inline_for_extraction noextract
let frodo_shake_st (a:S.frodo_alg) =
inputByteLen:size_t
-> input:lbuffer uint8 inputByteLen
-> outputByteLen:size_t
-> output:lbuffer uint8 outputByteLen
-> Stack unit
(requires fun h ->
live h input /\ live h output /\ disjoint input output)
(ensures fun h0 _ h1 -> modifies (loc output) h0 h1 /\
as_seq h1 output == S.frodo_shake a (v inputByteLen) (as_seq h0 input) (v outputByteLen))
inline_for_extraction noextract
let frodo_shake (a:S.frodo_alg) : frodo_shake_st a =
match a with
| S.Frodo64 | S.Frodo640 -> Hacl.SHA3.shake128_hacl
| S.Frodo976 | S.Frodo1344 -> Hacl.SHA3.shake256_hacl
inline_for_extraction noextract
let is_supported (a:S.frodo_gen_a) =
match a with
| S.SHAKE128 -> true
| S.AES128 -> false (* unfortunately, we don't have a verified impl of aes128 in Low* *)
val frodo_gen_matrix:
a:S.frodo_gen_a{is_supported a}
-> n:size_t{0 < v n /\ v n * v n <= max_size_t /\ v n <= maxint U16 /\ v n % 4 = 0}
-> seed:lbuffer uint8 16ul
-> a_matrix:matrix_t n n
-> Stack unit
(requires fun h ->
live h seed /\ live h a_matrix /\ disjoint seed a_matrix)
(ensures fun h0 _ h1 -> modifies1 a_matrix h0 h1 /\
as_matrix h1 a_matrix == S.frodo_gen_matrix a (v n) (as_seq h0 seed))
[@CInline]
let frodo_gen_matrix a n seed a_matrix =
match a with
| S.SHAKE128 -> Hacl.Impl.Frodo.Gen.frodo_gen_matrix_shake_4x n seed a_matrix
(* | S.AES128 -> Hacl.Impl.Frodo.Gen.frodo_gen_matrix_aes n seed a_matrix *)
(** CDF tables *)
let cdf_table640 :x:glbuffer uint16 13ul{witnessed x (S.cdf_table S.Frodo640) /\ recallable x} =
createL_global S.cdf_list_640
let cdf_table976 :x:glbuffer uint16 11ul{witnessed x (S.cdf_table S.Frodo976) /\ recallable x} =
createL_global S.cdf_list_976
let cdf_table1344 :x:glbuffer uint16 7ul{witnessed x (S.cdf_table S.Frodo1344) /\ recallable x} =
createL_global S.cdf_list_1344
inline_for_extraction noextract
let cdf_table_len (a:S.frodo_alg) : x:size_t{v x = S.cdf_table_len a} =
allow_inversion S.frodo_alg;
match a with
| S.Frodo64 | S.Frodo640 -> 13ul
| S.Frodo976 -> 11ul
| S.Frodo1344 -> 7ul | {
"checked_file": "/",
"dependencies": [
"Spec.Frodo.Params.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.SHA3.fst.checked",
"Hacl.Impl.Matrix.fst.checked",
"Hacl.Impl.Frodo.Gen.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Frodo.Params.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Frodo.Params",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Frodo.Params.frodo_alg
-> x:
Lib.Buffer.glbuffer Lib.IntTypes.uint16 (Hacl.Impl.Frodo.Params.cdf_table_len a)
{Lib.Buffer.witnessed x (Spec.Frodo.Params.cdf_table a) /\ Lib.Buffer.recallable x} | Prims.Tot | [
"total"
] | [] | [
"Spec.Frodo.Params.frodo_alg",
"Hacl.Impl.Frodo.Params.cdf_table640",
"Hacl.Impl.Frodo.Params.cdf_table976",
"Hacl.Impl.Frodo.Params.cdf_table1344",
"Lib.Buffer.glbuffer",
"Lib.IntTypes.uint16",
"Hacl.Impl.Frodo.Params.cdf_table_len",
"Prims.l_and",
"Lib.Buffer.witnessed",
"Spec.Frodo.Params.cdf_table",
"Lib.Buffer.recallable",
"Lib.Buffer.CONST",
"Prims.unit",
"FStar.Pervasives.allow_inversion"
] | [] | false | false | false | false | false | let cdf_table (a: S.frodo_alg)
: x: glbuffer uint16 (cdf_table_len a) {witnessed x (S.cdf_table a) /\ recallable x} =
| allow_inversion S.frodo_alg;
match a with
| S.Frodo64 | S.Frodo640 -> cdf_table640
| S.Frodo976 -> cdf_table976
| S.Frodo1344 -> cdf_table1344 | false |
Pulse.Checker.Prover.fst | Pulse.Checker.Prover.prove_pures | val prove_pures (#preamble: _) (pst: prover_state preamble)
: T.Tac (pst': prover_state preamble {pst' `pst_extends` pst /\ is_terminal pst'}) | val prove_pures (#preamble: _) (pst: prover_state preamble)
: T.Tac (pst': prover_state preamble {pst' `pst_extends` pst /\ is_terminal pst'}) | let rec prove_pures #preamble (pst:prover_state preamble)
: T.Tac (pst':prover_state preamble { pst' `pst_extends` pst /\
is_terminal pst' }) =
match pst.unsolved with
| [] -> pst
| {t=Tm_Pure p}::unsolved' ->
let pst_opt = IntroPure.intro_pure pst p unsolved' () in
(match pst_opt with
| None ->
let open Pulse.PP in
fail_doc pst.pg None [
text "Cannot prove pure proposition" ^/^
pp p
]
| Some pst1 ->
let pst2 = prove_pures pst1 in
assert (pst1 `pst_extends` pst);
assert (pst2 `pst_extends` pst1);
assert (pst2 `pst_extends` pst);
pst2)
| _ ->
fail pst.pg None
(Printf.sprintf "Impossible! prover.prove_pures: %s is not a pure, please file a bug-report"
(P.term_to_string (L.hd pst.unsolved))) | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 48,
"end_line": 109,
"start_col": 0,
"start_line": 85
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Prover
open FStar.List.Tot
open Pulse.Syntax
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Checker.Base
module RU = Pulse.RuntimeUtils
module L = FStar.List.Tot
module T = FStar.Tactics.V2
module P = Pulse.Syntax.Printer
module Pprint = FStar.Stubs.Pprint
module Metatheory = Pulse.Typing.Metatheory
module PS = Pulse.Checker.Prover.Substs
module ElimExists = Pulse.Checker.Prover.ElimExists
module ElimPure = Pulse.Checker.Prover.ElimPure
module Match = Pulse.Checker.Prover.Match
module IntroExists = Pulse.Checker.Prover.IntroExists
module IntroPure = Pulse.Checker.Prover.IntroPure
let coerce_eq (#a #b:Type) (x:a) (_:squash (a == b)) : y:b{y == x} = x
let elim_exists_and_pure (#g:env) (#ctxt:vprop)
(ctxt_typing:tot_typing g ctxt tm_vprop)
: T.Tac (g':env { env_extends g' g } &
ctxt':term &
tot_typing g' ctxt' tm_vprop &
continuation_elaborator g ctxt g' ctxt') =
let (| g1, ctxt1, d1, k1 |) = ElimExists.elim_exists ctxt_typing in
let (| g2, ctxt2, d2, k2 |) = ElimPure.elim_pure d1 in
(| g2, ctxt2, d2, k_elab_trans k1 k2 |)
let unsolved_equiv_pst (#preamble:_) (pst:prover_state preamble) (unsolved':list vprop)
(d:vprop_equiv (push_env pst.pg pst.uvs) (list_as_vprop pst.unsolved) (list_as_vprop unsolved'))
: prover_state preamble =
{ pst with unsolved = unsolved'; goals_inv = RU.magic () }
let rec collect_exists (g:env) (l:list vprop)
: exs:list vprop &
rest:list vprop &
vprop_equiv g (list_as_vprop l) (list_as_vprop (exs @ rest)) =
match l with
| [] -> (| [], [], VE_Refl _ _ |)
| hd::tl ->
let (| exs, rest, _ |) = collect_exists g tl in
match hd.t with
| Tm_ExistsSL _ _ _ ->
(| hd::exs, rest, RU.magic #(vprop_equiv _ _ _) () |)
| _ -> (| exs, hd::rest, RU.magic #(vprop_equiv _ _ _) () |)
let rec collect_pures (g:env) (l:list vprop)
: pures:list vprop &
rest:list vprop &
vprop_equiv g (list_as_vprop l) (list_as_vprop (rest @ pures)) =
match l with
| [] -> (| [], [], VE_Refl _ _ |)
| hd::tl ->
let (| pures, rest, _ |) = collect_pures g tl in
match hd.t with
| Tm_Pure _ -> (| hd::pures, rest, RU.magic #(vprop_equiv _ _ _) () |)
| _ -> (| pures, hd::rest, RU.magic #(vprop_equiv _ _ _) () |) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Readback.fsti.checked",
"Pulse.PP.fst.checked",
"Pulse.Config.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.Match.fsti.checked",
"Pulse.Checker.Prover.IntroPure.fsti.checked",
"Pulse.Checker.Prover.IntroExists.fsti.checked",
"Pulse.Checker.Prover.ElimPure.fsti.checked",
"Pulse.Checker.Prover.ElimExists.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Pprint.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.IntroPure",
"short_module": "IntroPure"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.IntroExists",
"short_module": "IntroExists"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Match",
"short_module": "Match"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.ElimPure",
"short_module": "ElimPure"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.ElimExists",
"short_module": "ElimExists"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "FStar.Stubs.Pprint",
"short_module": "Pprint"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | pst: Pulse.Checker.Prover.Base.prover_state preamble
-> FStar.Tactics.Effect.Tac
(pst':
Pulse.Checker.Prover.Base.prover_state preamble
{ Pulse.Checker.Prover.Base.pst_extends pst' pst /\
Pulse.Checker.Prover.Base.is_terminal pst' }) | FStar.Tactics.Effect.Tac | [] | [] | [
"Pulse.Checker.Prover.Base.preamble",
"Pulse.Checker.Prover.Base.prover_state",
"Pulse.Checker.Prover.Base.__proj__Mkprover_state__item__unsolved",
"Prims.l_and",
"Pulse.Checker.Prover.Base.pst_extends",
"Pulse.Checker.Prover.Base.is_terminal",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.range",
"Prims.list",
"Pulse.Syntax.Base.vprop",
"Pulse.Typing.Env.fail_doc",
"Pulse.Checker.Prover.Base.__proj__Mkprover_state__item__pg",
"FStar.Pervasives.Native.None",
"FStar.Stubs.Pprint.document",
"Prims.Cons",
"Prims.Nil",
"FStar.Stubs.Pprint.op_Hat_Slash_Hat",
"Pulse.PP.text",
"Pulse.PP.pp",
"Pulse.PP.uu___44",
"Prims.unit",
"Prims._assert",
"Pulse.Checker.Prover.prove_pures",
"FStar.Pervasives.Native.option",
"Pulse.Checker.Prover.IntroPure.intro_pure",
"Pulse.Typing.Env.fail",
"Prims.string",
"FStar.Printf.sprintf",
"Pulse.Syntax.Printer.term_to_string",
"FStar.List.Tot.Base.hd"
] | [
"recursion"
] | false | true | false | false | false | let rec prove_pures #preamble (pst: prover_state preamble)
: T.Tac (pst': prover_state preamble {pst' `pst_extends` pst /\ is_terminal pst'}) =
| match pst.unsolved with
| [] -> pst
| { t = Tm_Pure p } :: unsolved' ->
let pst_opt = IntroPure.intro_pure pst p unsolved' () in
(match pst_opt with
| None ->
let open Pulse.PP in fail_doc pst.pg None [text "Cannot prove pure proposition" ^/^ pp p]
| Some pst1 ->
let pst2 = prove_pures pst1 in
assert (pst1 `pst_extends` pst);
assert (pst2 `pst_extends` pst1);
assert (pst2 `pst_extends` pst);
pst2)
| _ ->
fail pst.pg
None
(Printf.sprintf "Impossible! prover.prove_pures: %s is not a pure, please file a bug-report"
(P.term_to_string (L.hd pst.unsolved))) | false |
Hacl.Spec.K256.Finv.fst | Hacl.Spec.K256.Finv.fsquare_times_lemma | val fsquare_times_lemma: a:S.felem -> b:nat ->
Lemma (fsquare_times a b == M.pow a (pow2 b) % S.prime) | val fsquare_times_lemma: a:S.felem -> b:nat ->
Lemma (fsquare_times a b == M.pow a (pow2 b) % S.prime) | let fsquare_times_lemma a b =
SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b;
LE.exp_pow2_lemma nat_mod_comm_monoid a b;
assert (fsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b));
M.lemma_pow_nat_mod_is_pow #S.prime a (pow2 b) | {
"file_name": "code/k256/Hacl.Spec.K256.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 48,
"end_line": 45,
"start_col": 0,
"start_line": 41
} | module Hacl.Spec.K256.Finv
open FStar.Mul
module SE = Spec.Exponentiation
module LE = Lib.Exponentiation
module M = Lib.NatMod
module S = Spec.K256
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.prime
let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.felem = {
SE.a_spec = S.felem;
SE.comm_monoid = nat_mod_comm_monoid;
SE.refl = (fun (x:S.felem) -> x);
}
val one_mod : SE.one_st S.felem mk_to_nat_mod_comm_monoid
let one_mod _ = S.one
val mul_mod : SE.mul_st S.felem mk_to_nat_mod_comm_monoid
let mul_mod x y = S.fmul x y
val sqr_mod : SE.sqr_st S.felem mk_to_nat_mod_comm_monoid
let sqr_mod x = S.fmul x x
let mk_nat_mod_concrete_ops : SE.concrete_ops S.felem = {
SE.to = mk_to_nat_mod_comm_monoid;
SE.one = one_mod;
SE.mul = mul_mod;
SE.sqr = sqr_mod;
}
let fsquare_times (a:S.felem) (b:nat) : S.felem =
SE.exp_pow2 mk_nat_mod_concrete_ops a b
val fsquare_times_lemma: a:S.felem -> b:nat -> | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.K256.PointOps.felem -> b: Prims.nat
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.K256.Finv.fsquare_times a b ==
Lib.NatMod.pow a (Prims.pow2 b) % Spec.K256.PointOps.prime) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.K256.PointOps.felem",
"Prims.nat",
"Lib.NatMod.lemma_pow_nat_mod_is_pow",
"Spec.K256.PointOps.prime",
"Prims.pow2",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Prims.l_or",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.K256.Finv.fsquare_times",
"Lib.Exponentiation.Definition.pow",
"Lib.NatMod.nat_mod",
"Hacl.Spec.K256.Finv.nat_mod_comm_monoid",
"Lib.Exponentiation.exp_pow2_lemma",
"Spec.Exponentiation.exp_pow2_lemma",
"Hacl.Spec.K256.Finv.mk_nat_mod_concrete_ops"
] | [] | true | false | true | false | false | let fsquare_times_lemma a b =
| SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b;
LE.exp_pow2_lemma nat_mod_comm_monoid a b;
assert (fsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b));
M.lemma_pow_nat_mod_is_pow #S.prime a (pow2 b) | false |
Hacl.Spec.K256.Finv.fst | Hacl.Spec.K256.Finv.sqr_mod | val sqr_mod : SE.sqr_st S.felem mk_to_nat_mod_comm_monoid | val sqr_mod : SE.sqr_st S.felem mk_to_nat_mod_comm_monoid | let sqr_mod x = S.fmul x x | {
"file_name": "code/k256/Hacl.Spec.K256.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 27,
"start_col": 0,
"start_line": 27
} | module Hacl.Spec.K256.Finv
open FStar.Mul
module SE = Spec.Exponentiation
module LE = Lib.Exponentiation
module M = Lib.NatMod
module S = Spec.K256
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.prime
let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.felem = {
SE.a_spec = S.felem;
SE.comm_monoid = nat_mod_comm_monoid;
SE.refl = (fun (x:S.felem) -> x);
}
val one_mod : SE.one_st S.felem mk_to_nat_mod_comm_monoid
let one_mod _ = S.one
val mul_mod : SE.mul_st S.felem mk_to_nat_mod_comm_monoid
let mul_mod x y = S.fmul x y | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Spec.Exponentiation.sqr_st Spec.K256.PointOps.felem Hacl.Spec.K256.Finv.mk_to_nat_mod_comm_monoid | Prims.Tot | [
"total"
] | [] | [
"Spec.K256.PointOps.felem",
"Spec.K256.PointOps.fmul"
] | [] | false | false | false | true | false | let sqr_mod x =
| S.fmul x x | false |
Hacl.Spec.K256.Finv.fst | Hacl.Spec.K256.Finv.one_mod | val one_mod : SE.one_st S.felem mk_to_nat_mod_comm_monoid | val one_mod : SE.one_st S.felem mk_to_nat_mod_comm_monoid | let one_mod _ = S.one | {
"file_name": "code/k256/Hacl.Spec.K256.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 21,
"end_line": 21,
"start_col": 0,
"start_line": 21
} | module Hacl.Spec.K256.Finv
open FStar.Mul
module SE = Spec.Exponentiation
module LE = Lib.Exponentiation
module M = Lib.NatMod
module S = Spec.K256
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.prime
let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.felem = {
SE.a_spec = S.felem;
SE.comm_monoid = nat_mod_comm_monoid;
SE.refl = (fun (x:S.felem) -> x);
} | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Spec.Exponentiation.one_st Spec.K256.PointOps.felem Hacl.Spec.K256.Finv.mk_to_nat_mod_comm_monoid | Prims.Tot | [
"total"
] | [] | [
"Prims.unit",
"Spec.K256.PointOps.one",
"Spec.K256.PointOps.felem"
] | [] | false | false | false | true | false | let one_mod _ =
| S.one | false |
Hacl.Spec.K256.Finv.fst | Hacl.Spec.K256.Finv.lemma_pow_mod_1 | val lemma_pow_mod_1: f:S.felem -> Lemma (f == M.pow f 1 % S.prime) | val lemma_pow_mod_1: f:S.felem -> Lemma (f == M.pow f 1 % S.prime) | let lemma_pow_mod_1 f =
M.lemma_pow1 f;
Math.Lemmas.small_mod f S.prime;
assert_norm (pow2 0 = 1);
assert (f == M.pow f 1 % S.prime) | {
"file_name": "code/k256/Hacl.Spec.K256.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 96,
"start_col": 0,
"start_line": 92
} | module Hacl.Spec.K256.Finv
open FStar.Mul
module SE = Spec.Exponentiation
module LE = Lib.Exponentiation
module M = Lib.NatMod
module S = Spec.K256
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.prime
let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.felem = {
SE.a_spec = S.felem;
SE.comm_monoid = nat_mod_comm_monoid;
SE.refl = (fun (x:S.felem) -> x);
}
val one_mod : SE.one_st S.felem mk_to_nat_mod_comm_monoid
let one_mod _ = S.one
val mul_mod : SE.mul_st S.felem mk_to_nat_mod_comm_monoid
let mul_mod x y = S.fmul x y
val sqr_mod : SE.sqr_st S.felem mk_to_nat_mod_comm_monoid
let sqr_mod x = S.fmul x x
let mk_nat_mod_concrete_ops : SE.concrete_ops S.felem = {
SE.to = mk_to_nat_mod_comm_monoid;
SE.one = one_mod;
SE.mul = mul_mod;
SE.sqr = sqr_mod;
}
let fsquare_times (a:S.felem) (b:nat) : S.felem =
SE.exp_pow2 mk_nat_mod_concrete_ops a b
val fsquare_times_lemma: a:S.felem -> b:nat ->
Lemma (fsquare_times a b == M.pow a (pow2 b) % S.prime)
let fsquare_times_lemma a b =
SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b;
LE.exp_pow2_lemma nat_mod_comm_monoid a b;
assert (fsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b));
M.lemma_pow_nat_mod_is_pow #S.prime a (pow2 b)
val fexp_223_23: f:S.felem -> tuple2 S.felem S.felem
let fexp_223_23 f =
let x2 = S.fmul (fsquare_times f 1) f in
let x3 = S.fmul (fsquare_times x2 1) f in
let x6 = S.fmul (fsquare_times x3 3) x3 in
let x9 = S.fmul (fsquare_times x6 3) x3 in
let x11 = S.fmul (fsquare_times x9 2) x2 in
let x22 = S.fmul (fsquare_times x11 11) x11 in
let x44 = S.fmul (fsquare_times x22 22) x22 in
let x88 = S.fmul (fsquare_times x44 44) x44 in
let x176 = S.fmul (fsquare_times x88 88) x88 in
let x220 = S.fmul (fsquare_times x176 44) x44 in
let x223 = S.fmul (fsquare_times x220 3) x3 in
let r = S.fmul (fsquare_times x223 23) x22 in
r, x2
(**
The algorithm is taken from
https://briansmith.org/ecc-inversion-addition-chains-01
*)
val finv: f:S.felem -> S.felem
let finv f =
let r, x2 = fexp_223_23 f in
let r = S.fmul (fsquare_times r 5) f in
let r = S.fmul (fsquare_times r 3) x2 in
let r = S.fmul (fsquare_times r 2) f in
r
val fsqrt: f:S.felem -> S.felem
let fsqrt f =
let r, x2 = fexp_223_23 f in
let r = S.fmul (fsquare_times r 6) x2 in
let r = fsquare_times r 2 in
r
val is_fsqrt: f:S.felem -> f2:S.felem -> bool
let is_fsqrt f f2 = S.fmul f f = f2 | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Spec.K256.PointOps.felem
-> FStar.Pervasives.Lemma (ensures f == Lib.NatMod.pow f 1 % Spec.K256.PointOps.prime) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.K256.PointOps.felem",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"Lib.NatMod.pow",
"Spec.K256.PointOps.prime",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality",
"Prims.pow2",
"FStar.Math.Lemmas.small_mod",
"Lib.NatMod.lemma_pow1"
] | [] | true | false | true | false | false | let lemma_pow_mod_1 f =
| M.lemma_pow1 f;
Math.Lemmas.small_mod f S.prime;
assert_norm (pow2 0 = 1);
assert (f == M.pow f 1 % S.prime) | false |
Hacl.Spec.K256.Finv.fst | Hacl.Spec.K256.Finv.mul_mod | val mul_mod : SE.mul_st S.felem mk_to_nat_mod_comm_monoid | val mul_mod : SE.mul_st S.felem mk_to_nat_mod_comm_monoid | let mul_mod x y = S.fmul x y | {
"file_name": "code/k256/Hacl.Spec.K256.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 28,
"end_line": 24,
"start_col": 0,
"start_line": 24
} | module Hacl.Spec.K256.Finv
open FStar.Mul
module SE = Spec.Exponentiation
module LE = Lib.Exponentiation
module M = Lib.NatMod
module S = Spec.K256
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.prime
let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.felem = {
SE.a_spec = S.felem;
SE.comm_monoid = nat_mod_comm_monoid;
SE.refl = (fun (x:S.felem) -> x);
}
val one_mod : SE.one_st S.felem mk_to_nat_mod_comm_monoid
let one_mod _ = S.one | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Spec.Exponentiation.mul_st Spec.K256.PointOps.felem Hacl.Spec.K256.Finv.mk_to_nat_mod_comm_monoid | Prims.Tot | [
"total"
] | [] | [
"Spec.K256.PointOps.felem",
"Spec.K256.PointOps.fmul"
] | [] | false | false | false | true | false | let mul_mod x y =
| S.fmul x y | false |
Hacl.Spec.K256.Finv.fst | Hacl.Spec.K256.Finv.is_fsqrt | val is_fsqrt: f:S.felem -> f2:S.felem -> bool | val is_fsqrt: f:S.felem -> f2:S.felem -> bool | let is_fsqrt f f2 = S.fmul f f = f2 | {
"file_name": "code/k256/Hacl.Spec.K256.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 88,
"start_col": 0,
"start_line": 88
} | module Hacl.Spec.K256.Finv
open FStar.Mul
module SE = Spec.Exponentiation
module LE = Lib.Exponentiation
module M = Lib.NatMod
module S = Spec.K256
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.prime
let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.felem = {
SE.a_spec = S.felem;
SE.comm_monoid = nat_mod_comm_monoid;
SE.refl = (fun (x:S.felem) -> x);
}
val one_mod : SE.one_st S.felem mk_to_nat_mod_comm_monoid
let one_mod _ = S.one
val mul_mod : SE.mul_st S.felem mk_to_nat_mod_comm_monoid
let mul_mod x y = S.fmul x y
val sqr_mod : SE.sqr_st S.felem mk_to_nat_mod_comm_monoid
let sqr_mod x = S.fmul x x
let mk_nat_mod_concrete_ops : SE.concrete_ops S.felem = {
SE.to = mk_to_nat_mod_comm_monoid;
SE.one = one_mod;
SE.mul = mul_mod;
SE.sqr = sqr_mod;
}
let fsquare_times (a:S.felem) (b:nat) : S.felem =
SE.exp_pow2 mk_nat_mod_concrete_ops a b
val fsquare_times_lemma: a:S.felem -> b:nat ->
Lemma (fsquare_times a b == M.pow a (pow2 b) % S.prime)
let fsquare_times_lemma a b =
SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b;
LE.exp_pow2_lemma nat_mod_comm_monoid a b;
assert (fsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b));
M.lemma_pow_nat_mod_is_pow #S.prime a (pow2 b)
val fexp_223_23: f:S.felem -> tuple2 S.felem S.felem
let fexp_223_23 f =
let x2 = S.fmul (fsquare_times f 1) f in
let x3 = S.fmul (fsquare_times x2 1) f in
let x6 = S.fmul (fsquare_times x3 3) x3 in
let x9 = S.fmul (fsquare_times x6 3) x3 in
let x11 = S.fmul (fsquare_times x9 2) x2 in
let x22 = S.fmul (fsquare_times x11 11) x11 in
let x44 = S.fmul (fsquare_times x22 22) x22 in
let x88 = S.fmul (fsquare_times x44 44) x44 in
let x176 = S.fmul (fsquare_times x88 88) x88 in
let x220 = S.fmul (fsquare_times x176 44) x44 in
let x223 = S.fmul (fsquare_times x220 3) x3 in
let r = S.fmul (fsquare_times x223 23) x22 in
r, x2
(**
The algorithm is taken from
https://briansmith.org/ecc-inversion-addition-chains-01
*)
val finv: f:S.felem -> S.felem
let finv f =
let r, x2 = fexp_223_23 f in
let r = S.fmul (fsquare_times r 5) f in
let r = S.fmul (fsquare_times r 3) x2 in
let r = S.fmul (fsquare_times r 2) f in
r
val fsqrt: f:S.felem -> S.felem
let fsqrt f =
let r, x2 = fexp_223_23 f in
let r = S.fmul (fsquare_times r 6) x2 in
let r = fsquare_times r 2 in
r | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Spec.K256.PointOps.felem -> f2: Spec.K256.PointOps.felem -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Spec.K256.PointOps.felem",
"Prims.op_Equality",
"Spec.K256.PointOps.fmul",
"Prims.bool"
] | [] | false | false | false | true | false | let is_fsqrt f f2 =
| S.fmul f f = f2 | false |
Hacl.Spec.K256.Finv.fst | Hacl.Spec.K256.Finv.fsqrt_is_fsqrt_lemma | val fsqrt_is_fsqrt_lemma: f:S.felem -> Lemma (fsqrt f == S.fsqrt f) | val fsqrt_is_fsqrt_lemma: f:S.felem -> Lemma (fsqrt f == S.fsqrt f) | let fsqrt_is_fsqrt_lemma f =
fsqrt_lemma f;
assert (fsqrt f == M.pow f ((S.prime + 1) / 4) % S.prime);
M.lemma_pow_mod #S.prime f ((S.prime + 1) / 4) | {
"file_name": "code/k256/Hacl.Spec.K256.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 48,
"end_line": 271,
"start_col": 0,
"start_line": 268
} | module Hacl.Spec.K256.Finv
open FStar.Mul
module SE = Spec.Exponentiation
module LE = Lib.Exponentiation
module M = Lib.NatMod
module S = Spec.K256
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.prime
let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.felem = {
SE.a_spec = S.felem;
SE.comm_monoid = nat_mod_comm_monoid;
SE.refl = (fun (x:S.felem) -> x);
}
val one_mod : SE.one_st S.felem mk_to_nat_mod_comm_monoid
let one_mod _ = S.one
val mul_mod : SE.mul_st S.felem mk_to_nat_mod_comm_monoid
let mul_mod x y = S.fmul x y
val sqr_mod : SE.sqr_st S.felem mk_to_nat_mod_comm_monoid
let sqr_mod x = S.fmul x x
let mk_nat_mod_concrete_ops : SE.concrete_ops S.felem = {
SE.to = mk_to_nat_mod_comm_monoid;
SE.one = one_mod;
SE.mul = mul_mod;
SE.sqr = sqr_mod;
}
let fsquare_times (a:S.felem) (b:nat) : S.felem =
SE.exp_pow2 mk_nat_mod_concrete_ops a b
val fsquare_times_lemma: a:S.felem -> b:nat ->
Lemma (fsquare_times a b == M.pow a (pow2 b) % S.prime)
let fsquare_times_lemma a b =
SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b;
LE.exp_pow2_lemma nat_mod_comm_monoid a b;
assert (fsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b));
M.lemma_pow_nat_mod_is_pow #S.prime a (pow2 b)
val fexp_223_23: f:S.felem -> tuple2 S.felem S.felem
let fexp_223_23 f =
let x2 = S.fmul (fsquare_times f 1) f in
let x3 = S.fmul (fsquare_times x2 1) f in
let x6 = S.fmul (fsquare_times x3 3) x3 in
let x9 = S.fmul (fsquare_times x6 3) x3 in
let x11 = S.fmul (fsquare_times x9 2) x2 in
let x22 = S.fmul (fsquare_times x11 11) x11 in
let x44 = S.fmul (fsquare_times x22 22) x22 in
let x88 = S.fmul (fsquare_times x44 44) x44 in
let x176 = S.fmul (fsquare_times x88 88) x88 in
let x220 = S.fmul (fsquare_times x176 44) x44 in
let x223 = S.fmul (fsquare_times x220 3) x3 in
let r = S.fmul (fsquare_times x223 23) x22 in
r, x2
(**
The algorithm is taken from
https://briansmith.org/ecc-inversion-addition-chains-01
*)
val finv: f:S.felem -> S.felem
let finv f =
let r, x2 = fexp_223_23 f in
let r = S.fmul (fsquare_times r 5) f in
let r = S.fmul (fsquare_times r 3) x2 in
let r = S.fmul (fsquare_times r 2) f in
r
val fsqrt: f:S.felem -> S.felem
let fsqrt f =
let r, x2 = fexp_223_23 f in
let r = S.fmul (fsquare_times r 6) x2 in
let r = fsquare_times r 2 in
r
val is_fsqrt: f:S.felem -> f2:S.felem -> bool
let is_fsqrt f f2 = S.fmul f f = f2
val lemma_pow_mod_1: f:S.felem -> Lemma (f == M.pow f 1 % S.prime)
let lemma_pow_mod_1 f =
M.lemma_pow1 f;
Math.Lemmas.small_mod f S.prime;
assert_norm (pow2 0 = 1);
assert (f == M.pow f 1 % S.prime)
val lemma_pow_mod_mul: f:S.felem -> a:nat -> b:nat ->
Lemma (S.fmul (M.pow f a % S.prime) (M.pow f b % S.prime) == M.pow f (a + b) % S.prime)
let lemma_pow_mod_mul f a b =
calc (==) {
S.fmul (M.pow f a % S.prime) (M.pow f b % S.prime);
(==) {
Math.Lemmas.lemma_mod_mul_distr_l (M.pow f a) (M.pow f b % S.prime) S.prime;
Math.Lemmas.lemma_mod_mul_distr_r (M.pow f a) (M.pow f b) S.prime }
M.pow f a * M.pow f b % S.prime;
(==) { M.lemma_pow_add f a b }
M.pow f (a + b) % S.prime;
}
val lemma_pow_pow_mod: f:S.felem -> a:nat -> b:nat ->
Lemma (M.pow (M.pow f a % S.prime) b % S.prime == M.pow f (a * b) % S.prime)
let lemma_pow_pow_mod f a b =
calc (==) {
M.pow (M.pow f a % S.prime) b % S.prime;
(==) { M.lemma_pow_mod_base (M.pow f a) b S.prime }
M.pow (M.pow f a) b % S.prime;
(==) { M.lemma_pow_mul f a b }
M.pow f (a * b) % S.prime;
}
val lemma_pow_pow_mod_mul: f:S.felem -> a:nat -> b:nat -> c:nat ->
Lemma (S.fmul (M.pow (M.pow f a % S.prime) b % S.prime) (M.pow f c % S.prime) == M.pow f (a * b + c) % S.prime)
let lemma_pow_pow_mod_mul f a b c =
calc (==) {
S.fmul (M.pow (M.pow f a % S.prime) b % S.prime) (M.pow f c % S.prime);
(==) { lemma_pow_pow_mod f a b }
S.fmul (M.pow f (a * b) % S.prime) (M.pow f c % S.prime);
(==) { lemma_pow_mod_mul f (a * b) c }
M.pow f (a * b + c) % S.prime;
}
val fexp_223_23_lemma: f:S.felem ->
Lemma (let (r, x2) = fexp_223_23 f in
x2 == M.pow f 0x3 % S.prime /\
r == M.pow f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff % S.prime)
let fexp_223_23_lemma f =
let x2 = S.fmul (fsquare_times f 1) f in
fsquare_times_lemma f 1;
assert_norm (pow2 1 = 0x2);
lemma_pow_mod_1 f;
lemma_pow_mod_mul f 0x2 0x1;
assert (x2 == M.pow f 0x3 % S.prime);
let x3 = S.fmul (fsquare_times x2 1) f in
fsquare_times_lemma x2 1;
lemma_pow_mod_1 f;
lemma_pow_pow_mod_mul f 0x3 0x2 0x1;
assert (x3 == M.pow f 0x7 % S.prime);
let x6 = S.fmul (fsquare_times x3 3) x3 in
fsquare_times_lemma x3 3;
assert_norm (pow2 3 = 8);
lemma_pow_pow_mod_mul f 0x7 0x8 0x7;
assert (x6 == M.pow f 0x3f % S.prime);
let x9 = S.fmul (fsquare_times x6 3) x3 in
fsquare_times_lemma x6 3;
lemma_pow_pow_mod_mul f 0x3f 0x8 0x7;
assert (x9 == M.pow f 0x1ff % S.prime);
let x11 = S.fmul (fsquare_times x9 2) x2 in
fsquare_times_lemma x9 2;
assert_norm (pow2 2 = 0x4);
lemma_pow_pow_mod_mul f 0x1ff 0x4 0x3;
assert (x11 == M.pow f 0x7ff % S.prime);
let x22 = S.fmul (fsquare_times x11 11) x11 in
fsquare_times_lemma x11 11;
assert_norm (pow2 11 = 0x800);
lemma_pow_pow_mod_mul f 0x7ff 0x800 0x7ff;
assert (x22 == M.pow f 0x3fffff % S.prime);
let x44 = S.fmul (fsquare_times x22 22) x22 in
fsquare_times_lemma x22 22;
assert_norm (pow2 22 = 0x400000);
lemma_pow_pow_mod_mul f 0x3fffff 0x400000 0x3fffff;
assert (x44 == M.pow f 0xfffffffffff % S.prime);
let x88 = S.fmul (fsquare_times x44 44) x44 in
fsquare_times_lemma x44 44;
assert_norm (pow2 44 = 0x100000000000);
lemma_pow_pow_mod_mul f 0xfffffffffff 0x100000000000 0xfffffffffff;
assert (x88 == M.pow f 0xffffffffffffffffffffff % S.prime);
let x176 = S.fmul (fsquare_times x88 88) x88 in
fsquare_times_lemma x88 88;
assert_norm (pow2 88 = 0x10000000000000000000000);
lemma_pow_pow_mod_mul f 0xffffffffffffffffffffff 0x10000000000000000000000 0xffffffffffffffffffffff;
assert (x176 == M.pow f 0xffffffffffffffffffffffffffffffffffffffffffff % S.prime);
let x220 = S.fmul (fsquare_times x176 44) x44 in
fsquare_times_lemma x176 44;
lemma_pow_pow_mod_mul f 0xffffffffffffffffffffffffffffffffffffffffffff 0x100000000000 0xfffffffffff;
assert (x220 == M.pow f 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffff % S.prime);
let x223 = S.fmul (fsquare_times x220 3) x3 in
fsquare_times_lemma x220 3;
lemma_pow_pow_mod_mul f 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffff 0x8 0x7;
assert (x223 == M.pow f 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff % S.prime);
let r0 = S.fmul (fsquare_times x223 23) x22 in
fsquare_times_lemma x223 23;
assert_norm (pow2 23 = 0x800000);
lemma_pow_pow_mod_mul f 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff 0x800000 0x3fffff;
assert (r0 == M.pow f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff % S.prime)
// S.prime - 2 = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2d
val finv_lemma: f:S.felem -> Lemma (finv f == M.pow f (S.prime - 2) % S.prime)
let finv_lemma f =
lemma_pow_mod_1 f;
let r0, x2 = fexp_223_23 f in
fexp_223_23_lemma f;
let r1 = S.fmul (fsquare_times r0 5) f in
fsquare_times_lemma r0 5;
assert_norm (pow2 5 = 0x20);
lemma_pow_pow_mod_mul f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff 0x20 0x1;
assert (r1 == M.pow f 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff7ffffe1 % S.prime);
let r2 = S.fmul (fsquare_times r1 3) x2 in
fsquare_times_lemma r1 3;
lemma_pow_pow_mod_mul f 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff7ffffe1 0x8 0x3;
assert (r2 == M.pow f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff0b % S.prime);
let r = S.fmul (fsquare_times r2 2) f in
fsquare_times_lemma r2 2;
lemma_pow_pow_mod_mul f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff0b 0x4 0x1;
assert (r == M.pow f 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2d % S.prime)
val finv_is_finv_lemma: f:S.felem -> Lemma (finv f == S.finv f)
let finv_is_finv_lemma f =
finv_lemma f;
assert (finv f == M.pow f (S.prime - 2) % S.prime);
M.lemma_pow_mod #S.prime f (S.prime - 2)
val fsqrt_lemma: f:S.felem -> Lemma (fsqrt f == M.pow f ((S.prime + 1) / 4) % S.prime)
let fsqrt_lemma f =
lemma_pow_mod_1 f;
let r0, x2 = fexp_223_23 f in
fexp_223_23_lemma f;
let r1 = S.fmul (fsquare_times r0 6) x2 in
fsquare_times_lemma r0 6;
assert_norm (pow2 6 = 0x40);
lemma_pow_pow_mod_mul f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff 0x40 0x3;
assert (r1 == M.pow f 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc3 % S.prime);
let r = fsquare_times r1 2 in
fsquare_times_lemma r1 2;
assert_norm (pow2 2 = 4);
lemma_pow_pow_mod f 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc3 0x4;
assert (r == M.pow f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff0c % S.prime);
assert_norm (0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff0c == (S.prime + 1) / 4) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Spec.K256.PointOps.felem
-> FStar.Pervasives.Lemma (ensures Hacl.Spec.K256.Finv.fsqrt f == Spec.K256.PointOps.fsqrt f) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.K256.PointOps.felem",
"Lib.NatMod.lemma_pow_mod",
"Spec.K256.PointOps.prime",
"Prims.op_Division",
"Prims.op_Addition",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Hacl.Spec.K256.Finv.fsqrt",
"Prims.op_Modulus",
"Lib.NatMod.pow",
"Hacl.Spec.K256.Finv.fsqrt_lemma"
] | [] | true | false | true | false | false | let fsqrt_is_fsqrt_lemma f =
| fsqrt_lemma f;
assert (fsqrt f == M.pow f ((S.prime + 1) / 4) % S.prime);
M.lemma_pow_mod #S.prime f ((S.prime + 1) / 4) | false |
Hacl.Spec.K256.Finv.fst | Hacl.Spec.K256.Finv.finv_is_finv_lemma | val finv_is_finv_lemma: f:S.felem -> Lemma (finv f == S.finv f) | val finv_is_finv_lemma: f:S.felem -> Lemma (finv f == S.finv f) | let finv_is_finv_lemma f =
finv_lemma f;
assert (finv f == M.pow f (S.prime - 2) % S.prime);
M.lemma_pow_mod #S.prime f (S.prime - 2) | {
"file_name": "code/k256/Hacl.Spec.K256.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 42,
"end_line": 243,
"start_col": 0,
"start_line": 240
} | module Hacl.Spec.K256.Finv
open FStar.Mul
module SE = Spec.Exponentiation
module LE = Lib.Exponentiation
module M = Lib.NatMod
module S = Spec.K256
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.prime
let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.felem = {
SE.a_spec = S.felem;
SE.comm_monoid = nat_mod_comm_monoid;
SE.refl = (fun (x:S.felem) -> x);
}
val one_mod : SE.one_st S.felem mk_to_nat_mod_comm_monoid
let one_mod _ = S.one
val mul_mod : SE.mul_st S.felem mk_to_nat_mod_comm_monoid
let mul_mod x y = S.fmul x y
val sqr_mod : SE.sqr_st S.felem mk_to_nat_mod_comm_monoid
let sqr_mod x = S.fmul x x
let mk_nat_mod_concrete_ops : SE.concrete_ops S.felem = {
SE.to = mk_to_nat_mod_comm_monoid;
SE.one = one_mod;
SE.mul = mul_mod;
SE.sqr = sqr_mod;
}
let fsquare_times (a:S.felem) (b:nat) : S.felem =
SE.exp_pow2 mk_nat_mod_concrete_ops a b
val fsquare_times_lemma: a:S.felem -> b:nat ->
Lemma (fsquare_times a b == M.pow a (pow2 b) % S.prime)
let fsquare_times_lemma a b =
SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b;
LE.exp_pow2_lemma nat_mod_comm_monoid a b;
assert (fsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b));
M.lemma_pow_nat_mod_is_pow #S.prime a (pow2 b)
val fexp_223_23: f:S.felem -> tuple2 S.felem S.felem
let fexp_223_23 f =
let x2 = S.fmul (fsquare_times f 1) f in
let x3 = S.fmul (fsquare_times x2 1) f in
let x6 = S.fmul (fsquare_times x3 3) x3 in
let x9 = S.fmul (fsquare_times x6 3) x3 in
let x11 = S.fmul (fsquare_times x9 2) x2 in
let x22 = S.fmul (fsquare_times x11 11) x11 in
let x44 = S.fmul (fsquare_times x22 22) x22 in
let x88 = S.fmul (fsquare_times x44 44) x44 in
let x176 = S.fmul (fsquare_times x88 88) x88 in
let x220 = S.fmul (fsquare_times x176 44) x44 in
let x223 = S.fmul (fsquare_times x220 3) x3 in
let r = S.fmul (fsquare_times x223 23) x22 in
r, x2
(**
The algorithm is taken from
https://briansmith.org/ecc-inversion-addition-chains-01
*)
val finv: f:S.felem -> S.felem
let finv f =
let r, x2 = fexp_223_23 f in
let r = S.fmul (fsquare_times r 5) f in
let r = S.fmul (fsquare_times r 3) x2 in
let r = S.fmul (fsquare_times r 2) f in
r
val fsqrt: f:S.felem -> S.felem
let fsqrt f =
let r, x2 = fexp_223_23 f in
let r = S.fmul (fsquare_times r 6) x2 in
let r = fsquare_times r 2 in
r
val is_fsqrt: f:S.felem -> f2:S.felem -> bool
let is_fsqrt f f2 = S.fmul f f = f2
val lemma_pow_mod_1: f:S.felem -> Lemma (f == M.pow f 1 % S.prime)
let lemma_pow_mod_1 f =
M.lemma_pow1 f;
Math.Lemmas.small_mod f S.prime;
assert_norm (pow2 0 = 1);
assert (f == M.pow f 1 % S.prime)
val lemma_pow_mod_mul: f:S.felem -> a:nat -> b:nat ->
Lemma (S.fmul (M.pow f a % S.prime) (M.pow f b % S.prime) == M.pow f (a + b) % S.prime)
let lemma_pow_mod_mul f a b =
calc (==) {
S.fmul (M.pow f a % S.prime) (M.pow f b % S.prime);
(==) {
Math.Lemmas.lemma_mod_mul_distr_l (M.pow f a) (M.pow f b % S.prime) S.prime;
Math.Lemmas.lemma_mod_mul_distr_r (M.pow f a) (M.pow f b) S.prime }
M.pow f a * M.pow f b % S.prime;
(==) { M.lemma_pow_add f a b }
M.pow f (a + b) % S.prime;
}
val lemma_pow_pow_mod: f:S.felem -> a:nat -> b:nat ->
Lemma (M.pow (M.pow f a % S.prime) b % S.prime == M.pow f (a * b) % S.prime)
let lemma_pow_pow_mod f a b =
calc (==) {
M.pow (M.pow f a % S.prime) b % S.prime;
(==) { M.lemma_pow_mod_base (M.pow f a) b S.prime }
M.pow (M.pow f a) b % S.prime;
(==) { M.lemma_pow_mul f a b }
M.pow f (a * b) % S.prime;
}
val lemma_pow_pow_mod_mul: f:S.felem -> a:nat -> b:nat -> c:nat ->
Lemma (S.fmul (M.pow (M.pow f a % S.prime) b % S.prime) (M.pow f c % S.prime) == M.pow f (a * b + c) % S.prime)
let lemma_pow_pow_mod_mul f a b c =
calc (==) {
S.fmul (M.pow (M.pow f a % S.prime) b % S.prime) (M.pow f c % S.prime);
(==) { lemma_pow_pow_mod f a b }
S.fmul (M.pow f (a * b) % S.prime) (M.pow f c % S.prime);
(==) { lemma_pow_mod_mul f (a * b) c }
M.pow f (a * b + c) % S.prime;
}
val fexp_223_23_lemma: f:S.felem ->
Lemma (let (r, x2) = fexp_223_23 f in
x2 == M.pow f 0x3 % S.prime /\
r == M.pow f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff % S.prime)
let fexp_223_23_lemma f =
let x2 = S.fmul (fsquare_times f 1) f in
fsquare_times_lemma f 1;
assert_norm (pow2 1 = 0x2);
lemma_pow_mod_1 f;
lemma_pow_mod_mul f 0x2 0x1;
assert (x2 == M.pow f 0x3 % S.prime);
let x3 = S.fmul (fsquare_times x2 1) f in
fsquare_times_lemma x2 1;
lemma_pow_mod_1 f;
lemma_pow_pow_mod_mul f 0x3 0x2 0x1;
assert (x3 == M.pow f 0x7 % S.prime);
let x6 = S.fmul (fsquare_times x3 3) x3 in
fsquare_times_lemma x3 3;
assert_norm (pow2 3 = 8);
lemma_pow_pow_mod_mul f 0x7 0x8 0x7;
assert (x6 == M.pow f 0x3f % S.prime);
let x9 = S.fmul (fsquare_times x6 3) x3 in
fsquare_times_lemma x6 3;
lemma_pow_pow_mod_mul f 0x3f 0x8 0x7;
assert (x9 == M.pow f 0x1ff % S.prime);
let x11 = S.fmul (fsquare_times x9 2) x2 in
fsquare_times_lemma x9 2;
assert_norm (pow2 2 = 0x4);
lemma_pow_pow_mod_mul f 0x1ff 0x4 0x3;
assert (x11 == M.pow f 0x7ff % S.prime);
let x22 = S.fmul (fsquare_times x11 11) x11 in
fsquare_times_lemma x11 11;
assert_norm (pow2 11 = 0x800);
lemma_pow_pow_mod_mul f 0x7ff 0x800 0x7ff;
assert (x22 == M.pow f 0x3fffff % S.prime);
let x44 = S.fmul (fsquare_times x22 22) x22 in
fsquare_times_lemma x22 22;
assert_norm (pow2 22 = 0x400000);
lemma_pow_pow_mod_mul f 0x3fffff 0x400000 0x3fffff;
assert (x44 == M.pow f 0xfffffffffff % S.prime);
let x88 = S.fmul (fsquare_times x44 44) x44 in
fsquare_times_lemma x44 44;
assert_norm (pow2 44 = 0x100000000000);
lemma_pow_pow_mod_mul f 0xfffffffffff 0x100000000000 0xfffffffffff;
assert (x88 == M.pow f 0xffffffffffffffffffffff % S.prime);
let x176 = S.fmul (fsquare_times x88 88) x88 in
fsquare_times_lemma x88 88;
assert_norm (pow2 88 = 0x10000000000000000000000);
lemma_pow_pow_mod_mul f 0xffffffffffffffffffffff 0x10000000000000000000000 0xffffffffffffffffffffff;
assert (x176 == M.pow f 0xffffffffffffffffffffffffffffffffffffffffffff % S.prime);
let x220 = S.fmul (fsquare_times x176 44) x44 in
fsquare_times_lemma x176 44;
lemma_pow_pow_mod_mul f 0xffffffffffffffffffffffffffffffffffffffffffff 0x100000000000 0xfffffffffff;
assert (x220 == M.pow f 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffff % S.prime);
let x223 = S.fmul (fsquare_times x220 3) x3 in
fsquare_times_lemma x220 3;
lemma_pow_pow_mod_mul f 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffff 0x8 0x7;
assert (x223 == M.pow f 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff % S.prime);
let r0 = S.fmul (fsquare_times x223 23) x22 in
fsquare_times_lemma x223 23;
assert_norm (pow2 23 = 0x800000);
lemma_pow_pow_mod_mul f 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff 0x800000 0x3fffff;
assert (r0 == M.pow f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff % S.prime)
// S.prime - 2 = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2d
val finv_lemma: f:S.felem -> Lemma (finv f == M.pow f (S.prime - 2) % S.prime)
let finv_lemma f =
lemma_pow_mod_1 f;
let r0, x2 = fexp_223_23 f in
fexp_223_23_lemma f;
let r1 = S.fmul (fsquare_times r0 5) f in
fsquare_times_lemma r0 5;
assert_norm (pow2 5 = 0x20);
lemma_pow_pow_mod_mul f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff 0x20 0x1;
assert (r1 == M.pow f 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff7ffffe1 % S.prime);
let r2 = S.fmul (fsquare_times r1 3) x2 in
fsquare_times_lemma r1 3;
lemma_pow_pow_mod_mul f 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff7ffffe1 0x8 0x3;
assert (r2 == M.pow f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff0b % S.prime);
let r = S.fmul (fsquare_times r2 2) f in
fsquare_times_lemma r2 2;
lemma_pow_pow_mod_mul f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff0b 0x4 0x1;
assert (r == M.pow f 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2d % S.prime) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Spec.K256.PointOps.felem
-> FStar.Pervasives.Lemma (ensures Hacl.Spec.K256.Finv.finv f == Spec.K256.PointOps.finv f) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.K256.PointOps.felem",
"Lib.NatMod.lemma_pow_mod",
"Spec.K256.PointOps.prime",
"Prims.op_Subtraction",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Hacl.Spec.K256.Finv.finv",
"Prims.op_Modulus",
"Lib.NatMod.pow",
"Hacl.Spec.K256.Finv.finv_lemma"
] | [] | true | false | true | false | false | let finv_is_finv_lemma f =
| finv_lemma f;
assert (finv f == M.pow f (S.prime - 2) % S.prime);
M.lemma_pow_mod #S.prime f (S.prime - 2) | false |
Hacl.Spec.K256.Finv.fst | Hacl.Spec.K256.Finv.fsqrt_lemma | val fsqrt_lemma: f:S.felem -> Lemma (fsqrt f == M.pow f ((S.prime + 1) / 4) % S.prime) | val fsqrt_lemma: f:S.felem -> Lemma (fsqrt f == M.pow f ((S.prime + 1) / 4) % S.prime) | let fsqrt_lemma f =
lemma_pow_mod_1 f;
let r0, x2 = fexp_223_23 f in
fexp_223_23_lemma f;
let r1 = S.fmul (fsquare_times r0 6) x2 in
fsquare_times_lemma r0 6;
assert_norm (pow2 6 = 0x40);
lemma_pow_pow_mod_mul f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff 0x40 0x3;
assert (r1 == M.pow f 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc3 % S.prime);
let r = fsquare_times r1 2 in
fsquare_times_lemma r1 2;
assert_norm (pow2 2 = 4);
lemma_pow_pow_mod f 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc3 0x4;
assert (r == M.pow f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff0c % S.prime);
assert_norm (0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff0c == (S.prime + 1) / 4) | {
"file_name": "code/k256/Hacl.Spec.K256.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 103,
"end_line": 264,
"start_col": 0,
"start_line": 247
} | module Hacl.Spec.K256.Finv
open FStar.Mul
module SE = Spec.Exponentiation
module LE = Lib.Exponentiation
module M = Lib.NatMod
module S = Spec.K256
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.prime
let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.felem = {
SE.a_spec = S.felem;
SE.comm_monoid = nat_mod_comm_monoid;
SE.refl = (fun (x:S.felem) -> x);
}
val one_mod : SE.one_st S.felem mk_to_nat_mod_comm_monoid
let one_mod _ = S.one
val mul_mod : SE.mul_st S.felem mk_to_nat_mod_comm_monoid
let mul_mod x y = S.fmul x y
val sqr_mod : SE.sqr_st S.felem mk_to_nat_mod_comm_monoid
let sqr_mod x = S.fmul x x
let mk_nat_mod_concrete_ops : SE.concrete_ops S.felem = {
SE.to = mk_to_nat_mod_comm_monoid;
SE.one = one_mod;
SE.mul = mul_mod;
SE.sqr = sqr_mod;
}
let fsquare_times (a:S.felem) (b:nat) : S.felem =
SE.exp_pow2 mk_nat_mod_concrete_ops a b
val fsquare_times_lemma: a:S.felem -> b:nat ->
Lemma (fsquare_times a b == M.pow a (pow2 b) % S.prime)
let fsquare_times_lemma a b =
SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b;
LE.exp_pow2_lemma nat_mod_comm_monoid a b;
assert (fsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b));
M.lemma_pow_nat_mod_is_pow #S.prime a (pow2 b)
val fexp_223_23: f:S.felem -> tuple2 S.felem S.felem
let fexp_223_23 f =
let x2 = S.fmul (fsquare_times f 1) f in
let x3 = S.fmul (fsquare_times x2 1) f in
let x6 = S.fmul (fsquare_times x3 3) x3 in
let x9 = S.fmul (fsquare_times x6 3) x3 in
let x11 = S.fmul (fsquare_times x9 2) x2 in
let x22 = S.fmul (fsquare_times x11 11) x11 in
let x44 = S.fmul (fsquare_times x22 22) x22 in
let x88 = S.fmul (fsquare_times x44 44) x44 in
let x176 = S.fmul (fsquare_times x88 88) x88 in
let x220 = S.fmul (fsquare_times x176 44) x44 in
let x223 = S.fmul (fsquare_times x220 3) x3 in
let r = S.fmul (fsquare_times x223 23) x22 in
r, x2
(**
The algorithm is taken from
https://briansmith.org/ecc-inversion-addition-chains-01
*)
val finv: f:S.felem -> S.felem
let finv f =
let r, x2 = fexp_223_23 f in
let r = S.fmul (fsquare_times r 5) f in
let r = S.fmul (fsquare_times r 3) x2 in
let r = S.fmul (fsquare_times r 2) f in
r
val fsqrt: f:S.felem -> S.felem
let fsqrt f =
let r, x2 = fexp_223_23 f in
let r = S.fmul (fsquare_times r 6) x2 in
let r = fsquare_times r 2 in
r
val is_fsqrt: f:S.felem -> f2:S.felem -> bool
let is_fsqrt f f2 = S.fmul f f = f2
val lemma_pow_mod_1: f:S.felem -> Lemma (f == M.pow f 1 % S.prime)
let lemma_pow_mod_1 f =
M.lemma_pow1 f;
Math.Lemmas.small_mod f S.prime;
assert_norm (pow2 0 = 1);
assert (f == M.pow f 1 % S.prime)
val lemma_pow_mod_mul: f:S.felem -> a:nat -> b:nat ->
Lemma (S.fmul (M.pow f a % S.prime) (M.pow f b % S.prime) == M.pow f (a + b) % S.prime)
let lemma_pow_mod_mul f a b =
calc (==) {
S.fmul (M.pow f a % S.prime) (M.pow f b % S.prime);
(==) {
Math.Lemmas.lemma_mod_mul_distr_l (M.pow f a) (M.pow f b % S.prime) S.prime;
Math.Lemmas.lemma_mod_mul_distr_r (M.pow f a) (M.pow f b) S.prime }
M.pow f a * M.pow f b % S.prime;
(==) { M.lemma_pow_add f a b }
M.pow f (a + b) % S.prime;
}
val lemma_pow_pow_mod: f:S.felem -> a:nat -> b:nat ->
Lemma (M.pow (M.pow f a % S.prime) b % S.prime == M.pow f (a * b) % S.prime)
let lemma_pow_pow_mod f a b =
calc (==) {
M.pow (M.pow f a % S.prime) b % S.prime;
(==) { M.lemma_pow_mod_base (M.pow f a) b S.prime }
M.pow (M.pow f a) b % S.prime;
(==) { M.lemma_pow_mul f a b }
M.pow f (a * b) % S.prime;
}
val lemma_pow_pow_mod_mul: f:S.felem -> a:nat -> b:nat -> c:nat ->
Lemma (S.fmul (M.pow (M.pow f a % S.prime) b % S.prime) (M.pow f c % S.prime) == M.pow f (a * b + c) % S.prime)
let lemma_pow_pow_mod_mul f a b c =
calc (==) {
S.fmul (M.pow (M.pow f a % S.prime) b % S.prime) (M.pow f c % S.prime);
(==) { lemma_pow_pow_mod f a b }
S.fmul (M.pow f (a * b) % S.prime) (M.pow f c % S.prime);
(==) { lemma_pow_mod_mul f (a * b) c }
M.pow f (a * b + c) % S.prime;
}
val fexp_223_23_lemma: f:S.felem ->
Lemma (let (r, x2) = fexp_223_23 f in
x2 == M.pow f 0x3 % S.prime /\
r == M.pow f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff % S.prime)
let fexp_223_23_lemma f =
let x2 = S.fmul (fsquare_times f 1) f in
fsquare_times_lemma f 1;
assert_norm (pow2 1 = 0x2);
lemma_pow_mod_1 f;
lemma_pow_mod_mul f 0x2 0x1;
assert (x2 == M.pow f 0x3 % S.prime);
let x3 = S.fmul (fsquare_times x2 1) f in
fsquare_times_lemma x2 1;
lemma_pow_mod_1 f;
lemma_pow_pow_mod_mul f 0x3 0x2 0x1;
assert (x3 == M.pow f 0x7 % S.prime);
let x6 = S.fmul (fsquare_times x3 3) x3 in
fsquare_times_lemma x3 3;
assert_norm (pow2 3 = 8);
lemma_pow_pow_mod_mul f 0x7 0x8 0x7;
assert (x6 == M.pow f 0x3f % S.prime);
let x9 = S.fmul (fsquare_times x6 3) x3 in
fsquare_times_lemma x6 3;
lemma_pow_pow_mod_mul f 0x3f 0x8 0x7;
assert (x9 == M.pow f 0x1ff % S.prime);
let x11 = S.fmul (fsquare_times x9 2) x2 in
fsquare_times_lemma x9 2;
assert_norm (pow2 2 = 0x4);
lemma_pow_pow_mod_mul f 0x1ff 0x4 0x3;
assert (x11 == M.pow f 0x7ff % S.prime);
let x22 = S.fmul (fsquare_times x11 11) x11 in
fsquare_times_lemma x11 11;
assert_norm (pow2 11 = 0x800);
lemma_pow_pow_mod_mul f 0x7ff 0x800 0x7ff;
assert (x22 == M.pow f 0x3fffff % S.prime);
let x44 = S.fmul (fsquare_times x22 22) x22 in
fsquare_times_lemma x22 22;
assert_norm (pow2 22 = 0x400000);
lemma_pow_pow_mod_mul f 0x3fffff 0x400000 0x3fffff;
assert (x44 == M.pow f 0xfffffffffff % S.prime);
let x88 = S.fmul (fsquare_times x44 44) x44 in
fsquare_times_lemma x44 44;
assert_norm (pow2 44 = 0x100000000000);
lemma_pow_pow_mod_mul f 0xfffffffffff 0x100000000000 0xfffffffffff;
assert (x88 == M.pow f 0xffffffffffffffffffffff % S.prime);
let x176 = S.fmul (fsquare_times x88 88) x88 in
fsquare_times_lemma x88 88;
assert_norm (pow2 88 = 0x10000000000000000000000);
lemma_pow_pow_mod_mul f 0xffffffffffffffffffffff 0x10000000000000000000000 0xffffffffffffffffffffff;
assert (x176 == M.pow f 0xffffffffffffffffffffffffffffffffffffffffffff % S.prime);
let x220 = S.fmul (fsquare_times x176 44) x44 in
fsquare_times_lemma x176 44;
lemma_pow_pow_mod_mul f 0xffffffffffffffffffffffffffffffffffffffffffff 0x100000000000 0xfffffffffff;
assert (x220 == M.pow f 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffff % S.prime);
let x223 = S.fmul (fsquare_times x220 3) x3 in
fsquare_times_lemma x220 3;
lemma_pow_pow_mod_mul f 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffff 0x8 0x7;
assert (x223 == M.pow f 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff % S.prime);
let r0 = S.fmul (fsquare_times x223 23) x22 in
fsquare_times_lemma x223 23;
assert_norm (pow2 23 = 0x800000);
lemma_pow_pow_mod_mul f 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff 0x800000 0x3fffff;
assert (r0 == M.pow f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff % S.prime)
// S.prime - 2 = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2d
val finv_lemma: f:S.felem -> Lemma (finv f == M.pow f (S.prime - 2) % S.prime)
let finv_lemma f =
lemma_pow_mod_1 f;
let r0, x2 = fexp_223_23 f in
fexp_223_23_lemma f;
let r1 = S.fmul (fsquare_times r0 5) f in
fsquare_times_lemma r0 5;
assert_norm (pow2 5 = 0x20);
lemma_pow_pow_mod_mul f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff 0x20 0x1;
assert (r1 == M.pow f 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff7ffffe1 % S.prime);
let r2 = S.fmul (fsquare_times r1 3) x2 in
fsquare_times_lemma r1 3;
lemma_pow_pow_mod_mul f 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff7ffffe1 0x8 0x3;
assert (r2 == M.pow f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff0b % S.prime);
let r = S.fmul (fsquare_times r2 2) f in
fsquare_times_lemma r2 2;
lemma_pow_pow_mod_mul f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff0b 0x4 0x1;
assert (r == M.pow f 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2d % S.prime)
val finv_is_finv_lemma: f:S.felem -> Lemma (finv f == S.finv f)
let finv_is_finv_lemma f =
finv_lemma f;
assert (finv f == M.pow f (S.prime - 2) % S.prime);
M.lemma_pow_mod #S.prime f (S.prime - 2) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Spec.K256.PointOps.felem
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.K256.Finv.fsqrt f ==
Lib.NatMod.pow f ((Spec.K256.PointOps.prime + 1) / 4) % Spec.K256.PointOps.prime) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.K256.PointOps.felem",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"Prims.op_Division",
"Prims.op_Addition",
"Spec.K256.PointOps.prime",
"Prims.unit",
"Prims._assert",
"Prims.op_Modulus",
"Lib.NatMod.pow",
"Hacl.Spec.K256.Finv.lemma_pow_pow_mod",
"Prims.b2t",
"Prims.op_Equality",
"Prims.pow2",
"Hacl.Spec.K256.Finv.fsquare_times_lemma",
"Hacl.Spec.K256.Finv.fsquare_times",
"Hacl.Spec.K256.Finv.lemma_pow_pow_mod_mul",
"Spec.K256.PointOps.fmul",
"Hacl.Spec.K256.Finv.fexp_223_23_lemma",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.K256.Finv.fexp_223_23",
"Hacl.Spec.K256.Finv.lemma_pow_mod_1"
] | [] | false | false | true | false | false | let fsqrt_lemma f =
| lemma_pow_mod_1 f;
let r0, x2 = fexp_223_23 f in
fexp_223_23_lemma f;
let r1 = S.fmul (fsquare_times r0 6) x2 in
fsquare_times_lemma r0 6;
assert_norm (pow2 6 = 0x40);
lemma_pow_pow_mod_mul f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff 0x40 0x3;
assert (r1 == M.pow f 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc3 % S.prime);
let r = fsquare_times r1 2 in
fsquare_times_lemma r1 2;
assert_norm (pow2 2 = 4);
lemma_pow_pow_mod f 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc3 0x4;
assert (r == M.pow f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff0c % S.prime);
assert_norm (0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff0c == (S.prime + 1) / 4
) | false |
Hacl.Spec.K256.Finv.fst | Hacl.Spec.K256.Finv.finv_lemma | val finv_lemma: f:S.felem -> Lemma (finv f == M.pow f (S.prime - 2) % S.prime) | val finv_lemma: f:S.felem -> Lemma (finv f == M.pow f (S.prime - 2) % S.prime) | let finv_lemma f =
lemma_pow_mod_1 f;
let r0, x2 = fexp_223_23 f in
fexp_223_23_lemma f;
let r1 = S.fmul (fsquare_times r0 5) f in
fsquare_times_lemma r0 5;
assert_norm (pow2 5 = 0x20);
lemma_pow_pow_mod_mul f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff 0x20 0x1;
assert (r1 == M.pow f 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff7ffffe1 % S.prime);
let r2 = S.fmul (fsquare_times r1 3) x2 in
fsquare_times_lemma r1 3;
lemma_pow_pow_mod_mul f 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff7ffffe1 0x8 0x3;
assert (r2 == M.pow f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff0b % S.prime);
let r = S.fmul (fsquare_times r2 2) f in
fsquare_times_lemma r2 2;
lemma_pow_pow_mod_mul f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff0b 0x4 0x1;
assert (r == M.pow f 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2d % S.prime) | {
"file_name": "code/k256/Hacl.Spec.K256.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 100,
"end_line": 236,
"start_col": 0,
"start_line": 216
} | module Hacl.Spec.K256.Finv
open FStar.Mul
module SE = Spec.Exponentiation
module LE = Lib.Exponentiation
module M = Lib.NatMod
module S = Spec.K256
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.prime
let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.felem = {
SE.a_spec = S.felem;
SE.comm_monoid = nat_mod_comm_monoid;
SE.refl = (fun (x:S.felem) -> x);
}
val one_mod : SE.one_st S.felem mk_to_nat_mod_comm_monoid
let one_mod _ = S.one
val mul_mod : SE.mul_st S.felem mk_to_nat_mod_comm_monoid
let mul_mod x y = S.fmul x y
val sqr_mod : SE.sqr_st S.felem mk_to_nat_mod_comm_monoid
let sqr_mod x = S.fmul x x
let mk_nat_mod_concrete_ops : SE.concrete_ops S.felem = {
SE.to = mk_to_nat_mod_comm_monoid;
SE.one = one_mod;
SE.mul = mul_mod;
SE.sqr = sqr_mod;
}
let fsquare_times (a:S.felem) (b:nat) : S.felem =
SE.exp_pow2 mk_nat_mod_concrete_ops a b
val fsquare_times_lemma: a:S.felem -> b:nat ->
Lemma (fsquare_times a b == M.pow a (pow2 b) % S.prime)
let fsquare_times_lemma a b =
SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b;
LE.exp_pow2_lemma nat_mod_comm_monoid a b;
assert (fsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b));
M.lemma_pow_nat_mod_is_pow #S.prime a (pow2 b)
val fexp_223_23: f:S.felem -> tuple2 S.felem S.felem
let fexp_223_23 f =
let x2 = S.fmul (fsquare_times f 1) f in
let x3 = S.fmul (fsquare_times x2 1) f in
let x6 = S.fmul (fsquare_times x3 3) x3 in
let x9 = S.fmul (fsquare_times x6 3) x3 in
let x11 = S.fmul (fsquare_times x9 2) x2 in
let x22 = S.fmul (fsquare_times x11 11) x11 in
let x44 = S.fmul (fsquare_times x22 22) x22 in
let x88 = S.fmul (fsquare_times x44 44) x44 in
let x176 = S.fmul (fsquare_times x88 88) x88 in
let x220 = S.fmul (fsquare_times x176 44) x44 in
let x223 = S.fmul (fsquare_times x220 3) x3 in
let r = S.fmul (fsquare_times x223 23) x22 in
r, x2
(**
The algorithm is taken from
https://briansmith.org/ecc-inversion-addition-chains-01
*)
val finv: f:S.felem -> S.felem
let finv f =
let r, x2 = fexp_223_23 f in
let r = S.fmul (fsquare_times r 5) f in
let r = S.fmul (fsquare_times r 3) x2 in
let r = S.fmul (fsquare_times r 2) f in
r
val fsqrt: f:S.felem -> S.felem
let fsqrt f =
let r, x2 = fexp_223_23 f in
let r = S.fmul (fsquare_times r 6) x2 in
let r = fsquare_times r 2 in
r
val is_fsqrt: f:S.felem -> f2:S.felem -> bool
let is_fsqrt f f2 = S.fmul f f = f2
val lemma_pow_mod_1: f:S.felem -> Lemma (f == M.pow f 1 % S.prime)
let lemma_pow_mod_1 f =
M.lemma_pow1 f;
Math.Lemmas.small_mod f S.prime;
assert_norm (pow2 0 = 1);
assert (f == M.pow f 1 % S.prime)
val lemma_pow_mod_mul: f:S.felem -> a:nat -> b:nat ->
Lemma (S.fmul (M.pow f a % S.prime) (M.pow f b % S.prime) == M.pow f (a + b) % S.prime)
let lemma_pow_mod_mul f a b =
calc (==) {
S.fmul (M.pow f a % S.prime) (M.pow f b % S.prime);
(==) {
Math.Lemmas.lemma_mod_mul_distr_l (M.pow f a) (M.pow f b % S.prime) S.prime;
Math.Lemmas.lemma_mod_mul_distr_r (M.pow f a) (M.pow f b) S.prime }
M.pow f a * M.pow f b % S.prime;
(==) { M.lemma_pow_add f a b }
M.pow f (a + b) % S.prime;
}
val lemma_pow_pow_mod: f:S.felem -> a:nat -> b:nat ->
Lemma (M.pow (M.pow f a % S.prime) b % S.prime == M.pow f (a * b) % S.prime)
let lemma_pow_pow_mod f a b =
calc (==) {
M.pow (M.pow f a % S.prime) b % S.prime;
(==) { M.lemma_pow_mod_base (M.pow f a) b S.prime }
M.pow (M.pow f a) b % S.prime;
(==) { M.lemma_pow_mul f a b }
M.pow f (a * b) % S.prime;
}
val lemma_pow_pow_mod_mul: f:S.felem -> a:nat -> b:nat -> c:nat ->
Lemma (S.fmul (M.pow (M.pow f a % S.prime) b % S.prime) (M.pow f c % S.prime) == M.pow f (a * b + c) % S.prime)
let lemma_pow_pow_mod_mul f a b c =
calc (==) {
S.fmul (M.pow (M.pow f a % S.prime) b % S.prime) (M.pow f c % S.prime);
(==) { lemma_pow_pow_mod f a b }
S.fmul (M.pow f (a * b) % S.prime) (M.pow f c % S.prime);
(==) { lemma_pow_mod_mul f (a * b) c }
M.pow f (a * b + c) % S.prime;
}
val fexp_223_23_lemma: f:S.felem ->
Lemma (let (r, x2) = fexp_223_23 f in
x2 == M.pow f 0x3 % S.prime /\
r == M.pow f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff % S.prime)
let fexp_223_23_lemma f =
let x2 = S.fmul (fsquare_times f 1) f in
fsquare_times_lemma f 1;
assert_norm (pow2 1 = 0x2);
lemma_pow_mod_1 f;
lemma_pow_mod_mul f 0x2 0x1;
assert (x2 == M.pow f 0x3 % S.prime);
let x3 = S.fmul (fsquare_times x2 1) f in
fsquare_times_lemma x2 1;
lemma_pow_mod_1 f;
lemma_pow_pow_mod_mul f 0x3 0x2 0x1;
assert (x3 == M.pow f 0x7 % S.prime);
let x6 = S.fmul (fsquare_times x3 3) x3 in
fsquare_times_lemma x3 3;
assert_norm (pow2 3 = 8);
lemma_pow_pow_mod_mul f 0x7 0x8 0x7;
assert (x6 == M.pow f 0x3f % S.prime);
let x9 = S.fmul (fsquare_times x6 3) x3 in
fsquare_times_lemma x6 3;
lemma_pow_pow_mod_mul f 0x3f 0x8 0x7;
assert (x9 == M.pow f 0x1ff % S.prime);
let x11 = S.fmul (fsquare_times x9 2) x2 in
fsquare_times_lemma x9 2;
assert_norm (pow2 2 = 0x4);
lemma_pow_pow_mod_mul f 0x1ff 0x4 0x3;
assert (x11 == M.pow f 0x7ff % S.prime);
let x22 = S.fmul (fsquare_times x11 11) x11 in
fsquare_times_lemma x11 11;
assert_norm (pow2 11 = 0x800);
lemma_pow_pow_mod_mul f 0x7ff 0x800 0x7ff;
assert (x22 == M.pow f 0x3fffff % S.prime);
let x44 = S.fmul (fsquare_times x22 22) x22 in
fsquare_times_lemma x22 22;
assert_norm (pow2 22 = 0x400000);
lemma_pow_pow_mod_mul f 0x3fffff 0x400000 0x3fffff;
assert (x44 == M.pow f 0xfffffffffff % S.prime);
let x88 = S.fmul (fsquare_times x44 44) x44 in
fsquare_times_lemma x44 44;
assert_norm (pow2 44 = 0x100000000000);
lemma_pow_pow_mod_mul f 0xfffffffffff 0x100000000000 0xfffffffffff;
assert (x88 == M.pow f 0xffffffffffffffffffffff % S.prime);
let x176 = S.fmul (fsquare_times x88 88) x88 in
fsquare_times_lemma x88 88;
assert_norm (pow2 88 = 0x10000000000000000000000);
lemma_pow_pow_mod_mul f 0xffffffffffffffffffffff 0x10000000000000000000000 0xffffffffffffffffffffff;
assert (x176 == M.pow f 0xffffffffffffffffffffffffffffffffffffffffffff % S.prime);
let x220 = S.fmul (fsquare_times x176 44) x44 in
fsquare_times_lemma x176 44;
lemma_pow_pow_mod_mul f 0xffffffffffffffffffffffffffffffffffffffffffff 0x100000000000 0xfffffffffff;
assert (x220 == M.pow f 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffff % S.prime);
let x223 = S.fmul (fsquare_times x220 3) x3 in
fsquare_times_lemma x220 3;
lemma_pow_pow_mod_mul f 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffff 0x8 0x7;
assert (x223 == M.pow f 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff % S.prime);
let r0 = S.fmul (fsquare_times x223 23) x22 in
fsquare_times_lemma x223 23;
assert_norm (pow2 23 = 0x800000);
lemma_pow_pow_mod_mul f 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff 0x800000 0x3fffff;
assert (r0 == M.pow f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff % S.prime)
// S.prime - 2 = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2d | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Spec.K256.PointOps.felem
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.K256.Finv.finv f ==
Lib.NatMod.pow f (Spec.K256.PointOps.prime - 2) % Spec.K256.PointOps.prime) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.K256.PointOps.felem",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"Lib.NatMod.pow",
"Spec.K256.PointOps.prime",
"Prims.unit",
"Hacl.Spec.K256.Finv.lemma_pow_pow_mod_mul",
"Hacl.Spec.K256.Finv.fsquare_times_lemma",
"Spec.K256.PointOps.fmul",
"Hacl.Spec.K256.Finv.fsquare_times",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality",
"Prims.pow2",
"Hacl.Spec.K256.Finv.fexp_223_23_lemma",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.K256.Finv.fexp_223_23",
"Hacl.Spec.K256.Finv.lemma_pow_mod_1"
] | [] | false | false | true | false | false | let finv_lemma f =
| lemma_pow_mod_1 f;
let r0, x2 = fexp_223_23 f in
fexp_223_23_lemma f;
let r1 = S.fmul (fsquare_times r0 5) f in
fsquare_times_lemma r0 5;
assert_norm (pow2 5 = 0x20);
lemma_pow_pow_mod_mul f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff 0x20 0x1;
assert (r1 == M.pow f 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff7ffffe1 % S.prime);
let r2 = S.fmul (fsquare_times r1 3) x2 in
fsquare_times_lemma r1 3;
lemma_pow_pow_mod_mul f 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff7ffffe1 0x8 0x3;
assert (r2 == M.pow f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff0b % S.prime);
let r = S.fmul (fsquare_times r2 2) f in
fsquare_times_lemma r2 2;
lemma_pow_pow_mod_mul f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff0b 0x4 0x1;
assert (r == M.pow f 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2d % S.prime) | false |
Hacl.Spec.K256.Finv.fst | Hacl.Spec.K256.Finv.lemma_pow_pow_mod | val lemma_pow_pow_mod: f:S.felem -> a:nat -> b:nat ->
Lemma (M.pow (M.pow f a % S.prime) b % S.prime == M.pow f (a * b) % S.prime) | val lemma_pow_pow_mod: f:S.felem -> a:nat -> b:nat ->
Lemma (M.pow (M.pow f a % S.prime) b % S.prime == M.pow f (a * b) % S.prime) | let lemma_pow_pow_mod f a b =
calc (==) {
M.pow (M.pow f a % S.prime) b % S.prime;
(==) { M.lemma_pow_mod_base (M.pow f a) b S.prime }
M.pow (M.pow f a) b % S.prime;
(==) { M.lemma_pow_mul f a b }
M.pow f (a * b) % S.prime;
} | {
"file_name": "code/k256/Hacl.Spec.K256.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 122,
"start_col": 0,
"start_line": 115
} | module Hacl.Spec.K256.Finv
open FStar.Mul
module SE = Spec.Exponentiation
module LE = Lib.Exponentiation
module M = Lib.NatMod
module S = Spec.K256
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.prime
let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.felem = {
SE.a_spec = S.felem;
SE.comm_monoid = nat_mod_comm_monoid;
SE.refl = (fun (x:S.felem) -> x);
}
val one_mod : SE.one_st S.felem mk_to_nat_mod_comm_monoid
let one_mod _ = S.one
val mul_mod : SE.mul_st S.felem mk_to_nat_mod_comm_monoid
let mul_mod x y = S.fmul x y
val sqr_mod : SE.sqr_st S.felem mk_to_nat_mod_comm_monoid
let sqr_mod x = S.fmul x x
let mk_nat_mod_concrete_ops : SE.concrete_ops S.felem = {
SE.to = mk_to_nat_mod_comm_monoid;
SE.one = one_mod;
SE.mul = mul_mod;
SE.sqr = sqr_mod;
}
let fsquare_times (a:S.felem) (b:nat) : S.felem =
SE.exp_pow2 mk_nat_mod_concrete_ops a b
val fsquare_times_lemma: a:S.felem -> b:nat ->
Lemma (fsquare_times a b == M.pow a (pow2 b) % S.prime)
let fsquare_times_lemma a b =
SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b;
LE.exp_pow2_lemma nat_mod_comm_monoid a b;
assert (fsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b));
M.lemma_pow_nat_mod_is_pow #S.prime a (pow2 b)
val fexp_223_23: f:S.felem -> tuple2 S.felem S.felem
let fexp_223_23 f =
let x2 = S.fmul (fsquare_times f 1) f in
let x3 = S.fmul (fsquare_times x2 1) f in
let x6 = S.fmul (fsquare_times x3 3) x3 in
let x9 = S.fmul (fsquare_times x6 3) x3 in
let x11 = S.fmul (fsquare_times x9 2) x2 in
let x22 = S.fmul (fsquare_times x11 11) x11 in
let x44 = S.fmul (fsquare_times x22 22) x22 in
let x88 = S.fmul (fsquare_times x44 44) x44 in
let x176 = S.fmul (fsquare_times x88 88) x88 in
let x220 = S.fmul (fsquare_times x176 44) x44 in
let x223 = S.fmul (fsquare_times x220 3) x3 in
let r = S.fmul (fsquare_times x223 23) x22 in
r, x2
(**
The algorithm is taken from
https://briansmith.org/ecc-inversion-addition-chains-01
*)
val finv: f:S.felem -> S.felem
let finv f =
let r, x2 = fexp_223_23 f in
let r = S.fmul (fsquare_times r 5) f in
let r = S.fmul (fsquare_times r 3) x2 in
let r = S.fmul (fsquare_times r 2) f in
r
val fsqrt: f:S.felem -> S.felem
let fsqrt f =
let r, x2 = fexp_223_23 f in
let r = S.fmul (fsquare_times r 6) x2 in
let r = fsquare_times r 2 in
r
val is_fsqrt: f:S.felem -> f2:S.felem -> bool
let is_fsqrt f f2 = S.fmul f f = f2
val lemma_pow_mod_1: f:S.felem -> Lemma (f == M.pow f 1 % S.prime)
let lemma_pow_mod_1 f =
M.lemma_pow1 f;
Math.Lemmas.small_mod f S.prime;
assert_norm (pow2 0 = 1);
assert (f == M.pow f 1 % S.prime)
val lemma_pow_mod_mul: f:S.felem -> a:nat -> b:nat ->
Lemma (S.fmul (M.pow f a % S.prime) (M.pow f b % S.prime) == M.pow f (a + b) % S.prime)
let lemma_pow_mod_mul f a b =
calc (==) {
S.fmul (M.pow f a % S.prime) (M.pow f b % S.prime);
(==) {
Math.Lemmas.lemma_mod_mul_distr_l (M.pow f a) (M.pow f b % S.prime) S.prime;
Math.Lemmas.lemma_mod_mul_distr_r (M.pow f a) (M.pow f b) S.prime }
M.pow f a * M.pow f b % S.prime;
(==) { M.lemma_pow_add f a b }
M.pow f (a + b) % S.prime;
}
val lemma_pow_pow_mod: f:S.felem -> a:nat -> b:nat -> | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Spec.K256.PointOps.felem -> a: Prims.nat -> b: Prims.nat
-> FStar.Pervasives.Lemma
(ensures
Lib.NatMod.pow (Lib.NatMod.pow f a % Spec.K256.PointOps.prime) b % Spec.K256.PointOps.prime ==
Lib.NatMod.pow f (a * b) % Spec.K256.PointOps.prime) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.K256.PointOps.felem",
"Prims.nat",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Modulus",
"Lib.NatMod.pow",
"Spec.K256.PointOps.prime",
"FStar.Mul.op_Star",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Lib.NatMod.lemma_pow_mod_base",
"Prims.squash",
"Lib.NatMod.lemma_pow_mul"
] | [] | false | false | true | false | false | let lemma_pow_pow_mod f a b =
| calc ( == ) {
M.pow (M.pow f a % S.prime) b % S.prime;
( == ) { M.lemma_pow_mod_base (M.pow f a) b S.prime }
M.pow (M.pow f a) b % S.prime;
( == ) { M.lemma_pow_mul f a b }
M.pow f (a * b) % S.prime;
} | false |
Hacl.Spec.K256.Finv.fst | Hacl.Spec.K256.Finv.lemma_pow_mod_mul | val lemma_pow_mod_mul: f:S.felem -> a:nat -> b:nat ->
Lemma (S.fmul (M.pow f a % S.prime) (M.pow f b % S.prime) == M.pow f (a + b) % S.prime) | val lemma_pow_mod_mul: f:S.felem -> a:nat -> b:nat ->
Lemma (S.fmul (M.pow f a % S.prime) (M.pow f b % S.prime) == M.pow f (a + b) % S.prime) | let lemma_pow_mod_mul f a b =
calc (==) {
S.fmul (M.pow f a % S.prime) (M.pow f b % S.prime);
(==) {
Math.Lemmas.lemma_mod_mul_distr_l (M.pow f a) (M.pow f b % S.prime) S.prime;
Math.Lemmas.lemma_mod_mul_distr_r (M.pow f a) (M.pow f b) S.prime }
M.pow f a * M.pow f b % S.prime;
(==) { M.lemma_pow_add f a b }
M.pow f (a + b) % S.prime;
} | {
"file_name": "code/k256/Hacl.Spec.K256.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 110,
"start_col": 0,
"start_line": 101
} | module Hacl.Spec.K256.Finv
open FStar.Mul
module SE = Spec.Exponentiation
module LE = Lib.Exponentiation
module M = Lib.NatMod
module S = Spec.K256
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.prime
let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.felem = {
SE.a_spec = S.felem;
SE.comm_monoid = nat_mod_comm_monoid;
SE.refl = (fun (x:S.felem) -> x);
}
val one_mod : SE.one_st S.felem mk_to_nat_mod_comm_monoid
let one_mod _ = S.one
val mul_mod : SE.mul_st S.felem mk_to_nat_mod_comm_monoid
let mul_mod x y = S.fmul x y
val sqr_mod : SE.sqr_st S.felem mk_to_nat_mod_comm_monoid
let sqr_mod x = S.fmul x x
let mk_nat_mod_concrete_ops : SE.concrete_ops S.felem = {
SE.to = mk_to_nat_mod_comm_monoid;
SE.one = one_mod;
SE.mul = mul_mod;
SE.sqr = sqr_mod;
}
let fsquare_times (a:S.felem) (b:nat) : S.felem =
SE.exp_pow2 mk_nat_mod_concrete_ops a b
val fsquare_times_lemma: a:S.felem -> b:nat ->
Lemma (fsquare_times a b == M.pow a (pow2 b) % S.prime)
let fsquare_times_lemma a b =
SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b;
LE.exp_pow2_lemma nat_mod_comm_monoid a b;
assert (fsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b));
M.lemma_pow_nat_mod_is_pow #S.prime a (pow2 b)
val fexp_223_23: f:S.felem -> tuple2 S.felem S.felem
let fexp_223_23 f =
let x2 = S.fmul (fsquare_times f 1) f in
let x3 = S.fmul (fsquare_times x2 1) f in
let x6 = S.fmul (fsquare_times x3 3) x3 in
let x9 = S.fmul (fsquare_times x6 3) x3 in
let x11 = S.fmul (fsquare_times x9 2) x2 in
let x22 = S.fmul (fsquare_times x11 11) x11 in
let x44 = S.fmul (fsquare_times x22 22) x22 in
let x88 = S.fmul (fsquare_times x44 44) x44 in
let x176 = S.fmul (fsquare_times x88 88) x88 in
let x220 = S.fmul (fsquare_times x176 44) x44 in
let x223 = S.fmul (fsquare_times x220 3) x3 in
let r = S.fmul (fsquare_times x223 23) x22 in
r, x2
(**
The algorithm is taken from
https://briansmith.org/ecc-inversion-addition-chains-01
*)
val finv: f:S.felem -> S.felem
let finv f =
let r, x2 = fexp_223_23 f in
let r = S.fmul (fsquare_times r 5) f in
let r = S.fmul (fsquare_times r 3) x2 in
let r = S.fmul (fsquare_times r 2) f in
r
val fsqrt: f:S.felem -> S.felem
let fsqrt f =
let r, x2 = fexp_223_23 f in
let r = S.fmul (fsquare_times r 6) x2 in
let r = fsquare_times r 2 in
r
val is_fsqrt: f:S.felem -> f2:S.felem -> bool
let is_fsqrt f f2 = S.fmul f f = f2
val lemma_pow_mod_1: f:S.felem -> Lemma (f == M.pow f 1 % S.prime)
let lemma_pow_mod_1 f =
M.lemma_pow1 f;
Math.Lemmas.small_mod f S.prime;
assert_norm (pow2 0 = 1);
assert (f == M.pow f 1 % S.prime)
val lemma_pow_mod_mul: f:S.felem -> a:nat -> b:nat -> | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Spec.K256.PointOps.felem -> a: Prims.nat -> b: Prims.nat
-> FStar.Pervasives.Lemma
(ensures
Spec.K256.PointOps.fmul (Lib.NatMod.pow f a % Spec.K256.PointOps.prime)
(Lib.NatMod.pow f b % Spec.K256.PointOps.prime) ==
Lib.NatMod.pow f (a + b) % Spec.K256.PointOps.prime) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.K256.PointOps.felem",
"Prims.nat",
"FStar.Calc.calc_finish",
"Prims.eq2",
"Spec.K256.PointOps.fmul",
"Prims.op_Modulus",
"Lib.NatMod.pow",
"Spec.K256.PointOps.prime",
"Prims.op_Addition",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Mul.op_Star",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.lemma_mod_mul_distr_r",
"FStar.Math.Lemmas.lemma_mod_mul_distr_l",
"Prims.squash",
"Lib.NatMod.lemma_pow_add"
] | [] | false | false | true | false | false | let lemma_pow_mod_mul f a b =
| calc ( == ) {
S.fmul (M.pow f a % S.prime) (M.pow f b % S.prime);
( == ) { (Math.Lemmas.lemma_mod_mul_distr_l (M.pow f a) (M.pow f b % S.prime) S.prime;
Math.Lemmas.lemma_mod_mul_distr_r (M.pow f a) (M.pow f b) S.prime) }
M.pow f a * M.pow f b % S.prime;
( == ) { M.lemma_pow_add f a b }
M.pow f (a + b) % S.prime;
} | false |
Hacl.Spec.K256.Finv.fst | Hacl.Spec.K256.Finv.fexp_223_23_lemma | val fexp_223_23_lemma: f:S.felem ->
Lemma (let (r, x2) = fexp_223_23 f in
x2 == M.pow f 0x3 % S.prime /\
r == M.pow f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff % S.prime) | val fexp_223_23_lemma: f:S.felem ->
Lemma (let (r, x2) = fexp_223_23 f in
x2 == M.pow f 0x3 % S.prime /\
r == M.pow f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff % S.prime) | let fexp_223_23_lemma f =
let x2 = S.fmul (fsquare_times f 1) f in
fsquare_times_lemma f 1;
assert_norm (pow2 1 = 0x2);
lemma_pow_mod_1 f;
lemma_pow_mod_mul f 0x2 0x1;
assert (x2 == M.pow f 0x3 % S.prime);
let x3 = S.fmul (fsquare_times x2 1) f in
fsquare_times_lemma x2 1;
lemma_pow_mod_1 f;
lemma_pow_pow_mod_mul f 0x3 0x2 0x1;
assert (x3 == M.pow f 0x7 % S.prime);
let x6 = S.fmul (fsquare_times x3 3) x3 in
fsquare_times_lemma x3 3;
assert_norm (pow2 3 = 8);
lemma_pow_pow_mod_mul f 0x7 0x8 0x7;
assert (x6 == M.pow f 0x3f % S.prime);
let x9 = S.fmul (fsquare_times x6 3) x3 in
fsquare_times_lemma x6 3;
lemma_pow_pow_mod_mul f 0x3f 0x8 0x7;
assert (x9 == M.pow f 0x1ff % S.prime);
let x11 = S.fmul (fsquare_times x9 2) x2 in
fsquare_times_lemma x9 2;
assert_norm (pow2 2 = 0x4);
lemma_pow_pow_mod_mul f 0x1ff 0x4 0x3;
assert (x11 == M.pow f 0x7ff % S.prime);
let x22 = S.fmul (fsquare_times x11 11) x11 in
fsquare_times_lemma x11 11;
assert_norm (pow2 11 = 0x800);
lemma_pow_pow_mod_mul f 0x7ff 0x800 0x7ff;
assert (x22 == M.pow f 0x3fffff % S.prime);
let x44 = S.fmul (fsquare_times x22 22) x22 in
fsquare_times_lemma x22 22;
assert_norm (pow2 22 = 0x400000);
lemma_pow_pow_mod_mul f 0x3fffff 0x400000 0x3fffff;
assert (x44 == M.pow f 0xfffffffffff % S.prime);
let x88 = S.fmul (fsquare_times x44 44) x44 in
fsquare_times_lemma x44 44;
assert_norm (pow2 44 = 0x100000000000);
lemma_pow_pow_mod_mul f 0xfffffffffff 0x100000000000 0xfffffffffff;
assert (x88 == M.pow f 0xffffffffffffffffffffff % S.prime);
let x176 = S.fmul (fsquare_times x88 88) x88 in
fsquare_times_lemma x88 88;
assert_norm (pow2 88 = 0x10000000000000000000000);
lemma_pow_pow_mod_mul f 0xffffffffffffffffffffff 0x10000000000000000000000 0xffffffffffffffffffffff;
assert (x176 == M.pow f 0xffffffffffffffffffffffffffffffffffffffffffff % S.prime);
let x220 = S.fmul (fsquare_times x176 44) x44 in
fsquare_times_lemma x176 44;
lemma_pow_pow_mod_mul f 0xffffffffffffffffffffffffffffffffffffffffffff 0x100000000000 0xfffffffffff;
assert (x220 == M.pow f 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffff % S.prime);
let x223 = S.fmul (fsquare_times x220 3) x3 in
fsquare_times_lemma x220 3;
lemma_pow_pow_mod_mul f 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffff 0x8 0x7;
assert (x223 == M.pow f 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff % S.prime);
let r0 = S.fmul (fsquare_times x223 23) x22 in
fsquare_times_lemma x223 23;
assert_norm (pow2 23 = 0x800000);
lemma_pow_pow_mod_mul f 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff 0x800000 0x3fffff;
assert (r0 == M.pow f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff % S.prime) | {
"file_name": "code/k256/Hacl.Spec.K256.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 99,
"end_line": 211,
"start_col": 0,
"start_line": 142
} | module Hacl.Spec.K256.Finv
open FStar.Mul
module SE = Spec.Exponentiation
module LE = Lib.Exponentiation
module M = Lib.NatMod
module S = Spec.K256
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.prime
let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.felem = {
SE.a_spec = S.felem;
SE.comm_monoid = nat_mod_comm_monoid;
SE.refl = (fun (x:S.felem) -> x);
}
val one_mod : SE.one_st S.felem mk_to_nat_mod_comm_monoid
let one_mod _ = S.one
val mul_mod : SE.mul_st S.felem mk_to_nat_mod_comm_monoid
let mul_mod x y = S.fmul x y
val sqr_mod : SE.sqr_st S.felem mk_to_nat_mod_comm_monoid
let sqr_mod x = S.fmul x x
let mk_nat_mod_concrete_ops : SE.concrete_ops S.felem = {
SE.to = mk_to_nat_mod_comm_monoid;
SE.one = one_mod;
SE.mul = mul_mod;
SE.sqr = sqr_mod;
}
let fsquare_times (a:S.felem) (b:nat) : S.felem =
SE.exp_pow2 mk_nat_mod_concrete_ops a b
val fsquare_times_lemma: a:S.felem -> b:nat ->
Lemma (fsquare_times a b == M.pow a (pow2 b) % S.prime)
let fsquare_times_lemma a b =
SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b;
LE.exp_pow2_lemma nat_mod_comm_monoid a b;
assert (fsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b));
M.lemma_pow_nat_mod_is_pow #S.prime a (pow2 b)
val fexp_223_23: f:S.felem -> tuple2 S.felem S.felem
let fexp_223_23 f =
let x2 = S.fmul (fsquare_times f 1) f in
let x3 = S.fmul (fsquare_times x2 1) f in
let x6 = S.fmul (fsquare_times x3 3) x3 in
let x9 = S.fmul (fsquare_times x6 3) x3 in
let x11 = S.fmul (fsquare_times x9 2) x2 in
let x22 = S.fmul (fsquare_times x11 11) x11 in
let x44 = S.fmul (fsquare_times x22 22) x22 in
let x88 = S.fmul (fsquare_times x44 44) x44 in
let x176 = S.fmul (fsquare_times x88 88) x88 in
let x220 = S.fmul (fsquare_times x176 44) x44 in
let x223 = S.fmul (fsquare_times x220 3) x3 in
let r = S.fmul (fsquare_times x223 23) x22 in
r, x2
(**
The algorithm is taken from
https://briansmith.org/ecc-inversion-addition-chains-01
*)
val finv: f:S.felem -> S.felem
let finv f =
let r, x2 = fexp_223_23 f in
let r = S.fmul (fsquare_times r 5) f in
let r = S.fmul (fsquare_times r 3) x2 in
let r = S.fmul (fsquare_times r 2) f in
r
val fsqrt: f:S.felem -> S.felem
let fsqrt f =
let r, x2 = fexp_223_23 f in
let r = S.fmul (fsquare_times r 6) x2 in
let r = fsquare_times r 2 in
r
val is_fsqrt: f:S.felem -> f2:S.felem -> bool
let is_fsqrt f f2 = S.fmul f f = f2
val lemma_pow_mod_1: f:S.felem -> Lemma (f == M.pow f 1 % S.prime)
let lemma_pow_mod_1 f =
M.lemma_pow1 f;
Math.Lemmas.small_mod f S.prime;
assert_norm (pow2 0 = 1);
assert (f == M.pow f 1 % S.prime)
val lemma_pow_mod_mul: f:S.felem -> a:nat -> b:nat ->
Lemma (S.fmul (M.pow f a % S.prime) (M.pow f b % S.prime) == M.pow f (a + b) % S.prime)
let lemma_pow_mod_mul f a b =
calc (==) {
S.fmul (M.pow f a % S.prime) (M.pow f b % S.prime);
(==) {
Math.Lemmas.lemma_mod_mul_distr_l (M.pow f a) (M.pow f b % S.prime) S.prime;
Math.Lemmas.lemma_mod_mul_distr_r (M.pow f a) (M.pow f b) S.prime }
M.pow f a * M.pow f b % S.prime;
(==) { M.lemma_pow_add f a b }
M.pow f (a + b) % S.prime;
}
val lemma_pow_pow_mod: f:S.felem -> a:nat -> b:nat ->
Lemma (M.pow (M.pow f a % S.prime) b % S.prime == M.pow f (a * b) % S.prime)
let lemma_pow_pow_mod f a b =
calc (==) {
M.pow (M.pow f a % S.prime) b % S.prime;
(==) { M.lemma_pow_mod_base (M.pow f a) b S.prime }
M.pow (M.pow f a) b % S.prime;
(==) { M.lemma_pow_mul f a b }
M.pow f (a * b) % S.prime;
}
val lemma_pow_pow_mod_mul: f:S.felem -> a:nat -> b:nat -> c:nat ->
Lemma (S.fmul (M.pow (M.pow f a % S.prime) b % S.prime) (M.pow f c % S.prime) == M.pow f (a * b + c) % S.prime)
let lemma_pow_pow_mod_mul f a b c =
calc (==) {
S.fmul (M.pow (M.pow f a % S.prime) b % S.prime) (M.pow f c % S.prime);
(==) { lemma_pow_pow_mod f a b }
S.fmul (M.pow f (a * b) % S.prime) (M.pow f c % S.prime);
(==) { lemma_pow_mod_mul f (a * b) c }
M.pow f (a * b + c) % S.prime;
}
val fexp_223_23_lemma: f:S.felem ->
Lemma (let (r, x2) = fexp_223_23 f in
x2 == M.pow f 0x3 % S.prime /\
r == M.pow f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff % S.prime) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Spec.K256.PointOps.felem
-> FStar.Pervasives.Lemma
(ensures
(let _ = Hacl.Spec.K256.Finv.fexp_223_23 f in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ r x2 = _ in
x2 == Lib.NatMod.pow f 0x3 % Spec.K256.PointOps.prime /\
r ==
Lib.NatMod.pow f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff %
Spec.K256.PointOps.prime)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.K256.PointOps.felem",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"Lib.NatMod.pow",
"Spec.K256.PointOps.prime",
"Prims.unit",
"Hacl.Spec.K256.Finv.lemma_pow_pow_mod_mul",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality",
"Prims.pow2",
"Hacl.Spec.K256.Finv.fsquare_times_lemma",
"Spec.K256.PointOps.fmul",
"Hacl.Spec.K256.Finv.fsquare_times",
"Hacl.Spec.K256.Finv.lemma_pow_mod_1",
"Hacl.Spec.K256.Finv.lemma_pow_mod_mul"
] | [] | true | false | true | false | false | let fexp_223_23_lemma f =
| let x2 = S.fmul (fsquare_times f 1) f in
fsquare_times_lemma f 1;
assert_norm (pow2 1 = 0x2);
lemma_pow_mod_1 f;
lemma_pow_mod_mul f 0x2 0x1;
assert (x2 == M.pow f 0x3 % S.prime);
let x3 = S.fmul (fsquare_times x2 1) f in
fsquare_times_lemma x2 1;
lemma_pow_mod_1 f;
lemma_pow_pow_mod_mul f 0x3 0x2 0x1;
assert (x3 == M.pow f 0x7 % S.prime);
let x6 = S.fmul (fsquare_times x3 3) x3 in
fsquare_times_lemma x3 3;
assert_norm (pow2 3 = 8);
lemma_pow_pow_mod_mul f 0x7 0x8 0x7;
assert (x6 == M.pow f 0x3f % S.prime);
let x9 = S.fmul (fsquare_times x6 3) x3 in
fsquare_times_lemma x6 3;
lemma_pow_pow_mod_mul f 0x3f 0x8 0x7;
assert (x9 == M.pow f 0x1ff % S.prime);
let x11 = S.fmul (fsquare_times x9 2) x2 in
fsquare_times_lemma x9 2;
assert_norm (pow2 2 = 0x4);
lemma_pow_pow_mod_mul f 0x1ff 0x4 0x3;
assert (x11 == M.pow f 0x7ff % S.prime);
let x22 = S.fmul (fsquare_times x11 11) x11 in
fsquare_times_lemma x11 11;
assert_norm (pow2 11 = 0x800);
lemma_pow_pow_mod_mul f 0x7ff 0x800 0x7ff;
assert (x22 == M.pow f 0x3fffff % S.prime);
let x44 = S.fmul (fsquare_times x22 22) x22 in
fsquare_times_lemma x22 22;
assert_norm (pow2 22 = 0x400000);
lemma_pow_pow_mod_mul f 0x3fffff 0x400000 0x3fffff;
assert (x44 == M.pow f 0xfffffffffff % S.prime);
let x88 = S.fmul (fsquare_times x44 44) x44 in
fsquare_times_lemma x44 44;
assert_norm (pow2 44 = 0x100000000000);
lemma_pow_pow_mod_mul f 0xfffffffffff 0x100000000000 0xfffffffffff;
assert (x88 == M.pow f 0xffffffffffffffffffffff % S.prime);
let x176 = S.fmul (fsquare_times x88 88) x88 in
fsquare_times_lemma x88 88;
assert_norm (pow2 88 = 0x10000000000000000000000);
lemma_pow_pow_mod_mul f 0xffffffffffffffffffffff 0x10000000000000000000000 0xffffffffffffffffffffff;
assert (x176 == M.pow f 0xffffffffffffffffffffffffffffffffffffffffffff % S.prime);
let x220 = S.fmul (fsquare_times x176 44) x44 in
fsquare_times_lemma x176 44;
lemma_pow_pow_mod_mul f 0xffffffffffffffffffffffffffffffffffffffffffff 0x100000000000 0xfffffffffff;
assert (x220 == M.pow f 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffff % S.prime);
let x223 = S.fmul (fsquare_times x220 3) x3 in
fsquare_times_lemma x220 3;
lemma_pow_pow_mod_mul f 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffff 0x8 0x7;
assert (x223 == M.pow f 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff % S.prime);
let r0 = S.fmul (fsquare_times x223 23) x22 in
fsquare_times_lemma x223 23;
assert_norm (pow2 23 = 0x800000);
lemma_pow_pow_mod_mul f 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff 0x800000 0x3fffff;
assert (r0 == M.pow f 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff % S.prime) | false |
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.block_len | val block_len : a: Spec.Hash.Definitions.hash_alg
-> n:
Lib.IntTypes.int_t Lib.IntTypes.U32 Lib.IntTypes.PUB
{Lib.IntTypes.v n = Spec.Hash.Definitions.block_length a} | let block_len a = Hacl.Hash.Definitions.block_len a | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 51,
"end_line": 78,
"start_col": 0,
"start_line": 78
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.hash_alg
-> n:
Lib.IntTypes.int_t Lib.IntTypes.U32 Lib.IntTypes.PUB
{Lib.IntTypes.v n = Spec.Hash.Definitions.block_length a} | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.hash_alg",
"Hacl.Hash.Definitions.block_len",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Lib.IntTypes.range",
"Prims.op_disEquality",
"Lib.IntTypes.v",
"Spec.Hash.Definitions.block_length"
] | [] | false | false | false | false | false | let block_len a =
| Hacl.Hash.Definitions.block_len a | false |
|
Pulse.Checker.Prover.fst | Pulse.Checker.Prover.prove_post_hint | val prove_post_hint (#g:env) (#ctxt:vprop)
(r:checker_result_t g ctxt None)
(post_hint:post_hint_opt g)
(rng:range)
: T.Tac (checker_result_t g ctxt post_hint) | val prove_post_hint (#g:env) (#ctxt:vprop)
(r:checker_result_t g ctxt None)
(post_hint:post_hint_opt g)
(rng:range)
: T.Tac (checker_result_t g ctxt post_hint) | let prove_post_hint (#g:env) (#ctxt:vprop)
(r:checker_result_t g ctxt None)
(post_hint:post_hint_opt g)
(rng:range)
: T.Tac (checker_result_t g ctxt post_hint) =
let g = push_context g "prove_post_hint" rng in
match post_hint with
| None -> r
| Some post_hint ->
let (| x, g2, (| u_ty, ty, ty_typing |), (| ctxt', ctxt'_typing |), k |) = r in
let ppname = mk_ppname_no_range "_posth" in
let post_hint_opened = open_term_nv post_hint.post (ppname, x) in
// TODO: subtyping
if not (eq_tm ty post_hint.ret_ty)
then
let open Pulse.PP in
fail_doc g (Some rng) [
text "Error in proving postcondition";
text "The return type" ^^
indent (pp ty) ^/^
text "does not match the expected" ^^
indent (pp post_hint.ret_ty)
]
else if eq_tm post_hint_opened ctxt'
then (| x, g2, (| u_ty, ty, ty_typing |), (| ctxt', ctxt'_typing |), k |)
else
let (| g3, nts, _, remaining_ctxt, k_post |) =
prove #g2 #ctxt' ctxt'_typing (mk_env (fstar_env g2)) #post_hint_opened (RU.magic ()) in
assert (nts == []);
let k_post
: continuation_elaborator g2 ctxt' g3 (post_hint_opened * remaining_ctxt) =
coerce_eq k_post () in
match check_equiv_emp g3 remaining_ctxt with
| None ->
let open Pulse.PP in
fail_doc g (Some rng) [
text "Error in proving postcondition";
text "Inferred postcondition additionally contains" ^^
indent (pp remaining_ctxt);
(if Tm_Star? remaining_ctxt.t
then text "Did you forget to free these resources?"
else text "Did you forget to free this resource?");
]
| Some d ->
let k_post
: continuation_elaborator g2 ctxt' g3 post_hint_opened =
k_elab_equiv k_post (VE_Refl _ _) (RU.magic #(vprop_equiv _ _ _) ()) in
//
// for the typing of ty in g3,
// we have typing of ty in g2 above, and g3 `env_extends` g2
//
//
// for the typing of post_hint_opened,
// again post_hint is well-typed in g, and g3 `env_extends` g
//
(| x, g3, (| u_ty, ty, RU.magic #(tot_typing _ _ _) () |),
(| post_hint_opened, RU.magic #(tot_typing _ _ _) () |), k_elab_trans k k_post |) | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 99,
"end_line": 456,
"start_col": 0,
"start_line": 393
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Prover
open FStar.List.Tot
open Pulse.Syntax
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Checker.Base
module RU = Pulse.RuntimeUtils
module L = FStar.List.Tot
module T = FStar.Tactics.V2
module P = Pulse.Syntax.Printer
module Pprint = FStar.Stubs.Pprint
module Metatheory = Pulse.Typing.Metatheory
module PS = Pulse.Checker.Prover.Substs
module ElimExists = Pulse.Checker.Prover.ElimExists
module ElimPure = Pulse.Checker.Prover.ElimPure
module Match = Pulse.Checker.Prover.Match
module IntroExists = Pulse.Checker.Prover.IntroExists
module IntroPure = Pulse.Checker.Prover.IntroPure
let coerce_eq (#a #b:Type) (x:a) (_:squash (a == b)) : y:b{y == x} = x
let elim_exists_and_pure (#g:env) (#ctxt:vprop)
(ctxt_typing:tot_typing g ctxt tm_vprop)
: T.Tac (g':env { env_extends g' g } &
ctxt':term &
tot_typing g' ctxt' tm_vprop &
continuation_elaborator g ctxt g' ctxt') =
let (| g1, ctxt1, d1, k1 |) = ElimExists.elim_exists ctxt_typing in
let (| g2, ctxt2, d2, k2 |) = ElimPure.elim_pure d1 in
(| g2, ctxt2, d2, k_elab_trans k1 k2 |)
let unsolved_equiv_pst (#preamble:_) (pst:prover_state preamble) (unsolved':list vprop)
(d:vprop_equiv (push_env pst.pg pst.uvs) (list_as_vprop pst.unsolved) (list_as_vprop unsolved'))
: prover_state preamble =
{ pst with unsolved = unsolved'; goals_inv = RU.magic () }
let rec collect_exists (g:env) (l:list vprop)
: exs:list vprop &
rest:list vprop &
vprop_equiv g (list_as_vprop l) (list_as_vprop (exs @ rest)) =
match l with
| [] -> (| [], [], VE_Refl _ _ |)
| hd::tl ->
let (| exs, rest, _ |) = collect_exists g tl in
match hd.t with
| Tm_ExistsSL _ _ _ ->
(| hd::exs, rest, RU.magic #(vprop_equiv _ _ _) () |)
| _ -> (| exs, hd::rest, RU.magic #(vprop_equiv _ _ _) () |)
let rec collect_pures (g:env) (l:list vprop)
: pures:list vprop &
rest:list vprop &
vprop_equiv g (list_as_vprop l) (list_as_vprop (rest @ pures)) =
match l with
| [] -> (| [], [], VE_Refl _ _ |)
| hd::tl ->
let (| pures, rest, _ |) = collect_pures g tl in
match hd.t with
| Tm_Pure _ -> (| hd::pures, rest, RU.magic #(vprop_equiv _ _ _) () |)
| _ -> (| pures, hd::rest, RU.magic #(vprop_equiv _ _ _) () |)
let rec prove_pures #preamble (pst:prover_state preamble)
: T.Tac (pst':prover_state preamble { pst' `pst_extends` pst /\
is_terminal pst' }) =
match pst.unsolved with
| [] -> pst
| {t=Tm_Pure p}::unsolved' ->
let pst_opt = IntroPure.intro_pure pst p unsolved' () in
(match pst_opt with
| None ->
let open Pulse.PP in
fail_doc pst.pg None [
text "Cannot prove pure proposition" ^/^
pp p
]
| Some pst1 ->
let pst2 = prove_pures pst1 in
assert (pst1 `pst_extends` pst);
assert (pst2 `pst_extends` pst1);
assert (pst2 `pst_extends` pst);
pst2)
| _ ->
fail pst.pg None
(Printf.sprintf "Impossible! prover.prove_pures: %s is not a pure, please file a bug-report"
(P.term_to_string (L.hd pst.unsolved)))
#push-options "--z3rlimit_factor 4"
let rec prover
(#preamble:_)
(pst0:prover_state preamble)
: T.Tac (pst':prover_state preamble { pst' `pst_extends` pst0 /\
is_terminal pst' }) =
debug_prover pst0.pg (fun _ ->
Printf.sprintf "At the prover top-level with remaining_ctxt: %s\nunsolved: %s"
(P.term_to_string (list_as_vprop pst0.remaining_ctxt))
(P.term_to_string (list_as_vprop pst0.unsolved)));
match pst0.unsolved with
| [] -> pst0
| _ ->
let pst = ElimExists.elim_exists_pst pst0 in
debug_prover pst.pg (fun _ ->
Printf.sprintf "prover: remaining_ctxt after elim exists: %s\n"
(P.term_to_string (list_as_vprop pst.remaining_ctxt)));
let pst = ElimPure.elim_pure_pst pst in
debug_prover pst.pg (fun _ ->
Printf.sprintf "prover: remaining_ctxt after elim pure: %s\n"
(P.term_to_string (list_as_vprop pst.remaining_ctxt)));
let (| exs, rest, d |) = collect_exists (push_env pst.pg pst.uvs) pst.unsolved in
debug_prover pst.pg (fun _ ->
Printf.sprintf "prover: tried to pull exists: exs: %s and rest: %s\n"
(P.term_to_string (list_as_vprop exs)) (P.term_to_string (list_as_vprop rest)));
let pst = unsolved_equiv_pst pst (exs@rest) d in
debug_prover pst.pg (fun _ ->
Printf.sprintf "prover: unsolved after pulling exists at the top: %s\n"
(P.term_to_string (list_as_vprop pst.unsolved)));
match pst.unsolved with
| {t=Tm_ExistsSL u b body}::unsolved' ->
IntroExists.intro_exists pst u b body unsolved' () prover
| _ ->
let (| pures, rest, d |) = collect_pures (push_env pst.pg pst.uvs) pst.unsolved in
let pst = unsolved_equiv_pst pst (rest@pures) d in
match pst.unsolved with
| {t=Tm_Pure _}::tl -> prove_pures pst
| q::tl ->
let pst_opt = Match.match_q pst q tl () prover in
match pst_opt with
| None ->
let open Pprint in
let open Pulse.PP in
let msg = [
text "Cannot prove:" ^^
indent (pp q);
text "In the context:" ^^
indent (pp (list_as_vprop pst.remaining_ctxt))
] @ (if Pulse.Config.debug_flag "initial_solver_state" then [
text "The prover was started with goal:" ^^
indent (pp preamble.goals);
text "and initial context:" ^^
indent (pp preamble.ctxt);
] else [])
in
// GM: I feel I should use (Some q.range) instead of None, but that makes
// several error locations worse.
fail_doc pst.pg None msg
| Some pst -> prover pst // a little wasteful?
#pop-options
let rec get_q_at_hd (g:env) (l:list vprop) (q:vprop { L.existsb (fun v -> eq_tm v q) l })
: l':list vprop &
vprop_equiv g (list_as_vprop l) (q * list_as_vprop l') =
match l with
| hd::tl ->
if eq_tm hd q then (| tl, RU.magic #(vprop_equiv _ _ _) () |)
else let (| tl', _ |) = get_q_at_hd g tl q in
(| hd::tl', RU.magic #(vprop_equiv _ _ _) () |)
#push-options "--z3rlimit_factor 4"
let prove
(#g:env) (#ctxt:vprop) (ctxt_typing:vprop_typing g ctxt)
(uvs:env { disjoint g uvs })
(#goals:vprop) (goals_typing:vprop_typing (push_env g uvs) goals)
: T.Tac (g1 : env { g1 `env_extends` g /\ disjoint g1 uvs } &
nts : PS.nt_substs &
effect_labels:list T.tot_or_ghost { PS.well_typed_nt_substs g1 uvs nts effect_labels } &
remaining_ctxt : vprop &
continuation_elaborator g ctxt g1 ((PS.nt_subst_term goals nts) * remaining_ctxt)) =
debug_prover g (fun _ ->
Printf.sprintf "\nEnter top-level prove with ctxt: %s\ngoals: %s\n"
(P.term_to_string ctxt) (P.term_to_string goals));
let ctxt_l = vprop_as_list ctxt in
if false && Nil? (bindings uvs) && L.existsb (fun v -> eq_tm v goals) ctxt_l
then begin
let (| l', d_eq |) = get_q_at_hd g ctxt_l goals in
let g1 = g in
let nts : PS.nt_substs = [] in
let remaining_ctxt = list_as_vprop l' in
let k : continuation_elaborator g ctxt g1 ctxt = k_elab_unit g ctxt in
assume (list_as_vprop (vprop_as_list ctxt) == ctxt);
let d_eq
: vprop_equiv g ctxt ((PS.nt_subst_term goals nts) * remaining_ctxt) = coerce_eq d_eq () in
(| g1, nts, [], remaining_ctxt, k_elab_equiv k (VE_Refl _ _) d_eq |)
end
else
let ctxt_frame_typing : vprop_typing g (ctxt * tm_emp) = RU.magic () in
let preamble = {
g0 = g;
ctxt;
frame = tm_emp;
ctxt_frame_typing;
goals;
} in
assume (list_as_vprop (vprop_as_list ctxt) == ctxt);
assume ((PS.empty).(tm_emp) == tm_emp);
let pst0 : prover_state preamble = {
pg = g;
remaining_ctxt = vprop_as_list ctxt;
remaining_ctxt_frame_typing = ctxt_frame_typing;
uvs = uvs;
ss = PS.empty;
nts = None;
solved = tm_emp;
unsolved = vprop_as_list goals;
k = k_elab_equiv (k_elab_unit g ctxt) (RU.magic ()) (RU.magic ());
goals_inv = RU.magic ();
solved_inv = ()
} in
let pst = prover pst0 in
let (| nts, effect_labels |)
: nts:PS.nt_substs &
effect_labels:list T.tot_or_ghost {
PS.well_typed_nt_substs pst.pg pst.uvs nts effect_labels /\
PS.is_permutation nts pst.ss
} =
match pst.nts with
| Some nts -> nts
| None ->
let r = PS.ss_to_nt_substs pst.pg pst.uvs pst.ss in
match r with
| Inr msg ->
fail pst.pg None
(Printf.sprintf "prover error: ill-typed substitutions (%s)" msg)
| Inl nts -> nts in
let nts_uvs, nts_uvs_effect_labels =
PS.well_typed_nt_substs_prefix pst.pg pst.uvs nts effect_labels uvs in
let k
: continuation_elaborator
g (ctxt * tm_emp)
pst.pg ((list_as_vprop pst.remaining_ctxt * tm_emp) * (PS.nt_subst_term pst.solved nts)) = pst.k in
// admit ()
let goals_inv
: vprop_equiv (push_env pst.pg pst.uvs) goals (list_as_vprop [] * pst.solved) = pst.goals_inv in
let goals_inv
: vprop_equiv pst.pg (PS.nt_subst_term goals nts) (PS.nt_subst_term (list_as_vprop [] * pst.solved) nts) =
PS.vprop_equiv_nt_substs_derived pst.pg pst.uvs goals_inv nts effect_labels in
// goals is well-typed in initial g + uvs
// so any of the remaining uvs in pst.uvs should not be in goals
// so we can drop their substitutions from the tail of nts
assume (PS.nt_subst_term goals nts == PS.nt_subst_term goals nts_uvs);
(| pst.pg, nts_uvs, nts_uvs_effect_labels, list_as_vprop pst.remaining_ctxt, k_elab_equiv k (RU.magic ()) (RU.magic ()) |)
#pop-options
let canon_post (c:comp_st) : comp_st =
let canon_st_comp_post (c:st_comp) : st_comp =
match Pulse.Readback.readback_ty (elab_term c.post) with
| None -> c
| Some post -> { c with post }
in
match c with
| C_ST s -> C_ST (canon_st_comp_post s)
| C_STAtomic i obs s -> C_STAtomic i obs (canon_st_comp_post s)
| C_STGhost s -> C_STGhost (canon_st_comp_post s)
irreducible
let typing_canon #g #t (#c:comp_st) (d:st_typing g t c) : st_typing g t (canon_post c) =
assume false;
d
#push-options "--z3rlimit_factor 8 --fuel 0 --ifuel 1 --retry 5"
let try_frame_pre_uvs (#g:env) (#ctxt:vprop) (ctxt_typing:tot_typing g ctxt tm_vprop)
(uvs:env { disjoint g uvs })
(d:(t:st_term & c:comp_st & st_typing (push_env g uvs) t c))
(res_ppname:ppname)
: T.Tac (checker_result_t g ctxt None) =
let (| t, c, d |) = d in
let g = push_context g "try_frame_pre" t.range in
let (| g1, nts, effect_labels, remaining_ctxt, k_frame |) =
prove #g #_ ctxt_typing uvs #(comp_pre c) (RU.magic ()) in
// assert (nts == []);
let d : st_typing (push_env g1 uvs) t c =
Metatheory.st_typing_weakening g uvs t c d g1 in
assert (comp_pre (PS.nt_subst_comp c nts) == PS.nt_subst_term (comp_pre c) nts);
let t = PS.nt_subst_st_term t nts in
let c = PS.nt_subst_comp c nts in
let d : st_typing g1 t c =
let r = PS.st_typing_nt_substs_derived g1 uvs d nts effect_labels in
match r with
| Inr (x, x_t) ->
fail g1 (Some t.range)
(Printf.sprintf "prover error: for term %s, implicit solution %s has ghost effect"
(P.st_term_to_string t)
(P.term_to_string x_t))
| Inl d -> d in
(* shouldn't need this once term becomes a view; currently we sometimes end up with a computation
type whose postcondition is Tm_FStar (`(p1 ** p2))) rather than a Tm_Star p1 p2;
canon_post normalizes that *)
let c = canon_post c in
let d = typing_canon d in
let k_frame : continuation_elaborator g ctxt g1 (comp_pre c * remaining_ctxt) = coerce_eq k_frame () in
let x = fresh g1 in
let ty = comp_res c in
let g2 = push_binding g1 x res_ppname ty in
assert (g2 `env_extends` g1);
let ctxt' = (open_term_nv (comp_post c) (res_ppname, x) * remaining_ctxt) in
let d : st_typing g1 t c = Metatheory.st_typing_weakening_standard d g1 in
let k
: continuation_elaborator g1 (remaining_ctxt * comp_pre c)
g2 ctxt' =
continuation_elaborator_with_bind remaining_ctxt d (RU.magic #(tot_typing _ _ _) ()) (res_ppname, x) in
let k
: continuation_elaborator g1 (comp_pre c * remaining_ctxt)
g2 ctxt' =
k_elab_equiv k (VE_Comm _ _ _) (VE_Refl _ _) in
let k = k_elab_trans k_frame k in
let comp_res_typing_in_g1, _, f =
Metatheory.st_comp_typing_inversion_cofinite
(fst <| Metatheory.comp_typing_inversion (Metatheory.st_typing_correctness d)) in
let d_ty
: universe_of g2 ty (comp_u c) =
Metatheory.tot_typing_weakening_single comp_res_typing_in_g1 x (comp_res c) in
assume (~ (x `Set.mem` freevars (comp_post c)));
let d_post
: vprop_typing g2 (open_term_nv (comp_post c) (res_ppname, x)) =
f x in
// the RU.magic is for the ctxt' typing
// see d_post for post typing
// then the remaining_ctxt typing should come from the prover state
// TODO: add it there
// and then ctxt' is just their `*`
(| x, g2, (| comp_u c, ty, d_ty |), (| ctxt', RU.magic #(tot_typing _ _ _) () |), k |)
#pop-options
let try_frame_pre (#g:env) (#ctxt:vprop) (ctxt_typing:tot_typing g ctxt tm_vprop)
(d:(t:st_term & c:comp_st & st_typing g t c))
(res_ppname:ppname)
: T.Tac (checker_result_t g ctxt None) =
let uvs = mk_env (fstar_env g) in
assert (equal g (push_env g uvs));
try_frame_pre_uvs ctxt_typing uvs d res_ppname | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Readback.fsti.checked",
"Pulse.PP.fst.checked",
"Pulse.Config.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.Match.fsti.checked",
"Pulse.Checker.Prover.IntroPure.fsti.checked",
"Pulse.Checker.Prover.IntroExists.fsti.checked",
"Pulse.Checker.Prover.ElimPure.fsti.checked",
"Pulse.Checker.Prover.ElimExists.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Pprint.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.IntroPure",
"short_module": "IntroPure"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.IntroExists",
"short_module": "IntroExists"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Match",
"short_module": "Match"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.ElimPure",
"short_module": "ElimPure"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.ElimExists",
"short_module": "ElimExists"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "FStar.Stubs.Pprint",
"short_module": "Pprint"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
r: Pulse.Checker.Base.checker_result_t g ctxt FStar.Pervasives.Native.None ->
post_hint: Pulse.Typing.post_hint_opt g ->
rng: Pulse.Syntax.Base.range
-> FStar.Tactics.Effect.Tac (Pulse.Checker.Base.checker_result_t g ctxt post_hint) | FStar.Tactics.Effect.Tac | [] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.vprop",
"Pulse.Checker.Base.checker_result_t",
"FStar.Pervasives.Native.None",
"Pulse.Typing.post_hint_t",
"Pulse.Typing.post_hint_opt",
"Pulse.Syntax.Base.range",
"Pulse.Syntax.Base.var",
"Pulse.Typing.Env.env_extends",
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.typ",
"Pulse.Typing.universe_of",
"Pulse.Typing.tot_typing",
"Pulse.Syntax.Base.tm_vprop",
"Pulse.Checker.Base.continuation_elaborator",
"FStar.Pervasives.dfst",
"Prims.Mkdtuple2",
"Pulse.Checker.Base.checker_result_inv",
"FStar.Pervasives.Mkdtuple3",
"Prims.op_Negation",
"Pulse.Syntax.Base.eq_tm",
"Pulse.Typing.__proj__Mkpost_hint_t__item__ret_ty",
"Pulse.Typing.Env.fail_doc",
"FStar.Pervasives.Native.Some",
"Prims.list",
"FStar.Stubs.Pprint.document",
"Prims.Cons",
"Pulse.PP.text",
"Prims.Nil",
"FStar.Stubs.Pprint.op_Hat_Hat",
"FStar.Stubs.Pprint.op_Hat_Slash_Hat",
"Pulse.PP.indent",
"Pulse.PP.pp",
"Pulse.Syntax.Base.term",
"Pulse.PP.uu___44",
"Prims.bool",
"FStar.Pervasives.Mkdtuple5",
"FStar.Pervasives.dtuple3",
"Prims.dtuple2",
"Prims.l_and",
"Pulse.Typing.Env.disjoint",
"Pulse.Typing.Env.mk_env",
"Pulse.Typing.Env.fstar_env",
"Pulse.Checker.Prover.Substs.nt_substs",
"FStar.Stubs.TypeChecker.Core.tot_or_ghost",
"Pulse.Checker.Prover.Substs.well_typed_nt_substs",
"Pulse.Checker.Prover.Base.op_Star",
"Pulse.Checker.Prover.Substs.nt_subst_term",
"Pulse.Checker.Base.check_equiv_emp",
"Pulse.Syntax.Base.uu___is_Tm_Star",
"Pulse.Syntax.Base.__proj__Mkterm__item__t",
"Pulse.Typing.vprop_equiv",
"Pulse.Syntax.Base.tm_emp",
"Pulse.RuntimeUtils.magic",
"Pulse.Syntax.Pure.tm_type",
"Pulse.Checker.Base.k_elab_trans",
"Pulse.Checker.Base.k_elab_equiv",
"Pulse.Typing.VE_Refl",
"Pulse.Checker.Prover.coerce_eq",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Pulse.Syntax.Naming.subst_elt",
"FStar.Pervasives.dtuple5",
"Pulse.Checker.Prover.prove",
"Pulse.Typing.Env.push_env",
"Pulse.Syntax.Naming.open_term_nv",
"Pulse.Typing.__proj__Mkpost_hint_t__item__post",
"FStar.Pervasives.Native.Mktuple2",
"Pulse.Syntax.Base.ppname",
"Pulse.Syntax.Base.mk_ppname_no_range",
"Pulse.Typing.Env.push_context"
] | [] | false | true | false | false | false | let prove_post_hint
(#g: env)
(#ctxt: vprop)
(r: checker_result_t g ctxt None)
(post_hint: post_hint_opt g)
(rng: range)
: T.Tac (checker_result_t g ctxt post_hint) =
| let g = push_context g "prove_post_hint" rng in
match post_hint with
| None -> r
| Some post_hint ->
let (| x , g2 , (| u_ty , ty , ty_typing |) , (| ctxt' , ctxt'_typing |) , k |) = r in
let ppname = mk_ppname_no_range "_posth" in
let post_hint_opened = open_term_nv post_hint.post (ppname, x) in
if not (eq_tm ty post_hint.ret_ty)
then
let open Pulse.PP in
fail_doc g
(Some rng)
[
text "Error in proving postcondition";
text "The return type" ^^
indent (pp ty) ^/^ text "does not match the expected" ^^ indent (pp post_hint.ret_ty)
]
else
if eq_tm post_hint_opened ctxt'
then (| x, g2, (| u_ty, ty, ty_typing |), (| ctxt', ctxt'_typing |), k |)
else
let (| g3 , nts , _ , remaining_ctxt , k_post |) =
prove #g2 #ctxt' ctxt'_typing (mk_env (fstar_env g2)) #post_hint_opened (RU.magic ())
in
assert (nts == []);
let k_post:continuation_elaborator g2 ctxt' g3 (post_hint_opened * remaining_ctxt) =
coerce_eq k_post ()
in
match check_equiv_emp g3 remaining_ctxt with
| None ->
let open Pulse.PP in
fail_doc g
(Some rng)
[
text "Error in proving postcondition";
text "Inferred postcondition additionally contains" ^^ indent (pp remaining_ctxt);
(if Tm_Star? remaining_ctxt.t
then text "Did you forget to free these resources?"
else text "Did you forget to free this resource?")
]
| Some d ->
let k_post:continuation_elaborator g2 ctxt' g3 post_hint_opened =
k_elab_equiv k_post (VE_Refl _ _) (RU.magic #(vprop_equiv _ _ _) ())
in
(|
x,
g3,
(| u_ty, ty, RU.magic #(tot_typing _ _ _) () |),
(| post_hint_opened, RU.magic #(tot_typing _ _ _) () |),
k_elab_trans k k_post
|) | false |
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.reset | val reset : a: FStar.Ghost.erased EverCrypt.Hash.alg
-> Hacl.Streaming.Functor.reset_st EverCrypt.Hash.Incremental.evercrypt_hash
(FStar.Ghost.hide (FStar.Ghost.reveal a))
(EverCrypt.Hash.state (FStar.Ghost.reveal a))
(FStar.Ghost.erased Prims.unit) | let reset (a: G.erased Hash.alg) = F.reset evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 100,
"end_line": 167,
"start_col": 0,
"start_line": 167
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a
inline_for_extraction noextract
let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
()
inline_for_extraction noextract
let prev_length_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Incremental.prev_length_t a
=
if is_keccak a then
()
else
i
#push-options "--z3rlimit 500"
inline_for_extraction noextract
let evercrypt_hash : block Hash.alg =
Block
Erased
agile_state
(stateful_unused Hash.alg)
unit
Hacl.Hash.Definitions.max_input_len64
(fun a () -> Spec.Hash.Definitions.hash_length a)
block_len
block_len // No vectorization
(fun _ -> 0ul)
(fun _ _ -> S.empty)
(fun a _ -> Spec.Agile.Hash.init a)
(fun a s prevlen input ->
let prevlen = extra_state_of_nat a prevlen in
Spec.Agile.Hash.update_multi a s prevlen input)
(fun a s prevlen input ->
let prevlen = prev_length_of_nat a prevlen in
Spec.Hash.Incremental.update_last a s prevlen input)
(fun a _ s () -> Spec.Agile.Hash.finish a s ())
(fun a _ s () -> Spec.Agile.Hash.hash a s)
(fun a s prevlen ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_zero_blake a prevlen s
else
Spec.Hash.Lemmas.update_multi_zero a s)
(* update_multi_associative *)
(fun a s prevlen1 prevlen2 input1 input2 ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_associative_blake a s prevlen1 prevlen2 input1 input2
else
Spec.Hash.Lemmas.update_multi_associative a s input1 input2)
(* spec_is_incremental *)
(fun a _ input () ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input ())
EverCrypt.Hash.alg_of_state
(fun i _ _ -> EverCrypt.Hash.init #i)
(fun i s prevlen blocks len -> EverCrypt.Hash.update_multi #i s prevlen blocks len)
(fun i s prevlen last last_len ->
EverCrypt.Hash.update_last #i s prevlen last last_len)
(fun i _ s dst _ -> EverCrypt.Hash.finish #i s dst)
#pop-options
let state_t =
F.state_s evercrypt_hash SHA2_256 ((agile_state).s SHA2_256) (G.erased unit)
// Public API (streaming)
// ----------------------
[@@ Comment
"Allocate initial state for the agile hash. The argument `a` stands for the
choice of algorithm (see Hacl_Spec.h). This API will automatically pick the most
efficient implementation, provided you have called EverCrypt_AutoConfig2_init()
before. The state is to be freed by calling `free`."]
let malloc a = F.malloc evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) ()
[@@ Comment | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.Ghost.erased EverCrypt.Hash.alg
-> Hacl.Streaming.Functor.reset_st EverCrypt.Hash.Incremental.evercrypt_hash
(FStar.Ghost.hide (FStar.Ghost.reveal a))
(EverCrypt.Hash.state (FStar.Ghost.reveal a))
(FStar.Ghost.erased Prims.unit) | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"EverCrypt.Hash.alg",
"Hacl.Streaming.Functor.reset",
"Spec.Hash.Definitions.fixed_len_alg",
"EverCrypt.Hash.Incremental.evercrypt_hash",
"EverCrypt.Hash.state",
"FStar.Ghost.reveal",
"Prims.unit",
"Hacl.Streaming.Functor.reset_st",
"FStar.Ghost.hide"
] | [] | false | false | false | false | false | let reset (a: G.erased Hash.alg) =
| F.reset evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) | false |
|
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.state_t | val state_t : Type0 | let state_t =
F.state_s evercrypt_hash SHA2_256 ((agile_state).s SHA2_256) (G.erased unit) | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 78,
"end_line": 153,
"start_col": 0,
"start_line": 152
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a
inline_for_extraction noextract
let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
()
inline_for_extraction noextract
let prev_length_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Incremental.prev_length_t a
=
if is_keccak a then
()
else
i
#push-options "--z3rlimit 500"
inline_for_extraction noextract
let evercrypt_hash : block Hash.alg =
Block
Erased
agile_state
(stateful_unused Hash.alg)
unit
Hacl.Hash.Definitions.max_input_len64
(fun a () -> Spec.Hash.Definitions.hash_length a)
block_len
block_len // No vectorization
(fun _ -> 0ul)
(fun _ _ -> S.empty)
(fun a _ -> Spec.Agile.Hash.init a)
(fun a s prevlen input ->
let prevlen = extra_state_of_nat a prevlen in
Spec.Agile.Hash.update_multi a s prevlen input)
(fun a s prevlen input ->
let prevlen = prev_length_of_nat a prevlen in
Spec.Hash.Incremental.update_last a s prevlen input)
(fun a _ s () -> Spec.Agile.Hash.finish a s ())
(fun a _ s () -> Spec.Agile.Hash.hash a s)
(fun a s prevlen ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_zero_blake a prevlen s
else
Spec.Hash.Lemmas.update_multi_zero a s)
(* update_multi_associative *)
(fun a s prevlen1 prevlen2 input1 input2 ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_associative_blake a s prevlen1 prevlen2 input1 input2
else
Spec.Hash.Lemmas.update_multi_associative a s input1 input2)
(* spec_is_incremental *)
(fun a _ input () ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input ())
EverCrypt.Hash.alg_of_state
(fun i _ _ -> EverCrypt.Hash.init #i)
(fun i s prevlen blocks len -> EverCrypt.Hash.update_multi #i s prevlen blocks len)
(fun i s prevlen last last_len ->
EverCrypt.Hash.update_last #i s prevlen last last_len)
(fun i _ s dst _ -> EverCrypt.Hash.finish #i s dst)
#pop-options | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.state_s",
"Spec.Hash.Definitions.fixed_len_alg",
"EverCrypt.Hash.Incremental.evercrypt_hash",
"Spec.Hash.Definitions.SHA2_256",
"Hacl.Streaming.Interface.__proj__Stateful__item__s",
"EverCrypt.Hash.Incremental.agile_state",
"FStar.Ghost.erased",
"Prims.unit"
] | [] | false | false | false | true | true | let state_t =
| F.state_s evercrypt_hash SHA2_256 ((agile_state).s SHA2_256) (G.erased unit) | false |
|
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.digest_st | val digest_st : a: Spec.Hash.Definitions.fixed_len_alg -> Type0 | let digest_st a = F.digest_st evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 87,
"end_line": 196,
"start_col": 0,
"start_line": 196
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a
inline_for_extraction noextract
let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
()
inline_for_extraction noextract
let prev_length_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Incremental.prev_length_t a
=
if is_keccak a then
()
else
i
#push-options "--z3rlimit 500"
inline_for_extraction noextract
let evercrypt_hash : block Hash.alg =
Block
Erased
agile_state
(stateful_unused Hash.alg)
unit
Hacl.Hash.Definitions.max_input_len64
(fun a () -> Spec.Hash.Definitions.hash_length a)
block_len
block_len // No vectorization
(fun _ -> 0ul)
(fun _ _ -> S.empty)
(fun a _ -> Spec.Agile.Hash.init a)
(fun a s prevlen input ->
let prevlen = extra_state_of_nat a prevlen in
Spec.Agile.Hash.update_multi a s prevlen input)
(fun a s prevlen input ->
let prevlen = prev_length_of_nat a prevlen in
Spec.Hash.Incremental.update_last a s prevlen input)
(fun a _ s () -> Spec.Agile.Hash.finish a s ())
(fun a _ s () -> Spec.Agile.Hash.hash a s)
(fun a s prevlen ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_zero_blake a prevlen s
else
Spec.Hash.Lemmas.update_multi_zero a s)
(* update_multi_associative *)
(fun a s prevlen1 prevlen2 input1 input2 ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_associative_blake a s prevlen1 prevlen2 input1 input2
else
Spec.Hash.Lemmas.update_multi_associative a s input1 input2)
(* spec_is_incremental *)
(fun a _ input () ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input ())
EverCrypt.Hash.alg_of_state
(fun i _ _ -> EverCrypt.Hash.init #i)
(fun i s prevlen blocks len -> EverCrypt.Hash.update_multi #i s prevlen blocks len)
(fun i s prevlen last last_len ->
EverCrypt.Hash.update_last #i s prevlen last last_len)
(fun i _ s dst _ -> EverCrypt.Hash.finish #i s dst)
#pop-options
let state_t =
F.state_s evercrypt_hash SHA2_256 ((agile_state).s SHA2_256) (G.erased unit)
// Public API (streaming)
// ----------------------
[@@ Comment
"Allocate initial state for the agile hash. The argument `a` stands for the
choice of algorithm (see Hacl_Spec.h). This API will automatically pick the most
efficient implementation, provided you have called EverCrypt_AutoConfig2_init()
before. The state is to be freed by calling `free`."]
let malloc a = F.malloc evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) ()
[@@ Comment
"Reset an existing state to the initial hash state with empty data."]
let reset (a: G.erased Hash.alg) = F.reset evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Feed an arbitrary amount of data into the hash. This function returns
EverCrypt_Error_Success for success, or EverCrypt_Error_MaximumLengthExceeded if
the combined length of all of the data passed to `update` (since the last call
to `init`) exceeds 2^61-1 bytes or 2^64-1 bytes, depending on the choice of
algorithm. Both limits are unlikely to be attained in practice."]
let update (i: G.erased Hash.alg)
(state:F.state evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit))
(chunk: B.buffer uint8)
(chunk_len: UInt32.t):
Stack EverCrypt.Error.error_code
(requires fun h0 -> F.update_pre evercrypt_hash i state chunk chunk_len h0)
(ensures fun h0 e h1 ->
match e with
| EverCrypt.Error.Success ->
S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i) /\
F.update_post evercrypt_hash i state chunk chunk_len h0 h1
| EverCrypt.Error.MaximumLengthExceeded ->
h0 == h1 /\
not (S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i))
| _ -> False)
=
match F.update evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit) state chunk chunk_len with
| Hacl.Streaming.Types.Success -> EverCrypt.Error.Success
| Hacl.Streaming.Types.MaximumLengthExceeded -> EverCrypt.Error.MaximumLengthExceeded | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.fixed_len_alg -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.fixed_len_alg",
"Hacl.Streaming.Functor.digest_st",
"EverCrypt.Hash.Incremental.evercrypt_hash",
"EverCrypt.Hash.state",
"FStar.Ghost.erased",
"Prims.unit"
] | [] | false | false | false | true | true | let digest_st a =
| F.digest_st evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) | false |
|
Hacl.Spec.K256.Finv.fst | Hacl.Spec.K256.Finv.lemma_pow_pow_mod_mul | val lemma_pow_pow_mod_mul: f:S.felem -> a:nat -> b:nat -> c:nat ->
Lemma (S.fmul (M.pow (M.pow f a % S.prime) b % S.prime) (M.pow f c % S.prime) == M.pow f (a * b + c) % S.prime) | val lemma_pow_pow_mod_mul: f:S.felem -> a:nat -> b:nat -> c:nat ->
Lemma (S.fmul (M.pow (M.pow f a % S.prime) b % S.prime) (M.pow f c % S.prime) == M.pow f (a * b + c) % S.prime) | let lemma_pow_pow_mod_mul f a b c =
calc (==) {
S.fmul (M.pow (M.pow f a % S.prime) b % S.prime) (M.pow f c % S.prime);
(==) { lemma_pow_pow_mod f a b }
S.fmul (M.pow f (a * b) % S.prime) (M.pow f c % S.prime);
(==) { lemma_pow_mod_mul f (a * b) c }
M.pow f (a * b + c) % S.prime;
} | {
"file_name": "code/k256/Hacl.Spec.K256.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 134,
"start_col": 0,
"start_line": 127
} | module Hacl.Spec.K256.Finv
open FStar.Mul
module SE = Spec.Exponentiation
module LE = Lib.Exponentiation
module M = Lib.NatMod
module S = Spec.K256
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.prime
let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.felem = {
SE.a_spec = S.felem;
SE.comm_monoid = nat_mod_comm_monoid;
SE.refl = (fun (x:S.felem) -> x);
}
val one_mod : SE.one_st S.felem mk_to_nat_mod_comm_monoid
let one_mod _ = S.one
val mul_mod : SE.mul_st S.felem mk_to_nat_mod_comm_monoid
let mul_mod x y = S.fmul x y
val sqr_mod : SE.sqr_st S.felem mk_to_nat_mod_comm_monoid
let sqr_mod x = S.fmul x x
let mk_nat_mod_concrete_ops : SE.concrete_ops S.felem = {
SE.to = mk_to_nat_mod_comm_monoid;
SE.one = one_mod;
SE.mul = mul_mod;
SE.sqr = sqr_mod;
}
let fsquare_times (a:S.felem) (b:nat) : S.felem =
SE.exp_pow2 mk_nat_mod_concrete_ops a b
val fsquare_times_lemma: a:S.felem -> b:nat ->
Lemma (fsquare_times a b == M.pow a (pow2 b) % S.prime)
let fsquare_times_lemma a b =
SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b;
LE.exp_pow2_lemma nat_mod_comm_monoid a b;
assert (fsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b));
M.lemma_pow_nat_mod_is_pow #S.prime a (pow2 b)
val fexp_223_23: f:S.felem -> tuple2 S.felem S.felem
let fexp_223_23 f =
let x2 = S.fmul (fsquare_times f 1) f in
let x3 = S.fmul (fsquare_times x2 1) f in
let x6 = S.fmul (fsquare_times x3 3) x3 in
let x9 = S.fmul (fsquare_times x6 3) x3 in
let x11 = S.fmul (fsquare_times x9 2) x2 in
let x22 = S.fmul (fsquare_times x11 11) x11 in
let x44 = S.fmul (fsquare_times x22 22) x22 in
let x88 = S.fmul (fsquare_times x44 44) x44 in
let x176 = S.fmul (fsquare_times x88 88) x88 in
let x220 = S.fmul (fsquare_times x176 44) x44 in
let x223 = S.fmul (fsquare_times x220 3) x3 in
let r = S.fmul (fsquare_times x223 23) x22 in
r, x2
(**
The algorithm is taken from
https://briansmith.org/ecc-inversion-addition-chains-01
*)
val finv: f:S.felem -> S.felem
let finv f =
let r, x2 = fexp_223_23 f in
let r = S.fmul (fsquare_times r 5) f in
let r = S.fmul (fsquare_times r 3) x2 in
let r = S.fmul (fsquare_times r 2) f in
r
val fsqrt: f:S.felem -> S.felem
let fsqrt f =
let r, x2 = fexp_223_23 f in
let r = S.fmul (fsquare_times r 6) x2 in
let r = fsquare_times r 2 in
r
val is_fsqrt: f:S.felem -> f2:S.felem -> bool
let is_fsqrt f f2 = S.fmul f f = f2
val lemma_pow_mod_1: f:S.felem -> Lemma (f == M.pow f 1 % S.prime)
let lemma_pow_mod_1 f =
M.lemma_pow1 f;
Math.Lemmas.small_mod f S.prime;
assert_norm (pow2 0 = 1);
assert (f == M.pow f 1 % S.prime)
val lemma_pow_mod_mul: f:S.felem -> a:nat -> b:nat ->
Lemma (S.fmul (M.pow f a % S.prime) (M.pow f b % S.prime) == M.pow f (a + b) % S.prime)
let lemma_pow_mod_mul f a b =
calc (==) {
S.fmul (M.pow f a % S.prime) (M.pow f b % S.prime);
(==) {
Math.Lemmas.lemma_mod_mul_distr_l (M.pow f a) (M.pow f b % S.prime) S.prime;
Math.Lemmas.lemma_mod_mul_distr_r (M.pow f a) (M.pow f b) S.prime }
M.pow f a * M.pow f b % S.prime;
(==) { M.lemma_pow_add f a b }
M.pow f (a + b) % S.prime;
}
val lemma_pow_pow_mod: f:S.felem -> a:nat -> b:nat ->
Lemma (M.pow (M.pow f a % S.prime) b % S.prime == M.pow f (a * b) % S.prime)
let lemma_pow_pow_mod f a b =
calc (==) {
M.pow (M.pow f a % S.prime) b % S.prime;
(==) { M.lemma_pow_mod_base (M.pow f a) b S.prime }
M.pow (M.pow f a) b % S.prime;
(==) { M.lemma_pow_mul f a b }
M.pow f (a * b) % S.prime;
}
val lemma_pow_pow_mod_mul: f:S.felem -> a:nat -> b:nat -> c:nat -> | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.K256.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.NatMod",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Spec.K256.PointOps.felem -> a: Prims.nat -> b: Prims.nat -> c: Prims.nat
-> FStar.Pervasives.Lemma
(ensures
Spec.K256.PointOps.fmul (Lib.NatMod.pow (Lib.NatMod.pow f a % Spec.K256.PointOps.prime) b %
Spec.K256.PointOps.prime)
(Lib.NatMod.pow f c % Spec.K256.PointOps.prime) ==
Lib.NatMod.pow f (a * b + c) % Spec.K256.PointOps.prime) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.K256.PointOps.felem",
"Prims.nat",
"FStar.Calc.calc_finish",
"Prims.eq2",
"Spec.K256.PointOps.fmul",
"Prims.op_Modulus",
"Lib.NatMod.pow",
"Spec.K256.PointOps.prime",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Hacl.Spec.K256.Finv.lemma_pow_pow_mod",
"Prims.squash",
"Hacl.Spec.K256.Finv.lemma_pow_mod_mul"
] | [] | false | false | true | false | false | let lemma_pow_pow_mod_mul f a b c =
| calc ( == ) {
S.fmul (M.pow (M.pow f a % S.prime) b % S.prime) (M.pow f c % S.prime);
( == ) { lemma_pow_pow_mod f a b }
S.fmul (M.pow f (a * b) % S.prime) (M.pow f c % S.prime);
( == ) { lemma_pow_mod_mul f (a * b) c }
M.pow f (a * b + c) % S.prime;
} | false |
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.hashed | val hashed : h: FStar.Monotonic.HyperStack.mem -> s: EverCrypt.Hash.Incremental.state a
-> Prims.GTot Hacl.Streaming.Functor.bytes | let hashed #a (h: HS.mem) (s: state a) =
F.seen evercrypt_hash a h s | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 348,
"start_col": 0,
"start_line": 347
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a
inline_for_extraction noextract
let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
()
inline_for_extraction noextract
let prev_length_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Incremental.prev_length_t a
=
if is_keccak a then
()
else
i
#push-options "--z3rlimit 500"
inline_for_extraction noextract
let evercrypt_hash : block Hash.alg =
Block
Erased
agile_state
(stateful_unused Hash.alg)
unit
Hacl.Hash.Definitions.max_input_len64
(fun a () -> Spec.Hash.Definitions.hash_length a)
block_len
block_len // No vectorization
(fun _ -> 0ul)
(fun _ _ -> S.empty)
(fun a _ -> Spec.Agile.Hash.init a)
(fun a s prevlen input ->
let prevlen = extra_state_of_nat a prevlen in
Spec.Agile.Hash.update_multi a s prevlen input)
(fun a s prevlen input ->
let prevlen = prev_length_of_nat a prevlen in
Spec.Hash.Incremental.update_last a s prevlen input)
(fun a _ s () -> Spec.Agile.Hash.finish a s ())
(fun a _ s () -> Spec.Agile.Hash.hash a s)
(fun a s prevlen ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_zero_blake a prevlen s
else
Spec.Hash.Lemmas.update_multi_zero a s)
(* update_multi_associative *)
(fun a s prevlen1 prevlen2 input1 input2 ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_associative_blake a s prevlen1 prevlen2 input1 input2
else
Spec.Hash.Lemmas.update_multi_associative a s input1 input2)
(* spec_is_incremental *)
(fun a _ input () ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input ())
EverCrypt.Hash.alg_of_state
(fun i _ _ -> EverCrypt.Hash.init #i)
(fun i s prevlen blocks len -> EverCrypt.Hash.update_multi #i s prevlen blocks len)
(fun i s prevlen last last_len ->
EverCrypt.Hash.update_last #i s prevlen last last_len)
(fun i _ s dst _ -> EverCrypt.Hash.finish #i s dst)
#pop-options
let state_t =
F.state_s evercrypt_hash SHA2_256 ((agile_state).s SHA2_256) (G.erased unit)
// Public API (streaming)
// ----------------------
[@@ Comment
"Allocate initial state for the agile hash. The argument `a` stands for the
choice of algorithm (see Hacl_Spec.h). This API will automatically pick the most
efficient implementation, provided you have called EverCrypt_AutoConfig2_init()
before. The state is to be freed by calling `free`."]
let malloc a = F.malloc evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) ()
[@@ Comment
"Reset an existing state to the initial hash state with empty data."]
let reset (a: G.erased Hash.alg) = F.reset evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Feed an arbitrary amount of data into the hash. This function returns
EverCrypt_Error_Success for success, or EverCrypt_Error_MaximumLengthExceeded if
the combined length of all of the data passed to `update` (since the last call
to `init`) exceeds 2^61-1 bytes or 2^64-1 bytes, depending on the choice of
algorithm. Both limits are unlikely to be attained in practice."]
let update (i: G.erased Hash.alg)
(state:F.state evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit))
(chunk: B.buffer uint8)
(chunk_len: UInt32.t):
Stack EverCrypt.Error.error_code
(requires fun h0 -> F.update_pre evercrypt_hash i state chunk chunk_len h0)
(ensures fun h0 e h1 ->
match e with
| EverCrypt.Error.Success ->
S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i) /\
F.update_post evercrypt_hash i state chunk chunk_len h0 h1
| EverCrypt.Error.MaximumLengthExceeded ->
h0 == h1 /\
not (S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i))
| _ -> False)
=
match F.update evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit) state chunk chunk_len with
| Hacl.Streaming.Types.Success -> EverCrypt.Error.Success
| Hacl.Streaming.Types.MaximumLengthExceeded -> EverCrypt.Error.MaximumLengthExceeded
inline_for_extraction noextract
let digest_st a = F.digest_st evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
/// The wrapper pattern, to ensure that the stack-allocated state is properly
/// monomorphized.
private
let digest_md5: digest_st MD5 = F.digest evercrypt_hash MD5 (EverCrypt.Hash.state MD5) (G.erased unit)
private
let digest_sha1: digest_st SHA1 = F.digest evercrypt_hash SHA1 (EverCrypt.Hash.state SHA1) (G.erased unit)
private
let digest_sha224: digest_st SHA2_224 = F.digest evercrypt_hash SHA2_224 (EverCrypt.Hash.state SHA2_224) (G.erased unit)
private
let digest_sha256: digest_st SHA2_256 = F.digest evercrypt_hash SHA2_256 (EverCrypt.Hash.state SHA2_256) (G.erased unit)
private
let digest_sha3_224: digest_st SHA3_224 = F.digest evercrypt_hash SHA3_224 (EverCrypt.Hash.state SHA3_224) (G.erased unit)
private
let digest_sha3_256: digest_st SHA3_256 = F.digest evercrypt_hash SHA3_256 (EverCrypt.Hash.state SHA3_256) (G.erased unit)
private
let digest_sha3_384: digest_st SHA3_384 = F.digest evercrypt_hash SHA3_384 (EverCrypt.Hash.state SHA3_384) (G.erased unit)
private
let digest_sha3_512: digest_st SHA3_512 = F.digest evercrypt_hash SHA3_512 (EverCrypt.Hash.state SHA3_512) (G.erased unit)
private
let digest_sha384: digest_st SHA2_384 = F.digest evercrypt_hash SHA2_384 (EverCrypt.Hash.state SHA2_384) (G.erased unit)
private
let digest_sha512: digest_st SHA2_512 = F.digest evercrypt_hash SHA2_512 (EverCrypt.Hash.state SHA2_512) (G.erased unit)
private
let digest_blake2s: digest_st Blake2S = F.digest evercrypt_hash Blake2S (EverCrypt.Hash.state Blake2S) (G.erased unit)
private
let digest_blake2b: digest_st Blake2B = F.digest evercrypt_hash Blake2B (EverCrypt.Hash.state Blake2B) (G.erased unit)
[@@ Comment
"Perform a run-time test to determine which algorithm was chosen for the given piece of state."]
let alg_of_state (a: G.erased Hash.alg) = F.index_of_state evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Write the resulting hash into `output`, an array whose length is
algorithm-specific. You can use the macros defined earlier in this file to
allocate a destination buffer of the right length. The state remains valid after
a call to `digest`, meaning the user may feed more data into the hash via
`update`. (The finish function operates on an internal copy of the state and
therefore does not invalidate the client-held state.)"]
val digest: a:G.erased Hash.alg -> digest_st a
let digest a state output l =
let a = alg_of_state a state in
match a with
| MD5 -> digest_md5 state output l
| SHA1 -> digest_sha1 state output l
| SHA2_224 -> digest_sha224 state output l
| SHA2_256 -> digest_sha256 state output l
| SHA2_384 -> digest_sha384 state output l
| SHA2_512 -> digest_sha512 state output l
| SHA3_224 -> digest_sha3_224 state output l
| SHA3_256 -> digest_sha3_256 state output l
| SHA3_384 -> digest_sha3_384 state output l
| SHA3_512 -> digest_sha3_512 state output l
| Blake2S -> digest_blake2s state output l
| Blake2B -> digest_blake2b state output l
[@@ Comment
"Free a state previously allocated with `create_in`."]
let free (i: G.erased Hash.alg) = F.free evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit)
// Private API (one-shot, multiplexing)
// ------------------------------------
private
val hash_256: Hacl.Hash.Definitions.hash_st SHA2_256
// A full one-shot hash that relies on vale at each multiplexing point
let hash_256 output input input_len =
let open EverCrypt.Hash in
// TODO: This function now only exists for SHA1 and MD5
Hacl.Hash.MD.mk_hash SHA2_256 Hacl.Hash.SHA2.alloca_256 update_multi_256
Hacl.Hash.SHA2.update_last_256 Hacl.Hash.SHA2.finish_256 output input input_len
private
val hash_224: Hacl.Hash.Definitions.hash_st SHA2_224
let hash_224 output input input_len =
let open EverCrypt.Hash in
Hacl.Hash.MD.mk_hash SHA2_224 Hacl.Hash.SHA2.alloca_224 update_multi_224
Hacl.Hash.SHA2.update_last_224 Hacl.Hash.SHA2.finish_224 output input input_len
// Public API (one-shot, agile and multiplexing)
// ---------------------------------------------
// NOTE: this function goes through all the Hacl.Hash.* wrappers which export
// the correct agile low-level type, and thus does not need to be aware of the
// implementation of Spec.Agile.Hash (no friend-ing).
//
// ALSO: for some reason, this function was historically exported with an order
// of arguments different from Hacl.Hash.Definitions.hash_st a. Would be worth
// fixing at some point.
[@@ Comment
"Hash `input`, of len `input_len`, into `output`, an array whose length is determined by
your choice of algorithm `a` (see Hacl_Spec.h). You can use the macros defined
earlier in this file to allocate a destination buffer of the right length. This
API will automatically pick the most efficient implementation, provided you have
called EverCrypt_AutoConfig2_init() before. "]
val hash:
a:Hash.alg ->
output:B.buffer Lib.IntTypes.uint8 {B.length output = hash_length a} ->
input:B.buffer Lib.IntTypes.uint8 ->
input_len:FStar.UInt32.t {B.length input = FStar.UInt32.v input_len /\ FStar.UInt32.v input_len `less_than_max_input_length` a} ->
Stack unit
(requires fun h0 ->
B.live h0 output /\
B.live h0 input /\
B.(loc_disjoint (loc_buffer input) (loc_buffer output)))
(ensures fun h0 _ h1 ->
B.(modifies (loc_buffer output) h0 h1) /\
B.as_seq h1 output == Spec.Agile.Hash.hash a (B.as_seq h0 input))
let hash a output input input_len =
match a with
| MD5 -> Hacl.Hash.MD5.hash_oneshot output input input_len
| SHA1 -> Hacl.Hash.SHA1.hash_oneshot output input input_len
| SHA2_224 -> hash_224 output input input_len
| SHA2_256 -> hash_256 output input input_len
| SHA2_384 -> Hacl.Streaming.SHA2.hash_384 output input input_len
| SHA2_512 -> Hacl.Streaming.SHA2.hash_512 output input input_len
| SHA3_224 -> Hacl.Hash.SHA3.hash SHA3_224 output input input_len
| SHA3_256 -> Hacl.Hash.SHA3.hash SHA3_256 output input input_len
| SHA3_384 -> Hacl.Hash.SHA3.hash SHA3_384 output input input_len
| SHA3_512 -> Hacl.Hash.SHA3.hash SHA3_512 output input input_len
| Blake2S ->
if EverCrypt.TargetConfig.hacl_can_compile_vec128 then
let vec128 = EverCrypt.AutoConfig2.has_vec128 () in
if vec128 then
Hacl.Hash.Blake2s_128.hash output input input_len
else
Hacl.Hash.Blake2s_32.hash output input input_len
else
Hacl.Hash.Blake2s_32.hash output input input_len
| Blake2B ->
if EverCrypt.TargetConfig.hacl_can_compile_vec256 then
let vec256 = EverCrypt.AutoConfig2.has_vec256 () in
if vec256 then
Hacl.Hash.Blake2b_256.hash output input input_len
else
Hacl.Hash.Blake2b_32.hash output input input_len
else
Hacl.Hash.Blake2b_32.hash output input input_len
// Public API (verified clients)
// -----------------------------
/// Finally, a few helpers predicates to make things easier for clients...
inline_for_extraction noextract
let state (a: Hash.alg) = F.state evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | h: FStar.Monotonic.HyperStack.mem -> s: EverCrypt.Hash.Incremental.state a
-> Prims.GTot Hacl.Streaming.Functor.bytes | Prims.GTot | [
"sometrivial"
] | [] | [
"EverCrypt.Hash.alg",
"FStar.Monotonic.HyperStack.mem",
"EverCrypt.Hash.Incremental.state",
"Hacl.Streaming.Functor.seen",
"Spec.Hash.Definitions.fixed_len_alg",
"EverCrypt.Hash.Incremental.evercrypt_hash",
"Hacl.Streaming.Functor.bytes"
] | [] | false | false | false | false | false | let hashed #a (h: HS.mem) (s: state a) =
| F.seen evercrypt_hash a h s | false |
|
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.malloc | val malloc : a: Spec.Hash.Definitions.fixed_len_alg -> r: FStar.Monotonic.HyperHeap.rid
-> FStar.HyperStack.ST.ST
(Hacl.Streaming.Functor.state EverCrypt.Hash.Incremental.evercrypt_hash
a
(EverCrypt.Hash.state a)
(FStar.Ghost.erased Prims.unit)) | let malloc a = F.malloc evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) () | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 84,
"end_line": 163,
"start_col": 0,
"start_line": 163
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a
inline_for_extraction noextract
let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
()
inline_for_extraction noextract
let prev_length_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Incremental.prev_length_t a
=
if is_keccak a then
()
else
i
#push-options "--z3rlimit 500"
inline_for_extraction noextract
let evercrypt_hash : block Hash.alg =
Block
Erased
agile_state
(stateful_unused Hash.alg)
unit
Hacl.Hash.Definitions.max_input_len64
(fun a () -> Spec.Hash.Definitions.hash_length a)
block_len
block_len // No vectorization
(fun _ -> 0ul)
(fun _ _ -> S.empty)
(fun a _ -> Spec.Agile.Hash.init a)
(fun a s prevlen input ->
let prevlen = extra_state_of_nat a prevlen in
Spec.Agile.Hash.update_multi a s prevlen input)
(fun a s prevlen input ->
let prevlen = prev_length_of_nat a prevlen in
Spec.Hash.Incremental.update_last a s prevlen input)
(fun a _ s () -> Spec.Agile.Hash.finish a s ())
(fun a _ s () -> Spec.Agile.Hash.hash a s)
(fun a s prevlen ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_zero_blake a prevlen s
else
Spec.Hash.Lemmas.update_multi_zero a s)
(* update_multi_associative *)
(fun a s prevlen1 prevlen2 input1 input2 ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_associative_blake a s prevlen1 prevlen2 input1 input2
else
Spec.Hash.Lemmas.update_multi_associative a s input1 input2)
(* spec_is_incremental *)
(fun a _ input () ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input ())
EverCrypt.Hash.alg_of_state
(fun i _ _ -> EverCrypt.Hash.init #i)
(fun i s prevlen blocks len -> EverCrypt.Hash.update_multi #i s prevlen blocks len)
(fun i s prevlen last last_len ->
EverCrypt.Hash.update_last #i s prevlen last last_len)
(fun i _ s dst _ -> EverCrypt.Hash.finish #i s dst)
#pop-options
let state_t =
F.state_s evercrypt_hash SHA2_256 ((agile_state).s SHA2_256) (G.erased unit)
// Public API (streaming)
// ----------------------
[@@ Comment
"Allocate initial state for the agile hash. The argument `a` stands for the
choice of algorithm (see Hacl_Spec.h). This API will automatically pick the most
efficient implementation, provided you have called EverCrypt_AutoConfig2_init() | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.fixed_len_alg -> r: FStar.Monotonic.HyperHeap.rid
-> FStar.HyperStack.ST.ST
(Hacl.Streaming.Functor.state EverCrypt.Hash.Incremental.evercrypt_hash
a
(EverCrypt.Hash.state a)
(FStar.Ghost.erased Prims.unit)) | FStar.HyperStack.ST.ST | [] | [] | [
"Spec.Hash.Definitions.fixed_len_alg",
"Hacl.Streaming.Functor.malloc",
"EverCrypt.Hash.Incremental.evercrypt_hash",
"EverCrypt.Hash.state",
"FStar.Ghost.erased",
"Prims.unit",
"FStar.Monotonic.HyperHeap.rid",
"Hacl.Streaming.Functor.state",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Hacl.Streaming.Interface.__proj__Stateful__item__invariant",
"Hacl.Streaming.Interface.__proj__Block__item__key",
"FStar.HyperStack.ST.is_eternal_region",
"Hacl.Streaming.Functor.invariant",
"Hacl.Streaming.Functor.freeable",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Hacl.Streaming.Functor.uint8",
"Hacl.Streaming.Functor.seen",
"FStar.Seq.Base.empty",
"Hacl.Streaming.Interface.__proj__Stateful__item__t",
"Hacl.Streaming.Functor.reveal_key",
"Hacl.Streaming.Interface.__proj__Stateful__item__v",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_none",
"LowStar.Monotonic.Buffer.fresh_loc",
"Hacl.Streaming.Functor.footprint",
"LowStar.Monotonic.Buffer.loc_includes",
"LowStar.Monotonic.Buffer.loc_region_only"
] | [] | false | true | false | false | false | let malloc a =
| F.malloc evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) () | false |
|
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.agile_state | val agile_state:stateful Hash.alg | val agile_state:stateful Hash.alg | let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i) | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 37,
"end_line": 52,
"start_col": 0,
"start_line": 33
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// --------------------------------------------------- | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Streaming.Interface.stateful Spec.Hash.Definitions.fixed_len_alg | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Interface.Stateful",
"EverCrypt.Hash.alg",
"EverCrypt.Hash.state",
"FStar.Monotonic.HyperStack.mem",
"EverCrypt.Hash.footprint",
"LowStar.Monotonic.Buffer.loc",
"EverCrypt.Hash.freeable",
"EverCrypt.Hash.invariant",
"Spec.Hash.Definitions.words_state",
"EverCrypt.Hash.repr",
"EverCrypt.Hash.invariant_loc_in_footprint",
"Prims.unit",
"EverCrypt.Hash.frame_invariant_implies_footprint_preservation",
"EverCrypt.Hash.frame_invariant",
"EverCrypt.Hash.alloca",
"EverCrypt.Hash.create_in",
"FStar.Ghost.erased",
"EverCrypt.Hash.free",
"Prims.l_and",
"LowStar.Monotonic.Buffer.modifies",
"FStar.Ghost.reveal",
"EverCrypt.Hash.copy",
"LowStar.Monotonic.Buffer.loc_disjoint",
"Prims.eq2",
"Prims.l_imp"
] | [] | false | false | false | true | false | let agile_state:stateful Hash.alg =
| Stateful EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i) | false |
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.update | val update
(i: G.erased Hash.alg)
(state: F.state evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit))
(chunk: B.buffer uint8)
(chunk_len: UInt32.t)
: Stack EverCrypt.Error.error_code
(requires fun h0 -> F.update_pre evercrypt_hash i state chunk chunk_len h0)
(ensures
fun h0 e h1 ->
match e with
| EverCrypt.Error.Success ->
S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <=
U64.v (evercrypt_hash.max_input_len i) /\
F.update_post evercrypt_hash i state chunk chunk_len h0 h1
| EverCrypt.Error.MaximumLengthExceeded ->
h0 == h1 /\
not (S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <=
U64.v (evercrypt_hash.max_input_len i))
| _ -> False) | val update
(i: G.erased Hash.alg)
(state: F.state evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit))
(chunk: B.buffer uint8)
(chunk_len: UInt32.t)
: Stack EverCrypt.Error.error_code
(requires fun h0 -> F.update_pre evercrypt_hash i state chunk chunk_len h0)
(ensures
fun h0 e h1 ->
match e with
| EverCrypt.Error.Success ->
S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <=
U64.v (evercrypt_hash.max_input_len i) /\
F.update_post evercrypt_hash i state chunk chunk_len h0 h1
| EverCrypt.Error.MaximumLengthExceeded ->
h0 == h1 /\
not (S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <=
U64.v (evercrypt_hash.max_input_len i))
| _ -> False) | let update (i: G.erased Hash.alg)
(state:F.state evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit))
(chunk: B.buffer uint8)
(chunk_len: UInt32.t):
Stack EverCrypt.Error.error_code
(requires fun h0 -> F.update_pre evercrypt_hash i state chunk chunk_len h0)
(ensures fun h0 e h1 ->
match e with
| EverCrypt.Error.Success ->
S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i) /\
F.update_post evercrypt_hash i state chunk chunk_len h0 h1
| EverCrypt.Error.MaximumLengthExceeded ->
h0 == h1 /\
not (S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i))
| _ -> False)
=
match F.update evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit) state chunk chunk_len with
| Hacl.Streaming.Types.Success -> EverCrypt.Error.Success
| Hacl.Streaming.Types.MaximumLengthExceeded -> EverCrypt.Error.MaximumLengthExceeded | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 87,
"end_line": 193,
"start_col": 0,
"start_line": 175
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a
inline_for_extraction noextract
let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
()
inline_for_extraction noextract
let prev_length_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Incremental.prev_length_t a
=
if is_keccak a then
()
else
i
#push-options "--z3rlimit 500"
inline_for_extraction noextract
let evercrypt_hash : block Hash.alg =
Block
Erased
agile_state
(stateful_unused Hash.alg)
unit
Hacl.Hash.Definitions.max_input_len64
(fun a () -> Spec.Hash.Definitions.hash_length a)
block_len
block_len // No vectorization
(fun _ -> 0ul)
(fun _ _ -> S.empty)
(fun a _ -> Spec.Agile.Hash.init a)
(fun a s prevlen input ->
let prevlen = extra_state_of_nat a prevlen in
Spec.Agile.Hash.update_multi a s prevlen input)
(fun a s prevlen input ->
let prevlen = prev_length_of_nat a prevlen in
Spec.Hash.Incremental.update_last a s prevlen input)
(fun a _ s () -> Spec.Agile.Hash.finish a s ())
(fun a _ s () -> Spec.Agile.Hash.hash a s)
(fun a s prevlen ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_zero_blake a prevlen s
else
Spec.Hash.Lemmas.update_multi_zero a s)
(* update_multi_associative *)
(fun a s prevlen1 prevlen2 input1 input2 ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_associative_blake a s prevlen1 prevlen2 input1 input2
else
Spec.Hash.Lemmas.update_multi_associative a s input1 input2)
(* spec_is_incremental *)
(fun a _ input () ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input ())
EverCrypt.Hash.alg_of_state
(fun i _ _ -> EverCrypt.Hash.init #i)
(fun i s prevlen blocks len -> EverCrypt.Hash.update_multi #i s prevlen blocks len)
(fun i s prevlen last last_len ->
EverCrypt.Hash.update_last #i s prevlen last last_len)
(fun i _ s dst _ -> EverCrypt.Hash.finish #i s dst)
#pop-options
let state_t =
F.state_s evercrypt_hash SHA2_256 ((agile_state).s SHA2_256) (G.erased unit)
// Public API (streaming)
// ----------------------
[@@ Comment
"Allocate initial state for the agile hash. The argument `a` stands for the
choice of algorithm (see Hacl_Spec.h). This API will automatically pick the most
efficient implementation, provided you have called EverCrypt_AutoConfig2_init()
before. The state is to be freed by calling `free`."]
let malloc a = F.malloc evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) ()
[@@ Comment
"Reset an existing state to the initial hash state with empty data."]
let reset (a: G.erased Hash.alg) = F.reset evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Feed an arbitrary amount of data into the hash. This function returns
EverCrypt_Error_Success for success, or EverCrypt_Error_MaximumLengthExceeded if
the combined length of all of the data passed to `update` (since the last call
to `init`) exceeds 2^61-1 bytes or 2^64-1 bytes, depending on the choice of | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
i: FStar.Ghost.erased EverCrypt.Hash.alg ->
state:
Hacl.Streaming.Functor.state EverCrypt.Hash.Incremental.evercrypt_hash
(FStar.Ghost.reveal i)
(EverCrypt.Hash.state (FStar.Ghost.reveal i))
(FStar.Ghost.erased Prims.unit) ->
chunk: LowStar.Buffer.buffer Hacl.Streaming.Interface.uint8 ->
chunk_len: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack EverCrypt.Error.error_code | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.Ghost.erased",
"EverCrypt.Hash.alg",
"Hacl.Streaming.Functor.state",
"Spec.Hash.Definitions.fixed_len_alg",
"EverCrypt.Hash.Incremental.evercrypt_hash",
"FStar.Ghost.reveal",
"EverCrypt.Hash.state",
"Prims.unit",
"LowStar.Buffer.buffer",
"Hacl.Streaming.Interface.uint8",
"FStar.UInt32.t",
"EverCrypt.Error.Success",
"EverCrypt.Error.MaximumLengthExceeded",
"EverCrypt.Error.error_code",
"Hacl.Streaming.Types.error_code",
"Hacl.Streaming.Functor.update",
"FStar.Monotonic.HyperStack.mem",
"Hacl.Streaming.Functor.update_pre",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.Seq.Base.length",
"Hacl.Streaming.Functor.uint8",
"Hacl.Streaming.Functor.seen",
"FStar.UInt32.v",
"FStar.UInt64.v",
"Hacl.Streaming.Interface.__proj__Block__item__max_input_len",
"Hacl.Streaming.Functor.update_post",
"Prims.eq2",
"Prims.op_Negation",
"Prims.l_False"
] | [] | false | true | false | false | false | let update
(i: G.erased Hash.alg)
(state: F.state evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit))
(chunk: B.buffer uint8)
(chunk_len: UInt32.t)
: Stack EverCrypt.Error.error_code
(requires fun h0 -> F.update_pre evercrypt_hash i state chunk chunk_len h0)
(ensures
fun h0 e h1 ->
match e with
| EverCrypt.Error.Success ->
S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <=
U64.v (evercrypt_hash.max_input_len i) /\
F.update_post evercrypt_hash i state chunk chunk_len h0 h1
| EverCrypt.Error.MaximumLengthExceeded ->
h0 == h1 /\
not (S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <=
U64.v (evercrypt_hash.max_input_len i))
| _ -> False) =
| match F.update evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit) state chunk chunk_len with
| Hacl.Streaming.Types.Success -> EverCrypt.Error.Success
| Hacl.Streaming.Types.MaximumLengthExceeded -> EverCrypt.Error.MaximumLengthExceeded | false |
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.prev_length_of_nat | val prev_length_of_nat (a: hash_alg) (i: nat{i % U32.v (block_len a) = 0})
: Spec.Hash.Incremental.prev_length_t a | val prev_length_of_nat (a: hash_alg) (i: nat{i % U32.v (block_len a) = 0})
: Spec.Hash.Incremental.prev_length_t a | let prev_length_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Incremental.prev_length_t a
=
if is_keccak a then
()
else
i | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 96,
"start_col": 0,
"start_line": 90
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a
inline_for_extraction noextract
let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
() | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Hash.Definitions.hash_alg ->
i: Prims.nat{i % FStar.UInt32.v (EverCrypt.Hash.Incremental.block_len a) = 0}
-> Spec.Hash.Incremental.Definitions.prev_length_t a | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.hash_alg",
"Prims.nat",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"FStar.UInt32.v",
"EverCrypt.Hash.Incremental.block_len",
"Spec.Hash.Definitions.is_keccak",
"Prims.bool",
"Spec.Hash.Incremental.Definitions.prev_length_t"
] | [] | false | false | false | false | false | let prev_length_of_nat (a: hash_alg) (i: nat{i % U32.v (block_len a) = 0})
: Spec.Hash.Incremental.prev_length_t a =
| if is_keccak a then () else i | false |
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.alg_of_state | val alg_of_state : a: FStar.Ghost.erased EverCrypt.Hash.alg ->
s:
Hacl.Streaming.Functor.state EverCrypt.Hash.Incremental.evercrypt_hash
(FStar.Ghost.reveal a)
(EverCrypt.Hash.state (FStar.Ghost.reveal a))
(FStar.Ghost.erased Prims.unit)
-> FStar.HyperStack.ST.Stack Spec.Hash.Definitions.fixed_len_alg | let alg_of_state (a: G.erased Hash.alg) = F.index_of_state evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 116,
"end_line": 227,
"start_col": 0,
"start_line": 227
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a
inline_for_extraction noextract
let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
()
inline_for_extraction noextract
let prev_length_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Incremental.prev_length_t a
=
if is_keccak a then
()
else
i
#push-options "--z3rlimit 500"
inline_for_extraction noextract
let evercrypt_hash : block Hash.alg =
Block
Erased
agile_state
(stateful_unused Hash.alg)
unit
Hacl.Hash.Definitions.max_input_len64
(fun a () -> Spec.Hash.Definitions.hash_length a)
block_len
block_len // No vectorization
(fun _ -> 0ul)
(fun _ _ -> S.empty)
(fun a _ -> Spec.Agile.Hash.init a)
(fun a s prevlen input ->
let prevlen = extra_state_of_nat a prevlen in
Spec.Agile.Hash.update_multi a s prevlen input)
(fun a s prevlen input ->
let prevlen = prev_length_of_nat a prevlen in
Spec.Hash.Incremental.update_last a s prevlen input)
(fun a _ s () -> Spec.Agile.Hash.finish a s ())
(fun a _ s () -> Spec.Agile.Hash.hash a s)
(fun a s prevlen ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_zero_blake a prevlen s
else
Spec.Hash.Lemmas.update_multi_zero a s)
(* update_multi_associative *)
(fun a s prevlen1 prevlen2 input1 input2 ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_associative_blake a s prevlen1 prevlen2 input1 input2
else
Spec.Hash.Lemmas.update_multi_associative a s input1 input2)
(* spec_is_incremental *)
(fun a _ input () ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input ())
EverCrypt.Hash.alg_of_state
(fun i _ _ -> EverCrypt.Hash.init #i)
(fun i s prevlen blocks len -> EverCrypt.Hash.update_multi #i s prevlen blocks len)
(fun i s prevlen last last_len ->
EverCrypt.Hash.update_last #i s prevlen last last_len)
(fun i _ s dst _ -> EverCrypt.Hash.finish #i s dst)
#pop-options
let state_t =
F.state_s evercrypt_hash SHA2_256 ((agile_state).s SHA2_256) (G.erased unit)
// Public API (streaming)
// ----------------------
[@@ Comment
"Allocate initial state for the agile hash. The argument `a` stands for the
choice of algorithm (see Hacl_Spec.h). This API will automatically pick the most
efficient implementation, provided you have called EverCrypt_AutoConfig2_init()
before. The state is to be freed by calling `free`."]
let malloc a = F.malloc evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) ()
[@@ Comment
"Reset an existing state to the initial hash state with empty data."]
let reset (a: G.erased Hash.alg) = F.reset evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Feed an arbitrary amount of data into the hash. This function returns
EverCrypt_Error_Success for success, or EverCrypt_Error_MaximumLengthExceeded if
the combined length of all of the data passed to `update` (since the last call
to `init`) exceeds 2^61-1 bytes or 2^64-1 bytes, depending on the choice of
algorithm. Both limits are unlikely to be attained in practice."]
let update (i: G.erased Hash.alg)
(state:F.state evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit))
(chunk: B.buffer uint8)
(chunk_len: UInt32.t):
Stack EverCrypt.Error.error_code
(requires fun h0 -> F.update_pre evercrypt_hash i state chunk chunk_len h0)
(ensures fun h0 e h1 ->
match e with
| EverCrypt.Error.Success ->
S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i) /\
F.update_post evercrypt_hash i state chunk chunk_len h0 h1
| EverCrypt.Error.MaximumLengthExceeded ->
h0 == h1 /\
not (S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i))
| _ -> False)
=
match F.update evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit) state chunk chunk_len with
| Hacl.Streaming.Types.Success -> EverCrypt.Error.Success
| Hacl.Streaming.Types.MaximumLengthExceeded -> EverCrypt.Error.MaximumLengthExceeded
inline_for_extraction noextract
let digest_st a = F.digest_st evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
/// The wrapper pattern, to ensure that the stack-allocated state is properly
/// monomorphized.
private
let digest_md5: digest_st MD5 = F.digest evercrypt_hash MD5 (EverCrypt.Hash.state MD5) (G.erased unit)
private
let digest_sha1: digest_st SHA1 = F.digest evercrypt_hash SHA1 (EverCrypt.Hash.state SHA1) (G.erased unit)
private
let digest_sha224: digest_st SHA2_224 = F.digest evercrypt_hash SHA2_224 (EverCrypt.Hash.state SHA2_224) (G.erased unit)
private
let digest_sha256: digest_st SHA2_256 = F.digest evercrypt_hash SHA2_256 (EverCrypt.Hash.state SHA2_256) (G.erased unit)
private
let digest_sha3_224: digest_st SHA3_224 = F.digest evercrypt_hash SHA3_224 (EverCrypt.Hash.state SHA3_224) (G.erased unit)
private
let digest_sha3_256: digest_st SHA3_256 = F.digest evercrypt_hash SHA3_256 (EverCrypt.Hash.state SHA3_256) (G.erased unit)
private
let digest_sha3_384: digest_st SHA3_384 = F.digest evercrypt_hash SHA3_384 (EverCrypt.Hash.state SHA3_384) (G.erased unit)
private
let digest_sha3_512: digest_st SHA3_512 = F.digest evercrypt_hash SHA3_512 (EverCrypt.Hash.state SHA3_512) (G.erased unit)
private
let digest_sha384: digest_st SHA2_384 = F.digest evercrypt_hash SHA2_384 (EverCrypt.Hash.state SHA2_384) (G.erased unit)
private
let digest_sha512: digest_st SHA2_512 = F.digest evercrypt_hash SHA2_512 (EverCrypt.Hash.state SHA2_512) (G.erased unit)
private
let digest_blake2s: digest_st Blake2S = F.digest evercrypt_hash Blake2S (EverCrypt.Hash.state Blake2S) (G.erased unit)
private
let digest_blake2b: digest_st Blake2B = F.digest evercrypt_hash Blake2B (EverCrypt.Hash.state Blake2B) (G.erased unit)
[@@ Comment | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: FStar.Ghost.erased EverCrypt.Hash.alg ->
s:
Hacl.Streaming.Functor.state EverCrypt.Hash.Incremental.evercrypt_hash
(FStar.Ghost.reveal a)
(EverCrypt.Hash.state (FStar.Ghost.reveal a))
(FStar.Ghost.erased Prims.unit)
-> FStar.HyperStack.ST.Stack Spec.Hash.Definitions.fixed_len_alg | FStar.HyperStack.ST.Stack | [] | [] | [
"FStar.Ghost.erased",
"EverCrypt.Hash.alg",
"Hacl.Streaming.Functor.index_of_state",
"Spec.Hash.Definitions.fixed_len_alg",
"EverCrypt.Hash.Incremental.evercrypt_hash",
"EverCrypt.Hash.state",
"FStar.Ghost.reveal",
"Prims.unit",
"Hacl.Streaming.Functor.state",
"FStar.Monotonic.HyperStack.mem",
"Hacl.Streaming.Functor.invariant",
"Prims.l_and",
"Prims.eq2"
] | [] | false | true | false | false | false | let alg_of_state (a: G.erased Hash.alg) =
| F.index_of_state evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) | false |
|
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.extra_state_of_nat | val extra_state_of_nat (a: hash_alg) (i: nat{i % U32.v (block_len a) = 0})
: Spec.Hash.Definitions.extra_state a | val extra_state_of_nat (a: hash_alg) (i: nat{i % U32.v (block_len a) = 0})
: Spec.Hash.Definitions.extra_state a | let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
() | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 6,
"end_line": 87,
"start_col": 0,
"start_line": 81
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Hash.Definitions.hash_alg ->
i: Prims.nat{i % FStar.UInt32.v (EverCrypt.Hash.Incremental.block_len a) = 0}
-> Spec.Hash.Definitions.extra_state a | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.hash_alg",
"Prims.nat",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"FStar.UInt32.v",
"EverCrypt.Hash.Incremental.block_len",
"Spec.Hash.Definitions.is_blake",
"Prims.bool",
"Spec.Hash.Definitions.extra_state"
] | [] | false | false | false | false | false | let extra_state_of_nat (a: hash_alg) (i: nat{i % U32.v (block_len a) = 0})
: Spec.Hash.Definitions.extra_state a =
| if is_blake a then i | false |
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.digest_sha1 | val digest_sha1:digest_st SHA1 | val digest_sha1:digest_st SHA1 | let digest_sha1: digest_st SHA1 = F.digest evercrypt_hash SHA1 (EverCrypt.Hash.state SHA1) (G.erased unit) | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 106,
"end_line": 203,
"start_col": 0,
"start_line": 203
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a
inline_for_extraction noextract
let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
()
inline_for_extraction noextract
let prev_length_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Incremental.prev_length_t a
=
if is_keccak a then
()
else
i
#push-options "--z3rlimit 500"
inline_for_extraction noextract
let evercrypt_hash : block Hash.alg =
Block
Erased
agile_state
(stateful_unused Hash.alg)
unit
Hacl.Hash.Definitions.max_input_len64
(fun a () -> Spec.Hash.Definitions.hash_length a)
block_len
block_len // No vectorization
(fun _ -> 0ul)
(fun _ _ -> S.empty)
(fun a _ -> Spec.Agile.Hash.init a)
(fun a s prevlen input ->
let prevlen = extra_state_of_nat a prevlen in
Spec.Agile.Hash.update_multi a s prevlen input)
(fun a s prevlen input ->
let prevlen = prev_length_of_nat a prevlen in
Spec.Hash.Incremental.update_last a s prevlen input)
(fun a _ s () -> Spec.Agile.Hash.finish a s ())
(fun a _ s () -> Spec.Agile.Hash.hash a s)
(fun a s prevlen ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_zero_blake a prevlen s
else
Spec.Hash.Lemmas.update_multi_zero a s)
(* update_multi_associative *)
(fun a s prevlen1 prevlen2 input1 input2 ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_associative_blake a s prevlen1 prevlen2 input1 input2
else
Spec.Hash.Lemmas.update_multi_associative a s input1 input2)
(* spec_is_incremental *)
(fun a _ input () ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input ())
EverCrypt.Hash.alg_of_state
(fun i _ _ -> EverCrypt.Hash.init #i)
(fun i s prevlen blocks len -> EverCrypt.Hash.update_multi #i s prevlen blocks len)
(fun i s prevlen last last_len ->
EverCrypt.Hash.update_last #i s prevlen last last_len)
(fun i _ s dst _ -> EverCrypt.Hash.finish #i s dst)
#pop-options
let state_t =
F.state_s evercrypt_hash SHA2_256 ((agile_state).s SHA2_256) (G.erased unit)
// Public API (streaming)
// ----------------------
[@@ Comment
"Allocate initial state for the agile hash. The argument `a` stands for the
choice of algorithm (see Hacl_Spec.h). This API will automatically pick the most
efficient implementation, provided you have called EverCrypt_AutoConfig2_init()
before. The state is to be freed by calling `free`."]
let malloc a = F.malloc evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) ()
[@@ Comment
"Reset an existing state to the initial hash state with empty data."]
let reset (a: G.erased Hash.alg) = F.reset evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Feed an arbitrary amount of data into the hash. This function returns
EverCrypt_Error_Success for success, or EverCrypt_Error_MaximumLengthExceeded if
the combined length of all of the data passed to `update` (since the last call
to `init`) exceeds 2^61-1 bytes or 2^64-1 bytes, depending on the choice of
algorithm. Both limits are unlikely to be attained in practice."]
let update (i: G.erased Hash.alg)
(state:F.state evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit))
(chunk: B.buffer uint8)
(chunk_len: UInt32.t):
Stack EverCrypt.Error.error_code
(requires fun h0 -> F.update_pre evercrypt_hash i state chunk chunk_len h0)
(ensures fun h0 e h1 ->
match e with
| EverCrypt.Error.Success ->
S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i) /\
F.update_post evercrypt_hash i state chunk chunk_len h0 h1
| EverCrypt.Error.MaximumLengthExceeded ->
h0 == h1 /\
not (S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i))
| _ -> False)
=
match F.update evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit) state chunk chunk_len with
| Hacl.Streaming.Types.Success -> EverCrypt.Error.Success
| Hacl.Streaming.Types.MaximumLengthExceeded -> EverCrypt.Error.MaximumLengthExceeded
inline_for_extraction noextract
let digest_st a = F.digest_st evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
/// The wrapper pattern, to ensure that the stack-allocated state is properly
/// monomorphized.
private
let digest_md5: digest_st MD5 = F.digest evercrypt_hash MD5 (EverCrypt.Hash.state MD5) (G.erased unit) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.Hash.Incremental.digest_st Spec.Hash.Definitions.SHA1 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.digest",
"Spec.Hash.Definitions.fixed_len_alg",
"EverCrypt.Hash.Incremental.evercrypt_hash",
"Spec.Hash.Definitions.SHA1",
"EverCrypt.Hash.state",
"FStar.Ghost.erased",
"Prims.unit"
] | [] | false | false | false | true | false | let digest_sha1:digest_st SHA1 =
| F.digest evercrypt_hash SHA1 (EverCrypt.Hash.state SHA1) (G.erased unit) | false |
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.digest_sha256 | val digest_sha256:digest_st SHA2_256 | val digest_sha256:digest_st SHA2_256 | let digest_sha256: digest_st SHA2_256 = F.digest evercrypt_hash SHA2_256 (EverCrypt.Hash.state SHA2_256) (G.erased unit) | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 120,
"end_line": 207,
"start_col": 0,
"start_line": 207
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a
inline_for_extraction noextract
let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
()
inline_for_extraction noextract
let prev_length_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Incremental.prev_length_t a
=
if is_keccak a then
()
else
i
#push-options "--z3rlimit 500"
inline_for_extraction noextract
let evercrypt_hash : block Hash.alg =
Block
Erased
agile_state
(stateful_unused Hash.alg)
unit
Hacl.Hash.Definitions.max_input_len64
(fun a () -> Spec.Hash.Definitions.hash_length a)
block_len
block_len // No vectorization
(fun _ -> 0ul)
(fun _ _ -> S.empty)
(fun a _ -> Spec.Agile.Hash.init a)
(fun a s prevlen input ->
let prevlen = extra_state_of_nat a prevlen in
Spec.Agile.Hash.update_multi a s prevlen input)
(fun a s prevlen input ->
let prevlen = prev_length_of_nat a prevlen in
Spec.Hash.Incremental.update_last a s prevlen input)
(fun a _ s () -> Spec.Agile.Hash.finish a s ())
(fun a _ s () -> Spec.Agile.Hash.hash a s)
(fun a s prevlen ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_zero_blake a prevlen s
else
Spec.Hash.Lemmas.update_multi_zero a s)
(* update_multi_associative *)
(fun a s prevlen1 prevlen2 input1 input2 ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_associative_blake a s prevlen1 prevlen2 input1 input2
else
Spec.Hash.Lemmas.update_multi_associative a s input1 input2)
(* spec_is_incremental *)
(fun a _ input () ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input ())
EverCrypt.Hash.alg_of_state
(fun i _ _ -> EverCrypt.Hash.init #i)
(fun i s prevlen blocks len -> EverCrypt.Hash.update_multi #i s prevlen blocks len)
(fun i s prevlen last last_len ->
EverCrypt.Hash.update_last #i s prevlen last last_len)
(fun i _ s dst _ -> EverCrypt.Hash.finish #i s dst)
#pop-options
let state_t =
F.state_s evercrypt_hash SHA2_256 ((agile_state).s SHA2_256) (G.erased unit)
// Public API (streaming)
// ----------------------
[@@ Comment
"Allocate initial state for the agile hash. The argument `a` stands for the
choice of algorithm (see Hacl_Spec.h). This API will automatically pick the most
efficient implementation, provided you have called EverCrypt_AutoConfig2_init()
before. The state is to be freed by calling `free`."]
let malloc a = F.malloc evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) ()
[@@ Comment
"Reset an existing state to the initial hash state with empty data."]
let reset (a: G.erased Hash.alg) = F.reset evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Feed an arbitrary amount of data into the hash. This function returns
EverCrypt_Error_Success for success, or EverCrypt_Error_MaximumLengthExceeded if
the combined length of all of the data passed to `update` (since the last call
to `init`) exceeds 2^61-1 bytes or 2^64-1 bytes, depending on the choice of
algorithm. Both limits are unlikely to be attained in practice."]
let update (i: G.erased Hash.alg)
(state:F.state evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit))
(chunk: B.buffer uint8)
(chunk_len: UInt32.t):
Stack EverCrypt.Error.error_code
(requires fun h0 -> F.update_pre evercrypt_hash i state chunk chunk_len h0)
(ensures fun h0 e h1 ->
match e with
| EverCrypt.Error.Success ->
S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i) /\
F.update_post evercrypt_hash i state chunk chunk_len h0 h1
| EverCrypt.Error.MaximumLengthExceeded ->
h0 == h1 /\
not (S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i))
| _ -> False)
=
match F.update evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit) state chunk chunk_len with
| Hacl.Streaming.Types.Success -> EverCrypt.Error.Success
| Hacl.Streaming.Types.MaximumLengthExceeded -> EverCrypt.Error.MaximumLengthExceeded
inline_for_extraction noextract
let digest_st a = F.digest_st evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
/// The wrapper pattern, to ensure that the stack-allocated state is properly
/// monomorphized.
private
let digest_md5: digest_st MD5 = F.digest evercrypt_hash MD5 (EverCrypt.Hash.state MD5) (G.erased unit)
private
let digest_sha1: digest_st SHA1 = F.digest evercrypt_hash SHA1 (EverCrypt.Hash.state SHA1) (G.erased unit)
private
let digest_sha224: digest_st SHA2_224 = F.digest evercrypt_hash SHA2_224 (EverCrypt.Hash.state SHA2_224) (G.erased unit) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.Hash.Incremental.digest_st Spec.Hash.Definitions.SHA2_256 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.digest",
"Spec.Hash.Definitions.fixed_len_alg",
"EverCrypt.Hash.Incremental.evercrypt_hash",
"Spec.Hash.Definitions.SHA2_256",
"EverCrypt.Hash.state",
"FStar.Ghost.erased",
"Prims.unit"
] | [] | false | false | false | true | false | let digest_sha256:digest_st SHA2_256 =
| F.digest evercrypt_hash SHA2_256 (EverCrypt.Hash.state SHA2_256) (G.erased unit) | false |
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.digest_sha3_256 | val digest_sha3_256:digest_st SHA3_256 | val digest_sha3_256:digest_st SHA3_256 | let digest_sha3_256: digest_st SHA3_256 = F.digest evercrypt_hash SHA3_256 (EverCrypt.Hash.state SHA3_256) (G.erased unit) | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 122,
"end_line": 211,
"start_col": 0,
"start_line": 211
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a
inline_for_extraction noextract
let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
()
inline_for_extraction noextract
let prev_length_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Incremental.prev_length_t a
=
if is_keccak a then
()
else
i
#push-options "--z3rlimit 500"
inline_for_extraction noextract
let evercrypt_hash : block Hash.alg =
Block
Erased
agile_state
(stateful_unused Hash.alg)
unit
Hacl.Hash.Definitions.max_input_len64
(fun a () -> Spec.Hash.Definitions.hash_length a)
block_len
block_len // No vectorization
(fun _ -> 0ul)
(fun _ _ -> S.empty)
(fun a _ -> Spec.Agile.Hash.init a)
(fun a s prevlen input ->
let prevlen = extra_state_of_nat a prevlen in
Spec.Agile.Hash.update_multi a s prevlen input)
(fun a s prevlen input ->
let prevlen = prev_length_of_nat a prevlen in
Spec.Hash.Incremental.update_last a s prevlen input)
(fun a _ s () -> Spec.Agile.Hash.finish a s ())
(fun a _ s () -> Spec.Agile.Hash.hash a s)
(fun a s prevlen ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_zero_blake a prevlen s
else
Spec.Hash.Lemmas.update_multi_zero a s)
(* update_multi_associative *)
(fun a s prevlen1 prevlen2 input1 input2 ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_associative_blake a s prevlen1 prevlen2 input1 input2
else
Spec.Hash.Lemmas.update_multi_associative a s input1 input2)
(* spec_is_incremental *)
(fun a _ input () ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input ())
EverCrypt.Hash.alg_of_state
(fun i _ _ -> EverCrypt.Hash.init #i)
(fun i s prevlen blocks len -> EverCrypt.Hash.update_multi #i s prevlen blocks len)
(fun i s prevlen last last_len ->
EverCrypt.Hash.update_last #i s prevlen last last_len)
(fun i _ s dst _ -> EverCrypt.Hash.finish #i s dst)
#pop-options
let state_t =
F.state_s evercrypt_hash SHA2_256 ((agile_state).s SHA2_256) (G.erased unit)
// Public API (streaming)
// ----------------------
[@@ Comment
"Allocate initial state for the agile hash. The argument `a` stands for the
choice of algorithm (see Hacl_Spec.h). This API will automatically pick the most
efficient implementation, provided you have called EverCrypt_AutoConfig2_init()
before. The state is to be freed by calling `free`."]
let malloc a = F.malloc evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) ()
[@@ Comment
"Reset an existing state to the initial hash state with empty data."]
let reset (a: G.erased Hash.alg) = F.reset evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Feed an arbitrary amount of data into the hash. This function returns
EverCrypt_Error_Success for success, or EverCrypt_Error_MaximumLengthExceeded if
the combined length of all of the data passed to `update` (since the last call
to `init`) exceeds 2^61-1 bytes or 2^64-1 bytes, depending on the choice of
algorithm. Both limits are unlikely to be attained in practice."]
let update (i: G.erased Hash.alg)
(state:F.state evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit))
(chunk: B.buffer uint8)
(chunk_len: UInt32.t):
Stack EverCrypt.Error.error_code
(requires fun h0 -> F.update_pre evercrypt_hash i state chunk chunk_len h0)
(ensures fun h0 e h1 ->
match e with
| EverCrypt.Error.Success ->
S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i) /\
F.update_post evercrypt_hash i state chunk chunk_len h0 h1
| EverCrypt.Error.MaximumLengthExceeded ->
h0 == h1 /\
not (S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i))
| _ -> False)
=
match F.update evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit) state chunk chunk_len with
| Hacl.Streaming.Types.Success -> EverCrypt.Error.Success
| Hacl.Streaming.Types.MaximumLengthExceeded -> EverCrypt.Error.MaximumLengthExceeded
inline_for_extraction noextract
let digest_st a = F.digest_st evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
/// The wrapper pattern, to ensure that the stack-allocated state is properly
/// monomorphized.
private
let digest_md5: digest_st MD5 = F.digest evercrypt_hash MD5 (EverCrypt.Hash.state MD5) (G.erased unit)
private
let digest_sha1: digest_st SHA1 = F.digest evercrypt_hash SHA1 (EverCrypt.Hash.state SHA1) (G.erased unit)
private
let digest_sha224: digest_st SHA2_224 = F.digest evercrypt_hash SHA2_224 (EverCrypt.Hash.state SHA2_224) (G.erased unit)
private
let digest_sha256: digest_st SHA2_256 = F.digest evercrypt_hash SHA2_256 (EverCrypt.Hash.state SHA2_256) (G.erased unit)
private
let digest_sha3_224: digest_st SHA3_224 = F.digest evercrypt_hash SHA3_224 (EverCrypt.Hash.state SHA3_224) (G.erased unit) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.Hash.Incremental.digest_st Spec.Hash.Definitions.SHA3_256 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.digest",
"Spec.Hash.Definitions.fixed_len_alg",
"EverCrypt.Hash.Incremental.evercrypt_hash",
"Spec.Hash.Definitions.SHA3_256",
"EverCrypt.Hash.state",
"FStar.Ghost.erased",
"Prims.unit"
] | [] | false | false | false | true | false | let digest_sha3_256:digest_st SHA3_256 =
| F.digest evercrypt_hash SHA3_256 (EverCrypt.Hash.state SHA3_256) (G.erased unit) | false |
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.digest_sha3_224 | val digest_sha3_224:digest_st SHA3_224 | val digest_sha3_224:digest_st SHA3_224 | let digest_sha3_224: digest_st SHA3_224 = F.digest evercrypt_hash SHA3_224 (EverCrypt.Hash.state SHA3_224) (G.erased unit) | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 122,
"end_line": 209,
"start_col": 0,
"start_line": 209
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a
inline_for_extraction noextract
let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
()
inline_for_extraction noextract
let prev_length_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Incremental.prev_length_t a
=
if is_keccak a then
()
else
i
#push-options "--z3rlimit 500"
inline_for_extraction noextract
let evercrypt_hash : block Hash.alg =
Block
Erased
agile_state
(stateful_unused Hash.alg)
unit
Hacl.Hash.Definitions.max_input_len64
(fun a () -> Spec.Hash.Definitions.hash_length a)
block_len
block_len // No vectorization
(fun _ -> 0ul)
(fun _ _ -> S.empty)
(fun a _ -> Spec.Agile.Hash.init a)
(fun a s prevlen input ->
let prevlen = extra_state_of_nat a prevlen in
Spec.Agile.Hash.update_multi a s prevlen input)
(fun a s prevlen input ->
let prevlen = prev_length_of_nat a prevlen in
Spec.Hash.Incremental.update_last a s prevlen input)
(fun a _ s () -> Spec.Agile.Hash.finish a s ())
(fun a _ s () -> Spec.Agile.Hash.hash a s)
(fun a s prevlen ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_zero_blake a prevlen s
else
Spec.Hash.Lemmas.update_multi_zero a s)
(* update_multi_associative *)
(fun a s prevlen1 prevlen2 input1 input2 ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_associative_blake a s prevlen1 prevlen2 input1 input2
else
Spec.Hash.Lemmas.update_multi_associative a s input1 input2)
(* spec_is_incremental *)
(fun a _ input () ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input ())
EverCrypt.Hash.alg_of_state
(fun i _ _ -> EverCrypt.Hash.init #i)
(fun i s prevlen blocks len -> EverCrypt.Hash.update_multi #i s prevlen blocks len)
(fun i s prevlen last last_len ->
EverCrypt.Hash.update_last #i s prevlen last last_len)
(fun i _ s dst _ -> EverCrypt.Hash.finish #i s dst)
#pop-options
let state_t =
F.state_s evercrypt_hash SHA2_256 ((agile_state).s SHA2_256) (G.erased unit)
// Public API (streaming)
// ----------------------
[@@ Comment
"Allocate initial state for the agile hash. The argument `a` stands for the
choice of algorithm (see Hacl_Spec.h). This API will automatically pick the most
efficient implementation, provided you have called EverCrypt_AutoConfig2_init()
before. The state is to be freed by calling `free`."]
let malloc a = F.malloc evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) ()
[@@ Comment
"Reset an existing state to the initial hash state with empty data."]
let reset (a: G.erased Hash.alg) = F.reset evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Feed an arbitrary amount of data into the hash. This function returns
EverCrypt_Error_Success for success, or EverCrypt_Error_MaximumLengthExceeded if
the combined length of all of the data passed to `update` (since the last call
to `init`) exceeds 2^61-1 bytes or 2^64-1 bytes, depending on the choice of
algorithm. Both limits are unlikely to be attained in practice."]
let update (i: G.erased Hash.alg)
(state:F.state evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit))
(chunk: B.buffer uint8)
(chunk_len: UInt32.t):
Stack EverCrypt.Error.error_code
(requires fun h0 -> F.update_pre evercrypt_hash i state chunk chunk_len h0)
(ensures fun h0 e h1 ->
match e with
| EverCrypt.Error.Success ->
S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i) /\
F.update_post evercrypt_hash i state chunk chunk_len h0 h1
| EverCrypt.Error.MaximumLengthExceeded ->
h0 == h1 /\
not (S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i))
| _ -> False)
=
match F.update evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit) state chunk chunk_len with
| Hacl.Streaming.Types.Success -> EverCrypt.Error.Success
| Hacl.Streaming.Types.MaximumLengthExceeded -> EverCrypt.Error.MaximumLengthExceeded
inline_for_extraction noextract
let digest_st a = F.digest_st evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
/// The wrapper pattern, to ensure that the stack-allocated state is properly
/// monomorphized.
private
let digest_md5: digest_st MD5 = F.digest evercrypt_hash MD5 (EverCrypt.Hash.state MD5) (G.erased unit)
private
let digest_sha1: digest_st SHA1 = F.digest evercrypt_hash SHA1 (EverCrypt.Hash.state SHA1) (G.erased unit)
private
let digest_sha224: digest_st SHA2_224 = F.digest evercrypt_hash SHA2_224 (EverCrypt.Hash.state SHA2_224) (G.erased unit)
private
let digest_sha256: digest_st SHA2_256 = F.digest evercrypt_hash SHA2_256 (EverCrypt.Hash.state SHA2_256) (G.erased unit) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.Hash.Incremental.digest_st Spec.Hash.Definitions.SHA3_224 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.digest",
"Spec.Hash.Definitions.fixed_len_alg",
"EverCrypt.Hash.Incremental.evercrypt_hash",
"Spec.Hash.Definitions.SHA3_224",
"EverCrypt.Hash.state",
"FStar.Ghost.erased",
"Prims.unit"
] | [] | false | false | false | true | false | let digest_sha3_224:digest_st SHA3_224 =
| F.digest evercrypt_hash SHA3_224 (EverCrypt.Hash.state SHA3_224) (G.erased unit) | false |
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.digest_sha384 | val digest_sha384:digest_st SHA2_384 | val digest_sha384:digest_st SHA2_384 | let digest_sha384: digest_st SHA2_384 = F.digest evercrypt_hash SHA2_384 (EverCrypt.Hash.state SHA2_384) (G.erased unit) | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 120,
"end_line": 217,
"start_col": 0,
"start_line": 217
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a
inline_for_extraction noextract
let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
()
inline_for_extraction noextract
let prev_length_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Incremental.prev_length_t a
=
if is_keccak a then
()
else
i
#push-options "--z3rlimit 500"
inline_for_extraction noextract
let evercrypt_hash : block Hash.alg =
Block
Erased
agile_state
(stateful_unused Hash.alg)
unit
Hacl.Hash.Definitions.max_input_len64
(fun a () -> Spec.Hash.Definitions.hash_length a)
block_len
block_len // No vectorization
(fun _ -> 0ul)
(fun _ _ -> S.empty)
(fun a _ -> Spec.Agile.Hash.init a)
(fun a s prevlen input ->
let prevlen = extra_state_of_nat a prevlen in
Spec.Agile.Hash.update_multi a s prevlen input)
(fun a s prevlen input ->
let prevlen = prev_length_of_nat a prevlen in
Spec.Hash.Incremental.update_last a s prevlen input)
(fun a _ s () -> Spec.Agile.Hash.finish a s ())
(fun a _ s () -> Spec.Agile.Hash.hash a s)
(fun a s prevlen ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_zero_blake a prevlen s
else
Spec.Hash.Lemmas.update_multi_zero a s)
(* update_multi_associative *)
(fun a s prevlen1 prevlen2 input1 input2 ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_associative_blake a s prevlen1 prevlen2 input1 input2
else
Spec.Hash.Lemmas.update_multi_associative a s input1 input2)
(* spec_is_incremental *)
(fun a _ input () ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input ())
EverCrypt.Hash.alg_of_state
(fun i _ _ -> EverCrypt.Hash.init #i)
(fun i s prevlen blocks len -> EverCrypt.Hash.update_multi #i s prevlen blocks len)
(fun i s prevlen last last_len ->
EverCrypt.Hash.update_last #i s prevlen last last_len)
(fun i _ s dst _ -> EverCrypt.Hash.finish #i s dst)
#pop-options
let state_t =
F.state_s evercrypt_hash SHA2_256 ((agile_state).s SHA2_256) (G.erased unit)
// Public API (streaming)
// ----------------------
[@@ Comment
"Allocate initial state for the agile hash. The argument `a` stands for the
choice of algorithm (see Hacl_Spec.h). This API will automatically pick the most
efficient implementation, provided you have called EverCrypt_AutoConfig2_init()
before. The state is to be freed by calling `free`."]
let malloc a = F.malloc evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) ()
[@@ Comment
"Reset an existing state to the initial hash state with empty data."]
let reset (a: G.erased Hash.alg) = F.reset evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Feed an arbitrary amount of data into the hash. This function returns
EverCrypt_Error_Success for success, or EverCrypt_Error_MaximumLengthExceeded if
the combined length of all of the data passed to `update` (since the last call
to `init`) exceeds 2^61-1 bytes or 2^64-1 bytes, depending on the choice of
algorithm. Both limits are unlikely to be attained in practice."]
let update (i: G.erased Hash.alg)
(state:F.state evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit))
(chunk: B.buffer uint8)
(chunk_len: UInt32.t):
Stack EverCrypt.Error.error_code
(requires fun h0 -> F.update_pre evercrypt_hash i state chunk chunk_len h0)
(ensures fun h0 e h1 ->
match e with
| EverCrypt.Error.Success ->
S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i) /\
F.update_post evercrypt_hash i state chunk chunk_len h0 h1
| EverCrypt.Error.MaximumLengthExceeded ->
h0 == h1 /\
not (S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i))
| _ -> False)
=
match F.update evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit) state chunk chunk_len with
| Hacl.Streaming.Types.Success -> EverCrypt.Error.Success
| Hacl.Streaming.Types.MaximumLengthExceeded -> EverCrypt.Error.MaximumLengthExceeded
inline_for_extraction noextract
let digest_st a = F.digest_st evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
/// The wrapper pattern, to ensure that the stack-allocated state is properly
/// monomorphized.
private
let digest_md5: digest_st MD5 = F.digest evercrypt_hash MD5 (EverCrypt.Hash.state MD5) (G.erased unit)
private
let digest_sha1: digest_st SHA1 = F.digest evercrypt_hash SHA1 (EverCrypt.Hash.state SHA1) (G.erased unit)
private
let digest_sha224: digest_st SHA2_224 = F.digest evercrypt_hash SHA2_224 (EverCrypt.Hash.state SHA2_224) (G.erased unit)
private
let digest_sha256: digest_st SHA2_256 = F.digest evercrypt_hash SHA2_256 (EverCrypt.Hash.state SHA2_256) (G.erased unit)
private
let digest_sha3_224: digest_st SHA3_224 = F.digest evercrypt_hash SHA3_224 (EverCrypt.Hash.state SHA3_224) (G.erased unit)
private
let digest_sha3_256: digest_st SHA3_256 = F.digest evercrypt_hash SHA3_256 (EverCrypt.Hash.state SHA3_256) (G.erased unit)
private
let digest_sha3_384: digest_st SHA3_384 = F.digest evercrypt_hash SHA3_384 (EverCrypt.Hash.state SHA3_384) (G.erased unit)
private
let digest_sha3_512: digest_st SHA3_512 = F.digest evercrypt_hash SHA3_512 (EverCrypt.Hash.state SHA3_512) (G.erased unit) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.Hash.Incremental.digest_st Spec.Hash.Definitions.SHA2_384 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.digest",
"Spec.Hash.Definitions.fixed_len_alg",
"EverCrypt.Hash.Incremental.evercrypt_hash",
"Spec.Hash.Definitions.SHA2_384",
"EverCrypt.Hash.state",
"FStar.Ghost.erased",
"Prims.unit"
] | [] | false | false | false | true | false | let digest_sha384:digest_st SHA2_384 =
| F.digest evercrypt_hash SHA2_384 (EverCrypt.Hash.state SHA2_384) (G.erased unit) | false |
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.digest | val digest: a:G.erased Hash.alg -> digest_st a | val digest: a:G.erased Hash.alg -> digest_st a | let digest a state output l =
let a = alg_of_state a state in
match a with
| MD5 -> digest_md5 state output l
| SHA1 -> digest_sha1 state output l
| SHA2_224 -> digest_sha224 state output l
| SHA2_256 -> digest_sha256 state output l
| SHA2_384 -> digest_sha384 state output l
| SHA2_512 -> digest_sha512 state output l
| SHA3_224 -> digest_sha3_224 state output l
| SHA3_256 -> digest_sha3_256 state output l
| SHA3_384 -> digest_sha3_384 state output l
| SHA3_512 -> digest_sha3_512 state output l
| Blake2S -> digest_blake2s state output l
| Blake2B -> digest_blake2b state output l | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 251,
"start_col": 0,
"start_line": 237
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a
inline_for_extraction noextract
let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
()
inline_for_extraction noextract
let prev_length_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Incremental.prev_length_t a
=
if is_keccak a then
()
else
i
#push-options "--z3rlimit 500"
inline_for_extraction noextract
let evercrypt_hash : block Hash.alg =
Block
Erased
agile_state
(stateful_unused Hash.alg)
unit
Hacl.Hash.Definitions.max_input_len64
(fun a () -> Spec.Hash.Definitions.hash_length a)
block_len
block_len // No vectorization
(fun _ -> 0ul)
(fun _ _ -> S.empty)
(fun a _ -> Spec.Agile.Hash.init a)
(fun a s prevlen input ->
let prevlen = extra_state_of_nat a prevlen in
Spec.Agile.Hash.update_multi a s prevlen input)
(fun a s prevlen input ->
let prevlen = prev_length_of_nat a prevlen in
Spec.Hash.Incremental.update_last a s prevlen input)
(fun a _ s () -> Spec.Agile.Hash.finish a s ())
(fun a _ s () -> Spec.Agile.Hash.hash a s)
(fun a s prevlen ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_zero_blake a prevlen s
else
Spec.Hash.Lemmas.update_multi_zero a s)
(* update_multi_associative *)
(fun a s prevlen1 prevlen2 input1 input2 ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_associative_blake a s prevlen1 prevlen2 input1 input2
else
Spec.Hash.Lemmas.update_multi_associative a s input1 input2)
(* spec_is_incremental *)
(fun a _ input () ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input ())
EverCrypt.Hash.alg_of_state
(fun i _ _ -> EverCrypt.Hash.init #i)
(fun i s prevlen blocks len -> EverCrypt.Hash.update_multi #i s prevlen blocks len)
(fun i s prevlen last last_len ->
EverCrypt.Hash.update_last #i s prevlen last last_len)
(fun i _ s dst _ -> EverCrypt.Hash.finish #i s dst)
#pop-options
let state_t =
F.state_s evercrypt_hash SHA2_256 ((agile_state).s SHA2_256) (G.erased unit)
// Public API (streaming)
// ----------------------
[@@ Comment
"Allocate initial state for the agile hash. The argument `a` stands for the
choice of algorithm (see Hacl_Spec.h). This API will automatically pick the most
efficient implementation, provided you have called EverCrypt_AutoConfig2_init()
before. The state is to be freed by calling `free`."]
let malloc a = F.malloc evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) ()
[@@ Comment
"Reset an existing state to the initial hash state with empty data."]
let reset (a: G.erased Hash.alg) = F.reset evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Feed an arbitrary amount of data into the hash. This function returns
EverCrypt_Error_Success for success, or EverCrypt_Error_MaximumLengthExceeded if
the combined length of all of the data passed to `update` (since the last call
to `init`) exceeds 2^61-1 bytes or 2^64-1 bytes, depending on the choice of
algorithm. Both limits are unlikely to be attained in practice."]
let update (i: G.erased Hash.alg)
(state:F.state evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit))
(chunk: B.buffer uint8)
(chunk_len: UInt32.t):
Stack EverCrypt.Error.error_code
(requires fun h0 -> F.update_pre evercrypt_hash i state chunk chunk_len h0)
(ensures fun h0 e h1 ->
match e with
| EverCrypt.Error.Success ->
S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i) /\
F.update_post evercrypt_hash i state chunk chunk_len h0 h1
| EverCrypt.Error.MaximumLengthExceeded ->
h0 == h1 /\
not (S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i))
| _ -> False)
=
match F.update evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit) state chunk chunk_len with
| Hacl.Streaming.Types.Success -> EverCrypt.Error.Success
| Hacl.Streaming.Types.MaximumLengthExceeded -> EverCrypt.Error.MaximumLengthExceeded
inline_for_extraction noextract
let digest_st a = F.digest_st evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
/// The wrapper pattern, to ensure that the stack-allocated state is properly
/// monomorphized.
private
let digest_md5: digest_st MD5 = F.digest evercrypt_hash MD5 (EverCrypt.Hash.state MD5) (G.erased unit)
private
let digest_sha1: digest_st SHA1 = F.digest evercrypt_hash SHA1 (EverCrypt.Hash.state SHA1) (G.erased unit)
private
let digest_sha224: digest_st SHA2_224 = F.digest evercrypt_hash SHA2_224 (EverCrypt.Hash.state SHA2_224) (G.erased unit)
private
let digest_sha256: digest_st SHA2_256 = F.digest evercrypt_hash SHA2_256 (EverCrypt.Hash.state SHA2_256) (G.erased unit)
private
let digest_sha3_224: digest_st SHA3_224 = F.digest evercrypt_hash SHA3_224 (EverCrypt.Hash.state SHA3_224) (G.erased unit)
private
let digest_sha3_256: digest_st SHA3_256 = F.digest evercrypt_hash SHA3_256 (EverCrypt.Hash.state SHA3_256) (G.erased unit)
private
let digest_sha3_384: digest_st SHA3_384 = F.digest evercrypt_hash SHA3_384 (EverCrypt.Hash.state SHA3_384) (G.erased unit)
private
let digest_sha3_512: digest_st SHA3_512 = F.digest evercrypt_hash SHA3_512 (EverCrypt.Hash.state SHA3_512) (G.erased unit)
private
let digest_sha384: digest_st SHA2_384 = F.digest evercrypt_hash SHA2_384 (EverCrypt.Hash.state SHA2_384) (G.erased unit)
private
let digest_sha512: digest_st SHA2_512 = F.digest evercrypt_hash SHA2_512 (EverCrypt.Hash.state SHA2_512) (G.erased unit)
private
let digest_blake2s: digest_st Blake2S = F.digest evercrypt_hash Blake2S (EverCrypt.Hash.state Blake2S) (G.erased unit)
private
let digest_blake2b: digest_st Blake2B = F.digest evercrypt_hash Blake2B (EverCrypt.Hash.state Blake2B) (G.erased unit)
[@@ Comment
"Perform a run-time test to determine which algorithm was chosen for the given piece of state."]
let alg_of_state (a: G.erased Hash.alg) = F.index_of_state evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Write the resulting hash into `output`, an array whose length is
algorithm-specific. You can use the macros defined earlier in this file to
allocate a destination buffer of the right length. The state remains valid after
a call to `digest`, meaning the user may feed more data into the hash via
`update`. (The finish function operates on an internal copy of the state and
therefore does not invalidate the client-held state.)"] | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.Ghost.erased EverCrypt.Hash.alg
-> EverCrypt.Hash.Incremental.digest_st (FStar.Ghost.reveal a) | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"EverCrypt.Hash.alg",
"Hacl.Streaming.Functor.state",
"Spec.Hash.Definitions.fixed_len_alg",
"EverCrypt.Hash.Incremental.evercrypt_hash",
"FStar.Ghost.reveal",
"EverCrypt.Hash.state",
"Prims.unit",
"LowStar.Buffer.buffer",
"Hacl.Streaming.Functor.uint8",
"Hacl.Streaming.Interface.__proj__Block__item__output_length_t",
"Prims.eq2",
"Prims.nat",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"Hacl.Streaming.Interface.__proj__Block__item__output_length",
"EverCrypt.Hash.Incremental.digest_md5",
"EverCrypt.Hash.Incremental.digest_sha1",
"EverCrypt.Hash.Incremental.digest_sha224",
"EverCrypt.Hash.Incremental.digest_sha256",
"EverCrypt.Hash.Incremental.digest_sha384",
"EverCrypt.Hash.Incremental.digest_sha512",
"EverCrypt.Hash.Incremental.digest_sha3_224",
"EverCrypt.Hash.Incremental.digest_sha3_256",
"EverCrypt.Hash.Incremental.digest_sha3_384",
"EverCrypt.Hash.Incremental.digest_sha3_512",
"EverCrypt.Hash.Incremental.digest_blake2s",
"EverCrypt.Hash.Incremental.digest_blake2b",
"EverCrypt.Hash.Incremental.alg_of_state"
] | [] | false | false | false | false | false | let digest a state output l =
| let a = alg_of_state a state in
match a with
| MD5 -> digest_md5 state output l
| SHA1 -> digest_sha1 state output l
| SHA2_224 -> digest_sha224 state output l
| SHA2_256 -> digest_sha256 state output l
| SHA2_384 -> digest_sha384 state output l
| SHA2_512 -> digest_sha512 state output l
| SHA3_224 -> digest_sha3_224 state output l
| SHA3_256 -> digest_sha3_256 state output l
| SHA3_384 -> digest_sha3_384 state output l
| SHA3_512 -> digest_sha3_512 state output l
| Blake2S -> digest_blake2s state output l
| Blake2B -> digest_blake2b state output l | false |
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.digest_sha224 | val digest_sha224:digest_st SHA2_224 | val digest_sha224:digest_st SHA2_224 | let digest_sha224: digest_st SHA2_224 = F.digest evercrypt_hash SHA2_224 (EverCrypt.Hash.state SHA2_224) (G.erased unit) | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 120,
"end_line": 205,
"start_col": 0,
"start_line": 205
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a
inline_for_extraction noextract
let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
()
inline_for_extraction noextract
let prev_length_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Incremental.prev_length_t a
=
if is_keccak a then
()
else
i
#push-options "--z3rlimit 500"
inline_for_extraction noextract
let evercrypt_hash : block Hash.alg =
Block
Erased
agile_state
(stateful_unused Hash.alg)
unit
Hacl.Hash.Definitions.max_input_len64
(fun a () -> Spec.Hash.Definitions.hash_length a)
block_len
block_len // No vectorization
(fun _ -> 0ul)
(fun _ _ -> S.empty)
(fun a _ -> Spec.Agile.Hash.init a)
(fun a s prevlen input ->
let prevlen = extra_state_of_nat a prevlen in
Spec.Agile.Hash.update_multi a s prevlen input)
(fun a s prevlen input ->
let prevlen = prev_length_of_nat a prevlen in
Spec.Hash.Incremental.update_last a s prevlen input)
(fun a _ s () -> Spec.Agile.Hash.finish a s ())
(fun a _ s () -> Spec.Agile.Hash.hash a s)
(fun a s prevlen ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_zero_blake a prevlen s
else
Spec.Hash.Lemmas.update_multi_zero a s)
(* update_multi_associative *)
(fun a s prevlen1 prevlen2 input1 input2 ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_associative_blake a s prevlen1 prevlen2 input1 input2
else
Spec.Hash.Lemmas.update_multi_associative a s input1 input2)
(* spec_is_incremental *)
(fun a _ input () ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input ())
EverCrypt.Hash.alg_of_state
(fun i _ _ -> EverCrypt.Hash.init #i)
(fun i s prevlen blocks len -> EverCrypt.Hash.update_multi #i s prevlen blocks len)
(fun i s prevlen last last_len ->
EverCrypt.Hash.update_last #i s prevlen last last_len)
(fun i _ s dst _ -> EverCrypt.Hash.finish #i s dst)
#pop-options
let state_t =
F.state_s evercrypt_hash SHA2_256 ((agile_state).s SHA2_256) (G.erased unit)
// Public API (streaming)
// ----------------------
[@@ Comment
"Allocate initial state for the agile hash. The argument `a` stands for the
choice of algorithm (see Hacl_Spec.h). This API will automatically pick the most
efficient implementation, provided you have called EverCrypt_AutoConfig2_init()
before. The state is to be freed by calling `free`."]
let malloc a = F.malloc evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) ()
[@@ Comment
"Reset an existing state to the initial hash state with empty data."]
let reset (a: G.erased Hash.alg) = F.reset evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Feed an arbitrary amount of data into the hash. This function returns
EverCrypt_Error_Success for success, or EverCrypt_Error_MaximumLengthExceeded if
the combined length of all of the data passed to `update` (since the last call
to `init`) exceeds 2^61-1 bytes or 2^64-1 bytes, depending on the choice of
algorithm. Both limits are unlikely to be attained in practice."]
let update (i: G.erased Hash.alg)
(state:F.state evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit))
(chunk: B.buffer uint8)
(chunk_len: UInt32.t):
Stack EverCrypt.Error.error_code
(requires fun h0 -> F.update_pre evercrypt_hash i state chunk chunk_len h0)
(ensures fun h0 e h1 ->
match e with
| EverCrypt.Error.Success ->
S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i) /\
F.update_post evercrypt_hash i state chunk chunk_len h0 h1
| EverCrypt.Error.MaximumLengthExceeded ->
h0 == h1 /\
not (S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i))
| _ -> False)
=
match F.update evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit) state chunk chunk_len with
| Hacl.Streaming.Types.Success -> EverCrypt.Error.Success
| Hacl.Streaming.Types.MaximumLengthExceeded -> EverCrypt.Error.MaximumLengthExceeded
inline_for_extraction noextract
let digest_st a = F.digest_st evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
/// The wrapper pattern, to ensure that the stack-allocated state is properly
/// monomorphized.
private
let digest_md5: digest_st MD5 = F.digest evercrypt_hash MD5 (EverCrypt.Hash.state MD5) (G.erased unit)
private
let digest_sha1: digest_st SHA1 = F.digest evercrypt_hash SHA1 (EverCrypt.Hash.state SHA1) (G.erased unit) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.Hash.Incremental.digest_st Spec.Hash.Definitions.SHA2_224 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.digest",
"Spec.Hash.Definitions.fixed_len_alg",
"EverCrypt.Hash.Incremental.evercrypt_hash",
"Spec.Hash.Definitions.SHA2_224",
"EverCrypt.Hash.state",
"FStar.Ghost.erased",
"Prims.unit"
] | [] | false | false | false | true | false | let digest_sha224:digest_st SHA2_224 =
| F.digest evercrypt_hash SHA2_224 (EverCrypt.Hash.state SHA2_224) (G.erased unit) | false |
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.free | val free : i: FStar.Ghost.erased EverCrypt.Hash.alg
-> Hacl.Streaming.Functor.free_st EverCrypt.Hash.Incremental.evercrypt_hash
(FStar.Ghost.reveal i)
(EverCrypt.Hash.state (FStar.Ghost.reveal i))
(FStar.Ghost.erased Prims.unit) | let free (i: G.erased Hash.alg) = F.free evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit) | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 98,
"end_line": 255,
"start_col": 0,
"start_line": 255
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a
inline_for_extraction noextract
let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
()
inline_for_extraction noextract
let prev_length_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Incremental.prev_length_t a
=
if is_keccak a then
()
else
i
#push-options "--z3rlimit 500"
inline_for_extraction noextract
let evercrypt_hash : block Hash.alg =
Block
Erased
agile_state
(stateful_unused Hash.alg)
unit
Hacl.Hash.Definitions.max_input_len64
(fun a () -> Spec.Hash.Definitions.hash_length a)
block_len
block_len // No vectorization
(fun _ -> 0ul)
(fun _ _ -> S.empty)
(fun a _ -> Spec.Agile.Hash.init a)
(fun a s prevlen input ->
let prevlen = extra_state_of_nat a prevlen in
Spec.Agile.Hash.update_multi a s prevlen input)
(fun a s prevlen input ->
let prevlen = prev_length_of_nat a prevlen in
Spec.Hash.Incremental.update_last a s prevlen input)
(fun a _ s () -> Spec.Agile.Hash.finish a s ())
(fun a _ s () -> Spec.Agile.Hash.hash a s)
(fun a s prevlen ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_zero_blake a prevlen s
else
Spec.Hash.Lemmas.update_multi_zero a s)
(* update_multi_associative *)
(fun a s prevlen1 prevlen2 input1 input2 ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_associative_blake a s prevlen1 prevlen2 input1 input2
else
Spec.Hash.Lemmas.update_multi_associative a s input1 input2)
(* spec_is_incremental *)
(fun a _ input () ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input ())
EverCrypt.Hash.alg_of_state
(fun i _ _ -> EverCrypt.Hash.init #i)
(fun i s prevlen blocks len -> EverCrypt.Hash.update_multi #i s prevlen blocks len)
(fun i s prevlen last last_len ->
EverCrypt.Hash.update_last #i s prevlen last last_len)
(fun i _ s dst _ -> EverCrypt.Hash.finish #i s dst)
#pop-options
let state_t =
F.state_s evercrypt_hash SHA2_256 ((agile_state).s SHA2_256) (G.erased unit)
// Public API (streaming)
// ----------------------
[@@ Comment
"Allocate initial state for the agile hash. The argument `a` stands for the
choice of algorithm (see Hacl_Spec.h). This API will automatically pick the most
efficient implementation, provided you have called EverCrypt_AutoConfig2_init()
before. The state is to be freed by calling `free`."]
let malloc a = F.malloc evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) ()
[@@ Comment
"Reset an existing state to the initial hash state with empty data."]
let reset (a: G.erased Hash.alg) = F.reset evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Feed an arbitrary amount of data into the hash. This function returns
EverCrypt_Error_Success for success, or EverCrypt_Error_MaximumLengthExceeded if
the combined length of all of the data passed to `update` (since the last call
to `init`) exceeds 2^61-1 bytes or 2^64-1 bytes, depending on the choice of
algorithm. Both limits are unlikely to be attained in practice."]
let update (i: G.erased Hash.alg)
(state:F.state evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit))
(chunk: B.buffer uint8)
(chunk_len: UInt32.t):
Stack EverCrypt.Error.error_code
(requires fun h0 -> F.update_pre evercrypt_hash i state chunk chunk_len h0)
(ensures fun h0 e h1 ->
match e with
| EverCrypt.Error.Success ->
S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i) /\
F.update_post evercrypt_hash i state chunk chunk_len h0 h1
| EverCrypt.Error.MaximumLengthExceeded ->
h0 == h1 /\
not (S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i))
| _ -> False)
=
match F.update evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit) state chunk chunk_len with
| Hacl.Streaming.Types.Success -> EverCrypt.Error.Success
| Hacl.Streaming.Types.MaximumLengthExceeded -> EverCrypt.Error.MaximumLengthExceeded
inline_for_extraction noextract
let digest_st a = F.digest_st evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
/// The wrapper pattern, to ensure that the stack-allocated state is properly
/// monomorphized.
private
let digest_md5: digest_st MD5 = F.digest evercrypt_hash MD5 (EverCrypt.Hash.state MD5) (G.erased unit)
private
let digest_sha1: digest_st SHA1 = F.digest evercrypt_hash SHA1 (EverCrypt.Hash.state SHA1) (G.erased unit)
private
let digest_sha224: digest_st SHA2_224 = F.digest evercrypt_hash SHA2_224 (EverCrypt.Hash.state SHA2_224) (G.erased unit)
private
let digest_sha256: digest_st SHA2_256 = F.digest evercrypt_hash SHA2_256 (EverCrypt.Hash.state SHA2_256) (G.erased unit)
private
let digest_sha3_224: digest_st SHA3_224 = F.digest evercrypt_hash SHA3_224 (EverCrypt.Hash.state SHA3_224) (G.erased unit)
private
let digest_sha3_256: digest_st SHA3_256 = F.digest evercrypt_hash SHA3_256 (EverCrypt.Hash.state SHA3_256) (G.erased unit)
private
let digest_sha3_384: digest_st SHA3_384 = F.digest evercrypt_hash SHA3_384 (EverCrypt.Hash.state SHA3_384) (G.erased unit)
private
let digest_sha3_512: digest_st SHA3_512 = F.digest evercrypt_hash SHA3_512 (EverCrypt.Hash.state SHA3_512) (G.erased unit)
private
let digest_sha384: digest_st SHA2_384 = F.digest evercrypt_hash SHA2_384 (EverCrypt.Hash.state SHA2_384) (G.erased unit)
private
let digest_sha512: digest_st SHA2_512 = F.digest evercrypt_hash SHA2_512 (EverCrypt.Hash.state SHA2_512) (G.erased unit)
private
let digest_blake2s: digest_st Blake2S = F.digest evercrypt_hash Blake2S (EverCrypt.Hash.state Blake2S) (G.erased unit)
private
let digest_blake2b: digest_st Blake2B = F.digest evercrypt_hash Blake2B (EverCrypt.Hash.state Blake2B) (G.erased unit)
[@@ Comment
"Perform a run-time test to determine which algorithm was chosen for the given piece of state."]
let alg_of_state (a: G.erased Hash.alg) = F.index_of_state evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Write the resulting hash into `output`, an array whose length is
algorithm-specific. You can use the macros defined earlier in this file to
allocate a destination buffer of the right length. The state remains valid after
a call to `digest`, meaning the user may feed more data into the hash via
`update`. (The finish function operates on an internal copy of the state and
therefore does not invalidate the client-held state.)"]
val digest: a:G.erased Hash.alg -> digest_st a
let digest a state output l =
let a = alg_of_state a state in
match a with
| MD5 -> digest_md5 state output l
| SHA1 -> digest_sha1 state output l
| SHA2_224 -> digest_sha224 state output l
| SHA2_256 -> digest_sha256 state output l
| SHA2_384 -> digest_sha384 state output l
| SHA2_512 -> digest_sha512 state output l
| SHA3_224 -> digest_sha3_224 state output l
| SHA3_256 -> digest_sha3_256 state output l
| SHA3_384 -> digest_sha3_384 state output l
| SHA3_512 -> digest_sha3_512 state output l
| Blake2S -> digest_blake2s state output l
| Blake2B -> digest_blake2b state output l
[@@ Comment | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: FStar.Ghost.erased EverCrypt.Hash.alg
-> Hacl.Streaming.Functor.free_st EverCrypt.Hash.Incremental.evercrypt_hash
(FStar.Ghost.reveal i)
(EverCrypt.Hash.state (FStar.Ghost.reveal i))
(FStar.Ghost.erased Prims.unit) | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"EverCrypt.Hash.alg",
"Hacl.Streaming.Functor.free",
"Spec.Hash.Definitions.fixed_len_alg",
"EverCrypt.Hash.Incremental.evercrypt_hash",
"EverCrypt.Hash.state",
"FStar.Ghost.reveal",
"Prims.unit",
"Hacl.Streaming.Functor.free_st"
] | [] | false | false | false | false | false | let free (i: G.erased Hash.alg) =
| F.free evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit) | false |
|
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.digest_blake2s | val digest_blake2s:digest_st Blake2S | val digest_blake2s:digest_st Blake2S | let digest_blake2s: digest_st Blake2S = F.digest evercrypt_hash Blake2S (EverCrypt.Hash.state Blake2S) (G.erased unit) | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 118,
"end_line": 221,
"start_col": 0,
"start_line": 221
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a
inline_for_extraction noextract
let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
()
inline_for_extraction noextract
let prev_length_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Incremental.prev_length_t a
=
if is_keccak a then
()
else
i
#push-options "--z3rlimit 500"
inline_for_extraction noextract
let evercrypt_hash : block Hash.alg =
Block
Erased
agile_state
(stateful_unused Hash.alg)
unit
Hacl.Hash.Definitions.max_input_len64
(fun a () -> Spec.Hash.Definitions.hash_length a)
block_len
block_len // No vectorization
(fun _ -> 0ul)
(fun _ _ -> S.empty)
(fun a _ -> Spec.Agile.Hash.init a)
(fun a s prevlen input ->
let prevlen = extra_state_of_nat a prevlen in
Spec.Agile.Hash.update_multi a s prevlen input)
(fun a s prevlen input ->
let prevlen = prev_length_of_nat a prevlen in
Spec.Hash.Incremental.update_last a s prevlen input)
(fun a _ s () -> Spec.Agile.Hash.finish a s ())
(fun a _ s () -> Spec.Agile.Hash.hash a s)
(fun a s prevlen ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_zero_blake a prevlen s
else
Spec.Hash.Lemmas.update_multi_zero a s)
(* update_multi_associative *)
(fun a s prevlen1 prevlen2 input1 input2 ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_associative_blake a s prevlen1 prevlen2 input1 input2
else
Spec.Hash.Lemmas.update_multi_associative a s input1 input2)
(* spec_is_incremental *)
(fun a _ input () ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input ())
EverCrypt.Hash.alg_of_state
(fun i _ _ -> EverCrypt.Hash.init #i)
(fun i s prevlen blocks len -> EverCrypt.Hash.update_multi #i s prevlen blocks len)
(fun i s prevlen last last_len ->
EverCrypt.Hash.update_last #i s prevlen last last_len)
(fun i _ s dst _ -> EverCrypt.Hash.finish #i s dst)
#pop-options
let state_t =
F.state_s evercrypt_hash SHA2_256 ((agile_state).s SHA2_256) (G.erased unit)
// Public API (streaming)
// ----------------------
[@@ Comment
"Allocate initial state for the agile hash. The argument `a` stands for the
choice of algorithm (see Hacl_Spec.h). This API will automatically pick the most
efficient implementation, provided you have called EverCrypt_AutoConfig2_init()
before. The state is to be freed by calling `free`."]
let malloc a = F.malloc evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) ()
[@@ Comment
"Reset an existing state to the initial hash state with empty data."]
let reset (a: G.erased Hash.alg) = F.reset evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Feed an arbitrary amount of data into the hash. This function returns
EverCrypt_Error_Success for success, or EverCrypt_Error_MaximumLengthExceeded if
the combined length of all of the data passed to `update` (since the last call
to `init`) exceeds 2^61-1 bytes or 2^64-1 bytes, depending on the choice of
algorithm. Both limits are unlikely to be attained in practice."]
let update (i: G.erased Hash.alg)
(state:F.state evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit))
(chunk: B.buffer uint8)
(chunk_len: UInt32.t):
Stack EverCrypt.Error.error_code
(requires fun h0 -> F.update_pre evercrypt_hash i state chunk chunk_len h0)
(ensures fun h0 e h1 ->
match e with
| EverCrypt.Error.Success ->
S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i) /\
F.update_post evercrypt_hash i state chunk chunk_len h0 h1
| EverCrypt.Error.MaximumLengthExceeded ->
h0 == h1 /\
not (S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i))
| _ -> False)
=
match F.update evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit) state chunk chunk_len with
| Hacl.Streaming.Types.Success -> EverCrypt.Error.Success
| Hacl.Streaming.Types.MaximumLengthExceeded -> EverCrypt.Error.MaximumLengthExceeded
inline_for_extraction noextract
let digest_st a = F.digest_st evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
/// The wrapper pattern, to ensure that the stack-allocated state is properly
/// monomorphized.
private
let digest_md5: digest_st MD5 = F.digest evercrypt_hash MD5 (EverCrypt.Hash.state MD5) (G.erased unit)
private
let digest_sha1: digest_st SHA1 = F.digest evercrypt_hash SHA1 (EverCrypt.Hash.state SHA1) (G.erased unit)
private
let digest_sha224: digest_st SHA2_224 = F.digest evercrypt_hash SHA2_224 (EverCrypt.Hash.state SHA2_224) (G.erased unit)
private
let digest_sha256: digest_st SHA2_256 = F.digest evercrypt_hash SHA2_256 (EverCrypt.Hash.state SHA2_256) (G.erased unit)
private
let digest_sha3_224: digest_st SHA3_224 = F.digest evercrypt_hash SHA3_224 (EverCrypt.Hash.state SHA3_224) (G.erased unit)
private
let digest_sha3_256: digest_st SHA3_256 = F.digest evercrypt_hash SHA3_256 (EverCrypt.Hash.state SHA3_256) (G.erased unit)
private
let digest_sha3_384: digest_st SHA3_384 = F.digest evercrypt_hash SHA3_384 (EverCrypt.Hash.state SHA3_384) (G.erased unit)
private
let digest_sha3_512: digest_st SHA3_512 = F.digest evercrypt_hash SHA3_512 (EverCrypt.Hash.state SHA3_512) (G.erased unit)
private
let digest_sha384: digest_st SHA2_384 = F.digest evercrypt_hash SHA2_384 (EverCrypt.Hash.state SHA2_384) (G.erased unit)
private
let digest_sha512: digest_st SHA2_512 = F.digest evercrypt_hash SHA2_512 (EverCrypt.Hash.state SHA2_512) (G.erased unit) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.Hash.Incremental.digest_st Spec.Hash.Definitions.Blake2S | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.digest",
"Spec.Hash.Definitions.fixed_len_alg",
"EverCrypt.Hash.Incremental.evercrypt_hash",
"Spec.Hash.Definitions.Blake2S",
"EverCrypt.Hash.state",
"FStar.Ghost.erased",
"Prims.unit"
] | [] | false | false | false | true | false | let digest_blake2s:digest_st Blake2S =
| F.digest evercrypt_hash Blake2S (EverCrypt.Hash.state Blake2S) (G.erased unit) | false |
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.hash_len | val hash_len (a: Hash.alg) : (x: UInt32.t{UInt32.v x == Spec.Agile.Hash.hash_length a}) | val hash_len (a: Hash.alg) : (x: UInt32.t{UInt32.v x == Spec.Agile.Hash.hash_length a}) | let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 31,
"end_line": 73,
"start_col": 0,
"start_line": 60
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: EverCrypt.Hash.alg -> x: FStar.UInt32.t{FStar.UInt32.v x == Spec.Hash.Definitions.hash_length a} | Prims.Tot | [
"total"
] | [] | [
"EverCrypt.Hash.alg",
"EverCrypt.Hash.Incremental.Macros.md5_hash_len",
"EverCrypt.Hash.Incremental.Macros.sha1_hash_len",
"EverCrypt.Hash.Incremental.Macros.sha2_224_hash_len",
"EverCrypt.Hash.Incremental.Macros.sha2_256_hash_len",
"EverCrypt.Hash.Incremental.Macros.sha2_384_hash_len",
"EverCrypt.Hash.Incremental.Macros.sha2_512_hash_len",
"EverCrypt.Hash.Incremental.Macros.sha3_224_hash_len",
"EverCrypt.Hash.Incremental.Macros.sha3_256_hash_len",
"EverCrypt.Hash.Incremental.Macros.sha3_384_hash_len",
"EverCrypt.Hash.Incremental.Macros.sha3_512_hash_len",
"EverCrypt.Hash.Incremental.Macros.blake2s_hash_len",
"EverCrypt.Hash.Incremental.Macros.blake2b_hash_len",
"FStar.UInt32.t",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.max_size_t",
"Prims.op_GreaterThan",
"FStar.UInt32.v",
"Spec.Hash.Definitions.hash_length"
] | [] | false | false | false | false | false | let hash_len (a: Hash.alg) : (x: UInt32.t{UInt32.v x == Spec.Agile.Hash.hash_length a}) =
| match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len | false |
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.digest_sha3_384 | val digest_sha3_384:digest_st SHA3_384 | val digest_sha3_384:digest_st SHA3_384 | let digest_sha3_384: digest_st SHA3_384 = F.digest evercrypt_hash SHA3_384 (EverCrypt.Hash.state SHA3_384) (G.erased unit) | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 122,
"end_line": 213,
"start_col": 0,
"start_line": 213
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a
inline_for_extraction noextract
let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
()
inline_for_extraction noextract
let prev_length_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Incremental.prev_length_t a
=
if is_keccak a then
()
else
i
#push-options "--z3rlimit 500"
inline_for_extraction noextract
let evercrypt_hash : block Hash.alg =
Block
Erased
agile_state
(stateful_unused Hash.alg)
unit
Hacl.Hash.Definitions.max_input_len64
(fun a () -> Spec.Hash.Definitions.hash_length a)
block_len
block_len // No vectorization
(fun _ -> 0ul)
(fun _ _ -> S.empty)
(fun a _ -> Spec.Agile.Hash.init a)
(fun a s prevlen input ->
let prevlen = extra_state_of_nat a prevlen in
Spec.Agile.Hash.update_multi a s prevlen input)
(fun a s prevlen input ->
let prevlen = prev_length_of_nat a prevlen in
Spec.Hash.Incremental.update_last a s prevlen input)
(fun a _ s () -> Spec.Agile.Hash.finish a s ())
(fun a _ s () -> Spec.Agile.Hash.hash a s)
(fun a s prevlen ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_zero_blake a prevlen s
else
Spec.Hash.Lemmas.update_multi_zero a s)
(* update_multi_associative *)
(fun a s prevlen1 prevlen2 input1 input2 ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_associative_blake a s prevlen1 prevlen2 input1 input2
else
Spec.Hash.Lemmas.update_multi_associative a s input1 input2)
(* spec_is_incremental *)
(fun a _ input () ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input ())
EverCrypt.Hash.alg_of_state
(fun i _ _ -> EverCrypt.Hash.init #i)
(fun i s prevlen blocks len -> EverCrypt.Hash.update_multi #i s prevlen blocks len)
(fun i s prevlen last last_len ->
EverCrypt.Hash.update_last #i s prevlen last last_len)
(fun i _ s dst _ -> EverCrypt.Hash.finish #i s dst)
#pop-options
let state_t =
F.state_s evercrypt_hash SHA2_256 ((agile_state).s SHA2_256) (G.erased unit)
// Public API (streaming)
// ----------------------
[@@ Comment
"Allocate initial state for the agile hash. The argument `a` stands for the
choice of algorithm (see Hacl_Spec.h). This API will automatically pick the most
efficient implementation, provided you have called EverCrypt_AutoConfig2_init()
before. The state is to be freed by calling `free`."]
let malloc a = F.malloc evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) ()
[@@ Comment
"Reset an existing state to the initial hash state with empty data."]
let reset (a: G.erased Hash.alg) = F.reset evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Feed an arbitrary amount of data into the hash. This function returns
EverCrypt_Error_Success for success, or EverCrypt_Error_MaximumLengthExceeded if
the combined length of all of the data passed to `update` (since the last call
to `init`) exceeds 2^61-1 bytes or 2^64-1 bytes, depending on the choice of
algorithm. Both limits are unlikely to be attained in practice."]
let update (i: G.erased Hash.alg)
(state:F.state evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit))
(chunk: B.buffer uint8)
(chunk_len: UInt32.t):
Stack EverCrypt.Error.error_code
(requires fun h0 -> F.update_pre evercrypt_hash i state chunk chunk_len h0)
(ensures fun h0 e h1 ->
match e with
| EverCrypt.Error.Success ->
S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i) /\
F.update_post evercrypt_hash i state chunk chunk_len h0 h1
| EverCrypt.Error.MaximumLengthExceeded ->
h0 == h1 /\
not (S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i))
| _ -> False)
=
match F.update evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit) state chunk chunk_len with
| Hacl.Streaming.Types.Success -> EverCrypt.Error.Success
| Hacl.Streaming.Types.MaximumLengthExceeded -> EverCrypt.Error.MaximumLengthExceeded
inline_for_extraction noextract
let digest_st a = F.digest_st evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
/// The wrapper pattern, to ensure that the stack-allocated state is properly
/// monomorphized.
private
let digest_md5: digest_st MD5 = F.digest evercrypt_hash MD5 (EverCrypt.Hash.state MD5) (G.erased unit)
private
let digest_sha1: digest_st SHA1 = F.digest evercrypt_hash SHA1 (EverCrypt.Hash.state SHA1) (G.erased unit)
private
let digest_sha224: digest_st SHA2_224 = F.digest evercrypt_hash SHA2_224 (EverCrypt.Hash.state SHA2_224) (G.erased unit)
private
let digest_sha256: digest_st SHA2_256 = F.digest evercrypt_hash SHA2_256 (EverCrypt.Hash.state SHA2_256) (G.erased unit)
private
let digest_sha3_224: digest_st SHA3_224 = F.digest evercrypt_hash SHA3_224 (EverCrypt.Hash.state SHA3_224) (G.erased unit)
private
let digest_sha3_256: digest_st SHA3_256 = F.digest evercrypt_hash SHA3_256 (EverCrypt.Hash.state SHA3_256) (G.erased unit) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.Hash.Incremental.digest_st Spec.Hash.Definitions.SHA3_384 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.digest",
"Spec.Hash.Definitions.fixed_len_alg",
"EverCrypt.Hash.Incremental.evercrypt_hash",
"Spec.Hash.Definitions.SHA3_384",
"EverCrypt.Hash.state",
"FStar.Ghost.erased",
"Prims.unit"
] | [] | false | false | false | true | false | let digest_sha3_384:digest_st SHA3_384 =
| F.digest evercrypt_hash SHA3_384 (EverCrypt.Hash.state SHA3_384) (G.erased unit) | false |
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.state | val state : a: EverCrypt.Hash.alg -> Type0 | let state (a: Hash.alg) = F.state evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 91,
"end_line": 344,
"start_col": 0,
"start_line": 344
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a
inline_for_extraction noextract
let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
()
inline_for_extraction noextract
let prev_length_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Incremental.prev_length_t a
=
if is_keccak a then
()
else
i
#push-options "--z3rlimit 500"
inline_for_extraction noextract
let evercrypt_hash : block Hash.alg =
Block
Erased
agile_state
(stateful_unused Hash.alg)
unit
Hacl.Hash.Definitions.max_input_len64
(fun a () -> Spec.Hash.Definitions.hash_length a)
block_len
block_len // No vectorization
(fun _ -> 0ul)
(fun _ _ -> S.empty)
(fun a _ -> Spec.Agile.Hash.init a)
(fun a s prevlen input ->
let prevlen = extra_state_of_nat a prevlen in
Spec.Agile.Hash.update_multi a s prevlen input)
(fun a s prevlen input ->
let prevlen = prev_length_of_nat a prevlen in
Spec.Hash.Incremental.update_last a s prevlen input)
(fun a _ s () -> Spec.Agile.Hash.finish a s ())
(fun a _ s () -> Spec.Agile.Hash.hash a s)
(fun a s prevlen ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_zero_blake a prevlen s
else
Spec.Hash.Lemmas.update_multi_zero a s)
(* update_multi_associative *)
(fun a s prevlen1 prevlen2 input1 input2 ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_associative_blake a s prevlen1 prevlen2 input1 input2
else
Spec.Hash.Lemmas.update_multi_associative a s input1 input2)
(* spec_is_incremental *)
(fun a _ input () ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input ())
EverCrypt.Hash.alg_of_state
(fun i _ _ -> EverCrypt.Hash.init #i)
(fun i s prevlen blocks len -> EverCrypt.Hash.update_multi #i s prevlen blocks len)
(fun i s prevlen last last_len ->
EverCrypt.Hash.update_last #i s prevlen last last_len)
(fun i _ s dst _ -> EverCrypt.Hash.finish #i s dst)
#pop-options
let state_t =
F.state_s evercrypt_hash SHA2_256 ((agile_state).s SHA2_256) (G.erased unit)
// Public API (streaming)
// ----------------------
[@@ Comment
"Allocate initial state for the agile hash. The argument `a` stands for the
choice of algorithm (see Hacl_Spec.h). This API will automatically pick the most
efficient implementation, provided you have called EverCrypt_AutoConfig2_init()
before. The state is to be freed by calling `free`."]
let malloc a = F.malloc evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) ()
[@@ Comment
"Reset an existing state to the initial hash state with empty data."]
let reset (a: G.erased Hash.alg) = F.reset evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Feed an arbitrary amount of data into the hash. This function returns
EverCrypt_Error_Success for success, or EverCrypt_Error_MaximumLengthExceeded if
the combined length of all of the data passed to `update` (since the last call
to `init`) exceeds 2^61-1 bytes or 2^64-1 bytes, depending on the choice of
algorithm. Both limits are unlikely to be attained in practice."]
let update (i: G.erased Hash.alg)
(state:F.state evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit))
(chunk: B.buffer uint8)
(chunk_len: UInt32.t):
Stack EverCrypt.Error.error_code
(requires fun h0 -> F.update_pre evercrypt_hash i state chunk chunk_len h0)
(ensures fun h0 e h1 ->
match e with
| EverCrypt.Error.Success ->
S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i) /\
F.update_post evercrypt_hash i state chunk chunk_len h0 h1
| EverCrypt.Error.MaximumLengthExceeded ->
h0 == h1 /\
not (S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i))
| _ -> False)
=
match F.update evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit) state chunk chunk_len with
| Hacl.Streaming.Types.Success -> EverCrypt.Error.Success
| Hacl.Streaming.Types.MaximumLengthExceeded -> EverCrypt.Error.MaximumLengthExceeded
inline_for_extraction noextract
let digest_st a = F.digest_st evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
/// The wrapper pattern, to ensure that the stack-allocated state is properly
/// monomorphized.
private
let digest_md5: digest_st MD5 = F.digest evercrypt_hash MD5 (EverCrypt.Hash.state MD5) (G.erased unit)
private
let digest_sha1: digest_st SHA1 = F.digest evercrypt_hash SHA1 (EverCrypt.Hash.state SHA1) (G.erased unit)
private
let digest_sha224: digest_st SHA2_224 = F.digest evercrypt_hash SHA2_224 (EverCrypt.Hash.state SHA2_224) (G.erased unit)
private
let digest_sha256: digest_st SHA2_256 = F.digest evercrypt_hash SHA2_256 (EverCrypt.Hash.state SHA2_256) (G.erased unit)
private
let digest_sha3_224: digest_st SHA3_224 = F.digest evercrypt_hash SHA3_224 (EverCrypt.Hash.state SHA3_224) (G.erased unit)
private
let digest_sha3_256: digest_st SHA3_256 = F.digest evercrypt_hash SHA3_256 (EverCrypt.Hash.state SHA3_256) (G.erased unit)
private
let digest_sha3_384: digest_st SHA3_384 = F.digest evercrypt_hash SHA3_384 (EverCrypt.Hash.state SHA3_384) (G.erased unit)
private
let digest_sha3_512: digest_st SHA3_512 = F.digest evercrypt_hash SHA3_512 (EverCrypt.Hash.state SHA3_512) (G.erased unit)
private
let digest_sha384: digest_st SHA2_384 = F.digest evercrypt_hash SHA2_384 (EverCrypt.Hash.state SHA2_384) (G.erased unit)
private
let digest_sha512: digest_st SHA2_512 = F.digest evercrypt_hash SHA2_512 (EverCrypt.Hash.state SHA2_512) (G.erased unit)
private
let digest_blake2s: digest_st Blake2S = F.digest evercrypt_hash Blake2S (EverCrypt.Hash.state Blake2S) (G.erased unit)
private
let digest_blake2b: digest_st Blake2B = F.digest evercrypt_hash Blake2B (EverCrypt.Hash.state Blake2B) (G.erased unit)
[@@ Comment
"Perform a run-time test to determine which algorithm was chosen for the given piece of state."]
let alg_of_state (a: G.erased Hash.alg) = F.index_of_state evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Write the resulting hash into `output`, an array whose length is
algorithm-specific. You can use the macros defined earlier in this file to
allocate a destination buffer of the right length. The state remains valid after
a call to `digest`, meaning the user may feed more data into the hash via
`update`. (The finish function operates on an internal copy of the state and
therefore does not invalidate the client-held state.)"]
val digest: a:G.erased Hash.alg -> digest_st a
let digest a state output l =
let a = alg_of_state a state in
match a with
| MD5 -> digest_md5 state output l
| SHA1 -> digest_sha1 state output l
| SHA2_224 -> digest_sha224 state output l
| SHA2_256 -> digest_sha256 state output l
| SHA2_384 -> digest_sha384 state output l
| SHA2_512 -> digest_sha512 state output l
| SHA3_224 -> digest_sha3_224 state output l
| SHA3_256 -> digest_sha3_256 state output l
| SHA3_384 -> digest_sha3_384 state output l
| SHA3_512 -> digest_sha3_512 state output l
| Blake2S -> digest_blake2s state output l
| Blake2B -> digest_blake2b state output l
[@@ Comment
"Free a state previously allocated with `create_in`."]
let free (i: G.erased Hash.alg) = F.free evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit)
// Private API (one-shot, multiplexing)
// ------------------------------------
private
val hash_256: Hacl.Hash.Definitions.hash_st SHA2_256
// A full one-shot hash that relies on vale at each multiplexing point
let hash_256 output input input_len =
let open EverCrypt.Hash in
// TODO: This function now only exists for SHA1 and MD5
Hacl.Hash.MD.mk_hash SHA2_256 Hacl.Hash.SHA2.alloca_256 update_multi_256
Hacl.Hash.SHA2.update_last_256 Hacl.Hash.SHA2.finish_256 output input input_len
private
val hash_224: Hacl.Hash.Definitions.hash_st SHA2_224
let hash_224 output input input_len =
let open EverCrypt.Hash in
Hacl.Hash.MD.mk_hash SHA2_224 Hacl.Hash.SHA2.alloca_224 update_multi_224
Hacl.Hash.SHA2.update_last_224 Hacl.Hash.SHA2.finish_224 output input input_len
// Public API (one-shot, agile and multiplexing)
// ---------------------------------------------
// NOTE: this function goes through all the Hacl.Hash.* wrappers which export
// the correct agile low-level type, and thus does not need to be aware of the
// implementation of Spec.Agile.Hash (no friend-ing).
//
// ALSO: for some reason, this function was historically exported with an order
// of arguments different from Hacl.Hash.Definitions.hash_st a. Would be worth
// fixing at some point.
[@@ Comment
"Hash `input`, of len `input_len`, into `output`, an array whose length is determined by
your choice of algorithm `a` (see Hacl_Spec.h). You can use the macros defined
earlier in this file to allocate a destination buffer of the right length. This
API will automatically pick the most efficient implementation, provided you have
called EverCrypt_AutoConfig2_init() before. "]
val hash:
a:Hash.alg ->
output:B.buffer Lib.IntTypes.uint8 {B.length output = hash_length a} ->
input:B.buffer Lib.IntTypes.uint8 ->
input_len:FStar.UInt32.t {B.length input = FStar.UInt32.v input_len /\ FStar.UInt32.v input_len `less_than_max_input_length` a} ->
Stack unit
(requires fun h0 ->
B.live h0 output /\
B.live h0 input /\
B.(loc_disjoint (loc_buffer input) (loc_buffer output)))
(ensures fun h0 _ h1 ->
B.(modifies (loc_buffer output) h0 h1) /\
B.as_seq h1 output == Spec.Agile.Hash.hash a (B.as_seq h0 input))
let hash a output input input_len =
match a with
| MD5 -> Hacl.Hash.MD5.hash_oneshot output input input_len
| SHA1 -> Hacl.Hash.SHA1.hash_oneshot output input input_len
| SHA2_224 -> hash_224 output input input_len
| SHA2_256 -> hash_256 output input input_len
| SHA2_384 -> Hacl.Streaming.SHA2.hash_384 output input input_len
| SHA2_512 -> Hacl.Streaming.SHA2.hash_512 output input input_len
| SHA3_224 -> Hacl.Hash.SHA3.hash SHA3_224 output input input_len
| SHA3_256 -> Hacl.Hash.SHA3.hash SHA3_256 output input input_len
| SHA3_384 -> Hacl.Hash.SHA3.hash SHA3_384 output input input_len
| SHA3_512 -> Hacl.Hash.SHA3.hash SHA3_512 output input input_len
| Blake2S ->
if EverCrypt.TargetConfig.hacl_can_compile_vec128 then
let vec128 = EverCrypt.AutoConfig2.has_vec128 () in
if vec128 then
Hacl.Hash.Blake2s_128.hash output input input_len
else
Hacl.Hash.Blake2s_32.hash output input input_len
else
Hacl.Hash.Blake2s_32.hash output input input_len
| Blake2B ->
if EverCrypt.TargetConfig.hacl_can_compile_vec256 then
let vec256 = EverCrypt.AutoConfig2.has_vec256 () in
if vec256 then
Hacl.Hash.Blake2b_256.hash output input input_len
else
Hacl.Hash.Blake2b_32.hash output input input_len
else
Hacl.Hash.Blake2b_32.hash output input input_len
// Public API (verified clients)
// -----------------------------
/// Finally, a few helpers predicates to make things easier for clients... | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: EverCrypt.Hash.alg -> Type0 | Prims.Tot | [
"total"
] | [] | [
"EverCrypt.Hash.alg",
"Hacl.Streaming.Functor.state",
"Spec.Hash.Definitions.fixed_len_alg",
"EverCrypt.Hash.Incremental.evercrypt_hash",
"EverCrypt.Hash.state",
"FStar.Ghost.erased",
"Prims.unit"
] | [] | false | false | false | true | true | let state (a: Hash.alg) =
| F.state evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) | false |
|
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.digest_sha3_512 | val digest_sha3_512:digest_st SHA3_512 | val digest_sha3_512:digest_st SHA3_512 | let digest_sha3_512: digest_st SHA3_512 = F.digest evercrypt_hash SHA3_512 (EverCrypt.Hash.state SHA3_512) (G.erased unit) | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 122,
"end_line": 215,
"start_col": 0,
"start_line": 215
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a
inline_for_extraction noextract
let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
()
inline_for_extraction noextract
let prev_length_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Incremental.prev_length_t a
=
if is_keccak a then
()
else
i
#push-options "--z3rlimit 500"
inline_for_extraction noextract
let evercrypt_hash : block Hash.alg =
Block
Erased
agile_state
(stateful_unused Hash.alg)
unit
Hacl.Hash.Definitions.max_input_len64
(fun a () -> Spec.Hash.Definitions.hash_length a)
block_len
block_len // No vectorization
(fun _ -> 0ul)
(fun _ _ -> S.empty)
(fun a _ -> Spec.Agile.Hash.init a)
(fun a s prevlen input ->
let prevlen = extra_state_of_nat a prevlen in
Spec.Agile.Hash.update_multi a s prevlen input)
(fun a s prevlen input ->
let prevlen = prev_length_of_nat a prevlen in
Spec.Hash.Incremental.update_last a s prevlen input)
(fun a _ s () -> Spec.Agile.Hash.finish a s ())
(fun a _ s () -> Spec.Agile.Hash.hash a s)
(fun a s prevlen ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_zero_blake a prevlen s
else
Spec.Hash.Lemmas.update_multi_zero a s)
(* update_multi_associative *)
(fun a s prevlen1 prevlen2 input1 input2 ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_associative_blake a s prevlen1 prevlen2 input1 input2
else
Spec.Hash.Lemmas.update_multi_associative a s input1 input2)
(* spec_is_incremental *)
(fun a _ input () ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input ())
EverCrypt.Hash.alg_of_state
(fun i _ _ -> EverCrypt.Hash.init #i)
(fun i s prevlen blocks len -> EverCrypt.Hash.update_multi #i s prevlen blocks len)
(fun i s prevlen last last_len ->
EverCrypt.Hash.update_last #i s prevlen last last_len)
(fun i _ s dst _ -> EverCrypt.Hash.finish #i s dst)
#pop-options
let state_t =
F.state_s evercrypt_hash SHA2_256 ((agile_state).s SHA2_256) (G.erased unit)
// Public API (streaming)
// ----------------------
[@@ Comment
"Allocate initial state for the agile hash. The argument `a` stands for the
choice of algorithm (see Hacl_Spec.h). This API will automatically pick the most
efficient implementation, provided you have called EverCrypt_AutoConfig2_init()
before. The state is to be freed by calling `free`."]
let malloc a = F.malloc evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) ()
[@@ Comment
"Reset an existing state to the initial hash state with empty data."]
let reset (a: G.erased Hash.alg) = F.reset evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Feed an arbitrary amount of data into the hash. This function returns
EverCrypt_Error_Success for success, or EverCrypt_Error_MaximumLengthExceeded if
the combined length of all of the data passed to `update` (since the last call
to `init`) exceeds 2^61-1 bytes or 2^64-1 bytes, depending on the choice of
algorithm. Both limits are unlikely to be attained in practice."]
let update (i: G.erased Hash.alg)
(state:F.state evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit))
(chunk: B.buffer uint8)
(chunk_len: UInt32.t):
Stack EverCrypt.Error.error_code
(requires fun h0 -> F.update_pre evercrypt_hash i state chunk chunk_len h0)
(ensures fun h0 e h1 ->
match e with
| EverCrypt.Error.Success ->
S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i) /\
F.update_post evercrypt_hash i state chunk chunk_len h0 h1
| EverCrypt.Error.MaximumLengthExceeded ->
h0 == h1 /\
not (S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i))
| _ -> False)
=
match F.update evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit) state chunk chunk_len with
| Hacl.Streaming.Types.Success -> EverCrypt.Error.Success
| Hacl.Streaming.Types.MaximumLengthExceeded -> EverCrypt.Error.MaximumLengthExceeded
inline_for_extraction noextract
let digest_st a = F.digest_st evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
/// The wrapper pattern, to ensure that the stack-allocated state is properly
/// monomorphized.
private
let digest_md5: digest_st MD5 = F.digest evercrypt_hash MD5 (EverCrypt.Hash.state MD5) (G.erased unit)
private
let digest_sha1: digest_st SHA1 = F.digest evercrypt_hash SHA1 (EverCrypt.Hash.state SHA1) (G.erased unit)
private
let digest_sha224: digest_st SHA2_224 = F.digest evercrypt_hash SHA2_224 (EverCrypt.Hash.state SHA2_224) (G.erased unit)
private
let digest_sha256: digest_st SHA2_256 = F.digest evercrypt_hash SHA2_256 (EverCrypt.Hash.state SHA2_256) (G.erased unit)
private
let digest_sha3_224: digest_st SHA3_224 = F.digest evercrypt_hash SHA3_224 (EverCrypt.Hash.state SHA3_224) (G.erased unit)
private
let digest_sha3_256: digest_st SHA3_256 = F.digest evercrypt_hash SHA3_256 (EverCrypt.Hash.state SHA3_256) (G.erased unit)
private
let digest_sha3_384: digest_st SHA3_384 = F.digest evercrypt_hash SHA3_384 (EverCrypt.Hash.state SHA3_384) (G.erased unit) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.Hash.Incremental.digest_st Spec.Hash.Definitions.SHA3_512 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.digest",
"Spec.Hash.Definitions.fixed_len_alg",
"EverCrypt.Hash.Incremental.evercrypt_hash",
"Spec.Hash.Definitions.SHA3_512",
"EverCrypt.Hash.state",
"FStar.Ghost.erased",
"Prims.unit"
] | [] | false | false | false | true | false | let digest_sha3_512:digest_st SHA3_512 =
| F.digest evercrypt_hash SHA3_512 (EverCrypt.Hash.state SHA3_512) (G.erased unit) | false |
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.digest_md5 | val digest_md5:digest_st MD5 | val digest_md5:digest_st MD5 | let digest_md5: digest_st MD5 = F.digest evercrypt_hash MD5 (EverCrypt.Hash.state MD5) (G.erased unit) | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 102,
"end_line": 201,
"start_col": 0,
"start_line": 201
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a
inline_for_extraction noextract
let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
()
inline_for_extraction noextract
let prev_length_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Incremental.prev_length_t a
=
if is_keccak a then
()
else
i
#push-options "--z3rlimit 500"
inline_for_extraction noextract
let evercrypt_hash : block Hash.alg =
Block
Erased
agile_state
(stateful_unused Hash.alg)
unit
Hacl.Hash.Definitions.max_input_len64
(fun a () -> Spec.Hash.Definitions.hash_length a)
block_len
block_len // No vectorization
(fun _ -> 0ul)
(fun _ _ -> S.empty)
(fun a _ -> Spec.Agile.Hash.init a)
(fun a s prevlen input ->
let prevlen = extra_state_of_nat a prevlen in
Spec.Agile.Hash.update_multi a s prevlen input)
(fun a s prevlen input ->
let prevlen = prev_length_of_nat a prevlen in
Spec.Hash.Incremental.update_last a s prevlen input)
(fun a _ s () -> Spec.Agile.Hash.finish a s ())
(fun a _ s () -> Spec.Agile.Hash.hash a s)
(fun a s prevlen ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_zero_blake a prevlen s
else
Spec.Hash.Lemmas.update_multi_zero a s)
(* update_multi_associative *)
(fun a s prevlen1 prevlen2 input1 input2 ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_associative_blake a s prevlen1 prevlen2 input1 input2
else
Spec.Hash.Lemmas.update_multi_associative a s input1 input2)
(* spec_is_incremental *)
(fun a _ input () ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input ())
EverCrypt.Hash.alg_of_state
(fun i _ _ -> EverCrypt.Hash.init #i)
(fun i s prevlen blocks len -> EverCrypt.Hash.update_multi #i s prevlen blocks len)
(fun i s prevlen last last_len ->
EverCrypt.Hash.update_last #i s prevlen last last_len)
(fun i _ s dst _ -> EverCrypt.Hash.finish #i s dst)
#pop-options
let state_t =
F.state_s evercrypt_hash SHA2_256 ((agile_state).s SHA2_256) (G.erased unit)
// Public API (streaming)
// ----------------------
[@@ Comment
"Allocate initial state for the agile hash. The argument `a` stands for the
choice of algorithm (see Hacl_Spec.h). This API will automatically pick the most
efficient implementation, provided you have called EverCrypt_AutoConfig2_init()
before. The state is to be freed by calling `free`."]
let malloc a = F.malloc evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) ()
[@@ Comment
"Reset an existing state to the initial hash state with empty data."]
let reset (a: G.erased Hash.alg) = F.reset evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Feed an arbitrary amount of data into the hash. This function returns
EverCrypt_Error_Success for success, or EverCrypt_Error_MaximumLengthExceeded if
the combined length of all of the data passed to `update` (since the last call
to `init`) exceeds 2^61-1 bytes or 2^64-1 bytes, depending on the choice of
algorithm. Both limits are unlikely to be attained in practice."]
let update (i: G.erased Hash.alg)
(state:F.state evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit))
(chunk: B.buffer uint8)
(chunk_len: UInt32.t):
Stack EverCrypt.Error.error_code
(requires fun h0 -> F.update_pre evercrypt_hash i state chunk chunk_len h0)
(ensures fun h0 e h1 ->
match e with
| EverCrypt.Error.Success ->
S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i) /\
F.update_post evercrypt_hash i state chunk chunk_len h0 h1
| EverCrypt.Error.MaximumLengthExceeded ->
h0 == h1 /\
not (S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i))
| _ -> False)
=
match F.update evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit) state chunk chunk_len with
| Hacl.Streaming.Types.Success -> EverCrypt.Error.Success
| Hacl.Streaming.Types.MaximumLengthExceeded -> EverCrypt.Error.MaximumLengthExceeded
inline_for_extraction noextract
let digest_st a = F.digest_st evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
/// The wrapper pattern, to ensure that the stack-allocated state is properly
/// monomorphized. | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.Hash.Incremental.digest_st Spec.Hash.Definitions.MD5 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.digest",
"Spec.Hash.Definitions.fixed_len_alg",
"EverCrypt.Hash.Incremental.evercrypt_hash",
"Spec.Hash.Definitions.MD5",
"EverCrypt.Hash.state",
"FStar.Ghost.erased",
"Prims.unit"
] | [] | false | false | false | true | false | let digest_md5:digest_st MD5 =
| F.digest evercrypt_hash MD5 (EverCrypt.Hash.state MD5) (G.erased unit) | false |
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.digest_sha512 | val digest_sha512:digest_st SHA2_512 | val digest_sha512:digest_st SHA2_512 | let digest_sha512: digest_st SHA2_512 = F.digest evercrypt_hash SHA2_512 (EverCrypt.Hash.state SHA2_512) (G.erased unit) | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 120,
"end_line": 219,
"start_col": 0,
"start_line": 219
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a
inline_for_extraction noextract
let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
()
inline_for_extraction noextract
let prev_length_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Incremental.prev_length_t a
=
if is_keccak a then
()
else
i
#push-options "--z3rlimit 500"
inline_for_extraction noextract
let evercrypt_hash : block Hash.alg =
Block
Erased
agile_state
(stateful_unused Hash.alg)
unit
Hacl.Hash.Definitions.max_input_len64
(fun a () -> Spec.Hash.Definitions.hash_length a)
block_len
block_len // No vectorization
(fun _ -> 0ul)
(fun _ _ -> S.empty)
(fun a _ -> Spec.Agile.Hash.init a)
(fun a s prevlen input ->
let prevlen = extra_state_of_nat a prevlen in
Spec.Agile.Hash.update_multi a s prevlen input)
(fun a s prevlen input ->
let prevlen = prev_length_of_nat a prevlen in
Spec.Hash.Incremental.update_last a s prevlen input)
(fun a _ s () -> Spec.Agile.Hash.finish a s ())
(fun a _ s () -> Spec.Agile.Hash.hash a s)
(fun a s prevlen ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_zero_blake a prevlen s
else
Spec.Hash.Lemmas.update_multi_zero a s)
(* update_multi_associative *)
(fun a s prevlen1 prevlen2 input1 input2 ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_associative_blake a s prevlen1 prevlen2 input1 input2
else
Spec.Hash.Lemmas.update_multi_associative a s input1 input2)
(* spec_is_incremental *)
(fun a _ input () ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input ())
EverCrypt.Hash.alg_of_state
(fun i _ _ -> EverCrypt.Hash.init #i)
(fun i s prevlen blocks len -> EverCrypt.Hash.update_multi #i s prevlen blocks len)
(fun i s prevlen last last_len ->
EverCrypt.Hash.update_last #i s prevlen last last_len)
(fun i _ s dst _ -> EverCrypt.Hash.finish #i s dst)
#pop-options
let state_t =
F.state_s evercrypt_hash SHA2_256 ((agile_state).s SHA2_256) (G.erased unit)
// Public API (streaming)
// ----------------------
[@@ Comment
"Allocate initial state for the agile hash. The argument `a` stands for the
choice of algorithm (see Hacl_Spec.h). This API will automatically pick the most
efficient implementation, provided you have called EverCrypt_AutoConfig2_init()
before. The state is to be freed by calling `free`."]
let malloc a = F.malloc evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) ()
[@@ Comment
"Reset an existing state to the initial hash state with empty data."]
let reset (a: G.erased Hash.alg) = F.reset evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Feed an arbitrary amount of data into the hash. This function returns
EverCrypt_Error_Success for success, or EverCrypt_Error_MaximumLengthExceeded if
the combined length of all of the data passed to `update` (since the last call
to `init`) exceeds 2^61-1 bytes or 2^64-1 bytes, depending on the choice of
algorithm. Both limits are unlikely to be attained in practice."]
let update (i: G.erased Hash.alg)
(state:F.state evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit))
(chunk: B.buffer uint8)
(chunk_len: UInt32.t):
Stack EverCrypt.Error.error_code
(requires fun h0 -> F.update_pre evercrypt_hash i state chunk chunk_len h0)
(ensures fun h0 e h1 ->
match e with
| EverCrypt.Error.Success ->
S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i) /\
F.update_post evercrypt_hash i state chunk chunk_len h0 h1
| EverCrypt.Error.MaximumLengthExceeded ->
h0 == h1 /\
not (S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i))
| _ -> False)
=
match F.update evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit) state chunk chunk_len with
| Hacl.Streaming.Types.Success -> EverCrypt.Error.Success
| Hacl.Streaming.Types.MaximumLengthExceeded -> EverCrypt.Error.MaximumLengthExceeded
inline_for_extraction noextract
let digest_st a = F.digest_st evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
/// The wrapper pattern, to ensure that the stack-allocated state is properly
/// monomorphized.
private
let digest_md5: digest_st MD5 = F.digest evercrypt_hash MD5 (EverCrypt.Hash.state MD5) (G.erased unit)
private
let digest_sha1: digest_st SHA1 = F.digest evercrypt_hash SHA1 (EverCrypt.Hash.state SHA1) (G.erased unit)
private
let digest_sha224: digest_st SHA2_224 = F.digest evercrypt_hash SHA2_224 (EverCrypt.Hash.state SHA2_224) (G.erased unit)
private
let digest_sha256: digest_st SHA2_256 = F.digest evercrypt_hash SHA2_256 (EverCrypt.Hash.state SHA2_256) (G.erased unit)
private
let digest_sha3_224: digest_st SHA3_224 = F.digest evercrypt_hash SHA3_224 (EverCrypt.Hash.state SHA3_224) (G.erased unit)
private
let digest_sha3_256: digest_st SHA3_256 = F.digest evercrypt_hash SHA3_256 (EverCrypt.Hash.state SHA3_256) (G.erased unit)
private
let digest_sha3_384: digest_st SHA3_384 = F.digest evercrypt_hash SHA3_384 (EverCrypt.Hash.state SHA3_384) (G.erased unit)
private
let digest_sha3_512: digest_st SHA3_512 = F.digest evercrypt_hash SHA3_512 (EverCrypt.Hash.state SHA3_512) (G.erased unit)
private
let digest_sha384: digest_st SHA2_384 = F.digest evercrypt_hash SHA2_384 (EverCrypt.Hash.state SHA2_384) (G.erased unit) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.Hash.Incremental.digest_st Spec.Hash.Definitions.SHA2_512 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.digest",
"Spec.Hash.Definitions.fixed_len_alg",
"EverCrypt.Hash.Incremental.evercrypt_hash",
"Spec.Hash.Definitions.SHA2_512",
"EverCrypt.Hash.state",
"FStar.Ghost.erased",
"Prims.unit"
] | [] | false | false | false | true | false | let digest_sha512:digest_st SHA2_512 =
| F.digest evercrypt_hash SHA2_512 (EverCrypt.Hash.state SHA2_512) (G.erased unit) | false |
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.digest_blake2b | val digest_blake2b:digest_st Blake2B | val digest_blake2b:digest_st Blake2B | let digest_blake2b: digest_st Blake2B = F.digest evercrypt_hash Blake2B (EverCrypt.Hash.state Blake2B) (G.erased unit) | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 118,
"end_line": 223,
"start_col": 0,
"start_line": 223
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a
inline_for_extraction noextract
let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
()
inline_for_extraction noextract
let prev_length_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Incremental.prev_length_t a
=
if is_keccak a then
()
else
i
#push-options "--z3rlimit 500"
inline_for_extraction noextract
let evercrypt_hash : block Hash.alg =
Block
Erased
agile_state
(stateful_unused Hash.alg)
unit
Hacl.Hash.Definitions.max_input_len64
(fun a () -> Spec.Hash.Definitions.hash_length a)
block_len
block_len // No vectorization
(fun _ -> 0ul)
(fun _ _ -> S.empty)
(fun a _ -> Spec.Agile.Hash.init a)
(fun a s prevlen input ->
let prevlen = extra_state_of_nat a prevlen in
Spec.Agile.Hash.update_multi a s prevlen input)
(fun a s prevlen input ->
let prevlen = prev_length_of_nat a prevlen in
Spec.Hash.Incremental.update_last a s prevlen input)
(fun a _ s () -> Spec.Agile.Hash.finish a s ())
(fun a _ s () -> Spec.Agile.Hash.hash a s)
(fun a s prevlen ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_zero_blake a prevlen s
else
Spec.Hash.Lemmas.update_multi_zero a s)
(* update_multi_associative *)
(fun a s prevlen1 prevlen2 input1 input2 ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_associative_blake a s prevlen1 prevlen2 input1 input2
else
Spec.Hash.Lemmas.update_multi_associative a s input1 input2)
(* spec_is_incremental *)
(fun a _ input () ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input ())
EverCrypt.Hash.alg_of_state
(fun i _ _ -> EverCrypt.Hash.init #i)
(fun i s prevlen blocks len -> EverCrypt.Hash.update_multi #i s prevlen blocks len)
(fun i s prevlen last last_len ->
EverCrypt.Hash.update_last #i s prevlen last last_len)
(fun i _ s dst _ -> EverCrypt.Hash.finish #i s dst)
#pop-options
let state_t =
F.state_s evercrypt_hash SHA2_256 ((agile_state).s SHA2_256) (G.erased unit)
// Public API (streaming)
// ----------------------
[@@ Comment
"Allocate initial state for the agile hash. The argument `a` stands for the
choice of algorithm (see Hacl_Spec.h). This API will automatically pick the most
efficient implementation, provided you have called EverCrypt_AutoConfig2_init()
before. The state is to be freed by calling `free`."]
let malloc a = F.malloc evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) ()
[@@ Comment
"Reset an existing state to the initial hash state with empty data."]
let reset (a: G.erased Hash.alg) = F.reset evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Feed an arbitrary amount of data into the hash. This function returns
EverCrypt_Error_Success for success, or EverCrypt_Error_MaximumLengthExceeded if
the combined length of all of the data passed to `update` (since the last call
to `init`) exceeds 2^61-1 bytes or 2^64-1 bytes, depending on the choice of
algorithm. Both limits are unlikely to be attained in practice."]
let update (i: G.erased Hash.alg)
(state:F.state evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit))
(chunk: B.buffer uint8)
(chunk_len: UInt32.t):
Stack EverCrypt.Error.error_code
(requires fun h0 -> F.update_pre evercrypt_hash i state chunk chunk_len h0)
(ensures fun h0 e h1 ->
match e with
| EverCrypt.Error.Success ->
S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i) /\
F.update_post evercrypt_hash i state chunk chunk_len h0 h1
| EverCrypt.Error.MaximumLengthExceeded ->
h0 == h1 /\
not (S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i))
| _ -> False)
=
match F.update evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit) state chunk chunk_len with
| Hacl.Streaming.Types.Success -> EverCrypt.Error.Success
| Hacl.Streaming.Types.MaximumLengthExceeded -> EverCrypt.Error.MaximumLengthExceeded
inline_for_extraction noextract
let digest_st a = F.digest_st evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
/// The wrapper pattern, to ensure that the stack-allocated state is properly
/// monomorphized.
private
let digest_md5: digest_st MD5 = F.digest evercrypt_hash MD5 (EverCrypt.Hash.state MD5) (G.erased unit)
private
let digest_sha1: digest_st SHA1 = F.digest evercrypt_hash SHA1 (EverCrypt.Hash.state SHA1) (G.erased unit)
private
let digest_sha224: digest_st SHA2_224 = F.digest evercrypt_hash SHA2_224 (EverCrypt.Hash.state SHA2_224) (G.erased unit)
private
let digest_sha256: digest_st SHA2_256 = F.digest evercrypt_hash SHA2_256 (EverCrypt.Hash.state SHA2_256) (G.erased unit)
private
let digest_sha3_224: digest_st SHA3_224 = F.digest evercrypt_hash SHA3_224 (EverCrypt.Hash.state SHA3_224) (G.erased unit)
private
let digest_sha3_256: digest_st SHA3_256 = F.digest evercrypt_hash SHA3_256 (EverCrypt.Hash.state SHA3_256) (G.erased unit)
private
let digest_sha3_384: digest_st SHA3_384 = F.digest evercrypt_hash SHA3_384 (EverCrypt.Hash.state SHA3_384) (G.erased unit)
private
let digest_sha3_512: digest_st SHA3_512 = F.digest evercrypt_hash SHA3_512 (EverCrypt.Hash.state SHA3_512) (G.erased unit)
private
let digest_sha384: digest_st SHA2_384 = F.digest evercrypt_hash SHA2_384 (EverCrypt.Hash.state SHA2_384) (G.erased unit)
private
let digest_sha512: digest_st SHA2_512 = F.digest evercrypt_hash SHA2_512 (EverCrypt.Hash.state SHA2_512) (G.erased unit)
private
let digest_blake2s: digest_st Blake2S = F.digest evercrypt_hash Blake2S (EverCrypt.Hash.state Blake2S) (G.erased unit) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | EverCrypt.Hash.Incremental.digest_st Spec.Hash.Definitions.Blake2B | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.digest",
"Spec.Hash.Definitions.fixed_len_alg",
"EverCrypt.Hash.Incremental.evercrypt_hash",
"Spec.Hash.Definitions.Blake2B",
"EverCrypt.Hash.state",
"FStar.Ghost.erased",
"Prims.unit"
] | [] | false | false | false | true | false | let digest_blake2b:digest_st Blake2B =
| F.digest evercrypt_hash Blake2B (EverCrypt.Hash.state Blake2B) (G.erased unit) | false |
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.hash_256 | val hash_256: Hacl.Hash.Definitions.hash_st SHA2_256 | val hash_256: Hacl.Hash.Definitions.hash_st SHA2_256 | let hash_256 output input input_len =
let open EverCrypt.Hash in
// TODO: This function now only exists for SHA1 and MD5
Hacl.Hash.MD.mk_hash SHA2_256 Hacl.Hash.SHA2.alloca_256 update_multi_256
Hacl.Hash.SHA2.update_last_256 Hacl.Hash.SHA2.finish_256 output input input_len | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 83,
"end_line": 268,
"start_col": 0,
"start_line": 264
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a
inline_for_extraction noextract
let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
()
inline_for_extraction noextract
let prev_length_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Incremental.prev_length_t a
=
if is_keccak a then
()
else
i
#push-options "--z3rlimit 500"
inline_for_extraction noextract
let evercrypt_hash : block Hash.alg =
Block
Erased
agile_state
(stateful_unused Hash.alg)
unit
Hacl.Hash.Definitions.max_input_len64
(fun a () -> Spec.Hash.Definitions.hash_length a)
block_len
block_len // No vectorization
(fun _ -> 0ul)
(fun _ _ -> S.empty)
(fun a _ -> Spec.Agile.Hash.init a)
(fun a s prevlen input ->
let prevlen = extra_state_of_nat a prevlen in
Spec.Agile.Hash.update_multi a s prevlen input)
(fun a s prevlen input ->
let prevlen = prev_length_of_nat a prevlen in
Spec.Hash.Incremental.update_last a s prevlen input)
(fun a _ s () -> Spec.Agile.Hash.finish a s ())
(fun a _ s () -> Spec.Agile.Hash.hash a s)
(fun a s prevlen ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_zero_blake a prevlen s
else
Spec.Hash.Lemmas.update_multi_zero a s)
(* update_multi_associative *)
(fun a s prevlen1 prevlen2 input1 input2 ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_associative_blake a s prevlen1 prevlen2 input1 input2
else
Spec.Hash.Lemmas.update_multi_associative a s input1 input2)
(* spec_is_incremental *)
(fun a _ input () ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input ())
EverCrypt.Hash.alg_of_state
(fun i _ _ -> EverCrypt.Hash.init #i)
(fun i s prevlen blocks len -> EverCrypt.Hash.update_multi #i s prevlen blocks len)
(fun i s prevlen last last_len ->
EverCrypt.Hash.update_last #i s prevlen last last_len)
(fun i _ s dst _ -> EverCrypt.Hash.finish #i s dst)
#pop-options
let state_t =
F.state_s evercrypt_hash SHA2_256 ((agile_state).s SHA2_256) (G.erased unit)
// Public API (streaming)
// ----------------------
[@@ Comment
"Allocate initial state for the agile hash. The argument `a` stands for the
choice of algorithm (see Hacl_Spec.h). This API will automatically pick the most
efficient implementation, provided you have called EverCrypt_AutoConfig2_init()
before. The state is to be freed by calling `free`."]
let malloc a = F.malloc evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) ()
[@@ Comment
"Reset an existing state to the initial hash state with empty data."]
let reset (a: G.erased Hash.alg) = F.reset evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Feed an arbitrary amount of data into the hash. This function returns
EverCrypt_Error_Success for success, or EverCrypt_Error_MaximumLengthExceeded if
the combined length of all of the data passed to `update` (since the last call
to `init`) exceeds 2^61-1 bytes or 2^64-1 bytes, depending on the choice of
algorithm. Both limits are unlikely to be attained in practice."]
let update (i: G.erased Hash.alg)
(state:F.state evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit))
(chunk: B.buffer uint8)
(chunk_len: UInt32.t):
Stack EverCrypt.Error.error_code
(requires fun h0 -> F.update_pre evercrypt_hash i state chunk chunk_len h0)
(ensures fun h0 e h1 ->
match e with
| EverCrypt.Error.Success ->
S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i) /\
F.update_post evercrypt_hash i state chunk chunk_len h0 h1
| EverCrypt.Error.MaximumLengthExceeded ->
h0 == h1 /\
not (S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i))
| _ -> False)
=
match F.update evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit) state chunk chunk_len with
| Hacl.Streaming.Types.Success -> EverCrypt.Error.Success
| Hacl.Streaming.Types.MaximumLengthExceeded -> EverCrypt.Error.MaximumLengthExceeded
inline_for_extraction noextract
let digest_st a = F.digest_st evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
/// The wrapper pattern, to ensure that the stack-allocated state is properly
/// monomorphized.
private
let digest_md5: digest_st MD5 = F.digest evercrypt_hash MD5 (EverCrypt.Hash.state MD5) (G.erased unit)
private
let digest_sha1: digest_st SHA1 = F.digest evercrypt_hash SHA1 (EverCrypt.Hash.state SHA1) (G.erased unit)
private
let digest_sha224: digest_st SHA2_224 = F.digest evercrypt_hash SHA2_224 (EverCrypt.Hash.state SHA2_224) (G.erased unit)
private
let digest_sha256: digest_st SHA2_256 = F.digest evercrypt_hash SHA2_256 (EverCrypt.Hash.state SHA2_256) (G.erased unit)
private
let digest_sha3_224: digest_st SHA3_224 = F.digest evercrypt_hash SHA3_224 (EverCrypt.Hash.state SHA3_224) (G.erased unit)
private
let digest_sha3_256: digest_st SHA3_256 = F.digest evercrypt_hash SHA3_256 (EverCrypt.Hash.state SHA3_256) (G.erased unit)
private
let digest_sha3_384: digest_st SHA3_384 = F.digest evercrypt_hash SHA3_384 (EverCrypt.Hash.state SHA3_384) (G.erased unit)
private
let digest_sha3_512: digest_st SHA3_512 = F.digest evercrypt_hash SHA3_512 (EverCrypt.Hash.state SHA3_512) (G.erased unit)
private
let digest_sha384: digest_st SHA2_384 = F.digest evercrypt_hash SHA2_384 (EverCrypt.Hash.state SHA2_384) (G.erased unit)
private
let digest_sha512: digest_st SHA2_512 = F.digest evercrypt_hash SHA2_512 (EverCrypt.Hash.state SHA2_512) (G.erased unit)
private
let digest_blake2s: digest_st Blake2S = F.digest evercrypt_hash Blake2S (EverCrypt.Hash.state Blake2S) (G.erased unit)
private
let digest_blake2b: digest_st Blake2B = F.digest evercrypt_hash Blake2B (EverCrypt.Hash.state Blake2B) (G.erased unit)
[@@ Comment
"Perform a run-time test to determine which algorithm was chosen for the given piece of state."]
let alg_of_state (a: G.erased Hash.alg) = F.index_of_state evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Write the resulting hash into `output`, an array whose length is
algorithm-specific. You can use the macros defined earlier in this file to
allocate a destination buffer of the right length. The state remains valid after
a call to `digest`, meaning the user may feed more data into the hash via
`update`. (The finish function operates on an internal copy of the state and
therefore does not invalidate the client-held state.)"]
val digest: a:G.erased Hash.alg -> digest_st a
let digest a state output l =
let a = alg_of_state a state in
match a with
| MD5 -> digest_md5 state output l
| SHA1 -> digest_sha1 state output l
| SHA2_224 -> digest_sha224 state output l
| SHA2_256 -> digest_sha256 state output l
| SHA2_384 -> digest_sha384 state output l
| SHA2_512 -> digest_sha512 state output l
| SHA3_224 -> digest_sha3_224 state output l
| SHA3_256 -> digest_sha3_256 state output l
| SHA3_384 -> digest_sha3_384 state output l
| SHA3_512 -> digest_sha3_512 state output l
| Blake2S -> digest_blake2s state output l
| Blake2B -> digest_blake2b state output l
[@@ Comment
"Free a state previously allocated with `create_in`."]
let free (i: G.erased Hash.alg) = F.free evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit)
// Private API (one-shot, multiplexing)
// ------------------------------------
private
val hash_256: Hacl.Hash.Definitions.hash_st SHA2_256 | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Hash.Definitions.hash_st Spec.Hash.Definitions.SHA2_256 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Hash.Definitions.hash_t",
"Spec.Hash.Definitions.SHA2_256",
"LowStar.Buffer.buffer",
"Lib.IntTypes.uint8",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.range",
"Lib.IntTypes.U32",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"Lib.IntTypes.v",
"Lib.IntTypes.PUB",
"Hacl.Hash.MD.mk_hash",
"Hacl.Hash.SHA2.alloca_256",
"EverCrypt.Hash.update_multi_256",
"Hacl.Hash.SHA2.update_last_256",
"Hacl.Hash.SHA2.finish_256",
"Prims.unit"
] | [] | false | false | false | true | false | let hash_256 output input input_len =
| let open EverCrypt.Hash in
Hacl.Hash.MD.mk_hash SHA2_256
Hacl.Hash.SHA2.alloca_256
update_multi_256
Hacl.Hash.SHA2.update_last_256
Hacl.Hash.SHA2.finish_256
output
input
input_len | false |
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.hash_224 | val hash_224: Hacl.Hash.Definitions.hash_st SHA2_224 | val hash_224: Hacl.Hash.Definitions.hash_st SHA2_224 | let hash_224 output input input_len =
let open EverCrypt.Hash in
Hacl.Hash.MD.mk_hash SHA2_224 Hacl.Hash.SHA2.alloca_224 update_multi_224
Hacl.Hash.SHA2.update_last_224 Hacl.Hash.SHA2.finish_224 output input input_len | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 83,
"end_line": 276,
"start_col": 0,
"start_line": 273
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a
inline_for_extraction noextract
let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
()
inline_for_extraction noextract
let prev_length_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Incremental.prev_length_t a
=
if is_keccak a then
()
else
i
#push-options "--z3rlimit 500"
inline_for_extraction noextract
let evercrypt_hash : block Hash.alg =
Block
Erased
agile_state
(stateful_unused Hash.alg)
unit
Hacl.Hash.Definitions.max_input_len64
(fun a () -> Spec.Hash.Definitions.hash_length a)
block_len
block_len // No vectorization
(fun _ -> 0ul)
(fun _ _ -> S.empty)
(fun a _ -> Spec.Agile.Hash.init a)
(fun a s prevlen input ->
let prevlen = extra_state_of_nat a prevlen in
Spec.Agile.Hash.update_multi a s prevlen input)
(fun a s prevlen input ->
let prevlen = prev_length_of_nat a prevlen in
Spec.Hash.Incremental.update_last a s prevlen input)
(fun a _ s () -> Spec.Agile.Hash.finish a s ())
(fun a _ s () -> Spec.Agile.Hash.hash a s)
(fun a s prevlen ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_zero_blake a prevlen s
else
Spec.Hash.Lemmas.update_multi_zero a s)
(* update_multi_associative *)
(fun a s prevlen1 prevlen2 input1 input2 ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_associative_blake a s prevlen1 prevlen2 input1 input2
else
Spec.Hash.Lemmas.update_multi_associative a s input1 input2)
(* spec_is_incremental *)
(fun a _ input () ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input ())
EverCrypt.Hash.alg_of_state
(fun i _ _ -> EverCrypt.Hash.init #i)
(fun i s prevlen blocks len -> EverCrypt.Hash.update_multi #i s prevlen blocks len)
(fun i s prevlen last last_len ->
EverCrypt.Hash.update_last #i s prevlen last last_len)
(fun i _ s dst _ -> EverCrypt.Hash.finish #i s dst)
#pop-options
let state_t =
F.state_s evercrypt_hash SHA2_256 ((agile_state).s SHA2_256) (G.erased unit)
// Public API (streaming)
// ----------------------
[@@ Comment
"Allocate initial state for the agile hash. The argument `a` stands for the
choice of algorithm (see Hacl_Spec.h). This API will automatically pick the most
efficient implementation, provided you have called EverCrypt_AutoConfig2_init()
before. The state is to be freed by calling `free`."]
let malloc a = F.malloc evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) ()
[@@ Comment
"Reset an existing state to the initial hash state with empty data."]
let reset (a: G.erased Hash.alg) = F.reset evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Feed an arbitrary amount of data into the hash. This function returns
EverCrypt_Error_Success for success, or EverCrypt_Error_MaximumLengthExceeded if
the combined length of all of the data passed to `update` (since the last call
to `init`) exceeds 2^61-1 bytes or 2^64-1 bytes, depending on the choice of
algorithm. Both limits are unlikely to be attained in practice."]
let update (i: G.erased Hash.alg)
(state:F.state evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit))
(chunk: B.buffer uint8)
(chunk_len: UInt32.t):
Stack EverCrypt.Error.error_code
(requires fun h0 -> F.update_pre evercrypt_hash i state chunk chunk_len h0)
(ensures fun h0 e h1 ->
match e with
| EverCrypt.Error.Success ->
S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i) /\
F.update_post evercrypt_hash i state chunk chunk_len h0 h1
| EverCrypt.Error.MaximumLengthExceeded ->
h0 == h1 /\
not (S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i))
| _ -> False)
=
match F.update evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit) state chunk chunk_len with
| Hacl.Streaming.Types.Success -> EverCrypt.Error.Success
| Hacl.Streaming.Types.MaximumLengthExceeded -> EverCrypt.Error.MaximumLengthExceeded
inline_for_extraction noextract
let digest_st a = F.digest_st evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
/// The wrapper pattern, to ensure that the stack-allocated state is properly
/// monomorphized.
private
let digest_md5: digest_st MD5 = F.digest evercrypt_hash MD5 (EverCrypt.Hash.state MD5) (G.erased unit)
private
let digest_sha1: digest_st SHA1 = F.digest evercrypt_hash SHA1 (EverCrypt.Hash.state SHA1) (G.erased unit)
private
let digest_sha224: digest_st SHA2_224 = F.digest evercrypt_hash SHA2_224 (EverCrypt.Hash.state SHA2_224) (G.erased unit)
private
let digest_sha256: digest_st SHA2_256 = F.digest evercrypt_hash SHA2_256 (EverCrypt.Hash.state SHA2_256) (G.erased unit)
private
let digest_sha3_224: digest_st SHA3_224 = F.digest evercrypt_hash SHA3_224 (EverCrypt.Hash.state SHA3_224) (G.erased unit)
private
let digest_sha3_256: digest_st SHA3_256 = F.digest evercrypt_hash SHA3_256 (EverCrypt.Hash.state SHA3_256) (G.erased unit)
private
let digest_sha3_384: digest_st SHA3_384 = F.digest evercrypt_hash SHA3_384 (EverCrypt.Hash.state SHA3_384) (G.erased unit)
private
let digest_sha3_512: digest_st SHA3_512 = F.digest evercrypt_hash SHA3_512 (EverCrypt.Hash.state SHA3_512) (G.erased unit)
private
let digest_sha384: digest_st SHA2_384 = F.digest evercrypt_hash SHA2_384 (EverCrypt.Hash.state SHA2_384) (G.erased unit)
private
let digest_sha512: digest_st SHA2_512 = F.digest evercrypt_hash SHA2_512 (EverCrypt.Hash.state SHA2_512) (G.erased unit)
private
let digest_blake2s: digest_st Blake2S = F.digest evercrypt_hash Blake2S (EverCrypt.Hash.state Blake2S) (G.erased unit)
private
let digest_blake2b: digest_st Blake2B = F.digest evercrypt_hash Blake2B (EverCrypt.Hash.state Blake2B) (G.erased unit)
[@@ Comment
"Perform a run-time test to determine which algorithm was chosen for the given piece of state."]
let alg_of_state (a: G.erased Hash.alg) = F.index_of_state evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Write the resulting hash into `output`, an array whose length is
algorithm-specific. You can use the macros defined earlier in this file to
allocate a destination buffer of the right length. The state remains valid after
a call to `digest`, meaning the user may feed more data into the hash via
`update`. (The finish function operates on an internal copy of the state and
therefore does not invalidate the client-held state.)"]
val digest: a:G.erased Hash.alg -> digest_st a
let digest a state output l =
let a = alg_of_state a state in
match a with
| MD5 -> digest_md5 state output l
| SHA1 -> digest_sha1 state output l
| SHA2_224 -> digest_sha224 state output l
| SHA2_256 -> digest_sha256 state output l
| SHA2_384 -> digest_sha384 state output l
| SHA2_512 -> digest_sha512 state output l
| SHA3_224 -> digest_sha3_224 state output l
| SHA3_256 -> digest_sha3_256 state output l
| SHA3_384 -> digest_sha3_384 state output l
| SHA3_512 -> digest_sha3_512 state output l
| Blake2S -> digest_blake2s state output l
| Blake2B -> digest_blake2b state output l
[@@ Comment
"Free a state previously allocated with `create_in`."]
let free (i: G.erased Hash.alg) = F.free evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit)
// Private API (one-shot, multiplexing)
// ------------------------------------
private
val hash_256: Hacl.Hash.Definitions.hash_st SHA2_256
// A full one-shot hash that relies on vale at each multiplexing point
let hash_256 output input input_len =
let open EverCrypt.Hash in
// TODO: This function now only exists for SHA1 and MD5
Hacl.Hash.MD.mk_hash SHA2_256 Hacl.Hash.SHA2.alloca_256 update_multi_256
Hacl.Hash.SHA2.update_last_256 Hacl.Hash.SHA2.finish_256 output input input_len
private
val hash_224: Hacl.Hash.Definitions.hash_st SHA2_224 | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Hash.Definitions.hash_st Spec.Hash.Definitions.SHA2_224 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Hash.Definitions.hash_t",
"Spec.Hash.Definitions.SHA2_224",
"LowStar.Buffer.buffer",
"Lib.IntTypes.uint8",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.range",
"Lib.IntTypes.U32",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"Lib.IntTypes.v",
"Lib.IntTypes.PUB",
"Hacl.Hash.MD.mk_hash",
"Hacl.Hash.SHA2.alloca_224",
"EverCrypt.Hash.update_multi_224",
"Hacl.Hash.SHA2.update_last_224",
"Hacl.Hash.SHA2.finish_224",
"Prims.unit"
] | [] | false | false | false | true | false | let hash_224 output input input_len =
| let open EverCrypt.Hash in
Hacl.Hash.MD.mk_hash SHA2_224
Hacl.Hash.SHA2.alloca_224
update_multi_224
Hacl.Hash.SHA2.update_last_224
Hacl.Hash.SHA2.finish_224
output
input
input_len | false |
Pulse.Checker.Prover.fst | Pulse.Checker.Prover.prover | val prover (#preamble: _) (pst0: prover_state preamble)
: T.Tac (pst': prover_state preamble {pst' `pst_extends` pst0 /\ is_terminal pst'}) | val prover (#preamble: _) (pst0: prover_state preamble)
: T.Tac (pst': prover_state preamble {pst' `pst_extends` pst0 /\ is_terminal pst'}) | let rec prover
(#preamble:_)
(pst0:prover_state preamble)
: T.Tac (pst':prover_state preamble { pst' `pst_extends` pst0 /\
is_terminal pst' }) =
debug_prover pst0.pg (fun _ ->
Printf.sprintf "At the prover top-level with remaining_ctxt: %s\nunsolved: %s"
(P.term_to_string (list_as_vprop pst0.remaining_ctxt))
(P.term_to_string (list_as_vprop pst0.unsolved)));
match pst0.unsolved with
| [] -> pst0
| _ ->
let pst = ElimExists.elim_exists_pst pst0 in
debug_prover pst.pg (fun _ ->
Printf.sprintf "prover: remaining_ctxt after elim exists: %s\n"
(P.term_to_string (list_as_vprop pst.remaining_ctxt)));
let pst = ElimPure.elim_pure_pst pst in
debug_prover pst.pg (fun _ ->
Printf.sprintf "prover: remaining_ctxt after elim pure: %s\n"
(P.term_to_string (list_as_vprop pst.remaining_ctxt)));
let (| exs, rest, d |) = collect_exists (push_env pst.pg pst.uvs) pst.unsolved in
debug_prover pst.pg (fun _ ->
Printf.sprintf "prover: tried to pull exists: exs: %s and rest: %s\n"
(P.term_to_string (list_as_vprop exs)) (P.term_to_string (list_as_vprop rest)));
let pst = unsolved_equiv_pst pst (exs@rest) d in
debug_prover pst.pg (fun _ ->
Printf.sprintf "prover: unsolved after pulling exists at the top: %s\n"
(P.term_to_string (list_as_vprop pst.unsolved)));
match pst.unsolved with
| {t=Tm_ExistsSL u b body}::unsolved' ->
IntroExists.intro_exists pst u b body unsolved' () prover
| _ ->
let (| pures, rest, d |) = collect_pures (push_env pst.pg pst.uvs) pst.unsolved in
let pst = unsolved_equiv_pst pst (rest@pures) d in
match pst.unsolved with
| {t=Tm_Pure _}::tl -> prove_pures pst
| q::tl ->
let pst_opt = Match.match_q pst q tl () prover in
match pst_opt with
| None ->
let open Pprint in
let open Pulse.PP in
let msg = [
text "Cannot prove:" ^^
indent (pp q);
text "In the context:" ^^
indent (pp (list_as_vprop pst.remaining_ctxt))
] @ (if Pulse.Config.debug_flag "initial_solver_state" then [
text "The prover was started with goal:" ^^
indent (pp preamble.goals);
text "and initial context:" ^^
indent (pp preamble.ctxt);
] else [])
in
// GM: I feel I should use (Some q.range) instead of None, but that makes
// several error locations worse.
fail_doc pst.pg None msg
| Some pst -> prover pst | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 32,
"end_line": 179,
"start_col": 0,
"start_line": 112
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Prover
open FStar.List.Tot
open Pulse.Syntax
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Checker.Base
module RU = Pulse.RuntimeUtils
module L = FStar.List.Tot
module T = FStar.Tactics.V2
module P = Pulse.Syntax.Printer
module Pprint = FStar.Stubs.Pprint
module Metatheory = Pulse.Typing.Metatheory
module PS = Pulse.Checker.Prover.Substs
module ElimExists = Pulse.Checker.Prover.ElimExists
module ElimPure = Pulse.Checker.Prover.ElimPure
module Match = Pulse.Checker.Prover.Match
module IntroExists = Pulse.Checker.Prover.IntroExists
module IntroPure = Pulse.Checker.Prover.IntroPure
let coerce_eq (#a #b:Type) (x:a) (_:squash (a == b)) : y:b{y == x} = x
let elim_exists_and_pure (#g:env) (#ctxt:vprop)
(ctxt_typing:tot_typing g ctxt tm_vprop)
: T.Tac (g':env { env_extends g' g } &
ctxt':term &
tot_typing g' ctxt' tm_vprop &
continuation_elaborator g ctxt g' ctxt') =
let (| g1, ctxt1, d1, k1 |) = ElimExists.elim_exists ctxt_typing in
let (| g2, ctxt2, d2, k2 |) = ElimPure.elim_pure d1 in
(| g2, ctxt2, d2, k_elab_trans k1 k2 |)
let unsolved_equiv_pst (#preamble:_) (pst:prover_state preamble) (unsolved':list vprop)
(d:vprop_equiv (push_env pst.pg pst.uvs) (list_as_vprop pst.unsolved) (list_as_vprop unsolved'))
: prover_state preamble =
{ pst with unsolved = unsolved'; goals_inv = RU.magic () }
let rec collect_exists (g:env) (l:list vprop)
: exs:list vprop &
rest:list vprop &
vprop_equiv g (list_as_vprop l) (list_as_vprop (exs @ rest)) =
match l with
| [] -> (| [], [], VE_Refl _ _ |)
| hd::tl ->
let (| exs, rest, _ |) = collect_exists g tl in
match hd.t with
| Tm_ExistsSL _ _ _ ->
(| hd::exs, rest, RU.magic #(vprop_equiv _ _ _) () |)
| _ -> (| exs, hd::rest, RU.magic #(vprop_equiv _ _ _) () |)
let rec collect_pures (g:env) (l:list vprop)
: pures:list vprop &
rest:list vprop &
vprop_equiv g (list_as_vprop l) (list_as_vprop (rest @ pures)) =
match l with
| [] -> (| [], [], VE_Refl _ _ |)
| hd::tl ->
let (| pures, rest, _ |) = collect_pures g tl in
match hd.t with
| Tm_Pure _ -> (| hd::pures, rest, RU.magic #(vprop_equiv _ _ _) () |)
| _ -> (| pures, hd::rest, RU.magic #(vprop_equiv _ _ _) () |)
let rec prove_pures #preamble (pst:prover_state preamble)
: T.Tac (pst':prover_state preamble { pst' `pst_extends` pst /\
is_terminal pst' }) =
match pst.unsolved with
| [] -> pst
| {t=Tm_Pure p}::unsolved' ->
let pst_opt = IntroPure.intro_pure pst p unsolved' () in
(match pst_opt with
| None ->
let open Pulse.PP in
fail_doc pst.pg None [
text "Cannot prove pure proposition" ^/^
pp p
]
| Some pst1 ->
let pst2 = prove_pures pst1 in
assert (pst1 `pst_extends` pst);
assert (pst2 `pst_extends` pst1);
assert (pst2 `pst_extends` pst);
pst2)
| _ ->
fail pst.pg None
(Printf.sprintf "Impossible! prover.prove_pures: %s is not a pure, please file a bug-report"
(P.term_to_string (L.hd pst.unsolved))) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Readback.fsti.checked",
"Pulse.PP.fst.checked",
"Pulse.Config.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Prover.Match.fsti.checked",
"Pulse.Checker.Prover.IntroPure.fsti.checked",
"Pulse.Checker.Prover.IntroExists.fsti.checked",
"Pulse.Checker.Prover.ElimPure.fsti.checked",
"Pulse.Checker.Prover.ElimExists.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Stubs.Pprint.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.IntroPure",
"short_module": "IntroPure"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.IntroExists",
"short_module": "IntroExists"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Match",
"short_module": "Match"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.ElimPure",
"short_module": "ElimPure"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.ElimExists",
"short_module": "ElimExists"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "FStar.Stubs.Pprint",
"short_module": "Pprint"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover.Base",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 4,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | pst0: Pulse.Checker.Prover.Base.prover_state preamble
-> FStar.Tactics.Effect.Tac
(pst':
Pulse.Checker.Prover.Base.prover_state preamble
{ Pulse.Checker.Prover.Base.pst_extends pst' pst0 /\
Pulse.Checker.Prover.Base.is_terminal pst' }) | FStar.Tactics.Effect.Tac | [] | [] | [
"Pulse.Checker.Prover.Base.preamble",
"Pulse.Checker.Prover.Base.prover_state",
"Pulse.Checker.Prover.Base.__proj__Mkprover_state__item__unsolved",
"Prims.l_and",
"Pulse.Checker.Prover.Base.pst_extends",
"Pulse.Checker.Prover.Base.is_terminal",
"Prims.list",
"Pulse.Syntax.Base.vprop",
"Pulse.Typing.vprop_equiv",
"Pulse.Typing.Env.push_env",
"Pulse.Checker.Prover.Base.__proj__Mkprover_state__item__pg",
"Pulse.Checker.Prover.Base.__proj__Mkprover_state__item__uvs",
"Pulse.Typing.Combinators.list_as_vprop",
"FStar.List.Tot.Base.op_At",
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.binder",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.range",
"Pulse.Checker.Prover.IntroExists.intro_exists",
"Pulse.Checker.Prover.prover",
"Pulse.Checker.Prover.prove_pures",
"Pulse.Typing.Env.fail_doc",
"FStar.Pervasives.Native.None",
"FStar.Stubs.Pprint.document",
"Prims.Cons",
"Prims.Nil",
"FStar.Stubs.Pprint.op_Hat_Hat",
"Pulse.PP.text",
"Pulse.PP.indent",
"Pulse.PP.pp",
"Pulse.PP.uu___44",
"Pulse.Checker.Prover.Base.__proj__Mkpreamble__item__ctxt",
"Pulse.Checker.Prover.Base.__proj__Mkpreamble__item__goals",
"Prims.bool",
"Pulse.Config.debug_flag",
"Pulse.Checker.Prover.Base.__proj__Mkprover_state__item__remaining_ctxt",
"FStar.Pervasives.Native.option",
"Pulse.Checker.Prover.Match.match_q",
"Pulse.Checker.Prover.unsolved_equiv_pst",
"FStar.Pervasives.dtuple3",
"Pulse.Checker.Prover.collect_pures",
"Prims.unit",
"Pulse.Checker.Prover.Util.debug_prover",
"FStar.Printf.sprintf",
"Prims.string",
"Pulse.Syntax.Printer.term_to_string",
"Pulse.Checker.Prover.collect_exists",
"Prims.eq2",
"Pulse.Checker.Prover.ElimPure.elim_pure_pst",
"Pulse.Checker.Prover.ElimExists.elim_exists_pst"
] | [
"recursion"
] | false | true | false | false | false | let rec prover (#preamble: _) (pst0: prover_state preamble)
: T.Tac (pst': prover_state preamble {pst' `pst_extends` pst0 /\ is_terminal pst'}) =
| debug_prover pst0.pg
(fun _ ->
Printf.sprintf "At the prover top-level with remaining_ctxt: %s\nunsolved: %s"
(P.term_to_string (list_as_vprop pst0.remaining_ctxt))
(P.term_to_string (list_as_vprop pst0.unsolved)));
match pst0.unsolved with
| [] -> pst0
| _ ->
let pst = ElimExists.elim_exists_pst pst0 in
debug_prover pst.pg
(fun _ ->
Printf.sprintf "prover: remaining_ctxt after elim exists: %s\n"
(P.term_to_string (list_as_vprop pst.remaining_ctxt)));
let pst = ElimPure.elim_pure_pst pst in
debug_prover pst.pg
(fun _ ->
Printf.sprintf "prover: remaining_ctxt after elim pure: %s\n"
(P.term_to_string (list_as_vprop pst.remaining_ctxt)));
let (| exs , rest , d |) = collect_exists (push_env pst.pg pst.uvs) pst.unsolved in
debug_prover pst.pg
(fun _ ->
Printf.sprintf "prover: tried to pull exists: exs: %s and rest: %s\n"
(P.term_to_string (list_as_vprop exs))
(P.term_to_string (list_as_vprop rest)));
let pst = unsolved_equiv_pst pst (exs @ rest) d in
debug_prover pst.pg
(fun _ ->
Printf.sprintf "prover: unsolved after pulling exists at the top: %s\n"
(P.term_to_string (list_as_vprop pst.unsolved)));
match pst.unsolved with
| { t = Tm_ExistsSL u b body } :: unsolved' ->
IntroExists.intro_exists pst u b body unsolved' () prover
| _ ->
let (| pures , rest , d |) = collect_pures (push_env pst.pg pst.uvs) pst.unsolved in
let pst = unsolved_equiv_pst pst (rest @ pures) d in
match pst.unsolved with
| { t = Tm_Pure _ } :: tl -> prove_pures pst
| q :: tl ->
let pst_opt = Match.match_q pst q tl () prover in
match pst_opt with
| None ->
let open Pprint in
let open Pulse.PP in
let msg =
[
text "Cannot prove:" ^^ indent (pp q);
text "In the context:" ^^ indent (pp (list_as_vprop pst.remaining_ctxt))
] @
(if Pulse.Config.debug_flag "initial_solver_state"
then
[
text "The prover was started with goal:" ^^ indent (pp preamble.goals);
text "and initial context:" ^^ indent (pp preamble.ctxt)
]
else [])
in
fail_doc pst.pg None msg
| Some pst -> prover pst | false |
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.hash | val hash:
a:Hash.alg ->
output:B.buffer Lib.IntTypes.uint8 {B.length output = hash_length a} ->
input:B.buffer Lib.IntTypes.uint8 ->
input_len:FStar.UInt32.t {B.length input = FStar.UInt32.v input_len /\ FStar.UInt32.v input_len `less_than_max_input_length` a} ->
Stack unit
(requires fun h0 ->
B.live h0 output /\
B.live h0 input /\
B.(loc_disjoint (loc_buffer input) (loc_buffer output)))
(ensures fun h0 _ h1 ->
B.(modifies (loc_buffer output) h0 h1) /\
B.as_seq h1 output == Spec.Agile.Hash.hash a (B.as_seq h0 input)) | val hash:
a:Hash.alg ->
output:B.buffer Lib.IntTypes.uint8 {B.length output = hash_length a} ->
input:B.buffer Lib.IntTypes.uint8 ->
input_len:FStar.UInt32.t {B.length input = FStar.UInt32.v input_len /\ FStar.UInt32.v input_len `less_than_max_input_length` a} ->
Stack unit
(requires fun h0 ->
B.live h0 output /\
B.live h0 input /\
B.(loc_disjoint (loc_buffer input) (loc_buffer output)))
(ensures fun h0 _ h1 ->
B.(modifies (loc_buffer output) h0 h1) /\
B.as_seq h1 output == Spec.Agile.Hash.hash a (B.as_seq h0 input)) | let hash a output input input_len =
match a with
| MD5 -> Hacl.Hash.MD5.hash_oneshot output input input_len
| SHA1 -> Hacl.Hash.SHA1.hash_oneshot output input input_len
| SHA2_224 -> hash_224 output input input_len
| SHA2_256 -> hash_256 output input input_len
| SHA2_384 -> Hacl.Streaming.SHA2.hash_384 output input input_len
| SHA2_512 -> Hacl.Streaming.SHA2.hash_512 output input input_len
| SHA3_224 -> Hacl.Hash.SHA3.hash SHA3_224 output input input_len
| SHA3_256 -> Hacl.Hash.SHA3.hash SHA3_256 output input input_len
| SHA3_384 -> Hacl.Hash.SHA3.hash SHA3_384 output input input_len
| SHA3_512 -> Hacl.Hash.SHA3.hash SHA3_512 output input input_len
| Blake2S ->
if EverCrypt.TargetConfig.hacl_can_compile_vec128 then
let vec128 = EverCrypt.AutoConfig2.has_vec128 () in
if vec128 then
Hacl.Hash.Blake2s_128.hash output input input_len
else
Hacl.Hash.Blake2s_32.hash output input input_len
else
Hacl.Hash.Blake2s_32.hash output input input_len
| Blake2B ->
if EverCrypt.TargetConfig.hacl_can_compile_vec256 then
let vec256 = EverCrypt.AutoConfig2.has_vec256 () in
if vec256 then
Hacl.Hash.Blake2b_256.hash output input input_len
else
Hacl.Hash.Blake2b_32.hash output input input_len
else
Hacl.Hash.Blake2b_32.hash output input input_len | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 56,
"end_line": 337,
"start_col": 0,
"start_line": 308
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a
inline_for_extraction noextract
let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
()
inline_for_extraction noextract
let prev_length_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Incremental.prev_length_t a
=
if is_keccak a then
()
else
i
#push-options "--z3rlimit 500"
inline_for_extraction noextract
let evercrypt_hash : block Hash.alg =
Block
Erased
agile_state
(stateful_unused Hash.alg)
unit
Hacl.Hash.Definitions.max_input_len64
(fun a () -> Spec.Hash.Definitions.hash_length a)
block_len
block_len // No vectorization
(fun _ -> 0ul)
(fun _ _ -> S.empty)
(fun a _ -> Spec.Agile.Hash.init a)
(fun a s prevlen input ->
let prevlen = extra_state_of_nat a prevlen in
Spec.Agile.Hash.update_multi a s prevlen input)
(fun a s prevlen input ->
let prevlen = prev_length_of_nat a prevlen in
Spec.Hash.Incremental.update_last a s prevlen input)
(fun a _ s () -> Spec.Agile.Hash.finish a s ())
(fun a _ s () -> Spec.Agile.Hash.hash a s)
(fun a s prevlen ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_zero_blake a prevlen s
else
Spec.Hash.Lemmas.update_multi_zero a s)
(* update_multi_associative *)
(fun a s prevlen1 prevlen2 input1 input2 ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_associative_blake a s prevlen1 prevlen2 input1 input2
else
Spec.Hash.Lemmas.update_multi_associative a s input1 input2)
(* spec_is_incremental *)
(fun a _ input () ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input ())
EverCrypt.Hash.alg_of_state
(fun i _ _ -> EverCrypt.Hash.init #i)
(fun i s prevlen blocks len -> EverCrypt.Hash.update_multi #i s prevlen blocks len)
(fun i s prevlen last last_len ->
EverCrypt.Hash.update_last #i s prevlen last last_len)
(fun i _ s dst _ -> EverCrypt.Hash.finish #i s dst)
#pop-options
let state_t =
F.state_s evercrypt_hash SHA2_256 ((agile_state).s SHA2_256) (G.erased unit)
// Public API (streaming)
// ----------------------
[@@ Comment
"Allocate initial state for the agile hash. The argument `a` stands for the
choice of algorithm (see Hacl_Spec.h). This API will automatically pick the most
efficient implementation, provided you have called EverCrypt_AutoConfig2_init()
before. The state is to be freed by calling `free`."]
let malloc a = F.malloc evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit) ()
[@@ Comment
"Reset an existing state to the initial hash state with empty data."]
let reset (a: G.erased Hash.alg) = F.reset evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Feed an arbitrary amount of data into the hash. This function returns
EverCrypt_Error_Success for success, or EverCrypt_Error_MaximumLengthExceeded if
the combined length of all of the data passed to `update` (since the last call
to `init`) exceeds 2^61-1 bytes or 2^64-1 bytes, depending on the choice of
algorithm. Both limits are unlikely to be attained in practice."]
let update (i: G.erased Hash.alg)
(state:F.state evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit))
(chunk: B.buffer uint8)
(chunk_len: UInt32.t):
Stack EverCrypt.Error.error_code
(requires fun h0 -> F.update_pre evercrypt_hash i state chunk chunk_len h0)
(ensures fun h0 e h1 ->
match e with
| EverCrypt.Error.Success ->
S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i) /\
F.update_post evercrypt_hash i state chunk chunk_len h0 h1
| EverCrypt.Error.MaximumLengthExceeded ->
h0 == h1 /\
not (S.length (F.seen evercrypt_hash i h0 state) + U32.v chunk_len <= U64.v (evercrypt_hash.max_input_len i))
| _ -> False)
=
match F.update evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit) state chunk chunk_len with
| Hacl.Streaming.Types.Success -> EverCrypt.Error.Success
| Hacl.Streaming.Types.MaximumLengthExceeded -> EverCrypt.Error.MaximumLengthExceeded
inline_for_extraction noextract
let digest_st a = F.digest_st evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
/// The wrapper pattern, to ensure that the stack-allocated state is properly
/// monomorphized.
private
let digest_md5: digest_st MD5 = F.digest evercrypt_hash MD5 (EverCrypt.Hash.state MD5) (G.erased unit)
private
let digest_sha1: digest_st SHA1 = F.digest evercrypt_hash SHA1 (EverCrypt.Hash.state SHA1) (G.erased unit)
private
let digest_sha224: digest_st SHA2_224 = F.digest evercrypt_hash SHA2_224 (EverCrypt.Hash.state SHA2_224) (G.erased unit)
private
let digest_sha256: digest_st SHA2_256 = F.digest evercrypt_hash SHA2_256 (EverCrypt.Hash.state SHA2_256) (G.erased unit)
private
let digest_sha3_224: digest_st SHA3_224 = F.digest evercrypt_hash SHA3_224 (EverCrypt.Hash.state SHA3_224) (G.erased unit)
private
let digest_sha3_256: digest_st SHA3_256 = F.digest evercrypt_hash SHA3_256 (EverCrypt.Hash.state SHA3_256) (G.erased unit)
private
let digest_sha3_384: digest_st SHA3_384 = F.digest evercrypt_hash SHA3_384 (EverCrypt.Hash.state SHA3_384) (G.erased unit)
private
let digest_sha3_512: digest_st SHA3_512 = F.digest evercrypt_hash SHA3_512 (EverCrypt.Hash.state SHA3_512) (G.erased unit)
private
let digest_sha384: digest_st SHA2_384 = F.digest evercrypt_hash SHA2_384 (EverCrypt.Hash.state SHA2_384) (G.erased unit)
private
let digest_sha512: digest_st SHA2_512 = F.digest evercrypt_hash SHA2_512 (EverCrypt.Hash.state SHA2_512) (G.erased unit)
private
let digest_blake2s: digest_st Blake2S = F.digest evercrypt_hash Blake2S (EverCrypt.Hash.state Blake2S) (G.erased unit)
private
let digest_blake2b: digest_st Blake2B = F.digest evercrypt_hash Blake2B (EverCrypt.Hash.state Blake2B) (G.erased unit)
[@@ Comment
"Perform a run-time test to determine which algorithm was chosen for the given piece of state."]
let alg_of_state (a: G.erased Hash.alg) = F.index_of_state evercrypt_hash a (EverCrypt.Hash.state a) (G.erased unit)
[@@ Comment
"Write the resulting hash into `output`, an array whose length is
algorithm-specific. You can use the macros defined earlier in this file to
allocate a destination buffer of the right length. The state remains valid after
a call to `digest`, meaning the user may feed more data into the hash via
`update`. (The finish function operates on an internal copy of the state and
therefore does not invalidate the client-held state.)"]
val digest: a:G.erased Hash.alg -> digest_st a
let digest a state output l =
let a = alg_of_state a state in
match a with
| MD5 -> digest_md5 state output l
| SHA1 -> digest_sha1 state output l
| SHA2_224 -> digest_sha224 state output l
| SHA2_256 -> digest_sha256 state output l
| SHA2_384 -> digest_sha384 state output l
| SHA2_512 -> digest_sha512 state output l
| SHA3_224 -> digest_sha3_224 state output l
| SHA3_256 -> digest_sha3_256 state output l
| SHA3_384 -> digest_sha3_384 state output l
| SHA3_512 -> digest_sha3_512 state output l
| Blake2S -> digest_blake2s state output l
| Blake2B -> digest_blake2b state output l
[@@ Comment
"Free a state previously allocated with `create_in`."]
let free (i: G.erased Hash.alg) = F.free evercrypt_hash i (EverCrypt.Hash.state i) (G.erased unit)
// Private API (one-shot, multiplexing)
// ------------------------------------
private
val hash_256: Hacl.Hash.Definitions.hash_st SHA2_256
// A full one-shot hash that relies on vale at each multiplexing point
let hash_256 output input input_len =
let open EverCrypt.Hash in
// TODO: This function now only exists for SHA1 and MD5
Hacl.Hash.MD.mk_hash SHA2_256 Hacl.Hash.SHA2.alloca_256 update_multi_256
Hacl.Hash.SHA2.update_last_256 Hacl.Hash.SHA2.finish_256 output input input_len
private
val hash_224: Hacl.Hash.Definitions.hash_st SHA2_224
let hash_224 output input input_len =
let open EverCrypt.Hash in
Hacl.Hash.MD.mk_hash SHA2_224 Hacl.Hash.SHA2.alloca_224 update_multi_224
Hacl.Hash.SHA2.update_last_224 Hacl.Hash.SHA2.finish_224 output input input_len
// Public API (one-shot, agile and multiplexing)
// ---------------------------------------------
// NOTE: this function goes through all the Hacl.Hash.* wrappers which export
// the correct agile low-level type, and thus does not need to be aware of the
// implementation of Spec.Agile.Hash (no friend-ing).
//
// ALSO: for some reason, this function was historically exported with an order
// of arguments different from Hacl.Hash.Definitions.hash_st a. Would be worth
// fixing at some point.
[@@ Comment
"Hash `input`, of len `input_len`, into `output`, an array whose length is determined by
your choice of algorithm `a` (see Hacl_Spec.h). You can use the macros defined
earlier in this file to allocate a destination buffer of the right length. This
API will automatically pick the most efficient implementation, provided you have
called EverCrypt_AutoConfig2_init() before. "]
val hash:
a:Hash.alg ->
output:B.buffer Lib.IntTypes.uint8 {B.length output = hash_length a} ->
input:B.buffer Lib.IntTypes.uint8 ->
input_len:FStar.UInt32.t {B.length input = FStar.UInt32.v input_len /\ FStar.UInt32.v input_len `less_than_max_input_length` a} ->
Stack unit
(requires fun h0 ->
B.live h0 output /\
B.live h0 input /\
B.(loc_disjoint (loc_buffer input) (loc_buffer output)))
(ensures fun h0 _ h1 ->
B.(modifies (loc_buffer output) h0 h1) /\ | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: EverCrypt.Hash.alg ->
output:
LowStar.Buffer.buffer Lib.IntTypes.uint8
{LowStar.Monotonic.Buffer.length output = Spec.Hash.Definitions.hash_length a} ->
input: LowStar.Buffer.buffer Lib.IntTypes.uint8 ->
input_len:
FStar.UInt32.t
{ LowStar.Monotonic.Buffer.length input = FStar.UInt32.v input_len /\
Spec.Hash.Definitions.less_than_max_input_length (FStar.UInt32.v input_len) a }
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"EverCrypt.Hash.alg",
"LowStar.Buffer.buffer",
"Lib.IntTypes.uint8",
"Prims.b2t",
"Prims.op_Equality",
"Prims.nat",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"Spec.Hash.Definitions.hash_length",
"FStar.UInt32.t",
"Prims.l_and",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"FStar.UInt32.v",
"Spec.Hash.Definitions.less_than_max_input_length",
"Hacl.Hash.MD5.hash_oneshot",
"Prims.unit",
"Hacl.Hash.SHA1.hash_oneshot",
"EverCrypt.Hash.Incremental.hash_224",
"EverCrypt.Hash.Incremental.hash_256",
"Hacl.Streaming.SHA2.hash_384",
"Hacl.Streaming.SHA2.hash_512",
"Hacl.Hash.SHA3.hash",
"Spec.Hash.Definitions.SHA3_224",
"Spec.Hash.Definitions.SHA3_256",
"Spec.Hash.Definitions.SHA3_384",
"Spec.Hash.Definitions.SHA3_512",
"EverCrypt.TargetConfig.hacl_can_compile_vec128",
"Hacl.Hash.Blake2s_128.hash",
"Prims.bool",
"Hacl.Hash.Blake2s_32.hash",
"EverCrypt.AutoConfig2.has_vec128",
"EverCrypt.TargetConfig.hacl_can_compile_vec256",
"Hacl.Hash.Blake2b_256.hash",
"Hacl.Hash.Blake2b_32.hash",
"EverCrypt.AutoConfig2.has_vec256"
] | [] | false | true | false | false | false | let hash a output input input_len =
| match a with
| MD5 -> Hacl.Hash.MD5.hash_oneshot output input input_len
| SHA1 -> Hacl.Hash.SHA1.hash_oneshot output input input_len
| SHA2_224 -> hash_224 output input input_len
| SHA2_256 -> hash_256 output input input_len
| SHA2_384 -> Hacl.Streaming.SHA2.hash_384 output input input_len
| SHA2_512 -> Hacl.Streaming.SHA2.hash_512 output input input_len
| SHA3_224 -> Hacl.Hash.SHA3.hash SHA3_224 output input input_len
| SHA3_256 -> Hacl.Hash.SHA3.hash SHA3_256 output input input_len
| SHA3_384 -> Hacl.Hash.SHA3.hash SHA3_384 output input input_len
| SHA3_512 -> Hacl.Hash.SHA3.hash SHA3_512 output input input_len
| Blake2S ->
if EverCrypt.TargetConfig.hacl_can_compile_vec128
then
let vec128 = EverCrypt.AutoConfig2.has_vec128 () in
if vec128
then Hacl.Hash.Blake2s_128.hash output input input_len
else Hacl.Hash.Blake2s_32.hash output input input_len
else Hacl.Hash.Blake2s_32.hash output input input_len
| Blake2B ->
if EverCrypt.TargetConfig.hacl_can_compile_vec256
then
let vec256 = EverCrypt.AutoConfig2.has_vec256 () in
if vec256
then Hacl.Hash.Blake2b_256.hash output input input_len
else Hacl.Hash.Blake2b_32.hash output input input_len
else Hacl.Hash.Blake2b_32.hash output input input_len | false |
EverCrypt.Hash.Incremental.fst | EverCrypt.Hash.Incremental.evercrypt_hash | val evercrypt_hash:block Hash.alg | val evercrypt_hash:block Hash.alg | let evercrypt_hash : block Hash.alg =
Block
Erased
agile_state
(stateful_unused Hash.alg)
unit
Hacl.Hash.Definitions.max_input_len64
(fun a () -> Spec.Hash.Definitions.hash_length a)
block_len
block_len // No vectorization
(fun _ -> 0ul)
(fun _ _ -> S.empty)
(fun a _ -> Spec.Agile.Hash.init a)
(fun a s prevlen input ->
let prevlen = extra_state_of_nat a prevlen in
Spec.Agile.Hash.update_multi a s prevlen input)
(fun a s prevlen input ->
let prevlen = prev_length_of_nat a prevlen in
Spec.Hash.Incremental.update_last a s prevlen input)
(fun a _ s () -> Spec.Agile.Hash.finish a s ())
(fun a _ s () -> Spec.Agile.Hash.hash a s)
(fun a s prevlen ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_zero_blake a prevlen s
else
Spec.Hash.Lemmas.update_multi_zero a s)
(* update_multi_associative *)
(fun a s prevlen1 prevlen2 input1 input2 ->
if is_blake a then
Spec.Hash.Lemmas.update_multi_associative_blake a s prevlen1 prevlen2 input1 input2
else
Spec.Hash.Lemmas.update_multi_associative a s input1 input2)
(* spec_is_incremental *)
(fun a _ input () ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input ())
EverCrypt.Hash.alg_of_state
(fun i _ _ -> EverCrypt.Hash.init #i)
(fun i s prevlen blocks len -> EverCrypt.Hash.update_multi #i s prevlen blocks len)
(fun i s prevlen last last_len ->
EverCrypt.Hash.update_last #i s prevlen last last_len)
(fun i _ s dst _ -> EverCrypt.Hash.finish #i s dst) | {
"file_name": "providers/evercrypt/fst/EverCrypt.Hash.Incremental.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 148,
"start_col": 0,
"start_line": 101
} | module EverCrypt.Hash.Incremental
open FStar.Mul
// Watch out: keep the module declarations in sync between fsti and fst
// (otherwise interleaving issues may bite).
module B = LowStar.Buffer
module S = FStar.Seq
module ST = FStar.HyperStack.ST
module HS = FStar.HyperStack
module G = FStar.Ghost
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module Hash = EverCrypt.Hash
open FStar.HyperStack.ST
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
include Spec.Hash.Definitions
include Hacl.Hash.Definitions
open Spec.Hash.Lemmas
#set-options "--z3rlimit 200 --max_fuel 0 --max_ifuel 0"
// Definitions for instantiating the streaming functor
// ---------------------------------------------------
inline_for_extraction noextract
let agile_state: stateful Hash.alg =
Stateful
EverCrypt.Hash.state
(fun #i h s -> EverCrypt.Hash.footprint s h)
EverCrypt.Hash.freeable
(fun #i h s -> EverCrypt.Hash.invariant s h)
Spec.Hash.Definitions.words_state
(fun i h s -> EverCrypt.Hash.repr s h)
(fun #i h s -> EverCrypt.Hash.invariant_loc_in_footprint s h)
(fun #i l s h0 h1 ->
EverCrypt.Hash.frame_invariant l s h0 h1;
EverCrypt.Hash.frame_invariant_implies_footprint_preservation l s h0 h1)
(fun #i l s h0 h1 -> ())
EverCrypt.Hash.alloca
EverCrypt.Hash.create_in
(fun i -> EverCrypt.Hash.free #i)
(fun i -> EverCrypt.Hash.copy #i)
include EverCrypt.Hash.Incremental.Macros
#push-options "--ifuel 1"
(* Adding some non-inlined definitions to factorize code. This one is public
because it's used by the WASM API, and is generally useful to callers. *)
let hash_len (a:Hash.alg) : (x:UInt32.t { UInt32.v x == Spec.Agile.Hash.hash_length a }) =
match a with
| MD5 -> md5_hash_len
| SHA1 -> sha1_hash_len
| SHA2_224 -> sha2_224_hash_len
| SHA2_256 -> sha2_256_hash_len
| SHA2_384 -> sha2_384_hash_len
| SHA2_512 -> sha2_512_hash_len
| SHA3_224 -> sha3_224_hash_len
| SHA3_256 -> sha3_256_hash_len
| SHA3_384 -> sha3_384_hash_len
| SHA3_512 -> sha3_512_hash_len
| Blake2S -> blake2s_hash_len
| Blake2B -> blake2b_hash_len
#pop-options
private
let block_len a = Hacl.Hash.Definitions.block_len a
inline_for_extraction noextract
let extra_state_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Definitions.extra_state a
=
if is_blake a then
i
else
()
inline_for_extraction noextract
let prev_length_of_nat (a: hash_alg) (i: nat { i % U32.v (block_len a) = 0 }):
Spec.Hash.Incremental.prev_length_t a
=
if is_keccak a then
()
else
i
#push-options "--z3rlimit 500" | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.SHA2.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA3.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.MD.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Blake2s_32.fsti.checked",
"Hacl.Hash.Blake2s_128.fsti.checked",
"Hacl.Hash.Blake2b_32.fsti.checked",
"Hacl.Hash.Blake2b_256.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"EverCrypt.TargetConfig.fsti.checked",
"EverCrypt.Hash.Incremental.Macros.fst.checked",
"EverCrypt.Hash.fsti.checked",
"EverCrypt.Error.fsti.checked",
"EverCrypt.AutoConfig2.fsti.checked"
],
"interface_file": false,
"source_file": "EverCrypt.Hash.Incremental.fst"
} | [
{
"abbrev": false,
"full_module": "EverCrypt.Hash.Incremental.Macros",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverCrypt.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverCrypt.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 500,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Streaming.Interface.block Spec.Hash.Definitions.fixed_len_alg | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Interface.Block",
"Spec.Hash.Definitions.fixed_len_alg",
"Hacl.Streaming.Interface.Erased",
"EverCrypt.Hash.Incremental.agile_state",
"Hacl.Streaming.Interface.stateful_unused",
"EverCrypt.Hash.alg",
"Prims.unit",
"Hacl.Hash.Definitions.max_input_len64",
"Spec.Hash.Definitions.hash_length",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"FStar.Integers.op_Greater",
"FStar.Integers.Signed",
"FStar.Integers.Winfinite",
"EverCrypt.Hash.Incremental.block_len",
"FStar.UInt32.__uint_to_t",
"FStar.UInt32.t",
"Prims.l_and",
"FStar.Integers.op_Less_Equals",
"FStar.UInt32.v",
"FStar.UInt64.v",
"Hacl.Streaming.Interface.__proj__Stateful__item__t",
"FStar.Seq.Base.empty",
"Hacl.Streaming.Interface.uint8",
"FStar.Seq.Base.seq",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"FStar.Seq.Base.length",
"Spec.Agile.Hash.init",
"FStar.Integers.nat",
"FStar.Integers.op_Percent",
"FStar.Integers.op_Plus",
"Spec.Agile.Hash.update_multi",
"Spec.Hash.Definitions.extra_state",
"EverCrypt.Hash.Incremental.extra_state_of_nat",
"Spec.Hash.Incremental.Definitions.update_last",
"Spec.Hash.Incremental.Definitions.prev_length_t",
"EverCrypt.Hash.Incremental.prev_length_of_nat",
"Spec.Agile.Hash.finish",
"Prims.nat",
"Spec.Agile.Hash.hash",
"Prims.eq2",
"Spec.Hash.Definitions.is_blake",
"Spec.Hash.Lemmas.update_multi_zero_blake",
"Prims.bool",
"Spec.Hash.Lemmas.update_multi_zero",
"Spec.Hash.Lemmas.update_multi_associative_blake",
"Spec.Hash.Lemmas.update_multi_associative",
"Spec.Hash.Incremental.hash_is_hash_incremental'",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.append",
"EverCrypt.Hash.alg_of_state",
"FStar.Ghost.erased",
"Hacl.Streaming.Interface.__proj__Stateful__item__s",
"FStar.Ghost.reveal",
"LowStar.Buffer.buffer",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"EverCrypt.Hash.init",
"FStar.Monotonic.HyperStack.mem",
"Hacl.Streaming.Interface.__proj__Stateful__item__invariant",
"LowStar.Monotonic.Buffer.live",
"LowStar.Monotonic.Buffer.loc_disjoint",
"Hacl.Streaming.Interface.__proj__Stateful__item__footprint",
"LowStar.Monotonic.Buffer.loc_buffer",
"Prims.l_imp",
"Hacl.Streaming.Interface.__proj__Stateful__item__freeable",
"Hacl.Streaming.Interface.__proj__Stateful__item__v",
"FStar.Seq.Base.slice",
"LowStar.Monotonic.Buffer.as_seq",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_union",
"LowStar.Monotonic.Buffer.loc",
"FStar.UInt64.t",
"EverCrypt.Hash.update_multi",
"LowStar.Monotonic.Buffer.len",
"EverCrypt.Hash.update_last",
"Hacl.Streaming.Interface.optional_key",
"EverCrypt.Hash.finish"
] | [] | false | false | false | true | false | let evercrypt_hash:block Hash.alg =
| Block Erased
agile_state
(stateful_unused Hash.alg)
unit
Hacl.Hash.Definitions.max_input_len64
(fun a () -> Spec.Hash.Definitions.hash_length a)
block_len
block_len
(fun _ -> 0ul)
(fun _ _ -> S.empty)
(fun a _ -> Spec.Agile.Hash.init a)
(fun a s prevlen input ->
let prevlen = extra_state_of_nat a prevlen in
Spec.Agile.Hash.update_multi a s prevlen input)
(fun a s prevlen input ->
let prevlen = prev_length_of_nat a prevlen in
Spec.Hash.Incremental.update_last a s prevlen input)
(fun a _ s () -> Spec.Agile.Hash.finish a s ())
(fun a _ s () -> Spec.Agile.Hash.hash a s)
(fun a s prevlen ->
if is_blake a
then Spec.Hash.Lemmas.update_multi_zero_blake a prevlen s
else Spec.Hash.Lemmas.update_multi_zero a s)
(fun a s prevlen1 prevlen2 input1 input2 ->
if is_blake a
then Spec.Hash.Lemmas.update_multi_associative_blake a s prevlen1 prevlen2 input1 input2
else Spec.Hash.Lemmas.update_multi_associative a s input1 input2)
(fun a _ input () ->
let input1 = S.append S.empty input in
assert (S.equal input1 input);
Spec.Hash.Incremental.hash_is_hash_incremental' a input ())
EverCrypt.Hash.alg_of_state
(fun i _ _ -> EverCrypt.Hash.init #i)
(fun i s prevlen blocks len -> EverCrypt.Hash.update_multi #i s prevlen blocks len)
(fun i s prevlen last last_len -> EverCrypt.Hash.update_last #i s prevlen last last_len)
(fun i _ s dst _ -> EverCrypt.Hash.finish #i s dst) | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.word | val word:Type0 | val word:Type0 | let word = Lib.IntTypes.uint32 | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 30,
"end_line": 28,
"start_col": 0,
"start_line": 28
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.uint32"
] | [] | false | false | false | true | true | let word =
| Lib.IntTypes.uint32 | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.ws_opaque_aux | val ws_opaque_aux : a: Spec.Hash.Definitions.sha2_alg ->
b: Spec.SHA2.block_w a ->
t: Spec.SHA2.counter{t < Spec.SHA2.size_k_w a}
-> Spec.Hash.Definitions.word a | let ws_opaque_aux = ws | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 38,
"start_col": 7,
"start_line": 38
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = () | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Hash.Definitions.sha2_alg ->
b: Spec.SHA2.block_w a ->
t: Spec.SHA2.counter{t < Spec.SHA2.size_k_w a}
-> Spec.Hash.Definitions.word a | Prims.Tot | [
"total"
] | [] | [
"Spec.SHA2.Lemmas.ws"
] | [] | false | false | false | false | false | let ws_opaque_aux =
| ws | false |
|
Hacl.Impl.SecretBox.fst | Hacl.Impl.SecretBox.secretbox_detached_cipher | val secretbox_detached_cipher:
mlen:size_t
-> c:lbuffer uint8 mlen
-> k:lbuffer uint8 32ul
-> xkeys:lbuffer uint8 96ul
-> n:lbuffer uint8 24ul
-> m:lbuffer uint8 mlen ->
Stack unit
(requires fun h ->
live h c /\ live h m /\ live h xkeys /\ live h n /\ live h k /\
eq_or_disjoint m c /\ disjoint xkeys c /\ disjoint xkeys m /\
disjoint n m /\ disjoint n c /\
(let subkey : Spec.key = LSeq.sub (as_seq h xkeys) 0 32 in
let aekey : Spec.aekey = LSeq.sub (as_seq h xkeys) 32 64 in
(subkey, aekey) == Spec.secretbox_init (as_seq h k) (as_seq h n)))
(ensures fun h0 _ h1 -> modifies (loc c) h0 h1 /\
(let (tag, cipher) = Spec.secretbox_detached (as_seq h0 k) (as_seq h0 n) (as_seq h0 m) in
as_seq h1 c == cipher)) | val secretbox_detached_cipher:
mlen:size_t
-> c:lbuffer uint8 mlen
-> k:lbuffer uint8 32ul
-> xkeys:lbuffer uint8 96ul
-> n:lbuffer uint8 24ul
-> m:lbuffer uint8 mlen ->
Stack unit
(requires fun h ->
live h c /\ live h m /\ live h xkeys /\ live h n /\ live h k /\
eq_or_disjoint m c /\ disjoint xkeys c /\ disjoint xkeys m /\
disjoint n m /\ disjoint n c /\
(let subkey : Spec.key = LSeq.sub (as_seq h xkeys) 0 32 in
let aekey : Spec.aekey = LSeq.sub (as_seq h xkeys) 32 64 in
(subkey, aekey) == Spec.secretbox_init (as_seq h k) (as_seq h n)))
(ensures fun h0 _ h1 -> modifies (loc c) h0 h1 /\
(let (tag, cipher) = Spec.secretbox_detached (as_seq h0 k) (as_seq h0 n) (as_seq h0 m) in
as_seq h1 c == cipher)) | let secretbox_detached_cipher mlen c k xkeys n m =
let h0 = ST.get () in
push_frame ();
let n1 = sub n 16ul 8ul in
let subkey = sub xkeys 0ul 32ul in
let mkey = sub xkeys 32ul 32ul in
let ekey0 = sub xkeys 64ul 32ul in
let mlen0 = get_len0 mlen in
let mlen1 = mlen -! mlen0 in
let m0 = sub m 0ul mlen0 in
let m1 = sub m mlen0 mlen1 in
let block0 = create 32ul (u8 0) in
update_sub block0 0ul mlen0 m0;
map2T 32ul block0 ( ^. ) block0 ekey0;
let c0 = sub c 0ul mlen0 in
let c1 = sub c mlen0 mlen1 in
let h1 = ST.get () in
copy c0 (sub block0 0ul mlen0);
let h2 = ST.get () in
//assert (as_seq h2 c0 == LSeq.sub (as_seq h1 block0) 0 (v mlen0));
salsa20_encrypt mlen1 c1 m1 subkey n1 1ul;
let h3 = ST.get () in
//assert (as_seq h3 c1 == Spec.Salsa20.salsa20_encrypt_bytes (as_seq h2 subkey) (as_seq h2 n1) 1 (as_seq h2 m1));
FStar.Seq.Properties.lemma_split (as_seq h3 c) (v mlen0);
//FStar.Seq.Properties.lemma_split (Seq.append (as_seq h2 c0) (as_seq h3 c1)) (v mlen0);
assert (as_seq h3 c == Seq.append (as_seq h2 c0) (as_seq h3 c1));
assert (
let (tag, cipher) = Spec.secretbox_detached (as_seq h0 k) (as_seq h0 n) (as_seq h0 m) in
as_seq h3 c == cipher);
pop_frame () | {
"file_name": "code/nacl-box/Hacl.Impl.SecretBox.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 14,
"end_line": 105,
"start_col": 0,
"start_line": 73
} | module Hacl.Impl.SecretBox
open FStar.HyperStack.All
open FStar.HyperStack
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Salsa20
open Hacl.Poly1305_32
module ST = FStar.HyperStack.ST
module Spec = Spec.SecretBox
module LSeq = Lib.Sequence
#set-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0"
val secretbox_init:
xkeys:lbuffer uint8 96ul
-> k:lbuffer uint8 32ul
-> n:lbuffer uint8 24ul ->
Stack unit
(requires fun h ->
live h xkeys /\ live h k /\ live h n /\
disjoint k xkeys /\ disjoint n xkeys)
(ensures fun h0 _ h1 ->
modifies (loc xkeys) h0 h1 /\
(let xkeys = as_seq h1 xkeys in
let subkey : Spec.key = LSeq.sub xkeys 0 32 in
let aekey : Spec.aekey = LSeq.sub xkeys 32 64 in
(subkey, aekey) == Spec.secretbox_init (as_seq h0 k) (as_seq h0 n)))
let secretbox_init xkeys k n =
let h0 = ST.get() in
let subkey = sub xkeys 0ul 32ul in
let aekey = sub xkeys 32ul 64ul in
let n0 = sub n 0ul 16ul in
let n1 = sub n 16ul 8ul in
hsalsa20 subkey k n0;
salsa20_key_block0 aekey subkey n1
inline_for_extraction noextract
let get_len0 (len:size_t) : Tot (r:size_t{v r <= 32 /\ v r == Spec.get_len0 (v len)}) =
if len <=. 32ul then len else 32ul
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val secretbox_detached_cipher:
mlen:size_t
-> c:lbuffer uint8 mlen
-> k:lbuffer uint8 32ul
-> xkeys:lbuffer uint8 96ul
-> n:lbuffer uint8 24ul
-> m:lbuffer uint8 mlen ->
Stack unit
(requires fun h ->
live h c /\ live h m /\ live h xkeys /\ live h n /\ live h k /\
eq_or_disjoint m c /\ disjoint xkeys c /\ disjoint xkeys m /\
disjoint n m /\ disjoint n c /\
(let subkey : Spec.key = LSeq.sub (as_seq h xkeys) 0 32 in
let aekey : Spec.aekey = LSeq.sub (as_seq h xkeys) 32 64 in
(subkey, aekey) == Spec.secretbox_init (as_seq h k) (as_seq h n)))
(ensures fun h0 _ h1 -> modifies (loc c) h0 h1 /\
(let (tag, cipher) = Spec.secretbox_detached (as_seq h0 k) (as_seq h0 n) (as_seq h0 m) in
as_seq h1 c == cipher)) | {
"checked_file": "/",
"dependencies": [
"Spec.SecretBox.fst.checked",
"Spec.Salsa20.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Streaming.Poly1305_32.fsti.checked",
"Hacl.Salsa20.fst.checked",
"Hacl.Poly1305_32.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.Properties.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.SecretBox.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Spec.SecretBox",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Poly1305_32",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Salsa20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
mlen: Lib.IntTypes.size_t ->
c: Lib.Buffer.lbuffer Lib.IntTypes.uint8 mlen ->
k: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul ->
xkeys: Lib.Buffer.lbuffer Lib.IntTypes.uint8 96ul ->
n: Lib.Buffer.lbuffer Lib.IntTypes.uint8 24ul ->
m: Lib.Buffer.lbuffer Lib.IntTypes.uint8 mlen
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Prims._assert",
"Spec.SecretBox.tag",
"Lib.ByteSequence.bytes",
"Prims.b2t",
"Prims.op_Equality",
"Prims.nat",
"Lib.Sequence.length",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Prims.eq2",
"Lib.Sequence.seq",
"Prims.l_or",
"FStar.Seq.Base.length",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"FStar.Pervasives.Native.tuple2",
"Lib.IntTypes.int_t",
"Spec.SecretBox.secretbox_detached",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.append",
"FStar.Seq.Properties.lemma_split",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Salsa20.salsa20_encrypt",
"Lib.Buffer.copy",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.sub",
"Lib.Buffer.map2T",
"Lib.IntTypes.op_Hat_Dot",
"Lib.Buffer.update_sub",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.create",
"Lib.IntTypes.u8",
"Lib.IntTypes.op_Subtraction_Bang",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Prims.int",
"Lib.IntTypes.range",
"Prims.op_GreaterThanOrEqual",
"Prims.op_Subtraction",
"Prims.pow2",
"Spec.SecretBox.get_len0",
"Hacl.Impl.SecretBox.get_len0",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let secretbox_detached_cipher mlen c k xkeys n m =
| let h0 = ST.get () in
push_frame ();
let n1 = sub n 16ul 8ul in
let subkey = sub xkeys 0ul 32ul in
let mkey = sub xkeys 32ul 32ul in
let ekey0 = sub xkeys 64ul 32ul in
let mlen0 = get_len0 mlen in
let mlen1 = mlen -! mlen0 in
let m0 = sub m 0ul mlen0 in
let m1 = sub m mlen0 mlen1 in
let block0 = create 32ul (u8 0) in
update_sub block0 0ul mlen0 m0;
map2T 32ul block0 ( ^. ) block0 ekey0;
let c0 = sub c 0ul mlen0 in
let c1 = sub c mlen0 mlen1 in
let h1 = ST.get () in
copy c0 (sub block0 0ul mlen0);
let h2 = ST.get () in
salsa20_encrypt mlen1 c1 m1 subkey n1 1ul;
let h3 = ST.get () in
FStar.Seq.Properties.lemma_split (as_seq h3 c) (v mlen0);
assert (as_seq h3 c == Seq.append (as_seq h2 c0) (as_seq h3 c1));
assert (let tag, cipher = Spec.secretbox_detached (as_seq h0 k) (as_seq h0 n) (as_seq h0 m) in
as_seq h3 c == cipher);
pop_frame () | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.shuffle_core_opaque_aux | val shuffle_core_opaque_aux : a: Spec.Hash.Definitions.sha2_alg ->
block: Spec.SHA2.block_w a ->
hash: Spec.Hash.Definitions.words_state a ->
t: Spec.SHA2.counter{t < Spec.SHA2.size_k_w a}
-> Spec.Hash.Definitions.words_state a | let shuffle_core_opaque_aux = shuffle_core | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 49,
"end_line": 42,
"start_col": 7,
"start_line": 42
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Hash.Definitions.sha2_alg ->
block: Spec.SHA2.block_w a ->
hash: Spec.Hash.Definitions.words_state a ->
t: Spec.SHA2.counter{t < Spec.SHA2.size_k_w a}
-> Spec.Hash.Definitions.words_state a | Prims.Tot | [
"total"
] | [] | [
"Spec.SHA2.Lemmas.shuffle_core"
] | [] | false | false | false | false | false | let shuffle_core_opaque_aux =
| shuffle_core | false |
|
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.update_multi_opaque_aux | val update_multi_opaque_aux : a: Spec.Hash.Definitions.hash_alg ->
hash: Spec.Hash.Definitions.words_state a ->
prev: Spec.Hash.Definitions.extra_state a ->
blocks: Spec.Hash.Definitions.bytes_blocks a
-> Prims.Pure (Spec.Hash.Definitions.words_state a) | let update_multi_opaque_aux = opaque_make update_multi | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 73,
"end_line": 46,
"start_col": 19,
"start_line": 46
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Hash.Definitions.hash_alg ->
hash: Spec.Hash.Definitions.words_state a ->
prev: Spec.Hash.Definitions.extra_state a ->
blocks: Spec.Hash.Definitions.bytes_blocks a
-> Prims.Pure (Spec.Hash.Definitions.words_state a) | Prims.Pure | [] | [] | [
"Vale.Def.Opaque_s.opaque_make",
"Spec.Hash.Definitions.hash_alg",
"Spec.Hash.Definitions.words_state",
"Spec.Hash.Definitions.extra_state",
"Spec.Hash.Definitions.bytes_blocks",
"Prims.b2t",
"Spec.Agile.Hash.update_multi_pre",
"Prims.l_True",
"Spec.Agile.Hash.update_multi"
] | [] | false | false | false | false | false | let update_multi_opaque_aux =
| opaque_make update_multi | false |
|
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.update_multi_reveal | val update_multi_reveal : _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.SHA.SHA_helpers.update_multi_opaque_aux == Spec.Agile.Hash.update_multi) | let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 118,
"end_line": 47,
"start_col": 12,
"start_line": 47
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.SHA.SHA_helpers.update_multi_opaque_aux == Spec.Agile.Hash.update_multi) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Opaque_s.opaque_revealer",
"Spec.Hash.Definitions.hash_alg",
"Spec.Hash.Definitions.words_state",
"Spec.Hash.Definitions.extra_state",
"Spec.Hash.Definitions.bytes_blocks",
"Prims.b2t",
"Spec.Agile.Hash.update_multi_pre",
"Prims.l_True",
"Vale.SHA.SHA_helpers.update_multi_opaque_aux",
"Spec.Agile.Hash.update_multi"
] | [] | true | false | true | false | false | let update_multi_reveal =
| opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi | false |
|
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.to_uint32 | val to_uint32 (n: nat32) : Lib.IntTypes.uint32 | val to_uint32 (n: nat32) : Lib.IntTypes.uint32 | let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 66,
"end_line": 27,
"start_col": 0,
"start_line": 27
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n: Vale.Def.Words_s.nat32 -> Lib.IntTypes.uint32 | Prims.Tot | [
"total"
] | [] | [
"Vale.Def.Words_s.nat32",
"Lib.IntTypes.u32",
"Lib.IntTypes.uint32"
] | [] | false | false | false | true | false | let to_uint32 (n: nat32) : Lib.IntTypes.uint32 =
| Lib.IntTypes.u32 n | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.k | val k : (s:seq word {length s = size_k_w_256}) | val k : (s:seq word {length s = size_k_w_256}) | let k = (Spec.SHA2.k0 SHA2_256) | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 31,
"end_line": 29,
"start_col": 0,
"start_line": 29
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s:
FStar.Seq.Base.seq Vale.SHA.SHA_helpers.word
{FStar.Seq.Base.length s = Vale.SHA.SHA_helpers.size_k_w_256} | Prims.Tot | [
"total"
] | [] | [
"Spec.SHA2.k0",
"Spec.Hash.Definitions.SHA2_256"
] | [] | false | false | false | false | false | let k =
| (Spec.SHA2.k0 SHA2_256) | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.add_mod32 | val add_mod32 (x: word) (y: nat32) : nat32 | val add_mod32 (x: word) (y: nat32) : nat32 | let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y)) | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 71,
"end_line": 54,
"start_col": 0,
"start_line": 54
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Vale.SHA.SHA_helpers.word -> y: Vale.Def.Words_s.nat32 -> Vale.Def.Words_s.nat32 | Prims.Tot | [
"total"
] | [] | [
"Vale.SHA.SHA_helpers.word",
"Vale.Def.Words_s.nat32",
"Vale.SHA.SHA_helpers.vv",
"FStar.UInt32.add_mod",
"Vale.SHA.SHA_helpers.to_uint32"
] | [] | false | false | false | true | false | let add_mod32 (x: word) (y: nat32) : nat32 =
| vv (add_mod x (to_uint32 y)) | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.vv | val vv (u: Lib.IntTypes.uint32) : nat32 | val vv (u: Lib.IntTypes.uint32) : nat32 | let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 57,
"end_line": 26,
"start_col": 0,
"start_line": 26
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | u8: Lib.IntTypes.uint32 -> Vale.Def.Words_s.nat32 | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.uint32",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.SEC",
"Vale.Def.Words_s.nat32"
] | [] | false | false | false | true | false | let vv (u: Lib.IntTypes.uint32) : nat32 =
| Lib.IntTypes.v u | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.word_to_nat32 | val word_to_nat32 (x:word) : nat32 | val word_to_nat32 (x:word) : nat32 | let word_to_nat32 = vv | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 22,
"end_line": 55,
"start_col": 0,
"start_line": 55
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Vale.SHA.SHA_helpers.word -> Vale.Def.Words_s.nat32 | Prims.Tot | [
"total"
] | [] | [
"Vale.SHA.SHA_helpers.vv"
] | [] | false | false | false | true | false | let word_to_nat32 =
| vv | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.nat32_to_word | val nat32_to_word (x:nat32) : word | val nat32_to_word (x:nat32) : word | let nat32_to_word = to_uint32 | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 56,
"start_col": 0,
"start_line": 56
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y)) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Vale.Def.Words_s.nat32 -> Vale.SHA.SHA_helpers.word | Prims.Tot | [
"total"
] | [] | [
"Vale.SHA.SHA_helpers.to_uint32"
] | [] | false | false | false | true | false | let nat32_to_word =
| to_uint32 | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.shuffle_core_opaque | val shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 | val shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 | let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 44,
"start_col": 0,
"start_line": 43
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
block: Vale.SHA.SHA_helpers.block_w ->
hash: Vale.SHA.SHA_helpers.hash256 ->
t: Vale.SHA.SHA_helpers.counter{t < Vale.SHA.SHA_helpers.size_k_w_256}
-> Vale.SHA.SHA_helpers.hash256 | Prims.Tot | [
"total"
] | [] | [
"Vale.SHA.SHA_helpers.block_w",
"Vale.SHA.SHA_helpers.hash256",
"Vale.SHA.SHA_helpers.counter",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.SHA.SHA_helpers.size_k_w_256",
"Vale.SHA.SHA_helpers.shuffle_core_opaque_aux",
"Spec.Hash.Definitions.SHA2_256"
] | [] | false | false | false | false | false | let shuffle_core_opaque (block: block_w) (hash: hash256) (t: counter{t < size_k_w_256}) : hash256 =
| shuffle_core_opaque_aux SHA2_256 block hash t | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.sha256_rnds2_spec_quad32 | val sha256_rnds2_spec_quad32 (src1 src2 wk: quad32) : quad32 | val sha256_rnds2_spec_quad32 (src1 src2 wk: quad32) : quad32 | let sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) : quad32 =
let abef', cdgh' = sha256_rnds2_spec_update_quad32 src2 src1 (to_uint32 wk.lo0) in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' (to_uint32 wk.lo1) in
abef'' | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 8,
"end_line": 169,
"start_col": 0,
"start_line": 166
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y))
let word_to_nat32 = vv
let nat32_to_word = to_uint32
let byte_to_nat8 = UInt8.v
let nat8_to_byte = UInt8.uint_to_t
let make_hash_def (abef cdgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abef.hi3 /\
hash.[1] == to_uint32 abef.hi2 /\
hash.[2] == to_uint32 cdgh.hi3 /\
hash.[3] == to_uint32 cdgh.hi2 /\
hash.[4] == to_uint32 abef.lo1 /\
hash.[5] == to_uint32 abef.lo0 /\
hash.[6] == to_uint32 cdgh.lo1 /\
hash.[7] == to_uint32 cdgh.lo0
} ) =
let a = to_uint32 abef.hi3 in
let b = to_uint32 abef.hi2 in
let c = to_uint32 cdgh.hi3 in
let d = to_uint32 cdgh.hi2 in
let e = to_uint32 abef.lo1 in
let f = to_uint32 abef.lo0 in
let g = to_uint32 cdgh.lo1 in
let h = to_uint32 cdgh.lo0 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
//assert_norm (index hash 2 == c);
hash
[@"opaque_to_smt"] let make_hash = opaque_make make_hash_def
irreducible let make_hash_reveal = opaque_revealer (`%make_hash) make_hash make_hash_def
let make_ordered_hash_def (abcd efgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abcd.lo0 /\
hash.[1] == to_uint32 abcd.lo1 /\
hash.[2] == to_uint32 abcd.hi2 /\
hash.[3] == to_uint32 abcd.hi3 /\
hash.[4] == to_uint32 efgh.lo0 /\
hash.[5] == to_uint32 efgh.lo1 /\
hash.[6] == to_uint32 efgh.hi2 /\
hash.[7] == to_uint32 efgh.hi3
})
=
let a = to_uint32 abcd.lo0 in
let b = to_uint32 abcd.lo1 in
let c = to_uint32 abcd.hi2 in
let d = to_uint32 abcd.hi3 in
let e = to_uint32 efgh.lo0 in
let f = to_uint32 efgh.lo1 in
let g = to_uint32 efgh.hi2 in
let h = to_uint32 efgh.hi3 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
hash
[@"opaque_to_smt"] let make_ordered_hash = opaque_make make_ordered_hash_def
irreducible let make_ordered_hash_reveal = opaque_revealer (`%make_ordered_hash) make_ordered_hash make_ordered_hash_def
let shuffle_core_properties (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}) :
Lemma(let h = shuffle_core_opaque block hash t in
let open Lib.IntTypes in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
h.[0] == t1 +. t2 /\
h.[1] == a0 /\
h.[2] == b0 /\
h.[3] == c0 /\
h.[4] == d0 +. t1 /\
h.[5] == e0 /\
h.[6] == f0 /\
h.[7] == g0)
=
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
let h = shuffle_core SHA2_256 block hash t in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
let l = [ t1 +. t2; a0; b0; c0; d0 +. t1; e0; f0; g0 ] in
assert (h == seq_of_list l);
elim_of_list l;
()
let sha256_rnds2_spec_update_quad32 (abef cdgh:quad32) (wk:UInt32.t) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let a', b', c', d', e', f', g', h' = sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3] hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let abef' = Mkfour (vv f') (vv e') (vv b') (vv a') in
let cdgh' = Mkfour (vv h') (vv g') (vv d') (vv c') in
(abef', cdgh') | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | src1: Vale.Def.Types_s.quad32 -> src2: Vale.Def.Types_s.quad32 -> wk: Vale.Def.Types_s.quad32
-> Vale.Def.Types_s.quad32 | Prims.Tot | [
"total"
] | [] | [
"Vale.Def.Types_s.quad32",
"FStar.Pervasives.Native.tuple2",
"Vale.SHA.SHA_helpers.sha256_rnds2_spec_update_quad32",
"Vale.SHA.SHA_helpers.to_uint32",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0"
] | [] | false | false | false | true | false | let sha256_rnds2_spec_quad32 (src1 src2 wk: quad32) : quad32 =
| let abef', cdgh' = sha256_rnds2_spec_update_quad32 src2 src1 (to_uint32 wk.lo0) in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' (to_uint32 wk.lo1) in
abef'' | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.ws_opaque | val ws_opaque (b:block_w) (t:counter{t < size_k_w_256}):nat32 | val ws_opaque (b:block_w) (t:counter{t < size_k_w_256}):nat32 | let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t) | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 33,
"end_line": 40,
"start_col": 0,
"start_line": 39
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = () | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.SHA.SHA_helpers.block_w ->
t: Vale.SHA.SHA_helpers.counter{t < Vale.SHA.SHA_helpers.size_k_w_256}
-> Vale.Def.Words_s.nat32 | Prims.Tot | [
"total"
] | [] | [
"Vale.SHA.SHA_helpers.block_w",
"Vale.SHA.SHA_helpers.counter",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.SHA.SHA_helpers.size_k_w_256",
"Vale.SHA.SHA_helpers.vv",
"Vale.SHA.SHA_helpers.ws_opaque_aux",
"Spec.Hash.Definitions.SHA2_256",
"Vale.Def.Words_s.nat32"
] | [] | false | false | false | false | false | let ws_opaque (b: block_w) (t: counter{t < size_k_w_256}) : nat32 =
| vv (ws_opaque_aux SHA2_256 b t) | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.update_multi_transparent | val update_multi_transparent (hash:hash256) (blocks:bytes_blocks):hash256 | val update_multi_transparent (hash:hash256) (blocks:bytes_blocks):hash256 | let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 38,
"end_line": 52,
"start_col": 0,
"start_line": 51
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | hash: Vale.SHA.SHA_helpers.hash256 -> blocks: Vale.SHA.SHA_helpers.bytes_blocks
-> Vale.SHA.SHA_helpers.hash256 | Prims.Tot | [
"total"
] | [] | [
"Vale.SHA.SHA_helpers.hash256",
"Vale.SHA.SHA_helpers.bytes_blocks",
"Spec.Agile.Hash.update_multi",
"Spec.Hash.Definitions.SHA2_256"
] | [] | false | false | false | true | false | let update_multi_transparent (hash: hash256) (blocks: bytes_blocks) =
| update_multi SHA2_256 hash () blocks | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.update_multi_opaque | val update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 | val update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 | let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks) | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 51,
"end_line": 49,
"start_col": 0,
"start_line": 48
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | hash: Vale.SHA.SHA_helpers.hash256 -> blocks: Vale.SHA.SHA_helpers.bytes_blocks
-> Vale.SHA.SHA_helpers.hash256 | Prims.Tot | [
"total"
] | [] | [
"Vale.SHA.SHA_helpers.hash256",
"Vale.SHA.SHA_helpers.bytes_blocks",
"Vale.SHA.SHA_helpers.update_multi_opaque_aux",
"Spec.Hash.Definitions.SHA2_256"
] | [] | false | false | false | true | false | let update_multi_opaque (hash: hash256) (blocks: bytes_blocks) : hash256 =
| (update_multi_opaque_aux SHA2_256 hash () blocks) | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.byte_to_nat8 | val byte_to_nat8 (b:byte) : nat8 | val byte_to_nat8 (b:byte) : nat8 | let byte_to_nat8 = UInt8.v | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 57,
"start_col": 0,
"start_line": 57
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y))
let word_to_nat32 = vv | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Vale.SHA.SHA_helpers.byte -> Vale.Def.Words_s.nat8 | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt8.v"
] | [] | false | false | false | true | false | let byte_to_nat8 =
| UInt8.v | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.add_mod_quad32 | val add_mod_quad32 (q0 q1: quad32) : quad32 | val add_mod_quad32 (q0 q1: quad32) : quad32 | let add_mod_quad32 (q0 q1:quad32) : quad32 =
Mkfour (vv (add_mod (to_uint32 q0.lo0) (to_uint32 q1.lo0)))
(vv (add_mod (to_uint32 q0.lo1) (to_uint32 q1.lo1)))
(vv (add_mod (to_uint32 q0.hi2) (to_uint32 q1.hi2)))
(vv (add_mod (to_uint32 q0.hi3) (to_uint32 q1.hi3))) | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 61,
"end_line": 435,
"start_col": 0,
"start_line": 431
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y))
let word_to_nat32 = vv
let nat32_to_word = to_uint32
let byte_to_nat8 = UInt8.v
let nat8_to_byte = UInt8.uint_to_t
let make_hash_def (abef cdgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abef.hi3 /\
hash.[1] == to_uint32 abef.hi2 /\
hash.[2] == to_uint32 cdgh.hi3 /\
hash.[3] == to_uint32 cdgh.hi2 /\
hash.[4] == to_uint32 abef.lo1 /\
hash.[5] == to_uint32 abef.lo0 /\
hash.[6] == to_uint32 cdgh.lo1 /\
hash.[7] == to_uint32 cdgh.lo0
} ) =
let a = to_uint32 abef.hi3 in
let b = to_uint32 abef.hi2 in
let c = to_uint32 cdgh.hi3 in
let d = to_uint32 cdgh.hi2 in
let e = to_uint32 abef.lo1 in
let f = to_uint32 abef.lo0 in
let g = to_uint32 cdgh.lo1 in
let h = to_uint32 cdgh.lo0 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
//assert_norm (index hash 2 == c);
hash
[@"opaque_to_smt"] let make_hash = opaque_make make_hash_def
irreducible let make_hash_reveal = opaque_revealer (`%make_hash) make_hash make_hash_def
let make_ordered_hash_def (abcd efgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abcd.lo0 /\
hash.[1] == to_uint32 abcd.lo1 /\
hash.[2] == to_uint32 abcd.hi2 /\
hash.[3] == to_uint32 abcd.hi3 /\
hash.[4] == to_uint32 efgh.lo0 /\
hash.[5] == to_uint32 efgh.lo1 /\
hash.[6] == to_uint32 efgh.hi2 /\
hash.[7] == to_uint32 efgh.hi3
})
=
let a = to_uint32 abcd.lo0 in
let b = to_uint32 abcd.lo1 in
let c = to_uint32 abcd.hi2 in
let d = to_uint32 abcd.hi3 in
let e = to_uint32 efgh.lo0 in
let f = to_uint32 efgh.lo1 in
let g = to_uint32 efgh.hi2 in
let h = to_uint32 efgh.hi3 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
hash
[@"opaque_to_smt"] let make_ordered_hash = opaque_make make_ordered_hash_def
irreducible let make_ordered_hash_reveal = opaque_revealer (`%make_ordered_hash) make_ordered_hash make_ordered_hash_def
let shuffle_core_properties (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}) :
Lemma(let h = shuffle_core_opaque block hash t in
let open Lib.IntTypes in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
h.[0] == t1 +. t2 /\
h.[1] == a0 /\
h.[2] == b0 /\
h.[3] == c0 /\
h.[4] == d0 +. t1 /\
h.[5] == e0 /\
h.[6] == f0 /\
h.[7] == g0)
=
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
let h = shuffle_core SHA2_256 block hash t in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
let l = [ t1 +. t2; a0; b0; c0; d0 +. t1; e0; f0; g0 ] in
assert (h == seq_of_list l);
elim_of_list l;
()
let sha256_rnds2_spec_update_quad32 (abef cdgh:quad32) (wk:UInt32.t) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let a', b', c', d', e', f', g', h' = sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3] hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let abef' = Mkfour (vv f') (vv e') (vv b') (vv a') in
let cdgh' = Mkfour (vv h') (vv g') (vv d') (vv c') in
(abef', cdgh')
let sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) : quad32 =
let abef', cdgh' = sha256_rnds2_spec_update_quad32 src2 src1 (to_uint32 wk.lo0) in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' (to_uint32 wk.lo1) in
abef''
let lemma_sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) :
Lemma (sha256_rnds2_spec src1 src2 wk == sha256_rnds2_spec_quad32 src1 src2 wk)
=
sha256_rnds2_spec_reveal ();
()
let lemma_add_mod_commutes (x y:UInt32.t) :
Lemma (add_mod x y == add_mod y x)
=
()
(*
let lemma_add_mod32_associates (x y z:int) :
Lemma ( ((x + y % pow2_32) + z) % pow2_32 == (x + ((y + z) % pow2_32)) % pow2_32 )
=
()
*)
let lemma_add_mod_associates_U32 (x y z:UInt32.t) :
Lemma (add_mod x (add_mod y z) == add_mod (add_mod x y) z)
=
let open Lib.IntTypes in
calc (==) {
v (x +. (y +. z));
(==) { }
(v x + (v y + v z) % pow2 32) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v x) (v y + v z) (pow2 32) }
((v x + v y) + v z) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v z) (v x + v y) (pow2 32) }
((v x + v y) % pow2 32 + v z) % pow2 32;
(==) { }
v ((x +. y) +. z);
};
v_inj (x +. (y +. z)) ((x +. y) +. z)
(*
assert_norm (pow2 32 == pow2_32);
//assert (add_mod y z == to_uint32 ((vv y + vv z) % pow2_32));
//assert (add_mod x (add_mod y z) == to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32));
lemma_add_mod32_associates (vv x) (vv y) (vv z);
//assert (to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32) ==
// to_uint32 (((vv x + vv y % pow2_32) + vv z) % pow2_32));
*)
#reset-options "--max_fuel 0 --max_ifuel 0"
let lemma_add_wrap_is_add_mod (n0 n1:nat32) :
Lemma (add_wrap n0 n1 == vv (add_mod (to_uint32 n0) (to_uint32 n1)))
=
assert_norm (pow2 32 == pow2_32);
()
let add_wrap_commutes (x y:nat32) :
Lemma(add_wrap x y == add_wrap y x)
=
()
// Walk F* through the math steps required to rearrange all of the add_mods
let lemma_add_mod_a (a b c d e f g h wk:UInt32.t) :
Lemma ( let u = add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk
(add_mod h
(add_mod (_Maj SHA2_256 a b c)
(_Sigma0 SHA2_256 a))))) in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
u == core)
=
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
lemma_add_mod_commutes (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c);
assert (t2 == add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
assert (t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
assert (core == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
// ==> add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk)
lemma_add_mod_commutes (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g);
// ==> add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk)
lemma_add_mod_associates_U32 (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)));
assert (core == add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)))));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
()
let lemma_add_mod_e (a b c d e f g h wk:UInt32.t) :
Lemma ( let u = add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk
(add_mod h
d))) in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
u == core)
=
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
// t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_commutes d t1;
// core == add_mod t1 d
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
assert (t1 == add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h);
lemma_add_mod_associates_U32 (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h d;
assert (core == add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) (add_mod h d));
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk (add_mod h d);
assert (core == add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) (add_mod wk (add_mod h d)));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d));
assert (core == add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d))));
()
let lemma_sha256_rnds2_spec_update_is_shuffle_core (hash:hash256) (wk:UInt32.t) (t:counter) (block:block_w) : Lemma
(requires t < size_k_w SHA2_256 /\ wk == to_uint32 (add_mod32 (k0 SHA2_256).[t] (ws_opaque block t)))
(ensures (let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash.[0] hash.[1] hash.[2] hash.[3]
hash.[4] hash.[5] hash.[6] hash.[7] wk in
let u = seq_of_list [a'; b'; c'; d'; e'; f'; g'; h'] in
let c = shuffle_core_opaque block hash t in
u == c))
=
let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash.[0] hash.[1] hash.[2] hash.[3]
hash.[4] hash.[5] hash.[6] hash.[7] wk in
let l:list Lib.IntTypes.uint32 = [a'; b'; c'; d'; e'; f'; g'; h'] in
let u:Seq.seq UInt32.t = seq_of_list l in
assert_norm (List.length l == 8);
let c = shuffle_core_opaque block hash t in
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
Pervasives.reveal_opaque (`%ws) ws;
shuffle_core_properties block hash t;
elim_of_list l;
Classical.forall_intro_3 lemma_add_mod_associates_U32;
lemma_add_mod_a hash.[0] hash.[1] hash.[2] hash.[3] hash.[4] hash.[5] hash.[6] hash.[7] wk;
lemma_add_mod_e hash.[0] hash.[1] hash.[2] hash.[3] hash.[4] hash.[5] hash.[6] hash.[7] wk
let sha256_rnds2_spec_update_core_quad32 (abef cdgh:quad32) (wk:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256}) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let abef' = Mkfour (vv hash1.[5]) (vv hash1.[4]) (vv hash1.[1]) (vv hash1.[0]) in
let cdgh' = Mkfour (vv hash1.[7]) (vv hash1.[6]) (vv hash1.[3]) (vv hash1.[2]) in
(abef', cdgh')
let lemma_rnds_quad32 (abef cdgh:quad32) (wk:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256}) : Lemma
(requires wk == to_uint32 (add_mod32 (k0 SHA2_256).[t] (ws_opaque block t)))
(ensures sha256_rnds2_spec_update_core_quad32 abef cdgh wk block t == sha256_rnds2_spec_update_quad32 abef cdgh wk)
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3]
hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let l = [a'; b'; c'; d'; e'; f'; g'; h'] in
elim_of_list l;
lemma_sha256_rnds2_spec_update_is_shuffle_core hash0 wk t block;
()
#push-options "--z3rlimit 30"
let lemma_rnds2_spec_quad32_is_shuffle_core_x2 (abef cdgh:quad32) (wk0 wk1:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256 - 1}) : Lemma
(requires vv wk0 == add_mod32 (k0 SHA2_256).[t] (ws_opaque block t) /\
vv wk1 == add_mod32 (k0 SHA2_256).[t+1] (ws_opaque block (t+1)))
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
hash2 == make_hash abef'' cdgh''))
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
lemma_rnds_quad32 abef cdgh wk0 block t;
lemma_rnds_quad32 abef' cdgh' wk1 block (t+1);
assert (equal (make_hash abef' cdgh') hash1);
assert (equal (make_hash abef'' cdgh'') hash2);
()
#pop-options
let sha256_rnds2_spec_update_quad32_x2_shifts (abef cdgh:quad32) (wk0 wk1:UInt32.t) :
Lemma ((let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
cdgh'' == abef))
=
()
let sha256_rnds2_spec_quad32_is_shuffle_core_x2 (abef cdgh wk:quad32) (block:block_w) (t:counter{t < size_k_w_256 - 1}) : Lemma
(requires wk.lo0 == add_mod32 (k0 SHA2_256).[t] (ws_opaque block t) /\
wk.lo1 == add_mod32 (k0 SHA2_256).[t+1] (ws_opaque block (t+1)))
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef' = sha256_rnds2_spec_quad32 cdgh abef wk in
hash2 == make_hash abef' abef))
=
lemma_rnds2_spec_quad32_is_shuffle_core_x2 abef cdgh (to_uint32 wk.lo0) (to_uint32 wk.lo1) block t;
sha256_rnds2_spec_update_quad32_x2_shifts abef cdgh (to_uint32 wk.lo0) (to_uint32 wk.lo1);
()
let lemma_sha256_rnds2_two_steps (abef cdgh xmm0:quad32) (t:counter) (block:block_w) : Lemma
(requires t + 1 < size_k_w_256 /\
xmm0.lo0 == add_wrap (vv (k0 SHA2_256).[t] ) (ws_opaque block t) /\
xmm0.lo1 == add_wrap (vv (k0 SHA2_256).[t+1]) (ws_opaque block (t+1)) )
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
hash2 == make_hash (sha256_rnds2_spec cdgh abef xmm0) abef))
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t] ) (ws_opaque block t);
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t+1]) (ws_opaque block (t+1));
sha256_rnds2_spec_quad32_is_shuffle_core_x2 abef cdgh xmm0 block t;
lemma_sha256_rnds2_spec_quad32 cdgh abef xmm0;
()
// Top-level proof for the SHA256_rnds2 instruction
let lemma_sha256_rnds2 (abef cdgh xmm0:quad32) (t:counter) (block:block_w) (hash_in:hash256) : Lemma
(requires t + 1 < size_k_w_256 /\
xmm0.lo0 == add_wrap (word_to_nat32 k.[t]) (ws_opaque block t) /\
xmm0.lo1 == add_wrap (word_to_nat32 k.[t+1]) (ws_opaque block (t+1)) /\
make_hash abef cdgh == Spec.Loops.repeat_range 0 t (shuffle_core_opaque block) hash_in
)
(ensures make_hash (sha256_rnds2_spec cdgh abef xmm0) abef ==
Spec.Loops.repeat_range 0 (t+2) (shuffle_core_opaque block) hash_in)
=
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t] ) (ws_opaque block t);
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t+1]) (ws_opaque block (t+1));
lemma_sha256_rnds2_two_steps abef cdgh xmm0 t block;
Spec.Loops.repeat_range_induction 0 (t + 1) (shuffle_core_opaque block) hash_in;
Spec.Loops.repeat_range_induction 0 (t + 2) (shuffle_core_opaque block) hash_in;
()
(* Proof work for the SHA256_msg* instructions *)
let _sigma0_quad32 (q:quad32) : quad32 =
Mkfour (vv (_sigma0 SHA2_256 (to_uint32 q.lo0)))
(vv (_sigma0 SHA2_256 (to_uint32 q.lo1)))
(vv (_sigma0 SHA2_256 (to_uint32 q.hi2)))
(vv (_sigma0 SHA2_256 (to_uint32 q.hi3)))
let _sigma1_quad32 (q:quad32) : quad32 =
Mkfour (vv (_sigma1 SHA2_256 (to_uint32 q.lo0)))
(vv (_sigma1 SHA2_256 (to_uint32 q.lo1)))
(vv (_sigma1 SHA2_256 (to_uint32 q.hi2)))
(vv (_sigma1 SHA2_256 (to_uint32 q.hi3)))
let ws_partial_def (t:counter) (block:block_w) : quad32 =
if 16 <= t && t < size_k_w_256 then
(let init = ws_quad32 (t-16) block in
let sigma0_in = ws_quad32 (t-15) block in
let sigma0_out = _sigma0_quad32 sigma0_in in
add_wrap_quad32 init sigma0_out)
else
Mkfour 0 0 0 0 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | q0: Vale.Def.Types_s.quad32 -> q1: Vale.Def.Types_s.quad32 -> Vale.Def.Types_s.quad32 | Prims.Tot | [
"total"
] | [] | [
"Vale.Def.Types_s.quad32",
"Vale.Def.Words_s.Mkfour",
"Vale.Def.Types_s.nat32",
"Vale.SHA.SHA_helpers.vv",
"FStar.UInt32.add_mod",
"Vale.SHA.SHA_helpers.to_uint32",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3"
] | [] | false | false | false | true | false | let add_mod_quad32 (q0 q1: quad32) : quad32 =
| Mkfour (vv (add_mod (to_uint32 q0.lo0) (to_uint32 q1.lo0)))
(vv (add_mod (to_uint32 q0.lo1) (to_uint32 q1.lo1)))
(vv (add_mod (to_uint32 q0.hi2) (to_uint32 q1.hi2)))
(vv (add_mod (to_uint32 q0.hi3) (to_uint32 q1.hi3))) | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.sha256_rnds2_spec_update_quad32 | val sha256_rnds2_spec_update_quad32 (abef cdgh: quad32) (wk: UInt32.t) : (quad32 & quad32) | val sha256_rnds2_spec_update_quad32 (abef cdgh: quad32) (wk: UInt32.t) : (quad32 & quad32) | let sha256_rnds2_spec_update_quad32 (abef cdgh:quad32) (wk:UInt32.t) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let a', b', c', d', e', f', g', h' = sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3] hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let abef' = Mkfour (vv f') (vv e') (vv b') (vv a') in
let cdgh' = Mkfour (vv h') (vv g') (vv d') (vv c') in
(abef', cdgh') | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 16,
"end_line": 164,
"start_col": 0,
"start_line": 159
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y))
let word_to_nat32 = vv
let nat32_to_word = to_uint32
let byte_to_nat8 = UInt8.v
let nat8_to_byte = UInt8.uint_to_t
let make_hash_def (abef cdgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abef.hi3 /\
hash.[1] == to_uint32 abef.hi2 /\
hash.[2] == to_uint32 cdgh.hi3 /\
hash.[3] == to_uint32 cdgh.hi2 /\
hash.[4] == to_uint32 abef.lo1 /\
hash.[5] == to_uint32 abef.lo0 /\
hash.[6] == to_uint32 cdgh.lo1 /\
hash.[7] == to_uint32 cdgh.lo0
} ) =
let a = to_uint32 abef.hi3 in
let b = to_uint32 abef.hi2 in
let c = to_uint32 cdgh.hi3 in
let d = to_uint32 cdgh.hi2 in
let e = to_uint32 abef.lo1 in
let f = to_uint32 abef.lo0 in
let g = to_uint32 cdgh.lo1 in
let h = to_uint32 cdgh.lo0 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
//assert_norm (index hash 2 == c);
hash
[@"opaque_to_smt"] let make_hash = opaque_make make_hash_def
irreducible let make_hash_reveal = opaque_revealer (`%make_hash) make_hash make_hash_def
let make_ordered_hash_def (abcd efgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abcd.lo0 /\
hash.[1] == to_uint32 abcd.lo1 /\
hash.[2] == to_uint32 abcd.hi2 /\
hash.[3] == to_uint32 abcd.hi3 /\
hash.[4] == to_uint32 efgh.lo0 /\
hash.[5] == to_uint32 efgh.lo1 /\
hash.[6] == to_uint32 efgh.hi2 /\
hash.[7] == to_uint32 efgh.hi3
})
=
let a = to_uint32 abcd.lo0 in
let b = to_uint32 abcd.lo1 in
let c = to_uint32 abcd.hi2 in
let d = to_uint32 abcd.hi3 in
let e = to_uint32 efgh.lo0 in
let f = to_uint32 efgh.lo1 in
let g = to_uint32 efgh.hi2 in
let h = to_uint32 efgh.hi3 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
hash
[@"opaque_to_smt"] let make_ordered_hash = opaque_make make_ordered_hash_def
irreducible let make_ordered_hash_reveal = opaque_revealer (`%make_ordered_hash) make_ordered_hash make_ordered_hash_def
let shuffle_core_properties (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}) :
Lemma(let h = shuffle_core_opaque block hash t in
let open Lib.IntTypes in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
h.[0] == t1 +. t2 /\
h.[1] == a0 /\
h.[2] == b0 /\
h.[3] == c0 /\
h.[4] == d0 +. t1 /\
h.[5] == e0 /\
h.[6] == f0 /\
h.[7] == g0)
=
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
let h = shuffle_core SHA2_256 block hash t in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
let l = [ t1 +. t2; a0; b0; c0; d0 +. t1; e0; f0; g0 ] in
assert (h == seq_of_list l);
elim_of_list l;
() | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | abef: Vale.Def.Types_s.quad32 -> cdgh: Vale.Def.Types_s.quad32 -> wk: FStar.UInt32.t
-> Vale.Def.Types_s.quad32 * Vale.Def.Types_s.quad32 | Prims.Tot | [
"total"
] | [] | [
"Vale.Def.Types_s.quad32",
"FStar.UInt32.t",
"Spec.Hash.Definitions.word",
"Spec.Hash.Definitions.SHA2_256",
"FStar.Pervasives.Native.Mktuple2",
"Vale.Def.Words_s.four",
"Vale.Def.Words_s.nat32",
"Vale.Def.Words_s.Mkfour",
"Vale.Def.Types_s.nat32",
"Vale.SHA.SHA_helpers.vv",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.tuple8",
"Vale.X64.CryptoInstructions_s.sha256_rnds2_spec_update",
"Spec.SHA2.op_String_Access",
"Vale.SHA.SHA_helpers.word",
"Vale.SHA.SHA_helpers.hash256",
"Vale.SHA.SHA_helpers.make_hash"
] | [] | false | false | false | true | false | let sha256_rnds2_spec_update_quad32 (abef cdgh: quad32) (wk: UInt32.t) : (quad32 & quad32) =
| let hash0 = make_hash abef cdgh in
let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash0.[ 0 ]
hash0.[ 1 ]
hash0.[ 2 ]
hash0.[ 3 ]
hash0.[ 4 ]
hash0.[ 5 ]
hash0.[ 6 ]
hash0.[ 7 ]
wk
in
let abef' = Mkfour (vv f') (vv e') (vv b') (vv a') in
let cdgh' = Mkfour (vv h') (vv g') (vv d') (vv c') in
(abef', cdgh') | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.nat8_to_byte | val nat8_to_byte (b:nat8) : byte | val nat8_to_byte (b:nat8) : byte | let nat8_to_byte = UInt8.uint_to_t | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 34,
"end_line": 58,
"start_col": 0,
"start_line": 58
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y))
let word_to_nat32 = vv
let nat32_to_word = to_uint32 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Vale.Def.Words_s.nat8 -> Vale.SHA.SHA_helpers.byte | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt8.uint_to_t"
] | [] | false | false | false | true | false | let nat8_to_byte =
| UInt8.uint_to_t | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.make_hash_reveal | val make_hash_reveal : _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.SHA.SHA_helpers.make_hash == Vale.SHA.SHA_helpers.make_hash_def) | let make_hash_reveal = opaque_revealer (`%make_hash) make_hash make_hash_def | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 88,
"end_line": 88,
"start_col": 12,
"start_line": 88
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y))
let word_to_nat32 = vv
let nat32_to_word = to_uint32
let byte_to_nat8 = UInt8.v
let nat8_to_byte = UInt8.uint_to_t
let make_hash_def (abef cdgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abef.hi3 /\
hash.[1] == to_uint32 abef.hi2 /\
hash.[2] == to_uint32 cdgh.hi3 /\
hash.[3] == to_uint32 cdgh.hi2 /\
hash.[4] == to_uint32 abef.lo1 /\
hash.[5] == to_uint32 abef.lo0 /\
hash.[6] == to_uint32 cdgh.lo1 /\
hash.[7] == to_uint32 cdgh.lo0
} ) =
let a = to_uint32 abef.hi3 in
let b = to_uint32 abef.hi2 in
let c = to_uint32 cdgh.hi3 in
let d = to_uint32 cdgh.hi2 in
let e = to_uint32 abef.lo1 in
let f = to_uint32 abef.lo0 in
let g = to_uint32 cdgh.lo1 in
let h = to_uint32 cdgh.lo0 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
//assert_norm (index hash 2 == c);
hash | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.SHA.SHA_helpers.make_hash == Vale.SHA.SHA_helpers.make_hash_def) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Opaque_s.opaque_revealer",
"Vale.Def.Types_s.quad32",
"Vale.SHA.SHA_helpers.hash256",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"Vale.SHA.SHA_helpers.word",
"Spec.SHA2.op_String_Access",
"Vale.SHA.SHA_helpers.nat32_to_word",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.SHA.SHA_helpers.make_hash",
"Vale.SHA.SHA_helpers.make_hash_def"
] | [] | true | false | true | false | false | let make_hash_reveal =
| opaque_revealer (`%make_hash) make_hash make_hash_def | false |
|
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.make_ordered_hash_reveal | val make_ordered_hash_reveal : _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.SHA.SHA_helpers.make_ordered_hash == Vale.SHA.SHA_helpers.make_ordered_hash_def) | let make_ordered_hash_reveal = opaque_revealer (`%make_ordered_hash) make_ordered_hash make_ordered_hash_def | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 120,
"end_line": 118,
"start_col": 12,
"start_line": 118
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y))
let word_to_nat32 = vv
let nat32_to_word = to_uint32
let byte_to_nat8 = UInt8.v
let nat8_to_byte = UInt8.uint_to_t
let make_hash_def (abef cdgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abef.hi3 /\
hash.[1] == to_uint32 abef.hi2 /\
hash.[2] == to_uint32 cdgh.hi3 /\
hash.[3] == to_uint32 cdgh.hi2 /\
hash.[4] == to_uint32 abef.lo1 /\
hash.[5] == to_uint32 abef.lo0 /\
hash.[6] == to_uint32 cdgh.lo1 /\
hash.[7] == to_uint32 cdgh.lo0
} ) =
let a = to_uint32 abef.hi3 in
let b = to_uint32 abef.hi2 in
let c = to_uint32 cdgh.hi3 in
let d = to_uint32 cdgh.hi2 in
let e = to_uint32 abef.lo1 in
let f = to_uint32 abef.lo0 in
let g = to_uint32 cdgh.lo1 in
let h = to_uint32 cdgh.lo0 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
//assert_norm (index hash 2 == c);
hash
[@"opaque_to_smt"] let make_hash = opaque_make make_hash_def
irreducible let make_hash_reveal = opaque_revealer (`%make_hash) make_hash make_hash_def
let make_ordered_hash_def (abcd efgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abcd.lo0 /\
hash.[1] == to_uint32 abcd.lo1 /\
hash.[2] == to_uint32 abcd.hi2 /\
hash.[3] == to_uint32 abcd.hi3 /\
hash.[4] == to_uint32 efgh.lo0 /\
hash.[5] == to_uint32 efgh.lo1 /\
hash.[6] == to_uint32 efgh.hi2 /\
hash.[7] == to_uint32 efgh.hi3
})
=
let a = to_uint32 abcd.lo0 in
let b = to_uint32 abcd.lo1 in
let c = to_uint32 abcd.hi2 in
let d = to_uint32 abcd.hi3 in
let e = to_uint32 efgh.lo0 in
let f = to_uint32 efgh.lo1 in
let g = to_uint32 efgh.hi2 in
let h = to_uint32 efgh.hi3 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
hash | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.SHA.SHA_helpers.make_ordered_hash == Vale.SHA.SHA_helpers.make_ordered_hash_def) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Opaque_s.opaque_revealer",
"Vale.Def.Types_s.quad32",
"Vale.SHA.SHA_helpers.hash256",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"Vale.SHA.SHA_helpers.word",
"Spec.SHA2.op_String_Access",
"Vale.SHA.SHA_helpers.nat32_to_word",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3",
"Vale.SHA.SHA_helpers.make_ordered_hash",
"Vale.SHA.SHA_helpers.make_ordered_hash_def"
] | [] | true | false | true | false | false | let make_ordered_hash_reveal =
| opaque_revealer (`%make_ordered_hash) make_ordered_hash make_ordered_hash_def | false |
|
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.make_hash | val make_hash (abef cdgh:quad32) : Pure (hash256)
(requires True)
(ensures fun hash ->
length hash == 8 /\
hash.[0] == nat32_to_word abef.hi3 /\
hash.[1] == nat32_to_word abef.hi2 /\
hash.[2] == nat32_to_word cdgh.hi3 /\
hash.[3] == nat32_to_word cdgh.hi2 /\
hash.[4] == nat32_to_word abef.lo1 /\
hash.[5] == nat32_to_word abef.lo0 /\
hash.[6] == nat32_to_word cdgh.lo1 /\
hash.[7] == nat32_to_word cdgh.lo0
) | val make_hash (abef cdgh:quad32) : Pure (hash256)
(requires True)
(ensures fun hash ->
length hash == 8 /\
hash.[0] == nat32_to_word abef.hi3 /\
hash.[1] == nat32_to_word abef.hi2 /\
hash.[2] == nat32_to_word cdgh.hi3 /\
hash.[3] == nat32_to_word cdgh.hi2 /\
hash.[4] == nat32_to_word abef.lo1 /\
hash.[5] == nat32_to_word abef.lo0 /\
hash.[6] == nat32_to_word cdgh.lo1 /\
hash.[7] == nat32_to_word cdgh.lo0
) | let make_hash = opaque_make make_hash_def | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 60,
"end_line": 87,
"start_col": 19,
"start_line": 87
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y))
let word_to_nat32 = vv
let nat32_to_word = to_uint32
let byte_to_nat8 = UInt8.v
let nat8_to_byte = UInt8.uint_to_t
let make_hash_def (abef cdgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abef.hi3 /\
hash.[1] == to_uint32 abef.hi2 /\
hash.[2] == to_uint32 cdgh.hi3 /\
hash.[3] == to_uint32 cdgh.hi2 /\
hash.[4] == to_uint32 abef.lo1 /\
hash.[5] == to_uint32 abef.lo0 /\
hash.[6] == to_uint32 cdgh.lo1 /\
hash.[7] == to_uint32 cdgh.lo0
} ) =
let a = to_uint32 abef.hi3 in
let b = to_uint32 abef.hi2 in
let c = to_uint32 cdgh.hi3 in
let d = to_uint32 cdgh.hi2 in
let e = to_uint32 abef.lo1 in
let f = to_uint32 abef.lo0 in
let g = to_uint32 cdgh.lo1 in
let h = to_uint32 cdgh.lo0 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
//assert_norm (index hash 2 == c); | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | abef: Vale.Def.Types_s.quad32 -> cdgh: Vale.Def.Types_s.quad32
-> Prims.Pure Vale.SHA.SHA_helpers.hash256 | Prims.Pure | [] | [] | [
"Vale.Def.Opaque_s.opaque_make",
"Vale.Def.Types_s.quad32",
"Vale.SHA.SHA_helpers.hash256",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"Vale.SHA.SHA_helpers.word",
"Spec.SHA2.op_String_Access",
"Vale.SHA.SHA_helpers.nat32_to_word",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.SHA.SHA_helpers.make_hash_def"
] | [] | false | false | false | false | false | let make_hash =
| opaque_make make_hash_def | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.make_ordered_hash | val make_ordered_hash (abcd efgh:quad32): Pure (hash256)
(requires True)
(ensures fun hash ->
length hash == 8 /\
hash.[0] == nat32_to_word abcd.lo0 /\
hash.[1] == nat32_to_word abcd.lo1 /\
hash.[2] == nat32_to_word abcd.hi2 /\
hash.[3] == nat32_to_word abcd.hi3 /\
hash.[4] == nat32_to_word efgh.lo0 /\
hash.[5] == nat32_to_word efgh.lo1 /\
hash.[6] == nat32_to_word efgh.hi2 /\
hash.[7] == nat32_to_word efgh.hi3
) | val make_ordered_hash (abcd efgh:quad32): Pure (hash256)
(requires True)
(ensures fun hash ->
length hash == 8 /\
hash.[0] == nat32_to_word abcd.lo0 /\
hash.[1] == nat32_to_word abcd.lo1 /\
hash.[2] == nat32_to_word abcd.hi2 /\
hash.[3] == nat32_to_word abcd.hi3 /\
hash.[4] == nat32_to_word efgh.lo0 /\
hash.[5] == nat32_to_word efgh.lo1 /\
hash.[6] == nat32_to_word efgh.hi2 /\
hash.[7] == nat32_to_word efgh.hi3
) | let make_ordered_hash = opaque_make make_ordered_hash_def | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 76,
"end_line": 117,
"start_col": 19,
"start_line": 117
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y))
let word_to_nat32 = vv
let nat32_to_word = to_uint32
let byte_to_nat8 = UInt8.v
let nat8_to_byte = UInt8.uint_to_t
let make_hash_def (abef cdgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abef.hi3 /\
hash.[1] == to_uint32 abef.hi2 /\
hash.[2] == to_uint32 cdgh.hi3 /\
hash.[3] == to_uint32 cdgh.hi2 /\
hash.[4] == to_uint32 abef.lo1 /\
hash.[5] == to_uint32 abef.lo0 /\
hash.[6] == to_uint32 cdgh.lo1 /\
hash.[7] == to_uint32 cdgh.lo0
} ) =
let a = to_uint32 abef.hi3 in
let b = to_uint32 abef.hi2 in
let c = to_uint32 cdgh.hi3 in
let d = to_uint32 cdgh.hi2 in
let e = to_uint32 abef.lo1 in
let f = to_uint32 abef.lo0 in
let g = to_uint32 cdgh.lo1 in
let h = to_uint32 cdgh.lo0 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
//assert_norm (index hash 2 == c);
hash
[@"opaque_to_smt"] let make_hash = opaque_make make_hash_def
irreducible let make_hash_reveal = opaque_revealer (`%make_hash) make_hash make_hash_def
let make_ordered_hash_def (abcd efgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abcd.lo0 /\
hash.[1] == to_uint32 abcd.lo1 /\
hash.[2] == to_uint32 abcd.hi2 /\
hash.[3] == to_uint32 abcd.hi3 /\
hash.[4] == to_uint32 efgh.lo0 /\
hash.[5] == to_uint32 efgh.lo1 /\
hash.[6] == to_uint32 efgh.hi2 /\
hash.[7] == to_uint32 efgh.hi3
})
=
let a = to_uint32 abcd.lo0 in
let b = to_uint32 abcd.lo1 in
let c = to_uint32 abcd.hi2 in
let d = to_uint32 abcd.hi3 in
let e = to_uint32 efgh.lo0 in
let f = to_uint32 efgh.lo1 in
let g = to_uint32 efgh.hi2 in
let h = to_uint32 efgh.hi3 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l; | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | abcd: Vale.Def.Types_s.quad32 -> efgh: Vale.Def.Types_s.quad32
-> Prims.Pure Vale.SHA.SHA_helpers.hash256 | Prims.Pure | [] | [] | [
"Vale.Def.Opaque_s.opaque_make",
"Vale.Def.Types_s.quad32",
"Vale.SHA.SHA_helpers.hash256",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"Vale.SHA.SHA_helpers.word",
"Spec.SHA2.op_String_Access",
"Vale.SHA.SHA_helpers.nat32_to_word",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3",
"Vale.SHA.SHA_helpers.make_ordered_hash_def"
] | [] | false | false | false | false | false | let make_ordered_hash =
| opaque_make make_ordered_hash_def | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers._sigma0_quad32 | val _sigma0_quad32 (q: quad32) : quad32 | val _sigma0_quad32 (q: quad32) : quad32 | let _sigma0_quad32 (q:quad32) : quad32 =
Mkfour (vv (_sigma0 SHA2_256 (to_uint32 q.lo0)))
(vv (_sigma0 SHA2_256 (to_uint32 q.lo1)))
(vv (_sigma0 SHA2_256 (to_uint32 q.hi2)))
(vv (_sigma0 SHA2_256 (to_uint32 q.hi3))) | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 414,
"start_col": 0,
"start_line": 410
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y))
let word_to_nat32 = vv
let nat32_to_word = to_uint32
let byte_to_nat8 = UInt8.v
let nat8_to_byte = UInt8.uint_to_t
let make_hash_def (abef cdgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abef.hi3 /\
hash.[1] == to_uint32 abef.hi2 /\
hash.[2] == to_uint32 cdgh.hi3 /\
hash.[3] == to_uint32 cdgh.hi2 /\
hash.[4] == to_uint32 abef.lo1 /\
hash.[5] == to_uint32 abef.lo0 /\
hash.[6] == to_uint32 cdgh.lo1 /\
hash.[7] == to_uint32 cdgh.lo0
} ) =
let a = to_uint32 abef.hi3 in
let b = to_uint32 abef.hi2 in
let c = to_uint32 cdgh.hi3 in
let d = to_uint32 cdgh.hi2 in
let e = to_uint32 abef.lo1 in
let f = to_uint32 abef.lo0 in
let g = to_uint32 cdgh.lo1 in
let h = to_uint32 cdgh.lo0 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
//assert_norm (index hash 2 == c);
hash
[@"opaque_to_smt"] let make_hash = opaque_make make_hash_def
irreducible let make_hash_reveal = opaque_revealer (`%make_hash) make_hash make_hash_def
let make_ordered_hash_def (abcd efgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abcd.lo0 /\
hash.[1] == to_uint32 abcd.lo1 /\
hash.[2] == to_uint32 abcd.hi2 /\
hash.[3] == to_uint32 abcd.hi3 /\
hash.[4] == to_uint32 efgh.lo0 /\
hash.[5] == to_uint32 efgh.lo1 /\
hash.[6] == to_uint32 efgh.hi2 /\
hash.[7] == to_uint32 efgh.hi3
})
=
let a = to_uint32 abcd.lo0 in
let b = to_uint32 abcd.lo1 in
let c = to_uint32 abcd.hi2 in
let d = to_uint32 abcd.hi3 in
let e = to_uint32 efgh.lo0 in
let f = to_uint32 efgh.lo1 in
let g = to_uint32 efgh.hi2 in
let h = to_uint32 efgh.hi3 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
hash
[@"opaque_to_smt"] let make_ordered_hash = opaque_make make_ordered_hash_def
irreducible let make_ordered_hash_reveal = opaque_revealer (`%make_ordered_hash) make_ordered_hash make_ordered_hash_def
let shuffle_core_properties (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}) :
Lemma(let h = shuffle_core_opaque block hash t in
let open Lib.IntTypes in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
h.[0] == t1 +. t2 /\
h.[1] == a0 /\
h.[2] == b0 /\
h.[3] == c0 /\
h.[4] == d0 +. t1 /\
h.[5] == e0 /\
h.[6] == f0 /\
h.[7] == g0)
=
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
let h = shuffle_core SHA2_256 block hash t in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
let l = [ t1 +. t2; a0; b0; c0; d0 +. t1; e0; f0; g0 ] in
assert (h == seq_of_list l);
elim_of_list l;
()
let sha256_rnds2_spec_update_quad32 (abef cdgh:quad32) (wk:UInt32.t) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let a', b', c', d', e', f', g', h' = sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3] hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let abef' = Mkfour (vv f') (vv e') (vv b') (vv a') in
let cdgh' = Mkfour (vv h') (vv g') (vv d') (vv c') in
(abef', cdgh')
let sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) : quad32 =
let abef', cdgh' = sha256_rnds2_spec_update_quad32 src2 src1 (to_uint32 wk.lo0) in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' (to_uint32 wk.lo1) in
abef''
let lemma_sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) :
Lemma (sha256_rnds2_spec src1 src2 wk == sha256_rnds2_spec_quad32 src1 src2 wk)
=
sha256_rnds2_spec_reveal ();
()
let lemma_add_mod_commutes (x y:UInt32.t) :
Lemma (add_mod x y == add_mod y x)
=
()
(*
let lemma_add_mod32_associates (x y z:int) :
Lemma ( ((x + y % pow2_32) + z) % pow2_32 == (x + ((y + z) % pow2_32)) % pow2_32 )
=
()
*)
let lemma_add_mod_associates_U32 (x y z:UInt32.t) :
Lemma (add_mod x (add_mod y z) == add_mod (add_mod x y) z)
=
let open Lib.IntTypes in
calc (==) {
v (x +. (y +. z));
(==) { }
(v x + (v y + v z) % pow2 32) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v x) (v y + v z) (pow2 32) }
((v x + v y) + v z) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v z) (v x + v y) (pow2 32) }
((v x + v y) % pow2 32 + v z) % pow2 32;
(==) { }
v ((x +. y) +. z);
};
v_inj (x +. (y +. z)) ((x +. y) +. z)
(*
assert_norm (pow2 32 == pow2_32);
//assert (add_mod y z == to_uint32 ((vv y + vv z) % pow2_32));
//assert (add_mod x (add_mod y z) == to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32));
lemma_add_mod32_associates (vv x) (vv y) (vv z);
//assert (to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32) ==
// to_uint32 (((vv x + vv y % pow2_32) + vv z) % pow2_32));
*)
#reset-options "--max_fuel 0 --max_ifuel 0"
let lemma_add_wrap_is_add_mod (n0 n1:nat32) :
Lemma (add_wrap n0 n1 == vv (add_mod (to_uint32 n0) (to_uint32 n1)))
=
assert_norm (pow2 32 == pow2_32);
()
let add_wrap_commutes (x y:nat32) :
Lemma(add_wrap x y == add_wrap y x)
=
()
// Walk F* through the math steps required to rearrange all of the add_mods
let lemma_add_mod_a (a b c d e f g h wk:UInt32.t) :
Lemma ( let u = add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk
(add_mod h
(add_mod (_Maj SHA2_256 a b c)
(_Sigma0 SHA2_256 a))))) in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
u == core)
=
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
lemma_add_mod_commutes (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c);
assert (t2 == add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
assert (t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
assert (core == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
// ==> add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk)
lemma_add_mod_commutes (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g);
// ==> add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk)
lemma_add_mod_associates_U32 (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)));
assert (core == add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)))));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
()
let lemma_add_mod_e (a b c d e f g h wk:UInt32.t) :
Lemma ( let u = add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk
(add_mod h
d))) in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
u == core)
=
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
// t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_commutes d t1;
// core == add_mod t1 d
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
assert (t1 == add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h);
lemma_add_mod_associates_U32 (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h d;
assert (core == add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) (add_mod h d));
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk (add_mod h d);
assert (core == add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) (add_mod wk (add_mod h d)));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d));
assert (core == add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d))));
()
let lemma_sha256_rnds2_spec_update_is_shuffle_core (hash:hash256) (wk:UInt32.t) (t:counter) (block:block_w) : Lemma
(requires t < size_k_w SHA2_256 /\ wk == to_uint32 (add_mod32 (k0 SHA2_256).[t] (ws_opaque block t)))
(ensures (let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash.[0] hash.[1] hash.[2] hash.[3]
hash.[4] hash.[5] hash.[6] hash.[7] wk in
let u = seq_of_list [a'; b'; c'; d'; e'; f'; g'; h'] in
let c = shuffle_core_opaque block hash t in
u == c))
=
let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash.[0] hash.[1] hash.[2] hash.[3]
hash.[4] hash.[5] hash.[6] hash.[7] wk in
let l:list Lib.IntTypes.uint32 = [a'; b'; c'; d'; e'; f'; g'; h'] in
let u:Seq.seq UInt32.t = seq_of_list l in
assert_norm (List.length l == 8);
let c = shuffle_core_opaque block hash t in
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
Pervasives.reveal_opaque (`%ws) ws;
shuffle_core_properties block hash t;
elim_of_list l;
Classical.forall_intro_3 lemma_add_mod_associates_U32;
lemma_add_mod_a hash.[0] hash.[1] hash.[2] hash.[3] hash.[4] hash.[5] hash.[6] hash.[7] wk;
lemma_add_mod_e hash.[0] hash.[1] hash.[2] hash.[3] hash.[4] hash.[5] hash.[6] hash.[7] wk
let sha256_rnds2_spec_update_core_quad32 (abef cdgh:quad32) (wk:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256}) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let abef' = Mkfour (vv hash1.[5]) (vv hash1.[4]) (vv hash1.[1]) (vv hash1.[0]) in
let cdgh' = Mkfour (vv hash1.[7]) (vv hash1.[6]) (vv hash1.[3]) (vv hash1.[2]) in
(abef', cdgh')
let lemma_rnds_quad32 (abef cdgh:quad32) (wk:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256}) : Lemma
(requires wk == to_uint32 (add_mod32 (k0 SHA2_256).[t] (ws_opaque block t)))
(ensures sha256_rnds2_spec_update_core_quad32 abef cdgh wk block t == sha256_rnds2_spec_update_quad32 abef cdgh wk)
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3]
hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let l = [a'; b'; c'; d'; e'; f'; g'; h'] in
elim_of_list l;
lemma_sha256_rnds2_spec_update_is_shuffle_core hash0 wk t block;
()
#push-options "--z3rlimit 30"
let lemma_rnds2_spec_quad32_is_shuffle_core_x2 (abef cdgh:quad32) (wk0 wk1:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256 - 1}) : Lemma
(requires vv wk0 == add_mod32 (k0 SHA2_256).[t] (ws_opaque block t) /\
vv wk1 == add_mod32 (k0 SHA2_256).[t+1] (ws_opaque block (t+1)))
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
hash2 == make_hash abef'' cdgh''))
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
lemma_rnds_quad32 abef cdgh wk0 block t;
lemma_rnds_quad32 abef' cdgh' wk1 block (t+1);
assert (equal (make_hash abef' cdgh') hash1);
assert (equal (make_hash abef'' cdgh'') hash2);
()
#pop-options
let sha256_rnds2_spec_update_quad32_x2_shifts (abef cdgh:quad32) (wk0 wk1:UInt32.t) :
Lemma ((let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
cdgh'' == abef))
=
()
let sha256_rnds2_spec_quad32_is_shuffle_core_x2 (abef cdgh wk:quad32) (block:block_w) (t:counter{t < size_k_w_256 - 1}) : Lemma
(requires wk.lo0 == add_mod32 (k0 SHA2_256).[t] (ws_opaque block t) /\
wk.lo1 == add_mod32 (k0 SHA2_256).[t+1] (ws_opaque block (t+1)))
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef' = sha256_rnds2_spec_quad32 cdgh abef wk in
hash2 == make_hash abef' abef))
=
lemma_rnds2_spec_quad32_is_shuffle_core_x2 abef cdgh (to_uint32 wk.lo0) (to_uint32 wk.lo1) block t;
sha256_rnds2_spec_update_quad32_x2_shifts abef cdgh (to_uint32 wk.lo0) (to_uint32 wk.lo1);
()
let lemma_sha256_rnds2_two_steps (abef cdgh xmm0:quad32) (t:counter) (block:block_w) : Lemma
(requires t + 1 < size_k_w_256 /\
xmm0.lo0 == add_wrap (vv (k0 SHA2_256).[t] ) (ws_opaque block t) /\
xmm0.lo1 == add_wrap (vv (k0 SHA2_256).[t+1]) (ws_opaque block (t+1)) )
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
hash2 == make_hash (sha256_rnds2_spec cdgh abef xmm0) abef))
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t] ) (ws_opaque block t);
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t+1]) (ws_opaque block (t+1));
sha256_rnds2_spec_quad32_is_shuffle_core_x2 abef cdgh xmm0 block t;
lemma_sha256_rnds2_spec_quad32 cdgh abef xmm0;
()
// Top-level proof for the SHA256_rnds2 instruction
let lemma_sha256_rnds2 (abef cdgh xmm0:quad32) (t:counter) (block:block_w) (hash_in:hash256) : Lemma
(requires t + 1 < size_k_w_256 /\
xmm0.lo0 == add_wrap (word_to_nat32 k.[t]) (ws_opaque block t) /\
xmm0.lo1 == add_wrap (word_to_nat32 k.[t+1]) (ws_opaque block (t+1)) /\
make_hash abef cdgh == Spec.Loops.repeat_range 0 t (shuffle_core_opaque block) hash_in
)
(ensures make_hash (sha256_rnds2_spec cdgh abef xmm0) abef ==
Spec.Loops.repeat_range 0 (t+2) (shuffle_core_opaque block) hash_in)
=
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t] ) (ws_opaque block t);
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t+1]) (ws_opaque block (t+1));
lemma_sha256_rnds2_two_steps abef cdgh xmm0 t block;
Spec.Loops.repeat_range_induction 0 (t + 1) (shuffle_core_opaque block) hash_in;
Spec.Loops.repeat_range_induction 0 (t + 2) (shuffle_core_opaque block) hash_in;
() | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | q: Vale.Def.Types_s.quad32 -> Vale.Def.Types_s.quad32 | Prims.Tot | [
"total"
] | [] | [
"Vale.Def.Types_s.quad32",
"Vale.Def.Words_s.Mkfour",
"Vale.Def.Types_s.nat32",
"Vale.SHA.SHA_helpers.vv",
"Spec.SHA2._sigma0",
"Spec.Hash.Definitions.SHA2_256",
"Vale.SHA.SHA_helpers.to_uint32",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3"
] | [] | false | false | false | true | false | let _sigma0_quad32 (q: quad32) : quad32 =
| Mkfour (vv (_sigma0 SHA2_256 (to_uint32 q.lo0)))
(vv (_sigma0 SHA2_256 (to_uint32 q.lo1)))
(vv (_sigma0 SHA2_256 (to_uint32 q.hi2)))
(vv (_sigma0 SHA2_256 (to_uint32 q.hi3))) | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.sha256_rnds2_spec_update_core_quad32 | val sha256_rnds2_spec_update_core_quad32
(abef cdgh: quad32)
(wk: UInt32.t)
(block: block_w)
(t: counter{t < size_k_w_256})
: (quad32 & quad32) | val sha256_rnds2_spec_update_core_quad32
(abef cdgh: quad32)
(wk: UInt32.t)
(block: block_w)
(t: counter{t < size_k_w_256})
: (quad32 & quad32) | let sha256_rnds2_spec_update_core_quad32 (abef cdgh:quad32) (wk:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256}) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let abef' = Mkfour (vv hash1.[5]) (vv hash1.[4]) (vv hash1.[1]) (vv hash1.[0]) in
let cdgh' = Mkfour (vv hash1.[7]) (vv hash1.[6]) (vv hash1.[3]) (vv hash1.[2]) in
(abef', cdgh') | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 16,
"end_line": 314,
"start_col": 0,
"start_line": 309
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y))
let word_to_nat32 = vv
let nat32_to_word = to_uint32
let byte_to_nat8 = UInt8.v
let nat8_to_byte = UInt8.uint_to_t
let make_hash_def (abef cdgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abef.hi3 /\
hash.[1] == to_uint32 abef.hi2 /\
hash.[2] == to_uint32 cdgh.hi3 /\
hash.[3] == to_uint32 cdgh.hi2 /\
hash.[4] == to_uint32 abef.lo1 /\
hash.[5] == to_uint32 abef.lo0 /\
hash.[6] == to_uint32 cdgh.lo1 /\
hash.[7] == to_uint32 cdgh.lo0
} ) =
let a = to_uint32 abef.hi3 in
let b = to_uint32 abef.hi2 in
let c = to_uint32 cdgh.hi3 in
let d = to_uint32 cdgh.hi2 in
let e = to_uint32 abef.lo1 in
let f = to_uint32 abef.lo0 in
let g = to_uint32 cdgh.lo1 in
let h = to_uint32 cdgh.lo0 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
//assert_norm (index hash 2 == c);
hash
[@"opaque_to_smt"] let make_hash = opaque_make make_hash_def
irreducible let make_hash_reveal = opaque_revealer (`%make_hash) make_hash make_hash_def
let make_ordered_hash_def (abcd efgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abcd.lo0 /\
hash.[1] == to_uint32 abcd.lo1 /\
hash.[2] == to_uint32 abcd.hi2 /\
hash.[3] == to_uint32 abcd.hi3 /\
hash.[4] == to_uint32 efgh.lo0 /\
hash.[5] == to_uint32 efgh.lo1 /\
hash.[6] == to_uint32 efgh.hi2 /\
hash.[7] == to_uint32 efgh.hi3
})
=
let a = to_uint32 abcd.lo0 in
let b = to_uint32 abcd.lo1 in
let c = to_uint32 abcd.hi2 in
let d = to_uint32 abcd.hi3 in
let e = to_uint32 efgh.lo0 in
let f = to_uint32 efgh.lo1 in
let g = to_uint32 efgh.hi2 in
let h = to_uint32 efgh.hi3 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
hash
[@"opaque_to_smt"] let make_ordered_hash = opaque_make make_ordered_hash_def
irreducible let make_ordered_hash_reveal = opaque_revealer (`%make_ordered_hash) make_ordered_hash make_ordered_hash_def
let shuffle_core_properties (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}) :
Lemma(let h = shuffle_core_opaque block hash t in
let open Lib.IntTypes in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
h.[0] == t1 +. t2 /\
h.[1] == a0 /\
h.[2] == b0 /\
h.[3] == c0 /\
h.[4] == d0 +. t1 /\
h.[5] == e0 /\
h.[6] == f0 /\
h.[7] == g0)
=
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
let h = shuffle_core SHA2_256 block hash t in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
let l = [ t1 +. t2; a0; b0; c0; d0 +. t1; e0; f0; g0 ] in
assert (h == seq_of_list l);
elim_of_list l;
()
let sha256_rnds2_spec_update_quad32 (abef cdgh:quad32) (wk:UInt32.t) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let a', b', c', d', e', f', g', h' = sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3] hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let abef' = Mkfour (vv f') (vv e') (vv b') (vv a') in
let cdgh' = Mkfour (vv h') (vv g') (vv d') (vv c') in
(abef', cdgh')
let sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) : quad32 =
let abef', cdgh' = sha256_rnds2_spec_update_quad32 src2 src1 (to_uint32 wk.lo0) in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' (to_uint32 wk.lo1) in
abef''
let lemma_sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) :
Lemma (sha256_rnds2_spec src1 src2 wk == sha256_rnds2_spec_quad32 src1 src2 wk)
=
sha256_rnds2_spec_reveal ();
()
let lemma_add_mod_commutes (x y:UInt32.t) :
Lemma (add_mod x y == add_mod y x)
=
()
(*
let lemma_add_mod32_associates (x y z:int) :
Lemma ( ((x + y % pow2_32) + z) % pow2_32 == (x + ((y + z) % pow2_32)) % pow2_32 )
=
()
*)
let lemma_add_mod_associates_U32 (x y z:UInt32.t) :
Lemma (add_mod x (add_mod y z) == add_mod (add_mod x y) z)
=
let open Lib.IntTypes in
calc (==) {
v (x +. (y +. z));
(==) { }
(v x + (v y + v z) % pow2 32) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v x) (v y + v z) (pow2 32) }
((v x + v y) + v z) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v z) (v x + v y) (pow2 32) }
((v x + v y) % pow2 32 + v z) % pow2 32;
(==) { }
v ((x +. y) +. z);
};
v_inj (x +. (y +. z)) ((x +. y) +. z)
(*
assert_norm (pow2 32 == pow2_32);
//assert (add_mod y z == to_uint32 ((vv y + vv z) % pow2_32));
//assert (add_mod x (add_mod y z) == to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32));
lemma_add_mod32_associates (vv x) (vv y) (vv z);
//assert (to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32) ==
// to_uint32 (((vv x + vv y % pow2_32) + vv z) % pow2_32));
*)
#reset-options "--max_fuel 0 --max_ifuel 0"
let lemma_add_wrap_is_add_mod (n0 n1:nat32) :
Lemma (add_wrap n0 n1 == vv (add_mod (to_uint32 n0) (to_uint32 n1)))
=
assert_norm (pow2 32 == pow2_32);
()
let add_wrap_commutes (x y:nat32) :
Lemma(add_wrap x y == add_wrap y x)
=
()
// Walk F* through the math steps required to rearrange all of the add_mods
let lemma_add_mod_a (a b c d e f g h wk:UInt32.t) :
Lemma ( let u = add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk
(add_mod h
(add_mod (_Maj SHA2_256 a b c)
(_Sigma0 SHA2_256 a))))) in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
u == core)
=
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
lemma_add_mod_commutes (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c);
assert (t2 == add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
assert (t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
assert (core == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
// ==> add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk)
lemma_add_mod_commutes (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g);
// ==> add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk)
lemma_add_mod_associates_U32 (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)));
assert (core == add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)))));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
()
let lemma_add_mod_e (a b c d e f g h wk:UInt32.t) :
Lemma ( let u = add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk
(add_mod h
d))) in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
u == core)
=
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
// t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_commutes d t1;
// core == add_mod t1 d
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
assert (t1 == add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h);
lemma_add_mod_associates_U32 (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h d;
assert (core == add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) (add_mod h d));
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk (add_mod h d);
assert (core == add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) (add_mod wk (add_mod h d)));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d));
assert (core == add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d))));
()
let lemma_sha256_rnds2_spec_update_is_shuffle_core (hash:hash256) (wk:UInt32.t) (t:counter) (block:block_w) : Lemma
(requires t < size_k_w SHA2_256 /\ wk == to_uint32 (add_mod32 (k0 SHA2_256).[t] (ws_opaque block t)))
(ensures (let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash.[0] hash.[1] hash.[2] hash.[3]
hash.[4] hash.[5] hash.[6] hash.[7] wk in
let u = seq_of_list [a'; b'; c'; d'; e'; f'; g'; h'] in
let c = shuffle_core_opaque block hash t in
u == c))
=
let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash.[0] hash.[1] hash.[2] hash.[3]
hash.[4] hash.[5] hash.[6] hash.[7] wk in
let l:list Lib.IntTypes.uint32 = [a'; b'; c'; d'; e'; f'; g'; h'] in
let u:Seq.seq UInt32.t = seq_of_list l in
assert_norm (List.length l == 8);
let c = shuffle_core_opaque block hash t in
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
Pervasives.reveal_opaque (`%ws) ws;
shuffle_core_properties block hash t;
elim_of_list l;
Classical.forall_intro_3 lemma_add_mod_associates_U32;
lemma_add_mod_a hash.[0] hash.[1] hash.[2] hash.[3] hash.[4] hash.[5] hash.[6] hash.[7] wk;
lemma_add_mod_e hash.[0] hash.[1] hash.[2] hash.[3] hash.[4] hash.[5] hash.[6] hash.[7] wk | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
abef: Vale.Def.Types_s.quad32 ->
cdgh: Vale.Def.Types_s.quad32 ->
wk: FStar.UInt32.t ->
block: Vale.SHA.SHA_helpers.block_w ->
t: Vale.SHA.SHA_helpers.counter{t < Vale.SHA.SHA_helpers.size_k_w_256}
-> Vale.Def.Types_s.quad32 * Vale.Def.Types_s.quad32 | Prims.Tot | [
"total"
] | [] | [
"Vale.Def.Types_s.quad32",
"FStar.UInt32.t",
"Vale.SHA.SHA_helpers.block_w",
"Vale.SHA.SHA_helpers.counter",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.SHA.SHA_helpers.size_k_w_256",
"FStar.Pervasives.Native.Mktuple2",
"Vale.Def.Words_s.four",
"Vale.Def.Words_s.nat32",
"Vale.Def.Words_s.Mkfour",
"Vale.Def.Types_s.nat32",
"Vale.SHA.SHA_helpers.vv",
"Spec.SHA2.op_String_Access",
"Vale.SHA.SHA_helpers.word",
"Vale.SHA.SHA_helpers.hash256",
"Vale.SHA.SHA_helpers.shuffle_core_opaque",
"Vale.SHA.SHA_helpers.make_hash",
"FStar.Pervasives.Native.tuple2"
] | [] | false | false | false | false | false | let sha256_rnds2_spec_update_core_quad32
(abef cdgh: quad32)
(wk: UInt32.t)
(block: block_w)
(t: counter{t < size_k_w_256})
: (quad32 & quad32) =
| let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let abef' = Mkfour (vv hash1.[ 5 ]) (vv hash1.[ 4 ]) (vv hash1.[ 1 ]) (vv hash1.[ 0 ]) in
let cdgh' = Mkfour (vv hash1.[ 7 ]) (vv hash1.[ 6 ]) (vv hash1.[ 3 ]) (vv hash1.[ 2 ]) in
(abef', cdgh') | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.make_ordered_hash_def | val make_ordered_hash_def (abcd efgh: quad32)
: (hash:
words_state SHA2_256
{ length hash == 8 /\ hash.[ 0 ] == to_uint32 abcd.lo0 /\ hash.[ 1 ] == to_uint32 abcd.lo1 /\
hash.[ 2 ] == to_uint32 abcd.hi2 /\ hash.[ 3 ] == to_uint32 abcd.hi3 /\
hash.[ 4 ] == to_uint32 efgh.lo0 /\ hash.[ 5 ] == to_uint32 efgh.lo1 /\
hash.[ 6 ] == to_uint32 efgh.hi2 /\ hash.[ 7 ] == to_uint32 efgh.hi3 }) | val make_ordered_hash_def (abcd efgh: quad32)
: (hash:
words_state SHA2_256
{ length hash == 8 /\ hash.[ 0 ] == to_uint32 abcd.lo0 /\ hash.[ 1 ] == to_uint32 abcd.lo1 /\
hash.[ 2 ] == to_uint32 abcd.hi2 /\ hash.[ 3 ] == to_uint32 abcd.hi3 /\
hash.[ 4 ] == to_uint32 efgh.lo0 /\ hash.[ 5 ] == to_uint32 efgh.lo1 /\
hash.[ 6 ] == to_uint32 efgh.hi2 /\ hash.[ 7 ] == to_uint32 efgh.hi3 }) | let make_ordered_hash_def (abcd efgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abcd.lo0 /\
hash.[1] == to_uint32 abcd.lo1 /\
hash.[2] == to_uint32 abcd.hi2 /\
hash.[3] == to_uint32 abcd.hi3 /\
hash.[4] == to_uint32 efgh.lo0 /\
hash.[5] == to_uint32 efgh.lo1 /\
hash.[6] == to_uint32 efgh.hi2 /\
hash.[7] == to_uint32 efgh.hi3
})
=
let a = to_uint32 abcd.lo0 in
let b = to_uint32 abcd.lo1 in
let c = to_uint32 abcd.hi2 in
let d = to_uint32 abcd.hi3 in
let e = to_uint32 efgh.lo0 in
let f = to_uint32 efgh.lo1 in
let g = to_uint32 efgh.hi2 in
let h = to_uint32 efgh.hi3 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
hash | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 8,
"end_line": 116,
"start_col": 0,
"start_line": 90
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y))
let word_to_nat32 = vv
let nat32_to_word = to_uint32
let byte_to_nat8 = UInt8.v
let nat8_to_byte = UInt8.uint_to_t
let make_hash_def (abef cdgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abef.hi3 /\
hash.[1] == to_uint32 abef.hi2 /\
hash.[2] == to_uint32 cdgh.hi3 /\
hash.[3] == to_uint32 cdgh.hi2 /\
hash.[4] == to_uint32 abef.lo1 /\
hash.[5] == to_uint32 abef.lo0 /\
hash.[6] == to_uint32 cdgh.lo1 /\
hash.[7] == to_uint32 cdgh.lo0
} ) =
let a = to_uint32 abef.hi3 in
let b = to_uint32 abef.hi2 in
let c = to_uint32 cdgh.hi3 in
let d = to_uint32 cdgh.hi2 in
let e = to_uint32 abef.lo1 in
let f = to_uint32 abef.lo0 in
let g = to_uint32 cdgh.lo1 in
let h = to_uint32 cdgh.lo0 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
//assert_norm (index hash 2 == c);
hash
[@"opaque_to_smt"] let make_hash = opaque_make make_hash_def
irreducible let make_hash_reveal = opaque_revealer (`%make_hash) make_hash make_hash_def | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | abcd: Vale.Def.Types_s.quad32 -> efgh: Vale.Def.Types_s.quad32
-> hash:
Spec.Hash.Definitions.words_state Spec.Hash.Definitions.SHA2_256
{ FStar.Seq.Base.length hash == 8 /\
hash.[ 0 ] == Vale.SHA.SHA_helpers.to_uint32 (Mkfour?.lo0 abcd) /\
hash.[ 1 ] == Vale.SHA.SHA_helpers.to_uint32 (Mkfour?.lo1 abcd) /\
hash.[ 2 ] == Vale.SHA.SHA_helpers.to_uint32 (Mkfour?.hi2 abcd) /\
hash.[ 3 ] == Vale.SHA.SHA_helpers.to_uint32 (Mkfour?.hi3 abcd) /\
hash.[ 4 ] == Vale.SHA.SHA_helpers.to_uint32 (Mkfour?.lo0 efgh) /\
hash.[ 5 ] == Vale.SHA.SHA_helpers.to_uint32 (Mkfour?.lo1 efgh) /\
hash.[ 6 ] == Vale.SHA.SHA_helpers.to_uint32 (Mkfour?.hi2 efgh) /\
hash.[ 7 ] == Vale.SHA.SHA_helpers.to_uint32 (Mkfour?.hi3 efgh) } | Prims.Tot | [
"total"
] | [] | [
"Vale.Def.Types_s.quad32",
"Prims.unit",
"FStar.Seq.Properties.elim_of_list",
"Spec.Hash.Definitions.word",
"Spec.Hash.Definitions.SHA2_256",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"FStar.Seq.Base.seq",
"Prims.nat",
"FStar.List.Tot.Base.length",
"FStar.Seq.Base.seq_of_list",
"FStar.Pervasives.assert_norm",
"Prims.list",
"Prims.Cons",
"Prims.Nil",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U32",
"Lib.IntTypes.SEC",
"Vale.SHA.SHA_helpers.to_uint32",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Spec.Hash.Definitions.words_state",
"Prims.l_and",
"FStar.UInt32.t",
"Spec.SHA2.op_String_Access"
] | [] | false | false | false | false | false | let make_ordered_hash_def (abcd efgh: quad32)
: (hash:
words_state SHA2_256
{ length hash == 8 /\ hash.[ 0 ] == to_uint32 abcd.lo0 /\ hash.[ 1 ] == to_uint32 abcd.lo1 /\
hash.[ 2 ] == to_uint32 abcd.hi2 /\ hash.[ 3 ] == to_uint32 abcd.hi3 /\
hash.[ 4 ] == to_uint32 efgh.lo0 /\ hash.[ 5 ] == to_uint32 efgh.lo1 /\
hash.[ 6 ] == to_uint32 efgh.hi2 /\ hash.[ 7 ] == to_uint32 efgh.hi3 }) =
| let a = to_uint32 abcd.lo0 in
let b = to_uint32 abcd.lo1 in
let c = to_uint32 abcd.hi2 in
let d = to_uint32 abcd.hi3 in
let e = to_uint32 efgh.lo0 in
let f = to_uint32 efgh.lo1 in
let g = to_uint32 efgh.hi2 in
let h = to_uint32 efgh.hi3 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
hash | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.lemma_rnds_quad32 | val lemma_rnds_quad32
(abef cdgh: quad32)
(wk: UInt32.t)
(block: block_w)
(t: counter{t < size_k_w_256})
: Lemma (requires wk == to_uint32 (add_mod32 (k0 SHA2_256).[ t ] (ws_opaque block t)))
(ensures
sha256_rnds2_spec_update_core_quad32 abef cdgh wk block t ==
sha256_rnds2_spec_update_quad32 abef cdgh wk) | val lemma_rnds_quad32
(abef cdgh: quad32)
(wk: UInt32.t)
(block: block_w)
(t: counter{t < size_k_w_256})
: Lemma (requires wk == to_uint32 (add_mod32 (k0 SHA2_256).[ t ] (ws_opaque block t)))
(ensures
sha256_rnds2_spec_update_core_quad32 abef cdgh wk block t ==
sha256_rnds2_spec_update_quad32 abef cdgh wk) | let lemma_rnds_quad32 (abef cdgh:quad32) (wk:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256}) : Lemma
(requires wk == to_uint32 (add_mod32 (k0 SHA2_256).[t] (ws_opaque block t)))
(ensures sha256_rnds2_spec_update_core_quad32 abef cdgh wk block t == sha256_rnds2_spec_update_quad32 abef cdgh wk)
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3]
hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let l = [a'; b'; c'; d'; e'; f'; g'; h'] in
elim_of_list l;
lemma_sha256_rnds2_spec_update_is_shuffle_core hash0 wk t block;
() | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 328,
"start_col": 0,
"start_line": 316
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y))
let word_to_nat32 = vv
let nat32_to_word = to_uint32
let byte_to_nat8 = UInt8.v
let nat8_to_byte = UInt8.uint_to_t
let make_hash_def (abef cdgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abef.hi3 /\
hash.[1] == to_uint32 abef.hi2 /\
hash.[2] == to_uint32 cdgh.hi3 /\
hash.[3] == to_uint32 cdgh.hi2 /\
hash.[4] == to_uint32 abef.lo1 /\
hash.[5] == to_uint32 abef.lo0 /\
hash.[6] == to_uint32 cdgh.lo1 /\
hash.[7] == to_uint32 cdgh.lo0
} ) =
let a = to_uint32 abef.hi3 in
let b = to_uint32 abef.hi2 in
let c = to_uint32 cdgh.hi3 in
let d = to_uint32 cdgh.hi2 in
let e = to_uint32 abef.lo1 in
let f = to_uint32 abef.lo0 in
let g = to_uint32 cdgh.lo1 in
let h = to_uint32 cdgh.lo0 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
//assert_norm (index hash 2 == c);
hash
[@"opaque_to_smt"] let make_hash = opaque_make make_hash_def
irreducible let make_hash_reveal = opaque_revealer (`%make_hash) make_hash make_hash_def
let make_ordered_hash_def (abcd efgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abcd.lo0 /\
hash.[1] == to_uint32 abcd.lo1 /\
hash.[2] == to_uint32 abcd.hi2 /\
hash.[3] == to_uint32 abcd.hi3 /\
hash.[4] == to_uint32 efgh.lo0 /\
hash.[5] == to_uint32 efgh.lo1 /\
hash.[6] == to_uint32 efgh.hi2 /\
hash.[7] == to_uint32 efgh.hi3
})
=
let a = to_uint32 abcd.lo0 in
let b = to_uint32 abcd.lo1 in
let c = to_uint32 abcd.hi2 in
let d = to_uint32 abcd.hi3 in
let e = to_uint32 efgh.lo0 in
let f = to_uint32 efgh.lo1 in
let g = to_uint32 efgh.hi2 in
let h = to_uint32 efgh.hi3 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
hash
[@"opaque_to_smt"] let make_ordered_hash = opaque_make make_ordered_hash_def
irreducible let make_ordered_hash_reveal = opaque_revealer (`%make_ordered_hash) make_ordered_hash make_ordered_hash_def
let shuffle_core_properties (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}) :
Lemma(let h = shuffle_core_opaque block hash t in
let open Lib.IntTypes in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
h.[0] == t1 +. t2 /\
h.[1] == a0 /\
h.[2] == b0 /\
h.[3] == c0 /\
h.[4] == d0 +. t1 /\
h.[5] == e0 /\
h.[6] == f0 /\
h.[7] == g0)
=
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
let h = shuffle_core SHA2_256 block hash t in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
let l = [ t1 +. t2; a0; b0; c0; d0 +. t1; e0; f0; g0 ] in
assert (h == seq_of_list l);
elim_of_list l;
()
let sha256_rnds2_spec_update_quad32 (abef cdgh:quad32) (wk:UInt32.t) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let a', b', c', d', e', f', g', h' = sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3] hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let abef' = Mkfour (vv f') (vv e') (vv b') (vv a') in
let cdgh' = Mkfour (vv h') (vv g') (vv d') (vv c') in
(abef', cdgh')
let sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) : quad32 =
let abef', cdgh' = sha256_rnds2_spec_update_quad32 src2 src1 (to_uint32 wk.lo0) in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' (to_uint32 wk.lo1) in
abef''
let lemma_sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) :
Lemma (sha256_rnds2_spec src1 src2 wk == sha256_rnds2_spec_quad32 src1 src2 wk)
=
sha256_rnds2_spec_reveal ();
()
let lemma_add_mod_commutes (x y:UInt32.t) :
Lemma (add_mod x y == add_mod y x)
=
()
(*
let lemma_add_mod32_associates (x y z:int) :
Lemma ( ((x + y % pow2_32) + z) % pow2_32 == (x + ((y + z) % pow2_32)) % pow2_32 )
=
()
*)
let lemma_add_mod_associates_U32 (x y z:UInt32.t) :
Lemma (add_mod x (add_mod y z) == add_mod (add_mod x y) z)
=
let open Lib.IntTypes in
calc (==) {
v (x +. (y +. z));
(==) { }
(v x + (v y + v z) % pow2 32) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v x) (v y + v z) (pow2 32) }
((v x + v y) + v z) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v z) (v x + v y) (pow2 32) }
((v x + v y) % pow2 32 + v z) % pow2 32;
(==) { }
v ((x +. y) +. z);
};
v_inj (x +. (y +. z)) ((x +. y) +. z)
(*
assert_norm (pow2 32 == pow2_32);
//assert (add_mod y z == to_uint32 ((vv y + vv z) % pow2_32));
//assert (add_mod x (add_mod y z) == to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32));
lemma_add_mod32_associates (vv x) (vv y) (vv z);
//assert (to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32) ==
// to_uint32 (((vv x + vv y % pow2_32) + vv z) % pow2_32));
*)
#reset-options "--max_fuel 0 --max_ifuel 0"
let lemma_add_wrap_is_add_mod (n0 n1:nat32) :
Lemma (add_wrap n0 n1 == vv (add_mod (to_uint32 n0) (to_uint32 n1)))
=
assert_norm (pow2 32 == pow2_32);
()
let add_wrap_commutes (x y:nat32) :
Lemma(add_wrap x y == add_wrap y x)
=
()
// Walk F* through the math steps required to rearrange all of the add_mods
let lemma_add_mod_a (a b c d e f g h wk:UInt32.t) :
Lemma ( let u = add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk
(add_mod h
(add_mod (_Maj SHA2_256 a b c)
(_Sigma0 SHA2_256 a))))) in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
u == core)
=
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
lemma_add_mod_commutes (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c);
assert (t2 == add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
assert (t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
assert (core == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
// ==> add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk)
lemma_add_mod_commutes (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g);
// ==> add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk)
lemma_add_mod_associates_U32 (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)));
assert (core == add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)))));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
()
let lemma_add_mod_e (a b c d e f g h wk:UInt32.t) :
Lemma ( let u = add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk
(add_mod h
d))) in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
u == core)
=
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
// t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_commutes d t1;
// core == add_mod t1 d
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
assert (t1 == add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h);
lemma_add_mod_associates_U32 (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h d;
assert (core == add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) (add_mod h d));
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk (add_mod h d);
assert (core == add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) (add_mod wk (add_mod h d)));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d));
assert (core == add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d))));
()
let lemma_sha256_rnds2_spec_update_is_shuffle_core (hash:hash256) (wk:UInt32.t) (t:counter) (block:block_w) : Lemma
(requires t < size_k_w SHA2_256 /\ wk == to_uint32 (add_mod32 (k0 SHA2_256).[t] (ws_opaque block t)))
(ensures (let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash.[0] hash.[1] hash.[2] hash.[3]
hash.[4] hash.[5] hash.[6] hash.[7] wk in
let u = seq_of_list [a'; b'; c'; d'; e'; f'; g'; h'] in
let c = shuffle_core_opaque block hash t in
u == c))
=
let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash.[0] hash.[1] hash.[2] hash.[3]
hash.[4] hash.[5] hash.[6] hash.[7] wk in
let l:list Lib.IntTypes.uint32 = [a'; b'; c'; d'; e'; f'; g'; h'] in
let u:Seq.seq UInt32.t = seq_of_list l in
assert_norm (List.length l == 8);
let c = shuffle_core_opaque block hash t in
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
Pervasives.reveal_opaque (`%ws) ws;
shuffle_core_properties block hash t;
elim_of_list l;
Classical.forall_intro_3 lemma_add_mod_associates_U32;
lemma_add_mod_a hash.[0] hash.[1] hash.[2] hash.[3] hash.[4] hash.[5] hash.[6] hash.[7] wk;
lemma_add_mod_e hash.[0] hash.[1] hash.[2] hash.[3] hash.[4] hash.[5] hash.[6] hash.[7] wk
let sha256_rnds2_spec_update_core_quad32 (abef cdgh:quad32) (wk:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256}) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let abef' = Mkfour (vv hash1.[5]) (vv hash1.[4]) (vv hash1.[1]) (vv hash1.[0]) in
let cdgh' = Mkfour (vv hash1.[7]) (vv hash1.[6]) (vv hash1.[3]) (vv hash1.[2]) in
(abef', cdgh') | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
abef: Vale.Def.Types_s.quad32 ->
cdgh: Vale.Def.Types_s.quad32 ->
wk: FStar.UInt32.t ->
block: Vale.SHA.SHA_helpers.block_w ->
t: Vale.SHA.SHA_helpers.counter{t < Vale.SHA.SHA_helpers.size_k_w_256}
-> FStar.Pervasives.Lemma
(requires
wk ==
Vale.SHA.SHA_helpers.to_uint32 (Vale.SHA.SHA_helpers.add_mod32 (Spec.SHA2.k0 Spec.Hash.Definitions.SHA2_256
).[ t ]
(Vale.SHA.SHA_helpers.ws_opaque block t)))
(ensures
Vale.SHA.SHA_helpers.sha256_rnds2_spec_update_core_quad32 abef cdgh wk block t ==
Vale.SHA.SHA_helpers.sha256_rnds2_spec_update_quad32 abef cdgh wk) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"FStar.UInt32.t",
"Vale.SHA.SHA_helpers.block_w",
"Vale.SHA.SHA_helpers.counter",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.SHA.SHA_helpers.size_k_w_256",
"Spec.Hash.Definitions.word",
"Spec.Hash.Definitions.SHA2_256",
"Prims.unit",
"Vale.SHA.SHA_helpers.lemma_sha256_rnds2_spec_update_is_shuffle_core",
"FStar.Seq.Properties.elim_of_list",
"Prims.list",
"Prims.Cons",
"Prims.Nil",
"FStar.Pervasives.Native.tuple8",
"Vale.X64.CryptoInstructions_s.sha256_rnds2_spec_update",
"Spec.SHA2.op_String_Access",
"Vale.SHA.SHA_helpers.word",
"Vale.SHA.SHA_helpers.hash256",
"Vale.SHA.SHA_helpers.shuffle_core_opaque",
"Vale.SHA.SHA_helpers.make_hash",
"Prims.eq2",
"Vale.SHA.SHA_helpers.to_uint32",
"Vale.SHA.SHA_helpers.add_mod32",
"Spec.SHA2.k0",
"Vale.SHA.SHA_helpers.ws_opaque",
"Prims.squash",
"FStar.Pervasives.Native.tuple2",
"Vale.SHA.SHA_helpers.sha256_rnds2_spec_update_core_quad32",
"Vale.SHA.SHA_helpers.sha256_rnds2_spec_update_quad32",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_rnds_quad32
(abef cdgh: quad32)
(wk: UInt32.t)
(block: block_w)
(t: counter{t < size_k_w_256})
: Lemma (requires wk == to_uint32 (add_mod32 (k0 SHA2_256).[ t ] (ws_opaque block t)))
(ensures
sha256_rnds2_spec_update_core_quad32 abef cdgh wk block t ==
sha256_rnds2_spec_update_quad32 abef cdgh wk) =
| let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash0.[ 0 ]
hash0.[ 1 ]
hash0.[ 2 ]
hash0.[ 3 ]
hash0.[ 4 ]
hash0.[ 5 ]
hash0.[ 6 ]
hash0.[ 7 ]
wk
in
let l = [a'; b'; c'; d'; e'; f'; g'; h'] in
elim_of_list l;
lemma_sha256_rnds2_spec_update_is_shuffle_core hash0 wk t block;
() | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.lemma_add_wrap_is_add_mod | val lemma_add_wrap_is_add_mod (n0 n1: nat32)
: Lemma (add_wrap n0 n1 == vv (add_mod (to_uint32 n0) (to_uint32 n1))) | val lemma_add_wrap_is_add_mod (n0 n1: nat32)
: Lemma (add_wrap n0 n1 == vv (add_mod (to_uint32 n0) (to_uint32 n1))) | let lemma_add_wrap_is_add_mod (n0 n1:nat32) :
Lemma (add_wrap n0 n1 == vv (add_mod (to_uint32 n0) (to_uint32 n1)))
=
assert_norm (pow2 32 == pow2_32);
() | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 221,
"start_col": 0,
"start_line": 217
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y))
let word_to_nat32 = vv
let nat32_to_word = to_uint32
let byte_to_nat8 = UInt8.v
let nat8_to_byte = UInt8.uint_to_t
let make_hash_def (abef cdgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abef.hi3 /\
hash.[1] == to_uint32 abef.hi2 /\
hash.[2] == to_uint32 cdgh.hi3 /\
hash.[3] == to_uint32 cdgh.hi2 /\
hash.[4] == to_uint32 abef.lo1 /\
hash.[5] == to_uint32 abef.lo0 /\
hash.[6] == to_uint32 cdgh.lo1 /\
hash.[7] == to_uint32 cdgh.lo0
} ) =
let a = to_uint32 abef.hi3 in
let b = to_uint32 abef.hi2 in
let c = to_uint32 cdgh.hi3 in
let d = to_uint32 cdgh.hi2 in
let e = to_uint32 abef.lo1 in
let f = to_uint32 abef.lo0 in
let g = to_uint32 cdgh.lo1 in
let h = to_uint32 cdgh.lo0 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
//assert_norm (index hash 2 == c);
hash
[@"opaque_to_smt"] let make_hash = opaque_make make_hash_def
irreducible let make_hash_reveal = opaque_revealer (`%make_hash) make_hash make_hash_def
let make_ordered_hash_def (abcd efgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abcd.lo0 /\
hash.[1] == to_uint32 abcd.lo1 /\
hash.[2] == to_uint32 abcd.hi2 /\
hash.[3] == to_uint32 abcd.hi3 /\
hash.[4] == to_uint32 efgh.lo0 /\
hash.[5] == to_uint32 efgh.lo1 /\
hash.[6] == to_uint32 efgh.hi2 /\
hash.[7] == to_uint32 efgh.hi3
})
=
let a = to_uint32 abcd.lo0 in
let b = to_uint32 abcd.lo1 in
let c = to_uint32 abcd.hi2 in
let d = to_uint32 abcd.hi3 in
let e = to_uint32 efgh.lo0 in
let f = to_uint32 efgh.lo1 in
let g = to_uint32 efgh.hi2 in
let h = to_uint32 efgh.hi3 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
hash
[@"opaque_to_smt"] let make_ordered_hash = opaque_make make_ordered_hash_def
irreducible let make_ordered_hash_reveal = opaque_revealer (`%make_ordered_hash) make_ordered_hash make_ordered_hash_def
let shuffle_core_properties (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}) :
Lemma(let h = shuffle_core_opaque block hash t in
let open Lib.IntTypes in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
h.[0] == t1 +. t2 /\
h.[1] == a0 /\
h.[2] == b0 /\
h.[3] == c0 /\
h.[4] == d0 +. t1 /\
h.[5] == e0 /\
h.[6] == f0 /\
h.[7] == g0)
=
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
let h = shuffle_core SHA2_256 block hash t in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
let l = [ t1 +. t2; a0; b0; c0; d0 +. t1; e0; f0; g0 ] in
assert (h == seq_of_list l);
elim_of_list l;
()
let sha256_rnds2_spec_update_quad32 (abef cdgh:quad32) (wk:UInt32.t) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let a', b', c', d', e', f', g', h' = sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3] hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let abef' = Mkfour (vv f') (vv e') (vv b') (vv a') in
let cdgh' = Mkfour (vv h') (vv g') (vv d') (vv c') in
(abef', cdgh')
let sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) : quad32 =
let abef', cdgh' = sha256_rnds2_spec_update_quad32 src2 src1 (to_uint32 wk.lo0) in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' (to_uint32 wk.lo1) in
abef''
let lemma_sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) :
Lemma (sha256_rnds2_spec src1 src2 wk == sha256_rnds2_spec_quad32 src1 src2 wk)
=
sha256_rnds2_spec_reveal ();
()
let lemma_add_mod_commutes (x y:UInt32.t) :
Lemma (add_mod x y == add_mod y x)
=
()
(*
let lemma_add_mod32_associates (x y z:int) :
Lemma ( ((x + y % pow2_32) + z) % pow2_32 == (x + ((y + z) % pow2_32)) % pow2_32 )
=
()
*)
let lemma_add_mod_associates_U32 (x y z:UInt32.t) :
Lemma (add_mod x (add_mod y z) == add_mod (add_mod x y) z)
=
let open Lib.IntTypes in
calc (==) {
v (x +. (y +. z));
(==) { }
(v x + (v y + v z) % pow2 32) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v x) (v y + v z) (pow2 32) }
((v x + v y) + v z) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v z) (v x + v y) (pow2 32) }
((v x + v y) % pow2 32 + v z) % pow2 32;
(==) { }
v ((x +. y) +. z);
};
v_inj (x +. (y +. z)) ((x +. y) +. z)
(*
assert_norm (pow2 32 == pow2_32);
//assert (add_mod y z == to_uint32 ((vv y + vv z) % pow2_32));
//assert (add_mod x (add_mod y z) == to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32));
lemma_add_mod32_associates (vv x) (vv y) (vv z);
//assert (to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32) ==
// to_uint32 (((vv x + vv y % pow2_32) + vv z) % pow2_32));
*)
#reset-options "--max_fuel 0 --max_ifuel 0" | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | n0: Vale.Def.Words_s.nat32 -> n1: Vale.Def.Words_s.nat32
-> FStar.Pervasives.Lemma
(ensures
Vale.Def.Types_s.add_wrap n0 n1 ==
Vale.SHA.SHA_helpers.vv (FStar.UInt32.add_mod (Vale.SHA.SHA_helpers.to_uint32 n0)
(Vale.SHA.SHA_helpers.to_uint32 n1))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Words_s.nat32",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"Prims.pow2",
"Vale.Def.Words_s.pow2_32",
"Prims.l_True",
"Prims.squash",
"Vale.Def.Words_s.natN",
"Vale.Def.Types_s.add_wrap",
"Vale.SHA.SHA_helpers.vv",
"FStar.UInt32.add_mod",
"Vale.SHA.SHA_helpers.to_uint32",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_add_wrap_is_add_mod (n0 n1: nat32)
: Lemma (add_wrap n0 n1 == vv (add_mod (to_uint32 n0) (to_uint32 n1))) =
| assert_norm (pow2 32 == pow2_32);
() | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.lemma_add_mod_e | val lemma_add_mod_e (a b c d e f g h wk: UInt32.t)
: Lemma
(let u =
add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d)))
in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
u == core) | val lemma_add_mod_e (a b c d e f g h wk: UInt32.t)
: Lemma
(let u =
add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d)))
in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
u == core) | let lemma_add_mod_e (a b c d e f g h wk:UInt32.t) :
Lemma ( let u = add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk
(add_mod h
d))) in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
u == core)
=
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
// t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_commutes d t1;
// core == add_mod t1 d
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
assert (t1 == add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h);
lemma_add_mod_associates_U32 (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h d;
assert (core == add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) (add_mod h d));
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk (add_mod h d);
assert (core == add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) (add_mod wk (add_mod h d)));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d));
assert (core == add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d))));
() | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 283,
"start_col": 0,
"start_line": 259
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y))
let word_to_nat32 = vv
let nat32_to_word = to_uint32
let byte_to_nat8 = UInt8.v
let nat8_to_byte = UInt8.uint_to_t
let make_hash_def (abef cdgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abef.hi3 /\
hash.[1] == to_uint32 abef.hi2 /\
hash.[2] == to_uint32 cdgh.hi3 /\
hash.[3] == to_uint32 cdgh.hi2 /\
hash.[4] == to_uint32 abef.lo1 /\
hash.[5] == to_uint32 abef.lo0 /\
hash.[6] == to_uint32 cdgh.lo1 /\
hash.[7] == to_uint32 cdgh.lo0
} ) =
let a = to_uint32 abef.hi3 in
let b = to_uint32 abef.hi2 in
let c = to_uint32 cdgh.hi3 in
let d = to_uint32 cdgh.hi2 in
let e = to_uint32 abef.lo1 in
let f = to_uint32 abef.lo0 in
let g = to_uint32 cdgh.lo1 in
let h = to_uint32 cdgh.lo0 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
//assert_norm (index hash 2 == c);
hash
[@"opaque_to_smt"] let make_hash = opaque_make make_hash_def
irreducible let make_hash_reveal = opaque_revealer (`%make_hash) make_hash make_hash_def
let make_ordered_hash_def (abcd efgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abcd.lo0 /\
hash.[1] == to_uint32 abcd.lo1 /\
hash.[2] == to_uint32 abcd.hi2 /\
hash.[3] == to_uint32 abcd.hi3 /\
hash.[4] == to_uint32 efgh.lo0 /\
hash.[5] == to_uint32 efgh.lo1 /\
hash.[6] == to_uint32 efgh.hi2 /\
hash.[7] == to_uint32 efgh.hi3
})
=
let a = to_uint32 abcd.lo0 in
let b = to_uint32 abcd.lo1 in
let c = to_uint32 abcd.hi2 in
let d = to_uint32 abcd.hi3 in
let e = to_uint32 efgh.lo0 in
let f = to_uint32 efgh.lo1 in
let g = to_uint32 efgh.hi2 in
let h = to_uint32 efgh.hi3 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
hash
[@"opaque_to_smt"] let make_ordered_hash = opaque_make make_ordered_hash_def
irreducible let make_ordered_hash_reveal = opaque_revealer (`%make_ordered_hash) make_ordered_hash make_ordered_hash_def
let shuffle_core_properties (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}) :
Lemma(let h = shuffle_core_opaque block hash t in
let open Lib.IntTypes in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
h.[0] == t1 +. t2 /\
h.[1] == a0 /\
h.[2] == b0 /\
h.[3] == c0 /\
h.[4] == d0 +. t1 /\
h.[5] == e0 /\
h.[6] == f0 /\
h.[7] == g0)
=
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
let h = shuffle_core SHA2_256 block hash t in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
let l = [ t1 +. t2; a0; b0; c0; d0 +. t1; e0; f0; g0 ] in
assert (h == seq_of_list l);
elim_of_list l;
()
let sha256_rnds2_spec_update_quad32 (abef cdgh:quad32) (wk:UInt32.t) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let a', b', c', d', e', f', g', h' = sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3] hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let abef' = Mkfour (vv f') (vv e') (vv b') (vv a') in
let cdgh' = Mkfour (vv h') (vv g') (vv d') (vv c') in
(abef', cdgh')
let sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) : quad32 =
let abef', cdgh' = sha256_rnds2_spec_update_quad32 src2 src1 (to_uint32 wk.lo0) in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' (to_uint32 wk.lo1) in
abef''
let lemma_sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) :
Lemma (sha256_rnds2_spec src1 src2 wk == sha256_rnds2_spec_quad32 src1 src2 wk)
=
sha256_rnds2_spec_reveal ();
()
let lemma_add_mod_commutes (x y:UInt32.t) :
Lemma (add_mod x y == add_mod y x)
=
()
(*
let lemma_add_mod32_associates (x y z:int) :
Lemma ( ((x + y % pow2_32) + z) % pow2_32 == (x + ((y + z) % pow2_32)) % pow2_32 )
=
()
*)
let lemma_add_mod_associates_U32 (x y z:UInt32.t) :
Lemma (add_mod x (add_mod y z) == add_mod (add_mod x y) z)
=
let open Lib.IntTypes in
calc (==) {
v (x +. (y +. z));
(==) { }
(v x + (v y + v z) % pow2 32) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v x) (v y + v z) (pow2 32) }
((v x + v y) + v z) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v z) (v x + v y) (pow2 32) }
((v x + v y) % pow2 32 + v z) % pow2 32;
(==) { }
v ((x +. y) +. z);
};
v_inj (x +. (y +. z)) ((x +. y) +. z)
(*
assert_norm (pow2 32 == pow2_32);
//assert (add_mod y z == to_uint32 ((vv y + vv z) % pow2_32));
//assert (add_mod x (add_mod y z) == to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32));
lemma_add_mod32_associates (vv x) (vv y) (vv z);
//assert (to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32) ==
// to_uint32 (((vv x + vv y % pow2_32) + vv z) % pow2_32));
*)
#reset-options "--max_fuel 0 --max_ifuel 0"
let lemma_add_wrap_is_add_mod (n0 n1:nat32) :
Lemma (add_wrap n0 n1 == vv (add_mod (to_uint32 n0) (to_uint32 n1)))
=
assert_norm (pow2 32 == pow2_32);
()
let add_wrap_commutes (x y:nat32) :
Lemma(add_wrap x y == add_wrap y x)
=
()
// Walk F* through the math steps required to rearrange all of the add_mods
let lemma_add_mod_a (a b c d e f g h wk:UInt32.t) :
Lemma ( let u = add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk
(add_mod h
(add_mod (_Maj SHA2_256 a b c)
(_Sigma0 SHA2_256 a))))) in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
u == core)
=
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
lemma_add_mod_commutes (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c);
assert (t2 == add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
assert (t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
assert (core == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
// ==> add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk)
lemma_add_mod_commutes (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g);
// ==> add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk)
lemma_add_mod_associates_U32 (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)));
assert (core == add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)))));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
() | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: FStar.UInt32.t ->
b: FStar.UInt32.t ->
c: FStar.UInt32.t ->
d: FStar.UInt32.t ->
e: FStar.UInt32.t ->
f: FStar.UInt32.t ->
g: FStar.UInt32.t ->
h: FStar.UInt32.t ->
wk: FStar.UInt32.t
-> FStar.Pervasives.Lemma
(ensures
(let u254 =
FStar.UInt32.add_mod (Spec.SHA2._Ch Spec.Hash.Definitions.SHA2_256 e f g)
(FStar.UInt32.add_mod (Spec.SHA2._Sigma1 Spec.Hash.Definitions.SHA2_256 e)
(FStar.UInt32.add_mod wk (FStar.UInt32.add_mod h d)))
in
let t1 =
FStar.UInt32.add_mod h
(FStar.UInt32.add_mod (Spec.SHA2._Sigma1 Spec.Hash.Definitions.SHA2_256 e)
(FStar.UInt32.add_mod (Spec.SHA2._Ch Spec.Hash.Definitions.SHA2_256 e f g) wk))
in
let core = FStar.UInt32.add_mod d t1 in
u254 == core)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.UInt32.t",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"FStar.UInt32.add_mod",
"Spec.SHA2._Ch",
"Spec.Hash.Definitions.SHA2_256",
"Spec.SHA2._Sigma1",
"Vale.SHA.SHA_helpers.lemma_add_mod_associates_U32",
"Vale.SHA.SHA_helpers.lemma_add_mod_commutes",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_add_mod_e (a b c d e f g h wk: UInt32.t)
: Lemma
(let u =
add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d)))
in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
u == core) =
| let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
lemma_add_mod_commutes d t1;
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
assert (t1 == add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h);
lemma_add_mod_associates_U32 (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h d;
assert (core ==
add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) (add_mod h d));
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk (add_mod h d);
assert (core ==
add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) (add_mod wk (add_mod h d)));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d));
assert (core ==
add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d))));
() | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers._sigma1_quad32 | val _sigma1_quad32 (q: quad32) : quad32 | val _sigma1_quad32 (q: quad32) : quad32 | let _sigma1_quad32 (q:quad32) : quad32 =
Mkfour (vv (_sigma1 SHA2_256 (to_uint32 q.lo0)))
(vv (_sigma1 SHA2_256 (to_uint32 q.lo1)))
(vv (_sigma1 SHA2_256 (to_uint32 q.hi2)))
(vv (_sigma1 SHA2_256 (to_uint32 q.hi3))) | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 420,
"start_col": 0,
"start_line": 416
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y))
let word_to_nat32 = vv
let nat32_to_word = to_uint32
let byte_to_nat8 = UInt8.v
let nat8_to_byte = UInt8.uint_to_t
let make_hash_def (abef cdgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abef.hi3 /\
hash.[1] == to_uint32 abef.hi2 /\
hash.[2] == to_uint32 cdgh.hi3 /\
hash.[3] == to_uint32 cdgh.hi2 /\
hash.[4] == to_uint32 abef.lo1 /\
hash.[5] == to_uint32 abef.lo0 /\
hash.[6] == to_uint32 cdgh.lo1 /\
hash.[7] == to_uint32 cdgh.lo0
} ) =
let a = to_uint32 abef.hi3 in
let b = to_uint32 abef.hi2 in
let c = to_uint32 cdgh.hi3 in
let d = to_uint32 cdgh.hi2 in
let e = to_uint32 abef.lo1 in
let f = to_uint32 abef.lo0 in
let g = to_uint32 cdgh.lo1 in
let h = to_uint32 cdgh.lo0 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
//assert_norm (index hash 2 == c);
hash
[@"opaque_to_smt"] let make_hash = opaque_make make_hash_def
irreducible let make_hash_reveal = opaque_revealer (`%make_hash) make_hash make_hash_def
let make_ordered_hash_def (abcd efgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abcd.lo0 /\
hash.[1] == to_uint32 abcd.lo1 /\
hash.[2] == to_uint32 abcd.hi2 /\
hash.[3] == to_uint32 abcd.hi3 /\
hash.[4] == to_uint32 efgh.lo0 /\
hash.[5] == to_uint32 efgh.lo1 /\
hash.[6] == to_uint32 efgh.hi2 /\
hash.[7] == to_uint32 efgh.hi3
})
=
let a = to_uint32 abcd.lo0 in
let b = to_uint32 abcd.lo1 in
let c = to_uint32 abcd.hi2 in
let d = to_uint32 abcd.hi3 in
let e = to_uint32 efgh.lo0 in
let f = to_uint32 efgh.lo1 in
let g = to_uint32 efgh.hi2 in
let h = to_uint32 efgh.hi3 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
hash
[@"opaque_to_smt"] let make_ordered_hash = opaque_make make_ordered_hash_def
irreducible let make_ordered_hash_reveal = opaque_revealer (`%make_ordered_hash) make_ordered_hash make_ordered_hash_def
let shuffle_core_properties (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}) :
Lemma(let h = shuffle_core_opaque block hash t in
let open Lib.IntTypes in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
h.[0] == t1 +. t2 /\
h.[1] == a0 /\
h.[2] == b0 /\
h.[3] == c0 /\
h.[4] == d0 +. t1 /\
h.[5] == e0 /\
h.[6] == f0 /\
h.[7] == g0)
=
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
let h = shuffle_core SHA2_256 block hash t in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
let l = [ t1 +. t2; a0; b0; c0; d0 +. t1; e0; f0; g0 ] in
assert (h == seq_of_list l);
elim_of_list l;
()
let sha256_rnds2_spec_update_quad32 (abef cdgh:quad32) (wk:UInt32.t) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let a', b', c', d', e', f', g', h' = sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3] hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let abef' = Mkfour (vv f') (vv e') (vv b') (vv a') in
let cdgh' = Mkfour (vv h') (vv g') (vv d') (vv c') in
(abef', cdgh')
let sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) : quad32 =
let abef', cdgh' = sha256_rnds2_spec_update_quad32 src2 src1 (to_uint32 wk.lo0) in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' (to_uint32 wk.lo1) in
abef''
let lemma_sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) :
Lemma (sha256_rnds2_spec src1 src2 wk == sha256_rnds2_spec_quad32 src1 src2 wk)
=
sha256_rnds2_spec_reveal ();
()
let lemma_add_mod_commutes (x y:UInt32.t) :
Lemma (add_mod x y == add_mod y x)
=
()
(*
let lemma_add_mod32_associates (x y z:int) :
Lemma ( ((x + y % pow2_32) + z) % pow2_32 == (x + ((y + z) % pow2_32)) % pow2_32 )
=
()
*)
let lemma_add_mod_associates_U32 (x y z:UInt32.t) :
Lemma (add_mod x (add_mod y z) == add_mod (add_mod x y) z)
=
let open Lib.IntTypes in
calc (==) {
v (x +. (y +. z));
(==) { }
(v x + (v y + v z) % pow2 32) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v x) (v y + v z) (pow2 32) }
((v x + v y) + v z) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v z) (v x + v y) (pow2 32) }
((v x + v y) % pow2 32 + v z) % pow2 32;
(==) { }
v ((x +. y) +. z);
};
v_inj (x +. (y +. z)) ((x +. y) +. z)
(*
assert_norm (pow2 32 == pow2_32);
//assert (add_mod y z == to_uint32 ((vv y + vv z) % pow2_32));
//assert (add_mod x (add_mod y z) == to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32));
lemma_add_mod32_associates (vv x) (vv y) (vv z);
//assert (to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32) ==
// to_uint32 (((vv x + vv y % pow2_32) + vv z) % pow2_32));
*)
#reset-options "--max_fuel 0 --max_ifuel 0"
let lemma_add_wrap_is_add_mod (n0 n1:nat32) :
Lemma (add_wrap n0 n1 == vv (add_mod (to_uint32 n0) (to_uint32 n1)))
=
assert_norm (pow2 32 == pow2_32);
()
let add_wrap_commutes (x y:nat32) :
Lemma(add_wrap x y == add_wrap y x)
=
()
// Walk F* through the math steps required to rearrange all of the add_mods
let lemma_add_mod_a (a b c d e f g h wk:UInt32.t) :
Lemma ( let u = add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk
(add_mod h
(add_mod (_Maj SHA2_256 a b c)
(_Sigma0 SHA2_256 a))))) in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
u == core)
=
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
lemma_add_mod_commutes (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c);
assert (t2 == add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
assert (t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
assert (core == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
// ==> add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk)
lemma_add_mod_commutes (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g);
// ==> add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk)
lemma_add_mod_associates_U32 (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)));
assert (core == add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)))));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
()
let lemma_add_mod_e (a b c d e f g h wk:UInt32.t) :
Lemma ( let u = add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk
(add_mod h
d))) in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
u == core)
=
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
// t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_commutes d t1;
// core == add_mod t1 d
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
assert (t1 == add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h);
lemma_add_mod_associates_U32 (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h d;
assert (core == add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) (add_mod h d));
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk (add_mod h d);
assert (core == add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) (add_mod wk (add_mod h d)));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d));
assert (core == add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d))));
()
let lemma_sha256_rnds2_spec_update_is_shuffle_core (hash:hash256) (wk:UInt32.t) (t:counter) (block:block_w) : Lemma
(requires t < size_k_w SHA2_256 /\ wk == to_uint32 (add_mod32 (k0 SHA2_256).[t] (ws_opaque block t)))
(ensures (let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash.[0] hash.[1] hash.[2] hash.[3]
hash.[4] hash.[5] hash.[6] hash.[7] wk in
let u = seq_of_list [a'; b'; c'; d'; e'; f'; g'; h'] in
let c = shuffle_core_opaque block hash t in
u == c))
=
let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash.[0] hash.[1] hash.[2] hash.[3]
hash.[4] hash.[5] hash.[6] hash.[7] wk in
let l:list Lib.IntTypes.uint32 = [a'; b'; c'; d'; e'; f'; g'; h'] in
let u:Seq.seq UInt32.t = seq_of_list l in
assert_norm (List.length l == 8);
let c = shuffle_core_opaque block hash t in
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
Pervasives.reveal_opaque (`%ws) ws;
shuffle_core_properties block hash t;
elim_of_list l;
Classical.forall_intro_3 lemma_add_mod_associates_U32;
lemma_add_mod_a hash.[0] hash.[1] hash.[2] hash.[3] hash.[4] hash.[5] hash.[6] hash.[7] wk;
lemma_add_mod_e hash.[0] hash.[1] hash.[2] hash.[3] hash.[4] hash.[5] hash.[6] hash.[7] wk
let sha256_rnds2_spec_update_core_quad32 (abef cdgh:quad32) (wk:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256}) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let abef' = Mkfour (vv hash1.[5]) (vv hash1.[4]) (vv hash1.[1]) (vv hash1.[0]) in
let cdgh' = Mkfour (vv hash1.[7]) (vv hash1.[6]) (vv hash1.[3]) (vv hash1.[2]) in
(abef', cdgh')
let lemma_rnds_quad32 (abef cdgh:quad32) (wk:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256}) : Lemma
(requires wk == to_uint32 (add_mod32 (k0 SHA2_256).[t] (ws_opaque block t)))
(ensures sha256_rnds2_spec_update_core_quad32 abef cdgh wk block t == sha256_rnds2_spec_update_quad32 abef cdgh wk)
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3]
hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let l = [a'; b'; c'; d'; e'; f'; g'; h'] in
elim_of_list l;
lemma_sha256_rnds2_spec_update_is_shuffle_core hash0 wk t block;
()
#push-options "--z3rlimit 30"
let lemma_rnds2_spec_quad32_is_shuffle_core_x2 (abef cdgh:quad32) (wk0 wk1:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256 - 1}) : Lemma
(requires vv wk0 == add_mod32 (k0 SHA2_256).[t] (ws_opaque block t) /\
vv wk1 == add_mod32 (k0 SHA2_256).[t+1] (ws_opaque block (t+1)))
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
hash2 == make_hash abef'' cdgh''))
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
lemma_rnds_quad32 abef cdgh wk0 block t;
lemma_rnds_quad32 abef' cdgh' wk1 block (t+1);
assert (equal (make_hash abef' cdgh') hash1);
assert (equal (make_hash abef'' cdgh'') hash2);
()
#pop-options
let sha256_rnds2_spec_update_quad32_x2_shifts (abef cdgh:quad32) (wk0 wk1:UInt32.t) :
Lemma ((let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
cdgh'' == abef))
=
()
let sha256_rnds2_spec_quad32_is_shuffle_core_x2 (abef cdgh wk:quad32) (block:block_w) (t:counter{t < size_k_w_256 - 1}) : Lemma
(requires wk.lo0 == add_mod32 (k0 SHA2_256).[t] (ws_opaque block t) /\
wk.lo1 == add_mod32 (k0 SHA2_256).[t+1] (ws_opaque block (t+1)))
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef' = sha256_rnds2_spec_quad32 cdgh abef wk in
hash2 == make_hash abef' abef))
=
lemma_rnds2_spec_quad32_is_shuffle_core_x2 abef cdgh (to_uint32 wk.lo0) (to_uint32 wk.lo1) block t;
sha256_rnds2_spec_update_quad32_x2_shifts abef cdgh (to_uint32 wk.lo0) (to_uint32 wk.lo1);
()
let lemma_sha256_rnds2_two_steps (abef cdgh xmm0:quad32) (t:counter) (block:block_w) : Lemma
(requires t + 1 < size_k_w_256 /\
xmm0.lo0 == add_wrap (vv (k0 SHA2_256).[t] ) (ws_opaque block t) /\
xmm0.lo1 == add_wrap (vv (k0 SHA2_256).[t+1]) (ws_opaque block (t+1)) )
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
hash2 == make_hash (sha256_rnds2_spec cdgh abef xmm0) abef))
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t] ) (ws_opaque block t);
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t+1]) (ws_opaque block (t+1));
sha256_rnds2_spec_quad32_is_shuffle_core_x2 abef cdgh xmm0 block t;
lemma_sha256_rnds2_spec_quad32 cdgh abef xmm0;
()
// Top-level proof for the SHA256_rnds2 instruction
let lemma_sha256_rnds2 (abef cdgh xmm0:quad32) (t:counter) (block:block_w) (hash_in:hash256) : Lemma
(requires t + 1 < size_k_w_256 /\
xmm0.lo0 == add_wrap (word_to_nat32 k.[t]) (ws_opaque block t) /\
xmm0.lo1 == add_wrap (word_to_nat32 k.[t+1]) (ws_opaque block (t+1)) /\
make_hash abef cdgh == Spec.Loops.repeat_range 0 t (shuffle_core_opaque block) hash_in
)
(ensures make_hash (sha256_rnds2_spec cdgh abef xmm0) abef ==
Spec.Loops.repeat_range 0 (t+2) (shuffle_core_opaque block) hash_in)
=
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t] ) (ws_opaque block t);
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t+1]) (ws_opaque block (t+1));
lemma_sha256_rnds2_two_steps abef cdgh xmm0 t block;
Spec.Loops.repeat_range_induction 0 (t + 1) (shuffle_core_opaque block) hash_in;
Spec.Loops.repeat_range_induction 0 (t + 2) (shuffle_core_opaque block) hash_in;
()
(* Proof work for the SHA256_msg* instructions *)
let _sigma0_quad32 (q:quad32) : quad32 =
Mkfour (vv (_sigma0 SHA2_256 (to_uint32 q.lo0)))
(vv (_sigma0 SHA2_256 (to_uint32 q.lo1)))
(vv (_sigma0 SHA2_256 (to_uint32 q.hi2)))
(vv (_sigma0 SHA2_256 (to_uint32 q.hi3))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | q: Vale.Def.Types_s.quad32 -> Vale.Def.Types_s.quad32 | Prims.Tot | [
"total"
] | [] | [
"Vale.Def.Types_s.quad32",
"Vale.Def.Words_s.Mkfour",
"Vale.Def.Types_s.nat32",
"Vale.SHA.SHA_helpers.vv",
"Spec.SHA2._sigma1",
"Spec.Hash.Definitions.SHA2_256",
"Vale.SHA.SHA_helpers.to_uint32",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3"
] | [] | false | false | false | true | false | let _sigma1_quad32 (q: quad32) : quad32 =
| Mkfour (vv (_sigma1 SHA2_256 (to_uint32 q.lo0)))
(vv (_sigma1 SHA2_256 (to_uint32 q.lo1)))
(vv (_sigma1 SHA2_256 (to_uint32 q.hi2)))
(vv (_sigma1 SHA2_256 (to_uint32 q.hi3))) | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.ws_partial_def | val ws_partial_def (t:counter) (block:block_w) : quad32 | val ws_partial_def (t:counter) (block:block_w) : quad32 | let ws_partial_def (t:counter) (block:block_w) : quad32 =
if 16 <= t && t < size_k_w_256 then
(let init = ws_quad32 (t-16) block in
let sigma0_in = ws_quad32 (t-15) block in
let sigma0_out = _sigma0_quad32 sigma0_in in
add_wrap_quad32 init sigma0_out)
else
Mkfour 0 0 0 0 | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 21,
"end_line": 429,
"start_col": 0,
"start_line": 422
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y))
let word_to_nat32 = vv
let nat32_to_word = to_uint32
let byte_to_nat8 = UInt8.v
let nat8_to_byte = UInt8.uint_to_t
let make_hash_def (abef cdgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abef.hi3 /\
hash.[1] == to_uint32 abef.hi2 /\
hash.[2] == to_uint32 cdgh.hi3 /\
hash.[3] == to_uint32 cdgh.hi2 /\
hash.[4] == to_uint32 abef.lo1 /\
hash.[5] == to_uint32 abef.lo0 /\
hash.[6] == to_uint32 cdgh.lo1 /\
hash.[7] == to_uint32 cdgh.lo0
} ) =
let a = to_uint32 abef.hi3 in
let b = to_uint32 abef.hi2 in
let c = to_uint32 cdgh.hi3 in
let d = to_uint32 cdgh.hi2 in
let e = to_uint32 abef.lo1 in
let f = to_uint32 abef.lo0 in
let g = to_uint32 cdgh.lo1 in
let h = to_uint32 cdgh.lo0 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
//assert_norm (index hash 2 == c);
hash
[@"opaque_to_smt"] let make_hash = opaque_make make_hash_def
irreducible let make_hash_reveal = opaque_revealer (`%make_hash) make_hash make_hash_def
let make_ordered_hash_def (abcd efgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abcd.lo0 /\
hash.[1] == to_uint32 abcd.lo1 /\
hash.[2] == to_uint32 abcd.hi2 /\
hash.[3] == to_uint32 abcd.hi3 /\
hash.[4] == to_uint32 efgh.lo0 /\
hash.[5] == to_uint32 efgh.lo1 /\
hash.[6] == to_uint32 efgh.hi2 /\
hash.[7] == to_uint32 efgh.hi3
})
=
let a = to_uint32 abcd.lo0 in
let b = to_uint32 abcd.lo1 in
let c = to_uint32 abcd.hi2 in
let d = to_uint32 abcd.hi3 in
let e = to_uint32 efgh.lo0 in
let f = to_uint32 efgh.lo1 in
let g = to_uint32 efgh.hi2 in
let h = to_uint32 efgh.hi3 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
hash
[@"opaque_to_smt"] let make_ordered_hash = opaque_make make_ordered_hash_def
irreducible let make_ordered_hash_reveal = opaque_revealer (`%make_ordered_hash) make_ordered_hash make_ordered_hash_def
let shuffle_core_properties (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}) :
Lemma(let h = shuffle_core_opaque block hash t in
let open Lib.IntTypes in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
h.[0] == t1 +. t2 /\
h.[1] == a0 /\
h.[2] == b0 /\
h.[3] == c0 /\
h.[4] == d0 +. t1 /\
h.[5] == e0 /\
h.[6] == f0 /\
h.[7] == g0)
=
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
let h = shuffle_core SHA2_256 block hash t in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
let l = [ t1 +. t2; a0; b0; c0; d0 +. t1; e0; f0; g0 ] in
assert (h == seq_of_list l);
elim_of_list l;
()
let sha256_rnds2_spec_update_quad32 (abef cdgh:quad32) (wk:UInt32.t) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let a', b', c', d', e', f', g', h' = sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3] hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let abef' = Mkfour (vv f') (vv e') (vv b') (vv a') in
let cdgh' = Mkfour (vv h') (vv g') (vv d') (vv c') in
(abef', cdgh')
let sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) : quad32 =
let abef', cdgh' = sha256_rnds2_spec_update_quad32 src2 src1 (to_uint32 wk.lo0) in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' (to_uint32 wk.lo1) in
abef''
let lemma_sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) :
Lemma (sha256_rnds2_spec src1 src2 wk == sha256_rnds2_spec_quad32 src1 src2 wk)
=
sha256_rnds2_spec_reveal ();
()
let lemma_add_mod_commutes (x y:UInt32.t) :
Lemma (add_mod x y == add_mod y x)
=
()
(*
let lemma_add_mod32_associates (x y z:int) :
Lemma ( ((x + y % pow2_32) + z) % pow2_32 == (x + ((y + z) % pow2_32)) % pow2_32 )
=
()
*)
let lemma_add_mod_associates_U32 (x y z:UInt32.t) :
Lemma (add_mod x (add_mod y z) == add_mod (add_mod x y) z)
=
let open Lib.IntTypes in
calc (==) {
v (x +. (y +. z));
(==) { }
(v x + (v y + v z) % pow2 32) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v x) (v y + v z) (pow2 32) }
((v x + v y) + v z) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v z) (v x + v y) (pow2 32) }
((v x + v y) % pow2 32 + v z) % pow2 32;
(==) { }
v ((x +. y) +. z);
};
v_inj (x +. (y +. z)) ((x +. y) +. z)
(*
assert_norm (pow2 32 == pow2_32);
//assert (add_mod y z == to_uint32 ((vv y + vv z) % pow2_32));
//assert (add_mod x (add_mod y z) == to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32));
lemma_add_mod32_associates (vv x) (vv y) (vv z);
//assert (to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32) ==
// to_uint32 (((vv x + vv y % pow2_32) + vv z) % pow2_32));
*)
#reset-options "--max_fuel 0 --max_ifuel 0"
let lemma_add_wrap_is_add_mod (n0 n1:nat32) :
Lemma (add_wrap n0 n1 == vv (add_mod (to_uint32 n0) (to_uint32 n1)))
=
assert_norm (pow2 32 == pow2_32);
()
let add_wrap_commutes (x y:nat32) :
Lemma(add_wrap x y == add_wrap y x)
=
()
// Walk F* through the math steps required to rearrange all of the add_mods
let lemma_add_mod_a (a b c d e f g h wk:UInt32.t) :
Lemma ( let u = add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk
(add_mod h
(add_mod (_Maj SHA2_256 a b c)
(_Sigma0 SHA2_256 a))))) in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
u == core)
=
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
lemma_add_mod_commutes (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c);
assert (t2 == add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
assert (t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
assert (core == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
// ==> add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk)
lemma_add_mod_commutes (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g);
// ==> add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk)
lemma_add_mod_associates_U32 (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)));
assert (core == add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)))));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
()
let lemma_add_mod_e (a b c d e f g h wk:UInt32.t) :
Lemma ( let u = add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk
(add_mod h
d))) in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
u == core)
=
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
// t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_commutes d t1;
// core == add_mod t1 d
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
assert (t1 == add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h);
lemma_add_mod_associates_U32 (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h d;
assert (core == add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) (add_mod h d));
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk (add_mod h d);
assert (core == add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) (add_mod wk (add_mod h d)));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d));
assert (core == add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d))));
()
let lemma_sha256_rnds2_spec_update_is_shuffle_core (hash:hash256) (wk:UInt32.t) (t:counter) (block:block_w) : Lemma
(requires t < size_k_w SHA2_256 /\ wk == to_uint32 (add_mod32 (k0 SHA2_256).[t] (ws_opaque block t)))
(ensures (let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash.[0] hash.[1] hash.[2] hash.[3]
hash.[4] hash.[5] hash.[6] hash.[7] wk in
let u = seq_of_list [a'; b'; c'; d'; e'; f'; g'; h'] in
let c = shuffle_core_opaque block hash t in
u == c))
=
let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash.[0] hash.[1] hash.[2] hash.[3]
hash.[4] hash.[5] hash.[6] hash.[7] wk in
let l:list Lib.IntTypes.uint32 = [a'; b'; c'; d'; e'; f'; g'; h'] in
let u:Seq.seq UInt32.t = seq_of_list l in
assert_norm (List.length l == 8);
let c = shuffle_core_opaque block hash t in
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
Pervasives.reveal_opaque (`%ws) ws;
shuffle_core_properties block hash t;
elim_of_list l;
Classical.forall_intro_3 lemma_add_mod_associates_U32;
lemma_add_mod_a hash.[0] hash.[1] hash.[2] hash.[3] hash.[4] hash.[5] hash.[6] hash.[7] wk;
lemma_add_mod_e hash.[0] hash.[1] hash.[2] hash.[3] hash.[4] hash.[5] hash.[6] hash.[7] wk
let sha256_rnds2_spec_update_core_quad32 (abef cdgh:quad32) (wk:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256}) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let abef' = Mkfour (vv hash1.[5]) (vv hash1.[4]) (vv hash1.[1]) (vv hash1.[0]) in
let cdgh' = Mkfour (vv hash1.[7]) (vv hash1.[6]) (vv hash1.[3]) (vv hash1.[2]) in
(abef', cdgh')
let lemma_rnds_quad32 (abef cdgh:quad32) (wk:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256}) : Lemma
(requires wk == to_uint32 (add_mod32 (k0 SHA2_256).[t] (ws_opaque block t)))
(ensures sha256_rnds2_spec_update_core_quad32 abef cdgh wk block t == sha256_rnds2_spec_update_quad32 abef cdgh wk)
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3]
hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let l = [a'; b'; c'; d'; e'; f'; g'; h'] in
elim_of_list l;
lemma_sha256_rnds2_spec_update_is_shuffle_core hash0 wk t block;
()
#push-options "--z3rlimit 30"
let lemma_rnds2_spec_quad32_is_shuffle_core_x2 (abef cdgh:quad32) (wk0 wk1:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256 - 1}) : Lemma
(requires vv wk0 == add_mod32 (k0 SHA2_256).[t] (ws_opaque block t) /\
vv wk1 == add_mod32 (k0 SHA2_256).[t+1] (ws_opaque block (t+1)))
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
hash2 == make_hash abef'' cdgh''))
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
lemma_rnds_quad32 abef cdgh wk0 block t;
lemma_rnds_quad32 abef' cdgh' wk1 block (t+1);
assert (equal (make_hash abef' cdgh') hash1);
assert (equal (make_hash abef'' cdgh'') hash2);
()
#pop-options
let sha256_rnds2_spec_update_quad32_x2_shifts (abef cdgh:quad32) (wk0 wk1:UInt32.t) :
Lemma ((let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
cdgh'' == abef))
=
()
let sha256_rnds2_spec_quad32_is_shuffle_core_x2 (abef cdgh wk:quad32) (block:block_w) (t:counter{t < size_k_w_256 - 1}) : Lemma
(requires wk.lo0 == add_mod32 (k0 SHA2_256).[t] (ws_opaque block t) /\
wk.lo1 == add_mod32 (k0 SHA2_256).[t+1] (ws_opaque block (t+1)))
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef' = sha256_rnds2_spec_quad32 cdgh abef wk in
hash2 == make_hash abef' abef))
=
lemma_rnds2_spec_quad32_is_shuffle_core_x2 abef cdgh (to_uint32 wk.lo0) (to_uint32 wk.lo1) block t;
sha256_rnds2_spec_update_quad32_x2_shifts abef cdgh (to_uint32 wk.lo0) (to_uint32 wk.lo1);
()
let lemma_sha256_rnds2_two_steps (abef cdgh xmm0:quad32) (t:counter) (block:block_w) : Lemma
(requires t + 1 < size_k_w_256 /\
xmm0.lo0 == add_wrap (vv (k0 SHA2_256).[t] ) (ws_opaque block t) /\
xmm0.lo1 == add_wrap (vv (k0 SHA2_256).[t+1]) (ws_opaque block (t+1)) )
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
hash2 == make_hash (sha256_rnds2_spec cdgh abef xmm0) abef))
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t] ) (ws_opaque block t);
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t+1]) (ws_opaque block (t+1));
sha256_rnds2_spec_quad32_is_shuffle_core_x2 abef cdgh xmm0 block t;
lemma_sha256_rnds2_spec_quad32 cdgh abef xmm0;
()
// Top-level proof for the SHA256_rnds2 instruction
let lemma_sha256_rnds2 (abef cdgh xmm0:quad32) (t:counter) (block:block_w) (hash_in:hash256) : Lemma
(requires t + 1 < size_k_w_256 /\
xmm0.lo0 == add_wrap (word_to_nat32 k.[t]) (ws_opaque block t) /\
xmm0.lo1 == add_wrap (word_to_nat32 k.[t+1]) (ws_opaque block (t+1)) /\
make_hash abef cdgh == Spec.Loops.repeat_range 0 t (shuffle_core_opaque block) hash_in
)
(ensures make_hash (sha256_rnds2_spec cdgh abef xmm0) abef ==
Spec.Loops.repeat_range 0 (t+2) (shuffle_core_opaque block) hash_in)
=
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t] ) (ws_opaque block t);
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t+1]) (ws_opaque block (t+1));
lemma_sha256_rnds2_two_steps abef cdgh xmm0 t block;
Spec.Loops.repeat_range_induction 0 (t + 1) (shuffle_core_opaque block) hash_in;
Spec.Loops.repeat_range_induction 0 (t + 2) (shuffle_core_opaque block) hash_in;
()
(* Proof work for the SHA256_msg* instructions *)
let _sigma0_quad32 (q:quad32) : quad32 =
Mkfour (vv (_sigma0 SHA2_256 (to_uint32 q.lo0)))
(vv (_sigma0 SHA2_256 (to_uint32 q.lo1)))
(vv (_sigma0 SHA2_256 (to_uint32 q.hi2)))
(vv (_sigma0 SHA2_256 (to_uint32 q.hi3)))
let _sigma1_quad32 (q:quad32) : quad32 =
Mkfour (vv (_sigma1 SHA2_256 (to_uint32 q.lo0)))
(vv (_sigma1 SHA2_256 (to_uint32 q.lo1)))
(vv (_sigma1 SHA2_256 (to_uint32 q.hi2)))
(vv (_sigma1 SHA2_256 (to_uint32 q.hi3))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Vale.SHA.SHA_helpers.counter -> block: Vale.SHA.SHA_helpers.block_w -> Vale.Def.Types_s.quad32 | Prims.Tot | [
"total"
] | [] | [
"Vale.SHA.SHA_helpers.counter",
"Vale.SHA.SHA_helpers.block_w",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Vale.SHA.SHA_helpers.size_k_w_256",
"Vale.Arch.Types.add_wrap_quad32",
"Vale.Def.Types_s.quad32",
"Vale.SHA.SHA_helpers._sigma0_quad32",
"Vale.SHA.SHA_helpers.ws_quad32",
"Prims.op_Subtraction",
"Prims.bool",
"Vale.Def.Words_s.Mkfour",
"Vale.Def.Types_s.nat32"
] | [] | false | false | false | true | false | let ws_partial_def (t: counter) (block: block_w) : quad32 =
| if 16 <= t && t < size_k_w_256
then
(let init = ws_quad32 (t - 16) block in
let sigma0_in = ws_quad32 (t - 15) block in
let sigma0_out = _sigma0_quad32 sigma0_in in
add_wrap_quad32 init sigma0_out)
else Mkfour 0 0 0 0 | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.lemma_add_mod_a | val lemma_add_mod_a (a b c d e f g h wk: UInt32.t)
: Lemma
(let u =
add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)))))
in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
u == core) | val lemma_add_mod_a (a b c d e f g h wk: UInt32.t)
: Lemma
(let u =
add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)))))
in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
u == core) | let lemma_add_mod_a (a b c d e f g h wk:UInt32.t) :
Lemma ( let u = add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk
(add_mod h
(add_mod (_Maj SHA2_256 a b c)
(_Sigma0 SHA2_256 a))))) in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
u == core)
=
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
lemma_add_mod_commutes (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c);
assert (t2 == add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
assert (t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
assert (core == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
// ==> add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk)
lemma_add_mod_commutes (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g);
// ==> add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk)
lemma_add_mod_associates_U32 (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)));
assert (core == add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)))));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
() | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 257,
"start_col": 0,
"start_line": 229
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y))
let word_to_nat32 = vv
let nat32_to_word = to_uint32
let byte_to_nat8 = UInt8.v
let nat8_to_byte = UInt8.uint_to_t
let make_hash_def (abef cdgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abef.hi3 /\
hash.[1] == to_uint32 abef.hi2 /\
hash.[2] == to_uint32 cdgh.hi3 /\
hash.[3] == to_uint32 cdgh.hi2 /\
hash.[4] == to_uint32 abef.lo1 /\
hash.[5] == to_uint32 abef.lo0 /\
hash.[6] == to_uint32 cdgh.lo1 /\
hash.[7] == to_uint32 cdgh.lo0
} ) =
let a = to_uint32 abef.hi3 in
let b = to_uint32 abef.hi2 in
let c = to_uint32 cdgh.hi3 in
let d = to_uint32 cdgh.hi2 in
let e = to_uint32 abef.lo1 in
let f = to_uint32 abef.lo0 in
let g = to_uint32 cdgh.lo1 in
let h = to_uint32 cdgh.lo0 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
//assert_norm (index hash 2 == c);
hash
[@"opaque_to_smt"] let make_hash = opaque_make make_hash_def
irreducible let make_hash_reveal = opaque_revealer (`%make_hash) make_hash make_hash_def
let make_ordered_hash_def (abcd efgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abcd.lo0 /\
hash.[1] == to_uint32 abcd.lo1 /\
hash.[2] == to_uint32 abcd.hi2 /\
hash.[3] == to_uint32 abcd.hi3 /\
hash.[4] == to_uint32 efgh.lo0 /\
hash.[5] == to_uint32 efgh.lo1 /\
hash.[6] == to_uint32 efgh.hi2 /\
hash.[7] == to_uint32 efgh.hi3
})
=
let a = to_uint32 abcd.lo0 in
let b = to_uint32 abcd.lo1 in
let c = to_uint32 abcd.hi2 in
let d = to_uint32 abcd.hi3 in
let e = to_uint32 efgh.lo0 in
let f = to_uint32 efgh.lo1 in
let g = to_uint32 efgh.hi2 in
let h = to_uint32 efgh.hi3 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
hash
[@"opaque_to_smt"] let make_ordered_hash = opaque_make make_ordered_hash_def
irreducible let make_ordered_hash_reveal = opaque_revealer (`%make_ordered_hash) make_ordered_hash make_ordered_hash_def
let shuffle_core_properties (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}) :
Lemma(let h = shuffle_core_opaque block hash t in
let open Lib.IntTypes in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
h.[0] == t1 +. t2 /\
h.[1] == a0 /\
h.[2] == b0 /\
h.[3] == c0 /\
h.[4] == d0 +. t1 /\
h.[5] == e0 /\
h.[6] == f0 /\
h.[7] == g0)
=
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
let h = shuffle_core SHA2_256 block hash t in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
let l = [ t1 +. t2; a0; b0; c0; d0 +. t1; e0; f0; g0 ] in
assert (h == seq_of_list l);
elim_of_list l;
()
let sha256_rnds2_spec_update_quad32 (abef cdgh:quad32) (wk:UInt32.t) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let a', b', c', d', e', f', g', h' = sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3] hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let abef' = Mkfour (vv f') (vv e') (vv b') (vv a') in
let cdgh' = Mkfour (vv h') (vv g') (vv d') (vv c') in
(abef', cdgh')
let sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) : quad32 =
let abef', cdgh' = sha256_rnds2_spec_update_quad32 src2 src1 (to_uint32 wk.lo0) in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' (to_uint32 wk.lo1) in
abef''
let lemma_sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) :
Lemma (sha256_rnds2_spec src1 src2 wk == sha256_rnds2_spec_quad32 src1 src2 wk)
=
sha256_rnds2_spec_reveal ();
()
let lemma_add_mod_commutes (x y:UInt32.t) :
Lemma (add_mod x y == add_mod y x)
=
()
(*
let lemma_add_mod32_associates (x y z:int) :
Lemma ( ((x + y % pow2_32) + z) % pow2_32 == (x + ((y + z) % pow2_32)) % pow2_32 )
=
()
*)
let lemma_add_mod_associates_U32 (x y z:UInt32.t) :
Lemma (add_mod x (add_mod y z) == add_mod (add_mod x y) z)
=
let open Lib.IntTypes in
calc (==) {
v (x +. (y +. z));
(==) { }
(v x + (v y + v z) % pow2 32) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v x) (v y + v z) (pow2 32) }
((v x + v y) + v z) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v z) (v x + v y) (pow2 32) }
((v x + v y) % pow2 32 + v z) % pow2 32;
(==) { }
v ((x +. y) +. z);
};
v_inj (x +. (y +. z)) ((x +. y) +. z)
(*
assert_norm (pow2 32 == pow2_32);
//assert (add_mod y z == to_uint32 ((vv y + vv z) % pow2_32));
//assert (add_mod x (add_mod y z) == to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32));
lemma_add_mod32_associates (vv x) (vv y) (vv z);
//assert (to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32) ==
// to_uint32 (((vv x + vv y % pow2_32) + vv z) % pow2_32));
*)
#reset-options "--max_fuel 0 --max_ifuel 0"
let lemma_add_wrap_is_add_mod (n0 n1:nat32) :
Lemma (add_wrap n0 n1 == vv (add_mod (to_uint32 n0) (to_uint32 n1)))
=
assert_norm (pow2 32 == pow2_32);
()
let add_wrap_commutes (x y:nat32) :
Lemma(add_wrap x y == add_wrap y x)
=
() | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: FStar.UInt32.t ->
b: FStar.UInt32.t ->
c: FStar.UInt32.t ->
d: FStar.UInt32.t ->
e: FStar.UInt32.t ->
f: FStar.UInt32.t ->
g: FStar.UInt32.t ->
h: FStar.UInt32.t ->
wk: FStar.UInt32.t
-> FStar.Pervasives.Lemma
(ensures
(let u228 =
FStar.UInt32.add_mod (Spec.SHA2._Ch Spec.Hash.Definitions.SHA2_256 e f g)
(FStar.UInt32.add_mod (Spec.SHA2._Sigma1 Spec.Hash.Definitions.SHA2_256 e)
(FStar.UInt32.add_mod wk
(FStar.UInt32.add_mod h
(FStar.UInt32.add_mod (Spec.SHA2._Maj Spec.Hash.Definitions.SHA2_256 a b c)
(Spec.SHA2._Sigma0 Spec.Hash.Definitions.SHA2_256 a)))))
in
let t1 =
FStar.UInt32.add_mod h
(FStar.UInt32.add_mod (Spec.SHA2._Sigma1 Spec.Hash.Definitions.SHA2_256 e)
(FStar.UInt32.add_mod (Spec.SHA2._Ch Spec.Hash.Definitions.SHA2_256 e f g) wk))
in
let t2 =
FStar.UInt32.add_mod (Spec.SHA2._Sigma0 Spec.Hash.Definitions.SHA2_256 a)
(Spec.SHA2._Maj Spec.Hash.Definitions.SHA2_256 a b c)
in
let core = FStar.UInt32.add_mod t1 t2 in
u228 == core)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.UInt32.t",
"Prims.unit",
"Vale.SHA.SHA_helpers.lemma_add_mod_associates_U32",
"Spec.SHA2._Ch",
"Spec.Hash.Definitions.SHA2_256",
"Spec.SHA2._Sigma1",
"FStar.UInt32.add_mod",
"Spec.SHA2._Maj",
"Spec.SHA2._Sigma0",
"Prims._assert",
"Prims.eq2",
"Vale.SHA.SHA_helpers.lemma_add_mod_commutes",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_add_mod_a (a b c d e f g h wk: UInt32.t)
: Lemma
(let u =
add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)))))
in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
u == core) =
| let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
lemma_add_mod_commutes (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c);
assert (t2 == add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
assert (t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk))
h
(add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
assert (core ==
add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk))
(add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
lemma_add_mod_commutes (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g);
lemma_add_mod_associates_U32 (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e))
wk
(add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)));
assert (core ==
add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e))
(add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)))));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g)
(_Sigma1 SHA2_256 e)
(add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
() | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.lemma_sha256_rnds2_spec_quad32 | val lemma_sha256_rnds2_spec_quad32 (src1 src2 wk: quad32)
: Lemma (sha256_rnds2_spec src1 src2 wk == sha256_rnds2_spec_quad32 src1 src2 wk) | val lemma_sha256_rnds2_spec_quad32 (src1 src2 wk: quad32)
: Lemma (sha256_rnds2_spec src1 src2 wk == sha256_rnds2_spec_quad32 src1 src2 wk) | let lemma_sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) :
Lemma (sha256_rnds2_spec src1 src2 wk == sha256_rnds2_spec_quad32 src1 src2 wk)
=
sha256_rnds2_spec_reveal ();
() | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 175,
"start_col": 0,
"start_line": 171
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y))
let word_to_nat32 = vv
let nat32_to_word = to_uint32
let byte_to_nat8 = UInt8.v
let nat8_to_byte = UInt8.uint_to_t
let make_hash_def (abef cdgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abef.hi3 /\
hash.[1] == to_uint32 abef.hi2 /\
hash.[2] == to_uint32 cdgh.hi3 /\
hash.[3] == to_uint32 cdgh.hi2 /\
hash.[4] == to_uint32 abef.lo1 /\
hash.[5] == to_uint32 abef.lo0 /\
hash.[6] == to_uint32 cdgh.lo1 /\
hash.[7] == to_uint32 cdgh.lo0
} ) =
let a = to_uint32 abef.hi3 in
let b = to_uint32 abef.hi2 in
let c = to_uint32 cdgh.hi3 in
let d = to_uint32 cdgh.hi2 in
let e = to_uint32 abef.lo1 in
let f = to_uint32 abef.lo0 in
let g = to_uint32 cdgh.lo1 in
let h = to_uint32 cdgh.lo0 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
//assert_norm (index hash 2 == c);
hash
[@"opaque_to_smt"] let make_hash = opaque_make make_hash_def
irreducible let make_hash_reveal = opaque_revealer (`%make_hash) make_hash make_hash_def
let make_ordered_hash_def (abcd efgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abcd.lo0 /\
hash.[1] == to_uint32 abcd.lo1 /\
hash.[2] == to_uint32 abcd.hi2 /\
hash.[3] == to_uint32 abcd.hi3 /\
hash.[4] == to_uint32 efgh.lo0 /\
hash.[5] == to_uint32 efgh.lo1 /\
hash.[6] == to_uint32 efgh.hi2 /\
hash.[7] == to_uint32 efgh.hi3
})
=
let a = to_uint32 abcd.lo0 in
let b = to_uint32 abcd.lo1 in
let c = to_uint32 abcd.hi2 in
let d = to_uint32 abcd.hi3 in
let e = to_uint32 efgh.lo0 in
let f = to_uint32 efgh.lo1 in
let g = to_uint32 efgh.hi2 in
let h = to_uint32 efgh.hi3 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
hash
[@"opaque_to_smt"] let make_ordered_hash = opaque_make make_ordered_hash_def
irreducible let make_ordered_hash_reveal = opaque_revealer (`%make_ordered_hash) make_ordered_hash make_ordered_hash_def
let shuffle_core_properties (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}) :
Lemma(let h = shuffle_core_opaque block hash t in
let open Lib.IntTypes in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
h.[0] == t1 +. t2 /\
h.[1] == a0 /\
h.[2] == b0 /\
h.[3] == c0 /\
h.[4] == d0 +. t1 /\
h.[5] == e0 /\
h.[6] == f0 /\
h.[7] == g0)
=
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
let h = shuffle_core SHA2_256 block hash t in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
let l = [ t1 +. t2; a0; b0; c0; d0 +. t1; e0; f0; g0 ] in
assert (h == seq_of_list l);
elim_of_list l;
()
let sha256_rnds2_spec_update_quad32 (abef cdgh:quad32) (wk:UInt32.t) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let a', b', c', d', e', f', g', h' = sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3] hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let abef' = Mkfour (vv f') (vv e') (vv b') (vv a') in
let cdgh' = Mkfour (vv h') (vv g') (vv d') (vv c') in
(abef', cdgh')
let sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) : quad32 =
let abef', cdgh' = sha256_rnds2_spec_update_quad32 src2 src1 (to_uint32 wk.lo0) in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' (to_uint32 wk.lo1) in
abef'' | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | src1: Vale.Def.Types_s.quad32 -> src2: Vale.Def.Types_s.quad32 -> wk: Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(ensures
Vale.X64.CryptoInstructions_s.sha256_rnds2_spec src1 src2 wk ==
Vale.SHA.SHA_helpers.sha256_rnds2_spec_quad32 src1 src2 wk) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Prims.unit",
"Vale.X64.CryptoInstructions_s.sha256_rnds2_spec_reveal",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Vale.X64.CryptoInstructions_s.sha256_rnds2_spec",
"Vale.SHA.SHA_helpers.sha256_rnds2_spec_quad32",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_sha256_rnds2_spec_quad32 (src1 src2 wk: quad32)
: Lemma (sha256_rnds2_spec src1 src2 wk == sha256_rnds2_spec_quad32 src1 src2 wk) =
| sha256_rnds2_spec_reveal ();
() | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.make_hash_def | val make_hash_def (abef cdgh: quad32)
: (hash:
words_state SHA2_256
{ length hash == 8 /\ hash.[ 0 ] == to_uint32 abef.hi3 /\ hash.[ 1 ] == to_uint32 abef.hi2 /\
hash.[ 2 ] == to_uint32 cdgh.hi3 /\ hash.[ 3 ] == to_uint32 cdgh.hi2 /\
hash.[ 4 ] == to_uint32 abef.lo1 /\ hash.[ 5 ] == to_uint32 abef.lo0 /\
hash.[ 6 ] == to_uint32 cdgh.lo1 /\ hash.[ 7 ] == to_uint32 cdgh.lo0 }) | val make_hash_def (abef cdgh: quad32)
: (hash:
words_state SHA2_256
{ length hash == 8 /\ hash.[ 0 ] == to_uint32 abef.hi3 /\ hash.[ 1 ] == to_uint32 abef.hi2 /\
hash.[ 2 ] == to_uint32 cdgh.hi3 /\ hash.[ 3 ] == to_uint32 cdgh.hi2 /\
hash.[ 4 ] == to_uint32 abef.lo1 /\ hash.[ 5 ] == to_uint32 abef.lo0 /\
hash.[ 6 ] == to_uint32 cdgh.lo1 /\ hash.[ 7 ] == to_uint32 cdgh.lo0 }) | let make_hash_def (abef cdgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abef.hi3 /\
hash.[1] == to_uint32 abef.hi2 /\
hash.[2] == to_uint32 cdgh.hi3 /\
hash.[3] == to_uint32 cdgh.hi2 /\
hash.[4] == to_uint32 abef.lo1 /\
hash.[5] == to_uint32 abef.lo0 /\
hash.[6] == to_uint32 cdgh.lo1 /\
hash.[7] == to_uint32 cdgh.lo0
} ) =
let a = to_uint32 abef.hi3 in
let b = to_uint32 abef.hi2 in
let c = to_uint32 cdgh.hi3 in
let d = to_uint32 cdgh.hi2 in
let e = to_uint32 abef.lo1 in
let f = to_uint32 abef.lo0 in
let g = to_uint32 cdgh.lo1 in
let h = to_uint32 cdgh.lo0 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
//assert_norm (index hash 2 == c);
hash | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 8,
"end_line": 86,
"start_col": 0,
"start_line": 60
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y))
let word_to_nat32 = vv
let nat32_to_word = to_uint32
let byte_to_nat8 = UInt8.v
let nat8_to_byte = UInt8.uint_to_t | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | abef: Vale.Def.Types_s.quad32 -> cdgh: Vale.Def.Types_s.quad32
-> hash:
Spec.Hash.Definitions.words_state Spec.Hash.Definitions.SHA2_256
{ FStar.Seq.Base.length hash == 8 /\
hash.[ 0 ] == Vale.SHA.SHA_helpers.to_uint32 (Mkfour?.hi3 abef) /\
hash.[ 1 ] == Vale.SHA.SHA_helpers.to_uint32 (Mkfour?.hi2 abef) /\
hash.[ 2 ] == Vale.SHA.SHA_helpers.to_uint32 (Mkfour?.hi3 cdgh) /\
hash.[ 3 ] == Vale.SHA.SHA_helpers.to_uint32 (Mkfour?.hi2 cdgh) /\
hash.[ 4 ] == Vale.SHA.SHA_helpers.to_uint32 (Mkfour?.lo1 abef) /\
hash.[ 5 ] == Vale.SHA.SHA_helpers.to_uint32 (Mkfour?.lo0 abef) /\
hash.[ 6 ] == Vale.SHA.SHA_helpers.to_uint32 (Mkfour?.lo1 cdgh) /\
hash.[ 7 ] == Vale.SHA.SHA_helpers.to_uint32 (Mkfour?.lo0 cdgh) } | Prims.Tot | [
"total"
] | [] | [
"Vale.Def.Types_s.quad32",
"Prims.unit",
"FStar.Seq.Properties.elim_of_list",
"Spec.Hash.Definitions.word",
"Spec.Hash.Definitions.SHA2_256",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"FStar.Seq.Base.seq",
"Prims.nat",
"FStar.List.Tot.Base.length",
"FStar.Seq.Base.seq_of_list",
"FStar.Pervasives.assert_norm",
"Prims.list",
"Prims.Cons",
"Prims.Nil",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U32",
"Lib.IntTypes.SEC",
"Vale.SHA.SHA_helpers.to_uint32",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3",
"Spec.Hash.Definitions.words_state",
"Prims.l_and",
"FStar.UInt32.t",
"Spec.SHA2.op_String_Access"
] | [] | false | false | false | false | false | let make_hash_def (abef cdgh: quad32)
: (hash:
words_state SHA2_256
{ length hash == 8 /\ hash.[ 0 ] == to_uint32 abef.hi3 /\ hash.[ 1 ] == to_uint32 abef.hi2 /\
hash.[ 2 ] == to_uint32 cdgh.hi3 /\ hash.[ 3 ] == to_uint32 cdgh.hi2 /\
hash.[ 4 ] == to_uint32 abef.lo1 /\ hash.[ 5 ] == to_uint32 abef.lo0 /\
hash.[ 6 ] == to_uint32 cdgh.lo1 /\ hash.[ 7 ] == to_uint32 cdgh.lo0 }) =
| let a = to_uint32 abef.hi3 in
let b = to_uint32 abef.hi2 in
let c = to_uint32 cdgh.hi3 in
let d = to_uint32 cdgh.hi2 in
let e = to_uint32 abef.lo1 in
let f = to_uint32 abef.lo0 in
let g = to_uint32 cdgh.lo1 in
let h = to_uint32 cdgh.lo0 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
hash | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.lemma_sha256_rnds2 | val lemma_sha256_rnds2 (abef cdgh xmm0:quad32) (t:counter) (block:block_w) (hash_in:hash256) : Lemma
(requires t + 1 < size_k_w_256 /\
xmm0.lo0 == add_wrap (word_to_nat32 k.[t]) (ws_opaque block t) /\
xmm0.lo1 == add_wrap (word_to_nat32 k.[t+1]) (ws_opaque block (t+1)) /\
make_hash abef cdgh == Spec.Loops.repeat_range 0 t (shuffle_core_opaque block) hash_in
)
(ensures make_hash (sha256_rnds2_spec cdgh abef xmm0) abef ==
Spec.Loops.repeat_range 0 (t+2) (shuffle_core_opaque block) hash_in) | val lemma_sha256_rnds2 (abef cdgh xmm0:quad32) (t:counter) (block:block_w) (hash_in:hash256) : Lemma
(requires t + 1 < size_k_w_256 /\
xmm0.lo0 == add_wrap (word_to_nat32 k.[t]) (ws_opaque block t) /\
xmm0.lo1 == add_wrap (word_to_nat32 k.[t+1]) (ws_opaque block (t+1)) /\
make_hash abef cdgh == Spec.Loops.repeat_range 0 t (shuffle_core_opaque block) hash_in
)
(ensures make_hash (sha256_rnds2_spec cdgh abef xmm0) abef ==
Spec.Loops.repeat_range 0 (t+2) (shuffle_core_opaque block) hash_in) | let lemma_sha256_rnds2 (abef cdgh xmm0:quad32) (t:counter) (block:block_w) (hash_in:hash256) : Lemma
(requires t + 1 < size_k_w_256 /\
xmm0.lo0 == add_wrap (word_to_nat32 k.[t]) (ws_opaque block t) /\
xmm0.lo1 == add_wrap (word_to_nat32 k.[t+1]) (ws_opaque block (t+1)) /\
make_hash abef cdgh == Spec.Loops.repeat_range 0 t (shuffle_core_opaque block) hash_in
)
(ensures make_hash (sha256_rnds2_spec cdgh abef xmm0) abef ==
Spec.Loops.repeat_range 0 (t+2) (shuffle_core_opaque block) hash_in)
=
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t] ) (ws_opaque block t);
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t+1]) (ws_opaque block (t+1));
lemma_sha256_rnds2_two_steps abef cdgh xmm0 t block;
Spec.Loops.repeat_range_induction 0 (t + 1) (shuffle_core_opaque block) hash_in;
Spec.Loops.repeat_range_induction 0 (t + 2) (shuffle_core_opaque block) hash_in;
() | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 407,
"start_col": 0,
"start_line": 393
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y))
let word_to_nat32 = vv
let nat32_to_word = to_uint32
let byte_to_nat8 = UInt8.v
let nat8_to_byte = UInt8.uint_to_t
let make_hash_def (abef cdgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abef.hi3 /\
hash.[1] == to_uint32 abef.hi2 /\
hash.[2] == to_uint32 cdgh.hi3 /\
hash.[3] == to_uint32 cdgh.hi2 /\
hash.[4] == to_uint32 abef.lo1 /\
hash.[5] == to_uint32 abef.lo0 /\
hash.[6] == to_uint32 cdgh.lo1 /\
hash.[7] == to_uint32 cdgh.lo0
} ) =
let a = to_uint32 abef.hi3 in
let b = to_uint32 abef.hi2 in
let c = to_uint32 cdgh.hi3 in
let d = to_uint32 cdgh.hi2 in
let e = to_uint32 abef.lo1 in
let f = to_uint32 abef.lo0 in
let g = to_uint32 cdgh.lo1 in
let h = to_uint32 cdgh.lo0 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
//assert_norm (index hash 2 == c);
hash
[@"opaque_to_smt"] let make_hash = opaque_make make_hash_def
irreducible let make_hash_reveal = opaque_revealer (`%make_hash) make_hash make_hash_def
let make_ordered_hash_def (abcd efgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abcd.lo0 /\
hash.[1] == to_uint32 abcd.lo1 /\
hash.[2] == to_uint32 abcd.hi2 /\
hash.[3] == to_uint32 abcd.hi3 /\
hash.[4] == to_uint32 efgh.lo0 /\
hash.[5] == to_uint32 efgh.lo1 /\
hash.[6] == to_uint32 efgh.hi2 /\
hash.[7] == to_uint32 efgh.hi3
})
=
let a = to_uint32 abcd.lo0 in
let b = to_uint32 abcd.lo1 in
let c = to_uint32 abcd.hi2 in
let d = to_uint32 abcd.hi3 in
let e = to_uint32 efgh.lo0 in
let f = to_uint32 efgh.lo1 in
let g = to_uint32 efgh.hi2 in
let h = to_uint32 efgh.hi3 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
hash
[@"opaque_to_smt"] let make_ordered_hash = opaque_make make_ordered_hash_def
irreducible let make_ordered_hash_reveal = opaque_revealer (`%make_ordered_hash) make_ordered_hash make_ordered_hash_def
let shuffle_core_properties (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}) :
Lemma(let h = shuffle_core_opaque block hash t in
let open Lib.IntTypes in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
h.[0] == t1 +. t2 /\
h.[1] == a0 /\
h.[2] == b0 /\
h.[3] == c0 /\
h.[4] == d0 +. t1 /\
h.[5] == e0 /\
h.[6] == f0 /\
h.[7] == g0)
=
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
let h = shuffle_core SHA2_256 block hash t in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
let l = [ t1 +. t2; a0; b0; c0; d0 +. t1; e0; f0; g0 ] in
assert (h == seq_of_list l);
elim_of_list l;
()
let sha256_rnds2_spec_update_quad32 (abef cdgh:quad32) (wk:UInt32.t) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let a', b', c', d', e', f', g', h' = sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3] hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let abef' = Mkfour (vv f') (vv e') (vv b') (vv a') in
let cdgh' = Mkfour (vv h') (vv g') (vv d') (vv c') in
(abef', cdgh')
let sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) : quad32 =
let abef', cdgh' = sha256_rnds2_spec_update_quad32 src2 src1 (to_uint32 wk.lo0) in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' (to_uint32 wk.lo1) in
abef''
let lemma_sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) :
Lemma (sha256_rnds2_spec src1 src2 wk == sha256_rnds2_spec_quad32 src1 src2 wk)
=
sha256_rnds2_spec_reveal ();
()
let lemma_add_mod_commutes (x y:UInt32.t) :
Lemma (add_mod x y == add_mod y x)
=
()
(*
let lemma_add_mod32_associates (x y z:int) :
Lemma ( ((x + y % pow2_32) + z) % pow2_32 == (x + ((y + z) % pow2_32)) % pow2_32 )
=
()
*)
let lemma_add_mod_associates_U32 (x y z:UInt32.t) :
Lemma (add_mod x (add_mod y z) == add_mod (add_mod x y) z)
=
let open Lib.IntTypes in
calc (==) {
v (x +. (y +. z));
(==) { }
(v x + (v y + v z) % pow2 32) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v x) (v y + v z) (pow2 32) }
((v x + v y) + v z) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v z) (v x + v y) (pow2 32) }
((v x + v y) % pow2 32 + v z) % pow2 32;
(==) { }
v ((x +. y) +. z);
};
v_inj (x +. (y +. z)) ((x +. y) +. z)
(*
assert_norm (pow2 32 == pow2_32);
//assert (add_mod y z == to_uint32 ((vv y + vv z) % pow2_32));
//assert (add_mod x (add_mod y z) == to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32));
lemma_add_mod32_associates (vv x) (vv y) (vv z);
//assert (to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32) ==
// to_uint32 (((vv x + vv y % pow2_32) + vv z) % pow2_32));
*)
#reset-options "--max_fuel 0 --max_ifuel 0"
let lemma_add_wrap_is_add_mod (n0 n1:nat32) :
Lemma (add_wrap n0 n1 == vv (add_mod (to_uint32 n0) (to_uint32 n1)))
=
assert_norm (pow2 32 == pow2_32);
()
let add_wrap_commutes (x y:nat32) :
Lemma(add_wrap x y == add_wrap y x)
=
()
// Walk F* through the math steps required to rearrange all of the add_mods
let lemma_add_mod_a (a b c d e f g h wk:UInt32.t) :
Lemma ( let u = add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk
(add_mod h
(add_mod (_Maj SHA2_256 a b c)
(_Sigma0 SHA2_256 a))))) in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
u == core)
=
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
lemma_add_mod_commutes (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c);
assert (t2 == add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
assert (t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
assert (core == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
// ==> add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk)
lemma_add_mod_commutes (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g);
// ==> add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk)
lemma_add_mod_associates_U32 (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)));
assert (core == add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)))));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
()
let lemma_add_mod_e (a b c d e f g h wk:UInt32.t) :
Lemma ( let u = add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk
(add_mod h
d))) in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
u == core)
=
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
// t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_commutes d t1;
// core == add_mod t1 d
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
assert (t1 == add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h);
lemma_add_mod_associates_U32 (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h d;
assert (core == add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) (add_mod h d));
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk (add_mod h d);
assert (core == add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) (add_mod wk (add_mod h d)));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d));
assert (core == add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d))));
()
let lemma_sha256_rnds2_spec_update_is_shuffle_core (hash:hash256) (wk:UInt32.t) (t:counter) (block:block_w) : Lemma
(requires t < size_k_w SHA2_256 /\ wk == to_uint32 (add_mod32 (k0 SHA2_256).[t] (ws_opaque block t)))
(ensures (let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash.[0] hash.[1] hash.[2] hash.[3]
hash.[4] hash.[5] hash.[6] hash.[7] wk in
let u = seq_of_list [a'; b'; c'; d'; e'; f'; g'; h'] in
let c = shuffle_core_opaque block hash t in
u == c))
=
let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash.[0] hash.[1] hash.[2] hash.[3]
hash.[4] hash.[5] hash.[6] hash.[7] wk in
let l:list Lib.IntTypes.uint32 = [a'; b'; c'; d'; e'; f'; g'; h'] in
let u:Seq.seq UInt32.t = seq_of_list l in
assert_norm (List.length l == 8);
let c = shuffle_core_opaque block hash t in
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
Pervasives.reveal_opaque (`%ws) ws;
shuffle_core_properties block hash t;
elim_of_list l;
Classical.forall_intro_3 lemma_add_mod_associates_U32;
lemma_add_mod_a hash.[0] hash.[1] hash.[2] hash.[3] hash.[4] hash.[5] hash.[6] hash.[7] wk;
lemma_add_mod_e hash.[0] hash.[1] hash.[2] hash.[3] hash.[4] hash.[5] hash.[6] hash.[7] wk
let sha256_rnds2_spec_update_core_quad32 (abef cdgh:quad32) (wk:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256}) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let abef' = Mkfour (vv hash1.[5]) (vv hash1.[4]) (vv hash1.[1]) (vv hash1.[0]) in
let cdgh' = Mkfour (vv hash1.[7]) (vv hash1.[6]) (vv hash1.[3]) (vv hash1.[2]) in
(abef', cdgh')
let lemma_rnds_quad32 (abef cdgh:quad32) (wk:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256}) : Lemma
(requires wk == to_uint32 (add_mod32 (k0 SHA2_256).[t] (ws_opaque block t)))
(ensures sha256_rnds2_spec_update_core_quad32 abef cdgh wk block t == sha256_rnds2_spec_update_quad32 abef cdgh wk)
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3]
hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let l = [a'; b'; c'; d'; e'; f'; g'; h'] in
elim_of_list l;
lemma_sha256_rnds2_spec_update_is_shuffle_core hash0 wk t block;
()
#push-options "--z3rlimit 30"
let lemma_rnds2_spec_quad32_is_shuffle_core_x2 (abef cdgh:quad32) (wk0 wk1:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256 - 1}) : Lemma
(requires vv wk0 == add_mod32 (k0 SHA2_256).[t] (ws_opaque block t) /\
vv wk1 == add_mod32 (k0 SHA2_256).[t+1] (ws_opaque block (t+1)))
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
hash2 == make_hash abef'' cdgh''))
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
lemma_rnds_quad32 abef cdgh wk0 block t;
lemma_rnds_quad32 abef' cdgh' wk1 block (t+1);
assert (equal (make_hash abef' cdgh') hash1);
assert (equal (make_hash abef'' cdgh'') hash2);
()
#pop-options
let sha256_rnds2_spec_update_quad32_x2_shifts (abef cdgh:quad32) (wk0 wk1:UInt32.t) :
Lemma ((let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
cdgh'' == abef))
=
()
let sha256_rnds2_spec_quad32_is_shuffle_core_x2 (abef cdgh wk:quad32) (block:block_w) (t:counter{t < size_k_w_256 - 1}) : Lemma
(requires wk.lo0 == add_mod32 (k0 SHA2_256).[t] (ws_opaque block t) /\
wk.lo1 == add_mod32 (k0 SHA2_256).[t+1] (ws_opaque block (t+1)))
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef' = sha256_rnds2_spec_quad32 cdgh abef wk in
hash2 == make_hash abef' abef))
=
lemma_rnds2_spec_quad32_is_shuffle_core_x2 abef cdgh (to_uint32 wk.lo0) (to_uint32 wk.lo1) block t;
sha256_rnds2_spec_update_quad32_x2_shifts abef cdgh (to_uint32 wk.lo0) (to_uint32 wk.lo1);
()
let lemma_sha256_rnds2_two_steps (abef cdgh xmm0:quad32) (t:counter) (block:block_w) : Lemma
(requires t + 1 < size_k_w_256 /\
xmm0.lo0 == add_wrap (vv (k0 SHA2_256).[t] ) (ws_opaque block t) /\
xmm0.lo1 == add_wrap (vv (k0 SHA2_256).[t+1]) (ws_opaque block (t+1)) )
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
hash2 == make_hash (sha256_rnds2_spec cdgh abef xmm0) abef))
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t] ) (ws_opaque block t);
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t+1]) (ws_opaque block (t+1));
sha256_rnds2_spec_quad32_is_shuffle_core_x2 abef cdgh xmm0 block t;
lemma_sha256_rnds2_spec_quad32 cdgh abef xmm0;
() | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
abef: Vale.Def.Types_s.quad32 ->
cdgh: Vale.Def.Types_s.quad32 ->
xmm0: Vale.Def.Types_s.quad32 ->
t: Vale.SHA.SHA_helpers.counter ->
block: Vale.SHA.SHA_helpers.block_w ->
hash_in: Vale.SHA.SHA_helpers.hash256
-> FStar.Pervasives.Lemma
(requires
t + 1 < Vale.SHA.SHA_helpers.size_k_w_256 /\
Mkfour?.lo0 xmm0 ==
Vale.Def.Types_s.add_wrap (Vale.SHA.SHA_helpers.word_to_nat32 Vale.SHA.SHA_helpers.k.[ t ])
(Vale.SHA.SHA_helpers.ws_opaque block t) /\
Mkfour?.lo1 xmm0 ==
Vale.Def.Types_s.add_wrap (Vale.SHA.SHA_helpers.word_to_nat32 Vale.SHA.SHA_helpers.k.[ t + 1
])
(Vale.SHA.SHA_helpers.ws_opaque block (t + 1)) /\
Vale.SHA.SHA_helpers.make_hash abef cdgh ==
Spec.Loops.repeat_range 0 t (Vale.SHA.SHA_helpers.shuffle_core_opaque block) hash_in)
(ensures
Vale.SHA.SHA_helpers.make_hash (Vale.X64.CryptoInstructions_s.sha256_rnds2_spec cdgh
abef
xmm0)
abef ==
Spec.Loops.repeat_range 0 (t + 2) (Vale.SHA.SHA_helpers.shuffle_core_opaque block) hash_in) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Vale.SHA.SHA_helpers.counter",
"Vale.SHA.SHA_helpers.block_w",
"Vale.SHA.SHA_helpers.hash256",
"Prims.unit",
"Spec.Loops.repeat_range_induction",
"Prims.op_Addition",
"Vale.SHA.SHA_helpers.shuffle_core_opaque",
"Vale.SHA.SHA_helpers.lemma_sha256_rnds2_two_steps",
"Vale.SHA.SHA_helpers.lemma_add_wrap_is_add_mod",
"Vale.SHA.SHA_helpers.vv",
"Spec.SHA2.op_String_Access",
"Spec.Hash.Definitions.word",
"Spec.Hash.Definitions.SHA2_256",
"Spec.SHA2.k0",
"Vale.SHA.SHA_helpers.ws_opaque",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Vale.SHA.SHA_helpers.size_k_w_256",
"Prims.eq2",
"Vale.Def.Words_s.natN",
"Vale.Def.Words_s.pow2_32",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Def.Types_s.nat32",
"Vale.Def.Types_s.add_wrap",
"Vale.SHA.SHA_helpers.word_to_nat32",
"Vale.SHA.SHA_helpers.word",
"Vale.SHA.SHA_helpers.k",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.SHA.SHA_helpers.make_hash",
"Spec.Loops.repeat_range",
"Prims.squash",
"Vale.X64.CryptoInstructions_s.sha256_rnds2_spec",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_sha256_rnds2 (abef cdgh xmm0: quad32) (t: counter) (block: block_w) (hash_in: hash256)
: Lemma
(requires
t + 1 < size_k_w_256 /\ xmm0.lo0 == add_wrap (word_to_nat32 k.[ t ]) (ws_opaque block t) /\
xmm0.lo1 == add_wrap (word_to_nat32 k.[ t + 1 ]) (ws_opaque block (t + 1)) /\
make_hash abef cdgh == Spec.Loops.repeat_range 0 t (shuffle_core_opaque block) hash_in)
(ensures
make_hash (sha256_rnds2_spec cdgh abef xmm0) abef ==
Spec.Loops.repeat_range 0 (t + 2) (shuffle_core_opaque block) hash_in) =
| lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[ t ]) (ws_opaque block t);
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[ t + 1 ]) (ws_opaque block (t + 1));
lemma_sha256_rnds2_two_steps abef cdgh xmm0 t block;
Spec.Loops.repeat_range_induction 0 (t + 1) (shuffle_core_opaque block) hash_in;
Spec.Loops.repeat_range_induction 0 (t + 2) (shuffle_core_opaque block) hash_in;
() | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.lemma_add_wrap_quad32_is_add_mod_quad32 | val lemma_add_wrap_quad32_is_add_mod_quad32 (q0 q1: quad32)
: Lemma (add_mod_quad32 q0 q1 == add_wrap_quad32 q0 q1) | val lemma_add_wrap_quad32_is_add_mod_quad32 (q0 q1: quad32)
: Lemma (add_mod_quad32 q0 q1 == add_wrap_quad32 q0 q1) | let lemma_add_wrap_quad32_is_add_mod_quad32 (q0 q1:quad32) :
Lemma (add_mod_quad32 q0 q1 == add_wrap_quad32 q0 q1)
=
FStar.Classical.forall_intro_2 lemma_add_wrap_is_add_mod;
() | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 441,
"start_col": 0,
"start_line": 437
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y))
let word_to_nat32 = vv
let nat32_to_word = to_uint32
let byte_to_nat8 = UInt8.v
let nat8_to_byte = UInt8.uint_to_t
let make_hash_def (abef cdgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abef.hi3 /\
hash.[1] == to_uint32 abef.hi2 /\
hash.[2] == to_uint32 cdgh.hi3 /\
hash.[3] == to_uint32 cdgh.hi2 /\
hash.[4] == to_uint32 abef.lo1 /\
hash.[5] == to_uint32 abef.lo0 /\
hash.[6] == to_uint32 cdgh.lo1 /\
hash.[7] == to_uint32 cdgh.lo0
} ) =
let a = to_uint32 abef.hi3 in
let b = to_uint32 abef.hi2 in
let c = to_uint32 cdgh.hi3 in
let d = to_uint32 cdgh.hi2 in
let e = to_uint32 abef.lo1 in
let f = to_uint32 abef.lo0 in
let g = to_uint32 cdgh.lo1 in
let h = to_uint32 cdgh.lo0 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
//assert_norm (index hash 2 == c);
hash
[@"opaque_to_smt"] let make_hash = opaque_make make_hash_def
irreducible let make_hash_reveal = opaque_revealer (`%make_hash) make_hash make_hash_def
let make_ordered_hash_def (abcd efgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abcd.lo0 /\
hash.[1] == to_uint32 abcd.lo1 /\
hash.[2] == to_uint32 abcd.hi2 /\
hash.[3] == to_uint32 abcd.hi3 /\
hash.[4] == to_uint32 efgh.lo0 /\
hash.[5] == to_uint32 efgh.lo1 /\
hash.[6] == to_uint32 efgh.hi2 /\
hash.[7] == to_uint32 efgh.hi3
})
=
let a = to_uint32 abcd.lo0 in
let b = to_uint32 abcd.lo1 in
let c = to_uint32 abcd.hi2 in
let d = to_uint32 abcd.hi3 in
let e = to_uint32 efgh.lo0 in
let f = to_uint32 efgh.lo1 in
let g = to_uint32 efgh.hi2 in
let h = to_uint32 efgh.hi3 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
hash
[@"opaque_to_smt"] let make_ordered_hash = opaque_make make_ordered_hash_def
irreducible let make_ordered_hash_reveal = opaque_revealer (`%make_ordered_hash) make_ordered_hash make_ordered_hash_def
let shuffle_core_properties (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}) :
Lemma(let h = shuffle_core_opaque block hash t in
let open Lib.IntTypes in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
h.[0] == t1 +. t2 /\
h.[1] == a0 /\
h.[2] == b0 /\
h.[3] == c0 /\
h.[4] == d0 +. t1 /\
h.[5] == e0 /\
h.[6] == f0 /\
h.[7] == g0)
=
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
let h = shuffle_core SHA2_256 block hash t in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
let l = [ t1 +. t2; a0; b0; c0; d0 +. t1; e0; f0; g0 ] in
assert (h == seq_of_list l);
elim_of_list l;
()
let sha256_rnds2_spec_update_quad32 (abef cdgh:quad32) (wk:UInt32.t) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let a', b', c', d', e', f', g', h' = sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3] hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let abef' = Mkfour (vv f') (vv e') (vv b') (vv a') in
let cdgh' = Mkfour (vv h') (vv g') (vv d') (vv c') in
(abef', cdgh')
let sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) : quad32 =
let abef', cdgh' = sha256_rnds2_spec_update_quad32 src2 src1 (to_uint32 wk.lo0) in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' (to_uint32 wk.lo1) in
abef''
let lemma_sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) :
Lemma (sha256_rnds2_spec src1 src2 wk == sha256_rnds2_spec_quad32 src1 src2 wk)
=
sha256_rnds2_spec_reveal ();
()
let lemma_add_mod_commutes (x y:UInt32.t) :
Lemma (add_mod x y == add_mod y x)
=
()
(*
let lemma_add_mod32_associates (x y z:int) :
Lemma ( ((x + y % pow2_32) + z) % pow2_32 == (x + ((y + z) % pow2_32)) % pow2_32 )
=
()
*)
let lemma_add_mod_associates_U32 (x y z:UInt32.t) :
Lemma (add_mod x (add_mod y z) == add_mod (add_mod x y) z)
=
let open Lib.IntTypes in
calc (==) {
v (x +. (y +. z));
(==) { }
(v x + (v y + v z) % pow2 32) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v x) (v y + v z) (pow2 32) }
((v x + v y) + v z) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v z) (v x + v y) (pow2 32) }
((v x + v y) % pow2 32 + v z) % pow2 32;
(==) { }
v ((x +. y) +. z);
};
v_inj (x +. (y +. z)) ((x +. y) +. z)
(*
assert_norm (pow2 32 == pow2_32);
//assert (add_mod y z == to_uint32 ((vv y + vv z) % pow2_32));
//assert (add_mod x (add_mod y z) == to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32));
lemma_add_mod32_associates (vv x) (vv y) (vv z);
//assert (to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32) ==
// to_uint32 (((vv x + vv y % pow2_32) + vv z) % pow2_32));
*)
#reset-options "--max_fuel 0 --max_ifuel 0"
let lemma_add_wrap_is_add_mod (n0 n1:nat32) :
Lemma (add_wrap n0 n1 == vv (add_mod (to_uint32 n0) (to_uint32 n1)))
=
assert_norm (pow2 32 == pow2_32);
()
let add_wrap_commutes (x y:nat32) :
Lemma(add_wrap x y == add_wrap y x)
=
()
// Walk F* through the math steps required to rearrange all of the add_mods
let lemma_add_mod_a (a b c d e f g h wk:UInt32.t) :
Lemma ( let u = add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk
(add_mod h
(add_mod (_Maj SHA2_256 a b c)
(_Sigma0 SHA2_256 a))))) in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
u == core)
=
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
lemma_add_mod_commutes (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c);
assert (t2 == add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
assert (t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
assert (core == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
// ==> add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk)
lemma_add_mod_commutes (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g);
// ==> add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk)
lemma_add_mod_associates_U32 (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)));
assert (core == add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)))));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
()
let lemma_add_mod_e (a b c d e f g h wk:UInt32.t) :
Lemma ( let u = add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk
(add_mod h
d))) in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
u == core)
=
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
// t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_commutes d t1;
// core == add_mod t1 d
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
assert (t1 == add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h);
lemma_add_mod_associates_U32 (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h d;
assert (core == add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) (add_mod h d));
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk (add_mod h d);
assert (core == add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) (add_mod wk (add_mod h d)));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d));
assert (core == add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d))));
()
let lemma_sha256_rnds2_spec_update_is_shuffle_core (hash:hash256) (wk:UInt32.t) (t:counter) (block:block_w) : Lemma
(requires t < size_k_w SHA2_256 /\ wk == to_uint32 (add_mod32 (k0 SHA2_256).[t] (ws_opaque block t)))
(ensures (let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash.[0] hash.[1] hash.[2] hash.[3]
hash.[4] hash.[5] hash.[6] hash.[7] wk in
let u = seq_of_list [a'; b'; c'; d'; e'; f'; g'; h'] in
let c = shuffle_core_opaque block hash t in
u == c))
=
let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash.[0] hash.[1] hash.[2] hash.[3]
hash.[4] hash.[5] hash.[6] hash.[7] wk in
let l:list Lib.IntTypes.uint32 = [a'; b'; c'; d'; e'; f'; g'; h'] in
let u:Seq.seq UInt32.t = seq_of_list l in
assert_norm (List.length l == 8);
let c = shuffle_core_opaque block hash t in
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
Pervasives.reveal_opaque (`%ws) ws;
shuffle_core_properties block hash t;
elim_of_list l;
Classical.forall_intro_3 lemma_add_mod_associates_U32;
lemma_add_mod_a hash.[0] hash.[1] hash.[2] hash.[3] hash.[4] hash.[5] hash.[6] hash.[7] wk;
lemma_add_mod_e hash.[0] hash.[1] hash.[2] hash.[3] hash.[4] hash.[5] hash.[6] hash.[7] wk
let sha256_rnds2_spec_update_core_quad32 (abef cdgh:quad32) (wk:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256}) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let abef' = Mkfour (vv hash1.[5]) (vv hash1.[4]) (vv hash1.[1]) (vv hash1.[0]) in
let cdgh' = Mkfour (vv hash1.[7]) (vv hash1.[6]) (vv hash1.[3]) (vv hash1.[2]) in
(abef', cdgh')
let lemma_rnds_quad32 (abef cdgh:quad32) (wk:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256}) : Lemma
(requires wk == to_uint32 (add_mod32 (k0 SHA2_256).[t] (ws_opaque block t)))
(ensures sha256_rnds2_spec_update_core_quad32 abef cdgh wk block t == sha256_rnds2_spec_update_quad32 abef cdgh wk)
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3]
hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let l = [a'; b'; c'; d'; e'; f'; g'; h'] in
elim_of_list l;
lemma_sha256_rnds2_spec_update_is_shuffle_core hash0 wk t block;
()
#push-options "--z3rlimit 30"
let lemma_rnds2_spec_quad32_is_shuffle_core_x2 (abef cdgh:quad32) (wk0 wk1:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256 - 1}) : Lemma
(requires vv wk0 == add_mod32 (k0 SHA2_256).[t] (ws_opaque block t) /\
vv wk1 == add_mod32 (k0 SHA2_256).[t+1] (ws_opaque block (t+1)))
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
hash2 == make_hash abef'' cdgh''))
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
lemma_rnds_quad32 abef cdgh wk0 block t;
lemma_rnds_quad32 abef' cdgh' wk1 block (t+1);
assert (equal (make_hash abef' cdgh') hash1);
assert (equal (make_hash abef'' cdgh'') hash2);
()
#pop-options
let sha256_rnds2_spec_update_quad32_x2_shifts (abef cdgh:quad32) (wk0 wk1:UInt32.t) :
Lemma ((let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
cdgh'' == abef))
=
()
let sha256_rnds2_spec_quad32_is_shuffle_core_x2 (abef cdgh wk:quad32) (block:block_w) (t:counter{t < size_k_w_256 - 1}) : Lemma
(requires wk.lo0 == add_mod32 (k0 SHA2_256).[t] (ws_opaque block t) /\
wk.lo1 == add_mod32 (k0 SHA2_256).[t+1] (ws_opaque block (t+1)))
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef' = sha256_rnds2_spec_quad32 cdgh abef wk in
hash2 == make_hash abef' abef))
=
lemma_rnds2_spec_quad32_is_shuffle_core_x2 abef cdgh (to_uint32 wk.lo0) (to_uint32 wk.lo1) block t;
sha256_rnds2_spec_update_quad32_x2_shifts abef cdgh (to_uint32 wk.lo0) (to_uint32 wk.lo1);
()
let lemma_sha256_rnds2_two_steps (abef cdgh xmm0:quad32) (t:counter) (block:block_w) : Lemma
(requires t + 1 < size_k_w_256 /\
xmm0.lo0 == add_wrap (vv (k0 SHA2_256).[t] ) (ws_opaque block t) /\
xmm0.lo1 == add_wrap (vv (k0 SHA2_256).[t+1]) (ws_opaque block (t+1)) )
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
hash2 == make_hash (sha256_rnds2_spec cdgh abef xmm0) abef))
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t] ) (ws_opaque block t);
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t+1]) (ws_opaque block (t+1));
sha256_rnds2_spec_quad32_is_shuffle_core_x2 abef cdgh xmm0 block t;
lemma_sha256_rnds2_spec_quad32 cdgh abef xmm0;
()
// Top-level proof for the SHA256_rnds2 instruction
let lemma_sha256_rnds2 (abef cdgh xmm0:quad32) (t:counter) (block:block_w) (hash_in:hash256) : Lemma
(requires t + 1 < size_k_w_256 /\
xmm0.lo0 == add_wrap (word_to_nat32 k.[t]) (ws_opaque block t) /\
xmm0.lo1 == add_wrap (word_to_nat32 k.[t+1]) (ws_opaque block (t+1)) /\
make_hash abef cdgh == Spec.Loops.repeat_range 0 t (shuffle_core_opaque block) hash_in
)
(ensures make_hash (sha256_rnds2_spec cdgh abef xmm0) abef ==
Spec.Loops.repeat_range 0 (t+2) (shuffle_core_opaque block) hash_in)
=
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t] ) (ws_opaque block t);
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t+1]) (ws_opaque block (t+1));
lemma_sha256_rnds2_two_steps abef cdgh xmm0 t block;
Spec.Loops.repeat_range_induction 0 (t + 1) (shuffle_core_opaque block) hash_in;
Spec.Loops.repeat_range_induction 0 (t + 2) (shuffle_core_opaque block) hash_in;
()
(* Proof work for the SHA256_msg* instructions *)
let _sigma0_quad32 (q:quad32) : quad32 =
Mkfour (vv (_sigma0 SHA2_256 (to_uint32 q.lo0)))
(vv (_sigma0 SHA2_256 (to_uint32 q.lo1)))
(vv (_sigma0 SHA2_256 (to_uint32 q.hi2)))
(vv (_sigma0 SHA2_256 (to_uint32 q.hi3)))
let _sigma1_quad32 (q:quad32) : quad32 =
Mkfour (vv (_sigma1 SHA2_256 (to_uint32 q.lo0)))
(vv (_sigma1 SHA2_256 (to_uint32 q.lo1)))
(vv (_sigma1 SHA2_256 (to_uint32 q.hi2)))
(vv (_sigma1 SHA2_256 (to_uint32 q.hi3)))
let ws_partial_def (t:counter) (block:block_w) : quad32 =
if 16 <= t && t < size_k_w_256 then
(let init = ws_quad32 (t-16) block in
let sigma0_in = ws_quad32 (t-15) block in
let sigma0_out = _sigma0_quad32 sigma0_in in
add_wrap_quad32 init sigma0_out)
else
Mkfour 0 0 0 0
let add_mod_quad32 (q0 q1:quad32) : quad32 =
Mkfour (vv (add_mod (to_uint32 q0.lo0) (to_uint32 q1.lo0)))
(vv (add_mod (to_uint32 q0.lo1) (to_uint32 q1.lo1)))
(vv (add_mod (to_uint32 q0.hi2) (to_uint32 q1.hi2)))
(vv (add_mod (to_uint32 q0.hi3) (to_uint32 q1.hi3))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | q0: Vale.Def.Types_s.quad32 -> q1: Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(ensures Vale.SHA.SHA_helpers.add_mod_quad32 q0 q1 == Vale.Arch.Types.add_wrap_quad32 q0 q1) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Prims.unit",
"FStar.Classical.forall_intro_2",
"Vale.Def.Words_s.nat32",
"Prims.eq2",
"Vale.Def.Words_s.natN",
"Vale.Def.Words_s.pow2_32",
"Vale.Def.Types_s.add_wrap",
"Vale.SHA.SHA_helpers.vv",
"FStar.UInt32.add_mod",
"Vale.SHA.SHA_helpers.to_uint32",
"Vale.SHA.SHA_helpers.lemma_add_wrap_is_add_mod",
"Prims.l_True",
"Prims.squash",
"Vale.SHA.SHA_helpers.add_mod_quad32",
"Vale.Arch.Types.add_wrap_quad32",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_add_wrap_quad32_is_add_mod_quad32 (q0 q1: quad32)
: Lemma (add_mod_quad32 q0 q1 == add_wrap_quad32 q0 q1) =
| FStar.Classical.forall_intro_2 lemma_add_wrap_is_add_mod;
() | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.sha256_rnds2_spec_quad32_is_shuffle_core_x2 | val sha256_rnds2_spec_quad32_is_shuffle_core_x2
(abef cdgh wk: quad32)
(block: block_w)
(t: counter{t < size_k_w_256 - 1})
: Lemma
(requires
wk.lo0 == add_mod32 (k0 SHA2_256).[ t ] (ws_opaque block t) /\
wk.lo1 == add_mod32 (k0 SHA2_256).[ t + 1 ] (ws_opaque block (t + 1)))
(ensures
(let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef' = sha256_rnds2_spec_quad32 cdgh abef wk in
hash2 == make_hash abef' abef)) | val sha256_rnds2_spec_quad32_is_shuffle_core_x2
(abef cdgh wk: quad32)
(block: block_w)
(t: counter{t < size_k_w_256 - 1})
: Lemma
(requires
wk.lo0 == add_mod32 (k0 SHA2_256).[ t ] (ws_opaque block t) /\
wk.lo1 == add_mod32 (k0 SHA2_256).[ t + 1 ] (ws_opaque block (t + 1)))
(ensures
(let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef' = sha256_rnds2_spec_quad32 cdgh abef wk in
hash2 == make_hash abef' abef)) | let sha256_rnds2_spec_quad32_is_shuffle_core_x2 (abef cdgh wk:quad32) (block:block_w) (t:counter{t < size_k_w_256 - 1}) : Lemma
(requires wk.lo0 == add_mod32 (k0 SHA2_256).[t] (ws_opaque block t) /\
wk.lo1 == add_mod32 (k0 SHA2_256).[t+1] (ws_opaque block (t+1)))
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef' = sha256_rnds2_spec_quad32 cdgh abef wk in
hash2 == make_hash abef' abef))
=
lemma_rnds2_spec_quad32_is_shuffle_core_x2 abef cdgh (to_uint32 wk.lo0) (to_uint32 wk.lo1) block t;
sha256_rnds2_spec_update_quad32_x2_shifts abef cdgh (to_uint32 wk.lo0) (to_uint32 wk.lo1);
() | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 372,
"start_col": 0,
"start_line": 361
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y))
let word_to_nat32 = vv
let nat32_to_word = to_uint32
let byte_to_nat8 = UInt8.v
let nat8_to_byte = UInt8.uint_to_t
let make_hash_def (abef cdgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abef.hi3 /\
hash.[1] == to_uint32 abef.hi2 /\
hash.[2] == to_uint32 cdgh.hi3 /\
hash.[3] == to_uint32 cdgh.hi2 /\
hash.[4] == to_uint32 abef.lo1 /\
hash.[5] == to_uint32 abef.lo0 /\
hash.[6] == to_uint32 cdgh.lo1 /\
hash.[7] == to_uint32 cdgh.lo0
} ) =
let a = to_uint32 abef.hi3 in
let b = to_uint32 abef.hi2 in
let c = to_uint32 cdgh.hi3 in
let d = to_uint32 cdgh.hi2 in
let e = to_uint32 abef.lo1 in
let f = to_uint32 abef.lo0 in
let g = to_uint32 cdgh.lo1 in
let h = to_uint32 cdgh.lo0 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
//assert_norm (index hash 2 == c);
hash
[@"opaque_to_smt"] let make_hash = opaque_make make_hash_def
irreducible let make_hash_reveal = opaque_revealer (`%make_hash) make_hash make_hash_def
let make_ordered_hash_def (abcd efgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abcd.lo0 /\
hash.[1] == to_uint32 abcd.lo1 /\
hash.[2] == to_uint32 abcd.hi2 /\
hash.[3] == to_uint32 abcd.hi3 /\
hash.[4] == to_uint32 efgh.lo0 /\
hash.[5] == to_uint32 efgh.lo1 /\
hash.[6] == to_uint32 efgh.hi2 /\
hash.[7] == to_uint32 efgh.hi3
})
=
let a = to_uint32 abcd.lo0 in
let b = to_uint32 abcd.lo1 in
let c = to_uint32 abcd.hi2 in
let d = to_uint32 abcd.hi3 in
let e = to_uint32 efgh.lo0 in
let f = to_uint32 efgh.lo1 in
let g = to_uint32 efgh.hi2 in
let h = to_uint32 efgh.hi3 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
hash
[@"opaque_to_smt"] let make_ordered_hash = opaque_make make_ordered_hash_def
irreducible let make_ordered_hash_reveal = opaque_revealer (`%make_ordered_hash) make_ordered_hash make_ordered_hash_def
let shuffle_core_properties (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}) :
Lemma(let h = shuffle_core_opaque block hash t in
let open Lib.IntTypes in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
h.[0] == t1 +. t2 /\
h.[1] == a0 /\
h.[2] == b0 /\
h.[3] == c0 /\
h.[4] == d0 +. t1 /\
h.[5] == e0 /\
h.[6] == f0 /\
h.[7] == g0)
=
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
let h = shuffle_core SHA2_256 block hash t in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
let l = [ t1 +. t2; a0; b0; c0; d0 +. t1; e0; f0; g0 ] in
assert (h == seq_of_list l);
elim_of_list l;
()
let sha256_rnds2_spec_update_quad32 (abef cdgh:quad32) (wk:UInt32.t) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let a', b', c', d', e', f', g', h' = sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3] hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let abef' = Mkfour (vv f') (vv e') (vv b') (vv a') in
let cdgh' = Mkfour (vv h') (vv g') (vv d') (vv c') in
(abef', cdgh')
let sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) : quad32 =
let abef', cdgh' = sha256_rnds2_spec_update_quad32 src2 src1 (to_uint32 wk.lo0) in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' (to_uint32 wk.lo1) in
abef''
let lemma_sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) :
Lemma (sha256_rnds2_spec src1 src2 wk == sha256_rnds2_spec_quad32 src1 src2 wk)
=
sha256_rnds2_spec_reveal ();
()
let lemma_add_mod_commutes (x y:UInt32.t) :
Lemma (add_mod x y == add_mod y x)
=
()
(*
let lemma_add_mod32_associates (x y z:int) :
Lemma ( ((x + y % pow2_32) + z) % pow2_32 == (x + ((y + z) % pow2_32)) % pow2_32 )
=
()
*)
let lemma_add_mod_associates_U32 (x y z:UInt32.t) :
Lemma (add_mod x (add_mod y z) == add_mod (add_mod x y) z)
=
let open Lib.IntTypes in
calc (==) {
v (x +. (y +. z));
(==) { }
(v x + (v y + v z) % pow2 32) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v x) (v y + v z) (pow2 32) }
((v x + v y) + v z) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v z) (v x + v y) (pow2 32) }
((v x + v y) % pow2 32 + v z) % pow2 32;
(==) { }
v ((x +. y) +. z);
};
v_inj (x +. (y +. z)) ((x +. y) +. z)
(*
assert_norm (pow2 32 == pow2_32);
//assert (add_mod y z == to_uint32 ((vv y + vv z) % pow2_32));
//assert (add_mod x (add_mod y z) == to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32));
lemma_add_mod32_associates (vv x) (vv y) (vv z);
//assert (to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32) ==
// to_uint32 (((vv x + vv y % pow2_32) + vv z) % pow2_32));
*)
#reset-options "--max_fuel 0 --max_ifuel 0"
let lemma_add_wrap_is_add_mod (n0 n1:nat32) :
Lemma (add_wrap n0 n1 == vv (add_mod (to_uint32 n0) (to_uint32 n1)))
=
assert_norm (pow2 32 == pow2_32);
()
let add_wrap_commutes (x y:nat32) :
Lemma(add_wrap x y == add_wrap y x)
=
()
// Walk F* through the math steps required to rearrange all of the add_mods
let lemma_add_mod_a (a b c d e f g h wk:UInt32.t) :
Lemma ( let u = add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk
(add_mod h
(add_mod (_Maj SHA2_256 a b c)
(_Sigma0 SHA2_256 a))))) in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
u == core)
=
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
lemma_add_mod_commutes (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c);
assert (t2 == add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
assert (t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
assert (core == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
// ==> add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk)
lemma_add_mod_commutes (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g);
// ==> add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk)
lemma_add_mod_associates_U32 (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)));
assert (core == add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)))));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
()
let lemma_add_mod_e (a b c d e f g h wk:UInt32.t) :
Lemma ( let u = add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk
(add_mod h
d))) in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
u == core)
=
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
// t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_commutes d t1;
// core == add_mod t1 d
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
assert (t1 == add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h);
lemma_add_mod_associates_U32 (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h d;
assert (core == add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) (add_mod h d));
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk (add_mod h d);
assert (core == add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) (add_mod wk (add_mod h d)));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d));
assert (core == add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d))));
()
let lemma_sha256_rnds2_spec_update_is_shuffle_core (hash:hash256) (wk:UInt32.t) (t:counter) (block:block_w) : Lemma
(requires t < size_k_w SHA2_256 /\ wk == to_uint32 (add_mod32 (k0 SHA2_256).[t] (ws_opaque block t)))
(ensures (let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash.[0] hash.[1] hash.[2] hash.[3]
hash.[4] hash.[5] hash.[6] hash.[7] wk in
let u = seq_of_list [a'; b'; c'; d'; e'; f'; g'; h'] in
let c = shuffle_core_opaque block hash t in
u == c))
=
let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash.[0] hash.[1] hash.[2] hash.[3]
hash.[4] hash.[5] hash.[6] hash.[7] wk in
let l:list Lib.IntTypes.uint32 = [a'; b'; c'; d'; e'; f'; g'; h'] in
let u:Seq.seq UInt32.t = seq_of_list l in
assert_norm (List.length l == 8);
let c = shuffle_core_opaque block hash t in
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
Pervasives.reveal_opaque (`%ws) ws;
shuffle_core_properties block hash t;
elim_of_list l;
Classical.forall_intro_3 lemma_add_mod_associates_U32;
lemma_add_mod_a hash.[0] hash.[1] hash.[2] hash.[3] hash.[4] hash.[5] hash.[6] hash.[7] wk;
lemma_add_mod_e hash.[0] hash.[1] hash.[2] hash.[3] hash.[4] hash.[5] hash.[6] hash.[7] wk
let sha256_rnds2_spec_update_core_quad32 (abef cdgh:quad32) (wk:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256}) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let abef' = Mkfour (vv hash1.[5]) (vv hash1.[4]) (vv hash1.[1]) (vv hash1.[0]) in
let cdgh' = Mkfour (vv hash1.[7]) (vv hash1.[6]) (vv hash1.[3]) (vv hash1.[2]) in
(abef', cdgh')
let lemma_rnds_quad32 (abef cdgh:quad32) (wk:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256}) : Lemma
(requires wk == to_uint32 (add_mod32 (k0 SHA2_256).[t] (ws_opaque block t)))
(ensures sha256_rnds2_spec_update_core_quad32 abef cdgh wk block t == sha256_rnds2_spec_update_quad32 abef cdgh wk)
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3]
hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let l = [a'; b'; c'; d'; e'; f'; g'; h'] in
elim_of_list l;
lemma_sha256_rnds2_spec_update_is_shuffle_core hash0 wk t block;
()
#push-options "--z3rlimit 30"
let lemma_rnds2_spec_quad32_is_shuffle_core_x2 (abef cdgh:quad32) (wk0 wk1:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256 - 1}) : Lemma
(requires vv wk0 == add_mod32 (k0 SHA2_256).[t] (ws_opaque block t) /\
vv wk1 == add_mod32 (k0 SHA2_256).[t+1] (ws_opaque block (t+1)))
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
hash2 == make_hash abef'' cdgh''))
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
lemma_rnds_quad32 abef cdgh wk0 block t;
lemma_rnds_quad32 abef' cdgh' wk1 block (t+1);
assert (equal (make_hash abef' cdgh') hash1);
assert (equal (make_hash abef'' cdgh'') hash2);
()
#pop-options
let sha256_rnds2_spec_update_quad32_x2_shifts (abef cdgh:quad32) (wk0 wk1:UInt32.t) :
Lemma ((let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
cdgh'' == abef))
=
() | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
abef: Vale.Def.Types_s.quad32 ->
cdgh: Vale.Def.Types_s.quad32 ->
wk: Vale.Def.Types_s.quad32 ->
block: Vale.SHA.SHA_helpers.block_w ->
t: Vale.SHA.SHA_helpers.counter{t < Vale.SHA.SHA_helpers.size_k_w_256 - 1}
-> FStar.Pervasives.Lemma
(requires
Mkfour?.lo0 wk ==
Vale.SHA.SHA_helpers.add_mod32 (Spec.SHA2.k0 Spec.Hash.Definitions.SHA2_256).[ t ]
(Vale.SHA.SHA_helpers.ws_opaque block t) /\
Mkfour?.lo1 wk ==
Vale.SHA.SHA_helpers.add_mod32 (Spec.SHA2.k0 Spec.Hash.Definitions.SHA2_256).[ t + 1 ]
(Vale.SHA.SHA_helpers.ws_opaque block (t + 1)))
(ensures
(let hash0 = Vale.SHA.SHA_helpers.make_hash abef cdgh in
let hash1 = Vale.SHA.SHA_helpers.shuffle_core_opaque block hash0 t in
let hash2 = Vale.SHA.SHA_helpers.shuffle_core_opaque block hash1 (t + 1) in
let abef' = Vale.SHA.SHA_helpers.sha256_rnds2_spec_quad32 cdgh abef wk in
hash2 == Vale.SHA.SHA_helpers.make_hash abef' abef)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Vale.SHA.SHA_helpers.block_w",
"Vale.SHA.SHA_helpers.counter",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Subtraction",
"Vale.SHA.SHA_helpers.size_k_w_256",
"Prims.unit",
"Vale.SHA.SHA_helpers.sha256_rnds2_spec_update_quad32_x2_shifts",
"Vale.SHA.SHA_helpers.to_uint32",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.SHA.SHA_helpers.lemma_rnds2_spec_quad32_is_shuffle_core_x2",
"Prims.l_and",
"Prims.eq2",
"Vale.Def.Words_s.nat32",
"Vale.SHA.SHA_helpers.add_mod32",
"Spec.SHA2.op_String_Access",
"Spec.Hash.Definitions.word",
"Spec.Hash.Definitions.SHA2_256",
"Spec.SHA2.k0",
"Vale.SHA.SHA_helpers.ws_opaque",
"Prims.op_Addition",
"Prims.squash",
"Vale.SHA.SHA_helpers.hash256",
"Vale.SHA.SHA_helpers.make_hash",
"Vale.SHA.SHA_helpers.sha256_rnds2_spec_quad32",
"Vale.SHA.SHA_helpers.shuffle_core_opaque",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let sha256_rnds2_spec_quad32_is_shuffle_core_x2
(abef cdgh wk: quad32)
(block: block_w)
(t: counter{t < size_k_w_256 - 1})
: Lemma
(requires
wk.lo0 == add_mod32 (k0 SHA2_256).[ t ] (ws_opaque block t) /\
wk.lo1 == add_mod32 (k0 SHA2_256).[ t + 1 ] (ws_opaque block (t + 1)))
(ensures
(let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef' = sha256_rnds2_spec_quad32 cdgh abef wk in
hash2 == make_hash abef' abef)) =
| lemma_rnds2_spec_quad32_is_shuffle_core_x2 abef cdgh (to_uint32 wk.lo0) (to_uint32 wk.lo1) block t;
sha256_rnds2_spec_update_quad32_x2_shifts abef cdgh (to_uint32 wk.lo0) (to_uint32 wk.lo1);
() | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.lemma_add_mod_associates_U32 | val lemma_add_mod_associates_U32 (x y z: UInt32.t)
: Lemma (add_mod x (add_mod y z) == add_mod (add_mod x y) z) | val lemma_add_mod_associates_U32 (x y z: UInt32.t)
: Lemma (add_mod x (add_mod y z) == add_mod (add_mod x y) z) | let lemma_add_mod_associates_U32 (x y z:UInt32.t) :
Lemma (add_mod x (add_mod y z) == add_mod (add_mod x y) z)
=
let open Lib.IntTypes in
calc (==) {
v (x +. (y +. z));
(==) { }
(v x + (v y + v z) % pow2 32) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v x) (v y + v z) (pow2 32) }
((v x + v y) + v z) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v z) (v x + v y) (pow2 32) }
((v x + v y) % pow2 32 + v z) % pow2 32;
(==) { }
v ((x +. y) +. z);
};
v_inj (x +. (y +. z)) ((x +. y) +. z) | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 204,
"start_col": 0,
"start_line": 189
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y))
let word_to_nat32 = vv
let nat32_to_word = to_uint32
let byte_to_nat8 = UInt8.v
let nat8_to_byte = UInt8.uint_to_t
let make_hash_def (abef cdgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abef.hi3 /\
hash.[1] == to_uint32 abef.hi2 /\
hash.[2] == to_uint32 cdgh.hi3 /\
hash.[3] == to_uint32 cdgh.hi2 /\
hash.[4] == to_uint32 abef.lo1 /\
hash.[5] == to_uint32 abef.lo0 /\
hash.[6] == to_uint32 cdgh.lo1 /\
hash.[7] == to_uint32 cdgh.lo0
} ) =
let a = to_uint32 abef.hi3 in
let b = to_uint32 abef.hi2 in
let c = to_uint32 cdgh.hi3 in
let d = to_uint32 cdgh.hi2 in
let e = to_uint32 abef.lo1 in
let f = to_uint32 abef.lo0 in
let g = to_uint32 cdgh.lo1 in
let h = to_uint32 cdgh.lo0 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
//assert_norm (index hash 2 == c);
hash
[@"opaque_to_smt"] let make_hash = opaque_make make_hash_def
irreducible let make_hash_reveal = opaque_revealer (`%make_hash) make_hash make_hash_def
let make_ordered_hash_def (abcd efgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abcd.lo0 /\
hash.[1] == to_uint32 abcd.lo1 /\
hash.[2] == to_uint32 abcd.hi2 /\
hash.[3] == to_uint32 abcd.hi3 /\
hash.[4] == to_uint32 efgh.lo0 /\
hash.[5] == to_uint32 efgh.lo1 /\
hash.[6] == to_uint32 efgh.hi2 /\
hash.[7] == to_uint32 efgh.hi3
})
=
let a = to_uint32 abcd.lo0 in
let b = to_uint32 abcd.lo1 in
let c = to_uint32 abcd.hi2 in
let d = to_uint32 abcd.hi3 in
let e = to_uint32 efgh.lo0 in
let f = to_uint32 efgh.lo1 in
let g = to_uint32 efgh.hi2 in
let h = to_uint32 efgh.hi3 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
hash
[@"opaque_to_smt"] let make_ordered_hash = opaque_make make_ordered_hash_def
irreducible let make_ordered_hash_reveal = opaque_revealer (`%make_ordered_hash) make_ordered_hash make_ordered_hash_def
let shuffle_core_properties (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}) :
Lemma(let h = shuffle_core_opaque block hash t in
let open Lib.IntTypes in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
h.[0] == t1 +. t2 /\
h.[1] == a0 /\
h.[2] == b0 /\
h.[3] == c0 /\
h.[4] == d0 +. t1 /\
h.[5] == e0 /\
h.[6] == f0 /\
h.[7] == g0)
=
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
let h = shuffle_core SHA2_256 block hash t in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
let l = [ t1 +. t2; a0; b0; c0; d0 +. t1; e0; f0; g0 ] in
assert (h == seq_of_list l);
elim_of_list l;
()
let sha256_rnds2_spec_update_quad32 (abef cdgh:quad32) (wk:UInt32.t) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let a', b', c', d', e', f', g', h' = sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3] hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let abef' = Mkfour (vv f') (vv e') (vv b') (vv a') in
let cdgh' = Mkfour (vv h') (vv g') (vv d') (vv c') in
(abef', cdgh')
let sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) : quad32 =
let abef', cdgh' = sha256_rnds2_spec_update_quad32 src2 src1 (to_uint32 wk.lo0) in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' (to_uint32 wk.lo1) in
abef''
let lemma_sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) :
Lemma (sha256_rnds2_spec src1 src2 wk == sha256_rnds2_spec_quad32 src1 src2 wk)
=
sha256_rnds2_spec_reveal ();
()
let lemma_add_mod_commutes (x y:UInt32.t) :
Lemma (add_mod x y == add_mod y x)
=
()
(*
let lemma_add_mod32_associates (x y z:int) :
Lemma ( ((x + y % pow2_32) + z) % pow2_32 == (x + ((y + z) % pow2_32)) % pow2_32 )
=
()
*) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt32.t -> y: FStar.UInt32.t -> z: FStar.UInt32.t
-> FStar.Pervasives.Lemma
(ensures
FStar.UInt32.add_mod x (FStar.UInt32.add_mod y z) ==
FStar.UInt32.add_mod (FStar.UInt32.add_mod x y) z) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.UInt32.t",
"FStar.UInt32.v_inj",
"Lib.IntTypes.op_Plus_Dot",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.unit",
"FStar.Calc.calc_finish",
"Lib.IntTypes.range_t",
"Prims.eq2",
"Lib.IntTypes.v",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"Prims.op_Modulus",
"Prims.op_Addition",
"Prims.pow2",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"FStar.Math.Lemmas.lemma_mod_add_distr",
"Prims.l_True",
"FStar.UInt32.add_mod",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_add_mod_associates_U32 (x y z: UInt32.t)
: Lemma (add_mod x (add_mod y z) == add_mod (add_mod x y) z) =
| let open Lib.IntTypes in
calc ( == ) {
v (x +. (y +. z));
( == ) { () }
(v x + (v y + v z) % pow2 32) % pow2 32;
( == ) { FStar.Math.Lemmas.lemma_mod_add_distr (v x) (v y + v z) (pow2 32) }
((v x + v y) + v z) % pow2 32;
( == ) { FStar.Math.Lemmas.lemma_mod_add_distr (v z) (v x + v y) (pow2 32) }
((v x + v y) % pow2 32 + v z) % pow2 32;
( == ) { () }
v ((x +. y) +. z);
};
v_inj (x +. (y +. z)) ((x +. y) +. z) | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.lemma_add_mod_ws_rearrangement | val lemma_add_mod_ws_rearrangement (a b c d: UInt32.t)
: Lemma (let open Lib.IntTypes in a +. b +. c +. d == d +. c +. b +. a) | val lemma_add_mod_ws_rearrangement (a b c d: UInt32.t)
: Lemma (let open Lib.IntTypes in a +. b +. c +. d == d +. c +. b +. a) | let lemma_add_mod_ws_rearrangement (a b c d:UInt32.t) :
Lemma (let open Lib.IntTypes in
a +. b +. c +. d == d +. c +. b +. a)
=
let open Lib.IntTypes in
calc (==) {
a +. b +. c +. d;
(==) {}
(((a +. b) +. c) +. d);
(==) { lemma_add_mod_commutes ((a +. b) +. c) d;
lemma_add_mod_commutes (a +. b) c;
lemma_add_mod_commutes a b
}
d +. (c +. (b +. a));
(==) { lemma_add_mod_associates_U32 d c (b +. a);
lemma_add_mod_associates_U32 (d +. c) b a}
(((d +. c) +. b) +. a);
} | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 478,
"start_col": 0,
"start_line": 461
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y))
let word_to_nat32 = vv
let nat32_to_word = to_uint32
let byte_to_nat8 = UInt8.v
let nat8_to_byte = UInt8.uint_to_t
let make_hash_def (abef cdgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abef.hi3 /\
hash.[1] == to_uint32 abef.hi2 /\
hash.[2] == to_uint32 cdgh.hi3 /\
hash.[3] == to_uint32 cdgh.hi2 /\
hash.[4] == to_uint32 abef.lo1 /\
hash.[5] == to_uint32 abef.lo0 /\
hash.[6] == to_uint32 cdgh.lo1 /\
hash.[7] == to_uint32 cdgh.lo0
} ) =
let a = to_uint32 abef.hi3 in
let b = to_uint32 abef.hi2 in
let c = to_uint32 cdgh.hi3 in
let d = to_uint32 cdgh.hi2 in
let e = to_uint32 abef.lo1 in
let f = to_uint32 abef.lo0 in
let g = to_uint32 cdgh.lo1 in
let h = to_uint32 cdgh.lo0 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
//assert_norm (index hash 2 == c);
hash
[@"opaque_to_smt"] let make_hash = opaque_make make_hash_def
irreducible let make_hash_reveal = opaque_revealer (`%make_hash) make_hash make_hash_def
let make_ordered_hash_def (abcd efgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abcd.lo0 /\
hash.[1] == to_uint32 abcd.lo1 /\
hash.[2] == to_uint32 abcd.hi2 /\
hash.[3] == to_uint32 abcd.hi3 /\
hash.[4] == to_uint32 efgh.lo0 /\
hash.[5] == to_uint32 efgh.lo1 /\
hash.[6] == to_uint32 efgh.hi2 /\
hash.[7] == to_uint32 efgh.hi3
})
=
let a = to_uint32 abcd.lo0 in
let b = to_uint32 abcd.lo1 in
let c = to_uint32 abcd.hi2 in
let d = to_uint32 abcd.hi3 in
let e = to_uint32 efgh.lo0 in
let f = to_uint32 efgh.lo1 in
let g = to_uint32 efgh.hi2 in
let h = to_uint32 efgh.hi3 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
hash
[@"opaque_to_smt"] let make_ordered_hash = opaque_make make_ordered_hash_def
irreducible let make_ordered_hash_reveal = opaque_revealer (`%make_ordered_hash) make_ordered_hash make_ordered_hash_def
let shuffle_core_properties (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}) :
Lemma(let h = shuffle_core_opaque block hash t in
let open Lib.IntTypes in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
h.[0] == t1 +. t2 /\
h.[1] == a0 /\
h.[2] == b0 /\
h.[3] == c0 /\
h.[4] == d0 +. t1 /\
h.[5] == e0 /\
h.[6] == f0 /\
h.[7] == g0)
=
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
let h = shuffle_core SHA2_256 block hash t in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
let l = [ t1 +. t2; a0; b0; c0; d0 +. t1; e0; f0; g0 ] in
assert (h == seq_of_list l);
elim_of_list l;
()
let sha256_rnds2_spec_update_quad32 (abef cdgh:quad32) (wk:UInt32.t) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let a', b', c', d', e', f', g', h' = sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3] hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let abef' = Mkfour (vv f') (vv e') (vv b') (vv a') in
let cdgh' = Mkfour (vv h') (vv g') (vv d') (vv c') in
(abef', cdgh')
let sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) : quad32 =
let abef', cdgh' = sha256_rnds2_spec_update_quad32 src2 src1 (to_uint32 wk.lo0) in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' (to_uint32 wk.lo1) in
abef''
let lemma_sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) :
Lemma (sha256_rnds2_spec src1 src2 wk == sha256_rnds2_spec_quad32 src1 src2 wk)
=
sha256_rnds2_spec_reveal ();
()
let lemma_add_mod_commutes (x y:UInt32.t) :
Lemma (add_mod x y == add_mod y x)
=
()
(*
let lemma_add_mod32_associates (x y z:int) :
Lemma ( ((x + y % pow2_32) + z) % pow2_32 == (x + ((y + z) % pow2_32)) % pow2_32 )
=
()
*)
let lemma_add_mod_associates_U32 (x y z:UInt32.t) :
Lemma (add_mod x (add_mod y z) == add_mod (add_mod x y) z)
=
let open Lib.IntTypes in
calc (==) {
v (x +. (y +. z));
(==) { }
(v x + (v y + v z) % pow2 32) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v x) (v y + v z) (pow2 32) }
((v x + v y) + v z) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v z) (v x + v y) (pow2 32) }
((v x + v y) % pow2 32 + v z) % pow2 32;
(==) { }
v ((x +. y) +. z);
};
v_inj (x +. (y +. z)) ((x +. y) +. z)
(*
assert_norm (pow2 32 == pow2_32);
//assert (add_mod y z == to_uint32 ((vv y + vv z) % pow2_32));
//assert (add_mod x (add_mod y z) == to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32));
lemma_add_mod32_associates (vv x) (vv y) (vv z);
//assert (to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32) ==
// to_uint32 (((vv x + vv y % pow2_32) + vv z) % pow2_32));
*)
#reset-options "--max_fuel 0 --max_ifuel 0"
let lemma_add_wrap_is_add_mod (n0 n1:nat32) :
Lemma (add_wrap n0 n1 == vv (add_mod (to_uint32 n0) (to_uint32 n1)))
=
assert_norm (pow2 32 == pow2_32);
()
let add_wrap_commutes (x y:nat32) :
Lemma(add_wrap x y == add_wrap y x)
=
()
// Walk F* through the math steps required to rearrange all of the add_mods
let lemma_add_mod_a (a b c d e f g h wk:UInt32.t) :
Lemma ( let u = add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk
(add_mod h
(add_mod (_Maj SHA2_256 a b c)
(_Sigma0 SHA2_256 a))))) in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
u == core)
=
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
lemma_add_mod_commutes (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c);
assert (t2 == add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
assert (t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
assert (core == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
// ==> add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk)
lemma_add_mod_commutes (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g);
// ==> add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk)
lemma_add_mod_associates_U32 (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)));
assert (core == add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)))));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
()
let lemma_add_mod_e (a b c d e f g h wk:UInt32.t) :
Lemma ( let u = add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk
(add_mod h
d))) in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
u == core)
=
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
// t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_commutes d t1;
// core == add_mod t1 d
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
assert (t1 == add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h);
lemma_add_mod_associates_U32 (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h d;
assert (core == add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) (add_mod h d));
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk (add_mod h d);
assert (core == add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) (add_mod wk (add_mod h d)));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d));
assert (core == add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d))));
()
let lemma_sha256_rnds2_spec_update_is_shuffle_core (hash:hash256) (wk:UInt32.t) (t:counter) (block:block_w) : Lemma
(requires t < size_k_w SHA2_256 /\ wk == to_uint32 (add_mod32 (k0 SHA2_256).[t] (ws_opaque block t)))
(ensures (let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash.[0] hash.[1] hash.[2] hash.[3]
hash.[4] hash.[5] hash.[6] hash.[7] wk in
let u = seq_of_list [a'; b'; c'; d'; e'; f'; g'; h'] in
let c = shuffle_core_opaque block hash t in
u == c))
=
let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash.[0] hash.[1] hash.[2] hash.[3]
hash.[4] hash.[5] hash.[6] hash.[7] wk in
let l:list Lib.IntTypes.uint32 = [a'; b'; c'; d'; e'; f'; g'; h'] in
let u:Seq.seq UInt32.t = seq_of_list l in
assert_norm (List.length l == 8);
let c = shuffle_core_opaque block hash t in
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
Pervasives.reveal_opaque (`%ws) ws;
shuffle_core_properties block hash t;
elim_of_list l;
Classical.forall_intro_3 lemma_add_mod_associates_U32;
lemma_add_mod_a hash.[0] hash.[1] hash.[2] hash.[3] hash.[4] hash.[5] hash.[6] hash.[7] wk;
lemma_add_mod_e hash.[0] hash.[1] hash.[2] hash.[3] hash.[4] hash.[5] hash.[6] hash.[7] wk
let sha256_rnds2_spec_update_core_quad32 (abef cdgh:quad32) (wk:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256}) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let abef' = Mkfour (vv hash1.[5]) (vv hash1.[4]) (vv hash1.[1]) (vv hash1.[0]) in
let cdgh' = Mkfour (vv hash1.[7]) (vv hash1.[6]) (vv hash1.[3]) (vv hash1.[2]) in
(abef', cdgh')
let lemma_rnds_quad32 (abef cdgh:quad32) (wk:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256}) : Lemma
(requires wk == to_uint32 (add_mod32 (k0 SHA2_256).[t] (ws_opaque block t)))
(ensures sha256_rnds2_spec_update_core_quad32 abef cdgh wk block t == sha256_rnds2_spec_update_quad32 abef cdgh wk)
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3]
hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let l = [a'; b'; c'; d'; e'; f'; g'; h'] in
elim_of_list l;
lemma_sha256_rnds2_spec_update_is_shuffle_core hash0 wk t block;
()
#push-options "--z3rlimit 30"
let lemma_rnds2_spec_quad32_is_shuffle_core_x2 (abef cdgh:quad32) (wk0 wk1:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256 - 1}) : Lemma
(requires vv wk0 == add_mod32 (k0 SHA2_256).[t] (ws_opaque block t) /\
vv wk1 == add_mod32 (k0 SHA2_256).[t+1] (ws_opaque block (t+1)))
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
hash2 == make_hash abef'' cdgh''))
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
lemma_rnds_quad32 abef cdgh wk0 block t;
lemma_rnds_quad32 abef' cdgh' wk1 block (t+1);
assert (equal (make_hash abef' cdgh') hash1);
assert (equal (make_hash abef'' cdgh'') hash2);
()
#pop-options
let sha256_rnds2_spec_update_quad32_x2_shifts (abef cdgh:quad32) (wk0 wk1:UInt32.t) :
Lemma ((let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
cdgh'' == abef))
=
()
let sha256_rnds2_spec_quad32_is_shuffle_core_x2 (abef cdgh wk:quad32) (block:block_w) (t:counter{t < size_k_w_256 - 1}) : Lemma
(requires wk.lo0 == add_mod32 (k0 SHA2_256).[t] (ws_opaque block t) /\
wk.lo1 == add_mod32 (k0 SHA2_256).[t+1] (ws_opaque block (t+1)))
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef' = sha256_rnds2_spec_quad32 cdgh abef wk in
hash2 == make_hash abef' abef))
=
lemma_rnds2_spec_quad32_is_shuffle_core_x2 abef cdgh (to_uint32 wk.lo0) (to_uint32 wk.lo1) block t;
sha256_rnds2_spec_update_quad32_x2_shifts abef cdgh (to_uint32 wk.lo0) (to_uint32 wk.lo1);
()
let lemma_sha256_rnds2_two_steps (abef cdgh xmm0:quad32) (t:counter) (block:block_w) : Lemma
(requires t + 1 < size_k_w_256 /\
xmm0.lo0 == add_wrap (vv (k0 SHA2_256).[t] ) (ws_opaque block t) /\
xmm0.lo1 == add_wrap (vv (k0 SHA2_256).[t+1]) (ws_opaque block (t+1)) )
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
hash2 == make_hash (sha256_rnds2_spec cdgh abef xmm0) abef))
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t] ) (ws_opaque block t);
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t+1]) (ws_opaque block (t+1));
sha256_rnds2_spec_quad32_is_shuffle_core_x2 abef cdgh xmm0 block t;
lemma_sha256_rnds2_spec_quad32 cdgh abef xmm0;
()
// Top-level proof for the SHA256_rnds2 instruction
let lemma_sha256_rnds2 (abef cdgh xmm0:quad32) (t:counter) (block:block_w) (hash_in:hash256) : Lemma
(requires t + 1 < size_k_w_256 /\
xmm0.lo0 == add_wrap (word_to_nat32 k.[t]) (ws_opaque block t) /\
xmm0.lo1 == add_wrap (word_to_nat32 k.[t+1]) (ws_opaque block (t+1)) /\
make_hash abef cdgh == Spec.Loops.repeat_range 0 t (shuffle_core_opaque block) hash_in
)
(ensures make_hash (sha256_rnds2_spec cdgh abef xmm0) abef ==
Spec.Loops.repeat_range 0 (t+2) (shuffle_core_opaque block) hash_in)
=
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t] ) (ws_opaque block t);
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t+1]) (ws_opaque block (t+1));
lemma_sha256_rnds2_two_steps abef cdgh xmm0 t block;
Spec.Loops.repeat_range_induction 0 (t + 1) (shuffle_core_opaque block) hash_in;
Spec.Loops.repeat_range_induction 0 (t + 2) (shuffle_core_opaque block) hash_in;
()
(* Proof work for the SHA256_msg* instructions *)
let _sigma0_quad32 (q:quad32) : quad32 =
Mkfour (vv (_sigma0 SHA2_256 (to_uint32 q.lo0)))
(vv (_sigma0 SHA2_256 (to_uint32 q.lo1)))
(vv (_sigma0 SHA2_256 (to_uint32 q.hi2)))
(vv (_sigma0 SHA2_256 (to_uint32 q.hi3)))
let _sigma1_quad32 (q:quad32) : quad32 =
Mkfour (vv (_sigma1 SHA2_256 (to_uint32 q.lo0)))
(vv (_sigma1 SHA2_256 (to_uint32 q.lo1)))
(vv (_sigma1 SHA2_256 (to_uint32 q.hi2)))
(vv (_sigma1 SHA2_256 (to_uint32 q.hi3)))
let ws_partial_def (t:counter) (block:block_w) : quad32 =
if 16 <= t && t < size_k_w_256 then
(let init = ws_quad32 (t-16) block in
let sigma0_in = ws_quad32 (t-15) block in
let sigma0_out = _sigma0_quad32 sigma0_in in
add_wrap_quad32 init sigma0_out)
else
Mkfour 0 0 0 0
let add_mod_quad32 (q0 q1:quad32) : quad32 =
Mkfour (vv (add_mod (to_uint32 q0.lo0) (to_uint32 q1.lo0)))
(vv (add_mod (to_uint32 q0.lo1) (to_uint32 q1.lo1)))
(vv (add_mod (to_uint32 q0.hi2) (to_uint32 q1.hi2)))
(vv (add_mod (to_uint32 q0.hi3) (to_uint32 q1.hi3)))
let lemma_add_wrap_quad32_is_add_mod_quad32 (q0 q1:quad32) :
Lemma (add_mod_quad32 q0 q1 == add_wrap_quad32 q0 q1)
=
FStar.Classical.forall_intro_2 lemma_add_wrap_is_add_mod;
()
#reset-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 30"
// Top-level proof for the SHA256_msg1 instruction
let lemma_sha256_msg1 (dst src:quad32) (t:counter) (block:block_w) : Lemma
(requires 16 <= t /\ t < size_k_w(SHA2_256) /\
dst == ws_quad32 (t-16) block /\
src.lo0 == ws_opaque block (t-12))
(ensures sha256_msg1_spec dst src == ws_partial t block)
=
sha256_msg1_spec_reveal ();
let init = ws_quad32 (t-16) block in
let sigma0_in = ws_quad32 (t-15) block in
let sigma0_out = _sigma0_quad32 sigma0_in in
lemma_add_wrap_quad32_is_add_mod_quad32 init sigma0_out;
ws_partial_reveal ();
()
#reset-options "--max_fuel 0 --max_ifuel 0" | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt32.t -> b: FStar.UInt32.t -> c: FStar.UInt32.t -> d: FStar.UInt32.t
-> FStar.Pervasives.Lemma (ensures a +. b +. c +. d == d +. c +. b +. a) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.UInt32.t",
"FStar.Calc.calc_finish",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.eq2",
"Lib.IntTypes.op_Plus_Dot",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"Vale.SHA.SHA_helpers.lemma_add_mod_commutes",
"Vale.SHA.SHA_helpers.lemma_add_mod_associates_U32",
"Prims.l_True",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_add_mod_ws_rearrangement (a b c d: UInt32.t)
: Lemma (let open Lib.IntTypes in a +. b +. c +. d == d +. c +. b +. a) =
| let open Lib.IntTypes in
calc ( == ) {
a +. b +. c +. d;
( == ) { () }
(((a +. b) +. c) +. d);
( == ) { (lemma_add_mod_commutes ((a +. b) +. c) d;
lemma_add_mod_commutes (a +. b) c;
lemma_add_mod_commutes a b) }
d +. (c +. (b +. a));
( == ) { (lemma_add_mod_associates_U32 d c (b +. a);
lemma_add_mod_associates_U32 (d +. c) b a) }
(((d +. c) +. b) +. a);
} | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.ws_computed_quad32 | val ws_computed_quad32 (t: counter{t < size_k_w_256 - 3}) (block: block_w) : quad32 | val ws_computed_quad32 (t: counter{t < size_k_w_256 - 3}) (block: block_w) : quad32 | let ws_computed_quad32 (t:counter{t < size_k_w_256 - 3}) (block:block_w) : quad32 =
Mkfour (vv (ws_computed block t))
(vv (ws_computed block (t+1)))
(vv (ws_computed block (t+2)))
(vv (ws_computed block (t+3))) | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 524,
"start_col": 0,
"start_line": 520
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y))
let word_to_nat32 = vv
let nat32_to_word = to_uint32
let byte_to_nat8 = UInt8.v
let nat8_to_byte = UInt8.uint_to_t
let make_hash_def (abef cdgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abef.hi3 /\
hash.[1] == to_uint32 abef.hi2 /\
hash.[2] == to_uint32 cdgh.hi3 /\
hash.[3] == to_uint32 cdgh.hi2 /\
hash.[4] == to_uint32 abef.lo1 /\
hash.[5] == to_uint32 abef.lo0 /\
hash.[6] == to_uint32 cdgh.lo1 /\
hash.[7] == to_uint32 cdgh.lo0
} ) =
let a = to_uint32 abef.hi3 in
let b = to_uint32 abef.hi2 in
let c = to_uint32 cdgh.hi3 in
let d = to_uint32 cdgh.hi2 in
let e = to_uint32 abef.lo1 in
let f = to_uint32 abef.lo0 in
let g = to_uint32 cdgh.lo1 in
let h = to_uint32 cdgh.lo0 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
//assert_norm (index hash 2 == c);
hash
[@"opaque_to_smt"] let make_hash = opaque_make make_hash_def
irreducible let make_hash_reveal = opaque_revealer (`%make_hash) make_hash make_hash_def
let make_ordered_hash_def (abcd efgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abcd.lo0 /\
hash.[1] == to_uint32 abcd.lo1 /\
hash.[2] == to_uint32 abcd.hi2 /\
hash.[3] == to_uint32 abcd.hi3 /\
hash.[4] == to_uint32 efgh.lo0 /\
hash.[5] == to_uint32 efgh.lo1 /\
hash.[6] == to_uint32 efgh.hi2 /\
hash.[7] == to_uint32 efgh.hi3
})
=
let a = to_uint32 abcd.lo0 in
let b = to_uint32 abcd.lo1 in
let c = to_uint32 abcd.hi2 in
let d = to_uint32 abcd.hi3 in
let e = to_uint32 efgh.lo0 in
let f = to_uint32 efgh.lo1 in
let g = to_uint32 efgh.hi2 in
let h = to_uint32 efgh.hi3 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
hash
[@"opaque_to_smt"] let make_ordered_hash = opaque_make make_ordered_hash_def
irreducible let make_ordered_hash_reveal = opaque_revealer (`%make_ordered_hash) make_ordered_hash make_ordered_hash_def
let shuffle_core_properties (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}) :
Lemma(let h = shuffle_core_opaque block hash t in
let open Lib.IntTypes in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
h.[0] == t1 +. t2 /\
h.[1] == a0 /\
h.[2] == b0 /\
h.[3] == c0 /\
h.[4] == d0 +. t1 /\
h.[5] == e0 /\
h.[6] == f0 /\
h.[7] == g0)
=
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
let h = shuffle_core SHA2_256 block hash t in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
let l = [ t1 +. t2; a0; b0; c0; d0 +. t1; e0; f0; g0 ] in
assert (h == seq_of_list l);
elim_of_list l;
()
let sha256_rnds2_spec_update_quad32 (abef cdgh:quad32) (wk:UInt32.t) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let a', b', c', d', e', f', g', h' = sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3] hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let abef' = Mkfour (vv f') (vv e') (vv b') (vv a') in
let cdgh' = Mkfour (vv h') (vv g') (vv d') (vv c') in
(abef', cdgh')
let sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) : quad32 =
let abef', cdgh' = sha256_rnds2_spec_update_quad32 src2 src1 (to_uint32 wk.lo0) in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' (to_uint32 wk.lo1) in
abef''
let lemma_sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) :
Lemma (sha256_rnds2_spec src1 src2 wk == sha256_rnds2_spec_quad32 src1 src2 wk)
=
sha256_rnds2_spec_reveal ();
()
let lemma_add_mod_commutes (x y:UInt32.t) :
Lemma (add_mod x y == add_mod y x)
=
()
(*
let lemma_add_mod32_associates (x y z:int) :
Lemma ( ((x + y % pow2_32) + z) % pow2_32 == (x + ((y + z) % pow2_32)) % pow2_32 )
=
()
*)
let lemma_add_mod_associates_U32 (x y z:UInt32.t) :
Lemma (add_mod x (add_mod y z) == add_mod (add_mod x y) z)
=
let open Lib.IntTypes in
calc (==) {
v (x +. (y +. z));
(==) { }
(v x + (v y + v z) % pow2 32) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v x) (v y + v z) (pow2 32) }
((v x + v y) + v z) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v z) (v x + v y) (pow2 32) }
((v x + v y) % pow2 32 + v z) % pow2 32;
(==) { }
v ((x +. y) +. z);
};
v_inj (x +. (y +. z)) ((x +. y) +. z)
(*
assert_norm (pow2 32 == pow2_32);
//assert (add_mod y z == to_uint32 ((vv y + vv z) % pow2_32));
//assert (add_mod x (add_mod y z) == to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32));
lemma_add_mod32_associates (vv x) (vv y) (vv z);
//assert (to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32) ==
// to_uint32 (((vv x + vv y % pow2_32) + vv z) % pow2_32));
*)
#reset-options "--max_fuel 0 --max_ifuel 0"
let lemma_add_wrap_is_add_mod (n0 n1:nat32) :
Lemma (add_wrap n0 n1 == vv (add_mod (to_uint32 n0) (to_uint32 n1)))
=
assert_norm (pow2 32 == pow2_32);
()
let add_wrap_commutes (x y:nat32) :
Lemma(add_wrap x y == add_wrap y x)
=
()
// Walk F* through the math steps required to rearrange all of the add_mods
let lemma_add_mod_a (a b c d e f g h wk:UInt32.t) :
Lemma ( let u = add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk
(add_mod h
(add_mod (_Maj SHA2_256 a b c)
(_Sigma0 SHA2_256 a))))) in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
u == core)
=
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
lemma_add_mod_commutes (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c);
assert (t2 == add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
assert (t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
assert (core == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
// ==> add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk)
lemma_add_mod_commutes (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g);
// ==> add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk)
lemma_add_mod_associates_U32 (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)));
assert (core == add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)))));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
()
let lemma_add_mod_e (a b c d e f g h wk:UInt32.t) :
Lemma ( let u = add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk
(add_mod h
d))) in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
u == core)
=
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
// t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_commutes d t1;
// core == add_mod t1 d
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
assert (t1 == add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h);
lemma_add_mod_associates_U32 (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h d;
assert (core == add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) (add_mod h d));
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk (add_mod h d);
assert (core == add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) (add_mod wk (add_mod h d)));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d));
assert (core == add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d))));
()
let lemma_sha256_rnds2_spec_update_is_shuffle_core (hash:hash256) (wk:UInt32.t) (t:counter) (block:block_w) : Lemma
(requires t < size_k_w SHA2_256 /\ wk == to_uint32 (add_mod32 (k0 SHA2_256).[t] (ws_opaque block t)))
(ensures (let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash.[0] hash.[1] hash.[2] hash.[3]
hash.[4] hash.[5] hash.[6] hash.[7] wk in
let u = seq_of_list [a'; b'; c'; d'; e'; f'; g'; h'] in
let c = shuffle_core_opaque block hash t in
u == c))
=
let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash.[0] hash.[1] hash.[2] hash.[3]
hash.[4] hash.[5] hash.[6] hash.[7] wk in
let l:list Lib.IntTypes.uint32 = [a'; b'; c'; d'; e'; f'; g'; h'] in
let u:Seq.seq UInt32.t = seq_of_list l in
assert_norm (List.length l == 8);
let c = shuffle_core_opaque block hash t in
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
Pervasives.reveal_opaque (`%ws) ws;
shuffle_core_properties block hash t;
elim_of_list l;
Classical.forall_intro_3 lemma_add_mod_associates_U32;
lemma_add_mod_a hash.[0] hash.[1] hash.[2] hash.[3] hash.[4] hash.[5] hash.[6] hash.[7] wk;
lemma_add_mod_e hash.[0] hash.[1] hash.[2] hash.[3] hash.[4] hash.[5] hash.[6] hash.[7] wk
let sha256_rnds2_spec_update_core_quad32 (abef cdgh:quad32) (wk:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256}) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let abef' = Mkfour (vv hash1.[5]) (vv hash1.[4]) (vv hash1.[1]) (vv hash1.[0]) in
let cdgh' = Mkfour (vv hash1.[7]) (vv hash1.[6]) (vv hash1.[3]) (vv hash1.[2]) in
(abef', cdgh')
let lemma_rnds_quad32 (abef cdgh:quad32) (wk:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256}) : Lemma
(requires wk == to_uint32 (add_mod32 (k0 SHA2_256).[t] (ws_opaque block t)))
(ensures sha256_rnds2_spec_update_core_quad32 abef cdgh wk block t == sha256_rnds2_spec_update_quad32 abef cdgh wk)
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3]
hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let l = [a'; b'; c'; d'; e'; f'; g'; h'] in
elim_of_list l;
lemma_sha256_rnds2_spec_update_is_shuffle_core hash0 wk t block;
()
#push-options "--z3rlimit 30"
let lemma_rnds2_spec_quad32_is_shuffle_core_x2 (abef cdgh:quad32) (wk0 wk1:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256 - 1}) : Lemma
(requires vv wk0 == add_mod32 (k0 SHA2_256).[t] (ws_opaque block t) /\
vv wk1 == add_mod32 (k0 SHA2_256).[t+1] (ws_opaque block (t+1)))
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
hash2 == make_hash abef'' cdgh''))
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
lemma_rnds_quad32 abef cdgh wk0 block t;
lemma_rnds_quad32 abef' cdgh' wk1 block (t+1);
assert (equal (make_hash abef' cdgh') hash1);
assert (equal (make_hash abef'' cdgh'') hash2);
()
#pop-options
let sha256_rnds2_spec_update_quad32_x2_shifts (abef cdgh:quad32) (wk0 wk1:UInt32.t) :
Lemma ((let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
cdgh'' == abef))
=
()
let sha256_rnds2_spec_quad32_is_shuffle_core_x2 (abef cdgh wk:quad32) (block:block_w) (t:counter{t < size_k_w_256 - 1}) : Lemma
(requires wk.lo0 == add_mod32 (k0 SHA2_256).[t] (ws_opaque block t) /\
wk.lo1 == add_mod32 (k0 SHA2_256).[t+1] (ws_opaque block (t+1)))
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef' = sha256_rnds2_spec_quad32 cdgh abef wk in
hash2 == make_hash abef' abef))
=
lemma_rnds2_spec_quad32_is_shuffle_core_x2 abef cdgh (to_uint32 wk.lo0) (to_uint32 wk.lo1) block t;
sha256_rnds2_spec_update_quad32_x2_shifts abef cdgh (to_uint32 wk.lo0) (to_uint32 wk.lo1);
()
let lemma_sha256_rnds2_two_steps (abef cdgh xmm0:quad32) (t:counter) (block:block_w) : Lemma
(requires t + 1 < size_k_w_256 /\
xmm0.lo0 == add_wrap (vv (k0 SHA2_256).[t] ) (ws_opaque block t) /\
xmm0.lo1 == add_wrap (vv (k0 SHA2_256).[t+1]) (ws_opaque block (t+1)) )
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
hash2 == make_hash (sha256_rnds2_spec cdgh abef xmm0) abef))
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t] ) (ws_opaque block t);
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t+1]) (ws_opaque block (t+1));
sha256_rnds2_spec_quad32_is_shuffle_core_x2 abef cdgh xmm0 block t;
lemma_sha256_rnds2_spec_quad32 cdgh abef xmm0;
()
// Top-level proof for the SHA256_rnds2 instruction
let lemma_sha256_rnds2 (abef cdgh xmm0:quad32) (t:counter) (block:block_w) (hash_in:hash256) : Lemma
(requires t + 1 < size_k_w_256 /\
xmm0.lo0 == add_wrap (word_to_nat32 k.[t]) (ws_opaque block t) /\
xmm0.lo1 == add_wrap (word_to_nat32 k.[t+1]) (ws_opaque block (t+1)) /\
make_hash abef cdgh == Spec.Loops.repeat_range 0 t (shuffle_core_opaque block) hash_in
)
(ensures make_hash (sha256_rnds2_spec cdgh abef xmm0) abef ==
Spec.Loops.repeat_range 0 (t+2) (shuffle_core_opaque block) hash_in)
=
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t] ) (ws_opaque block t);
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t+1]) (ws_opaque block (t+1));
lemma_sha256_rnds2_two_steps abef cdgh xmm0 t block;
Spec.Loops.repeat_range_induction 0 (t + 1) (shuffle_core_opaque block) hash_in;
Spec.Loops.repeat_range_induction 0 (t + 2) (shuffle_core_opaque block) hash_in;
()
(* Proof work for the SHA256_msg* instructions *)
let _sigma0_quad32 (q:quad32) : quad32 =
Mkfour (vv (_sigma0 SHA2_256 (to_uint32 q.lo0)))
(vv (_sigma0 SHA2_256 (to_uint32 q.lo1)))
(vv (_sigma0 SHA2_256 (to_uint32 q.hi2)))
(vv (_sigma0 SHA2_256 (to_uint32 q.hi3)))
let _sigma1_quad32 (q:quad32) : quad32 =
Mkfour (vv (_sigma1 SHA2_256 (to_uint32 q.lo0)))
(vv (_sigma1 SHA2_256 (to_uint32 q.lo1)))
(vv (_sigma1 SHA2_256 (to_uint32 q.hi2)))
(vv (_sigma1 SHA2_256 (to_uint32 q.hi3)))
let ws_partial_def (t:counter) (block:block_w) : quad32 =
if 16 <= t && t < size_k_w_256 then
(let init = ws_quad32 (t-16) block in
let sigma0_in = ws_quad32 (t-15) block in
let sigma0_out = _sigma0_quad32 sigma0_in in
add_wrap_quad32 init sigma0_out)
else
Mkfour 0 0 0 0
let add_mod_quad32 (q0 q1:quad32) : quad32 =
Mkfour (vv (add_mod (to_uint32 q0.lo0) (to_uint32 q1.lo0)))
(vv (add_mod (to_uint32 q0.lo1) (to_uint32 q1.lo1)))
(vv (add_mod (to_uint32 q0.hi2) (to_uint32 q1.hi2)))
(vv (add_mod (to_uint32 q0.hi3) (to_uint32 q1.hi3)))
let lemma_add_wrap_quad32_is_add_mod_quad32 (q0 q1:quad32) :
Lemma (add_mod_quad32 q0 q1 == add_wrap_quad32 q0 q1)
=
FStar.Classical.forall_intro_2 lemma_add_wrap_is_add_mod;
()
#reset-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 30"
// Top-level proof for the SHA256_msg1 instruction
let lemma_sha256_msg1 (dst src:quad32) (t:counter) (block:block_w) : Lemma
(requires 16 <= t /\ t < size_k_w(SHA2_256) /\
dst == ws_quad32 (t-16) block /\
src.lo0 == ws_opaque block (t-12))
(ensures sha256_msg1_spec dst src == ws_partial t block)
=
sha256_msg1_spec_reveal ();
let init = ws_quad32 (t-16) block in
let sigma0_in = ws_quad32 (t-15) block in
let sigma0_out = _sigma0_quad32 sigma0_in in
lemma_add_wrap_quad32_is_add_mod_quad32 init sigma0_out;
ws_partial_reveal ();
()
#reset-options "--max_fuel 0 --max_ifuel 0"
let lemma_add_mod_ws_rearrangement (a b c d:UInt32.t) :
Lemma (let open Lib.IntTypes in
a +. b +. c +. d == d +. c +. b +. a)
=
let open Lib.IntTypes in
calc (==) {
a +. b +. c +. d;
(==) {}
(((a +. b) +. c) +. d);
(==) { lemma_add_mod_commutes ((a +. b) +. c) d;
lemma_add_mod_commutes (a +. b) c;
lemma_add_mod_commutes a b
}
d +. (c +. (b +. a));
(==) { lemma_add_mod_associates_U32 d c (b +. a);
lemma_add_mod_associates_U32 (d +. c) b a}
(((d +. c) +. b) +. a);
}
let ws_computed (b:block_w) (t:counter{t < size_k_w_256}): Tot (UInt32.t) =
if t < block_word_length SHA2_256 then to_uint32 (ws_opaque b t)
else
let t16 = to_uint32 (ws_opaque b (t - 16)) in
let t15 = to_uint32 (ws_opaque b (t - 15)) in
let t7 = to_uint32 (ws_opaque b (t - 7)) in
let t2 = to_uint32 (ws_opaque b (t - 2)) in
let s1 = _sigma1 SHA2_256 t2 in
let s0 = _sigma0 SHA2_256 t15 in
let open Lib.IntTypes in
(t16 +. s0 +. t7 +. s1)
#push-options "--max_fuel 1"
let lemma_ws_computed_is_ws (b:block_w) (t:counter{t < size_k_w_256}) :
Lemma (ws_computed b t == ws SHA2_256 b t)
=
Pervasives.reveal_opaque (`%ws) ws;
if t < block_word_length SHA2_256 then (
assert (vv (ws_computed b t) == ws_opaque b t);
assert (to_uint32 (ws_opaque b t) == ws SHA2_256 b t);
()
) else (
let t16 = to_uint32 (ws_opaque b (t - 16)) in
let t15 = to_uint32 (ws_opaque b (t - 15)) in
let t7 = to_uint32 (ws_opaque b (t - 7)) in
let t2 = to_uint32 (ws_opaque b (t - 2)) in
let s1 = _sigma1 SHA2_256 t2 in
let s0 = _sigma0 SHA2_256 t15 in
lemma_add_mod_ws_rearrangement s1 t7 s0 t16;
()
)
#pop-options
let lemma_ws_computed_is_ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) :
Lemma (vv (ws_computed b t) == ws_opaque b t)
=
lemma_ws_computed_is_ws b t;
Pervasives.reveal_opaque (`%ws) ws;
() | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t: Vale.SHA.SHA_helpers.counter{t < Vale.SHA.SHA_helpers.size_k_w_256 - 3} ->
block: Vale.SHA.SHA_helpers.block_w
-> Vale.Def.Types_s.quad32 | Prims.Tot | [
"total"
] | [] | [
"Vale.SHA.SHA_helpers.counter",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Subtraction",
"Vale.SHA.SHA_helpers.size_k_w_256",
"Vale.SHA.SHA_helpers.block_w",
"Vale.Def.Words_s.Mkfour",
"Vale.Def.Types_s.nat32",
"Vale.SHA.SHA_helpers.vv",
"Vale.SHA.SHA_helpers.ws_computed",
"Prims.op_Addition",
"Vale.Def.Types_s.quad32"
] | [] | false | false | false | false | false | let ws_computed_quad32 (t: counter{t < size_k_w_256 - 3}) (block: block_w) : quad32 =
| Mkfour (vv (ws_computed block t))
(vv (ws_computed block (t + 1)))
(vv (ws_computed block (t + 2)))
(vv (ws_computed block (t + 3))) | false |
Vale.SHA.SHA_helpers.fst | Vale.SHA.SHA_helpers.shuffle_opaque | val shuffle_opaque : a: Spec.Hash.Definitions.sha2_alg ->
hash: Spec.Hash.Definitions.words_state a ->
block: Spec.SHA2.block_w a
-> Spec.Hash.Definitions.words_state a | let shuffle_opaque = shuffle | {
"file_name": "vale/code/crypto/sha/Vale.SHA.SHA_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 649,
"start_col": 7,
"start_line": 649
} | module Vale.SHA.SHA_helpers
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Spec.SHA2
open Spec.SHA2.Lemmas
open Spec.Agile.Hash
open Spec.Hash.Definitions
open Spec.Hash.Lemmas
open Vale.X64.CryptoInstructions_s
open Vale.Def.Types_s
open Vale.Def.Words_s
open FStar.Seq
open FStar.UInt32 // Interop with UInt-based SHA spec
open Vale.Arch.Types
friend Spec.SHA2
friend Spec.SHA2.Lemmas
friend Vale.X64.CryptoInstructions_s
#reset-options "--max_fuel 0 --max_ifuel 0"
// Define these specific converters here, so that F* only reasons about
// the correctness of the conversion once, rather that at every call site
let vv (u:Lib.IntTypes.uint32) : nat32 = Lib.IntTypes.v u
let to_uint32 (n:nat32) : Lib.IntTypes.uint32 = Lib.IntTypes.u32 n
let word = Lib.IntTypes.uint32
let k = (Spec.SHA2.k0 SHA2_256)
let reveal_word () = ()
val add_mod_lemma:x:Lib.IntTypes.uint32 -> y:Lib.IntTypes.uint32 ->
Lemma (add_mod x y == Lib.IntTypes.(x +. y))
[SMTPat (Lib.IntTypes.(x +. y))]
let add_mod_lemma x y = ()
unfold let ws_opaque_aux = ws
let ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) : nat32 =
vv (ws_opaque_aux SHA2_256 b t)
unfold let shuffle_core_opaque_aux = shuffle_core
let shuffle_core_opaque (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}):hash256 =
shuffle_core_opaque_aux SHA2_256 block hash t
[@"opaque_to_smt"] let update_multi_opaque_aux = opaque_make update_multi
irreducible let update_multi_reveal = opaque_revealer (`%update_multi_opaque_aux) update_multi_opaque_aux update_multi
let update_multi_opaque (hash:hash256) (blocks:bytes_blocks):hash256 =
(update_multi_opaque_aux SHA2_256 hash () blocks)
let update_multi_transparent (hash:hash256) (blocks:bytes_blocks) =
update_multi SHA2_256 hash () blocks
let add_mod32 (x:word) (y:nat32) : nat32 = vv (add_mod x (to_uint32 y))
let word_to_nat32 = vv
let nat32_to_word = to_uint32
let byte_to_nat8 = UInt8.v
let nat8_to_byte = UInt8.uint_to_t
let make_hash_def (abef cdgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abef.hi3 /\
hash.[1] == to_uint32 abef.hi2 /\
hash.[2] == to_uint32 cdgh.hi3 /\
hash.[3] == to_uint32 cdgh.hi2 /\
hash.[4] == to_uint32 abef.lo1 /\
hash.[5] == to_uint32 abef.lo0 /\
hash.[6] == to_uint32 cdgh.lo1 /\
hash.[7] == to_uint32 cdgh.lo0
} ) =
let a = to_uint32 abef.hi3 in
let b = to_uint32 abef.hi2 in
let c = to_uint32 cdgh.hi3 in
let d = to_uint32 cdgh.hi2 in
let e = to_uint32 abef.lo1 in
let f = to_uint32 abef.lo0 in
let g = to_uint32 cdgh.lo1 in
let h = to_uint32 cdgh.lo0 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
//assert_norm (index hash 2 == c);
hash
[@"opaque_to_smt"] let make_hash = opaque_make make_hash_def
irreducible let make_hash_reveal = opaque_revealer (`%make_hash) make_hash make_hash_def
let make_ordered_hash_def (abcd efgh:quad32) :
(hash:words_state SHA2_256 {
length hash == 8 /\
hash.[0] == to_uint32 abcd.lo0 /\
hash.[1] == to_uint32 abcd.lo1 /\
hash.[2] == to_uint32 abcd.hi2 /\
hash.[3] == to_uint32 abcd.hi3 /\
hash.[4] == to_uint32 efgh.lo0 /\
hash.[5] == to_uint32 efgh.lo1 /\
hash.[6] == to_uint32 efgh.hi2 /\
hash.[7] == to_uint32 efgh.hi3
})
=
let a = to_uint32 abcd.lo0 in
let b = to_uint32 abcd.lo1 in
let c = to_uint32 abcd.hi2 in
let d = to_uint32 abcd.hi3 in
let e = to_uint32 efgh.lo0 in
let f = to_uint32 efgh.lo1 in
let g = to_uint32 efgh.hi2 in
let h = to_uint32 efgh.hi3 in
let l = [a; b; c; d; e; f; g; h] in
assert_norm (List.length l == 8);
let hash = seq_of_list l in
assert (length hash == 8);
elim_of_list l;
hash
[@"opaque_to_smt"] let make_ordered_hash = opaque_make make_ordered_hash_def
irreducible let make_ordered_hash_reveal = opaque_revealer (`%make_ordered_hash) make_ordered_hash make_ordered_hash_def
let shuffle_core_properties (block:block_w) (hash:hash256) (t:counter{t < size_k_w_256}) :
Lemma(let h = shuffle_core_opaque block hash t in
let open Lib.IntTypes in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
h.[0] == t1 +. t2 /\
h.[1] == a0 /\
h.[2] == b0 /\
h.[3] == c0 /\
h.[4] == d0 +. t1 /\
h.[5] == e0 /\
h.[6] == f0 /\
h.[7] == g0)
=
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
let h = shuffle_core SHA2_256 block hash t in
let a0 = hash.[0] in
let b0 = hash.[1] in
let c0 = hash.[2] in
let d0 = hash.[3] in
let e0 = hash.[4] in
let f0 = hash.[5] in
let g0 = hash.[6] in
let h0 = hash.[7] in
let t1 = h0 +. (_Sigma1 SHA2_256 e0) +. (_Ch SHA2_256 e0 f0 g0) +. (k0 SHA2_256).[t] +. (ws SHA2_256 block t) in
let t2 = (_Sigma0 SHA2_256 a0) +. (_Maj SHA2_256 a0 b0 c0) in
let l = [ t1 +. t2; a0; b0; c0; d0 +. t1; e0; f0; g0 ] in
assert (h == seq_of_list l);
elim_of_list l;
()
let sha256_rnds2_spec_update_quad32 (abef cdgh:quad32) (wk:UInt32.t) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let a', b', c', d', e', f', g', h' = sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3] hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let abef' = Mkfour (vv f') (vv e') (vv b') (vv a') in
let cdgh' = Mkfour (vv h') (vv g') (vv d') (vv c') in
(abef', cdgh')
let sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) : quad32 =
let abef', cdgh' = sha256_rnds2_spec_update_quad32 src2 src1 (to_uint32 wk.lo0) in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' (to_uint32 wk.lo1) in
abef''
let lemma_sha256_rnds2_spec_quad32 (src1 src2 wk:quad32) :
Lemma (sha256_rnds2_spec src1 src2 wk == sha256_rnds2_spec_quad32 src1 src2 wk)
=
sha256_rnds2_spec_reveal ();
()
let lemma_add_mod_commutes (x y:UInt32.t) :
Lemma (add_mod x y == add_mod y x)
=
()
(*
let lemma_add_mod32_associates (x y z:int) :
Lemma ( ((x + y % pow2_32) + z) % pow2_32 == (x + ((y + z) % pow2_32)) % pow2_32 )
=
()
*)
let lemma_add_mod_associates_U32 (x y z:UInt32.t) :
Lemma (add_mod x (add_mod y z) == add_mod (add_mod x y) z)
=
let open Lib.IntTypes in
calc (==) {
v (x +. (y +. z));
(==) { }
(v x + (v y + v z) % pow2 32) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v x) (v y + v z) (pow2 32) }
((v x + v y) + v z) % pow2 32;
(==) { FStar.Math.Lemmas.lemma_mod_add_distr (v z) (v x + v y) (pow2 32) }
((v x + v y) % pow2 32 + v z) % pow2 32;
(==) { }
v ((x +. y) +. z);
};
v_inj (x +. (y +. z)) ((x +. y) +. z)
(*
assert_norm (pow2 32 == pow2_32);
//assert (add_mod y z == to_uint32 ((vv y + vv z) % pow2_32));
//assert (add_mod x (add_mod y z) == to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32));
lemma_add_mod32_associates (vv x) (vv y) (vv z);
//assert (to_uint32 ((vv x + vv (to_uint32 ((vv y + vv z) % pow2_32))) % pow2_32) ==
// to_uint32 (((vv x + vv y % pow2_32) + vv z) % pow2_32));
*)
#reset-options "--max_fuel 0 --max_ifuel 0"
let lemma_add_wrap_is_add_mod (n0 n1:nat32) :
Lemma (add_wrap n0 n1 == vv (add_mod (to_uint32 n0) (to_uint32 n1)))
=
assert_norm (pow2 32 == pow2_32);
()
let add_wrap_commutes (x y:nat32) :
Lemma(add_wrap x y == add_wrap y x)
=
()
// Walk F* through the math steps required to rearrange all of the add_mods
let lemma_add_mod_a (a b c d e f g h wk:UInt32.t) :
Lemma ( let u = add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk
(add_mod h
(add_mod (_Maj SHA2_256 a b c)
(_Sigma0 SHA2_256 a))))) in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
u == core)
=
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let t2 = add_mod (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c) in
let core = add_mod t1 t2 in
lemma_add_mod_commutes (_Sigma0 SHA2_256 a) (_Maj SHA2_256 a b c);
assert (t2 == add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
assert (t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a));
assert (core == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
// ==> add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk)
lemma_add_mod_commutes (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g);
// ==> add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk)
lemma_add_mod_associates_U32 (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)));
assert (core == add_mod (add_mod (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e)) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a)))));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h (add_mod (_Maj SHA2_256 a b c) (_Sigma0 SHA2_256 a))));
()
let lemma_add_mod_e (a b c d e f g h wk:UInt32.t) :
Lemma ( let u = add_mod (_Ch SHA2_256 e f g)
(add_mod (_Sigma1 SHA2_256 e)
(add_mod wk
(add_mod h
d))) in
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
u == core)
=
let t1 = add_mod h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) in
let core = add_mod d t1 in
lemma_add_mod_commutes h (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk));
// t1 == add_mod (add_mod (_Sigma1 SHA2_256 e) (add_mod (_Ch SHA2_256 e f g) wk)) h);
lemma_add_mod_commutes d t1;
// core == add_mod t1 d
lemma_add_mod_associates_U32 (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g) wk;
assert (t1 == add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h);
lemma_add_mod_associates_U32 (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) h d;
assert (core == add_mod (add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk) (add_mod h d));
lemma_add_mod_associates_U32 (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) wk (add_mod h d);
assert (core == add_mod (add_mod (_Sigma1 SHA2_256 e) (_Ch SHA2_256 e f g)) (add_mod wk (add_mod h d)));
lemma_add_mod_associates_U32 (_Ch SHA2_256 e f g) (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d));
assert (core == add_mod (_Ch SHA2_256 e f g) (add_mod (_Sigma1 SHA2_256 e) (add_mod wk (add_mod h d))));
()
let lemma_sha256_rnds2_spec_update_is_shuffle_core (hash:hash256) (wk:UInt32.t) (t:counter) (block:block_w) : Lemma
(requires t < size_k_w SHA2_256 /\ wk == to_uint32 (add_mod32 (k0 SHA2_256).[t] (ws_opaque block t)))
(ensures (let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash.[0] hash.[1] hash.[2] hash.[3]
hash.[4] hash.[5] hash.[6] hash.[7] wk in
let u = seq_of_list [a'; b'; c'; d'; e'; f'; g'; h'] in
let c = shuffle_core_opaque block hash t in
u == c))
=
let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash.[0] hash.[1] hash.[2] hash.[3]
hash.[4] hash.[5] hash.[6] hash.[7] wk in
let l:list Lib.IntTypes.uint32 = [a'; b'; c'; d'; e'; f'; g'; h'] in
let u:Seq.seq UInt32.t = seq_of_list l in
assert_norm (List.length l == 8);
let c = shuffle_core_opaque block hash t in
Pervasives.reveal_opaque (`%shuffle_core) shuffle_core;
Pervasives.reveal_opaque (`%ws) ws;
shuffle_core_properties block hash t;
elim_of_list l;
Classical.forall_intro_3 lemma_add_mod_associates_U32;
lemma_add_mod_a hash.[0] hash.[1] hash.[2] hash.[3] hash.[4] hash.[5] hash.[6] hash.[7] wk;
lemma_add_mod_e hash.[0] hash.[1] hash.[2] hash.[3] hash.[4] hash.[5] hash.[6] hash.[7] wk
let sha256_rnds2_spec_update_core_quad32 (abef cdgh:quad32) (wk:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256}) : (quad32 & quad32) =
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let abef' = Mkfour (vv hash1.[5]) (vv hash1.[4]) (vv hash1.[1]) (vv hash1.[0]) in
let cdgh' = Mkfour (vv hash1.[7]) (vv hash1.[6]) (vv hash1.[3]) (vv hash1.[2]) in
(abef', cdgh')
let lemma_rnds_quad32 (abef cdgh:quad32) (wk:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256}) : Lemma
(requires wk == to_uint32 (add_mod32 (k0 SHA2_256).[t] (ws_opaque block t)))
(ensures sha256_rnds2_spec_update_core_quad32 abef cdgh wk block t == sha256_rnds2_spec_update_quad32 abef cdgh wk)
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let a', b', c', d', e', f', g', h' =
sha256_rnds2_spec_update hash0.[0] hash0.[1] hash0.[2] hash0.[3]
hash0.[4] hash0.[5] hash0.[6] hash0.[7] wk in
let l = [a'; b'; c'; d'; e'; f'; g'; h'] in
elim_of_list l;
lemma_sha256_rnds2_spec_update_is_shuffle_core hash0 wk t block;
()
#push-options "--z3rlimit 30"
let lemma_rnds2_spec_quad32_is_shuffle_core_x2 (abef cdgh:quad32) (wk0 wk1:UInt32.t) (block:block_w) (t:counter{t < size_k_w_256 - 1}) : Lemma
(requires vv wk0 == add_mod32 (k0 SHA2_256).[t] (ws_opaque block t) /\
vv wk1 == add_mod32 (k0 SHA2_256).[t+1] (ws_opaque block (t+1)))
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
hash2 == make_hash abef'' cdgh''))
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
lemma_rnds_quad32 abef cdgh wk0 block t;
lemma_rnds_quad32 abef' cdgh' wk1 block (t+1);
assert (equal (make_hash abef' cdgh') hash1);
assert (equal (make_hash abef'' cdgh'') hash2);
()
#pop-options
let sha256_rnds2_spec_update_quad32_x2_shifts (abef cdgh:quad32) (wk0 wk1:UInt32.t) :
Lemma ((let abef', cdgh' = sha256_rnds2_spec_update_quad32 abef cdgh wk0 in
let abef'', cdgh'' = sha256_rnds2_spec_update_quad32 abef' cdgh' wk1 in
cdgh'' == abef))
=
()
let sha256_rnds2_spec_quad32_is_shuffle_core_x2 (abef cdgh wk:quad32) (block:block_w) (t:counter{t < size_k_w_256 - 1}) : Lemma
(requires wk.lo0 == add_mod32 (k0 SHA2_256).[t] (ws_opaque block t) /\
wk.lo1 == add_mod32 (k0 SHA2_256).[t+1] (ws_opaque block (t+1)))
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
let abef' = sha256_rnds2_spec_quad32 cdgh abef wk in
hash2 == make_hash abef' abef))
=
lemma_rnds2_spec_quad32_is_shuffle_core_x2 abef cdgh (to_uint32 wk.lo0) (to_uint32 wk.lo1) block t;
sha256_rnds2_spec_update_quad32_x2_shifts abef cdgh (to_uint32 wk.lo0) (to_uint32 wk.lo1);
()
let lemma_sha256_rnds2_two_steps (abef cdgh xmm0:quad32) (t:counter) (block:block_w) : Lemma
(requires t + 1 < size_k_w_256 /\
xmm0.lo0 == add_wrap (vv (k0 SHA2_256).[t] ) (ws_opaque block t) /\
xmm0.lo1 == add_wrap (vv (k0 SHA2_256).[t+1]) (ws_opaque block (t+1)) )
(ensures (let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
hash2 == make_hash (sha256_rnds2_spec cdgh abef xmm0) abef))
=
let hash0 = make_hash abef cdgh in
let hash1 = shuffle_core_opaque block hash0 t in
let hash2 = shuffle_core_opaque block hash1 (t + 1) in
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t] ) (ws_opaque block t);
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t+1]) (ws_opaque block (t+1));
sha256_rnds2_spec_quad32_is_shuffle_core_x2 abef cdgh xmm0 block t;
lemma_sha256_rnds2_spec_quad32 cdgh abef xmm0;
()
// Top-level proof for the SHA256_rnds2 instruction
let lemma_sha256_rnds2 (abef cdgh xmm0:quad32) (t:counter) (block:block_w) (hash_in:hash256) : Lemma
(requires t + 1 < size_k_w_256 /\
xmm0.lo0 == add_wrap (word_to_nat32 k.[t]) (ws_opaque block t) /\
xmm0.lo1 == add_wrap (word_to_nat32 k.[t+1]) (ws_opaque block (t+1)) /\
make_hash abef cdgh == Spec.Loops.repeat_range 0 t (shuffle_core_opaque block) hash_in
)
(ensures make_hash (sha256_rnds2_spec cdgh abef xmm0) abef ==
Spec.Loops.repeat_range 0 (t+2) (shuffle_core_opaque block) hash_in)
=
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t] ) (ws_opaque block t);
lemma_add_wrap_is_add_mod (vv (k0 SHA2_256).[t+1]) (ws_opaque block (t+1));
lemma_sha256_rnds2_two_steps abef cdgh xmm0 t block;
Spec.Loops.repeat_range_induction 0 (t + 1) (shuffle_core_opaque block) hash_in;
Spec.Loops.repeat_range_induction 0 (t + 2) (shuffle_core_opaque block) hash_in;
()
(* Proof work for the SHA256_msg* instructions *)
let _sigma0_quad32 (q:quad32) : quad32 =
Mkfour (vv (_sigma0 SHA2_256 (to_uint32 q.lo0)))
(vv (_sigma0 SHA2_256 (to_uint32 q.lo1)))
(vv (_sigma0 SHA2_256 (to_uint32 q.hi2)))
(vv (_sigma0 SHA2_256 (to_uint32 q.hi3)))
let _sigma1_quad32 (q:quad32) : quad32 =
Mkfour (vv (_sigma1 SHA2_256 (to_uint32 q.lo0)))
(vv (_sigma1 SHA2_256 (to_uint32 q.lo1)))
(vv (_sigma1 SHA2_256 (to_uint32 q.hi2)))
(vv (_sigma1 SHA2_256 (to_uint32 q.hi3)))
let ws_partial_def (t:counter) (block:block_w) : quad32 =
if 16 <= t && t < size_k_w_256 then
(let init = ws_quad32 (t-16) block in
let sigma0_in = ws_quad32 (t-15) block in
let sigma0_out = _sigma0_quad32 sigma0_in in
add_wrap_quad32 init sigma0_out)
else
Mkfour 0 0 0 0
let add_mod_quad32 (q0 q1:quad32) : quad32 =
Mkfour (vv (add_mod (to_uint32 q0.lo0) (to_uint32 q1.lo0)))
(vv (add_mod (to_uint32 q0.lo1) (to_uint32 q1.lo1)))
(vv (add_mod (to_uint32 q0.hi2) (to_uint32 q1.hi2)))
(vv (add_mod (to_uint32 q0.hi3) (to_uint32 q1.hi3)))
let lemma_add_wrap_quad32_is_add_mod_quad32 (q0 q1:quad32) :
Lemma (add_mod_quad32 q0 q1 == add_wrap_quad32 q0 q1)
=
FStar.Classical.forall_intro_2 lemma_add_wrap_is_add_mod;
()
#reset-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 30"
// Top-level proof for the SHA256_msg1 instruction
let lemma_sha256_msg1 (dst src:quad32) (t:counter) (block:block_w) : Lemma
(requires 16 <= t /\ t < size_k_w(SHA2_256) /\
dst == ws_quad32 (t-16) block /\
src.lo0 == ws_opaque block (t-12))
(ensures sha256_msg1_spec dst src == ws_partial t block)
=
sha256_msg1_spec_reveal ();
let init = ws_quad32 (t-16) block in
let sigma0_in = ws_quad32 (t-15) block in
let sigma0_out = _sigma0_quad32 sigma0_in in
lemma_add_wrap_quad32_is_add_mod_quad32 init sigma0_out;
ws_partial_reveal ();
()
#reset-options "--max_fuel 0 --max_ifuel 0"
let lemma_add_mod_ws_rearrangement (a b c d:UInt32.t) :
Lemma (let open Lib.IntTypes in
a +. b +. c +. d == d +. c +. b +. a)
=
let open Lib.IntTypes in
calc (==) {
a +. b +. c +. d;
(==) {}
(((a +. b) +. c) +. d);
(==) { lemma_add_mod_commutes ((a +. b) +. c) d;
lemma_add_mod_commutes (a +. b) c;
lemma_add_mod_commutes a b
}
d +. (c +. (b +. a));
(==) { lemma_add_mod_associates_U32 d c (b +. a);
lemma_add_mod_associates_U32 (d +. c) b a}
(((d +. c) +. b) +. a);
}
let ws_computed (b:block_w) (t:counter{t < size_k_w_256}): Tot (UInt32.t) =
if t < block_word_length SHA2_256 then to_uint32 (ws_opaque b t)
else
let t16 = to_uint32 (ws_opaque b (t - 16)) in
let t15 = to_uint32 (ws_opaque b (t - 15)) in
let t7 = to_uint32 (ws_opaque b (t - 7)) in
let t2 = to_uint32 (ws_opaque b (t - 2)) in
let s1 = _sigma1 SHA2_256 t2 in
let s0 = _sigma0 SHA2_256 t15 in
let open Lib.IntTypes in
(t16 +. s0 +. t7 +. s1)
#push-options "--max_fuel 1"
let lemma_ws_computed_is_ws (b:block_w) (t:counter{t < size_k_w_256}) :
Lemma (ws_computed b t == ws SHA2_256 b t)
=
Pervasives.reveal_opaque (`%ws) ws;
if t < block_word_length SHA2_256 then (
assert (vv (ws_computed b t) == ws_opaque b t);
assert (to_uint32 (ws_opaque b t) == ws SHA2_256 b t);
()
) else (
let t16 = to_uint32 (ws_opaque b (t - 16)) in
let t15 = to_uint32 (ws_opaque b (t - 15)) in
let t7 = to_uint32 (ws_opaque b (t - 7)) in
let t2 = to_uint32 (ws_opaque b (t - 2)) in
let s1 = _sigma1 SHA2_256 t2 in
let s0 = _sigma0 SHA2_256 t15 in
lemma_add_mod_ws_rearrangement s1 t7 s0 t16;
()
)
#pop-options
let lemma_ws_computed_is_ws_opaque (b:block_w) (t:counter{t < size_k_w_256}) :
Lemma (vv (ws_computed b t) == ws_opaque b t)
=
lemma_ws_computed_is_ws b t;
Pervasives.reveal_opaque (`%ws) ws;
()
let ws_computed_quad32 (t:counter{t < size_k_w_256 - 3}) (block:block_w) : quad32 =
Mkfour (vv (ws_computed block t))
(vv (ws_computed block (t+1)))
(vv (ws_computed block (t+2)))
(vv (ws_computed block (t+3)))
let lemma_ws_computed_is_ws_quad32 (b:block_w) (t:counter{t < size_k_w_256 - 3}) :
Lemma (ws_computed_quad32 t b == ws_quad32 t b)
=
let w = ws_computed_quad32 t b in
let w' = ws_quad32 t b in
lemma_ws_computed_is_ws_opaque b t;
lemma_ws_computed_is_ws_opaque b (t+1);
lemma_ws_computed_is_ws_opaque b (t+2);
lemma_ws_computed_is_ws_opaque b (t+3);
()
#push-options "--z3rlimit 30"
let lemma_ws_computed_quad32 (t:counter{16 <= t /\ t < size_k_w_256 - 4}) (block:block_w) :
Lemma (let t_minus_16 = ws_quad32 (t-16) block in
let t_minus_15 = ws_quad32 (t-15) block in
let t_minus_7 = ws_quad32 (t - 7) block in
let t_minus_2 = ws_quad32 (t - 2) block in
let m1 = add_mod_quad32 t_minus_16 (_sigma0_quad32 t_minus_15) in
let m2 = add_mod_quad32 m1 t_minus_7 in
let m3 = add_mod_quad32 m2 (_sigma1_quad32 t_minus_2) in
m3 == ws_computed_quad32 t block )
=
()
#pop-options
let sha256_msg1_spec_t (t:counter{t < size_k_w_256 - 1}) (block:block_w) : quad32 =
let init = ws_quad32 t block in
let next = ws_quad32 (t + 1) block in
let msg1 = add_mod_quad32 init (_sigma0_quad32 next) in
msg1
#push-options "--ifuel 1"
let lemma_sha256_msg1_spec_t_partial (t:counter) (block:block_w) : Lemma
(requires 16 <= t /\ t < size_k_w_256 - 3)
(ensures ws_partial t block == sha256_msg1_spec_t (t-16) block)
=
ws_partial_reveal ();
let init = ws_quad32 (t-16) block in
let next = ws_quad32 (t-15) block in
lemma_add_wrap_quad32_is_add_mod_quad32 init (_sigma0_quad32 next);
()
#pop-options
let lemma_sha256_msg1_spec_t (src1 src2:quad32) (t:counter) (block:block_w) : Lemma
(requires t < size_k_w_256 - 4 /\
src1 == ws_quad32 t block /\
src2.lo0 == ws_opaque block (t+4))
(ensures sha256_msg1_spec_t t block == sha256_msg1_spec src1 src2)
=
sha256_msg1_spec_reveal ();
()
#push-options "--z3rlimit 70"
let lemma_sha256_step2 (src1 src2:quad32) (t:counter) (block:block_w) : Lemma
(requires 16 <= t /\ t < size_k_w(SHA2_256) - 3 /\
src2.hi2 == ws_opaque block (t-2) /\
src2.hi3 == ws_opaque block (t-1) /\
(let w = sha256_msg1_spec_t (t-16) block in
let mid = ws_quad32 (t-7) block in
src1 == add_mod_quad32 w mid))
(ensures sha256_msg2_spec src1 src2 == ws_computed_quad32 t block)
=
sha256_msg2_spec_reveal ();
let w = sha256_msg1_spec_t (t-16) block in
let mid = ws_quad32 (t-7) block in
let final = sha256_msg2_spec src1 src2 in
lemma_ws_computed_is_ws_opaque block (t);
lemma_ws_computed_is_ws_opaque block (t+1);
()
#pop-options
// Top-level proof for the SHA256_msg2 instruction
let lemma_sha256_msg2 (src1 src2:quad32) (t:counter) (block:block_w) : Lemma
(requires 16 <= t /\ t < size_k_w(SHA2_256) - 3 /\
(let step1 = ws_partial t block in
let t_minus_7 = ws_quad32 (t-7) block in
src1 == add_wrap_quad32 step1 t_minus_7 /\
src2.hi2 == ws_opaque block (t-2) /\
src2.hi3 == ws_opaque block (t-1)))
(ensures sha256_msg2_spec src1 src2 == ws_quad32 t block)
=
let step1 = ws_partial t block in
let t_minus_7 = ws_quad32 (t-7) block in
lemma_sha256_msg1_spec_t_partial t block;
// ==> step1 == sha256_msg1_spec_t (t-16) block
lemma_add_wrap_quad32_is_add_mod_quad32 step1 t_minus_7;
lemma_sha256_step2 src1 src2 t block;
lemma_ws_computed_is_ws_quad32 block t;
()
(* Abbreviations and lemmas for the code itself *)
#reset-options "--z3rlimit 20 --max_fuel 1"
let lemma_quads_to_block qs
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #nat32);
reveal_opaque (`%ws) ws
#reset-options "--max_fuel 0 --max_ifuel 0"
let translate_hash_update (h0 h1 h0' h1' a0 a1:quad32) : Lemma
(requires h0' == add_wrap_quad32 a0 h0 /\
h1' == add_wrap_quad32 a1 h1)
(ensures (
let h = make_hash h0 h1 in
let a = make_hash a0 a1 in
let h' = make_hash h0' h1' in
let open Lib.IntTypes in
let mapped = Spec.Loops.seq_map2 ( +. ) h a in
mapped == h'))
=
let h = make_hash h0 h1 in
let a = make_hash a0 a1 in
let h' = make_hash h0' h1' in
let open Lib.IntTypes in
let mapped = Spec.Loops.seq_map2 ( +. ) h a in
FStar.Classical.forall_intro_2 lemma_add_wrap_is_add_mod;
assert (equal mapped h');
() | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.X64.CryptoInstructions_s.fst.checked",
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Seq.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.Lemmas.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.SHA2.fst.checked",
"Spec.Loops.fst.checked",
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.SHA.SHA_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.UInt32 // Interop with UInt-based SHA spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt32",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CryptoInstructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.SHA",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Hash.Definitions.sha2_alg ->
hash: Spec.Hash.Definitions.words_state a ->
block: Spec.SHA2.block_w a
-> Spec.Hash.Definitions.words_state a | Prims.Tot | [
"total"
] | [] | [
"Spec.SHA2.shuffle"
] | [] | false | false | false | false | false | let shuffle_opaque =
| shuffle | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.